scripts
This commit is contained in:
@@ -11,11 +11,12 @@ import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[1] / "toolkits/testing/scripts"
|
||||
SOURCE = Path(__file__).resolve().parents[1] / "toolkits/testing"
|
||||
|
||||
|
||||
def run(*args, cwd=None, env=None):
|
||||
return subprocess.run(args, cwd=cwd, env=env, capture_output=True, text=True)
|
||||
return subprocess.run(args, cwd=cwd, env=env, stdin=subprocess.DEVNULL,
|
||||
capture_output=True, text=True)
|
||||
|
||||
|
||||
class ToolkitTests(unittest.TestCase):
|
||||
@@ -27,9 +28,13 @@ class ToolkitTests(unittest.TestCase):
|
||||
(self.root / "scripts").mkdir()
|
||||
(self.root / "docs").mkdir()
|
||||
(self.root / ".bortstack").mkdir()
|
||||
for name in ("testtask.sh", "testrunner.sh", "toolkit.py", "target.py"):
|
||||
shutil.copy2(SOURCE / name, self.root / "scripts" / name)
|
||||
(self.root / "docs/TASKS.md").write_text("## PI-042 — Current\nBranch/worktree: `feature/homepage`\n\n## TASK-001 — Legacy\nBranch/worktree: `feature-legacy`\n")
|
||||
for name in ("testtask.sh", "testrunner.sh"):
|
||||
shutil.copy2(SOURCE / "scripts" / name, self.root / "scripts" / name)
|
||||
runtime = self.root / ".bortstack/testing"
|
||||
runtime.mkdir()
|
||||
for name in ("toolkit.py", "target.py"):
|
||||
shutil.copy2(SOURCE / "runtime" / name, runtime / name)
|
||||
(self.root / "docs/TASKS.md").write_text("## PI-042 — Current\nBranch/worktree: `feature/homepage`\n\n## TASK-001: Legacy\nBranch/worktree: `feature-legacy`\n")
|
||||
(self.root / ".bortstack/testing.json").write_text(json.dumps({
|
||||
"version": 1,
|
||||
"manual": {"kind": "compose", "environment": "development", "file": "compose.yml", "project": "fixture", "ports": {"TEST_PORT": 59991}, "urls": ["http://127.0.0.1:59991/"]},
|
||||
@@ -84,6 +89,31 @@ class ToolkitTests(unittest.TestCase):
|
||||
run("git", "branch", "PI-042", cwd=self.root)
|
||||
self.assertIn("ambiguous identifier", self.runner("PI-042").stderr)
|
||||
|
||||
def test_manual_task_selects_registered_detached_snapshot(self):
|
||||
config = self.root / ".bortstack/testing.json"
|
||||
value = json.loads(config.read_text())
|
||||
value["manual"]["acceptance_snapshots"] = ".test-worktrees"
|
||||
config.write_text(json.dumps(value))
|
||||
branch_tree = Path(self.temp.name) / "legacy branch"
|
||||
run("git", "worktree", "add", "-q", str(branch_tree), "feature-legacy", cwd=self.root)
|
||||
launcher = str(self.root / "scripts/testtask.sh")
|
||||
|
||||
missing = run(launcher, "001", "--status", cwd=self.root)
|
||||
self.assertEqual(missing.returncode, 2, missing.stderr)
|
||||
self.assertIn("requires a registered detached acceptance snapshot", missing.stderr)
|
||||
|
||||
snapshot = self.root / ".test-worktrees/task-001"
|
||||
added = run("git", "worktree", "add", "-q", "--detach", str(snapshot), cwd=self.root)
|
||||
self.assertEqual(added.returncode, 0, added.stderr)
|
||||
(snapshot / ".bortstack/testing.json").write_text(json.dumps(value))
|
||||
for target in ("001", "TASK-001"):
|
||||
result = run(launcher, target, "--status", cwd=self.root)
|
||||
self.assertIn(f"worktree: {snapshot}", result.stdout)
|
||||
self.assertNotEqual(result.returncode, 2, result.stderr)
|
||||
automated = self.runner("TASK-001")
|
||||
self.assertEqual(automated.returncode, 0, automated.stderr)
|
||||
self.assertIn(f"worktree: {branch_tree}", automated.stdout)
|
||||
|
||||
def test_configuration_and_act_safety(self):
|
||||
config = self.root / ".bortstack/testing.json"
|
||||
value = json.loads(config.read_text())
|
||||
@@ -156,9 +186,9 @@ class ToolkitTests(unittest.TestCase):
|
||||
self.assertIn("stop", Path(env["DOCKER_LOG"]).read_text())
|
||||
|
||||
def test_interactive_custom_credentials_are_ephemeral(self):
|
||||
sys.path.insert(0, str(SOURCE))
|
||||
self.addCleanup(lambda: sys.path.remove(str(SOURCE)))
|
||||
spec = importlib.util.spec_from_file_location("forge_toolkit_test", SOURCE / "toolkit.py")
|
||||
sys.path.insert(0, str(SOURCE / "runtime"))
|
||||
self.addCleanup(lambda: sys.path.remove(str(SOURCE / "runtime")))
|
||||
spec = importlib.util.spec_from_file_location("forge_toolkit_test", SOURCE / "runtime/toolkit.py")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
private = Path(self.temp.name) / "config"
|
||||
@@ -185,9 +215,9 @@ class ToolkitTests(unittest.TestCase):
|
||||
module.credentials("fixture", False)
|
||||
|
||||
def test_port_conflict_does_not_start_compose(self):
|
||||
sys.path.insert(0, str(SOURCE))
|
||||
self.addCleanup(lambda: sys.path.remove(str(SOURCE)))
|
||||
spec = importlib.util.spec_from_file_location("forge_toolkit_port_test", SOURCE / "toolkit.py")
|
||||
sys.path.insert(0, str(SOURCE / "runtime"))
|
||||
self.addCleanup(lambda: sys.path.remove(str(SOURCE / "runtime")))
|
||||
spec = importlib.util.spec_from_file_location("forge_toolkit_port_test", SOURCE / "runtime/toolkit.py")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
bin_dir = Path(self.temp.name) / "bin-port"
|
||||
|
||||
Reference in New Issue
Block a user