Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 75 additions & 2 deletions docs/features/code-index/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ exists. These call shapes are not captured output from a document/code qualifica
| `code.callers` | who calls this, `depth` hops; an override also reports the base declaration's callers |
| `code.callees` | what this calls, `depth` hops |
| `code.impact` | blast radius of a symbol, or of `files` / a `diff`: callers, tests reaching the change, co-change partners |
| `code.test_gate` | which tests a change obliges, and which touched functions no test reaches |
| `code.test_gate` | which tests a change obliges, which touched definitions a coverage run measured unexecuted, and which the index links no test to |
| `code.tests_for` | which tests cover something |
| `code.test_home` | where a new test belongs |
| `code.coverage_claim` | "is this already tested?" |
Expand Down Expand Up @@ -436,7 +436,7 @@ for row in r.get("co_change_missing", []):
print("usually changes with this diff:", row)
```

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

### Find the tests a change obliges

`code.test_gate` takes `files` and/or a `diff` against the revision the index holds: the
working tree against `HEAD`, a pull request against its merge base. Each changed line
touches the innermost function or class it sits in, so a diff with three lines of context
touches only the definitions it edits. Added lines that replace nothing touch the
definition that holds the lines on both sides of them. When the diff carries its lines
and not only its hunk headers, the added text decides two more cases: lines that are all
decorators touch the definition below them, and in Python a run indented as deep as the
line above it touches the definition that line ends. Text added directly above a
definition is otherwise a new definition, which the index does not hold. A run added after
a definition's last line and indented less than that line is not placed: the index holds
no column for a definition, so the run may sit in that definition or in one around it (a
method appended to a class whose last line is its last method's). A changed line outside
every definition, or one that is not placed, touches nothing and adds `unmapped_changes`
to `causes`; so does a changed source file that touches no definition.

Each row of `tests` is one test file with the kind of evidence in `why`, strongest first:

- `changed_test`: the file is in the diff. It says nothing about a touched definition; a
changed test runs.
- `coverage`: an imported coverage run the index verified measured the file executing a
touched definition, named in `links_to`. `confidence` is the specificity of the test-map
row that says so: how few tests share the most specific line the file's tests run. When
a call chain links the file too, `evidence` names the chain's test and the row carries
its `hop`, `callers` and `via`.
- `static_call`: a call chain links one of the file's tests to a touched definition
(`links_to`), with the nearest `hop` and how many of its tests do (`callers`).
- `stem_partner`: the file's name holds the stem of an edited file (`test_foo.py` for
`foo.py`), among the test map's rows. It says nothing about a touched definition.
- `test_map`: mined history ties the file to an edited file, and says nothing about a
touched definition.
- `file_neighbor`: the file calls `callees` other definitions of the edited files and says
nothing about a touched definition. Neighbours are a lead when little else is known:
they are listed only while the other kinds leave fewer than four rows, and never more
than fill the list to four.

A `static_call` row carries `via` when the chain does not start at the definition itself:
`constructor` (the test calls the class of a touched `__init__` or `__new__`), `enclosing`
(it calls the function a touched nested function is defined in) or `fixture` (it reaches
through a fixture). Within a kind a file a call chain names a test in is first, the
nearest hop before the others, then the file linked to more of the touched definitions,
then the one with more tests doing so, then the more specific `coverage` row. A test file
is listed once, under its strongest kind.

The touched definitions land in two lists with different meanings:

- `untested` holds the definitions an imported coverage run measured unexecuted, with the
run's `commit`. It is empty unless such a run exists at a revision the index verified.
The run is read against a definition's body: the lines after the first of every extent
a tier holds of it at the run's commit. The first line is the declaration, which runs
when the module is imported, under whichever test imports it first; whether it ran says
nothing about the body, so a definition the index holds only a one-line extent for is
never measured. The statements of a class body also run at import: a class reads
executed when a test is the first to import its module. Definitions that share a name in
one file, such as a property's getter and setter, are touched and measured apart.
- `unlinked` holds the definitions no coverage run measured and no call chain links a test
to. It does not say that no test runs them: tests reach code through fixtures,
string-dispatched entry points and public APIs the call graph holds no edge for. A
`stem_partner`, `test_map` or `file_neighbor` row never takes a definition off this list.

`obligations` is true while `tests` or `untested` is non-empty. A green test says as much
as its 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, not always, runs it; a
`stem_partner`, `test_map` or `file_neighbor` test is about the file and may not run the
changed code. `epistemic` is `measured` when a verified coverage run settled every touched
definition, every changed line sat in one and every changed source file touched one, and
`lower_bound` otherwise; the op never answers `exact`. `causes` lists what limits the
answer under either value: the call graph's own causes limit `tests`, and `truncated` also
says that the read of the coverage rows was cut. A change of test files only touches no
source definition: it is `lower_bound` with no cause, because the gate lists the changed
tests and does not look for the tests that use a changed test helper.

## History, PRs and releases

These read the PR plane that the `code_pr_history` worker fills from GitHub
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Fields for every `code` op: [operations/code.md](operations/code.md).
| [`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 | |
| [`code.symbol`](operations/code.md#codesymbol) | Find an exact definition by name or path:line. | viewer | read | yes | |
| [`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 | |
| [`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 | |
| [`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 | |
| [`code.test_home`](operations/code.md#codetest_home) | Where does a new test case belong? | viewer | read | no | |
| [`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 | |
| [`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 | |
Expand Down
29 changes: 16 additions & 13 deletions docs/reference/operations/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ Symbol-shaped (name/symbol_id) or diff-shaped (files/diff) blast radius.
| `name` | `str` | `''` | Symbol shape: the seed's bare, qualified or partly qualified name, or `path:line`. |
| `symbol_id` | `str` | `''` | Symbol shape: an index symbol id for the seed; wins over `name`. |
| `depth` | `int` | `2` | How many caller hops the radius walks from the seeds (1–2). |
| `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. |
| `diff` | `str` | `''` | A unified diff (at most 200,000 chars); its hunk ranges pick the edited functions as seeds. |
| `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. |
| `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. |
| `exclude_authors` | `list[str]` | *(computed)* | Left out of `owners`: the change's own author(s) are not its reviewers. |
| `summary_only` | `bool` | `False` | Hub-safe ergonomics. |
| `per_hop_limit` | `int` | `200` | At most this many `impacted_symbols` rows from each hop (1–500). |
Expand All @@ -889,7 +889,7 @@ Symbol-shaped (name/symbol_id) or diff-shaped (files/diff) blast radius.
| `impacted_tests` | `list[dict[str, Any]]` | Tests the test map ties to the seed and impacted paths: {test_path, src_path, confidence}. |
| `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. |
| `blast_radius_score` | `float` | impacted/50 + tests/40, capped at 1. |
| `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… |
| `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… |
| `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. |
| `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… |
| `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… |
Expand Down Expand Up @@ -1720,7 +1720,7 @@ The regression history of one function: the merged PRs that touched it (with lin

## `code.test_gate`

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

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

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

| Output field | Type | Meaning |
| --- | --- | --- |
| `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. |
| `untested` | `list[dict[str, Any]]` | Touched source symbols no test reaches by any evidence class: {qualified_name, path, start_line}. |
| `tests` | `list[dict[str, Any]]` | {test_path, why, evidence, run, run_unknown} per test file, strongest evidence first. |
| `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}. |
| `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}. |
| `changed_files` | `list[str]` | The change as the gate saw it. |
| `touched_symbols` | `list[dict[str, Any]]` | The source symbols the change touches, {qualified_name, path, start_line, tier}, by path and line (first 200). |
| `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. |
| `touched_symbols` | `list[dict[str, Any]]` | The source definitions the change touches, {qualified_name, path, start_line, tier}, by path and line (first 200). |
| `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… |
| `tests_total` | `int` | Rows of `tests` before `limit`. |
| `untested_total` | `int` | Rows of `untested` before `limit`. |
| `unlinked_total` | `int` | Rows of `unlinked` before `limit`. |
| `tests_capped` | `bool` | True when `limit` cut `tests` short of `tests_total`. |
| `untested_capped` | `bool` | True when `limit` cut `untested` short of `untested_total`. |
| `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. |
| `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… |
| `causes` | `list[str]` | Why `epistemic` is lower_bound (values above); [] when it is exact. |
| `unlinked_capped` | `bool` | True when `limit` cut `unlinked` short of `unlinked_total`. |
| `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. |
| `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`. |
| `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… |
| `by_hop_counts` | `dict[int, int]` | Distinct symbols reached per hop BEFORE any slicing: {1: n, 2: m}. |
| `trace_run_id` | `str` | Id of this call's row in `loom.code_search_trace`. |

Expand Down
2 changes: 1 addition & 1 deletion integrations/claude-code-plugin/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "loom",
"displayName": "ClickHouse Loom",
"version": "1.2.76",
"version": "1.2.77",
"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.",
"author": {
"name": "ClickHouse"
Expand Down
Loading
Loading