From 0f6857c26e5b2777c6be927dbc75fdcdbfe0e750 Mon Sep 17 00:00:00 2001 From: godosa Date: Wed, 7 Oct 2026 09:12:20 +0200 Subject: split projects 1/6: Config.split, push key, .wf-home discovery Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01JEAjUkQRrCYX5MZhWxdtj2 --- tests/test_split.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/test_split.py (limited to 'tests') diff --git a/tests/test_split.py b/tests/test_split.py new file mode 100644 index 0000000..2026e33 --- /dev/null +++ b/tests/test_split.py @@ -0,0 +1,74 @@ +import subprocess +import unittest +from pathlib import Path + +from test_cli import TOML, Cli +from test_claims import git +from test_merge import IDENT + + +class SplitCli(Cli): + """Private project (self.root, git, workflow.toml with code_root) + sibling code repo (self.code).""" + toml = TOML + 'code_root = "../code"\n' + + def setUp(self): + super().setUp() + git(self.root, "init", "-q", "-b", "master") + (self.root / ".gitignore").write_text(".wf/\nout/\n") + git(self.root, "add", "-A") + git(self.root, "commit", "-qm", "init") + self.code = self.root.parent / "code" + self.code.mkdir() + git(self.code, "init", "-q", "-b", "master") + (self.code / ".gitignore").write_text(".worktrees/\n.wf-home\n") + (self.code / "lib.txt").write_text("a\n") + git(self.code, "add", "-A") + git(self.code, "commit", "-qm", "init") + + def add_wt(self, lane="sonnet", id="t-three"): + """Code worktree on branch / with .wf-home (what wf start makes).""" + wt = self.code / ".worktrees" / lane + git(self.code, "worktree", "add", "-q", str(wt), "-b", f"{lane}/{id}") + (wt / ".wf-home").write_text(f"{self.root}\n") + return wt + + def log(self, repo, rev="master"): + return subprocess.run(["git", "log", "--format=%s", rev], cwd=repo, capture_output=True, text=True).stdout + + def sha(self, repo, rev="master"): + return subprocess.run(["git", "rev-parse", "--short", rev], cwd=repo, capture_output=True, text=True).stdout.strip() + + +class DiscoveryTest(SplitCli): + def test_wf_in_code_worktree_finds_private_project(self): + wt = self.add_wt() + code, out, err = self.wf("show", "t-three", project=False, cwd=wt) + self.assertEqual(code, 0, err) + self.assertIn("**t-three**", out) + + def test_dangling_wf_home_is_config_error(self): + wt = self.add_wt() + (wt / ".wf-home").write_text(f"{self.root.parent / 'gone'}\n") + code, out, err = self.wf("show", "t-three", project=False, cwd=wt) + self.assertNotEqual(code, 0) + self.assertIn(".wf-home points to", err) + self.assertNotIn("Traceback", err) + + def test_split_and_code_main(self): + import sys + sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + from wflib import config + cfg = config.load(self.root) + self.assertTrue(cfg.split) + self.assertEqual(config.code_main(cfg), self.code) + self.assertEqual(cfg.push, []) + + def test_code_root_inside_same_repo_not_split(self): + import sys + sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + from wflib import config + (self.root / "workflow.toml").write_text(TOML + 'code_root = "."\npush = ["true"]\n') + cfg = config.load(self.root) + self.assertFalse(cfg.split) + self.assertIsNone(config.code_main(cfg)) + self.assertEqual(cfg.push, ["true"]) -- cgit