53 lines
2.4 KiB
Python
53 lines
2.4 KiB
Python
"""Exercise the contributor branch handoff with disposable Git repositories."""
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
def git(repo, *args):
|
|
return subprocess.check_output(["git", "-C", str(repo), *args], text=True).strip()
|
|
|
|
|
|
class ContributorWorkflowTests(unittest.TestCase):
|
|
def test_two_consecutive_tasks_preserve_unmerged_first_task(self):
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
base = Path(temp) / "project"
|
|
base.mkdir()
|
|
git(base, "init", "-q", "-b", "codex")
|
|
git(base, "config", "user.name", "Fixture")
|
|
git(base, "config", "user.email", "fixture@example.org")
|
|
(base / "AGENTS.md").write_text("Dedicated task branches; Captain approves merges.\n")
|
|
git(base, "add", "AGENTS.md")
|
|
git(base, "commit", "-qm", "base")
|
|
root_commit = git(base, "rev-parse", "HEAD")
|
|
|
|
first = Path(temp) / "task-001"
|
|
git(base, "worktree", "add", "-qb", "task-001", str(first), "codex")
|
|
(first / "feature-a.txt").write_text("task A\n")
|
|
(first / "notes.txt").write_text("safe untracked note\n")
|
|
self.assertIn("?? notes.txt", git(first, "status", "--short"))
|
|
git(first, "add", "feature-a.txt")
|
|
git(first, "commit", "-qm", "task A ready for review")
|
|
first_commit = git(first, "rev-parse", "HEAD")
|
|
self.assertIn("?? notes.txt", git(first, "status", "--short"))
|
|
# A local marker exercises the ordering gate; it is not an actual PR.
|
|
review_reference = f"local-review:{first_commit[:8]}"
|
|
self.assertTrue(review_reference.startswith("local-review:"))
|
|
|
|
second = Path(temp) / "task-002"
|
|
git(base, "worktree", "add", "-qb", "task-002", str(second), "codex")
|
|
(second / "feature-b.txt").write_text("task B\n")
|
|
git(second, "add", "feature-b.txt")
|
|
git(second, "commit", "-qm", "task B candidate")
|
|
self.assertEqual(git(base, "rev-parse", "HEAD"), root_commit)
|
|
self.assertNotEqual(git(second, "rev-parse", "HEAD"), first_commit)
|
|
self.assertFalse((second / "feature-a.txt").exists())
|
|
self.assertTrue((first / "notes.txt").exists())
|
|
self.assertIn(str(first), git(base, "worktree", "list"))
|
|
self.assertIn(str(second), git(base, "worktree", "list"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|