Skip to content

Commit 0d2ce06

Browse files
zlareb1claude
andauthored
The test gate touches only the edited definitions and labels every test with its evidence (#1707)
* The test gate touches only the edited definitions and labels every test with its evidence code.test_gate picked its seeds from hunk-header names and new-side hunk spans, read no classes, and listed a touched definition as `untested` whenever the static graph held no test edge to it. Against SWE-bench Verified gold patches and per-test coverage that list flagged tested and untested code alike. - The touched definitions are the innermost function or class holding a changed old-side line (the revision the index holds). A hunk sent without its lines changes what its header's old range says, so the hooks' zero-context headers read the same. A header name is used only for a definition the index holds no body extent for. code.impact's diff shape shares the rule. - A class's callers credit its `__init__` and `__new__`, and the callers of a function credit the functions nested in it. - Each test row says its kind of evidence in `why`: `changed_test`, `coverage`, `static_call`, `file_neighbor` (new: the test files calling other definitions of the edited files, one grouped read), `test_map`. `graph_hop` and `stem_partner` are gone. - `untested` holds only definitions a verified coverage run measured unexecuted. `unlinked` holds the ones no run measured and no call chain links a test to; a file-level row never clears it, and it is no obligation. - `epistemic` is `measured` or `lower_bound`, never `exact`. - The plugins say "the index links no test to" for `unlinked`, "measured unexecuted at <commit>" for `untested`, ask for a test only for the latter, and ask for file neighbours only up to four tests in all. Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * A hunk shorter than its header counts ends at the next file header A diff whose hunk carries fewer lines than its counts, followed by another file's `---`/`+++` header, read that header as a removed and an added line and lost the file. The header is now recognised when a hunk header follows it, or when the hunk has no line yet. The operations guide lists the evidence kinds instead of adding a table, so the cell positions of the page's other tables stay where its translations expect them. Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * File neighbours fill a short test-gate list, and a coverage run is read against a definition's body The gate listed up to `limit` file neighbours ahead of the test map, so thirty neighbour files pushed every map row off a default page, and a plugin of the previous release took each of them for a test to run. Neighbours say nothing about a touched definition: the server lists them only while the other kinds leave fewer than four rows. `stem_partner` is a kind again, and a test file a call chain links keeps that row ahead of a file-level map row, because a test file is listed once and the call-chain row names the test and the definition. On an index with an imported coverage run, rows in a covering test's file are 97% for `coverage`, 91% for `static_call`, 53% for `stem_partner` and 31% for `test_map`. A coverage run is read against every tier row's extent of a definition that is wider than one line. A compiler row may be the declaration line only; testing that line marked a function whose body ran as unexecuted under `epistemic: measured`. A definition with no wider extent is not measured. Text added directly above a definition touches it only when the added lines are all decorators, which needs the diff's lines; a new function added there is a change no definition answers for. In Python, lines appended as deep as the line above continue the definition that line ends. A file's removed ranges are merged before one walk, so the cost of a headers-only diff follows the file's extent and not what its hunk headers claim. `measured` also needs every changed source file to touch a definition, and `causes` keeps the call graph's causes under either answer. The hop-only `confidence` of a `static_call` row is gone: it came from two repositories and ignored the edge's own tier. A neighbour's `callees` counts a definition both tiers hold once. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> * A hunk header names the nearest same-named definition above it, found by bisection The fallback for a hunk whose lines sit in no definition walked every row of the file for each hunk. Rows are grouped by bare name in line order, so a headers-only diff of thousands of hunks costs a bisection each. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> * The test gate reads a coverage run against a definition's body lines, keeps same-named definitions apart and orders coverage rows by call chain and specificity - A coverage run is read against the lines after the first of every extent a tier holds of a definition at the run's commit. The first line is the declaration, which runs when the module is imported, under whichever test imports it first. The extents are matched by id in the read that carries their parsing commit, so tiers parsed at different commits are measured on the extent the run's commit holds. - Touched rows are no longer folded by qualified name. The store already folds the two tiers' rows of one definition where their spans coincide; rows that share a name and sit apart (a property's getter and setter) are different definitions, touched and measured apart. - A `coverage` row carries the specificity of its test-map row as `confidence`, and the test name, `hop`, `callers` and `via` of a call chain that links the file too. Within a kind a chain-linked file is first, then the more specific row. - `truncated` is also a cause when the read of the coverage rows was cut. - The wire comment, the feature page and the skill reference say that a `static_call` test is linked by a call chain and usually, not always, runs the definition, and that a change of test files only is `lower_bound` with no cause. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> * A run added below a definition's last line and indented less than it is documented as not placed The index holds no column for a definition. Where a class and its last method end on one line, text added below that line and indented less than it may be the method's (a statement after its last nested block) or the class's (a new method), and the two indents the diff shows cannot tell which. The run touches neither and counts in unmapped_changes, so the answer is lower_bound. The operations page and the docstring say so, and a test holds the three cases. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> --------- Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent ddebfd6 commit 0d2ce06

42 files changed

Lines changed: 5646 additions & 4023 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/features/code-index/operations.md‎

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ exists. These call shapes are not captured output from a document/code qualifica
403403
| `code.callers` | who calls this, `depth` hops; an override also reports the base declaration's callers |
404404
| `code.callees` | what this calls, `depth` hops |
405405
| `code.impact` | blast radius of a symbol, or of `files` / a `diff`: callers, tests reaching the change, co-change partners |
406-
| `code.test_gate` | which tests a change obliges, and which touched functions no test reaches |
406+
| `code.test_gate` | which tests a change obliges, which touched definitions a coverage run measured unexecuted, and which the index links no test to |
407407
| `code.tests_for` | which tests cover something |
408408
| `code.test_home` | where a new test belongs |
409409
| `code.coverage_claim` | "is this already tested?" |
@@ -436,7 +436,7 @@ for row in r.get("co_change_missing", []):
436436
print("usually changes with this diff:", row)
437437
```
438438

439-
The diff shape returns the symbols the hunks overlap, the tests that reach them, and
439+
The diff shape returns the functions the changed lines sit in, the tests that reach them, and
440440
`co_change_missing`; `files` alone treats every function in those files as changed.
441441
Both shapes return `owners`: recency-weighted PR authors over the seed paths, with
442442
`exclude_authors` (normally the change's own author) removed. The index holds merged
@@ -459,6 +459,79 @@ Report the indexed revision, the callers and tests found, the contract checks
459459
performed, and any consumers outside the available scope. A caller list identifies
460460
where to investigate; it does not establish that an API remains compatible.
461461

462+
### Find the tests a change obliges
463+
464+
`code.test_gate` takes `files` and/or a `diff` against the revision the index holds: the
465+
working tree against `HEAD`, a pull request against its merge base. Each changed line
466+
touches the innermost function or class it sits in, so a diff with three lines of context
467+
touches only the definitions it edits. Added lines that replace nothing touch the
468+
definition that holds the lines on both sides of them. When the diff carries its lines
469+
and not only its hunk headers, the added text decides two more cases: lines that are all
470+
decorators touch the definition below them, and in Python a run indented as deep as the
471+
line above it touches the definition that line ends. Text added directly above a
472+
definition is otherwise a new definition, which the index does not hold. A run added after
473+
a definition's last line and indented less than that line is not placed: the index holds
474+
no column for a definition, so the run may sit in that definition or in one around it (a
475+
method appended to a class whose last line is its last method's). A changed line outside
476+
every definition, or one that is not placed, touches nothing and adds `unmapped_changes`
477+
to `causes`; so does a changed source file that touches no definition.
478+
479+
Each row of `tests` is one test file with the kind of evidence in `why`, strongest first:
480+
481+
- `changed_test`: the file is in the diff. It says nothing about a touched definition; a
482+
changed test runs.
483+
- `coverage`: an imported coverage run the index verified measured the file executing a
484+
touched definition, named in `links_to`. `confidence` is the specificity of the test-map
485+
row that says so: how few tests share the most specific line the file's tests run. When
486+
a call chain links the file too, `evidence` names the chain's test and the row carries
487+
its `hop`, `callers` and `via`.
488+
- `static_call`: a call chain links one of the file's tests to a touched definition
489+
(`links_to`), with the nearest `hop` and how many of its tests do (`callers`).
490+
- `stem_partner`: the file's name holds the stem of an edited file (`test_foo.py` for
491+
`foo.py`), among the test map's rows. It says nothing about a touched definition.
492+
- `test_map`: mined history ties the file to an edited file, and says nothing about a
493+
touched definition.
494+
- `file_neighbor`: the file calls `callees` other definitions of the edited files and says
495+
nothing about a touched definition. Neighbours are a lead when little else is known:
496+
they are listed only while the other kinds leave fewer than four rows, and never more
497+
than fill the list to four.
498+
499+
A `static_call` row carries `via` when the chain does not start at the definition itself:
500+
`constructor` (the test calls the class of a touched `__init__` or `__new__`), `enclosing`
501+
(it calls the function a touched nested function is defined in) or `fixture` (it reaches
502+
through a fixture). Within a kind a file a call chain names a test in is first, the
503+
nearest hop before the others, then the file linked to more of the touched definitions,
504+
then the one with more tests doing so, then the more specific `coverage` row. A test file
505+
is listed once, under its strongest kind.
506+
507+
The touched definitions land in two lists with different meanings:
508+
509+
- `untested` holds the definitions an imported coverage run measured unexecuted, with the
510+
run's `commit`. It is empty unless such a run exists at a revision the index verified.
511+
The run is read against a definition's body: the lines after the first of every extent
512+
a tier holds of it at the run's commit. The first line is the declaration, which runs
513+
when the module is imported, under whichever test imports it first; whether it ran says
514+
nothing about the body, so a definition the index holds only a one-line extent for is
515+
never measured. The statements of a class body also run at import: a class reads
516+
executed when a test is the first to import its module. Definitions that share a name in
517+
one file, such as a property's getter and setter, are touched and measured apart.
518+
- `unlinked` holds the definitions no coverage run measured and no call chain links a test
519+
to. It does not say that no test runs them: tests reach code through fixtures,
520+
string-dispatched entry points and public APIs the call graph holds no edge for. A
521+
`stem_partner`, `test_map` or `file_neighbor` row never takes a definition off this list.
522+
523+
`obligations` is true while `tests` or `untested` is non-empty. A green test says as much
524+
as its row's `why`: a `coverage` test was measured executing a touched definition; a
525+
`static_call` test is linked to one by a call chain and usually, not always, runs it; a
526+
`stem_partner`, `test_map` or `file_neighbor` test is about the file and may not run the
527+
changed code. `epistemic` is `measured` when a verified coverage run settled every touched
528+
definition, every changed line sat in one and every changed source file touched one, and
529+
`lower_bound` otherwise; the op never answers `exact`. `causes` lists what limits the
530+
answer under either value: the call graph's own causes limit `tests`, and `truncated` also
531+
says that the read of the coverage rows was cut. A change of test files only touches no
532+
source definition: it is `lower_bound` with no cause, because the gate lists the changed
533+
tests and does not look for the tests that use a changed test helper.
534+
462535
## History, PRs and releases
463536

464537
These read the PR plane that the `code_pr_history` worker fills from GitHub

‎docs/reference/operations.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Fields for every `code` op: [operations/code.md](operations/code.md).
234234
| [`code.setting_facts`](operations/code.md#codesetting_facts) | One ClickHouse setting, the four places that define it: its declaration and tier (production / important / beta / experimental / obsolete), every default change with the release it shipped in… | viewer | read | no | |
235235
| [`code.symbol`](operations/code.md#codesymbol) | Find an exact definition by name or path:line. | viewer | read | yes | |
236236
| [`code.symbol_history`](operations/code.md#codesymbol_history) | The regression history of one function: the merged PRs that touched it (with linked issues, reverts, inline review comments inside its span), and — through the tracker namespace bound to this code… | viewer | read | no | |
237-
| [`code.test_gate`](operations/code.md#codetest_gate) | The pre-PR question in one call: for THIS change, which tests must run, and which touched code no test reaches. | viewer | read | no | |
237+
| [`code.test_gate`](operations/code.md#codetest_gate) | The pre-PR question in one call: for THIS change, which tests must run, and which touched definitions no test is shown to run. | viewer | read | no | |
238238
| [`code.test_home`](operations/code.md#codetest_home) | Where does a new test case belong? | viewer | read | no | |
239239
| [`code.tests_for`](operations/code.md#codetests_for) | Which stateless tests carry EVERY named facet: the tests that `SET` a setting, call a function, create an `ENGINE`, read a `system.*` table, use a `FORMAT`, carry a `-- Tags:` tag, or expect an error… | viewer | read | no | |
240240
| [`code.trace`](operations/code.md#codetrace) | Paste a stack trace / backtrace; get each frame resolved to its definition in one call — the incident-workflow entry point. | viewer | read | yes | |

‎docs/reference/operations/code.md‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,8 @@ Symbol-shaped (name/symbol_id) or diff-shaped (files/diff) blast radius.
873873
| `name` | `str` | `''` | Symbol shape: the seed's bare, qualified or partly qualified name, or `path:line`. |
874874
| `symbol_id` | `str` | `''` | Symbol shape: an index symbol id for the seed; wins over `name`. |
875875
| `depth` | `int` | `2` | How many caller hops the radius walks from the seeds (1–2). |
876-
| `files` | `list[str]` | *(computed)* | Diff shape: repo-relative changed paths, and/or a unified diff whose hunk line ranges narrow the touched set from whole files to the symbols actually edited. |
877-
| `diff` | `str` | `''` | A unified diff (at most 200,000 chars); its hunk ranges pick the edited functions as seeds. |
876+
| `files` | `list[str]` | *(computed)* | Diff shape: repo-relative changed paths, and/or a unified diff whose changed lines narrow the touched set from whole files to the symbols actually edited. |
877+
| `diff` | `str` | `''` | A unified diff (at most 200,000 chars) against the revision the index holds; each changed line seeds the innermost function it sits in. |
878878
| `exclude_authors` | `list[str]` | *(computed)* | Left out of `owners`: the change's own author(s) are not its reviewers. |
879879
| `summary_only` | `bool` | `False` | Hub-safe ergonomics. |
880880
| `per_hop_limit` | `int` | `200` | At most this many `impacted_symbols` rows from each hop (1–500). |
@@ -889,7 +889,7 @@ Symbol-shaped (name/symbol_id) or diff-shaped (files/diff) blast radius.
889889
| `impacted_tests` | `list[dict[str, Any]]` | Tests the test map ties to the seed and impacted paths: {test_path, src_path, confidence}. |
890890
| `co_change_files` | `list[dict[str, Any]]` | Files changed in the same merged PRs as the seed paths, most often first ({path, prs}, at most 20): the last 10 PRs for the symbol shape, 50 for the diff shape. |
891891
| `blast_radius_score` | `float` | impacted/50 + tests/40, capped at 1. |
892-
| `touched_symbols` | `list[dict[str, Any]]` | Diff shape only: the symbols the change touches (hunk-overlap when a diff was given, else every function in the files), and the files that historically co-change with the touched set but are absent from it — the "did you forget to update… |
892+
| `touched_symbols` | `list[dict[str, Any]]` | Diff shape only: the symbols the change touches (the functions its changed lines sit in when a diff was given, else every function in the files), and the files that historically co-change with the touched set but are absent from it — the… |
893893
| `co_change_missing` | `list[dict[str, Any]]` | Diff shape: co-change files absent from the change ({path, prs, of}, at most 5, support at least 4 PRs and 15%); empty for the symbol shape. |
894894
| `owners` | `list[dict[str, Any]]` | Who to ask: {author, share, prs, reviews, last_merged_at} from merged PRs over the seed paths — the PRs a person AUTHORED (`prs`) and the ones they REVIEWED (`reviews`, inline comments), recency-decayed (120-day half-life), share floor, at… |
895895
| `reverts` | `list[dict[str, Any]]` | Merged PRs over the seed paths that were REVERTS ({pr_number, title, merged_at}, newest first, <=5): the one kind of history that says what not to do, invisible to symbol lookups (the code is back) and to co-change (same files as the… |
@@ -1720,7 +1720,7 @@ The regression history of one function: the merged PRs that touched it (with lin
17201720

17211721
## `code.test_gate`
17221722

1723-
The pre-PR question in one call: for THIS change, which tests must run, and which touched code no test reaches.
1723+
The pre-PR question in one call: for THIS change, which tests must run, and which touched definitions no test is shown to run.
17241724

17251725
`POST /v1/code.test_gate` · MCP `loom_code_test_gate` · role `viewer` · read · not listed under the MCP `all` toolset
17261726

@@ -1732,24 +1732,27 @@ The pre-PR question in one call: for THIS change, which tests must run, and whic
17321732
| `user_id` | `str` | `'-'` | The end user the row belongs to; `'-'` for none. |
17331733
| `consumer` | `str` | `''` | trace attribution: which integration is calling (clickgap\|claude-code\|…) |
17341734
| `files` | `list[str]` | *(computed)* | Changed file paths; a test file here is itself a test to run. |
1735-
| `diff` | `str` | `''` | A unified diff; its hunks (line spans, hunk-header names) pick the touched functions. |
1735+
| `diff` | `str` | `''` | A unified diff against the revision the index holds (the working tree against HEAD, a pull request against its merge base). |
17361736
| `depth` | `int` | `2` | Reverse-edge hops to look for tests through. |
1737-
| `limit` | `int` | `30` | At most this many rows in each of `tests` and `untested` (at most 200). |
1737+
| `limit` | `int` | `30` | At most this many rows in each of `tests`, `untested` and `unlinked` (at most 200). |
17381738

17391739
| Output field | Type | Meaning |
17401740
| --- | --- | --- |
1741-
| `tests` | `list[dict[str, Any]]` | {test_path, why, evidence, run, run_unknown, [src_path], [confidence], [hop]} why in {changed_test, stem_partner, test_map, graph_hop}, strongest first. |
1742-
| `untested` | `list[dict[str, Any]]` | Touched source symbols no test reaches by any evidence class: {qualified_name, path, start_line}. |
1741+
| `tests` | `list[dict[str, Any]]` | {test_path, why, evidence, run, run_unknown} per test file, strongest evidence first. |
1742+
| `untested` | `list[dict[str, Any]]` | Touched source definitions a coverage run measured unexecuted, at a commit the index verified: {qualified_name, path, start_line, commit}. |
1743+
| `unlinked` | `list[dict[str, Any]]` | Touched source definitions no coverage run measured and no call chain links a test to: {qualified_name, path, start_line}. |
17431744
| `changed_files` | `list[str]` | The change as the gate saw it. |
1744-
| `touched_symbols` | `list[dict[str, Any]]` | The source symbols the change touches, {qualified_name, path, start_line, tier}, by path and line (first 200). |
1745-
| `obligations` | `bool` | True while either list is non-empty: run the tests, then rely on green; write a test for (or explain) the untested rows. |
1745+
| `touched_symbols` | `list[dict[str, Any]]` | The source definitions the change touches, {qualified_name, path, start_line, tier}, by path and line (first 200). |
1746+
| `obligations` | `bool` | True while `tests` or `untested` is non-empty: run the tests, whose green says as much as each row's `why` (a `coverage` test was measured executing a touched definition; a `static_call` test is linked to one by a call chain and usually… |
17461747
| `tests_total` | `int` | Rows of `tests` before `limit`. |
17471748
| `untested_total` | `int` | Rows of `untested` before `limit`. |
1749+
| `unlinked_total` | `int` | Rows of `unlinked` before `limit`. |
17481750
| `tests_capped` | `bool` | True when `limit` cut `tests` short of `tests_total`. |
17491751
| `untested_capped` | `bool` | True when `limit` cut `untested` short of `untested_total`. |
1750-
| `counts_floor` | `bool` | Same epistemic contract as code.callers: the graph is a floor, so "no test reaches this" means none the index can see. |
1751-
| `epistemic` | `str` | Epistemic envelope, as on code.callers: "exact" when the compiler tier covers every seed file, no call site named like a seed was declined, and no override seed lacks its base; otherwise "lower_bound" with `causes` from {unresolved_calls… |
1752-
| `causes` | `list[str]` | Why `epistemic` is lower_bound (values above); [] when it is exact. |
1752+
| `unlinked_capped` | `bool` | True when `limit` cut `unlinked` short of `unlinked_total`. |
1753+
| `counts_floor` | `bool` | Same epistemic contract as code.callers: the graph is a floor, so a test missing from `tests` is one the index cannot see. |
1754+
| `epistemic` | `str` | `measured` when a verified coverage run settled every touched definition, every changed line sat in one and every changed source file touched one; otherwise `lower_bound`. |
1755+
| `causes` | `list[str]` | What limits the answer, from code.callers' causes (unresolved_calls, ambiguous_calls, treesitter_only_files, external_calls, truncated: a hop read or the read of the coverage rows hit its limit), which limit `tests` under either… |
17531756
| `by_hop_counts` | `dict[int, int]` | Distinct symbols reached per hop BEFORE any slicing: {1: n, 2: m}. |
17541757
| `trace_run_id` | `str` | Id of this call's row in `loom.code_search_trace`. |
17551758

‎integrations/claude-code-plugin/.claude-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "loom",
33
"displayName": "ClickHouse Loom",
4-
"version": "1.2.76",
4+
"version": "1.2.77",
55
"description": "Shared long-term memory and code intelligence for Claude Code, self-hosted on ClickHouse. MCP tools to save and recall decisions, preferences and corrections across sessions and teammates; lifecycle hooks that capture each session with no model call; a code index that answers where-is, who-calls and blast-radius questions with line-accurate units instead of whole-file reads.",
66
"author": {
77
"name": "ClickHouse"

0 commit comments

Comments
 (0)