aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_split.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/test_split.py b/tests/test_split.py
index 346c138..d382a9f 100644
--- a/tests/test_split.py
+++ b/tests/test_split.py
@@ -109,3 +109,89 @@ class StartSplitTest(SplitCli):
code, out, err = self.wf("next", "--lane", "fast", "--as", "opus", env=me)
self.assertIn(f" wf start <task> --worktree {self.code / '.worktrees' / 'fast'} --branch fast/<task> "
f"(run in {self.root}; wf there writes this TASKS.md)\n", out)
+
+
+class FinishSplitTest(SplitCli):
+ def setUp(self):
+ super().setUp()
+ self.wt = self.add_wt()
+
+ def finish(self, *args):
+ return self.wf("finish", *args, "--no-push", project=False, cwd=self.wt, env=IDENT)
+
+ def test_code_only(self):
+ (self.wt / "code.txt").write_text("x\n")
+ code, out, err = self.finish("t-three", "-m", "ok", "--commit", "impl", "code.txt")
+ self.assertEqual(code, 0, out + err)
+ self.assertEqual(self.log(self.code), "impl\ninit\n")
+ csha = self.sha(self.code)
+ self.assertEqual(self.log(self.root), f"t-three done (code {csha})\ninit\n")
+ self.assertTrue(out.endswith(f"report: commit {csha} books {self.sha(self.root)}\n"), out)
+ self.assertEqual(subprocess.run(["git", "branch", "--list", "sonnet/t-three"], cwd=self.code,
+ capture_output=True, text=True).stdout, "")
+ self.assertIn("t-three", (self.root / "tasks" / "archive.md").read_text())
+
+ def test_code_and_private_path(self):
+ (self.wt / "code.txt").write_text("x\n")
+ (self.root / "docs" / "notes.md").write_text("n\n")
+ code, out, err = self.finish("t-three", "-m", "ok", "--commit", "impl", "code.txt",
+ str(self.root / "docs" / "notes.md"))
+ self.assertEqual(code, 0, out + err)
+ self.assertEqual(self.log(self.code), "impl\ninit\n")
+ self.assertEqual(self.log(self.root), f"impl (code {self.sha(self.code)})\ninit\n")
+ self.assertIn("docs/notes.md", subprocess.run(["git", "show", "--stat", "HEAD"], cwd=self.root,
+ capture_output=True, text=True).stdout)
+
+ def test_private_only(self):
+ (self.root / "docs" / "notes.md").write_text("n\n")
+ code, out, err = self.finish("t-three", "-m", "ok", "--commit", "areas", str(self.root / "docs" / "notes.md"))
+ self.assertEqual(code, 0, out + err)
+ self.assertEqual(self.log(self.code), "init\n") # no empty code commit
+ self.assertEqual(self.log(self.root), "areas\ninit\n")
+ self.assertTrue(out.endswith(f"report: commit - books {self.sha(self.root)}\n"), out)
+ self.assertEqual(subprocess.run(["git", "branch", "--list", "sonnet/t-three"], cwd=self.code,
+ capture_output=True, text=True).stdout, "")
+
+ def test_stray_code_file_refused_task_open(self):
+ (self.wt / "code.txt").write_text("x\n")
+ (self.wt / "stray.txt").write_text("s\n")
+ code, out, err = self.finish("t-three", "-m", "ok", "--commit", "impl", "code.txt")
+ self.assertNotEqual(code, 0)
+ self.assertIn("stray.txt", err)
+ self.assertIn("- **t-three**", (self.root / "TASKS.md").read_text())
+
+ def test_path_in_neither_repo_refused(self):
+ other = self.root.parent / "elsewhere.txt"
+ other.write_text("e\n")
+ code, out, err = self.finish("t-three", "-m", "ok", "--commit", "impl", str(other))
+ self.assertNotEqual(code, 0)
+ self.assertIn("in neither repo", err)
+
+ def test_rebase_conflict_commits_nothing_private(self):
+ (self.wt / "lib.txt").write_text("branch\n")
+ (self.code / "lib.txt").write_text("master\n")
+ git(self.code, "commit", "-qam", "moved")
+ code, out, err = self.finish("t-three", "-m", "ok", "--commit", "impl", "lib.txt")
+ self.assertNotEqual(code, 0)
+ self.assertIn("conflicts", err)
+ self.assertEqual(self.log(self.root), "init\n") # books not committed yet
+ (self.wt / "lib.txt").write_text("both\n") # resolve by hand as the worker would
+ git(self.wt, "reset", "-q", "--soft", "master")
+ git(self.wt, "commit", "-qam", "impl")
+ code, out, err = self.wf("merge", "--no-push", project=False, cwd=self.wt, env=IDENT)
+ self.assertEqual(code, 0, out + err)
+ self.assertTrue(self.log(self.root).startswith("t-three done (code "), self.log(self.root))
+
+ def test_wip_commits_both(self):
+ (self.wt / "code.txt").write_text("x\n")
+ (self.root / "docs" / "notes.md").write_text("n\n")
+ code, out, err = self.wf("wip", "t-three", "-m", "half", "--commit", "wip", "code.txt",
+ str(self.root / "docs" / "notes.md"), project=False, cwd=self.wt, env=IDENT)
+ self.assertEqual(code, 0, out + err)
+ self.assertEqual(self.log(self.code, "sonnet/t-three"), "wip\ninit\n")
+ self.assertEqual(self.log(self.root), "t-three wip: half\ninit\n")
+
+ def test_done_lines_name_private_books(self):
+ code, out, err = self.wf("done", "t-three", "-m", "ok", project=False, cwd=self.wt, env=IDENT)
+ self.assertEqual(code, 0, out + err)
+ self.assertIn("commit TASKS.md tasks/archive.md, push home", out)