diff --git a/tests/python/test_brief.py b/tests/python/test_brief.py index 629a776c..b0df710e 100644 --- a/tests/python/test_brief.py +++ b/tests/python/test_brief.py @@ -1203,6 +1203,34 @@ def test_areas_a_pushed_branchs_base_is_its_remotes_master( assert [e["area"] for e in areas(repo)] == [["src/p.cpp", "tools/p.py"]] +BENCH = "docs/benchmarks/2026-11-03/other-acceptance/run.json" + + +def test_areas_a_probe_beside_a_branch_carrying_committed_benchmarks_passes( + repo: Path, home: Path, trees: dict[str, Path] +) -> None: + """2026-11-03: a branch's committed benchmark files are not its tester's to + write, and a probe writes only its own folder; neither refuses the other.""" + commit_file(trees["A"], BENCH) + commit_file(trees["A"], "tests/test_x.py") + ok(repo, home, *area_brief(trees["B"], persona="perf")) + ok(repo, home, *area_brief(trees["A"], persona="tester")) + ok(repo, home, *area_brief(trees["B"], "docs/benchmarks/2026-11-03/probe/", persona="perf")) + assert len(areas(repo)) == 2 + + +def test_areas_two_writers_on_one_committed_file_are_refused( + repo: Path, home: Path, trees: dict[str, Path] +) -> None: + commit_file(trees["A"], "tests/test_x.py") + ok(repo, home, *area_brief(trees["A"], persona="tester")) + refused(repo, home, *area_brief(trees["B"], "tests/test_x.py"), says=f"{SAME}tests/test_x.py") + probe = "docs/benchmarks/2026-11-03/probe/" + ok(repo, home, *area_brief(trees["C"], probe, persona="perf")) + refused(repo, home, *area_brief(trees["B"], f"{probe}r.json", persona="perf"), + says=f"{SAME}{probe}r.json") # fmt: skip + + # ---------------------------------------------------------------- settled results first diff --git a/tools/brief.py b/tools/brief.py index 9134849e..c7de169f 100644 --- a/tools/brief.py +++ b/tools/brief.py @@ -163,17 +163,18 @@ def _inside(path: str, prefix: str) -> bool: return path == prefix or path.startswith(prefix.rstrip("/") + "/") -def _area(worktree: str, declared: list[str]) -> set[str]: - """Pipe 3.6: what the branch changes against its base, plus `declared` before its - first commit. The base is where it leaves the master of its upstream's remote (a +def _area(worktree: str, declared: list[str], limit: list[str]) -> set[str]: + """Pipe 3.6: what the branch changes against its base inside `limit` (all, when + empty: a file it carries but may not write is not its to guard), plus `declared` + before its first commit. The base is where it leaves the master of its upstream's remote (a private-repo branch shares no recent history with origin/master; a pushed branch's upstream is its own copy), else origin/master, else master.""" up = _git(worktree, "rev-parse", "--abbrev-ref", "@{upstream}") or "" refs = (up if up.endswith("master") else up.partition("/")[0] + "/master", "origin/master", "master") # fmt: skip base = next(filter(None, (_git(worktree, "merge-base", "HEAD", r) for r in refs)), None) - changed = set((_git(worktree, "diff", "--name-only", base, "HEAD") or "").splitlines() - if base else ()) # fmt: skip + diff = (_git(worktree, "diff", "--name-only", base, "HEAD") or "") if base else "" + changed = {p for p in diff.splitlines() if not limit or any(_inside(p, w) for w in limit)} return changed | set(declared) if base in (None, _git(worktree, "rev-parse", "HEAD")) \ else changed # fmt: skip @@ -198,7 +199,8 @@ def name(e: dict[str, str | list[str]]) -> str: return f"@{e['persona']} ({e['item'] or 'no item'}, in {e['worktree']})" for other in running: - theirs = _area(str(other["worktree"]), list(other["declared"])) + theirs = _area(str(other["worktree"]), list(other["declared"]), + list(other.get("limit", []))) # fmt: skip shared = sorted({b if _inside(b, a) else a for a in mine["area"] for b in theirs if _inside(a, b) or _inside(b, a)}) # fmt: skip if shared: @@ -375,7 +377,8 @@ def _brief(argv: list[str] | None) -> str: declared = args.area or prefixes mine = {"persona": persona, "worktree": str(worktree), "item": args.item, "branch": _git(worktree, "rev-parse", "--abbrev-ref", "HEAD") or "", "note": str(note), - "declared": declared, "area": sorted(_area(str(worktree), declared))} # fmt: skip + "declared": declared, "limit": prefixes, + "area": sorted(_area(str(worktree), declared, declared))} # fmt: skip if persona == "perf": mine["timed"] = "untimed" if args.untimed else "timed" if WRITES[persona]: