forked from linkong/planet
81 lines
3.0 KiB
Python
81 lines
3.0 KiB
Python
"""Exercise the validation entry point when Bun is found through a login shell."""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
class ToolResolutionTests(unittest.TestCase):
|
|
def test_validation_exposes_resolved_bun_to_package_scripts(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
harness = root / "scripts" / "harness"
|
|
harness.mkdir(parents=True)
|
|
(root / "frontend").mkdir()
|
|
for name in ("validate.sh", "lib.sh"):
|
|
shutil.copy2(ROOT / "scripts" / "harness" / name, harness / name)
|
|
quick = harness / "quick-check.sh"
|
|
quick.write_text("#!/bin/bash\nexit 0\n")
|
|
quick.chmod(0o755)
|
|
|
|
tools = root / "login-tools"
|
|
tools.mkdir()
|
|
bun = tools / "bun"
|
|
bun.write_text(
|
|
"#!/bin/bash\n"
|
|
"set -e\n"
|
|
'if [ "$1" = run ]; then\n'
|
|
" /bin/bash -c 'command -v bun >/dev/null || exit 42'\n"
|
|
' test "$3" = --outDir || exit 43\n'
|
|
' printf "%s" "$4" > "$TEST_BUILD_DIR_LOG"\n'
|
|
' printf "build output" > "$4/generated.txt"\n'
|
|
"fi\n"
|
|
)
|
|
bun.chmod(0o755)
|
|
login_shell = root / "login-shell"
|
|
login_shell.write_text(
|
|
"#!/bin/bash\n"
|
|
'if [ "$2" = "command -v bun" ]; then\n'
|
|
' printf "%s\\n" "$TEST_LOGIN_BUN"\n'
|
|
"else\n"
|
|
" exit 1\n"
|
|
"fi\n"
|
|
)
|
|
login_shell.chmod(0o755)
|
|
path_tools = root / "path-tools"
|
|
path_tools.mkdir()
|
|
for command in ("dirname", "sed", "mktemp", "rm"):
|
|
(path_tools / command).symlink_to(shutil.which(command))
|
|
env = {
|
|
**os.environ,
|
|
"PATH": str(path_tools),
|
|
"SHELL": str(login_shell),
|
|
"TEST_LOGIN_BUN": str(bun),
|
|
"TEST_BUILD_DIR_LOG": str(root / "build-dir.txt"),
|
|
"TMPDIR": str(root),
|
|
"PLANET_HARNESS_FRONTEND_SMOKE": "0",
|
|
"PLANET_HARNESS_DOCKER_SMOKE": "0",
|
|
}
|
|
result = subprocess.run(
|
|
["/bin/bash", str(harness / "validate.sh")],
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=10,
|
|
)
|
|
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
|
self.assertIn("harness validation passed", result.stdout)
|
|
build_dir = Path((root / "build-dir.txt").read_text())
|
|
self.assertEqual(build_dir.parent, root)
|
|
self.assertFalse(build_dir.exists())
|
|
self.assertFalse((root / "frontend" / "dist").exists())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|