|
| 1 | +"""In-place (no-worktree) task resolution in the review faculty.""" |
| 2 | + |
| 3 | +import subprocess |
| 4 | +import sys |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "agents" / "faculties" / "review")) |
| 8 | + |
| 9 | +import _review # noqa: E402 |
| 10 | + |
| 11 | +ACTIVE = """\ |
| 12 | +# Active Tasks |
| 13 | +
|
| 14 | +## other-task |
| 15 | +- worktree: ~/Code/PyAutoLabs-wt/other-task |
| 16 | +- repos: |
| 17 | + - PyAutoArray: feature/other-task |
| 18 | +
|
| 19 | +## my-inplace-task |
| 20 | +- issue: https://example/1 |
| 21 | +- status: workspace-dev |
| 22 | +- worktree: none (in-place) |
| 23 | +- repos: |
| 24 | + - repo_a: feature/my-inplace-task |
| 25 | + - repo_b: feature/my-inplace-task |
| 26 | +
|
| 27 | +## no-repos-task |
| 28 | +- repos: |
| 29 | +""" |
| 30 | + |
| 31 | + |
| 32 | +def make_root(tmp_path, monkeypatch): |
| 33 | + (tmp_path / "PyAutoMind").mkdir() |
| 34 | + (tmp_path / "PyAutoMind" / "active.md").write_text(ACTIVE) |
| 35 | + for name in ("repo_a", "repo_b"): |
| 36 | + subprocess.run(["git", "init", "-q", str(tmp_path / name)], check=True) |
| 37 | + monkeypatch.setenv("PYAUTO_ROOT", str(tmp_path)) |
| 38 | + return tmp_path |
| 39 | + |
| 40 | + |
| 41 | +def test_in_place_repos_reads_only_the_named_tasks_block(tmp_path, monkeypatch): |
| 42 | + root = make_root(tmp_path, monkeypatch) |
| 43 | + repos = _review.in_place_repos("my-inplace-task") |
| 44 | + assert repos == [root / "repo_a", root / "repo_b"] |
| 45 | + |
| 46 | + |
| 47 | +def test_in_place_repos_skips_missing_checkouts_and_unknown_tasks(tmp_path, monkeypatch): |
| 48 | + make_root(tmp_path, monkeypatch) |
| 49 | + # other-task claims PyAutoArray, which has no checkout under this root. |
| 50 | + assert _review.in_place_repos("other-task") == [] |
| 51 | + assert _review.in_place_repos("nonexistent") == [] |
| 52 | + assert _review.in_place_repos("no-repos-task") == [] |
| 53 | + |
| 54 | + |
| 55 | +def test_resolve_repos_falls_back_when_no_worktree(tmp_path, monkeypatch): |
| 56 | + root = make_root(tmp_path, monkeypatch) |
| 57 | + monkeypatch.setattr(_review, "WT_BASE", tmp_path / "no-such-wt-base") |
| 58 | + repos = _review.resolve_repos("my-inplace-task", []) |
| 59 | + assert repos == [root / "repo_a", root / "repo_b"] |
0 commit comments