From e0fcc9075312ad3c36b1296b6802e2fec9b0c909 Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 05:44:47 +0000 Subject: [PATCH 01/13] code.symbol_history and the review brief name the PRs behind a regression record code.symbol_history returns regression_prs: up to three PRs behind its named_fix_prs, reverts and caused_issues counts, strongest first, each with its title, merge date, kinds, fix_by, the issues it caused, up to four test files it changed and a code.test_gate query for them. A code.review_brief history row that makes `regressions` carries them. The counts and verdicts are unchanged. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/features/code-index/history-and-prs.md | 13 ++++ docs/reference/operations/code.md | 1 + sdk/go/wire/models.gen.go | 1 + sdk/python/loom/ops.py | 1 + sdk/rust/src/wire_models.rs | 6 ++ sdk/rust/tests/registry_contracts.rs | 5 ++ sdk/typescript/src/generated/ops.ts | 1 + server/code/api/models_history.py | 8 +++ server/code/app/index/review_brief_build.py | 36 +++++----- server/code/app/symbol_history.py | 1 + server/code/domain/index/symbol_history.py | 64 +++++++++++++++++ tests/unit/test_code_review_brief_sections.py | 4 ++ tests/unit/test_code_symbol_history.py | 72 +++++++++++++++++++ 13 files changed, 197 insertions(+), 16 deletions(-) diff --git a/docs/features/code-index/history-and-prs.md b/docs/features/code-index/history-and-prs.md index 8794a107f1e..f1faa318054 100644 --- a/docs/features/code-index/history-and-prs.md +++ b/docs/features/code-index/history-and-prs.md @@ -171,6 +171,17 @@ the PRs of its files (every file that defines a name), newest first; a `numbers` answers in one page of up to `limit` PRs and refuses `offset`. `code.symbol_history` narrows this to one function's regression history: the PRs that touched its span, their linked issues and reverts, and the review comments inside it. +Its `regression_prs` names up to three PRs behind the summary's `named_fix_prs`, +`reverts` and `caused_issues`, read from the whole window whatever `limit` serves. Each +carries its title as the one-line cause, its merge date, `kinds` (`fix`, `revert`, +`caused_issue` with the issue numbers), and up to four test files it changed, as the PR +ledger lists them, those with a known run recipe first. When it changed a test file, +`test_query` is the `code.test_gate` call that lists how to run them. A PR behind more of +the counts comes first, then a fix before a revert before a PR issues trace back to. A fix +says `fix_by`: `title` when its title says fix, crash, regression and the like, or +`linked_issue` when it is counted only for closing an issue, which a feature or +performance PR does too; a `title` fix ranks first. The record is the PR ledger's, so it +holds for every language the index reads. `code.blame_range` takes a `path`, a line range (at most 400 lines) and a window as release versions (`from_version`, `to_version`) or commit shas. It combines the PR @@ -203,6 +214,8 @@ record by its file and name (`path:symbol`), so a name many files define, such a `path:symbol` form does not parse, such as a path without an extension or with `[`, or a name such as `(anonymous namespace)::f`, reads the bare name, as does a form past the op's 300-character name bound; a record of another file's definition is `unknown`. +A row whose counts make the section `regressions` carries that record's `regression_prs`, +so the brief names the earlier fixes, reverts and culprit PRs with their test files. The answer comes first: `verdict` and `verdict_causes`, read off every section the brief holds, whatever the tier serves, and off `rationale` when this read serves it. A verdict diff --git a/docs/reference/operations/code.md b/docs/reference/operations/code.md index d271d547248..acd0c23cd58 100644 --- a/docs/reference/operations/code.md +++ b/docs/reference/operations/code.md @@ -1730,6 +1730,7 @@ The regression history of one function: the merged PRs that touched it (with lin | `review_comments` | `list[dict[str, Any]]` | inline review comments inside the symbol's span, newest first (≤5) | | `open_issues_naming` | `list[dict[str, Any]]` | open issues whose text names the function (QA), most severe first (≤5) | | `summary` | `dict[str, Any]` | {prs_total, named_prs, fix_prs, named_fix_prs, reverts, caused_issues[], open_issues_naming, last_touched, oldest_in_window, authors[], note} | +| `regression_prs` | `list[dict[str, Any]]` | The PRs behind the summary's named_fix_prs, reverts and caused_issues, from the whole window whatever `limit` serves, strongest first (≤3): {pr_number, title, merged_at (date), kinds[] (fix \| revert \| caused_issue), fix_by (with fix: title… | | `tracker_namespace` | `str` | The tracker namespace that answered the QA side; "" when none is bound or its read failed. | | `tracker_unavailable` | `bool` | True when a tracker is bound but its read failed. | | `trace_run_id` | `str` | Id of this call's trace row; pass it to `code.outcome`. | diff --git a/sdk/go/wire/models.gen.go b/sdk/go/wire/models.gen.go index 11bd896debe..c1ea612b1ab 100644 --- a/sdk/go/wire/models.gen.go +++ b/sdk/go/wire/models.gen.go @@ -2464,6 +2464,7 @@ type CodeSymbolHistoryOutput struct { ReviewComments *[]map[string]json.RawMessage `json:"review_comments,omitempty"` OpenIssuesNaming *[]map[string]json.RawMessage `json:"open_issues_naming,omitempty"` Summary *map[string]json.RawMessage `json:"summary,omitempty"` + RegressionPrs *[]map[string]json.RawMessage `json:"regression_prs,omitempty"` TrackerNamespace *string `json:"tracker_namespace,omitempty"` TrackerUnavailable *bool `json:"tracker_unavailable,omitempty"` TraceRunID *string `json:"trace_run_id,omitempty"` diff --git a/sdk/python/loom/ops.py b/sdk/python/loom/ops.py index fed55a178ba..b46e24dd58f 100644 --- a/sdk/python/loom/ops.py +++ b/sdk/python/loom/ops.py @@ -8718,6 +8718,7 @@ class CodeSymbolHistoryOutput(TypedDict, total=False): review_comments: NotRequired[list[dict[str, Any]]] open_issues_naming: NotRequired[list[dict[str, Any]]] summary: NotRequired[dict[str, Any]] + regression_prs: NotRequired[list[dict[str, Any]]] tracker_namespace: NotRequired[str] tracker_unavailable: NotRequired[bool] trace_run_id: NotRequired[str] diff --git a/sdk/rust/src/wire_models.rs b/sdk/rust/src/wire_models.rs index dee1f7fb442..41597946daf 100644 --- a/sdk/rust/src/wire_models.rs +++ b/sdk/rust/src/wire_models.rs @@ -15764,6 +15764,8 @@ pub struct CodeSymbolHistoryOutput { pub open_issues_naming: Vec>, #[serde(default = "default_code_symbol_history_output_summary")] pub summary: std::collections::HashMap, + #[serde(default = "default_code_symbol_history_output_regression_prs")] + pub regression_prs: Vec>, #[serde(default = "default_code_symbol_history_output_tracker_namespace")] pub tracker_namespace: String, #[serde(default = "default_code_symbol_history_output_tracker_unavailable")] @@ -69490,6 +69492,10 @@ fn default_code_symbol_history_output_open_issues_naming( fn default_code_symbol_history_output_summary() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } +fn default_code_symbol_history_output_regression_prs( +) -> Vec> { + serde_json::from_str("[]").expect("schema default") +} fn default_code_symbol_history_output_tracker_namespace() -> String { serde_json::from_str("\"\"").expect("schema default") } diff --git a/sdk/rust/tests/registry_contracts.rs b/sdk/rust/tests/registry_contracts.rs index 16f15cd3ff0..364dbae8b1a 100644 --- a/sdk/rust/tests/registry_contracts.rs +++ b/sdk/rust/tests/registry_contracts.rs @@ -10697,6 +10697,11 @@ fn code_symbol_history() { serde_json::from_str::("{}").unwrap(), "code.symbol_history:summary" ); + assert_eq!( + encoded["regression_prs"], + serde_json::from_str::("[]").unwrap(), + "code.symbol_history:regression_prs" + ); assert_eq!( encoded["tracker_namespace"], serde_json::from_str::("\"\"").unwrap(), diff --git a/sdk/typescript/src/generated/ops.ts b/sdk/typescript/src/generated/ops.ts index 5ed29683ca0..944f4c3f38c 100644 --- a/sdk/typescript/src/generated/ops.ts +++ b/sdk/typescript/src/generated/ops.ts @@ -1915,6 +1915,7 @@ export interface CodeSymbolHistoryOutput { review_comments?: Array>; open_issues_naming?: Array>; summary?: Record; + regression_prs?: Array>; tracker_namespace?: string; tracker_unavailable?: boolean; trace_run_id?: string; diff --git a/server/code/api/models_history.py b/server/code/api/models_history.py index b27899132d2..d221ce8fa58 100644 --- a/server/code/api/models_history.py +++ b/server/code/api/models_history.py @@ -617,6 +617,14 @@ class CodeSymbolHistoryOutput(BaseModel): # {prs_total, named_prs, fix_prs, named_fix_prs, reverts, caused_issues[], # open_issues_naming, last_touched, oldest_in_window, authors[], note} summary: dict[str, Any] = Field(default_factory=dict) + # The PRs behind the summary's named_fix_prs, reverts and caused_issues, from the whole + # window whatever `limit` serves, strongest first (≤3): {pr_number, title, merged_at + # (date), kinds[] (fix | revert | caused_issue), fix_by (with fix: title, when the + # title says fix, crash, regression and the like, or linked_issue, when it only closes + # an issue), caused_issues[] (with caused_issue), test_files[] (≤4: the test files the + # PR changed, as the ledger lists them, those with a known run recipe first), + # test_query ({op: code.test_gate, args: {files}}, only when test_files is not empty)} + regression_prs: list[dict[str, Any]] = Field(default_factory=list) # The tracker namespace that answered the QA side; "" when none is bound or # its read failed. tracker_namespace: str = "" diff --git a/server/code/app/index/review_brief_build.py b/server/code/app/index/review_brief_build.py index 56ea5fea290..1be073fe2cb 100644 --- a/server/code/app/index/review_brief_build.py +++ b/server/code/app/index/review_brief_build.py @@ -64,6 +64,7 @@ from server.code.app.symbol.diff import _parse_unified_diff_full, is_blank from server.code.app.symbol.resolve import _parse_file_symbol from server.code.domain.index.epistemic import CAUSE_NEW_SIDE_FAILED, CAUSE_UNMAPPED +from server.code.domain.index.symbol_history import EVIDENCE_PRS from server.code.domain.index.test_gate import is_test_path from server.observability import degradations @@ -934,22 +935,25 @@ async def _history_section( if resolved and resolved != path: res = {"verdict": "unknown"} s = dict(res.get("summary") or {}) - rows.append( - { - "qualified_name": name, - "path": path, - "verdict": str(res.get("verdict") or "unknown"), - "prs_total": int(s.get("prs_total") or 0), - "fix_prs": int(s.get("fix_prs") or 0), - "named_fix_prs": int(s.get("named_fix_prs") or 0), - "reverts": int(s.get("reverts") or 0), - "caused_issues": len(list(s.get("caused_issues") or [])), - "open_issues_naming": int(s.get("open_issues_naming") or 0), - "last_touched": str(s.get("last_touched") or ""), - "tracker": not bool(res.get("tracker_unavailable")) - and bool(res.get("tracker_namespace")), - } - ) + row: dict[str, Any] = { + "qualified_name": name, + "path": path, + "verdict": str(res.get("verdict") or "unknown"), + "prs_total": int(s.get("prs_total") or 0), + "fix_prs": int(s.get("fix_prs") or 0), + "named_fix_prs": int(s.get("named_fix_prs") or 0), + "reverts": int(s.get("reverts") or 0), + "caused_issues": len(list(s.get("caused_issues") or [])), + "open_issues_naming": int(s.get("open_issues_naming") or 0), + "last_touched": str(s.get("last_touched") or ""), + "tracker": not bool(res.get("tracker_unavailable")) + and bool(res.get("tracker_namespace")), + } + if row["named_fix_prs"] or row["reverts"] or row["caused_issues"]: + # the PRs behind the counts that make `regressions`, each with its title + # and the test files it changed + row["regression_prs"] = list(res.get("regression_prs") or [])[:EVIDENCE_PRS] + rows.append(row) # the tracker is bound and its read failed: the issues it traces are unread unavailable += bool(res.get("tracker_unavailable")) rows.sort( diff --git a/server/code/app/symbol_history.py b/server/code/app/symbol_history.py index 4d66356e0c6..0d969f8d46a 100644 --- a/server/code/app/symbol_history.py +++ b/server/code/app/symbol_history.py @@ -218,6 +218,7 @@ async def handle_code_symbol_history(input: Any) -> Any: review_comments=span_comments, open_issues_naming=[_open_issue_view(r) for r in open_issues[:5]], summary=summary, + regression_prs=sh.regression_prs(rows), tracker_namespace=tracker_ns, tracker_unavailable=tracker_unavailable, trace_run_id=trace_run_id, diff --git a/server/code/domain/index/symbol_history.py b/server/code/domain/index/symbol_history.py index 0b69a8fcd00..c05299a062b 100644 --- a/server/code/domain/index/symbol_history.py +++ b/server/code/domain/index/symbol_history.py @@ -17,6 +17,7 @@ from typing import Any from server.code.domain.index.blame_range import sha_text +from server.code.domain.index.test_gate import is_test_path, run_command_for HISTORY = "history" NO_HISTORY = "no_history" @@ -25,6 +26,9 @@ # counts those among them that touch the definition, and `limit` serves up to all. # not a setting: the op's `limit` bound on the wire is derived from it PR_WINDOW = 120 +# not a setting: bounds on `regression_prs`, the evidence behind the summary's counts +EVIDENCE_PRS = 3 +EVIDENCE_TEST_FILES = 4 _FIX_RE = re.compile( r"(?i)\b(fix|fixes|fixed|fixing|bug|crash|regression|logical error|segfault|" @@ -49,6 +53,8 @@ class PrRow: # false (QA diff does not) | unknown touches_symbol: str = "unknown" tracker: dict[str, Any] = field(default_factory=dict) + # the test files among the PR's changed files, as the ledger lists them + test_files: list[str] = field(default_factory=list) def as_dict(self) -> dict[str, Any]: out: dict[str, Any] = { @@ -150,6 +156,7 @@ def build_rows( is_backport=bool(_BACKPORT_RE.match(title)), linked_issues=linked, comments_on_symbol=by_pr_comments.get(n, 0), + test_files=[str(f) for f in (r.get("files") or []) if is_test_path(str(f))], ) # loom's own function-level hint: the PR's title or description # names the function (a review comment inside the span counts too) @@ -245,6 +252,62 @@ def summarize( } +_KIND_ORDER = {"fix": 0, "revert": 1, "caused_issue": 2} + + +def _evidence_kinds(row: PrRow) -> list[str]: + """Which of the summary's regression counts the row adds to: `fix` (a named fix), + `revert`, `caused_issue` (an issue the tracker traces back to it).""" + if row.touches_symbol == "false": + return [] + kinds: list[str] = [] + if row.is_fix and not row.is_revert and row.touches_symbol in ("true", "named"): + kinds.append("fix") + if row.is_revert: + kinds.append("revert") + if row.tracker.get("caused"): + kinds.append("caused_issue") + return kinds + + +def regression_prs(rows: list[PrRow]) -> list[dict[str, Any]]: + """The PRs behind `named_fix_prs`, `reverts` and `caused_issues`, strongest first: a + PR behind more of the counts, then a named fix before a revert before a PR issues + trace back to, a fix its title names before one counted only for closing an issue + (`fix_by`), then the newest. Each carries its title as the one-line cause and the + test files it changed, runnable ones first, with the `code.test_gate` query that + lists how to run them; no query when it changed none.""" + + def strength(rk: tuple[PrRow, list[str]]) -> tuple[int, int, bool]: + row, kinds = rk + by_title = "fix" in kinds and bool(_FIX_RE.search(row.title)) + return -len(kinds), _KIND_ORDER[kinds[0]], not by_title + + picked = [(r, k) for r in rows if (k := _evidence_kinds(r))] + picked.sort(key=lambda rk: rk[0].merged_at, reverse=True) + picked.sort(key=strength) + out: list[dict[str, Any]] = [] + for row, kinds in picked[:EVIDENCE_PRS]: + # a file with a known run recipe (a test) before one without (its fixture) + tests = sorted(row.test_files, key=lambda p: run_command_for(p)[1]) + tests = tests[:EVIDENCE_TEST_FILES] + item: dict[str, Any] = { + "pr_number": row.pr_number, + "title": row.title[:160], + "merged_at": row.merged_at[:10], + "kinds": kinds, + "test_files": tests, + } + if "fix" in kinds: + item["fix_by"] = "title" if _FIX_RE.search(row.title) else "linked_issue" + if "caused_issue" in kinds: + item["caused_issues"] = list(row.tracker["caused"]) + if tests: + item["test_query"] = {"op": "code.test_gate", "args": {"files": tests}} + out.append(item) + return out + + def verdict_of(rows: list[PrRow], *, resolved: bool) -> tuple[str, list[str]]: if not resolved: return UNKNOWN, ["symbol_unresolved"] @@ -259,6 +322,7 @@ def verdict_of(rows: list[PrRow], *, resolved: bool) -> tuple[str, list[str]]: "build_rows", "in_span", "is_fix_title", + "regression_prs", "summarize", "verdict_of", ] diff --git a/tests/unit/test_code_review_brief_sections.py b/tests/unit/test_code_review_brief_sections.py index ca28bdc2b54..7dba55fe4dc 100644 --- a/tests/unit/test_code_review_brief_sections.py +++ b/tests/unit/test_code_review_brief_sections.py @@ -618,6 +618,7 @@ async def __call__(self, op: str, body: dict[str, Any]) -> dict[str, Any]: "open_issues_naming": 0, "last_touched": "2026-09-01", }, + "regression_prs": [{"pr_number": 117000, "kinds": ["fix"]}] if named else [], "tracker_namespace": "", "tracker_unavailable": False, } @@ -813,6 +814,9 @@ async def test_build_assembles_every_section_with_verdicts_and_decisions() -> No assert secs["history"]["verdict"] == "regressions" assert secs["history"]["rows"][0]["qualified_name"] == "DB::MergeTreeData::loadDataParts" assert secs["history"]["rows"][0]["named_fix_prs"] == 1 + # the row that makes `regressions` names the PRs behind its counts; a clean one does not + assert secs["history"]["rows"][0]["regression_prs"] == [{"pr_number": 117000, "kinds": ["fix"]}] + assert "regression_prs" not in secs["history"]["rows"][1] assert {r["qualified_name"] for r in secs["history"]["rows"]} == { "DB::MergeTreeData::loadDataParts", "DB::Settings::dump", diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index 37a80a42e39..2b7413e2505 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -167,6 +167,67 @@ def test_build_rows_marks_touch_from_tracker_and_summarises() -> None: assert "2 open issues name it today" in summary["note"] +def test_regression_prs_name_the_rows_behind_the_counts_strongest_first() -> None: + def row(n: int, title: str, at: str, **kw: Any) -> sh.PrRow: + return sh.PrRow(pr_number=n, title=title, merged_at=f"{at}T10:00:00", **kw) + + rows = [ + # a named fix counted only for closing an issue, newest + row(60, "Speed up the loader", "2026-09-05", is_fix=True, touches_symbol="named"), + # a fix whose diff misses the function adds to no count + row(50, "Fix crash", "2026-09-04", is_fix=True, touches_symbol="false"), + row( + 40, + "Fix crash in load_items", + "2026-09-03", + is_fix=True, + touches_symbol="true", + test_files=["tests/fixtures/items.json", "tests/test_items.py"], + ), + row(30, 'Revert "Load items"', "2026-09-02", is_revert=True, is_fix=True), + row(20, "Load items in parallel", "2026-09-01", tracker={"caused": [100, 101]}), + # a fix that also caused an issue backs two counts: strongest + row( + 10, + "Fix race", + "2026-08-01", + is_fix=True, + touches_symbol="true", + tracker={"caused": [102]}, + ), + ] + out = sh.regression_prs(rows) + assert [e["pr_number"] for e in out] == [10, 40, 60] + assert out[0]["kinds"] == ["fix", "caused_issue"] and out[0]["caused_issues"] == [102] + assert out[0]["fix_by"] == "title" and out[0]["test_files"] == [] + assert "test_query" not in out[0] and out[0]["merged_at"] == "2026-08-01" + # the runnable test before its fixture, and the query that lists how to run them + assert out[1]["test_files"] == ["tests/test_items.py", "tests/fixtures/items.json"] + assert out[1]["test_query"] == {"op": "code.test_gate", "args": {"files": out[1]["test_files"]}} + assert out[2]["fix_by"] == "linked_issue" + # past the cap: the revert, then the PR issues trace back to + rest = sh.regression_prs([r for r in rows if r.pr_number in (30, 20)]) + assert [(e["pr_number"], e["kinds"]) for e in rest] == [ + (30, ["revert"]), + (20, ["caused_issue"]), + ] + assert "fix_by" not in rest[0] and rest[1]["caused_issues"] == [100, 101] + + +def test_build_rows_keep_the_test_files_a_pr_changed() -> None: + rows = sh.build_rows( + [{"pr_number": 1, "title": "t", "files": ["app/items.py", "tests/test_items.py"]}], + issue_facts={}, + comments=[], + span=(1, 2), + tracker_facts={}, + tracker_edges=[], + frames=[], + qa_ok=False, + ) + assert rows[0].test_files == ["tests/test_items.py"] + + def test_without_tracker_rows_stay_file_level_and_the_note_says_so() -> None: rows = sh.build_rows( PRS, @@ -311,6 +372,17 @@ async def test_handler_assembles_loom_and_tracker(wired) -> None: ] assert out.open_issues_naming[0]["number"] == 300 and out.summary["open_issues_naming"] == 1 assert out.summary["reverts"] == 1 and out.summary["last_touched"] == "2026-09-01" + assert [(e["pr_number"], e["kinds"]) for e in out.regression_prs] == [ + (900, ["fix"]), + (850, ["revert"]), + ] + # the evidence reads the whole window, not the `limit` rows served + one = await h.handle_code_symbol_history( + CodeSymbolHistoryInput( + org=ORG, namespace=NS, name="DB::MergeTreeData::loadDataParts", limit=1 + ) + ) + assert len(one.prs) == 1 and one.regression_prs == out.regression_prs @pytest.mark.asyncio From 7d5cb18af052970d9ecc82ece3151be4395c0d79 Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 05:59:10 +0000 Subject: [PATCH 02/13] Order regression test files by the deployment's run recipes too regression_prs reads code_test_gate_run_templates as code.test_gate does, so a repository whose runner only that setting knows lists its tests before their fixtures. The brief copies the op's list as served. Tests cover the four-file cap and an override recipe on a made-up layout. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/features/code-index/history-and-prs.md | 15 +++++---- server/code/api/models_history.py | 2 +- server/code/app/index/review_brief_build.py | 3 +- server/code/app/symbol_history.py | 3 +- server/code/domain/index/symbol_history.py | 7 ++-- tests/unit/test_code_symbol_history.py | 36 +++++++++++++++++++++ 6 files changed, 52 insertions(+), 14 deletions(-) diff --git a/docs/features/code-index/history-and-prs.md b/docs/features/code-index/history-and-prs.md index f1faa318054..77f070db129 100644 --- a/docs/features/code-index/history-and-prs.md +++ b/docs/features/code-index/history-and-prs.md @@ -175,13 +175,14 @@ Its `regression_prs` names up to three PRs behind the summary's `named_fix_prs`, `reverts` and `caused_issues`, read from the whole window whatever `limit` serves. Each carries its title as the one-line cause, its merge date, `kinds` (`fix`, `revert`, `caused_issue` with the issue numbers), and up to four test files it changed, as the PR -ledger lists them, those with a known run recipe first. When it changed a test file, -`test_query` is the `code.test_gate` call that lists how to run them. A PR behind more of -the counts comes first, then a fix before a revert before a PR issues trace back to. A fix -says `fix_by`: `title` when its title says fix, crash, regression and the like, or -`linked_issue` when it is counted only for closing an issue, which a feature or -performance PR does too; a `title` fix ranks first. The record is the PR ledger's, so it -holds for every language the index reads. +ledger lists them, first those `code.test_gate` has a run recipe for (its built-in ones +and `code_test_gate_run_templates`). When it changed a test file, `test_query` is the +`code.test_gate` call that lists how to run them. A PR behind more of the counts comes +first, then a fix before a revert before a PR issues trace back to. A fix says `fix_by`: +`title` when its title says fix, crash, regression and the like, or `linked_issue` when it +is counted only for closing an issue, which a feature or performance PR does too; a +`title` fix ranks first. The record is the PR ledger's, so it holds for every language +the index reads. `code.blame_range` takes a `path`, a line range (at most 400 lines) and a window as release versions (`from_version`, `to_version`) or commit shas. It combines the PR diff --git a/server/code/api/models_history.py b/server/code/api/models_history.py index d221ce8fa58..4ed45c370be 100644 --- a/server/code/api/models_history.py +++ b/server/code/api/models_history.py @@ -622,7 +622,7 @@ class CodeSymbolHistoryOutput(BaseModel): # (date), kinds[] (fix | revert | caused_issue), fix_by (with fix: title, when the # title says fix, crash, regression and the like, or linked_issue, when it only closes # an issue), caused_issues[] (with caused_issue), test_files[] (≤4: the test files the - # PR changed, as the ledger lists them, those with a known run recipe first), + # PR changed, as the ledger lists them, those code.test_gate has a run recipe for first), # test_query ({op: code.test_gate, args: {files}}, only when test_files is not empty)} regression_prs: list[dict[str, Any]] = Field(default_factory=list) # The tracker namespace that answered the QA side; "" when none is bound or diff --git a/server/code/app/index/review_brief_build.py b/server/code/app/index/review_brief_build.py index 1be073fe2cb..9682dbcca30 100644 --- a/server/code/app/index/review_brief_build.py +++ b/server/code/app/index/review_brief_build.py @@ -64,7 +64,6 @@ from server.code.app.symbol.diff import _parse_unified_diff_full, is_blank from server.code.app.symbol.resolve import _parse_file_symbol from server.code.domain.index.epistemic import CAUSE_NEW_SIDE_FAILED, CAUSE_UNMAPPED -from server.code.domain.index.symbol_history import EVIDENCE_PRS from server.code.domain.index.test_gate import is_test_path from server.observability import degradations @@ -952,7 +951,7 @@ async def _history_section( if row["named_fix_prs"] or row["reverts"] or row["caused_issues"]: # the PRs behind the counts that make `regressions`, each with its title # and the test files it changed - row["regression_prs"] = list(res.get("regression_prs") or [])[:EVIDENCE_PRS] + row["regression_prs"] = list(res.get("regression_prs") or []) rows.append(row) # the tracker is bound and its read failed: the issues it traces are unread unavailable += bool(res.get("tracker_unavailable")) diff --git a/server/code/app/symbol_history.py b/server/code/app/symbol_history.py index 0d969f8d46a..72e7348c044 100644 --- a/server/code/app/symbol_history.py +++ b/server/code/app/symbol_history.py @@ -28,6 +28,7 @@ from server.code.store.index import CodeRepo from server.core.errors import ValidationError from server.observability import degradations +from server.settings import settings from server.tracker.domain import bisect as bi logger = logging.getLogger(__name__) @@ -218,7 +219,7 @@ async def handle_code_symbol_history(input: Any) -> Any: review_comments=span_comments, open_issues_naming=[_open_issue_view(r) for r in open_issues[:5]], summary=summary, - regression_prs=sh.regression_prs(rows), + regression_prs=sh.regression_prs(rows, str(settings.code_test_gate_run_templates)), tracker_namespace=tracker_ns, tracker_unavailable=tracker_unavailable, trace_run_id=trace_run_id, diff --git a/server/code/domain/index/symbol_history.py b/server/code/domain/index/symbol_history.py index c05299a062b..7e2cabf99e6 100644 --- a/server/code/domain/index/symbol_history.py +++ b/server/code/domain/index/symbol_history.py @@ -270,13 +270,14 @@ def _evidence_kinds(row: PrRow) -> list[str]: return kinds -def regression_prs(rows: list[PrRow]) -> list[dict[str, Any]]: +def regression_prs(rows: list[PrRow], run_templates: str = "") -> list[dict[str, Any]]: """The PRs behind `named_fix_prs`, `reverts` and `caused_issues`, strongest first: a PR behind more of the counts, then a named fix before a revert before a PR issues trace back to, a fix its title names before one counted only for closing an issue (`fix_by`), then the newest. Each carries its title as the one-line cause and the test files it changed, runnable ones first, with the `code.test_gate` query that - lists how to run them; no query when it changed none.""" + lists how to run them; no query when it changed none. `run_templates` is the + deployment's run recipes, as code.test_gate reads them.""" def strength(rk: tuple[PrRow, list[str]]) -> tuple[int, int, bool]: row, kinds = rk @@ -289,7 +290,7 @@ def strength(rk: tuple[PrRow, list[str]]) -> tuple[int, int, bool]: out: list[dict[str, Any]] = [] for row, kinds in picked[:EVIDENCE_PRS]: # a file with a known run recipe (a test) before one without (its fixture) - tests = sorted(row.test_files, key=lambda p: run_command_for(p)[1]) + tests = sorted(row.test_files, key=lambda p: run_command_for(p, run_templates)[1]) tests = tests[:EVIDENCE_TEST_FILES] item: dict[str, Any] = { "pr_number": row.pr_number, diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index 2b7413e2505..8b9f94b07a1 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -214,6 +214,42 @@ def row(n: int, title: str, at: str, **kw: Any) -> sh.PrRow: assert "fix_by" not in rest[0] and rest[1]["caused_issues"] == [100, 101] +def test_regression_test_files_follow_the_deployments_run_recipes() -> None: + # a layout no built-in recipe knows: ledger order until a run template names the cases + row = sh.PrRow( + pr_number=7, + title="Fix overflow in tally", + merged_at="2026-09-01T00:00:00", + is_fix=True, + touches_symbol="true", + test_files=["spec/tally.expected", "spec/tally.case"], + ) + plain = sh.regression_prs([row]) + assert plain[0]["test_files"] == ["spec/tally.expected", "spec/tally.case"] + recipes = '[{"pattern": "^spec/.+\\\\.case$", "run": "./run-case {path}"}]' + ordered = sh.regression_prs([row], recipes) + assert ordered[0]["test_files"] == ["spec/tally.case", "spec/tally.expected"] + + +def test_regression_prs_keep_four_test_files_runnable_first() -> None: + fixtures = [f"tests/fixtures/case{i}.json" for i in range(4)] + row = sh.PrRow( + pr_number=8, + title="Fix leak in pool", + merged_at="2026-09-01T00:00:00", + is_fix=True, + touches_symbol="true", + test_files=[*fixtures, "tests/test_pool.py", "tests/test_pool_reuse.py"], + ) + out = sh.regression_prs([row])[0] + assert out["test_files"] == [ + "tests/test_pool.py", + "tests/test_pool_reuse.py", + "tests/fixtures/case0.json", + "tests/fixtures/case1.json", + ] + + def test_build_rows_keep_the_test_files_a_pr_changed() -> None: rows = sh.build_rows( [{"pr_number": 1, "title": "t", "files": ["app/items.py", "tests/test_items.py"]}], From e034fd4e0ff0f5d31433d7b93422fdd806d8b290 Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 06:09:20 +0000 Subject: [PATCH 03/13] Name regression tests before fixtures on any layout; one rule for the counts A test file no run recipe knows (a gtest, a JUnit class) now sorts before fixtures that are tests only by their directory, so the four-file cap keeps it. summarize counts named fixes, reverts and caused issues through the same rule regression_prs names them by, and the brief copies whatever the op returned. Test files are picked only for the PRs named. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/features/code-index/history-and-prs.md | 8 ++- server/code/api/models_history.py | 2 +- server/code/app/index/review_brief_build.py | 8 +-- server/code/domain/index/symbol_history.py | 65 ++++++++++++--------- server/code/domain/index/test_gate.py | 6 ++ tests/unit/test_code_symbol_history.py | 52 +++++++++++++++-- 6 files changed, 101 insertions(+), 40 deletions(-) diff --git a/docs/features/code-index/history-and-prs.md b/docs/features/code-index/history-and-prs.md index 77f070db129..b0e1f5ea270 100644 --- a/docs/features/code-index/history-and-prs.md +++ b/docs/features/code-index/history-and-prs.md @@ -175,8 +175,9 @@ Its `regression_prs` names up to three PRs behind the summary's `named_fix_prs`, `reverts` and `caused_issues`, read from the whole window whatever `limit` serves. Each carries its title as the one-line cause, its merge date, `kinds` (`fix`, `revert`, `caused_issue` with the issue numbers), and up to four test files it changed, as the PR -ledger lists them, first those `code.test_gate` has a run recipe for (its built-in ones -and `code_test_gate_run_templates`). When it changed a test file, `test_query` is the +ledger lists them: first those `code.test_gate` has a run recipe for (its built-in ones +and `code_test_gate_run_templates`), then files named as tests before fixtures that are +tests only by their directory. When it changed a test file, `test_query` is the `code.test_gate` call that lists how to run them. A PR behind more of the counts comes first, then a fix before a revert before a PR issues trace back to. A fix says `fix_by`: `title` when its title says fix, crash, regression and the like, or `linked_issue` when it @@ -216,7 +217,8 @@ record by its file and name (`path:symbol`), so a name many files define, such a name such as `(anonymous namespace)::f`, reads the bare name, as does a form past the op's 300-character name bound; a record of another file's definition is `unknown`. A row whose counts make the section `regressions` carries that record's `regression_prs`, -so the brief names the earlier fixes, reverts and culprit PRs with their test files. +so the brief names the earlier fixes, reverts and culprit PRs with their test files; a +brief stored by an earlier build has the counts without it. The answer comes first: `verdict` and `verdict_causes`, read off every section the brief holds, whatever the tier serves, and off `rationale` when this read serves it. A verdict diff --git a/server/code/api/models_history.py b/server/code/api/models_history.py index 4ed45c370be..21725eb1cb3 100644 --- a/server/code/api/models_history.py +++ b/server/code/api/models_history.py @@ -622,7 +622,7 @@ class CodeSymbolHistoryOutput(BaseModel): # (date), kinds[] (fix | revert | caused_issue), fix_by (with fix: title, when the # title says fix, crash, regression and the like, or linked_issue, when it only closes # an issue), caused_issues[] (with caused_issue), test_files[] (≤4: the test files the - # PR changed, as the ledger lists them, those code.test_gate has a run recipe for first), + # PR changed: those code.test_gate has a run recipe for, then those named as tests), # test_query ({op: code.test_gate, args: {files}}, only when test_files is not empty)} regression_prs: list[dict[str, Any]] = Field(default_factory=list) # The tracker namespace that answered the QA side; "" when none is bound or diff --git a/server/code/app/index/review_brief_build.py b/server/code/app/index/review_brief_build.py index 9682dbcca30..11b1eae82cf 100644 --- a/server/code/app/index/review_brief_build.py +++ b/server/code/app/index/review_brief_build.py @@ -948,10 +948,10 @@ async def _history_section( "tracker": not bool(res.get("tracker_unavailable")) and bool(res.get("tracker_namespace")), } - if row["named_fix_prs"] or row["reverts"] or row["caused_issues"]: - # the PRs behind the counts that make `regressions`, each with its title - # and the test files it changed - row["regression_prs"] = list(res.get("regression_prs") or []) + if prs := list(res.get("regression_prs") or []): + # the PRs behind the counts that make `regressions` (the op names none on a + # row without them), each with its title and the test files it changed + row["regression_prs"] = prs rows.append(row) # the tracker is bound and its read failed: the issues it traces are unread unavailable += bool(res.get("tracker_unavailable")) diff --git a/server/code/domain/index/symbol_history.py b/server/code/domain/index/symbol_history.py index 7e2cabf99e6..86c576914a9 100644 --- a/server/code/domain/index/symbol_history.py +++ b/server/code/domain/index/symbol_history.py @@ -17,7 +17,7 @@ from typing import Any from server.code.domain.index.blame_range import sha_text -from server.code.domain.index.test_gate import is_test_path, run_command_for +from server.code.domain.index.test_gate import is_test_named, is_test_path, run_command_for HISTORY = "history" NO_HISTORY = "no_history" @@ -53,8 +53,8 @@ class PrRow: # false (QA diff does not) | unknown touches_symbol: str = "unknown" tracker: dict[str, Any] = field(default_factory=dict) - # the test files among the PR's changed files, as the ledger lists them - test_files: list[str] = field(default_factory=list) + # the PR's changed files, as the ledger lists them + files: list[str] = field(default_factory=list) def as_dict(self) -> dict[str, Any]: out: dict[str, Any] = { @@ -156,7 +156,7 @@ def build_rows( is_backport=bool(_BACKPORT_RE.match(title)), linked_issues=linked, comments_on_symbol=by_pr_comments.get(n, 0), - test_files=[str(f) for f in (r.get("files") or []) if is_test_path(str(f))], + files=[str(f) for f in r.get("files") or []], ) # loom's own function-level hint: the PR's title or description # names the function (a review comment inside the span counts too) @@ -201,9 +201,11 @@ def summarize( touching = [r for r in rows if r.touches_symbol != "false"] named = [r for r in touching if r.touches_symbol in ("true", "named")] fixes = [r for r in touching if r.is_fix and not r.is_revert] - named_fixes = [r for r in named if r.is_fix and not r.is_revert] - reverts = [r for r in touching if r.is_revert] - caused = sorted({i for r in touching for i in (r.tracker.get("caused") or [])}) + # the counts that make `regressions`, by the rule `regression_prs` names them with + kinds = [(r, _evidence_kinds(r)) for r in touching] + named_fixes = [r for r, k in kinds if "fix" in k] + reverts = [r for r, k in kinds if "revert" in k] + caused = sorted({i for r, k in kinds if "caused_issue" in k for i in r.tracker["caused"]}) authors: dict[str, int] = {} for r in touching: if r.author and not r.author.endswith("[bot]") and not r.author.startswith("robot-"): @@ -270,28 +272,37 @@ def _evidence_kinds(row: PrRow) -> list[str]: return kinds +def _fix_by(row: PrRow, kinds: list[str]) -> str: + """How a named fix was recognized: `title` (its title says fix, crash, regression and the + like) or `linked_issue` (it closes an issue, which a feature PR may do too); '' when + the row is no named fix.""" + if "fix" not in kinds: + return "" + return "title" if _FIX_RE.search(row.title) else "linked_issue" + + +def _test_files(row: PrRow, run_templates: str) -> list[str]: + """The PR's test files, those code.test_gate has a run recipe for first, then those + named as tests before fixtures that are tests only by their directory.""" + tests = [f for f in row.files if is_test_path(f)] + tests.sort(key=lambda p: (run_command_for(p, run_templates)[1], not is_test_named(p))) + return tests[:EVIDENCE_TEST_FILES] + + def regression_prs(rows: list[PrRow], run_templates: str = "") -> list[dict[str, Any]]: """The PRs behind `named_fix_prs`, `reverts` and `caused_issues`, strongest first: a PR behind more of the counts, then a named fix before a revert before a PR issues - trace back to, a fix its title names before one counted only for closing an issue - (`fix_by`), then the newest. Each carries its title as the one-line cause and the - test files it changed, runnable ones first, with the `code.test_gate` query that - lists how to run them; no query when it changed none. `run_templates` is the - deployment's run recipes, as code.test_gate reads them.""" - - def strength(rk: tuple[PrRow, list[str]]) -> tuple[int, int, bool]: - row, kinds = rk - by_title = "fix" in kinds and bool(_FIX_RE.search(row.title)) - return -len(kinds), _KIND_ORDER[kinds[0]], not by_title - - picked = [(r, k) for r in rows if (k := _evidence_kinds(r))] - picked.sort(key=lambda rk: rk[0].merged_at, reverse=True) - picked.sort(key=strength) + trace back to, a `title` fix before a `linked_issue` one (`_fix_by`), then the + newest. Each carries its title as the one-line cause and the test files it changed + (`_test_files`), with the `code.test_gate` query that lists how to run them; no query + when it changed none. `run_templates` is the deployment's run recipes, as + code.test_gate reads them.""" + picked = [(r, k, _fix_by(r, k)) for r in rows if (k := _evidence_kinds(r))] + picked.sort(key=lambda p: p[0].merged_at, reverse=True) + picked.sort(key=lambda p: (-len(p[1]), _KIND_ORDER[p[1][0]], p[2] == "linked_issue")) out: list[dict[str, Any]] = [] - for row, kinds in picked[:EVIDENCE_PRS]: - # a file with a known run recipe (a test) before one without (its fixture) - tests = sorted(row.test_files, key=lambda p: run_command_for(p, run_templates)[1]) - tests = tests[:EVIDENCE_TEST_FILES] + for row, kinds, fix_by in picked[:EVIDENCE_PRS]: + tests = _test_files(row, run_templates) item: dict[str, Any] = { "pr_number": row.pr_number, "title": row.title[:160], @@ -299,8 +310,8 @@ def strength(rk: tuple[PrRow, list[str]]) -> tuple[int, int, bool]: "kinds": kinds, "test_files": tests, } - if "fix" in kinds: - item["fix_by"] = "title" if _FIX_RE.search(row.title) else "linked_issue" + if fix_by: + item["fix_by"] = fix_by if "caused_issue" in kinds: item["caused_issues"] = list(row.tracker["caused"]) if tests: diff --git a/server/code/domain/index/test_gate.py b/server/code/domain/index/test_gate.py index 75c7247227e..c7582a954c8 100644 --- a/server/code/domain/index/test_gate.py +++ b/server/code/domain/index/test_gate.py @@ -107,6 +107,12 @@ def is_test_path(path: str) -> bool: return bool(_TEST_DIR_RE.search(p) or _TEST_FILE_RE.search(p)) +def is_test_named(path: str) -> bool: + """A file whose own name marks it a test (test_x.py, x_test.go, XTest.java, + gtest_x.cpp), as against a fixture that is a test path only by its directory.""" + return bool(_TEST_FILE_RE.search((path or "").strip().lstrip("./"))) + + def _stem(path: str) -> str: name = PurePosixPath(path).stem.lower() # 02345_foo_bar.sql -> foo_bar; test_foo -> foo; foo_test -> foo diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index 8b9f94b07a1..fd9799aebc2 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -182,7 +182,7 @@ def row(n: int, title: str, at: str, **kw: Any) -> sh.PrRow: "2026-09-03", is_fix=True, touches_symbol="true", - test_files=["tests/fixtures/items.json", "tests/test_items.py"], + files=["app/items.py", "tests/fixtures/items.json", "tests/test_items.py"], ), row(30, 'Revert "Load items"', "2026-09-02", is_revert=True, is_fix=True), row(20, "Load items in parallel", "2026-09-01", tracker={"caused": [100, 101]}), @@ -222,7 +222,7 @@ def test_regression_test_files_follow_the_deployments_run_recipes() -> None: merged_at="2026-09-01T00:00:00", is_fix=True, touches_symbol="true", - test_files=["spec/tally.expected", "spec/tally.case"], + files=["spec/tally.expected", "spec/tally.case"], ) plain = sh.regression_prs([row]) assert plain[0]["test_files"] == ["spec/tally.expected", "spec/tally.case"] @@ -239,7 +239,7 @@ def test_regression_prs_keep_four_test_files_runnable_first() -> None: merged_at="2026-09-01T00:00:00", is_fix=True, touches_symbol="true", - test_files=[*fixtures, "tests/test_pool.py", "tests/test_pool_reuse.py"], + files=[*fixtures, "tests/test_pool.py", "tests/test_pool_reuse.py"], ) out = sh.regression_prs([row])[0] assert out["test_files"] == [ @@ -250,7 +250,49 @@ def test_regression_prs_keep_four_test_files_runnable_first() -> None: ] -def test_build_rows_keep_the_test_files_a_pr_changed() -> None: +def test_a_layout_without_a_run_recipe_keeps_its_named_tests_before_fixtures() -> None: + # a C++ and a Java layout no built-in recipe runs: the file named as a test survives the cap + def fix(n: int, files: list[str]) -> sh.PrRow: + return sh.PrRow( + pr_number=n, + title="Fix overflow", + merged_at=f"2026-09-0{n}T00:00:00", + is_fix=True, + touches_symbol="true", + files=files, + ) + + data = [f"lib/tests/data/{c}.txt" for c in "abcd"] + java = [f"core/src/test/fixtures/{c}.json" for c in "abcd"] + out = sh.regression_prs( + [ + fix(2, [*data, "lib/tests/gtest_counter.cpp"]), + fix(1, [*java, "core/src/test/java/app/CounterTest.java"]), + ] + ) + assert out[0]["test_files"][0] == "lib/tests/gtest_counter.cpp" + assert out[1]["test_files"][0] == "core/src/test/java/app/CounterTest.java" + assert all(len(e["test_files"]) == 4 for e in out) + + +def test_regression_prs_break_ties_on_the_newest_and_match_the_counts() -> None: + def row(n: int, at: str, touch: str) -> sh.PrRow: + return sh.PrRow( + pr_number=n, title="Fix leak", merged_at=at, is_fix=True, touches_symbol=touch + ) + + rows = [ + row(1, "2026-07-01T00:00:00", "true"), + row(2, "2026-09-01T00:00:00", "named"), + # a fix that touched only the file is no named fix: neither counted nor named + row(3, "2026-10-01T00:00:00", "unknown"), + ] + assert [e["pr_number"] for e in sh.regression_prs(rows)] == [2, 1] + summary = sh.summarize(rows, window_prs=10, open_issues=0, qa_ok=True) + assert summary["named_fix_prs"] == 2 and summary["fix_prs"] == 3 + + +def test_build_rows_keep_the_files_a_pr_changed() -> None: rows = sh.build_rows( [{"pr_number": 1, "title": "t", "files": ["app/items.py", "tests/test_items.py"]}], issue_facts={}, @@ -261,7 +303,7 @@ def test_build_rows_keep_the_test_files_a_pr_changed() -> None: frames=[], qa_ok=False, ) - assert rows[0].test_files == ["tests/test_items.py"] + assert rows[0].files == ["app/items.py", "tests/test_items.py"] def test_without_tracker_rows_stay_file_level_and_the_note_says_so() -> None: From b90a92751685b58233b26c42e63470bce74744ec Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 06:20:18 +0000 Subject: [PATCH 04/13] Rank fixes counted only for an issue last; replayable test_gate arguments A fix counted only for closing an issue now ranks after every revert and culprit PR, so the three-entry cap keeps the stronger evidence. Each entry's test files are now one `test_gate` object, the code.test_gate arguments (org, namespace, files) for the namespace the history was read from, in place of a file list and a query that repeated it. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/features/code-index/history-and-prs.md | 22 +++---- docs/reference/operations/code.md | 2 +- server/code/api/models_history.py | 14 +++-- server/code/app/symbol_history.py | 4 +- server/code/domain/index/symbol_history.py | 22 +++---- tests/unit/test_code_symbol_history.py | 64 ++++++++++++--------- 6 files changed, 71 insertions(+), 57 deletions(-) diff --git a/docs/features/code-index/history-and-prs.md b/docs/features/code-index/history-and-prs.md index b0e1f5ea270..4d233a53799 100644 --- a/docs/features/code-index/history-and-prs.md +++ b/docs/features/code-index/history-and-prs.md @@ -173,17 +173,17 @@ answers in one page of up to `limit` PRs and refuses `offset`. touched its span, their linked issues and reverts, and the review comments inside it. Its `regression_prs` names up to three PRs behind the summary's `named_fix_prs`, `reverts` and `caused_issues`, read from the whole window whatever `limit` serves. Each -carries its title as the one-line cause, its merge date, `kinds` (`fix`, `revert`, -`caused_issue` with the issue numbers), and up to four test files it changed, as the PR -ledger lists them: first those `code.test_gate` has a run recipe for (its built-in ones -and `code_test_gate_run_templates`), then files named as tests before fixtures that are -tests only by their directory. When it changed a test file, `test_query` is the -`code.test_gate` call that lists how to run them. A PR behind more of the counts comes -first, then a fix before a revert before a PR issues trace back to. A fix says `fix_by`: -`title` when its title says fix, crash, regression and the like, or `linked_issue` when it -is counted only for closing an issue, which a feature or performance PR does too; a -`title` fix ranks first. The record is the PR ledger's, so it holds for every language -the index reads. +carries its title as the one-line cause, its merge date and `kinds` (`fix`, `revert`, +`caused_issue` with the issue numbers). A fix says `fix_by`: `title` when its title says +fix, crash, regression and the like, or `linked_issue` when it is counted only for closing +an issue, which a feature or performance PR does too. A PR behind more of the counts comes +first, then every entry before a `linked_issue` fix, then a fix before a revert before a +PR issues trace back to, then the newest. When the PR changed test files, `test_gate` holds +the `code.test_gate` arguments (`org`, `namespace`, `files`) that list how to run up to +four of them in the namespace the history was read from: first those `code.test_gate` has +a run recipe for (its built-in ones and `code_test_gate_run_templates`), then files named +as tests, then fixtures that are tests only by their directory. The record is the PR +ledger's, so it holds for every language the index reads. `code.blame_range` takes a `path`, a line range (at most 400 lines) and a window as release versions (`from_version`, `to_version`) or commit shas. It combines the PR diff --git a/docs/reference/operations/code.md b/docs/reference/operations/code.md index acd0c23cd58..8ca448ee4ca 100644 --- a/docs/reference/operations/code.md +++ b/docs/reference/operations/code.md @@ -1730,7 +1730,7 @@ The regression history of one function: the merged PRs that touched it (with lin | `review_comments` | `list[dict[str, Any]]` | inline review comments inside the symbol's span, newest first (≤5) | | `open_issues_naming` | `list[dict[str, Any]]` | open issues whose text names the function (QA), most severe first (≤5) | | `summary` | `dict[str, Any]` | {prs_total, named_prs, fix_prs, named_fix_prs, reverts, caused_issues[], open_issues_naming, last_touched, oldest_in_window, authors[], note} | -| `regression_prs` | `list[dict[str, Any]]` | The PRs behind the summary's named_fix_prs, reverts and caused_issues, from the whole window whatever `limit` serves, strongest first (≤3): {pr_number, title, merged_at (date), kinds[] (fix \| revert \| caused_issue), fix_by (with fix: title… | +| `regression_prs` | `list[dict[str, Any]]` | The PRs behind the summary's named_fix_prs, reverts and caused_issues, from the whole window whatever `limit` serves, strongest first (≤3; a fix counted only for closing an issue last): {pr_number, title, merged_at (date), kinds[] (fix \|… | | `tracker_namespace` | `str` | The tracker namespace that answered the QA side; "" when none is bound or its read failed. | | `tracker_unavailable` | `bool` | True when a tracker is bound but its read failed. | | `trace_run_id` | `str` | Id of this call's trace row; pass it to `code.outcome`. | diff --git a/server/code/api/models_history.py b/server/code/api/models_history.py index 21725eb1cb3..ad473050cf6 100644 --- a/server/code/api/models_history.py +++ b/server/code/api/models_history.py @@ -618,12 +618,14 @@ class CodeSymbolHistoryOutput(BaseModel): # open_issues_naming, last_touched, oldest_in_window, authors[], note} summary: dict[str, Any] = Field(default_factory=dict) # The PRs behind the summary's named_fix_prs, reverts and caused_issues, from the whole - # window whatever `limit` serves, strongest first (≤3): {pr_number, title, merged_at - # (date), kinds[] (fix | revert | caused_issue), fix_by (with fix: title, when the - # title says fix, crash, regression and the like, or linked_issue, when it only closes - # an issue), caused_issues[] (with caused_issue), test_files[] (≤4: the test files the - # PR changed: those code.test_gate has a run recipe for, then those named as tests), - # test_query ({op: code.test_gate, args: {files}}, only when test_files is not empty)} + # window whatever `limit` serves, strongest first (≤3; a fix counted only for closing an + # issue last): {pr_number, title, merged_at (date), kinds[] (fix | revert | + # caused_issue), fix_by (with fix: title, when the title says fix, crash, regression and + # the like, or linked_issue, when it only closes an issue), caused_issues[] (with + # caused_issue), test_gate (only when the PR changed test files: the code.test_gate + # arguments {org, namespace, files} that list how to run them, files ≤4 as the ledger + # lists them: those code.test_gate has a run recipe for, then those named as tests, + # then fixtures under a test directory)} regression_prs: list[dict[str, Any]] = Field(default_factory=list) # The tracker namespace that answered the QA side; "" when none is bound or # its read failed. diff --git a/server/code/app/symbol_history.py b/server/code/app/symbol_history.py index 72e7348c044..abcfd69c5a1 100644 --- a/server/code/app/symbol_history.py +++ b/server/code/app/symbol_history.py @@ -219,7 +219,9 @@ async def handle_code_symbol_history(input: Any) -> Any: review_comments=span_comments, open_issues_naming=[_open_issue_view(r) for r in open_issues[:5]], summary=summary, - regression_prs=sh.regression_prs(rows, str(settings.code_test_gate_run_templates)), + regression_prs=sh.regression_prs( + rows, org=org, namespace=ns, run_templates=str(settings.code_test_gate_run_templates) + ), tracker_namespace=tracker_ns, tracker_unavailable=tracker_unavailable, trace_run_id=trace_run_id, diff --git a/server/code/domain/index/symbol_history.py b/server/code/domain/index/symbol_history.py index 86c576914a9..a9b327b1d3e 100644 --- a/server/code/domain/index/symbol_history.py +++ b/server/code/domain/index/symbol_history.py @@ -289,33 +289,33 @@ def _test_files(row: PrRow, run_templates: str) -> list[str]: return tests[:EVIDENCE_TEST_FILES] -def regression_prs(rows: list[PrRow], run_templates: str = "") -> list[dict[str, Any]]: +def regression_prs( + rows: list[PrRow], *, org: str, namespace: str, run_templates: str = "" +) -> list[dict[str, Any]]: """The PRs behind `named_fix_prs`, `reverts` and `caused_issues`, strongest first: a - PR behind more of the counts, then a named fix before a revert before a PR issues - trace back to, a `title` fix before a `linked_issue` one (`_fix_by`), then the - newest. Each carries its title as the one-line cause and the test files it changed - (`_test_files`), with the `code.test_gate` query that lists how to run them; no query - when it changed none. `run_templates` is the deployment's run recipes, as + PR behind more of the counts, then any of them before a fix counted only for closing + an issue (`_fix_by`), then a named fix before a revert before a PR issues trace back + to, then the newest. Each carries its title as the one-line cause and, when it + changed test files (`_test_files`), the `code.test_gate` arguments that list how to + run them in this namespace. `run_templates` is the deployment's run recipes, as code.test_gate reads them.""" picked = [(r, k, _fix_by(r, k)) for r in rows if (k := _evidence_kinds(r))] picked.sort(key=lambda p: p[0].merged_at, reverse=True) - picked.sort(key=lambda p: (-len(p[1]), _KIND_ORDER[p[1][0]], p[2] == "linked_issue")) + picked.sort(key=lambda p: (-len(p[1]), p[2] == "linked_issue", _KIND_ORDER[p[1][0]])) out: list[dict[str, Any]] = [] for row, kinds, fix_by in picked[:EVIDENCE_PRS]: - tests = _test_files(row, run_templates) item: dict[str, Any] = { "pr_number": row.pr_number, "title": row.title[:160], "merged_at": row.merged_at[:10], "kinds": kinds, - "test_files": tests, } if fix_by: item["fix_by"] = fix_by if "caused_issue" in kinds: item["caused_issues"] = list(row.tracker["caused"]) - if tests: - item["test_query"] = {"op": "code.test_gate", "args": {"files": tests}} + if tests := _test_files(row, run_templates): + item["test_gate"] = {"org": org, "namespace": namespace, "files": tests} out.append(item) return out diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index fd9799aebc2..323b8a0ad2b 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -39,7 +39,7 @@ "merged_at": datetime(2026, 9, 1), "linked_issues": [100], "is_revert": False, - "files": [PATH], + "files": [PATH, "tests/test_parts_loading.py"], }, { "pr_number": 850, @@ -167,6 +167,10 @@ def test_build_rows_marks_touch_from_tracker_and_summarises() -> None: assert "2 open issues name it today" in summary["note"] +def _evidence(rows: list[sh.PrRow], **kw: Any) -> list[dict[str, Any]]: + return sh.regression_prs(rows, org="acme", namespace="code-shop", **kw) + + def test_regression_prs_name_the_rows_behind_the_counts_strongest_first() -> None: def row(n: int, title: str, at: str, **kw: Any) -> sh.PrRow: return sh.PrRow(pr_number=n, title=title, merged_at=f"{at}T10:00:00", **kw) @@ -196,22 +200,22 @@ def row(n: int, title: str, at: str, **kw: Any) -> sh.PrRow: tracker={"caused": [102]}, ), ] - out = sh.regression_prs(rows) - assert [e["pr_number"] for e in out] == [10, 40, 60] + out = _evidence(rows) + assert [e["pr_number"] for e in out] == [10, 40, 30] assert out[0]["kinds"] == ["fix", "caused_issue"] and out[0]["caused_issues"] == [102] - assert out[0]["fix_by"] == "title" and out[0]["test_files"] == [] - assert "test_query" not in out[0] and out[0]["merged_at"] == "2026-08-01" - # the runnable test before its fixture, and the query that lists how to run them - assert out[1]["test_files"] == ["tests/test_items.py", "tests/fixtures/items.json"] - assert out[1]["test_query"] == {"op": "code.test_gate", "args": {"files": out[1]["test_files"]}} - assert out[2]["fix_by"] == "linked_issue" - # past the cap: the revert, then the PR issues trace back to - rest = sh.regression_prs([r for r in rows if r.pr_number in (30, 20)]) - assert [(e["pr_number"], e["kinds"]) for e in rest] == [ - (30, ["revert"]), - (20, ["caused_issue"]), - ] - assert "fix_by" not in rest[0] and rest[1]["caused_issues"] == [100, 101] + assert out[0]["fix_by"] == "title" and "test_gate" not in out[0] + assert out[0]["merged_at"] == "2026-08-01" + # the runnable test before its fixture, as code.test_gate arguments in this namespace + assert out[1]["test_gate"] == { + "org": "acme", + "namespace": "code-shop", + "files": ["tests/test_items.py", "tests/fixtures/items.json"], + } + assert out[2]["kinds"] == ["revert"] and "fix_by" not in out[2] + # past the cap: the PR issues trace back to before a fix counted only for an issue + rest = _evidence([r for r in rows if r.pr_number in (60, 20)]) + assert [(e["pr_number"], e.get("fix_by")) for e in rest] == [(20, None), (60, "linked_issue")] + assert rest[0]["caused_issues"] == [100, 101] def test_regression_test_files_follow_the_deployments_run_recipes() -> None: @@ -224,11 +228,11 @@ def test_regression_test_files_follow_the_deployments_run_recipes() -> None: touches_symbol="true", files=["spec/tally.expected", "spec/tally.case"], ) - plain = sh.regression_prs([row]) - assert plain[0]["test_files"] == ["spec/tally.expected", "spec/tally.case"] + plain = _evidence([row]) + assert plain[0]["test_gate"]["files"] == ["spec/tally.expected", "spec/tally.case"] recipes = '[{"pattern": "^spec/.+\\\\.case$", "run": "./run-case {path}"}]' - ordered = sh.regression_prs([row], recipes) - assert ordered[0]["test_files"] == ["spec/tally.case", "spec/tally.expected"] + ordered = _evidence([row], run_templates=recipes) + assert ordered[0]["test_gate"]["files"] == ["spec/tally.case", "spec/tally.expected"] def test_regression_prs_keep_four_test_files_runnable_first() -> None: @@ -241,8 +245,8 @@ def test_regression_prs_keep_four_test_files_runnable_first() -> None: touches_symbol="true", files=[*fixtures, "tests/test_pool.py", "tests/test_pool_reuse.py"], ) - out = sh.regression_prs([row])[0] - assert out["test_files"] == [ + out = _evidence([row])[0] + assert out["test_gate"]["files"] == [ "tests/test_pool.py", "tests/test_pool_reuse.py", "tests/fixtures/case0.json", @@ -264,15 +268,15 @@ def fix(n: int, files: list[str]) -> sh.PrRow: data = [f"lib/tests/data/{c}.txt" for c in "abcd"] java = [f"core/src/test/fixtures/{c}.json" for c in "abcd"] - out = sh.regression_prs( + out = _evidence( [ fix(2, [*data, "lib/tests/gtest_counter.cpp"]), fix(1, [*java, "core/src/test/java/app/CounterTest.java"]), ] ) - assert out[0]["test_files"][0] == "lib/tests/gtest_counter.cpp" - assert out[1]["test_files"][0] == "core/src/test/java/app/CounterTest.java" - assert all(len(e["test_files"]) == 4 for e in out) + assert out[0]["test_gate"]["files"][0] == "lib/tests/gtest_counter.cpp" + assert out[1]["test_gate"]["files"][0] == "core/src/test/java/app/CounterTest.java" + assert all(len(e["test_gate"]["files"]) == 4 for e in out) def test_regression_prs_break_ties_on_the_newest_and_match_the_counts() -> None: @@ -287,7 +291,7 @@ def row(n: int, at: str, touch: str) -> sh.PrRow: # a fix that touched only the file is no named fix: neither counted nor named row(3, "2026-10-01T00:00:00", "unknown"), ] - assert [e["pr_number"] for e in sh.regression_prs(rows)] == [2, 1] + assert [e["pr_number"] for e in _evidence(rows)] == [2, 1] summary = sh.summarize(rows, window_prs=10, open_issues=0, qa_ok=True) assert summary["named_fix_prs"] == 2 and summary["fix_prs"] == 3 @@ -454,6 +458,12 @@ async def test_handler_assembles_loom_and_tracker(wired) -> None: (900, ["fix"]), (850, ["revert"]), ] + # replayable on the namespace the history was read from + assert out.regression_prs[0]["test_gate"] == { + "org": ORG, + "namespace": NS, + "files": ["tests/test_parts_loading.py"], + } # the evidence reads the whole window, not the `limit` rows served one = await h.handle_code_symbol_history( CodeSymbolHistoryInput( From ebaaab83951fafe29479cfd43f4cd6441c583174 Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 06:25:59 +0000 Subject: [PATCH 05/13] One test-path normalisation; assert reverts and caused issues match their entries Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- server/code/domain/index/test_gate.py | 4 +--- tests/unit/test_code_symbol_history.py | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/code/domain/index/test_gate.py b/server/code/domain/index/test_gate.py index c7582a954c8..11280d612bc 100644 --- a/server/code/domain/index/test_gate.py +++ b/server/code/domain/index/test_gate.py @@ -102,9 +102,7 @@ def is_test_path(path: str) -> bool: tests/, test/ or spec/, or a test-named file. Fixture and data files under tests/ count too — a changed fixture is still something to re-run against.""" p = (path or "").strip().lstrip("./") - if not p: - return False - return bool(_TEST_DIR_RE.search(p) or _TEST_FILE_RE.search(p)) + return bool(p) and (bool(_TEST_DIR_RE.search(p)) or is_test_named(p)) def is_test_named(path: str) -> bool: diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index 323b8a0ad2b..26a7ffae6b3 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -216,6 +216,10 @@ def row(n: int, title: str, at: str, **kw: Any) -> sh.PrRow: rest = _evidence([r for r in rows if r.pr_number in (60, 20)]) assert [(e["pr_number"], e.get("fix_by")) for e in rest] == [(20, None), (60, "linked_issue")] assert rest[0]["caused_issues"] == [100, 101] + # the entries and the counts come from one rule + summary = sh.summarize(rows, window_prs=10, open_issues=0, qa_ok=True) + assert summary["named_fix_prs"] == 3 and summary["reverts"] == 1 + assert summary["caused_issues"] == [100, 101, 102] def test_regression_test_files_follow_the_deployments_run_recipes() -> None: From 6d78eb3f823a504f58fec2eb6258fde0d783f9c3 Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 06:44:06 +0000 Subject: [PATCH 06/13] A brief leaves out the issues a restricted tracker traces back to a PR A stored brief is read by every viewer of the code namespace. When a history record's tracker namespace is restricted, or its classification cannot be read, the brief's copy of regression_prs drops the caused_issue kind and its issue numbers, and an entry with no kind left, as the brief's qa section leaves that tracker out. The field comment states the order as the code sorts it. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/features/code-index/history-and-prs.md | 5 ++- docs/reference/operations/code.md | 2 +- server/code/api/models_history.py | 17 ++++---- server/code/app/index/review_brief_build.py | 39 ++++++++++++++++- tests/unit/test_code_review_brief_sections.py | 43 +++++++++++++++++++ tests/unit/test_code_symbol_history.py | 15 +++++++ 6 files changed, 110 insertions(+), 11 deletions(-) diff --git a/docs/features/code-index/history-and-prs.md b/docs/features/code-index/history-and-prs.md index 4d233a53799..34c19e24cca 100644 --- a/docs/features/code-index/history-and-prs.md +++ b/docs/features/code-index/history-and-prs.md @@ -218,7 +218,10 @@ name such as `(anonymous namespace)::f`, reads the bare name, as does a form pas op's 300-character name bound; a record of another file's definition is `unknown`. A row whose counts make the section `regressions` carries that record's `regression_prs`, so the brief names the earlier fixes, reverts and culprit PRs with their test files; a -brief stored by an earlier build has the counts without it. +brief stored by an earlier build has the counts without it. When the record's tracker +namespace is restricted, or its classification cannot be read, the brief leaves out the +issues that tracker traces back to a PR, as it leaves out its `qa` section, and an entry +that only names such a PR. The answer comes first: `verdict` and `verdict_causes`, read off every section the brief holds, whatever the tier serves, and off `rationale` when this read serves it. A verdict diff --git a/docs/reference/operations/code.md b/docs/reference/operations/code.md index 8ca448ee4ca..23bf6478e55 100644 --- a/docs/reference/operations/code.md +++ b/docs/reference/operations/code.md @@ -1730,7 +1730,7 @@ The regression history of one function: the merged PRs that touched it (with lin | `review_comments` | `list[dict[str, Any]]` | inline review comments inside the symbol's span, newest first (≤5) | | `open_issues_naming` | `list[dict[str, Any]]` | open issues whose text names the function (QA), most severe first (≤5) | | `summary` | `dict[str, Any]` | {prs_total, named_prs, fix_prs, named_fix_prs, reverts, caused_issues[], open_issues_naming, last_touched, oldest_in_window, authors[], note} | -| `regression_prs` | `list[dict[str, Any]]` | The PRs behind the summary's named_fix_prs, reverts and caused_issues, from the whole window whatever `limit` serves, strongest first (≤3; a fix counted only for closing an issue last): {pr_number, title, merged_at (date), kinds[] (fix \|… | +| `regression_prs` | `list[dict[str, Any]]` | The PRs behind the summary's named_fix_prs, reverts and caused_issues, from the whole window whatever `limit` serves, strongest first (≤3): behind more of the counts, then a fix counted only for closing an issue after the rest, then fix… | | `tracker_namespace` | `str` | The tracker namespace that answered the QA side; "" when none is bound or its read failed. | | `tracker_unavailable` | `bool` | True when a tracker is bound but its read failed. | | `trace_run_id` | `str` | Id of this call's trace row; pass it to `code.outcome`. | diff --git a/server/code/api/models_history.py b/server/code/api/models_history.py index ad473050cf6..5b96fcba0bc 100644 --- a/server/code/api/models_history.py +++ b/server/code/api/models_history.py @@ -618,14 +618,15 @@ class CodeSymbolHistoryOutput(BaseModel): # open_issues_naming, last_touched, oldest_in_window, authors[], note} summary: dict[str, Any] = Field(default_factory=dict) # The PRs behind the summary's named_fix_prs, reverts and caused_issues, from the whole - # window whatever `limit` serves, strongest first (≤3; a fix counted only for closing an - # issue last): {pr_number, title, merged_at (date), kinds[] (fix | revert | - # caused_issue), fix_by (with fix: title, when the title says fix, crash, regression and - # the like, or linked_issue, when it only closes an issue), caused_issues[] (with - # caused_issue), test_gate (only when the PR changed test files: the code.test_gate - # arguments {org, namespace, files} that list how to run them, files ≤4 as the ledger - # lists them: those code.test_gate has a run recipe for, then those named as tests, - # then fixtures under a test directory)} + # window whatever `limit` serves, strongest first (≤3): behind more of the counts, then + # a fix counted only for closing an issue after the rest, then fix, revert, + # caused_issue, then the newest. {pr_number, title, merged_at (date), kinds[] (fix | + # revert | caused_issue), fix_by (with fix: title, when the title says fix, crash, + # regression and the like, or linked_issue, when it only closes an issue), + # caused_issues[] (with caused_issue), test_gate (only when the PR changed test files: + # the code.test_gate arguments {org, namespace, files} that list how to run them, + # files ≤4 of the ledger's test paths: those code.test_gate has a run recipe for, then + # those named as tests, then fixtures under a test directory)} regression_prs: list[dict[str, Any]] = Field(default_factory=list) # The tracker namespace that answered the QA side; "" when none is bound or # its read failed. diff --git a/server/code/app/index/review_brief_build.py b/server/code/app/index/review_brief_build.py index 11b1eae82cf..732f6f7a193 100644 --- a/server/code/app/index/review_brief_build.py +++ b/server/code/app/index/review_brief_build.py @@ -894,6 +894,39 @@ def _history_name(name: str, path: str) -> str: return form if carried else name +async def _restricted_trackers(org: str, results: list[Any]) -> set[str]: + """The tracker namespaces among the history answers that are restricted, or whose + classification could not be read: as the brief's `qa` section, none of their rows + enter a brief, which every viewer of the code namespace reads once stored.""" + from server.auth.directory import ClassificationUnavailable + from server.identity.app.namespace_classification import is_restricted + + names = { + str(r.get("tracker_namespace") or "") + for r in results + if not isinstance(r, BaseException) and r.get("regression_prs") + } - {""} + closed: set[str] = set() + for ns in names: + try: + if await is_restricted(org, ns): + closed.add(ns) + except ClassificationUnavailable: + closed.add(ns) + return closed + + +def _without_tracker_kinds(prs: list[dict[str, Any]]) -> list[dict[str, Any]]: + """The entries less what only the tracker says: the issues traced back to a PR. An + entry left with no kind is dropped.""" + out: list[dict[str, Any]] = [] + for e in prs: + kinds = [k for k in e.get("kinds") or [] if k != "caused_issue"] + if kinds: + out.append({**{k: v for k, v in e.items() if k != "caused_issues"}, "kinds": kinds}) + return out + + async def _history_section( call: CallOp, inp: BriefInputs, defs: list[tuple[str, str]] ) -> dict[str, Any]: @@ -922,6 +955,7 @@ async def _history_section( causes: list[str] = [] unavailable = 0 left = 0 # functions an op refused to read: a cap + closed = await _restricted_trackers(inp.org, results) for (name, path), res in zip(defs, results, strict=True): if isinstance(res, BaseException): if refused(res): @@ -948,7 +982,10 @@ async def _history_section( "tracker": not bool(res.get("tracker_unavailable")) and bool(res.get("tracker_namespace")), } - if prs := list(res.get("regression_prs") or []): + prs = list(res.get("regression_prs") or []) + if prs and str(res.get("tracker_namespace") or "") in closed: + prs = _without_tracker_kinds(prs) + if prs: # the PRs behind the counts that make `regressions` (the op names none on a # row without them), each with its title and the test files it changed row["regression_prs"] = prs diff --git a/tests/unit/test_code_review_brief_sections.py b/tests/unit/test_code_review_brief_sections.py index 7dba55fe4dc..2a72f97acca 100644 --- a/tests/unit/test_code_review_brief_sections.py +++ b/tests/unit/test_code_review_brief_sections.py @@ -3617,3 +3617,46 @@ async def down(*a: Any) -> Any: assert degradations.current() == ["code.review_brief: reviewers_unread (TimeoutError)"] assert payload["provenance"]["tracker"] == rb.FAILED assert payload["stored"] is False and repo.inserted == [] + + +@pytest.mark.asyncio +@pytest.mark.parametrize("binding", ["open", "restricted", "unclassified"]) +async def test_history_rows_name_a_restricted_trackers_culprits_to_no_one( + monkeypatch: pytest.MonkeyPatch, binding: str +) -> None: + """A stored brief is read by every viewer of the code namespace, so the issues a + restricted tracker (or one whose classification is unread) traces back to a PR stay + out of its rows, as out of its `qa` section; the ledger's fixes and reverts stay.""" + import server.identity.app.namespace_classification as nc + from server.auth.directory import ClassificationUnavailable + + async def is_restricted(org: str, ns: str) -> bool: + if binding == "unclassified": + raise ClassificationUnavailable("directory unread") + return binding == "restricted" + + monkeypatch.setattr(nc, "is_restricted", is_restricted) + evidence = [ + {"pr_number": 3, "kinds": ["fix", "caused_issue"], "caused_issues": [9]}, + {"pr_number": 2, "kinds": ["revert"]}, + {"pr_number": 1, "kinds": ["caused_issue"], "caused_issues": [8]}, + ] + + async def call(op: str, body: dict[str, Any]) -> dict[str, Any]: + return { + "verdict": "history", + "symbol": {"path": "app/counter.py"}, + "summary": {"named_fix_prs": 1, "reverts": 1, "caused_issues": [8, 9]}, + "regression_prs": evidence, + "tracker_namespace": "tracker-shop", + } + + hist = await review_brief_build._history_section( + call, _inputs(), [("app.counter::bump", "app/counter.py")] + ) + assert hist["verdict"] == "regressions" + served = hist["rows"][0]["regression_prs"] + if binding == "open": + assert served == evidence + else: + assert served == [{"pr_number": 3, "kinds": ["fix"]}, {"pr_number": 2, "kinds": ["revert"]}] diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index 26a7ffae6b3..7c11db32c42 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -216,6 +216,21 @@ def row(n: int, title: str, at: str, **kw: Any) -> sh.PrRow: rest = _evidence([r for r in rows if r.pr_number in (60, 20)]) assert [(e["pr_number"], e.get("fix_by")) for e in rest] == [(20, None), (60, "linked_issue")] assert rest[0]["caused_issues"] == [100, 101] + # more counts first: a fix counted only for an issue that also caused one leads + both = sh.PrRow( + pr_number=5, + title="Speed up the loader", + merged_at="2026-01-01T00:00:00", + is_fix=True, + touches_symbol="named", + tracker={"caused": [103]}, + ) + lead = _evidence([both, *[r for r in rows if r.pr_number in (40, 30)]]) + assert [(e["pr_number"], e.get("fix_by")) for e in lead] == [ + (5, "linked_issue"), + (40, "title"), + (30, None), + ] # the entries and the counts come from one rule summary = sh.summarize(rows, window_prs=10, open_issues=0, qa_ok=True) assert summary["named_fix_prs"] == 3 and summary["reverts"] == 1 From 4b62563ea867ccc78c013564885dc0c945e52056 Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 06:52:42 +0000 Subject: [PATCH 07/13] A brief names no regression PR read through a restricted tracker A fix entry can rest on the tracker alone (its diff match or a fixes link), so filtering kinds left tracker facts in a stored brief and broke the cap and order. When the records' tracker namespace is restricted or unclassified the brief keeps the counts and carries no regression_prs. The docs say a listed test path may since be gone. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/features/code-index/history-and-prs.md | 12 ++--- server/code/api/models_history.py | 3 +- server/code/app/index/review_brief_build.py | 53 ++++++++----------- tests/unit/test_code_review_brief_sections.py | 17 +++--- 4 files changed, 38 insertions(+), 47 deletions(-) diff --git a/docs/features/code-index/history-and-prs.md b/docs/features/code-index/history-and-prs.md index 34c19e24cca..918aef2122a 100644 --- a/docs/features/code-index/history-and-prs.md +++ b/docs/features/code-index/history-and-prs.md @@ -182,8 +182,9 @@ PR issues trace back to, then the newest. When the PR changed test files, `test_ the `code.test_gate` arguments (`org`, `namespace`, `files`) that list how to run up to four of them in the namespace the history was read from: first those `code.test_gate` has a run recipe for (its built-in ones and `code_test_gate_run_templates`), then files named -as tests, then fixtures that are tests only by their directory. The record is the PR -ledger's, so it holds for every language the index reads. +as tests, then fixtures that are tests only by their directory. They are the paths the +ledger lists for the PR, so one it deleted or a later PR renamed may be gone. The record +is the PR ledger's, so it holds for every language the index reads. `code.blame_range` takes a `path`, a line range (at most 400 lines) and a window as release versions (`from_version`, `to_version`) or commit shas. It combines the PR @@ -218,10 +219,9 @@ name such as `(anonymous namespace)::f`, reads the bare name, as does a form pas op's 300-character name bound; a record of another file's definition is `unknown`. A row whose counts make the section `regressions` carries that record's `regression_prs`, so the brief names the earlier fixes, reverts and culprit PRs with their test files; a -brief stored by an earlier build has the counts without it. When the record's tracker -namespace is restricted, or its classification cannot be read, the brief leaves out the -issues that tracker traces back to a PR, as it leaves out its `qa` section, and an entry -that only names such a PR. +brief stored by an earlier build has the counts without it. When the records' tracker +namespace is restricted, or its classification cannot be read, the brief carries the +counts without `regression_prs`, as it leaves that tracker out of its `qa` section. The answer comes first: `verdict` and `verdict_causes`, read off every section the brief holds, whatever the tier serves, and off `rationale` when this read serves it. A verdict diff --git a/server/code/api/models_history.py b/server/code/api/models_history.py index 5b96fcba0bc..0cb020a2564 100644 --- a/server/code/api/models_history.py +++ b/server/code/api/models_history.py @@ -626,7 +626,8 @@ class CodeSymbolHistoryOutput(BaseModel): # caused_issues[] (with caused_issue), test_gate (only when the PR changed test files: # the code.test_gate arguments {org, namespace, files} that list how to run them, # files ≤4 of the ledger's test paths: those code.test_gate has a run recipe for, then - # those named as tests, then fixtures under a test directory)} + # those named as tests, then fixtures under a test directory; a path the PR deleted + # or a later PR renamed may be gone)} regression_prs: list[dict[str, Any]] = Field(default_factory=list) # The tracker namespace that answered the QA side; "" when none is bound or # its read failed. diff --git a/server/code/app/index/review_brief_build.py b/server/code/app/index/review_brief_build.py index 732f6f7a193..2d43b73fc40 100644 --- a/server/code/app/index/review_brief_build.py +++ b/server/code/app/index/review_brief_build.py @@ -894,37 +894,27 @@ def _history_name(name: str, path: str) -> str: return form if carried else name -async def _restricted_trackers(org: str, results: list[Any]) -> set[str]: - """The tracker namespaces among the history answers that are restricted, or whose - classification could not be read: as the brief's `qa` section, none of their rows - enter a brief, which every viewer of the code namespace reads once stored.""" +async def _tracker_closed(org: str, results: list[Any]) -> bool: + """Whether the tracker namespace the history records read from is restricted, or its + classification could not be read. A stored brief is read by every viewer of the code + namespace, so as for the `qa` section, none of that tracker's rows may enter it.""" from server.auth.directory import ClassificationUnavailable from server.identity.app.namespace_classification import is_restricted - names = { - str(r.get("tracker_namespace") or "") - for r in results - if not isinstance(r, BaseException) and r.get("regression_prs") - } - {""} - closed: set[str] = set() - for ns in names: - try: - if await is_restricted(org, ns): - closed.add(ns) - except ClassificationUnavailable: - closed.add(ns) - return closed - - -def _without_tracker_kinds(prs: list[dict[str, Any]]) -> list[dict[str, Any]]: - """The entries less what only the tracker says: the issues traced back to a PR. An - entry left with no kind is dropped.""" - out: list[dict[str, Any]] = [] - for e in prs: - kinds = [k for k in e.get("kinds") or [] if k != "caused_issue"] - if kinds: - out.append({**{k: v for k, v in e.items() if k != "caused_issues"}, "kinds": kinds}) - return out + tracker = next( + ( + str(r.get("tracker_namespace") or "") + for r in results + if not isinstance(r, BaseException) and r.get("regression_prs") + ), + "", + ) + if not tracker: + return False + try: + return await is_restricted(org, tracker) + except ClassificationUnavailable: + return True async def _history_section( @@ -955,7 +945,8 @@ async def _history_section( causes: list[str] = [] unavailable = 0 left = 0 # functions an op refused to read: a cap - closed = await _restricted_trackers(inp.org, results) + # every record reads the one tracker bound to the code namespace + closed = await _tracker_closed(inp.org, results) for (name, path), res in zip(defs, results, strict=True): if isinstance(res, BaseException): if refused(res): @@ -982,9 +973,7 @@ async def _history_section( "tracker": not bool(res.get("tracker_unavailable")) and bool(res.get("tracker_namespace")), } - prs = list(res.get("regression_prs") or []) - if prs and str(res.get("tracker_namespace") or "") in closed: - prs = _without_tracker_kinds(prs) + prs = [] if closed else list(res.get("regression_prs") or []) if prs: # the PRs behind the counts that make `regressions` (the op names none on a # row without them), each with its title and the test files it changed diff --git a/tests/unit/test_code_review_brief_sections.py b/tests/unit/test_code_review_brief_sections.py index 2a72f97acca..1a382dca46b 100644 --- a/tests/unit/test_code_review_brief_sections.py +++ b/tests/unit/test_code_review_brief_sections.py @@ -3621,12 +3621,12 @@ async def down(*a: Any) -> Any: @pytest.mark.asyncio @pytest.mark.parametrize("binding", ["open", "restricted", "unclassified"]) -async def test_history_rows_name_a_restricted_trackers_culprits_to_no_one( +async def test_history_rows_name_no_pr_a_restricted_tracker_read( monkeypatch: pytest.MonkeyPatch, binding: str ) -> None: - """A stored brief is read by every viewer of the code namespace, so the issues a - restricted tracker (or one whose classification is unread) traces back to a PR stay - out of its rows, as out of its `qa` section; the ledger's fixes and reverts stay.""" + """A stored brief is read by every viewer of the code namespace, so a record read + through a restricted tracker (or one whose classification is unread) names no PR in + it, as that tracker stays out of its `qa` section.""" import server.identity.app.namespace_classification as nc from server.auth.directory import ClassificationUnavailable @@ -3654,9 +3654,10 @@ async def call(op: str, body: dict[str, Any]) -> dict[str, Any]: hist = await review_brief_build._history_section( call, _inputs(), [("app.counter::bump", "app/counter.py")] ) - assert hist["verdict"] == "regressions" - served = hist["rows"][0]["regression_prs"] + # the counts and the verdict stand either way + assert hist["verdict"] == "regressions" and hist["rows"][0]["named_fix_prs"] == 1 if binding == "open": - assert served == evidence + assert hist["rows"][0]["regression_prs"] == evidence else: - assert served == [{"pr_number": 3, "kinds": ["fix"]}, {"pr_number": 2, "kinds": ["revert"]}] + # a tracker match or link may be all a fix entry rests on: none is copied + assert "regression_prs" not in hist["rows"][0] From 5b6409c98d7dc24474abc77d74e41b8995f90630 Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 07:04:36 +0000 Subject: [PATCH 08/13] The brief reads its tracker from the binding; a named ranking key A record whose tracker side raised names no namespace, so the brief now reads the namespace bound to the code namespace, as its qa section does, and only when a record names a PR. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/features/code-index/history-and-prs.md | 7 ++++--- server/code/app/index/review_brief_build.py | 19 +++++++------------ server/code/domain/index/symbol_history.py | 9 +++++++-- tests/unit/test_code_review_brief_sections.py | 10 +++++++++- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/docs/features/code-index/history-and-prs.md b/docs/features/code-index/history-and-prs.md index 918aef2122a..f1b9966a684 100644 --- a/docs/features/code-index/history-and-prs.md +++ b/docs/features/code-index/history-and-prs.md @@ -219,9 +219,10 @@ name such as `(anonymous namespace)::f`, reads the bare name, as does a form pas op's 300-character name bound; a record of another file's definition is `unknown`. A row whose counts make the section `regressions` carries that record's `regression_prs`, so the brief names the earlier fixes, reverts and culprit PRs with their test files; a -brief stored by an earlier build has the counts without it. When the records' tracker -namespace is restricted, or its classification cannot be read, the brief carries the -counts without `regression_prs`, as it leaves that tracker out of its `qa` section. +brief stored by an earlier build has the counts without it. When the tracker +namespace bound to the code namespace is restricted, or its classification cannot be +read, the brief carries the counts without `regression_prs`, as it leaves that tracker +out of its `qa` section. The answer comes first: `verdict` and `verdict_causes`, read off every section the brief holds, whatever the tier serves, and off `rationale` when this read serves it. A verdict diff --git a/server/code/app/index/review_brief_build.py b/server/code/app/index/review_brief_build.py index 2d43b73fc40..d183e623cac 100644 --- a/server/code/app/index/review_brief_build.py +++ b/server/code/app/index/review_brief_build.py @@ -894,21 +894,16 @@ def _history_name(name: str, path: str) -> str: return form if carried else name -async def _tracker_closed(org: str, results: list[Any]) -> bool: - """Whether the tracker namespace the history records read from is restricted, or its +async def _tracker_closed(org: str, ns: str) -> bool: + """Whether the tracker namespace bound to the code namespace is restricted, or its classification could not be read. A stored brief is read by every viewer of the code namespace, so as for the `qa` section, none of that tracker's rows may enter it.""" from server.auth.directory import ClassificationUnavailable from server.identity.app.namespace_classification import is_restricted + from server.tracker.app.binding import refresh_overrides, tracker_namespace_for - tracker = next( - ( - str(r.get("tracker_namespace") or "") - for r in results - if not isinstance(r, BaseException) and r.get("regression_prs") - ), - "", - ) + await refresh_overrides() # the links as of the refresh interval, branches included + tracker = tracker_namespace_for(org, ns) if not tracker: return False try: @@ -945,8 +940,8 @@ async def _history_section( causes: list[str] = [] unavailable = 0 left = 0 # functions an op refused to read: a cap - # every record reads the one tracker bound to the code namespace - closed = await _tracker_closed(inp.org, results) + named = any(not isinstance(r, BaseException) and r.get("regression_prs") for r in results) + closed = named and await _tracker_closed(inp.org, inp.ns) for (name, path), res in zip(defs, results, strict=True): if isinstance(res, BaseException): if refused(res): diff --git a/server/code/domain/index/symbol_history.py b/server/code/domain/index/symbol_history.py index a9b327b1d3e..3587eda2b1e 100644 --- a/server/code/domain/index/symbol_history.py +++ b/server/code/domain/index/symbol_history.py @@ -299,9 +299,14 @@ def regression_prs( changed test files (`_test_files`), the `code.test_gate` arguments that list how to run them in this namespace. `run_templates` is the deployment's run recipes, as code.test_gate reads them.""" + + def strength(entry: tuple[PrRow, list[str], str]) -> tuple[int, bool, int]: + _, kinds, fix_by = entry + return -len(kinds), fix_by == "linked_issue", _KIND_ORDER[kinds[0]] + picked = [(r, k, _fix_by(r, k)) for r in rows if (k := _evidence_kinds(r))] - picked.sort(key=lambda p: p[0].merged_at, reverse=True) - picked.sort(key=lambda p: (-len(p[1]), p[2] == "linked_issue", _KIND_ORDER[p[1][0]])) + picked.sort(key=lambda entry: entry[0].merged_at, reverse=True) # ties: the newest + picked.sort(key=strength) out: list[dict[str, Any]] = [] for row, kinds, fix_by in picked[:EVIDENCE_PRS]: item: dict[str, Any] = { diff --git a/tests/unit/test_code_review_brief_sections.py b/tests/unit/test_code_review_brief_sections.py index 1a382dca46b..2110e3a8e73 100644 --- a/tests/unit/test_code_review_brief_sections.py +++ b/tests/unit/test_code_review_brief_sections.py @@ -3628,14 +3628,21 @@ async def test_history_rows_name_no_pr_a_restricted_tracker_read( through a restricted tracker (or one whose classification is unread) names no PR in it, as that tracker stays out of its `qa` section.""" import server.identity.app.namespace_classification as nc + import server.tracker.app.binding as binding_mod from server.auth.directory import ClassificationUnavailable async def is_restricted(org: str, ns: str) -> bool: + assert ns == "tracker-shop" # the binding's namespace, whatever a record says if binding == "unclassified": raise ClassificationUnavailable("directory unread") return binding == "restricted" + async def refresh() -> None: + return None + monkeypatch.setattr(nc, "is_restricted", is_restricted) + monkeypatch.setattr(binding_mod, "refresh_overrides", refresh) + monkeypatch.setattr(binding_mod, "tracker_namespace_for", lambda org, ns: "tracker-shop") evidence = [ {"pr_number": 3, "kinds": ["fix", "caused_issue"], "caused_issues": [9]}, {"pr_number": 2, "kinds": ["revert"]}, @@ -3648,7 +3655,8 @@ async def call(op: str, body: dict[str, Any]) -> dict[str, Any]: "symbol": {"path": "app/counter.py"}, "summary": {"named_fix_prs": 1, "reverts": 1, "caused_issues": [8, 9]}, "regression_prs": evidence, - "tracker_namespace": "tracker-shop", + # a record whose tracker side raised names no namespace + "tracker_namespace": "", } hist = await review_brief_build._history_section( From 82f613b3f010eac708b10373eb6a6e25b84444ea Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 07:14:37 +0000 Subject: [PATCH 09/13] The brief checks every tracker a history record may rest on The binding can move between the op's read and the brief's check, so the brief is closed when the bound tracker or any tracker a record says it read is restricted or unclassified. A handler test shows the deployment's run templates reach the ordering. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/features/code-index/history-and-prs.md | 11 ++--- server/code/app/index/review_brief_build.py | 31 ++++++++------ tests/unit/test_code_review_brief_sections.py | 40 +++++++++++-------- tests/unit/test_code_symbol_history.py | 20 ++++++++++ 4 files changed, 68 insertions(+), 34 deletions(-) diff --git a/docs/features/code-index/history-and-prs.md b/docs/features/code-index/history-and-prs.md index f1b9966a684..635692713e4 100644 --- a/docs/features/code-index/history-and-prs.md +++ b/docs/features/code-index/history-and-prs.md @@ -184,7 +184,8 @@ four of them in the namespace the history was read from: first those `code.test_ a run recipe for (its built-in ones and `code_test_gate_run_templates`), then files named as tests, then fixtures that are tests only by their directory. They are the paths the ledger lists for the PR, so one it deleted or a later PR renamed may be gone. The record -is the PR ledger's, so it holds for every language the index reads. +is the PR ledger's; a test file is one `code.test_gate` counts as a test (a test +directory, or a test file name in the languages it lists). `code.blame_range` takes a `path`, a line range (at most 400 lines) and a window as release versions (`from_version`, `to_version`) or commit shas. It combines the PR @@ -219,10 +220,10 @@ name such as `(anonymous namespace)::f`, reads the bare name, as does a form pas op's 300-character name bound; a record of another file's definition is `unknown`. A row whose counts make the section `regressions` carries that record's `regression_prs`, so the brief names the earlier fixes, reverts and culprit PRs with their test files; a -brief stored by an earlier build has the counts without it. When the tracker -namespace bound to the code namespace is restricted, or its classification cannot be -read, the brief carries the counts without `regression_prs`, as it leaves that tracker -out of its `qa` section. +brief stored by an earlier build has the counts without it. When a tracker +namespace a record may rest on, the one bound to the code namespace or the one the record +says it read, is restricted, or its classification cannot be read, the brief carries the +counts without `regression_prs`, as it leaves that tracker out of its `qa` section. The answer comes first: `verdict` and `verdict_causes`, read off every section the brief holds, whatever the tier serves, and off `rationale` when this read serves it. A verdict diff --git a/server/code/app/index/review_brief_build.py b/server/code/app/index/review_brief_build.py index d183e623cac..931b502a5d7 100644 --- a/server/code/app/index/review_brief_build.py +++ b/server/code/app/index/review_brief_build.py @@ -894,22 +894,27 @@ def _history_name(name: str, path: str) -> str: return form if carried else name -async def _tracker_closed(org: str, ns: str) -> bool: - """Whether the tracker namespace bound to the code namespace is restricted, or its - classification could not be read. A stored brief is read by every viewer of the code - namespace, so as for the `qa` section, none of that tracker's rows may enter it.""" +async def _tracker_closed(org: str, ns: str, results: list[Any]) -> bool: + """Whether a tracker namespace the history records may rest on is restricted, or its + classification could not be read: the one bound to the code namespace now (a record + whose tracker side raised names none) and each one a record says it read (the binding + may have moved since). A stored brief is read by every viewer of the code namespace, + so as for the `qa` section, none of such a tracker's rows may enter it.""" from server.auth.directory import ClassificationUnavailable from server.identity.app.namespace_classification import is_restricted from server.tracker.app.binding import refresh_overrides, tracker_namespace_for await refresh_overrides() # the links as of the refresh interval, branches included - tracker = tracker_namespace_for(org, ns) - if not tracker: - return False - try: - return await is_restricted(org, tracker) - except ClassificationUnavailable: - return True + trackers = {tracker_namespace_for(org, ns)} | { + str(r.get("tracker_namespace") or "") for r in results if not isinstance(r, BaseException) + } + for tracker in sorted(trackers - {""}): + try: + if await is_restricted(org, tracker): + return True + except ClassificationUnavailable: + return True + return False async def _history_section( @@ -940,8 +945,8 @@ async def _history_section( causes: list[str] = [] unavailable = 0 left = 0 # functions an op refused to read: a cap - named = any(not isinstance(r, BaseException) and r.get("regression_prs") for r in results) - closed = named and await _tracker_closed(inp.org, inp.ns) + listed = any(not isinstance(r, BaseException) and r.get("regression_prs") for r in results) + closed = listed and await _tracker_closed(inp.org, inp.ns, results) for (name, path), res in zip(defs, results, strict=True): if isinstance(res, BaseException): if refused(res): diff --git a/tests/unit/test_code_review_brief_sections.py b/tests/unit/test_code_review_brief_sections.py index 2110e3a8e73..1f8635a7d4f 100644 --- a/tests/unit/test_code_review_brief_sections.py +++ b/tests/unit/test_code_review_brief_sections.py @@ -3620,43 +3620,51 @@ async def down(*a: Any) -> Any: @pytest.mark.asyncio -@pytest.mark.parametrize("binding", ["open", "restricted", "unclassified"]) +@pytest.mark.parametrize( + ("bound", "read", "closed"), + [ + ("open", "", False), + ("restricted", "", True), # the record's tracker side raised: the binding decides + ("unclassified", "", True), + ("open", "restricted", True), # the binding moved off the tracker the record read + ("restricted", "open", True), + ("open", "open", False), + ], +) async def test_history_rows_name_no_pr_a_restricted_tracker_read( - monkeypatch: pytest.MonkeyPatch, binding: str + monkeypatch: pytest.MonkeyPatch, bound: str, read: str, closed: bool ) -> None: - """A stored brief is read by every viewer of the code namespace, so a record read - through a restricted tracker (or one whose classification is unread) names no PR in - it, as that tracker stays out of its `qa` section.""" + """A stored brief is read by every viewer of the code namespace, so a record that may + rest on a restricted tracker (or one whose classification is unread), the bound one + or the one the record says it read, names no PR in it, as that tracker stays out of + its `qa` section.""" import server.identity.app.namespace_classification as nc import server.tracker.app.binding as binding_mod from server.auth.directory import ClassificationUnavailable async def is_restricted(org: str, ns: str) -> bool: - assert ns == "tracker-shop" # the binding's namespace, whatever a record says - if binding == "unclassified": + if ns == "unclassified": raise ClassificationUnavailable("directory unread") - return binding == "restricted" + return ns == "restricted" async def refresh() -> None: return None monkeypatch.setattr(nc, "is_restricted", is_restricted) monkeypatch.setattr(binding_mod, "refresh_overrides", refresh) - monkeypatch.setattr(binding_mod, "tracker_namespace_for", lambda org, ns: "tracker-shop") + monkeypatch.setattr(binding_mod, "tracker_namespace_for", lambda org, ns: bound) evidence = [ {"pr_number": 3, "kinds": ["fix", "caused_issue"], "caused_issues": [9]}, {"pr_number": 2, "kinds": ["revert"]}, - {"pr_number": 1, "kinds": ["caused_issue"], "caused_issues": [8]}, ] async def call(op: str, body: dict[str, Any]) -> dict[str, Any]: return { "verdict": "history", "symbol": {"path": "app/counter.py"}, - "summary": {"named_fix_prs": 1, "reverts": 1, "caused_issues": [8, 9]}, + "summary": {"named_fix_prs": 1, "reverts": 1, "caused_issues": [9]}, "regression_prs": evidence, - # a record whose tracker side raised names no namespace - "tracker_namespace": "", + "tracker_namespace": read, } hist = await review_brief_build._history_section( @@ -3664,8 +3672,8 @@ async def call(op: str, body: dict[str, Any]) -> dict[str, Any]: ) # the counts and the verdict stand either way assert hist["verdict"] == "regressions" and hist["rows"][0]["named_fix_prs"] == 1 - if binding == "open": - assert hist["rows"][0]["regression_prs"] == evidence - else: + if closed: # a tracker match or link may be all a fix entry rests on: none is copied assert "regression_prs" not in hist["rows"][0] + else: + assert hist["rows"][0]["regression_prs"] == evidence diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index 7c11db32c42..28c5fe11834 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -573,3 +573,23 @@ async def _no_items(self, org, ns, numbers): "code_index: issue_facts_unread (TimeoutError)", "tracker: symbol_facts_unread (RuntimeError)", ] + + +@pytest.mark.asyncio +async def test_handler_orders_test_files_by_the_deployments_run_templates( + wired, monkeypatch: pytest.MonkeyPatch +) -> None: + recipes = '[{"pattern": "^tests/test_parts", "run": "./run {path}"}]' + monkeypatch.setattr(h.settings, "code_test_gate_run_templates", recipes) + seen: list[str] = [] + real = sh.regression_prs + + def spy(rows: list[sh.PrRow], **kw: Any) -> list[dict[str, Any]]: + seen.append(kw["run_templates"]) + return real(rows, **kw) + + monkeypatch.setattr(h.sh, "regression_prs", spy) + await h.handle_code_symbol_history( + CodeSymbolHistoryInput(org=ORG, namespace=NS, name="DB::MergeTreeData::loadDataParts") + ) + assert seen == [recipes] From 0cf77069d72aacf925c9d5e76124f5e1caff74fc Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 07:26:01 +0000 Subject: [PATCH 10/13] An unread tracker classification keeps the brief unstored; a bad run template is no recipe A brief that leaves out regression_prs because the tracker's classification could not be read is served and not stored, so the next read builds it again; no verdict rests on it. run_command_for treats a template that does not format as no recipe, so it cannot fail code.symbol_history. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/features/code-index/history-and-prs.md | 9 +++--- server/code/app/index/review_brief_build.py | 32 ++++++++++++------- server/code/domain/index/test_gate.py | 4 +-- tests/unit/test_code_review_brief_sections.py | 6 ++++ tests/unit/test_code_symbol_history.py | 29 +++++++++++------ 5 files changed, 52 insertions(+), 28 deletions(-) diff --git a/docs/features/code-index/history-and-prs.md b/docs/features/code-index/history-and-prs.md index 635692713e4..b4044144df0 100644 --- a/docs/features/code-index/history-and-prs.md +++ b/docs/features/code-index/history-and-prs.md @@ -220,10 +220,11 @@ name such as `(anonymous namespace)::f`, reads the bare name, as does a form pas op's 300-character name bound; a record of another file's definition is `unknown`. A row whose counts make the section `regressions` carries that record's `regression_prs`, so the brief names the earlier fixes, reverts and culprit PRs with their test files; a -brief stored by an earlier build has the counts without it. When a tracker -namespace a record may rest on, the one bound to the code namespace or the one the record -says it read, is restricted, or its classification cannot be read, the brief carries the -counts without `regression_prs`, as it leaves that tracker out of its `qa` section. +brief stored by an earlier build has the counts without it. When a tracker namespace a +record may rest on, the one bound to the code namespace or the one the record says it +read, is restricted, the brief carries the counts without `regression_prs`, as it leaves +that tracker out of its `qa` section. When its classification cannot be read, the brief +leaves them out too and is not stored, so the next read builds it again. The answer comes first: `verdict` and `verdict_causes`, read off every section the brief holds, whatever the tier serves, and off `rationale` when this read serves it. A verdict diff --git a/server/code/app/index/review_brief_build.py b/server/code/app/index/review_brief_build.py index 931b502a5d7..274b61e5de2 100644 --- a/server/code/app/index/review_brief_build.py +++ b/server/code/app/index/review_brief_build.py @@ -894,12 +894,18 @@ def _history_name(name: str, path: str) -> str: return form if carried else name -async def _tracker_closed(org: str, ns: str, results: list[Any]) -> bool: - """Whether a tracker namespace the history records may rest on is restricted, or its - classification could not be read: the one bound to the code namespace now (a record - whose tracker side raised names none) and each one a record says it read (the binding - may have moved since). A stored brief is read by every viewer of the code namespace, - so as for the `qa` section, none of such a tracker's rows may enter it.""" +# `_tracker_gate`: a tracker the brief may carry rows of, one it may not, and an +# unread classification (closed too, and the brief is not stored, so the next read +# builds it again) +TRACKER_OPEN, TRACKER_CLOSED, TRACKER_UNREAD = "open", "closed", "unread" + + +async def _tracker_gate(org: str, ns: str, results: list[Any]) -> str: + """Whether the brief may carry the rows of the tracker namespaces the history records + may rest on: the one bound to the code namespace now (a record whose tracker side + raised names none) and each one a record says it read (the binding may have moved + since). A stored brief is read by every viewer of the code namespace, so as for the + `qa` section, a restricted tracker's rows never enter it.""" from server.auth.directory import ClassificationUnavailable from server.identity.app.namespace_classification import is_restricted from server.tracker.app.binding import refresh_overrides, tracker_namespace_for @@ -911,10 +917,10 @@ async def _tracker_closed(org: str, ns: str, results: list[Any]) -> bool: for tracker in sorted(trackers - {""}): try: if await is_restricted(org, tracker): - return True + return TRACKER_CLOSED except ClassificationUnavailable: - return True - return False + return TRACKER_UNREAD + return TRACKER_OPEN async def _history_section( @@ -946,7 +952,7 @@ async def _history_section( unavailable = 0 left = 0 # functions an op refused to read: a cap listed = any(not isinstance(r, BaseException) and r.get("regression_prs") for r in results) - closed = listed and await _tracker_closed(inp.org, inp.ns, results) + gate = await _tracker_gate(inp.org, inp.ns, results) if listed else TRACKER_OPEN for (name, path), res in zip(defs, results, strict=True): if isinstance(res, BaseException): if refused(res): @@ -973,7 +979,7 @@ async def _history_section( "tracker": not bool(res.get("tracker_unavailable")) and bool(res.get("tracker_namespace")), } - prs = [] if closed else list(res.get("regression_prs") or []) + prs = list(res.get("regression_prs") or []) if gate == TRACKER_OPEN else [] if prs: # the PRs behind the counts that make `regressions` (the op names none on a # row without them), each with its title and the test files it changed @@ -995,7 +1001,9 @@ async def _history_section( epistemic="lower_bound", causes=causes, rows=rows, - failed=causes, # every cause here is a read that raised + # every cause here is a read that raised; an unread tracker classification decides + # no verdict, so it keeps the brief unstored without being a cause + failed=[*causes, *(["tracker_classification_unread"] if gate == TRACKER_UNREAD else [])], note="touch is file-level unless `qa` is true on the row; every count is a floor", ) _cut(out, NOT_READ, left) diff --git a/server/code/domain/index/test_gate.py b/server/code/domain/index/test_gate.py index 11280d612bc..91d920135c9 100644 --- a/server/code/domain/index/test_gate.py +++ b/server/code/domain/index/test_gate.py @@ -190,8 +190,8 @@ def run_command_for(test_path: str, overrides_json: str = "") -> tuple[str, bool groups = {f"g{i}": g or "" for i, g in enumerate(m.groups(), start=1)} try: return tpl.format(**ctx, **groups), False - except (KeyError, IndexError): - continue + except (KeyError, IndexError, ValueError, AttributeError): + continue # a template that does not format (a field it lacks, a stray brace) return "", True diff --git a/tests/unit/test_code_review_brief_sections.py b/tests/unit/test_code_review_brief_sections.py index 1f8635a7d4f..81850b0b81d 100644 --- a/tests/unit/test_code_review_brief_sections.py +++ b/tests/unit/test_code_review_brief_sections.py @@ -3677,3 +3677,9 @@ async def call(op: str, body: dict[str, Any]) -> dict[str, Any]: assert "regression_prs" not in hist["rows"][0] else: assert hist["rows"][0]["regression_prs"] == evidence + # an unread classification keeps the brief unstored, deciding no verdict + unread = "unclassified" in (bound, read) + assert rb.failed_reads({"history": hist}) == ( + ["history:tracker_classification_unread"] if unread else [] + ) + assert hist["causes"] == [] diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index 28c5fe11834..92d5de04518 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -6,6 +6,7 @@ from __future__ import annotations +import json from datetime import datetime from typing import Any @@ -579,17 +580,25 @@ async def _no_items(self, org, ns, numbers): async def test_handler_orders_test_files_by_the_deployments_run_templates( wired, monkeypatch: pytest.MonkeyPatch ) -> None: - recipes = '[{"pattern": "^tests/test_parts", "run": "./run {path}"}]' + # the ledger lists the fixture first; only the deployment's template runs the case + monkeypatch.setitem(PRS[0], "files", [PATH, "spec/parts.expected", "spec/parts.case"]) + recipes = '[{"pattern": "^spec/.+[.]case$", "run": "./run-case {path}"}]' monkeypatch.setattr(h.settings, "code_test_gate_run_templates", recipes) - seen: list[str] = [] - real = sh.regression_prs + out = await h.handle_code_symbol_history( + CodeSymbolHistoryInput(org=ORG, namespace=NS, name="DB::MergeTreeData::loadDataParts") + ) + assert out.regression_prs[0]["test_gate"]["files"] == ["spec/parts.case", "spec/parts.expected"] - def spy(rows: list[sh.PrRow], **kw: Any) -> list[dict[str, Any]]: - seen.append(kw["run_templates"]) - return real(rows, **kw) - monkeypatch.setattr(h.sh, "regression_prs", spy) - await h.handle_code_symbol_history( - CodeSymbolHistoryInput(org=ORG, namespace=NS, name="DB::MergeTreeData::loadDataParts") +def test_a_template_that_does_not_format_counts_as_no_recipe() -> None: + row = sh.PrRow( + pr_number=9, + title="Fix overflow", + merged_at="2026-09-01T00:00:00", + is_fix=True, + touches_symbol="true", + files=["spec/a.case"], ) - assert seen == [recipes] + for run in ("./run {path", "./run {path.x}"): + recipes = json.dumps([{"pattern": "^spec/", "run": run}]) + assert _evidence([row], run_templates=recipes)[0]["test_gate"]["files"] == ["spec/a.case"] From 8426c88cd7c6fb6d86297b47b69a50304ffe0b0a Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 07:31:45 +0000 Subject: [PATCH 11/13] A run template that indexes a string counts as no recipe too Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- server/code/domain/index/test_gate.py | 2 +- tests/unit/test_code_symbol_history.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/code/domain/index/test_gate.py b/server/code/domain/index/test_gate.py index 91d920135c9..8598e150260 100644 --- a/server/code/domain/index/test_gate.py +++ b/server/code/domain/index/test_gate.py @@ -190,7 +190,7 @@ def run_command_for(test_path: str, overrides_json: str = "") -> tuple[str, bool groups = {f"g{i}": g or "" for i, g in enumerate(m.groups(), start=1)} try: return tpl.format(**ctx, **groups), False - except (KeyError, IndexError, ValueError, AttributeError): + except (KeyError, IndexError, ValueError, AttributeError, TypeError): continue # a template that does not format (a field it lacks, a stray brace) return "", True diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index 92d5de04518..1271cb5647d 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -599,6 +599,6 @@ def test_a_template_that_does_not_format_counts_as_no_recipe() -> None: touches_symbol="true", files=["spec/a.case"], ) - for run in ("./run {path", "./run {path.x}"): + for run in ("./run {path", "./run {path.x}", "./run {path[x]}"): recipes = json.dumps([{"pattern": "^spec/", "run": run}]) assert _evidence([row], run_templates=recipes)[0]["test_gate"]["files"] == ["spec/a.case"] From f86abc6d529dd4cc1458f085f5df5ea61b4e1d15 Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 07:48:08 +0000 Subject: [PATCH 12/13] One file per test suite before a second in a regression PR's test files Four config files of one integration suite no longer push another suite the PR changed out of the four-file cap: within the order, one file of each run command comes before a second of it. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/features/code-index/history-and-prs.md | 3 ++- server/code/api/models_history.py | 5 +++-- server/code/domain/index/symbol_history.py | 15 ++++++++++++--- tests/unit/test_code_symbol_history.py | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/docs/features/code-index/history-and-prs.md b/docs/features/code-index/history-and-prs.md index b4044144df0..899a3de4640 100644 --- a/docs/features/code-index/history-and-prs.md +++ b/docs/features/code-index/history-and-prs.md @@ -182,7 +182,8 @@ PR issues trace back to, then the newest. When the PR changed test files, `test_ the `code.test_gate` arguments (`org`, `namespace`, `files`) that list how to run up to four of them in the namespace the history was read from: first those `code.test_gate` has a run recipe for (its built-in ones and `code_test_gate_run_templates`), then files named -as tests, then fixtures that are tests only by their directory. They are the paths the +as tests, then fixtures that are tests only by their directory, with one file of each run +command (such as one suite's directory) before a second of it. They are the paths the ledger lists for the PR, so one it deleted or a later PR renamed may be gone. The record is the PR ledger's; a test file is one `code.test_gate` counts as a test (a test directory, or a test file name in the languages it lists). diff --git a/server/code/api/models_history.py b/server/code/api/models_history.py index 0cb020a2564..291338f7a2b 100644 --- a/server/code/api/models_history.py +++ b/server/code/api/models_history.py @@ -626,8 +626,9 @@ class CodeSymbolHistoryOutput(BaseModel): # caused_issues[] (with caused_issue), test_gate (only when the PR changed test files: # the code.test_gate arguments {org, namespace, files} that list how to run them, # files ≤4 of the ledger's test paths: those code.test_gate has a run recipe for, then - # those named as tests, then fixtures under a test directory; a path the PR deleted - # or a later PR renamed may be gone)} + # those named as tests, then fixtures under a test directory, one file of each run + # command before a second of it; a path the PR deleted or a later PR renamed may be + # gone)} regression_prs: list[dict[str, Any]] = Field(default_factory=list) # The tracker namespace that answered the QA side; "" when none is bound or # its read failed. diff --git a/server/code/domain/index/symbol_history.py b/server/code/domain/index/symbol_history.py index 3587eda2b1e..c4e88de3228 100644 --- a/server/code/domain/index/symbol_history.py +++ b/server/code/domain/index/symbol_history.py @@ -283,9 +283,18 @@ def _fix_by(row: PrRow, kinds: list[str]) -> str: def _test_files(row: PrRow, run_templates: str) -> list[str]: """The PR's test files, those code.test_gate has a run recipe for first, then those - named as tests before fixtures that are tests only by their directory.""" - tests = [f for f in row.files if is_test_path(f)] - tests.sort(key=lambda p: (run_command_for(p, run_templates)[1], not is_test_named(p))) + named as tests before fixtures that are tests only by their directory; within that + order one file of each run command (a suite's directory) before a second of it, so the + files of one suite cannot crowd out another the PR changed.""" + runs = {p: run_command_for(p, run_templates) for p in row.files if is_test_path(p)} + tests = sorted(runs, key=lambda p: (runs[p][1], not is_test_named(p))) + seen: set[str] = set() + repeat: dict[str, bool] = {} + for p in tests: + run = runs[p][0] or p # a file with no recipe is its own + repeat[p] = run in seen + seen.add(run) + tests.sort(key=lambda p: repeat[p]) return tests[:EVIDENCE_TEST_FILES] diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index 1271cb5647d..1e174154cc8 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -590,6 +590,21 @@ async def test_handler_orders_test_files_by_the_deployments_run_templates( assert out.regression_prs[0]["test_gate"]["files"] == ["spec/parts.case", "spec/parts.expected"] +def test_one_suites_files_do_not_crowd_out_another_suite() -> None: + suite_a = [f"tests/integration/test_a/configs/{c}.xml" for c in "abcd"] + row = sh.PrRow( + pr_number=4, + title="Fix reconnect", + merged_at="2026-09-01T00:00:00", + is_fix=True, + touches_symbol="true", + files=[*suite_a, "tests/integration/test_b/test.py"], + ) + files = _evidence([row])[0]["test_gate"]["files"] + assert files[:2] == [suite_a[0], "tests/integration/test_b/test.py"] + assert len(files) == 4 + + def test_a_template_that_does_not_format_counts_as_no_recipe() -> None: row = sh.PrRow( pr_number=9, From f705d553b2c76d6b6c4aa1abacae1747a1f5594a Mon Sep 17 00:00:00 2001 From: zlareb1 Date: Sun, 6 Dec 2026 07:57:06 +0000 Subject: [PATCH 13/13] Read the tracker of the history records a brief keeps A record whose symbol resolved to another file is discarded before the tracker gate, so its tracker no longer keeps the brief unstored. The regression_prs field description is one sentence, and the suite-ordering test uses a made-up run template. Co-Authored-By: Claude Opus 5.5 Signed-off-by: zlareb1 --- docs/reference/operations/code.md | 2 +- server/code/api/models_history.py | 14 ++------ server/code/app/index/review_brief_build.py | 11 ++++-- server/code/domain/index/symbol_history.py | 2 +- tests/unit/test_code_review_brief_sections.py | 35 +++++++++++++++++++ tests/unit/test_code_symbol_history.py | 9 ++--- 6 files changed, 52 insertions(+), 21 deletions(-) diff --git a/docs/reference/operations/code.md b/docs/reference/operations/code.md index 23bf6478e55..3a0cc5eece4 100644 --- a/docs/reference/operations/code.md +++ b/docs/reference/operations/code.md @@ -1730,7 +1730,7 @@ The regression history of one function: the merged PRs that touched it (with lin | `review_comments` | `list[dict[str, Any]]` | inline review comments inside the symbol's span, newest first (≤5) | | `open_issues_naming` | `list[dict[str, Any]]` | open issues whose text names the function (QA), most severe first (≤5) | | `summary` | `dict[str, Any]` | {prs_total, named_prs, fix_prs, named_fix_prs, reverts, caused_issues[], open_issues_naming, last_touched, oldest_in_window, authors[], note} | -| `regression_prs` | `list[dict[str, Any]]` | The PRs behind the summary's named_fix_prs, reverts and caused_issues, from the whole window whatever `limit` serves, strongest first (≤3): behind more of the counts, then a fix counted only for closing an issue after the rest, then fix… | +| `regression_prs` | `list[dict[str, Any]]` | Up to 3 PRs behind named_fix_prs, reverts and caused_issues, strongest first, each with its title, merge date, kinds and a code.test_gate query for the tests it changed. | | `tracker_namespace` | `str` | The tracker namespace that answered the QA side; "" when none is bound or its read failed. | | `tracker_unavailable` | `bool` | True when a tracker is bound but its read failed. | | `trace_run_id` | `str` | Id of this call's trace row; pass it to `code.outcome`. | diff --git a/server/code/api/models_history.py b/server/code/api/models_history.py index 291338f7a2b..381ab49e5d1 100644 --- a/server/code/api/models_history.py +++ b/server/code/api/models_history.py @@ -617,18 +617,8 @@ class CodeSymbolHistoryOutput(BaseModel): # {prs_total, named_prs, fix_prs, named_fix_prs, reverts, caused_issues[], # open_issues_naming, last_touched, oldest_in_window, authors[], note} summary: dict[str, Any] = Field(default_factory=dict) - # The PRs behind the summary's named_fix_prs, reverts and caused_issues, from the whole - # window whatever `limit` serves, strongest first (≤3): behind more of the counts, then - # a fix counted only for closing an issue after the rest, then fix, revert, - # caused_issue, then the newest. {pr_number, title, merged_at (date), kinds[] (fix | - # revert | caused_issue), fix_by (with fix: title, when the title says fix, crash, - # regression and the like, or linked_issue, when it only closes an issue), - # caused_issues[] (with caused_issue), test_gate (only when the PR changed test files: - # the code.test_gate arguments {org, namespace, files} that list how to run them, - # files ≤4 of the ledger's test paths: those code.test_gate has a run recipe for, then - # those named as tests, then fixtures under a test directory, one file of each run - # command before a second of it; a path the PR deleted or a later PR renamed may be - # gone)} + # Up to 3 PRs behind named_fix_prs, reverts and caused_issues, strongest first, each + # with its title, merge date, kinds and a code.test_gate query for the tests it changed. regression_prs: list[dict[str, Any]] = Field(default_factory=list) # The tracker namespace that answered the QA side; "" when none is bound or # its read failed. diff --git a/server/code/app/index/review_brief_build.py b/server/code/app/index/review_brief_build.py index 274b61e5de2..e7e66eb24a2 100644 --- a/server/code/app/index/review_brief_build.py +++ b/server/code/app/index/review_brief_build.py @@ -951,6 +951,14 @@ async def _history_section( causes: list[str] = [] unavailable = 0 left = 0 # functions an op refused to read: a cap + # a name that resolved to another file's definition reads as unknown + results = [ + r + if isinstance(r, BaseException) + or str((r.get("symbol") or {}).get("path") or "") in ("", path) + else {"verdict": "unknown"} + for (_, path), r in zip(defs, results, strict=True) + ] listed = any(not isinstance(r, BaseException) and r.get("regression_prs") for r in results) gate = await _tracker_gate(inp.org, inp.ns, results) if listed else TRACKER_OPEN for (name, path), res in zip(defs, results, strict=True): @@ -961,9 +969,6 @@ async def _history_section( degradations.partial("code.review_brief", "symbol_history_failed", res) causes.append(failure_cause("symbol_history", res)) continue - resolved = str((res.get("symbol") or {}).get("path") or "") - if resolved and resolved != path: - res = {"verdict": "unknown"} s = dict(res.get("summary") or {}) row: dict[str, Any] = { "qualified_name": name, diff --git a/server/code/domain/index/symbol_history.py b/server/code/domain/index/symbol_history.py index c4e88de3228..ac2ee11aaa9 100644 --- a/server/code/domain/index/symbol_history.py +++ b/server/code/domain/index/symbol_history.py @@ -291,7 +291,7 @@ def _test_files(row: PrRow, run_templates: str) -> list[str]: seen: set[str] = set() repeat: dict[str, bool] = {} for p in tests: - run = runs[p][0] or p # a file with no recipe is its own + run = runs[p][0] or p # a file with no recipe is its own run command repeat[p] = run in seen seen.add(run) tests.sort(key=lambda p: repeat[p]) diff --git a/tests/unit/test_code_review_brief_sections.py b/tests/unit/test_code_review_brief_sections.py index 81850b0b81d..dd92a0b40ac 100644 --- a/tests/unit/test_code_review_brief_sections.py +++ b/tests/unit/test_code_review_brief_sections.py @@ -3683,3 +3683,38 @@ async def call(op: str, body: dict[str, Any]) -> dict[str, Any]: ["history:tracker_classification_unread"] if unread else [] ) assert hist["causes"] == [] + + +@pytest.mark.asyncio +async def test_a_record_of_another_file_reads_no_tracker(monkeypatch: pytest.MonkeyPatch) -> None: + """A record whose symbol is another file's is discarded, so its tracker does not keep + the brief unstored.""" + import server.identity.app.namespace_classification as nc + import server.tracker.app.binding as binding_mod + from server.auth.directory import ClassificationUnavailable + + async def is_restricted(org: str, ns: str) -> bool: + raise ClassificationUnavailable("directory unread") + + async def refresh() -> None: + return None + + monkeypatch.setattr(nc, "is_restricted", is_restricted) + monkeypatch.setattr(binding_mod, "refresh_overrides", refresh) + monkeypatch.setattr(binding_mod, "tracker_namespace_for", lambda org, ns: "qa") + + async def call(op: str, body: dict[str, Any]) -> dict[str, Any]: + return { + "verdict": "history", + "symbol": {"path": "app/other.py"}, + "summary": {"named_fix_prs": 1}, + "regression_prs": [{"pr_number": 3, "kinds": ["fix"]}], + "tracker_namespace": "qa", + } + + hist = await review_brief_build._history_section( + call, _inputs(), [("app.counter::bump", "app/counter.py")] + ) + assert hist["rows"][0]["verdict"] == "unknown" + assert "regression_prs" not in hist["rows"][0] + assert rb.failed_reads({"history": hist}) == [] diff --git a/tests/unit/test_code_symbol_history.py b/tests/unit/test_code_symbol_history.py index 1e174154cc8..52148373dff 100644 --- a/tests/unit/test_code_symbol_history.py +++ b/tests/unit/test_code_symbol_history.py @@ -591,17 +591,18 @@ async def test_handler_orders_test_files_by_the_deployments_run_templates( def test_one_suites_files_do_not_crowd_out_another_suite() -> None: - suite_a = [f"tests/integration/test_a/configs/{c}.xml" for c in "abcd"] + suite_a = [f"spec/alpha/{c}.case" for c in "abcd"] row = sh.PrRow( pr_number=4, title="Fix reconnect", merged_at="2026-09-01T00:00:00", is_fix=True, touches_symbol="true", - files=[*suite_a, "tests/integration/test_b/test.py"], + files=[*suite_a, "spec/beta/a.case"], ) - files = _evidence([row])[0]["test_gate"]["files"] - assert files[:2] == [suite_a[0], "tests/integration/test_b/test.py"] + recipes = '[{"pattern": "^spec/([^/]+)/", "run": "./run-suite {g1}"}]' + files = _evidence([row], run_templates=recipes)[0]["test_gate"]["files"] + assert files[:2] == [suite_a[0], "spec/beta/a.case"] assert len(files) == 4