@diffci.com/diffci 0.3.23 → 0.3.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist-client/src/client/agent-setup.d.ts +23 -0
  2. package/dist-client/src/client/agent-setup.js +111 -0
  3. package/dist-client/src/client/cli.js +26 -8
  4. package/dist-client/src/client/failure-baseline.js +0 -0
  5. package/dist-client/src/client/full-command.d.ts +10 -0
  6. package/dist-client/src/client/full-command.js +22 -0
  7. package/dist-client/src/client/hook.d.ts +1 -0
  8. package/dist-client/src/client/hook.js +9 -0
  9. package/dist-client/src/client/mcp.js +10 -4
  10. package/dist-client/src/client/observe.js +10 -5
  11. package/dist-client/src/client/verify.js +18 -3
  12. package/node_modules/@diffci.com/core/README.md +4 -0
  13. package/node_modules/@diffci.com/core/dist/cache/graph-cache.d.ts +1 -1
  14. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +3 -1
  15. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
  16. package/node_modules/@diffci.com/core/dist/git/git-diff.js +16 -0
  17. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  18. package/node_modules/@diffci.com/core/dist/planner/test-command.d.ts +4 -0
  19. package/node_modules/@diffci.com/core/dist/planner/test-command.js +127 -20
  20. package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
  21. package/node_modules/@diffci.com/core/dist/repo/analyzer.js +9 -2
  22. package/node_modules/@diffci.com/core/dist/repo/analyzer.js.map +1 -1
  23. package/node_modules/@diffci.com/core/dist/repo/graph.js +231 -28
  24. package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
  25. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +4 -0
  26. package/node_modules/@diffci.com/core/dist/repo/impact.js +40 -6
  27. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  28. package/node_modules/@diffci.com/core/dist/repo/test-discovery.d.ts +5 -1
  29. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +55 -6
  30. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
  31. package/node_modules/@diffci.com/core/dist/repo/types.d.ts +7 -0
  32. package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +3 -1
  33. package/node_modules/@diffci.com/core/src/git/git-diff.ts +13 -0
  34. package/node_modules/@diffci.com/core/src/planner/test-command.ts +125 -16
  35. package/node_modules/@diffci.com/core/src/repo/analyzer.ts +9 -2
  36. package/node_modules/@diffci.com/core/src/repo/graph.ts +206 -30
  37. package/node_modules/@diffci.com/core/src/repo/impact.ts +37 -6
  38. package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +52 -8
  39. package/node_modules/@diffci.com/core/src/repo/types.ts +7 -0
  40. package/package.json +2 -2
@@ -21,6 +21,8 @@ const NEXT_ENTRY_NAMES = new Set(["page","layout","route","api","loading","error
21
21
  function isLockfile(filePath: string): boolean { return /(?:^|\/)(?:package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lockb?)$/.test(filePath); }
22
22
  function isSourceFilePath(filePath: string): boolean { return SOURCE_EXTENSIONS.has(extname(filePath).toLowerCase()); }
23
23
  function isAssetFilePath(filePath: string): boolean { return ASSET_EXTENSIONS.has(extname(filePath).toLowerCase()); }
24
+ /** Vitest's default `typecheck.include`: tests whose outcome is the type checker's. */
25
+ const TYPE_TEST_FILE = /\.(?:test|spec)-d\.[cm]?[jt]sx?$/;
24
26
  // "Is this a test?" is answered by the profile's test patterns (src/repo/test-discovery.ts) - one shared
25
27
  // definition with analyzer discovery and graph node flags. Module-level helpers receive it explicitly.
26
28
  type IsTestFile = (filePath: string) => boolean;
@@ -260,6 +262,16 @@ export class ImpactAnalyzer {
260
262
  private selectTestPhases = false;
261
263
  private testPhases = new Set<string>();
262
264
  private workersOutsideSuite: boolean | undefined;
265
+ private runtimeTestSelection = false;
266
+
267
+ /** Dependents whose tests a change to `path` can affect. When the graph allows runtime selection
268
+ * (DependencyGraphResult.runtimeTestSelection) an `import type` edge selects only type tests. */
269
+ private testDependents(graph: DependencyGraph, path: string, dependents: readonly string[]): ReadonlySet<string> {
270
+ if (!this.runtimeTestSelection || !graph.transitiveRuntimeDependentsOf) return new Set(dependents);
271
+ const selected = new Set(graph.transitiveRuntimeDependentsOf(path));
272
+ for (const dependent of dependents) if (TYPE_TEST_FILE.test(dependent)) selected.add(dependent);
273
+ return selected;
274
+ }
263
275
 
264
276
  /** True when nothing in the repository runs a Worker (file-references.ts, suiteMayRunWorkers); false,
265
277
  * which keeps wrangler configs global, whenever repository contents are unavailable. */
@@ -281,6 +293,7 @@ export class ImpactAnalyzer {
281
293
  this.selectTestPhases = options.selectTestPhases === true;
282
294
  this.testPhases = new Set();
283
295
  this.workersOutsideSuite = undefined;
296
+ this.runtimeTestSelection = graphResult.runtimeTestSelection === true;
284
297
  this.sortedRepositoryFiles = options.repositoryFiles ? [...options.repositoryFiles].sort() : [];
285
298
  this.compiledProjectCache = undefined;
286
299
  // One read per file per analysis, however many changed files ask who reads them.
@@ -605,6 +618,18 @@ export class ImpactAnalyzer {
605
618
  if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
606
619
  return;
607
620
  }
621
+ // A workspace package's manifest edit beyond version and metadata fields (git-diff.ts clears those)
622
+ // changes what the package installs, runs or exports, which reaches every package importing it.
623
+ // Readers that name the file are only the package's own tests, so they cannot bound it (2026-11-03).
624
+ const workspaceManifest = changedPath.endsWith("/package.json") && !changedPath.split("/").includes("node_modules")
625
+ && !this.contentCleared.has(changedPath) && changedImpact.file.changeType !== "added";
626
+ if (workspaceManifest) {
627
+ const message = `Workspace package manifest changed dependencies, scripts or resolution fields: ${changedPath}; full validation required`;
628
+ evidence.push(makeEvidence("UNKNOWN_FILE", changedPath, message));
629
+ riskSignals.push({ level: "critical", reason: "DEPENDENCY_MANIFEST", message, paths: [changedPath] });
630
+ if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
631
+ return;
632
+ }
608
633
  if (category === "test-fixture") {
609
634
  // Resolved per change PATH (a rename's old path resolves independently); an unresolvable side
610
635
  // degrades to the unknown-file fallback below rather than being silently dropped.
@@ -774,11 +799,13 @@ export class ImpactAnalyzer {
774
799
  for (const code of resolution.code) {
775
800
  if (!affectedSources.has(code)) affectedSources.set(code, []);
776
801
  affectedSources.get(code)!.push(makeEvidence("FILE_REFERENCE", changedPath, `${code} reads ${changedPath}`, code));
777
- for (const dependent of graph.transitiveDependentsOf(code)) {
778
- if (this.isTestFile(dependent)) this.addAffectedTest(changedPath, dependent, graph, affectedTests, "FILE_REFERENCE", evidence);
802
+ const codeDependents = graph.transitiveDependentsOf(code);
803
+ const testDependents = this.testDependents(graph, code, codeDependents);
804
+ for (const dependent of codeDependents) {
805
+ if (this.isTestFile(dependent) && testDependents.has(dependent)) this.addAffectedTest(changedPath, dependent, graph, affectedTests, "FILE_REFERENCE", evidence);
779
806
  else if (nodeByPath(graph, dependent)?.isEntryPoint) this.addAffectedEntryPoint(dependent, profile, affectedEntryPoints, "FILE_REFERENCE", changedPath, evidence);
780
807
  }
781
- for (const scriptPath of collectScriptsAmong([code, ...graph.transitiveDependentsOf(code)], this.isTestFile, this.layout)) {
808
+ for (const scriptPath of collectScriptsAmong([code, ...codeDependents], this.isTestFile, this.layout)) {
782
809
  if (!affectedScripts.has(scriptPath)) affectedScripts.set(scriptPath, []);
783
810
  affectedScripts.get(scriptPath)!.push(makeEvidence("FILE_REFERENCE", changedPath, `${changedPath} is read by script ${scriptPath}`, scriptPath));
784
811
  }
@@ -800,11 +827,12 @@ export class ImpactAnalyzer {
800
827
  affectedAssets.get(assetPath)!.push(makeEvidence("ASSET_DEPENDENCY", assetPath, `Changed asset: ${assetPath}`));
801
828
  if (!hasNode(graph, assetPath)) return;
802
829
  const dependents = graph.transitiveDependentsOf(assetPath);
830
+ const testDependents = this.testDependents(graph, assetPath, dependents);
803
831
  for (const dependent of dependents) {
804
832
  if (nodeByPath(graph, dependent)?.isEntryPoint) {
805
833
  this.addAffectedEntryPoint(dependent, profile, affectedEntryPoints, "ASSET_DEPENDENCY", assetPath, evidence);
806
834
  }
807
- if (this.isTestFile(dependent)) {
835
+ if (this.isTestFile(dependent) && testDependents.has(dependent)) {
808
836
  this.addAffectedTest(assetPath, dependent, graph, affectedTests, "ASSET_DEPENDENCY", evidence);
809
837
  }
810
838
  if (isSourceFilePath(dependent) && !this.isTestFile(dependent)) {
@@ -847,6 +875,7 @@ export class ImpactAnalyzer {
847
875
  }
848
876
 
849
877
  const dependents = graph.transitiveDependentsOf(sourcePath);
878
+ const testDependents = this.testDependents(graph, sourcePath, dependents);
850
879
  for (const dependent of dependents) {
851
880
  if (!this.isTestFile(dependent)) {
852
881
  if (!affectedSources.has(dependent)) affectedSources.set(dependent, []);
@@ -855,7 +884,7 @@ export class ImpactAnalyzer {
855
884
  if (nodeByPath(graph, dependent)?.isEntryPoint) {
856
885
  this.addAffectedEntryPoint(dependent, profile, affectedEntryPoints, "DEPENDENCY", sourcePath, evidence);
857
886
  }
858
- if (this.isTestFile(dependent)) {
887
+ if (this.isTestFile(dependent) && testDependents.has(dependent)) {
859
888
  this.addAffectedTest(sourcePath, dependent, graph, affectedTests, "DEPENDENCY", evidence);
860
889
  }
861
890
  }
@@ -1042,7 +1071,9 @@ export class ImpactAnalyzer {
1042
1071
  if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
1043
1072
  continue;
1044
1073
  }
1045
- const runners = [importer, ...graph.transitiveDependentsOf(importer)].filter((path) => this.isTestFile(path));
1074
+ const importerDependents = graph.transitiveDependentsOf(importer);
1075
+ const testDependents = this.testDependents(graph, importer, importerDependents);
1076
+ const runners = [importer, ...importerDependents.filter((path) => testDependents.has(path))].filter((path) => this.isTestFile(path));
1046
1077
  for (const test of runners) this.addAffectedTest(importer, test, graph, affectedTests, "COMPUTED_IMPORT", evidence);
1047
1078
  evidence.push(makeEvidence("COMPUTED_IMPORT", importer, `${importer} loads a computed module specifier; the ${runners.length} test(s) that run it are selected`));
1048
1079
  }
@@ -30,8 +30,9 @@ export type TestFamily = "unit" | "snapshot" | "e2e" | "integration" | "benchmar
30
30
  export interface TestRunnerConfig {
31
31
  /** A known unsupported declaration that makes even a nonempty test universe incomplete. */
32
32
  discoveryError?: string;
33
- /** Inline Vitest projects; undefined means no projects, null means ambiguous. */
34
- projects?: { name: string; includes: string[]; runtimeSelectionSafe: boolean }[] | null;
33
+ /** Inline Vitest projects; undefined means no projects, null means ambiguous. `excludes` holds the
34
+ * root `test.exclude` and the project's own, which `extends: true` concatenates. */
35
+ projects?: { name: string; includes: string[]; excludes?: string[]; runtimeSelectionSafe: boolean }[] | null;
35
36
  runtimeSelectionUnsafe?: boolean;
36
37
  /** Repo-relative config file, e.g. "vitest.e2e.config.ts". */
37
38
  file: string;
@@ -116,7 +117,9 @@ function inlineProjects(source: string): TestRunnerConfig["projects"] {
116
117
  let found: ts.Node[] = [];
117
118
  let sharedState = false;
118
119
  const visit = (node: ts.Node): void => {
119
- if (ts.isPropertyAssignment(node) && node.name.getText(ast) === "projects") found.push(node.initializer);
120
+ // Only `test.projects`: plugin options use the same name (LobeHub's `tsconfigPaths({ projects })`).
121
+ if (ts.isPropertyAssignment(node) && node.name.getText(ast) === "projects" && ts.isObjectLiteralExpression(node.parent)
122
+ && ts.isPropertyAssignment(node.parent.parent) && node.parent.parent.name.getText(ast) === "test") found.push(node.initializer);
120
123
  if (ts.isPropertyAssignment(node) && node.name.getText(ast) === "isolate" && node.initializer.kind !== ts.SyntaxKind.TrueKeyword) sharedState = true;
121
124
  ts.forEachChild(node, visit);
122
125
  };
@@ -127,27 +130,68 @@ function inlineProjects(source: string): TestRunnerConfig["projects"] {
127
130
  if (!ts.isObjectLiteralExpression(node)) return;
128
131
  const values = new Map<string, ts.Expression>();
129
132
  for (const property of node.properties) {
130
- if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name) || values.has(property.name.text)) return;
131
- values.set(property.name.text, property.initializer);
133
+ // `{ alias, exclude }` shorthand names a binding of the same name.
134
+ const value = ts.isPropertyAssignment(property) ? property.initializer : ts.isShorthandPropertyAssignment(property) ? property.name : undefined;
135
+ if (!value || !property.name || !ts.isIdentifier(property.name) || values.has(property.name.text)) return;
136
+ values.set(property.name.text, value);
137
+ }
138
+ return values;
139
+ };
140
+ // Top-level `const exclude = ['...']`, which configs spread into projects (2026-11-04, LobeHub).
141
+ const constArrays = new Map<string, ts.ArrayLiteralExpression>();
142
+ for (const statement of ast.statements) {
143
+ if (!ts.isVariableStatement(statement) || !(statement.declarationList.flags & ts.NodeFlags.Const)) continue;
144
+ for (const declaration of statement.declarationList.declarations) {
145
+ if (ts.isIdentifier(declaration.name) && declaration.initializer && ts.isArrayLiteralExpression(declaration.initializer)) constArrays.set(declaration.name.text, declaration.initializer);
146
+ }
147
+ }
148
+ const strings = (node: ts.Expression, depth = 0): string[] | undefined => {
149
+ if (depth > 4) return;
150
+ if (ts.isIdentifier(node)) return constArrays.has(node.text) ? strings(constArrays.get(node.text)!, depth + 1) : undefined;
151
+ if (!ts.isArrayLiteralExpression(node)) return;
152
+ const values: string[] = [];
153
+ for (const element of node.elements) {
154
+ const lifted = ts.isStringLiteral(element) ? [element.text] : ts.isSpreadElement(element) ? strings(element.expression, depth + 1) : undefined;
155
+ if (!lifted) return;
156
+ values.push(...lifted);
132
157
  }
133
158
  return values;
134
159
  };
135
160
  const projects: NonNullable<TestRunnerConfig["projects"]> = [];
136
161
  const inherited = properties(found[0].parent.parent);
137
- const inheritedSafe = inherited && [...inherited.keys()].every(key => ["projects", "coverage", "setupFiles", "globalSetup", "isolate"].includes(key));
162
+ // Root options that only shape how each file is loaded or reported. Running a subset of files under
163
+ // them runs each file exactly as the full run would (2026-11-04: LobeHub's root sets alias, deps,
164
+ // environment, exclude, globals and server.deps beside setupFiles and coverage).
165
+ const inheritedSafe = inherited && [...inherited.keys()].every(key => ["projects", "coverage", "setupFiles", "globalSetup", "isolate", "alias", "deps", "environment", "exclude", "globals", "server"].includes(key));
166
+ const inheritedExclude = inherited?.get("exclude");
167
+ const rootExcludes = inheritedExclude ? strings(inheritedExclude) : [];
168
+ if (!rootExcludes) return null;
138
169
  for (const element of found[0].elements) {
139
170
  const project = properties(element);
140
171
  const test = project?.get("test");
141
172
  const fields = test && properties(test);
142
173
  const name = fields?.get("name");
143
174
  const include = fields?.get("include");
144
- if (!project || project.size !== 2 || project.get("extends")?.kind !== ts.SyntaxKind.TrueKeyword || !fields || !name || !ts.isStringLiteral(name) || !/^[\w-]+$/.test(name.text) || !include || !ts.isArrayLiteralExpression(include) || !include.elements.length || include.elements.some(value => !ts.isStringLiteral(value))) return null;
175
+ const exclude = fields?.get("exclude");
176
+ // `extends: true` concatenates arrays, so a project without `include` takes the root's, and with no
177
+ // root include Vitest's default. A root include is not modelled.
178
+ const includes = include ? strings(include) : inherited?.has("include") ? undefined : [VITEST_DEFAULT_INCLUDE];
179
+ const excludes = exclude ? strings(exclude) : [];
180
+ if (!project || project.size !== 2 || project.get("extends")?.kind !== ts.SyntaxKind.TrueKeyword || !fields || !name || !ts.isStringLiteral(name) || !/^[\w-]+$/.test(name.text) || !includes?.length || !excludes) return null;
145
181
  if (projects.some(value => value.name === name.text)) return null;
146
- projects.push({ name: name.text, includes: include.elements.map(value => (value as ts.StringLiteral).text), runtimeSelectionSafe: Boolean(inheritedSafe) && !sharedState && [...fields.keys()].every(key => ["name", "include", "isolate"].includes(key)) });
182
+ projects.push({
183
+ name: name.text,
184
+ includes,
185
+ ...(rootExcludes.length || excludes.length ? { excludes: [...new Set([...rootExcludes, ...excludes])] } : {}),
186
+ runtimeSelectionSafe: Boolean(inheritedSafe) && !sharedState && [...fields.keys()].every(key => ["name", "include", "exclude", "environment", "isolate"].includes(key)),
187
+ });
147
188
  }
148
189
  return projects.length ? projects : null;
149
190
  }
150
191
 
192
+ /** Vitest's own `test.include` default. */
193
+ export const VITEST_DEFAULT_INCLUDE = "**/*.{test,spec}.?(c|m)[jt]s?(x)";
194
+
151
195
  export interface TestDiscovery {
152
196
  configs: TestRunnerConfig[];
153
197
  /**
@@ -171,6 +171,9 @@ export interface DependencyGraph {
171
171
  dependentsOf(filePath: string): string[];
172
172
  transitiveDependenciesOf(filePath: string): string[];
173
173
  transitiveDependentsOf(filePath: string): string[];
174
+ /** Dependents through edges that exist at runtime (`import type` excluded). Absent means unknown, and
175
+ * callers fall back to transitiveDependentsOf. */
176
+ transitiveRuntimeDependentsOf?(filePath: string): string[];
174
177
  }
175
178
 
176
179
  export interface UnresolvedDependency {
@@ -248,4 +251,8 @@ export interface DependencyGraphResult {
248
251
  * rather than assuming COMPLETE, matching computeConfidence()'s own priority (project-reference use
249
252
  * caps confidence even when nothing else flags a problem). Previously computed but never exposed. */
250
253
  resolvedViaProjectReferences: boolean;
254
+ /** Tests may be selected through runtime edges alone: every test runner found compiles without type
255
+ * checking, so an `import type` edge cannot change a test's outcome (2026-11-03). Absent or false
256
+ * means type-only edges select tests too. */
257
+ runtimeTestSelection?: boolean;
251
258
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diffci.com/diffci",
3
- "version": "0.3.23",
3
+ "version": "0.3.24",
4
4
  "description": "Fail-closed, change-aware verification for AI coding agents with conservative affected-test selection",
5
5
  "keywords": [
6
6
  "ci",
@@ -66,7 +66,7 @@
66
66
  "test": "node scripts/run-tests.mjs"
67
67
  },
68
68
  "dependencies": {
69
- "@diffci.com/core": "git+https://github.com/DiffCI/core.git#2fc16bcf8710599f87739dbff9a7b3df16405db6",
69
+ "@diffci.com/core": "git+https://github.com/DiffCI/core.git#5ffdd32b58c7eed44c3bc14fd6dbfc0e849bcf91",
70
70
  "yaml": "^2.9.0"
71
71
  },
72
72
  "devDependencies": {