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
4 changes: 2 additions & 2 deletions docs/features/integrations/claude-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ Loom tests for src/app/router.py: .venv/bin/python -m pytest tests/test_router.p
the index links no test to. A held stop costs the session one more model request, so
any test run since that change lets the stop pass: a shell command that starts a test
runner and finished no earlier than the newest write among the code files the session
changed. A documentation or prose file (`.md`, `.rst`, `.txt`, a changelog) written
after the run holds nothing. The gate reads that command for a runner's name only. Which tests ran and how they went cannot be read
changed. A documentation or prose file (`.md`, `.rst`, a changelog, a `.txt` file under `docs/`)
written after the run holds nothing. The gate reads that command for a runner's name only. Which tests ran and how they went cannot be read
reliably from shell commands, so that judgement stays with the agent and with CI. The
plugin README lists the runners under **Stops that pass**.

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.69",
"version": "1.2.71",
"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
2 changes: 1 addition & 1 deletion integrations/claude-code-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ the duplicate, run `claude mcp remove <name> -s user`.

**Tests at edit time.** The test gate names a file's tests on the tool call that changes it, where the agent is still working on the file. For a source file they are the tests the index links to it through its name, the test map or the call graph, each of them present in the checkout, with the tests that have no known runner listed by path; for a test file, the file's own command. A file with no test to name in the checkout gets the changed functions the index links no test to instead (`the index links no test to Router::match`), worded as the index's view, because its call graph is a floor. A file is asked about once per session, at its first change, so a function changed later in the same file is not named; a file the server gave no answer for is asked about once more, at the next call that names it; at most four files are asked about per tool call. A test is named once per session, so the test you edit after its source file adds no second line. A test the tool call's own command runs is not named on the result of that run: its command stands there whole, in this checkout, so `pytest tests/test_a.py::test_one`, `docker exec app pytest tests/test_a.py` and `echo "pytest tests/test_a.py"` still get the line.

**Stops that pass.** By default the test gate holds the end of a session only when the session ran no test since its last code change. Whether a session ran the right tests, and how they went, cannot be read reliably from its shell commands: a session that runs the whole suite, compares against a stashed tree or pipes pytest through `grep` has run the tests in a way no fixed rule reads, and a gate that holds the stop on that reading holds sessions that did the work. So the stop passes, before anything is asked of the server, when the transcript holds a shell command that starts a test runner and finished no earlier than the newest write among the code files the session changed. A changed file that is documentation or prose by its name (`.md`, `.mdx`, `.rst`, `.adoc`, `.txt` other than `CMakeLists.txt` and a requirements file, or a `CHANGELOG`, `CHANGES`, `HISTORY` or `NEWS` file) is left out of that comparison, so a note written after the run holds nothing; so is a deleted file. A runner is `pytest`, `unittest`, `tox`, `nox`, `jest`, `vitest`, `mocha`, `nextest`, `rspec`, `phpunit`, `ctest` or `clickhouse-test`, or `go`, `cargo`, `npm`, `pnpm`, `yarn`, `bun`, `deno`, `make`, `mvn`, `gradle`, `dotnet`, `swift`, `bazel`, `mix`, `rake` or `node` with an argument in which `test` or `tests` follows no letter and no lower-case letter follows it (`make test-unit`, `node --test`, `gradle :app:test`, `gradlew testDebugUnitTest`, but not `npm install x@latest` or `npm install @testing-library/react`). The command's output is not read: a run that failed, ran other tests or ran in a container passes, and so does a command that only names a runner, such as `grep -rn pytest .`. A session that wrote a changed code file after its last such command, or that ran none, is held once per distinct change with the tests to run and the functions the index links no test to; a harness the list does not name is not seen, and that stop is held once too. A latest prompt that ends with "Do not run the tests" passes when the gate names tests the checkout has. With no transcript the stop is not held. A team that wants the stop held until the named tests ran on the final tree sets `LOOM_TEST_GATE=block` in the environment Claude Code starts in; the two paragraphs below describe that mode, which names nothing at edit time.
**Stops that pass.** By default the test gate holds the end of a session only when the session ran no test since its last code change. Whether a session ran the right tests, and how they went, cannot be read reliably from its shell commands: a session that runs the whole suite, compares against a stashed tree in one command or pipes pytest through `grep` has run the tests in a way no fixed rule reads, and a gate that holds the stop on that reading holds sessions that did the work. So the stop passes, before anything is asked of the server, when the transcript holds a shell command that starts a test runner and finished no earlier than the newest write among the code files the session changed. A changed file that is documentation or prose by its name is left out of that comparison, so a note written after the run holds nothing; so is a deleted file. Such a name ends in `.md`, `.mdx`, `.markdown`, `.rst`, `.adoc` or `.asciidoc`, or is `CHANGELOG`, `CHANGES`, `HISTORY` or `NEWS`. A `.txt` file is one when it has one of those four names or is `README.txt`, `LICENSE.txt`, `NOTICE.txt` or `AUTHORS.txt`, or lies under a `docs` or `doc` directory with no `requirements` or `constraints` in its path below it (`docs/releases/5.2.txt`); any other `.txt` file is code, as a requirements file or a test fixture is. A `git stash pop` in a later command than the run rewrites the changed files, so that stop is held. A runner is `pytest`, `unittest`, `tox`, `nox`, `jest`, `vitest`, `mocha`, `nextest`, `rspec`, `phpunit`, `ctest` or `clickhouse-test`, or `go`, `cargo`, `npm`, `pnpm`, `yarn`, `bun`, `deno`, `make`, `mvn`, `gradle`, `gradlew`, `dotnet`, `swift`, `bazel`, `mix`, `rake` or `node` with an argument in which `test` or `tests` follows no letter and no lower-case letter follows it (`make test-unit`, `node --test`, `gradle :app:test`, `gradlew testDebugUnitTest`, but not `make latest`, `go vet ./internal/testutil/...` or `cargo build -p testcontainers`); or `make`, `npm`, `pnpm`, `yarn`, `bun` or `rake` with a target or a script whose name starts with `test` (`make testall`, `npm run testci`); or `gradle` or `gradlew` with a task that ends in `Test` after a lower-case letter (`gradlew integrationTest`, but not `gradlew compileTestJava`). A name after `install`, `uninstall`, `add`, `i`, `ci`, `get`, `remove`, `rm`, `update`, `upgrade`, `download` or `require` in the same simple command is a package, not a run (`pip install -U pytest`, `npm i -D @types/jest`, `yarn remove jest`), and neither the word after `-x` (`gradle build -x test`) nor `test.skip` (`mvn package -Dmaven.test.skip=true`) is one. A backslash at a line's end joins the next line to the command. Two shapes are misread: a build tool's target that has a verb's name hides the run after it, so `make install test` and `mvn clean install test` are taken for no run and that stop is held once; and a target that only builds counts when its name reads as a run (`gradlew assembleAndroidTest`, `make testdata`). The command's output is not read: a run that failed, ran other tests or ran in a container passes, and so does a command that only names a runner, such as `grep -rn pytest .`. A session that wrote a changed code file after its last such command, or that ran none, is held once per distinct change with the tests to run and the functions the index links no test to; a harness the list does not name is not seen, and that stop is held once too. A latest prompt that ends with "Do not run the tests" passes when the gate names tests the checkout has. With no transcript the stop is not held. In a Codex rollout the session's changes are read from `apply_patch` and from the shell tool under each of its names (`exec`, `exec_command`, `shell`, `shell_command`, `container.exec`), so a rollout that changed a file through any of them is held, with `LOOM_TEST_GATE=block` too. A team that wants the stop held until the named tests ran on the final tree sets `LOOM_TEST_GATE=block` in the environment Claude Code starts in; the two paragraphs below describe that mode, which names nothing at edit time.

**Untested functions.** The index's call graph is a floor: a test may reach a function the graph holds no edge to, such as a constructor the test calls by building the object. Beside tests to run that the checkout has, the reason of a held stop therefore lists the functions as the index's view, `the index links no test to: … (the tests named here may still reach it)`. With no such test it reads `no test reaches: …` and asks for a test.

Expand Down
9 changes: 6 additions & 3 deletions integrations/claude-code-plugin/hooks/HOOKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ detached (`lib/flush-job.mjs` holds its job shapes and delivery policy).
At Stop, with uncommitted changes this session made in a loom-indexed
repo (dirty paths the transcript shows an edit tool targeted or a shell
command named, written since the session's first row; a tree left dirty
before the session gates nothing), it sends the change's paths, hunk
before the session gates nothing; in a Codex rollout the calls read are
`apply_patch` and the shell tool under each name `rolloutShell` takes,
in either mode), it sends the change's paths, hunk
ranges and function names only (`diffHeaders`) to code.test_gate for its
obligations and blocks the stop once per distinct change with a reason
naming them. By default a stop passes, and asks the server nothing, when
Expand All @@ -358,8 +360,9 @@ detached (`lib/flush-job.mjs` holds its job shapes and delivery policy).
(`testedSince`, `lastCodeChange`): the command's text is read for a
runner's name only, not for which tests ran or how they went, so a run
that failed, was piped or ran between `git stash` and `git stash pop`
passes, in a Claude Code transcript or a Codex rollout. With no
transcript the default holds no stop.
in the same command passes, in a Claude Code transcript or a Codex
rollout; a pop in a later command rewrites the changed files, and that
stop is held. With no transcript the default holds no stop.
With LOOM_TEST_GATE=block nothing is printed at edit time, and a Claude
Code stop passes only when its transcript already answers the ask to run
the named tests (`runAnswered` in lib/test-gate.mjs); a Codex rollout
Expand Down
65 changes: 47 additions & 18 deletions integrations/claude-code-plugin/lib/test-gate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export function sessionScope(changed, objs, { root, cwd } = {}) {
const call = o.payload || {};
if (
["custom_tool_call", "function_call"].includes(call.type) &&
["exec", "exec_command", "shell", "apply_patch"].includes(call.name)
(rolloutShell(call.name) || call.name === "apply_patch")
) {
const input = call.input ?? call.arguments;
if (typeof input === "string") commands.push(input);
Expand Down Expand Up @@ -629,16 +629,40 @@ function runsHere(command, run) {
}

// A shell command that starts a test runner, wrapped or piped in any way: a
// program `code.test_gate` names a run with or a common other one, or a
// build tool with an argument in which `test` or `tests` follows no letter
// and no lower-case letter follows it (`make test-unit`, `npm run test`,
// `node --test`, `gradle :app:test`, `gradlew testDebugUnitTest`). `import
// pytest`, `pip install pytest`, `pytest.raises`, `npm install x@latest`,
// `npm install @testing-library/react` and `node scripts/attest.js` are not
// program `code.test_gate` names a run with or a common other one; a build
// tool with an argument in which `test` or `tests` follows no letter and no
// lower-case letter follows it (`make test-unit`, `npm run test`, `node
// --test`, `gradle :app:test`, `gradlew testDebugUnitTest`); a tool that runs
// a target or a script by its name, with a name that starts with `test`
// (`make testall`, `npm run testci`); or Gradle with a task that ends in
// `Test` after a lower-case letter (`gradlew integrationTest`). `import
// pytest`, `pytest.raises`, `make latest`, `go vet ./internal/testutil/...`,
// `cargo build -p testcontainers` and `gradlew compileTestJava` are not
// runs. A command that only mentions a runner counts: what is read is
// whether the session ran a test at all.
const RUNNER =
/(?<![\w.-])(?:(?<!(?:import|install)\s)(?:py\.?test|unittest|tox|nox|jest|vitest|mocha|nextest|rspec|phpunit|ctest|clickhouse-test)(?![\w.-])|(?:go|cargo|npm|pnpm|yarn|bun|deno|make|mvn|gradle|gradlew|dotnet|swift|bazel|mix|rake|node)\s[^\n;|&]*(?<![A-Za-z])tests?(?![a-z]))/;
//
// After one of these verbs earlier in the simple command the name is a
// package: `pip install -U pytest`, `npm i -D @types/jest`, `yarn remove
// jest`, `go get github.com/stretchr/testify`. A flag is no verb: `npx
// --no-install jest` and `docker run --rm app pytest` run. A build tool's
// target of a verb's name hides the run after it: `make install test` is
// read as none.
const FETCHED = String.raw`\s(?:(?:un)?install|add|i|ci|get|remove|rm|update|upgrade|download|require)\s[^\n;|&]*`;
// What a build tool is told to leave out is no run, for every tool of the
// list: the word after `-x`, where Gradle takes a task to exclude (`gradle
// build -x test`), and `test.skip`, Maven's property (`mvn package
// -Dmaven.test.skip=true`).
const LEFT_OUT = String.raw`\s-x\s+\S*`;
const RUNNER = new RegExp(
String.raw`(?<![\w.-])(?:(?<!import\s)(?:py\.?test|unittest|tox|nox|jest|vitest|mocha|nextest|rspec|phpunit|ctest|clickhouse-test)(?![\w.-])(?<!${FETCHED})` +
String.raw`|(?:go|cargo|npm|pnpm|yarn|bun|deno|make|mvn|gradle|gradlew|dotnet|swift|bazel|mix|rake|node)\s[^\n;|&]*(?<![A-Za-z])tests?(?![a-z]|\.skip)(?<!${FETCHED}|${LEFT_OUT})` +
String.raw`|(?:make|npm|pnpm|yarn|bun|rake)\s[^\n;|&]*(?<=\s)test[a-z](?<!${FETCHED})` +
String.raw`|gradlew?\s[^\n;|&]*[a-z]Test(?![A-Za-z])(?<!${LEFT_OUT}))`,
);

/** True when `command` starts a test runner (`RUNNER`), read as the shell
* reads it: a backslash at a line's end joins the next line to it. */
const startsRunner = (command) => RUNNER.test(command.replace(/\\\n/g, ""));

/** True for the name of a Codex rollout's shell tool, under any of the names
* `normalizeToolName` folds onto Bash. */
Expand All @@ -662,8 +686,9 @@ function rolloutCommand(call) {
* True when the transcript holds a shell command that starts a test runner
* (`RUNNER`) and finished at or after `since` (epoch ms), or has no dated
* result: Claude Code rows and Codex rollout calls, sidechains skipped. Its
* output is not read, so a run that failed, was piped into `grep` or ran
* between `git stash` and `git stash pop` counts.
* output is not read, so a run that failed or was piped into `grep` counts.
* So does one between `git stash` and `git stash pop` in the same command; a
* pop in a later command rewrites the changed files after the run.
*/
export function testedSince(objs, since) {
const done = new Map();
Expand All @@ -673,7 +698,7 @@ export function testedSince(objs, since) {
if (o?.type === "response_item") {
const call = o.payload || {};
if (/_output$/.test(call.type)) done.set(call.call_id, at);
else if (rolloutShell(call.name) && RUNNER.test(rolloutCommand(call))) {
else if (rolloutShell(call.name) && startsRunner(rolloutCommand(call))) {
runs.push(call.call_id);
}
continue;
Expand All @@ -685,7 +710,7 @@ export function testedSince(objs, since) {
o.type === "assistant" &&
b?.type === "tool_use" &&
["Bash", "PowerShell"].includes(normalizeToolName(b.name)) &&
RUNNER.test(commandText(b.input))
startsRunner(commandText(b.input))
) {
runs.push(b.id);
}
Expand All @@ -694,12 +719,16 @@ export function testedSince(objs, since) {
return runs.some((id) => !(done.get(id) < since));
}

// Documentation and prose by name: a test run answers no change to one.
// `CMakeLists.txt` and a requirements file are code.
const PROSE = /\.(?:md|mdx|rst|txt|adoc)$/i;
// Documentation and prose by name: a test run answers no change to one. A
// `.txt` file is code (a requirements file, a build list, a test fixture)
// unless its name or a `docs` directory above it says prose: `CHANGES.txt`,
// `docs/releases/5.2.txt`. A requirements or a constraints file under `docs`
// stays code.
const PROSE = /\.(?:md|mdx|markdown|rst|adoc|asciidoc)$/i;
const CHANGELOG = /(?:^|\/)(?:CHANGELOG|CHANGES|HISTORY|NEWS)$/;
const CODE_TXT = /(?:^|\/)(?:CMakeLists|[^/]*requirements[^/]*)\.txt$/i;
const isProse = (file) => CHANGELOG.test(file) || (PROSE.test(file) && !CODE_TXT.test(file));
const PROSE_TXT =
/(?:^|\/)(?:changelog|changes|history|news|readme|license|notice|authors|docs?\/(?!.*(?:requirements|constraints)).*)\.txt$/i;
const isProse = (file) => CHANGELOG.test(file) || PROSE.test(file) || PROSE_TXT.test(file);

/** The newest modification time, in epoch ms, among the code files of
* `files` under `root`: a test run that finished since then saw each of
Expand Down
Loading
Loading