From 654298cad942d69de4a8523e4a2bcb07b8265829 Mon Sep 17 00:00:00 2001 From: Taylor Date: Tue, 20 Oct 2026 19:13:15 -0700 Subject: [PATCH 1/4] fix(select): a data file whose graph nodes nothing points at runs the full suite A changed .sql, .cypher, .graphql or other data file with graph nodes but no dependents selected zero tests: CGraph records no reads of data, so the graph's silence there is not evidence that nothing reads it. Its own walk reaching no test and nothing outside the file now fails open with an unmapped-file reason marked unreached; code files keep zero tests. On turing-api every migration edit selected 0 tests (5 of 5 tried). Co-Authored-By: Claude Opus 5.5 --- src/comment.test.ts | 16 +++++++++++ src/comment.ts | 6 +++- src/detect.ts | 13 +++++++++ src/select.test.ts | 69 +++++++++++++++++++++++++++++++++++++++++++++ src/select.ts | 23 +++++++++++++-- src/types.ts | 6 ++++ 6 files changed, 129 insertions(+), 4 deletions(-) diff --git a/src/comment.test.ts b/src/comment.test.ts index 10d8ac7..3bf27e6 100644 --- a/src/comment.test.ts +++ b/src/comment.test.ts @@ -288,6 +288,22 @@ describe("renderComment: fail-open", () => { expect(md).toContain("All 2 unmapped files"); }); + it("says a data file has graph nodes nothing points at instead of claiming it has none", () => { + const md = renderComment( + { + kind: "all", + reasons: [ + { kind: "unmapped-file", path: "db/migrations/0002_audit.sql", unreached: true }, + { kind: "unmapped-file", path: "assets/logo.svg" }, + ], + }, + ctx, + ); + expect(md).toContain("**1 file has no graph node**"); + expect(md).toContain("**1 data file has graph nodes nothing points at**"); + expect(md).toContain("so code may still read it, and selecting no tests would drop its tests"); + }); + it("offers the unmapped files nothing names as ignore patterns, and only those", () => { const md = renderComment( { diff --git a/src/comment.ts b/src/comment.ts index f8edd1b..d98c492 100644 --- a/src/comment.ts +++ b/src/comment.ts @@ -461,12 +461,16 @@ function renderUnmapped(reasons: Extract 50 ? `\n… ${paths.length - 50} more` : ""; const loaded = reasons.filter((r) => r.convention).length; - const nodeless = paths.length - loaded; + const unreached = reasons.filter((r) => r.unreached).length; + const nodeless = paths.length - loaded - unreached; return [ ...(nodeless > 0 ? [`**${nodeless} file${nodeless === 1 ? " has" : "s have"} no graph node** (config, asset, or unextracted).`, ""] : []), ...(loaded > 0 ? [`**${loaded} file${loaded === 1 ? " is" : "s are"} loaded by convention** (framework config, a build or dependency manifest, toolchain config): the graph has nodes for ${loaded === 1 ? "it" : "them"}, but every test may depend on ${loaded === 1 ? "it" : "them"}.`, ""] : []), + ...(unreached > 0 + ? [`**${unreached} data file${unreached === 1 ? " has" : "s have"} graph nodes nothing points at** (SQL, Cypher, GraphQL and the like): the graph records no reads of data, so code may still read ${unreached === 1 ? "it" : "them"}, and selecting no tests would drop ${unreached === 1 ? "its" : "their"} tests.`, ""] + : []), "If these files cannot change which tests should run, add a pattern for them to `ignore`. If they feed tests (fixtures, data), this outcome is correct.", "", ...suggestIgnores(reasons.filter((r) => r.unnamed).map((r) => r.path)), diff --git a/src/detect.ts b/src/detect.ts index 4abc339..cf7030d 100644 --- a/src/detect.ts +++ b/src/detect.ts @@ -28,6 +28,19 @@ export function isTestPath(path: string): boolean { ); } +/** + * Code whose uses CGraph extracts: the languages its `detect.cpp` parses with a + * grammar (C, C++, C#, Apex, Go, Rust, Groovy, Java, JavaScript, Kotlin, Delphi, + * Python, Ruby, Scala, TypeScript). Every other file the graph holds (SQL, Cypher, + * Protobuf, GraphQL, OpenAPI, XML, configs) is data: CGraph records no read of it, + * so nothing pointing at its nodes is not evidence that nothing reads it. + */ +const CODE = /\.(?:c|h|cc|cpp|cxx|hpp|hh|hxx|cs|cls|trigger|go|rs|groovy|gvy|gradle|java|js|jsx|mjs|cjs|kt|kts|pas|pp|dpr|py|pyw|rb|scala|sc|ts|tsx)$/i; + +export function isCodePath(path: string): boolean { + return CODE.test(path); +} + /** * JVM test conventions for Java and Kotlin, taken from the build tools' own * default class-name patterns — the JVM analog of Go's compiler-enforced diff --git a/src/select.test.ts b/src/select.test.ts index fa6005c..20b3a20 100644 --- a/src/select.test.ts +++ b/src/select.test.ts @@ -231,6 +231,75 @@ describe("select", () => { expect(JSON.stringify(sel.reasons[0])).toContain("no content root"); }); + describe("a data file whose graph nodes nothing points at", () => { + const node = (id: string, type: string, file: string, line?: number) => ({ + id, + label: id, + type, + source_file: file, + ...(line !== undefined && { source_location: { start_line: line, end_line: line } }), + }); + // A code path to one test, a migration whose table a model uses, and data files nothing in the graph points at. + const graph = indexGraph( + [ + node("f_lib", "file", "/repo/src/lib.ts"), + node("fn_parse", "function", "/repo/src/lib.ts", 1), + node("f_test", "file", "/repo/src/lib.test.ts"), + node("f_model", "file", "/repo/src/model.ts"), + node("fn_model", "function", "/repo/src/model.ts", 1), + node("f_model_test", "file", "/repo/src/model.test.ts"), + node("sql_used", "sql_file", "/repo/db/0001_users.sql"), + node("sql_users", "sql_table", "/repo/db/0001_users.sql", 1), + { id: "table:local:users", label: "users", type: "table", source_file: "/repo/db/0001_users.sql" }, + node("sql_lone", "sql_file", "/repo/db/0002_audit.sql"), + node("sql_audit", "sql_table", "/repo/db/0002_audit.sql", 1), + { id: "table:local:audit", label: "audit", type: "table", source_file: "/repo/db/0002_audit.sql" }, + node("f_cypher", "file", "/repo/db/q.cypher"), + node("f_dead", "file", "/repo/src/dead.ts"), + node("fn_dead", "function", "/repo/src/dead.ts", 1), + ], + [ + { source: "f_lib", target: "fn_parse", relation: "contains" }, + { source: "f_test", target: "fn_parse", relation: "imports" }, + { source: "f_model", target: "fn_model", relation: "contains" }, + { source: "fn_model", target: "table:local:users", relation: "uses" }, + { source: "f_model_test", target: "fn_model", relation: "imports" }, + { source: "table:local:users", target: "sql_users", relation: "handled_by" }, + { source: "table:local:audit", target: "sql_audit", relation: "handled_by" }, + { source: "f_dead", target: "fn_dead", relation: "contains" }, + ], + ); + const edit = (path: string): string => `diff --git a/${path} b/${path}\nindex 1..2 100644\n--- a/${path}\n+++ b/${path}\n@@ -1,1 +1,1 @@\n-a\n+b\n`; + const opts = { graph, minDensity: 0, minTestReachability: 0 }; + + it("fails open on a .sql file whose table nothing uses, instead of selecting zero tests", () => { + const sel = select(edit("db/0002_audit.sql"), opts); + expect(sel.kind).toBe("all"); + if (sel.kind !== "all") return; + expect(sel.reasons).toEqual([{ kind: "unmapped-file", path: "db/0002_audit.sql", unreached: true }]); + }); + + it("fails open on a .cypher file with only its file node", () => { + const sel = select(edit("db/q.cypher"), opts); + expect(sel.kind === "all" && sel.reasons).toEqual([{ kind: "unmapped-file", path: "db/q.cypher", unreached: true }]); + }); + + it("keeps the subset for a .sql file whose table code uses", () => { + const sel = select(edit("db/0001_users.sql"), opts); + expect(sel.kind === "subset" && sel.tests).toEqual(["/repo/src/model.test.ts"]); + }); + + it("keeps a code file with no dependents at zero tests: there the graph's silence is evidence", () => { + const sel = select(edit("src/dead.ts"), opts); + expect(sel.kind === "subset" && sel.tests).toEqual([]); + }); + + it("fails open on the data file even when another file in the diff selects tests", () => { + const sel = select(edit("src/lib.ts") + edit("db/q.cypher"), opts); + expect(sel.kind === "all" && sel.reasons.map((r) => r.kind === "unmapped-file" && r.path)).toEqual(["db/q.cypher"]); + }); + }); + it("is deterministic: identical inputs produce identical output", () => { const a = JSON.stringify(select(DIFF_IN_PARSE, { graph: g, minDensity: 0 })); const b = JSON.stringify(select(DIFF_IN_PARSE, { graph: g, minDensity: 0 })); diff --git a/src/select.ts b/src/select.ts index c6bdbe3..47eff51 100644 --- a/src/select.ts +++ b/src/select.ts @@ -1,5 +1,5 @@ import { statSync } from "node:fs"; -import { testFiles, testReachability } from "./detect.js"; +import { isCodePath, testFiles, testReachability } from "./detect.js"; import { parseUnifiedDiff } from "./diff.js"; import type { CodeGraph } from "./graph.js"; import { dependencyDirection, isContract, nodesInFile, translatePath } from "./graph.js"; @@ -267,7 +267,7 @@ export function select(diffText: string, opts: SelectOptions): Selection { /** Walk one seed set (head ids, or base ids translated to head paths). */ const walk = ( seeds: Set, - ): { blast: string[]; tests: Set; reached: Map> } => { + ): { blast: string[]; tests: Set; reached: Map>; files: Set } => { const headSeeds = new Set(); const baseSeeds = new Set(); for (const id of seeds) { @@ -277,9 +277,12 @@ export function select(diffText: string, opts: SelectOptions): Selection { const blast: string[] = []; const tests = new Set(); const reached = new Map>(); + // Every file a dependent sits in, contract or not: the data-file check below needs to know whether anything outside the file was reached. + const files = new Set(); // A contract the walk crosses is not code: it is neither blast radius nor a reached file. A // test file it was minted in still counts, so selection stays a superset of what it was. const record = (file: string, type: string, label: string, loc: string, contract: boolean): void => { + files.add(file); if (contract) { if (testSet.has(file)) tests.add(file); return; @@ -316,11 +319,13 @@ export function select(diffText: string, opts: SelectOptions): Selection { record(headFile, node.type, node.label, loc, isContract(id)); } } - return { blast, tests, reached }; + return { blast, tests, reached, files }; }; let whole: ReturnType; const files: ChangedFileImpact[] = []; + // Data files whose own walk reached no test and nothing outside the file (see `isCodePath`). + const unreached: string[] = []; try { whole = walk(mapping.seeds); for (const file of changed) { @@ -332,6 +337,12 @@ export function select(diffText: string, opts: SelectOptions): Selection { } const own = walk(seeds); const proof = opts.inert?.get(file.path)?.why; + // A data file's nodes that nothing points at say nothing about who reads it: CGraph records no reads of data, + // so a `.sql` or `.cypher` change would select zero tests. A manifest walked through the code naming its scripts is not one. + if (!isCodePath(file.path) && proof === undefined && own.tests.size === 0) { + const itself = new Set(nodesInFile(opts.graph, file.path).flatMap((n) => (n.source_file ? [n.source_file] : []))); + if ([...own.files].every((f) => itself.has(f))) unreached.push(file.path); + } const symbols = new Set(); for (const id of seeds) { const node = opts.graph.byId.get(id) ?? opts.baseGraph?.byId.get(id); @@ -358,6 +369,12 @@ export function select(diffText: string, opts: SelectOptions): Selection { } throw e; } + if (unreached.length > 0) { + const reasons: FailOpenReason[] = unreached.map((path) => ({ kind: "unmapped-file", path, unreached: true })); + const references = opts.references; + if (references === undefined) return { kind: "all", reasons }; + return { kind: "all", reasons: reasons.map((r) => (r.kind === "unmapped-file" ? advise(r, references.get(r.path), opts.graph, knownTests, budget) : r)) }; + } const tests = whole.tests; // Files cgraph deliberately skipped were dropped from `changed` above; they // still belong in the per-file report, as ignored, in diff order. diff --git a/src/types.ts b/src/types.ts index 6278a2f..432304c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -45,6 +45,12 @@ export type FailOpenReason = * (`loadedByConvention` in `unnamed.ts`), so it fails open all the same. */ convention?: true; + /** + * The graph has nodes for this data file (SQL, Cypher, GraphQL, …), but + * nothing in the graph points at them: CGraph records no reads of data, + * so code may still read it, and selecting nothing would drop its tests. + */ + unreached?: true; /** * Advice, never selection (see `references.ts`): code that reads this * file, the test files those readers reach (absolute, like `tests`), and From f1aa5818c6356dbfbea1456fd925a8ca71d63cdc Mon Sep 17 00:00:00 2001 From: Taylor Date: Tue, 20 Oct 2026 19:13:16 -0700 Subject: [PATCH 2/4] fix(checkpoint): take the intent's narration and test runs from the session that worked Entire attaches every session live in the checkout when a commit is made. Narration and test commands were taken from the first session with any text, so a PR's Intent opened with another task's narration (turing-webapp#827: a call-summary session among ten). When some session worked on the commit's files, only those now count, as the ask already did. Co-Authored-By: Claude Opus 5.5 --- src/checkpoint.test.ts | 17 +++++++++++++++++ src/checkpoint.ts | 22 ++++++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/checkpoint.test.ts b/src/checkpoint.test.ts index d751b9b..437e9d8 100644 --- a/src/checkpoint.test.ts +++ b/src/checkpoint.test.ts @@ -423,6 +423,23 @@ describe("checkpointFor on the branch backend", () => { expect(cp?.prompt).toBe("put the minimum back"); }); + it("says what the working session did and ran, not a session on another task that Entire attached", () => { + // Entire attaches every session live in the checkout: session 0 summarises a call, the other session does the commit. + const HEX_W = "6a1b2c3d4e5f"; + const aside = [rec("user", stamp(1), [user("summarise the planning call")]), rec("assistant", stamp(2), [text("I'll read the call transcript and pull the comments.")]), rec("assistant", stamp(3), [bash("bunx vitest run src/unrelated.test.ts")])]; + const work = [ + rec("user", stamp(20), [user("let the cap go to sixteen")]), + rec("assistant", stamp(21), [text("I've read the ticket; raising the cap.")]), + rec("assistant", stamp(22), [edit("src/round-size.ts", "export const ROUND_SIZE_MAX = 16;"), bash("bunx vitest run src/round-size.test.ts")]), + ]; + writeBranchCheckpoint(HEX_W, branchFiles(HEX_W, stamp(23), aside, "", { session: OTHER, transcript: work })); + const w = commitFile("src/round-size.ts", "export const ROUND_SIZE_MAX = 16;\n", `fix: the cap goes to sixteen\n\nEntire-Checkpoint: ${HEX_W}\n`); + const cp = checkpointFor(repo, w, [], new Map(), ["src/round-size.ts"]); + expect(cp?.prompt).toBe("let the cap go to sixteen"); + expect(cp?.narration.started).toBe("I've read the ticket; raising the cap."); + expect(cp?.testCommands).toEqual(["bunx vitest run src/round-size.test.ts"]); + }); + it("finds a symbol's reason in the since-window even when the narration window starts later", () => { const cp = checkpointFor(repo, commitA, [{ path: "src/round-size.ts", label: "ROUND_SIZE_MAX" }], new Map(), ["src/round-size.ts"]); expect(cp?.reasons).toEqual([{ path: "src/round-size.ts", label: "ROUND_SIZE_MAX", turn: 4, why: "I'll start by reading the ticket, then set up a worktree off dev." }]); diff --git a/src/checkpoint.ts b/src/checkpoint.ts index 390cde0..82c0363 100644 --- a/src/checkpoint.ts +++ b/src/checkpoint.ts @@ -909,6 +909,9 @@ export function checkpointFor(repo: string, commit: string, symbols: SymbolAt[] const decisions: Decision[] = []; const testCommands = new Set(); let narration: Narration = { started: "", ended: "", texts: 0, tools: 0 }; + // Each session's own part, combined after the loop; `activity` counts texts and tool calls across every session. + const parts: { worked: boolean; narration: Narration; testCommands: string[] }[] = []; + let activity = 0; const sessions: CheckpointSession[] = []; let readBefore = 0; const reasons = new Map(); @@ -946,21 +949,28 @@ export function checkpointFor(repo: string, commit: string, symbols: SymbolAt[] } if (extended) readBefore++; sessions.push({ id: sessionId, lines, hash }); - for (const c of testCommandsIn(turnWindow)) testCommands.add(c); for (const r of symbolReasonsIn(sinceWindow, symbols, contents)) reasons.set(`${r.path}\0${r.label}`, r); const n = narrationIn(stepWindow); + activity += n.texts + n.tools; + parts.push({ worked, narration: n, testCommands: testCommandsIn(turnWindow) }); + } + // Entire attaches every session live in the repo when the commit is made. When some worked on the commit's + // files, only theirs say what the commit's session did and ran; the rest (other tasks in the same checkout) are left out. + const own = parts.some((p) => p.worked) ? parts.filter((p) => p.worked) : parts; + for (const p of own) { + for (const c of p.testCommands) testCommands.add(c); narration = { - started: narration.started || n.started, - ended: n.texts > 0 ? n.ended || n.started : narration.ended, - texts: narration.texts + n.texts, - tools: narration.tools + n.tools, + started: narration.started || p.narration.started, + ended: p.narration.texts > 0 ? p.narration.ended || p.narration.started : narration.ended, + texts: narration.texts + p.narration.texts, + tools: narration.tools + p.narration.tools, }; } if (narration.ended === narration.started) narration.ended = ""; let prompt = ask; for (let i = 0; prompt === "" && i < sessionCount; i++) prompt = typed(i); // The same step: every session's transcript extends what an earlier commit read, and nothing came after. - const sameStep = readBefore > 0 && readBefore === sessions.length && narration.texts === 0 && narration.tools === 0 ? read.get(sessions[0]!.id)?.sha : undefined; + const sameStep = readBefore > 0 && readBefore === sessions.length && activity === 0 ? read.get(sessions[0]!.id)?.sha : undefined; return { id, commit: git(repo, ["rev-parse", `${commit}^{commit}`]).trim(), From 29d2252f9c6985f685a27ce8ecc35240d367637c Mon Sep 17 00:00:00 2001 From: Taylor Date: Tue, 20 Oct 2026 19:14:14 -0700 Subject: [PATCH 3/4] chore: 0.23.1 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 +++++++ README.md | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 102c73c..8e5f9af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.23.1 + +Two fixes: a data file could select zero tests, and a PR's Intent could open with another session's work. + +- A changed data file whose graph nodes nothing points at now runs the full suite instead of selecting zero tests. CGraph extracts dependencies only from code (C, C++, C#, Apex, Go, Rust, Groovy, Java, JavaScript, Kotlin, Delphi, Python, Ruby, Scala, TypeScript), so for SQL, Cypher, GraphQL, Protobuf, OpenAPI and XML files the graph records no reads, and its silence is not evidence that nothing reads them. On a TypeScript service, a one-line edit to each of five migrations selected 0 tests before, and runs the full suite now. Before this, migrations were masked whenever their journal file had no graph node, and exposed once the journal folder was ignored. A data file whose nodes something in the graph does point at (a table a model uses) keeps its subset, and a code file nothing depends on still selects zero tests. The comment says the file "has graph nodes nothing points at" (`unreached` on the reason), not that it has none. +- The Intent cell's narration and the "Ran before push" commands come only from the sessions that worked on the commit's files, as the prompt already did. Entire attaches every session live in the checkout when a commit is made. On one web-app PR, ten sessions were attached. The Intent opened with a call-summary session's first line, and 30 test commands came from other tasks. Now it shows the working session's own words and its 2 commands. With no session working on the files, every session still counts. + ## 0.23.0 "What the agent decided" finds test outcomes, edits and subagents the way agents actually work. Replayed on 96 checkpointed commits of a web-app repository since 2026-09-20, the section had a line for 1 of them before (a design note) and for 20 after: 13 with runs that failed and then passed, 6 commits made right after a failing run with no pass, and 4 with design notes weighing alternatives (one commit can have several). diff --git a/README.md b/README.md index 8377176..c3a6812 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ What the reviewer sees, in order: | --- | --- | | **Verdict** — `N of M test files reach this diff`, `K agent commits` | the selection, unchanged | | **Summary** — Changed, Tests reached, Downstream code (with a **review effort** tier: `high` from 20 dependents or 10 mapped files, `low` under 5 dependents and 4 files, `medium` between; fixed thresholds), plus **Intent** (how many commits carry a checkpoint, which models), **Reviewed by** (who has reviewed other than the author, or `no reviewer other than the author (login) so far`; and the humans whose commits last changed the changed and reached files before this range, agent-authored commits set aside), **Symbols** (changed / added / removed / moved), **Since push ``** (new commits, changed files, tests reached, newly reached files) | the checkpoint refs, `cgraph change-context`, the snapshot embedded in the previous comment | -| **What each commit did** — Commit · Intent · Files · Reaches · Ran before push, folded after 10 commits | each commit's `Entire-Checkpoint:` trailer, resolved to `refs/entire/checkpoints//` (a 26-character id) or to `//` on the branch `entire/checkpoints/v1` (a 12-character id); the Intent cell is what the agent said in the turn that produced the commit, then the agent and model; without a checkpoint, the commit's own marks (an `Agent-Logs-Url:` trailer, a vendor address as author or `Co-authored-by:`) name the agent | +| **What each commit did** — Commit · Intent · Files · Reaches · Ran before push, folded after 10 commits | each commit's `Entire-Checkpoint:` trailer, resolved to `refs/entire/checkpoints//` (a 26-character id) or to `//` on the branch `entire/checkpoints/v1` (a 12-character id); the Intent cell is what the agent said in the turn that produced the commit (only the sessions that worked on the commit's files count when Entire attached others live in the same checkout), then the agent and model; without a checkpoint, the commit's own marks (an `Agent-Logs-Url:` trailer, a vendor address as author or `Co-authored-by:`) name the agent | | **What the agent decided** — at most 8 lines, each with its kind and commit, in session order; omitted when no checkpoint holds one | the turns in each checkpoint's part of the compact transcript, from the commit's own turn on, that hold a tool call working on one of the PR's files at this repo's root (an edit tool's absolute path, a command naming it, or a command run at the root that names it by its repo path, the shell's directory being followed through `cd`s across calls; the root is the one the edits to files inside folders and those commands agree on, else the one the last `git commit` ran in, and with none nothing is read; a subagent's tool calls, when Entire keeps its transcript, count inside the turn that started it), skipping what the agent does while away from the repo (from the transcript's start, and after an edit, read or search outside the root, a `cd`, `pushd` or `git -C` elsewhere, a `../` or `$VAR/` path, or an absolute path outside the root, until it works at the root or `cd`s back; this carries across turns, as the shell's directory does) (`src/decisions.ts`, no model): a test runner and the test files the change carries that failed and then passed or whose last run failed (by the runner's own summary line in the call's output, read and never shown, else the call's status for a bare run; one run per command, none against swapped-in code; files named only when the run targets nothing else), reverts (by a fixed label such as `git revert`), and design notes the change adds that weigh alternatives (by repo path). No free text is quoted, neither what a person typed nor what the agent wrote. More than 8: test outcomes and reverts are kept first | | **Claims checked** — `refuted`, `partial` or `consistent`, refuted first | `blastline check` on removed symbols against the base graph; a changed declaration against its base-graph callers outside the diff; the reaching tests against the test commands the checkpoint ran; files touched against the commit; the PR body and each commit message against the diff | | **What each changed file reaches** — a **Why** column (present when a checkpoint carries one) gives, per file, the agent's own line before the edit that touched each changed symbol, with its turn; a **Read** column gives the order (widest reach first; a changed file another changed file reaches sits right after it as `with `; test files last), the Change column names what happened to each symbol | the reach walk; `cgraph change-context`, `changes[].symbol_changes` | diff --git a/package.json b/package.json index 6c74ddc..aa8f9b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blastline", - "version": "0.23.0", + "version": "0.23.1", "description": "Graph-backed test impact and blast radius for CI and PRs, built on CGraph", "license": "MIT", "type": "module", From c4100d91496c8fa8b4e6ac50adfc9689661434a7 Mon Sep 17 00:00:00 2001 From: Taylor Date: Tue, 20 Oct 2026 19:24:27 -0700 Subject: [PATCH 4/4] fix(select): any data file that reaches no test fails open Review of #59: a migration that only another migration's foreign key points at (sql_table references sql_table) still selected zero tests, because its walk reached a file outside itself. Drop that condition: a data file whose walk reaches no test fails open, whatever it reached. Remove the advise() call that could never run (references are built for nodeless files only). Tests for data reached by data, data reached by untested code, and a manifest walked through its readers. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- README.md | 2 +- src/comment.test.ts | 4 ++-- src/comment.ts | 2 +- src/select.test.ts | 26 +++++++++++++++++++++++++- src/select.ts | 26 ++++++++------------------ src/types.ts | 4 ++-- 7 files changed, 40 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e5f9af..a29c5af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Two fixes: a data file could select zero tests, and a PR's Intent could open with another session's work. -- A changed data file whose graph nodes nothing points at now runs the full suite instead of selecting zero tests. CGraph extracts dependencies only from code (C, C++, C#, Apex, Go, Rust, Groovy, Java, JavaScript, Kotlin, Delphi, Python, Ruby, Scala, TypeScript), so for SQL, Cypher, GraphQL, Protobuf, OpenAPI and XML files the graph records no reads, and its silence is not evidence that nothing reads them. On a TypeScript service, a one-line edit to each of five migrations selected 0 tests before, and runs the full suite now. Before this, migrations were masked whenever their journal file had no graph node, and exposed once the journal folder was ignored. A data file whose nodes something in the graph does point at (a table a model uses) keeps its subset, and a code file nothing depends on still selects zero tests. The comment says the file "has graph nodes nothing points at" (`unreached` on the reason), not that it has none. +- A changed data file whose walk reaches no test now runs the full suite instead of selecting zero tests. "Data" means a file that isn't in one of the languages CGraph parses as code (C, C++, C#, Apex, Go, Rust, Groovy, Java, JavaScript, Kotlin, Delphi, Python, Ruby, Scala, TypeScript), such as SQL, Cypher, GraphQL, Protobuf, OpenAPI and XML. The graph records no reads of data by code, so a walk that finds no test is not evidence that no test reads the file. That holds whether nothing points at the file's nodes, only another migration's foreign key does, or only untested code does. On a TypeScript service, a one-line edit to each of five migrations selected 0 tests before and runs the full suite now; migrations were masked while their journal file had no graph node, and exposed once the journal folder was ignored. A data file whose walk reaches tests (a table a model uses) keeps its subset, and a code file nothing depends on still selects zero tests. The comment says the file "reaches no test in the graph" (`unreached` on the reason), not that it has no node. - The Intent cell's narration and the "Ran before push" commands come only from the sessions that worked on the commit's files, as the prompt already did. Entire attaches every session live in the checkout when a commit is made. On one web-app PR, ten sessions were attached. The Intent opened with a call-summary session's first line, and 30 test commands came from other tasks. Now it shows the working session's own words and its 2 commands. With no session working on the files, every session still counts. ## 0.23.0 diff --git a/README.md b/README.md index c3a6812..5add018 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Fail-open triggers, each a typed reason in the output: | Reason | Fires when | | --- | --- | -| `unmapped-file` | a changed file has no graph node (configs, lockfiles, assets) — declare irrelevant paths with `--ignore`. A file on the loaded-by-convention list in `src/unnamed.ts` (Spring `application*.yml`, Gradle and other build or dependency manifests, test-runner and toolchain config, test setup files, `conftest.py`, `build.rs`) fires it even when the graph has nodes for it, and the comment says so: cgraph gives `application.yml` and `build.gradle.kts` nodes, and seeding them selected a handful of tests or none. When nothing outside Markdown names a file or any folder above it (case ignored), and it is not on the never-list in `src/unnamed.ts` (Spring config, `src/*/resources/`, snapshots, `testdata`/`fixtures` folders, dependency manifests and lockfiles for JS, Python, JVM, Go, Rust, Ruby, PHP, .NET, Swift and Dart, build files such as `Makefile`, and test-runner and toolchain config), the comment offers it as a pattern to add under `ignore: |`; the run still fails open. One exception: a **CMake hunk that does nothing but register new test targets** is read rather than refused, and the tests it declares are selected (see below) | +| `unmapped-file` | a changed file has no graph node (configs, lockfiles, assets) — declare irrelevant paths with `--ignore`. A data file (one not in a language CGraph parses as code: SQL, Cypher, GraphQL, …) whose walk reaches no test fails open too, marked `unreached`: the graph records no reads of data by code, so selecting nothing could drop its tests. A file on the loaded-by-convention list in `src/unnamed.ts` (Spring `application*.yml`, Gradle and other build or dependency manifests, test-runner and toolchain config, test setup files, `conftest.py`, `build.rs`) fires it even when the graph has nodes for it, and the comment says so: cgraph gives `application.yml` and `build.gradle.kts` nodes, and seeding them selected a handful of tests or none. When nothing outside Markdown names a file or any folder above it (case ignored), and it is not on the never-list in `src/unnamed.ts` (Spring config, `src/*/resources/`, snapshots, `testdata`/`fixtures` folders, dependency manifests and lockfiles for JS, Python, JVM, Go, Rust, Ruby, PHP, .NET, Swift and Dart, build files such as `Makefile`, and test-runner and toolchain config), the comment offers it as a pattern to add under `ignore: |`; the run still fails open. One exception: a **CMake hunk that does nothing but register new test targets** is read rather than refused, and the tests it declares are selected (see below) | | `stale-graph` | the graph fails a content-root pin (`--expect-root`, or `--daemon-verify` against the live CGraph daemon), or `graph.json` is older than the head commit | | `sparse-graph` | the graph averages under 3 edges per file — an under-extracted graph produces subsets that look smart and are blind, so blastline refuses | | `disconnected-tests` | tests can forward-reach under 25% of the code's symbols — the graph passed the density floor but is blind for selection (how broken Go/Python extraction presented, and how every Rust graph presents today) | diff --git a/src/comment.test.ts b/src/comment.test.ts index 3bf27e6..4b7c7b9 100644 --- a/src/comment.test.ts +++ b/src/comment.test.ts @@ -288,7 +288,7 @@ describe("renderComment: fail-open", () => { expect(md).toContain("All 2 unmapped files"); }); - it("says a data file has graph nodes nothing points at instead of claiming it has none", () => { + it("says a data file reaches no test instead of claiming it has no graph node", () => { const md = renderComment( { kind: "all", @@ -300,7 +300,7 @@ describe("renderComment: fail-open", () => { ctx, ); expect(md).toContain("**1 file has no graph node**"); - expect(md).toContain("**1 data file has graph nodes nothing points at**"); + expect(md).toContain("**1 data file reaches no test in the graph**"); expect(md).toContain("so code may still read it, and selecting no tests would drop its tests"); }); diff --git a/src/comment.ts b/src/comment.ts index d98c492..eeeaf6f 100644 --- a/src/comment.ts +++ b/src/comment.ts @@ -469,7 +469,7 @@ function renderUnmapped(reasons: Extract 0 - ? [`**${unreached} data file${unreached === 1 ? " has" : "s have"} graph nodes nothing points at** (SQL, Cypher, GraphQL and the like): the graph records no reads of data, so code may still read ${unreached === 1 ? "it" : "them"}, and selecting no tests would drop ${unreached === 1 ? "its" : "their"} tests.`, ""] + ? [`**${unreached} data file${unreached === 1 ? " reaches" : "s reach"} no test in the graph** (SQL, Cypher, GraphQL and the like): the graph records no reads of data by code, so code may still read ${unreached === 1 ? "it" : "them"}, and selecting no tests would drop ${unreached === 1 ? "its" : "their"} tests.`, ""] : []), "If these files cannot change which tests should run, add a pattern for them to `ignore`. If they feed tests (fixtures, data), this outcome is correct.", "", diff --git a/src/select.test.ts b/src/select.test.ts index 20b3a20..6af6d5a 100644 --- a/src/select.test.ts +++ b/src/select.test.ts @@ -231,7 +231,7 @@ describe("select", () => { expect(JSON.stringify(sel.reasons[0])).toContain("no content root"); }); - describe("a data file whose graph nodes nothing points at", () => { + describe("a data file that reaches no test", () => { const node = (id: string, type: string, file: string, line?: number) => ({ id, label: id, @@ -257,6 +257,10 @@ describe("select", () => { node("f_cypher", "file", "/repo/db/q.cypher"), node("f_dead", "file", "/repo/src/dead.ts"), node("fn_dead", "function", "/repo/src/dead.ts", 1), + node("sql_new", "sql_file", "/repo/db/0003_teams.sql"), + node("sql_teams", "sql_table", "/repo/db/0003_teams.sql", 1), + node("f_routes", "file", "/repo/conf/routes.xml"), + node("f_pkg", "file", "/repo/package.json"), ], [ { source: "f_lib", target: "fn_parse", relation: "contains" }, @@ -267,6 +271,10 @@ describe("select", () => { { source: "table:local:users", target: "sql_users", relation: "handled_by" }, { source: "table:local:audit", target: "sql_audit", relation: "handled_by" }, { source: "f_dead", target: "fn_dead", relation: "contains" }, + // A later migration's foreign key: the audit table references teams. + { source: "sql_audit", target: "sql_teams", relation: "references" }, + // Code no test reaches reads the routes file. + { source: "fn_dead", target: "f_routes", relation: "uses" }, ], ); const edit = (path: string): string => `diff --git a/${path} b/${path}\nindex 1..2 100644\n--- a/${path}\n+++ b/${path}\n@@ -1,1 +1,1 @@\n-a\n+b\n`; @@ -294,6 +302,22 @@ describe("select", () => { expect(sel.kind === "subset" && sel.tests).toEqual([]); }); + it("fails open on a migration only another migration's foreign key points at", () => { + const sel = select(edit("db/0003_teams.sql"), opts); + expect(sel.kind === "all" && sel.reasons).toEqual([{ kind: "unmapped-file", path: "db/0003_teams.sql", unreached: true }]); + }); + + it("fails open on a data file only code that reaches no test points at", () => { + const sel = select(edit("conf/routes.xml"), opts); + expect(sel.kind === "all" && sel.reasons).toEqual([{ kind: "unmapped-file", path: "conf/routes.xml", unreached: true }]); + }); + + it("leaves a manifest whose new scripts code names to its readers' walk", () => { + const inert = new Map([["package.json", { why: "adds scripts only `src/dead.ts` names", readers: [{ file: "src/dead.ts", line: 1 }] }]]); + const sel = select(edit("package.json"), { ...opts, inert }); + expect(sel.kind === "subset" && sel.tests).toEqual([]); + }); + it("fails open on the data file even when another file in the diff selects tests", () => { const sel = select(edit("src/lib.ts") + edit("db/q.cypher"), opts); expect(sel.kind === "all" && sel.reasons.map((r) => r.kind === "unmapped-file" && r.path)).toEqual(["db/q.cypher"]); diff --git a/src/select.ts b/src/select.ts index 47eff51..43b5e29 100644 --- a/src/select.ts +++ b/src/select.ts @@ -267,7 +267,7 @@ export function select(diffText: string, opts: SelectOptions): Selection { /** Walk one seed set (head ids, or base ids translated to head paths). */ const walk = ( seeds: Set, - ): { blast: string[]; tests: Set; reached: Map>; files: Set } => { + ): { blast: string[]; tests: Set; reached: Map> } => { const headSeeds = new Set(); const baseSeeds = new Set(); for (const id of seeds) { @@ -277,12 +277,9 @@ export function select(diffText: string, opts: SelectOptions): Selection { const blast: string[] = []; const tests = new Set(); const reached = new Map>(); - // Every file a dependent sits in, contract or not: the data-file check below needs to know whether anything outside the file was reached. - const files = new Set(); // A contract the walk crosses is not code: it is neither blast radius nor a reached file. A // test file it was minted in still counts, so selection stays a superset of what it was. const record = (file: string, type: string, label: string, loc: string, contract: boolean): void => { - files.add(file); if (contract) { if (testSet.has(file)) tests.add(file); return; @@ -319,12 +316,12 @@ export function select(diffText: string, opts: SelectOptions): Selection { record(headFile, node.type, node.label, loc, isContract(id)); } } - return { blast, tests, reached, files }; + return { blast, tests, reached }; }; let whole: ReturnType; const files: ChangedFileImpact[] = []; - // Data files whose own walk reached no test and nothing outside the file (see `isCodePath`). + // Data files whose own walk reached no test (see `isCodePath`). const unreached: string[] = []; try { whole = walk(mapping.seeds); @@ -337,12 +334,10 @@ export function select(diffText: string, opts: SelectOptions): Selection { } const own = walk(seeds); const proof = opts.inert?.get(file.path)?.why; - // A data file's nodes that nothing points at say nothing about who reads it: CGraph records no reads of data, - // so a `.sql` or `.cypher` change would select zero tests. A manifest walked through the code naming its scripts is not one. - if (!isCodePath(file.path) && proof === undefined && own.tests.size === 0) { - const itself = new Set(nodesInFile(opts.graph, file.path).flatMap((n) => (n.source_file ? [n.source_file] : []))); - if ([...own.files].every((f) => itself.has(f))) unreached.push(file.path); - } + // A data file that reaches no test says nothing about who reads it: CGraph records no reads of data by code, so a + // `.sql` or `.cypher` change would select zero tests, whether nothing points at its nodes or only another migration's + // foreign key does. A manifest walked through the code naming its scripts is not one. + if (!isCodePath(file.path) && proof === undefined && own.tests.size === 0) unreached.push(file.path); const symbols = new Set(); for (const id of seeds) { const node = opts.graph.byId.get(id) ?? opts.baseGraph?.byId.get(id); @@ -369,12 +364,7 @@ export function select(diffText: string, opts: SelectOptions): Selection { } throw e; } - if (unreached.length > 0) { - const reasons: FailOpenReason[] = unreached.map((path) => ({ kind: "unmapped-file", path, unreached: true })); - const references = opts.references; - if (references === undefined) return { kind: "all", reasons }; - return { kind: "all", reasons: reasons.map((r) => (r.kind === "unmapped-file" ? advise(r, references.get(r.path), opts.graph, knownTests, budget) : r)) }; - } + if (unreached.length > 0) return { kind: "all", reasons: unreached.map((path) => ({ kind: "unmapped-file", path, unreached: true })) }; const tests = whole.tests; // Files cgraph deliberately skipped were dropped from `changed` above; they // still belong in the per-file report, as ignored, in diff order. diff --git a/src/types.ts b/src/types.ts index 432304c..4c0cb0e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -47,8 +47,8 @@ export type FailOpenReason = convention?: true; /** * The graph has nodes for this data file (SQL, Cypher, GraphQL, …), but - * nothing in the graph points at them: CGraph records no reads of data, - * so code may still read it, and selecting nothing would drop its tests. + * its walk reaches no test: CGraph records no reads of data by code, so + * code may still read it, and selecting nothing would drop its tests. */ unreached?: true; /**