@diffci.com/diffci 0.3.21 → 0.3.23
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.
- package/dist-client/src/client/agent-identity.d.ts +26 -0
- package/dist-client/src/client/agent-identity.js +62 -0
- package/dist-client/src/client/agent-selection.d.ts +55 -0
- package/dist-client/src/client/cli.d.ts +2 -0
- package/dist-client/src/client/cli.js +75 -4
- package/dist-client/src/client/command-batches.d.ts +27 -0
- package/dist-client/src/client/command-batches.js +8 -1
- package/dist-client/src/client/context.d.ts +47 -0
- package/dist-client/src/client/delivery-warning.d.ts +1 -0
- package/dist-client/src/client/economics.d.ts +17 -0
- package/dist-client/src/client/enforce-misses-collect.d.ts +49 -0
- package/dist-client/src/client/enforce-misses.d.ts +124 -0
- package/dist-client/src/client/enforce-policy.d.ts +33 -0
- package/dist-client/src/client/failure-baseline.d.ts +67 -0
- package/dist-client/src/client/failure-baseline.js +43 -19
- package/dist-client/src/client/feedback-prompt.d.ts +6 -0
- package/dist-client/src/client/full-command.d.ts +16 -0
- package/dist-client/src/client/gate-checks.d.ts +54 -0
- package/dist-client/src/client/gate-checks.js +16 -4
- package/dist-client/src/client/gate.d.ts +154 -0
- package/dist-client/src/client/hook.d.ts +27 -0
- package/dist-client/src/client/install.d.ts +19 -0
- package/dist-client/src/client/mcp.d.ts +2 -0
- package/dist-client/src/client/observe.d.ts +52 -0
- package/dist-client/src/client/observe.js +25 -3
- package/dist-client/src/client/package-identity.d.ts +14 -0
- package/dist-client/src/client/pilot-packet.d.ts +6 -0
- package/dist-client/src/client/report.d.ts +265 -0
- package/dist-client/src/client/selected-coverage.d.ts +39 -0
- package/dist-client/src/client/selected-coverage.js +159 -0
- package/dist-client/src/client/shared-graph-cache.d.ts +113 -0
- package/dist-client/src/client/shared-graph-cache.js +347 -0
- package/dist-client/src/client/spec-conflicts.d.ts +19 -0
- package/dist-client/src/client/submit.d.ts +61 -0
- package/dist-client/src/client/telemetry.d.ts +13 -0
- package/dist-client/src/client/usage-signal.d.ts +19 -0
- package/dist-client/src/client/verify-savings.d.ts +188 -0
- package/dist-client/src/client/verify-savings.js +4 -0
- package/dist-client/src/client/verify.d.ts +113 -0
- package/dist-client/src/client/verify.js +56 -16
- package/dist-client/src/client/workflow-guard.d.ts +59 -0
- package/dist-client/src/client/workflow-guard.js +267 -0
- package/dist-client/src/client/workflow-templates.d.ts +8 -0
- package/dist-client/src/client/working-tree.d.ts +26 -0
- package/dist-client/src/preflight/fingerprint.d.ts +29 -0
- package/dist-client/src/preflight/taxonomy.d.ts +10 -0
- package/node_modules/@diffci.com/core/README.md +4 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +110 -10
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/types.d.ts +6 -2
- package/node_modules/@diffci.com/core/dist/planner/test-command.d.ts +2 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +53 -1
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +1 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +17 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/pnpm-lockfile.d.ts +6 -0
- package/node_modules/@diffci.com/core/dist/repo/pnpm-lockfile.js +161 -0
- package/node_modules/@diffci.com/core/dist/repo/pnpm-lockfile.js.map +1 -0
- package/node_modules/@diffci.com/core/package.json +1 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +95 -9
- package/node_modules/@diffci.com/core/src/git/types.ts +6 -2
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +52 -1
- package/node_modules/@diffci.com/core/src/repo/impact.ts +16 -1
- package/node_modules/@diffci.com/core/src/repo/pnpm-lockfile.ts +147 -0
- package/package.json +9 -2
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { infrastructureRole, isImplicitlyLoadedFile, testScriptClosure } from "../repo/file-references.js";
|
|
14
14
|
import { workflowMayRunTests } from "../repo/workflow-test-steps.js";
|
|
15
15
|
import { npmLockAffectedDependencies } from "../repo/npm-lockfile.js";
|
|
16
|
+
import { pnpmLockAffectedDependencies } from "../repo/pnpm-lockfile.js";
|
|
16
17
|
import { yarnLockAffectedDependencies } from "../repo/yarn-lockfile.js";
|
|
17
18
|
import { LOCKFILE } from "../repo/lockfiles.js";
|
|
18
19
|
|
|
@@ -233,8 +234,20 @@ const CONFIG_PATTERNS = [
|
|
|
233
234
|
// flag for that file, otherwise the path-based rule still forces FULL fallback.
|
|
234
235
|
// Only explicitly understood descriptive fields may be ignored. Unknown fields can configure
|
|
235
236
|
// tools (including DiffCI itself), so a behavioral-field allowlist is unsafe.
|
|
237
|
+
//
|
|
238
|
+
// Added with a reason each (#48):
|
|
239
|
+
// - `maintainers`: npm registry metadata, like `author` and `contributors`; no installer, runner or
|
|
240
|
+
// bundler reads it.
|
|
241
|
+
// Deliberately NOT ignored, so a change still forces a full run:
|
|
242
|
+
// - `engines`: Yarn Classic fails the install on a mismatch, and npm does under `engine-strict`.
|
|
243
|
+
// - `packageManager`: Corepack picks the package manager (and its version) from it.
|
|
244
|
+
// - `sideEffects`: bundlers (webpack, Rollup, esbuild) use it to drop modules, so a bundled test can
|
|
245
|
+
// change.
|
|
246
|
+
// - `browserslist`: Babel preset-env, Autoprefixer and SWC compile against it, which changes the code
|
|
247
|
+
// babel-jest and similar transforms hand to the tests.
|
|
248
|
+
// - `prettier`, `eslintConfig`, `jest` and other tool configuration: the tool reads its options here.
|
|
236
249
|
const PACKAGE_JSON_METADATA_FIELDS = new Set([
|
|
237
|
-
"description", "keywords", "author", "contributors", "homepage", "license", "bugs", "repository",
|
|
250
|
+
"description", "keywords", "author", "contributors", "maintainers", "homepage", "license", "bugs", "repository",
|
|
238
251
|
]);
|
|
239
252
|
|
|
240
253
|
/** Narrows a path-based "package.json changed" signal to whether any behaviorally-relevant field
|
|
@@ -263,8 +276,11 @@ export function hasRelevantPackageJsonChange(oldContent: string | undefined, new
|
|
|
263
276
|
* Fields whose change cannot alter how `npm test` runs, but which a test may read (a release test
|
|
264
277
|
* asserting `version`, a packaging test reading `files`). 2026-10-21 telemetry: `version` alone was the
|
|
265
278
|
* only package.json change in 18 of one dogfood repository's 84 full runs, and non-test scripts in 15 more.
|
|
279
|
+
*
|
|
280
|
+
* `man` (#48): npm links the listed pages on a global install; nothing reads it while tests run, but a
|
|
281
|
+
* packaging test may check the paths, so it is data rather than metadata.
|
|
266
282
|
*/
|
|
267
|
-
const PACKAGE_JSON_DATA_FIELDS = new Set(["version", "files", "private", "publishConfig", "funding", "mcpName"]);
|
|
283
|
+
const PACKAGE_JSON_DATA_FIELDS = new Set(["version", "files", "private", "publishConfig", "funding", "mcpName", "man"]);
|
|
268
284
|
|
|
269
285
|
function parsePackageScripts(content: string | undefined): unknown {
|
|
270
286
|
if (content === undefined) return undefined;
|
|
@@ -344,6 +360,9 @@ export interface PackageJsonChange {
|
|
|
344
360
|
testScriptAddedPaths: string[];
|
|
345
361
|
/** Dependency names whose entry changed, when `kind` is `dependencies`. */
|
|
346
362
|
changedDependencies: string[];
|
|
363
|
+
/** `kind` is `dependencies` and the edit only changed the request of a dependency that stays in
|
|
364
|
+
* the same field (no addition, removal or move between fields, and nothing but metadata besides). */
|
|
365
|
+
specifiersOnly: boolean;
|
|
347
366
|
}
|
|
348
367
|
|
|
349
368
|
/**
|
|
@@ -359,8 +378,8 @@ export interface PackageJsonChange {
|
|
|
359
378
|
* workspaces and unparseable JSON.
|
|
360
379
|
*/
|
|
361
380
|
export function packageJsonChange(oldContent: string | undefined, newContent: string | undefined): PackageJsonChange {
|
|
362
|
-
const result = (kind: PackageJsonChange["kind"], testScriptAddedPaths: string[] = [], changedDependencies: string[] = []): PackageJsonChange =>
|
|
363
|
-
({ kind, testScriptAddedPaths, changedDependencies });
|
|
381
|
+
const result = (kind: PackageJsonChange["kind"], testScriptAddedPaths: string[] = [], changedDependencies: string[] = [], specifiersOnly = false): PackageJsonChange =>
|
|
382
|
+
({ kind, testScriptAddedPaths, changedDependencies, specifiersOnly });
|
|
364
383
|
if (!hasRelevantPackageJsonChange(oldContent, newContent)) return result("metadata");
|
|
365
384
|
let oldJson: Record<string, unknown>;
|
|
366
385
|
let newJson: Record<string, unknown>;
|
|
@@ -376,17 +395,24 @@ export function packageJsonChange(oldContent: string | undefined, newContent: st
|
|
|
376
395
|
const closure = new Set([...testScriptClosure(oldScripts), ...testScriptClosure(newScripts)]);
|
|
377
396
|
const added = new Set<string>();
|
|
378
397
|
const dependencies = new Set<string>();
|
|
398
|
+
let specifiersOnly = true;
|
|
379
399
|
for (const field of new Set([...Object.keys(oldJson), ...Object.keys(newJson)])) {
|
|
380
|
-
if (PACKAGE_JSON_METADATA_FIELDS.has(field)
|
|
400
|
+
if (PACKAGE_JSON_METADATA_FIELDS.has(field)) continue;
|
|
381
401
|
if (JSON.stringify(oldJson[field]) === JSON.stringify(newJson[field])) continue;
|
|
402
|
+
if (PACKAGE_JSON_DATA_FIELDS.has(field)) { specifiersOnly = false; continue; }
|
|
382
403
|
if (DEPENDENCY_FIELDS.has(field)) {
|
|
383
404
|
const before = scriptRecord(oldJson[field]);
|
|
384
405
|
const after = scriptRecord(newJson[field]);
|
|
385
406
|
if (!before || !after) return result("behavioral");
|
|
386
|
-
for (const name of new Set([...Object.keys(before), ...Object.keys(after)]))
|
|
407
|
+
for (const name of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
408
|
+
if (before[name] === after[name]) continue;
|
|
409
|
+
dependencies.add(name);
|
|
410
|
+
if (before[name] === undefined || after[name] === undefined) specifiersOnly = false;
|
|
411
|
+
}
|
|
387
412
|
continue;
|
|
388
413
|
}
|
|
389
414
|
if (field !== "scripts") return result("behavioral");
|
|
415
|
+
specifiersOnly = false;
|
|
390
416
|
for (const name of new Set([...Object.keys(oldScripts), ...Object.keys(newScripts)])) {
|
|
391
417
|
if (oldScripts[name] === newScripts[name] || !closure.has(name)) continue;
|
|
392
418
|
const edit = oldScripts[name] !== undefined && newScripts[name] !== undefined ? testListEdit(oldScripts[name]!, newScripts[name]!) : undefined;
|
|
@@ -394,7 +420,9 @@ export function packageJsonChange(oldContent: string | undefined, newContent: st
|
|
|
394
420
|
for (const path of edit.added) added.add(path);
|
|
395
421
|
}
|
|
396
422
|
}
|
|
397
|
-
return
|
|
423
|
+
return dependencies.size > 0
|
|
424
|
+
? result("dependencies", [...added].sort(), [...dependencies].sort(), specifiersOnly)
|
|
425
|
+
: result("data", [...added].sort());
|
|
398
426
|
}
|
|
399
427
|
|
|
400
428
|
/** packageJsonChange's kind, with a dependency change reported as behavioral. */
|
|
@@ -413,6 +441,17 @@ function readFileAtSha(sha: string, path: string, repoPath: string | undefined):
|
|
|
413
441
|
return result.stdout;
|
|
414
442
|
}
|
|
415
443
|
|
|
444
|
+
/** Root entries include directories and gitlinks, which recursive file inventories can omit. */
|
|
445
|
+
function readRootPathsAtSha(sha: string, repoPath: string | undefined): ReadonlySet<string> | undefined {
|
|
446
|
+
const result = runGit(["ls-tree", "--full-tree", "--name-only", "-z", sha], repoPath);
|
|
447
|
+
if (result.status !== 0 || !result.stdout.endsWith("\0")) return undefined;
|
|
448
|
+
const paths = result.stdout.slice(0, -1).split("\0");
|
|
449
|
+
// An absence decision needs a complete listing. Keep whitespace and backslashes literal.
|
|
450
|
+
if (paths.some((path) => !path || path === "." || path === ".." || path.includes("/"))) return undefined;
|
|
451
|
+
const roots = new Set(paths);
|
|
452
|
+
return roots.size === paths.length ? roots : undefined;
|
|
453
|
+
}
|
|
454
|
+
|
|
416
455
|
export function computeAnalysis(files: ChangedFile[]): GitDeltaAnalysis {
|
|
417
456
|
const paths = files.flatMap((f) =>
|
|
418
457
|
f.oldPath ? [f.path, f.oldPath] : [f.path],
|
|
@@ -627,6 +666,7 @@ export async function analyzeGitDelta(
|
|
|
627
666
|
narrowed.add(changedPackageJson);
|
|
628
667
|
if (packageChange!.kind !== "metadata" && !referenceResolvedPaths.includes("package.json")) referenceResolvedPaths.push("package.json");
|
|
629
668
|
if (packageChange!.testScriptAddedPaths.length > 0) analysis.testScriptAddedPaths = packageChange!.testScriptAddedPaths;
|
|
669
|
+
if (packageChange!.specifiersOnly) analysis.packageJsonSpecifiersOnly = true;
|
|
630
670
|
}
|
|
631
671
|
}
|
|
632
672
|
}
|
|
@@ -645,8 +685,13 @@ export async function analyzeGitDelta(
|
|
|
645
685
|
const afterDirect = yarnDirectDependencies(newPackageJson);
|
|
646
686
|
// A second package manager or alternate Yarn install layout is outside this model, even when
|
|
647
687
|
// its configuration did not change in this delta.
|
|
648
|
-
const
|
|
649
|
-
|
|
688
|
+
const alternateLayouts = ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "bun.lock", "bun.lockb", ".yarnrc", ".yarnrc.yml", ".pnp.js", ".pnp.cjs"];
|
|
689
|
+
const unsupportedLayout = [baseSha, headSha].some((sha) => {
|
|
690
|
+
const roots = readRootPathsAtSha(sha, repoPath);
|
|
691
|
+
// Either revision can rule out narrowing, including a layout deleted before HEAD.
|
|
692
|
+
// An unavailable or malformed listing cannot prove that these paths are absent.
|
|
693
|
+
return !roots || alternateLayouts.some((path) => roots.has(path));
|
|
694
|
+
});
|
|
650
695
|
const affected = beforeDirect && afterDirect && !unsupportedLayout
|
|
651
696
|
? yarnLockAffectedDependencies(readFileAtSha(baseSha, "yarn.lock", repoPath), readFileAtSha(headSha, "yarn.lock", repoPath), beforeDirect, afterDirect)
|
|
652
697
|
: undefined;
|
|
@@ -660,6 +705,47 @@ export async function analyzeGitDelta(
|
|
|
660
705
|
narrowed.add(changedPackageJson);
|
|
661
706
|
if (packageChange!.kind !== "metadata" && !referenceResolvedPaths.includes("package.json")) referenceResolvedPaths.push("package.json");
|
|
662
707
|
if (packageChange!.testScriptAddedPaths.length > 0) analysis.testScriptAddedPaths = packageChange!.testScriptAddedPaths;
|
|
708
|
+
if (packageChange!.specifiersOnly) analysis.packageJsonSpecifiersOnly = true;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
// 2026-11-02: pnpm records each snapshot's resolved edges, peers included, so attribution follows
|
|
713
|
+
// the npm model (src/repo/pnpm-lockfile.ts). Single-project lockfiles only; pnpm's own
|
|
714
|
+
// configuration files can change resolution or hoisting without a lockfile difference.
|
|
715
|
+
const changedPnpmLock = filesWithBinary.find((f) => f.path === "pnpm-lock.yaml" && f.changeType === "modified");
|
|
716
|
+
const otherPnpmConfiguration = allPaths.some((path) => path !== "pnpm-lock.yaml" && path !== "package.json" && (
|
|
717
|
+
LOCKFILE.test(posix.basename(path))
|
|
718
|
+
|| /^(?:\.npmrc|pnpm-workspace\.yaml|\.pnpmfile\.cjs)$/.test(path)
|
|
719
|
+
|| CONFIG_PATTERNS.some((pattern) => pattern.test(path) || pattern.test(posix.basename(path)))
|
|
720
|
+
|| isImplicitlyLoadedFile(path)));
|
|
721
|
+
if (dependencyEdit && changedPnpmLock && !otherPnpmConfiguration && (!analysis.dependencyManifestChanged || changedPackageJson)) {
|
|
722
|
+
const manifests = [oldPackageJson, newPackageJson].map((content) => { try { return JSON.parse(content ?? "") as Record<string, unknown>; } catch { return undefined; } });
|
|
723
|
+
const direct = new Set<string>();
|
|
724
|
+
let modelled = manifests.every((manifest) => manifest && manifest.workspaces === undefined
|
|
725
|
+
&& (manifest.packageManager === undefined || (typeof manifest.packageManager === "string" && manifest.packageManager.startsWith("pnpm@"))));
|
|
726
|
+
for (const manifest of manifests) {
|
|
727
|
+
for (const field of DEPENDENCY_FIELDS) {
|
|
728
|
+
const record = scriptRecord(manifest?.[field]);
|
|
729
|
+
if (!record) { modelled = false; continue; }
|
|
730
|
+
for (const name of Object.keys(record)) direct.add(name);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
const unsupportedLayout = ["package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "bun.lock", "bun.lockb"]
|
|
734
|
+
.some((path) => [baseSha, headSha].some((sha) => readFileAtSha(sha, path, repoPath) !== undefined));
|
|
735
|
+
const affected = modelled && !unsupportedLayout
|
|
736
|
+
? pnpmLockAffectedDependencies(readFileAtSha(baseSha, "pnpm-lock.yaml", repoPath), readFileAtSha(headSha, "pnpm-lock.yaml", repoPath), [...direct])
|
|
737
|
+
: undefined;
|
|
738
|
+
if (affected && (packageChange?.changedDependencies ?? []).every((name) => affected.includes(name))) {
|
|
739
|
+
analysis.dependencyManifestChanged = false;
|
|
740
|
+
analysis.lockfileChanged = false;
|
|
741
|
+
analysis.changedDependencies = affected;
|
|
742
|
+
analysis.dependencyLockfile = "pnpm-lock.yaml";
|
|
743
|
+
narrowed.add(changedPnpmLock);
|
|
744
|
+
if (changedPackageJson) {
|
|
745
|
+
narrowed.add(changedPackageJson);
|
|
746
|
+
if (packageChange!.kind !== "metadata" && !referenceResolvedPaths.includes("package.json")) referenceResolvedPaths.push("package.json");
|
|
747
|
+
if (packageChange!.testScriptAddedPaths.length > 0) analysis.testScriptAddedPaths = packageChange!.testScriptAddedPaths;
|
|
748
|
+
if (packageChange!.specifiersOnly) analysis.packageJsonSpecifiersOnly = true;
|
|
663
749
|
}
|
|
664
750
|
}
|
|
665
751
|
}
|
|
@@ -48,12 +48,16 @@ export interface GitDeltaAnalysis {
|
|
|
48
48
|
* the suite from this change on, so ImpactAnalyzer selects them. */
|
|
49
49
|
testScriptAddedPaths?: string[];
|
|
50
50
|
/** Direct dependencies potentially affected by a modeled manifest/lockfile change. npm uses its
|
|
51
|
-
* installed tree; Classic Yarn includes all roots because its lockfile omits peer relationships.
|
|
51
|
+
* installed tree and pnpm its snapshot edges; Classic Yarn includes all roots because its lockfile omits peer relationships.
|
|
52
52
|
* ImpactAnalyzer selects their importers or falls back. Absent when no narrowing happened. */
|
|
53
53
|
changedDependencies?: string[];
|
|
54
54
|
/** A modeled lockfile whose raw readers must still be resolved, including for semantic no-ops.
|
|
55
55
|
* Its dependency effects are covered by changedDependencies. */
|
|
56
|
-
dependencyLockfile?: "yarn.lock";
|
|
56
|
+
dependencyLockfile?: "yarn.lock" | "pnpm-lock.yaml";
|
|
57
|
+
/** The root package.json edit only changed dependency requests that a modeled lockfile change
|
|
58
|
+
* accounts for (2026-11-02). Its dependency effect is in changedDependencies, so ImpactAnalyzer
|
|
59
|
+
* accepts no readers of the file itself. */
|
|
60
|
+
packageJsonSpecifiersOnly?: boolean;
|
|
57
61
|
/** The changed paths behind each flag above, so a fallback reason can name its files (2026-10-21:
|
|
58
62
|
* "Configuration file(s) changed" was the most frequent reason in both telemetry cohorts and never
|
|
59
63
|
* said which file). Absent on analyses produced before this field existed. */
|
|
@@ -110,6 +110,44 @@ function configAllowsPath(config: TestRunnerConfig, path: string): boolean {
|
|
|
110
110
|
&& isUnderRoots(path, config.roots);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Test paths with pattern characters (2026-11-01).
|
|
115
|
+
*
|
|
116
|
+
* WHY. Next.js puts route tests under `[id]`, `[...slug]`, `[[...slug]]` and `(group)` directories.
|
|
117
|
+
* Most runners read a file argument as a pattern, not a path: `node --test` globs it, jest and
|
|
118
|
+
* playwright treat it as a regex, mocha, ava, jasmine, tap and cypress glob it. `[...path]` then
|
|
119
|
+
* becomes a character class that matches nothing, and when other selected files do run the command
|
|
120
|
+
* exits 0 having silently skipped the one that mattered (DentalPresence ebac4289f73a: a seeded bug in
|
|
121
|
+
* `src/app/ingest/[...path]/route.ts` went uncaught while 120 other tests passed).
|
|
122
|
+
*
|
|
123
|
+
* WHAT. `node --test` gets each metacharacter as a one-character class, the only escape its glob
|
|
124
|
+
* accepts: it sets `windowsPathsNoEscape` on every platform, so a backslash never escapes. Vitest and
|
|
125
|
+
* bun match file arguments as substrings, so their paths pass through unchanged. Other runners, and
|
|
126
|
+
* brace lists that no class can escape (brace expansion runs first), are refused, which leaves the
|
|
127
|
+
* caller to run the full suite.
|
|
128
|
+
*
|
|
129
|
+
* The class is wrapped in an extglob, `[` becoming `@([[])` rather than `[[]` (2026-11-02). The CLI
|
|
130
|
+
* runs TypeScript tests as `npx --no-install tsx --test ...`, and npx hands its arguments to a second
|
|
131
|
+
* `sh -c`, quoting only those with characters such as `(` or `*`. A bare `[[]...path[]]` went through
|
|
132
|
+
* unquoted, that shell expanded it back to the real `[...path]` directory, and node's glob matched
|
|
133
|
+
* nothing again (DentalPresence ebac4289f73a under CLI 0.3.22, on Linux; cmd.exe never expands, so
|
|
134
|
+
* Windows passed). The parentheses make npx quote the argument, and `@(x)` matches exactly `x`.
|
|
135
|
+
*/
|
|
136
|
+
const PATTERN_CHARACTERS = /[[\]*?{}()+^$|]/;
|
|
137
|
+
const LITERAL_PATH_FRAMEWORKS: ReadonlySet<KnownTestFramework> = new Set(["vitest", "bun:test"]);
|
|
138
|
+
|
|
139
|
+
/** `path` as a `node --test` glob that matches only itself, or undefined when none can. */
|
|
140
|
+
export function nodeTestGlobForPath(path: string): string | undefined {
|
|
141
|
+
if (/\{[^}]*(?:,|\.\.)[^}]*\}/.test(path)) return undefined;
|
|
142
|
+
return path.replace(/[[\]*?{}()]/g, (character) => `@([${character}])`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function unrunnablePaths(framework: KnownTestFramework, paths: readonly string[]): string[] {
|
|
146
|
+
if (LITERAL_PATH_FRAMEWORKS.has(framework)) return [];
|
|
147
|
+
if (framework === "node:test") return paths.filter((path) => nodeTestGlobForPath(path) === undefined);
|
|
148
|
+
return paths.filter((path) => PATTERN_CHARACTERS.test(path));
|
|
149
|
+
}
|
|
150
|
+
|
|
113
151
|
function buildCommand(
|
|
114
152
|
framework: KnownTestFramework,
|
|
115
153
|
packageManager: PackageManager,
|
|
@@ -119,7 +157,9 @@ function buildCommand(
|
|
|
119
157
|
const invocation = RUNNER_INVOCATION[framework];
|
|
120
158
|
const configArgs = configFile && invocation.configFlag ? [invocation.configFlag, configFile] : [];
|
|
121
159
|
const pathArgs =
|
|
122
|
-
invocation.pathStyle === "comma-separated-spec-flag" ? ["--spec", paths.join(",")]
|
|
160
|
+
invocation.pathStyle === "comma-separated-spec-flag" ? ["--spec", paths.join(",")]
|
|
161
|
+
: framework === "node:test" ? paths.map((path) => nodeTestGlobForPath(path) ?? path)
|
|
162
|
+
: [...paths];
|
|
123
163
|
|
|
124
164
|
if (isDirectlyInvoked(framework)) {
|
|
125
165
|
return { executable: invocation.binary, args: [...invocation.leadingArgs, ...configArgs, ...pathArgs] };
|
|
@@ -263,6 +303,7 @@ export function planSelectiveTestCommands(
|
|
|
263
303
|
|
|
264
304
|
const remaining = new Set(paths);
|
|
265
305
|
const groups: SelectiveTestCommandGroup[] = [];
|
|
306
|
+
const routed: Array<{ framework: KnownTestFramework; paths: string[] }> = [];
|
|
266
307
|
|
|
267
308
|
// A config with explicit include globs is the strongest statement a repository makes about which
|
|
268
309
|
// command runs which files, so those claims are honoured first.
|
|
@@ -274,6 +315,7 @@ export function planSelectiveTestCommands(
|
|
|
274
315
|
if (claimed.length === 0) continue;
|
|
275
316
|
for (const p of claimed) remaining.delete(p);
|
|
276
317
|
const framework = frameworkOfConfig(config);
|
|
318
|
+
routed.push({ framework, paths: claimed });
|
|
277
319
|
groups.push({
|
|
278
320
|
runnerId: `${framework}:${config.file}`,
|
|
279
321
|
label: `${framework} (${config.file})`,
|
|
@@ -304,6 +346,7 @@ export function planSelectiveTestCommands(
|
|
|
304
346
|
|| config.authoritative && !config.includes.some(glob => matchesGlob(path, glob))))) {
|
|
305
347
|
return { commands: [], groups: [], unroutedPaths: rest, refusalReason: "Selected tests are outside the default runner configuration" };
|
|
306
348
|
}
|
|
349
|
+
routed.push({ framework: primary, paths: rest });
|
|
307
350
|
groups.push({
|
|
308
351
|
runnerId: primary,
|
|
309
352
|
label: `${primary} (default configuration)`,
|
|
@@ -312,10 +355,18 @@ export function planSelectiveTestCommands(
|
|
|
312
355
|
});
|
|
313
356
|
}
|
|
314
357
|
|
|
358
|
+
const unrunnable = [...new Set(routed.flatMap(({ framework, paths }) => unrunnablePaths(framework, paths)))].sort();
|
|
359
|
+
if (unrunnable.length) {
|
|
360
|
+
return { commands: [], groups: [], unroutedPaths: unrunnable, refusalReason: `The runner reads test paths as patterns and cannot be given ${unrunnable[0]} literally` };
|
|
361
|
+
}
|
|
315
362
|
return { commands: groups.map((g) => g.commandSpec), groups, unroutedPaths: [] };
|
|
316
363
|
}
|
|
317
364
|
|
|
365
|
+
/** Arguments with glob characters are double-quoted when that is safe: `sh` would otherwise expand
|
|
366
|
+
* `[[]` back into the bracketed path, and `cmd.exe` keeps backslashes, so a backslash-escaped
|
|
367
|
+
* `\[` reaches the runner on Windows. Inside double quotes both shells pass the brackets through. */
|
|
318
368
|
function shellEscape(arg: string): string {
|
|
369
|
+
if (/[[\]*?{}]/.test(arg) && !/["$`\\%!\r\n]/.test(arg)) return `"${arg}"`;
|
|
319
370
|
return arg.replace(/([\s'"\\$|&;<>(){}\[\]*?#~`])/g, "\\$1");
|
|
320
371
|
}
|
|
321
372
|
|
|
@@ -252,6 +252,7 @@ export class ImpactAnalyzer {
|
|
|
252
252
|
private repositoryFiles: ReadonlySet<string> | undefined;
|
|
253
253
|
private contentCleared: ReadonlySet<string> = new Set();
|
|
254
254
|
private dependencyLockfile: string | undefined;
|
|
255
|
+
private packageJsonSpecifiersOnly = false;
|
|
255
256
|
private readRepositoryFile: ((path: string) => string | undefined) | undefined;
|
|
256
257
|
private sortedRepositoryFiles: string[] = [];
|
|
257
258
|
private compiledProjectCache: CompiledProject[] | undefined;
|
|
@@ -292,6 +293,7 @@ export class ImpactAnalyzer {
|
|
|
292
293
|
const referenceResolved = new Set(delta.analysis.referenceResolvedPaths ?? []);
|
|
293
294
|
this.contentCleared = referenceResolved;
|
|
294
295
|
this.dependencyLockfile = delta.analysis.dependencyLockfile;
|
|
296
|
+
this.packageJsonSpecifiersOnly = delta.analysis.packageJsonSpecifiersOnly === true;
|
|
295
297
|
const changedImpacts: ChangedImpact[] = delta.files.map((file) => ({ file, category: classifyChangedFile(file, this.isTestFile, this.layout, options.repositoryFiles, referenceResolved), reasons: changedFileReasons(file) }));
|
|
296
298
|
const evidence: ImpactEvidence[] = [];
|
|
297
299
|
const riskSignals: ImpactRiskSignal[] = [];
|
|
@@ -528,6 +530,14 @@ export class ImpactAnalyzer {
|
|
|
528
530
|
.map((ref) => packageRoot(ref.specifier)).filter((name) => !packages.includes(name)))].sort();
|
|
529
531
|
if (undeclared.length) fail(`Yarn lockfile changed and repository imports undeclared dependencies (${undeclared.join(", ")}); full validation required`);
|
|
530
532
|
}
|
|
533
|
+
if (delta.analysis.dependencyLockfile === "pnpm-lock.yaml") {
|
|
534
|
+
// pnpm is strict by default, but `public-hoist-pattern` and a hoisted node-linker expose
|
|
535
|
+
// transitive packages at the root. An undeclared import of one is not attributed to a root.
|
|
536
|
+
const declared = new Set([...profile.packageJson.dependencies, ...profile.packageJson.devDependencies]);
|
|
537
|
+
const undeclared = [...new Set(graphResult.references.filter((ref) => ref.resolution === "external-package")
|
|
538
|
+
.map((ref) => packageRoot(ref.specifier)).filter((name) => !declared.has(name)))].sort();
|
|
539
|
+
if (undeclared.length) fail(`pnpm lockfile changed and repository imports undeclared dependencies (${undeclared.join(", ")}); full validation required`);
|
|
540
|
+
}
|
|
531
541
|
const scripts = profile.packageJson.scripts;
|
|
532
542
|
const closureBodies = [...testScriptClosure(scripts)].map((name) => scripts[name] ?? "");
|
|
533
543
|
for (const name of packages) {
|
|
@@ -608,7 +618,12 @@ export class ImpactAnalyzer {
|
|
|
608
618
|
}
|
|
609
619
|
}
|
|
610
620
|
if (category === "unknown" || category === "test-fixture") {
|
|
611
|
-
|
|
621
|
+
// A package.json edit limited to dependency requests is covered by dependency selection, like
|
|
622
|
+
// the lockfile above, so finding no reader is not a gap. Tooling that loads a file naming it
|
|
623
|
+
// still is (2026-11-02).
|
|
624
|
+
const specifiersOnly = changedPath === "package.json" && this.packageJsonSpecifiersOnly;
|
|
625
|
+
const options = specifiersOnly ? { allowNoReaders: true, implicitReadersUnresolvable: true } : {};
|
|
626
|
+
if (this.resolveByReference(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, options)) return;
|
|
612
627
|
const message = `Unknown changed file: ${changedPath}`;
|
|
613
628
|
evidence.push(makeEvidence("UNKNOWN_FILE", changedPath, message));
|
|
614
629
|
riskSignals.push({ level: "critical", reason: "UNKNOWN_FILE", message, paths: [changedPath] });
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Which direct dependencies did a pnpm-lock.yaml change reach? (2026-11-02.)
|
|
4
|
+
*
|
|
5
|
+
* WHY. npm and Yarn Classic dependency bumps are attributed to the direct dependencies they reach
|
|
6
|
+
* (npm-lockfile.ts, yarn-lockfile.ts); a pnpm lockfile change still forced the full suite. The
|
|
7
|
+
* question is the same: which direct dependencies now resolve to a different installed tree. The
|
|
8
|
+
* impact analyzer then selects the tests that import those packages.
|
|
9
|
+
*
|
|
10
|
+
* THE MODEL. Lockfile format 9.0 (pnpm 9 and 10) lists the root project's requests under
|
|
11
|
+
* `importers["."]`, each with the `version` it resolved to. Every resolved package has a `packages`
|
|
12
|
+
* entry keyed `name@version` (its resolution) and one `snapshots` entry per peer context, keyed
|
|
13
|
+
* `name@version(peer@x)`, holding its own resolved dependency edges. A snapshot changed when its
|
|
14
|
+
* entry or its package entry changed, or was added or removed. A direct dependency is affected when
|
|
15
|
+
* its request changed, or its snapshot closure, in the old or the new lockfile, contains a changed
|
|
16
|
+
* snapshot. Peers resolved for a snapshot are among its edges and in its key, so a peer bump changes
|
|
17
|
+
* every snapshot that depends on that peer.
|
|
18
|
+
*
|
|
19
|
+
* FAILING CLOSED. Anything this does not model returns undefined, and the caller keeps the global
|
|
20
|
+
* lockfile signal: another lockfile format, an unparseable or oversized file, workspaces (an importer
|
|
21
|
+
* other than "."), `link:` or `file:` dependencies, a change to any top-level field such as
|
|
22
|
+
* `settings`, `overrides`, `patchedDependencies` or `catalogs`, a missing edge, or a changed package no
|
|
23
|
+
* direct dependency reaches.
|
|
24
|
+
*/
|
|
25
|
+
import { parse } from "yaml";
|
|
26
|
+
|
|
27
|
+
type YamlRecord = Record<string, unknown>;
|
|
28
|
+
|
|
29
|
+
interface Lockfile {
|
|
30
|
+
importer: Record<string, { field: string; entry: unknown; version: string }>;
|
|
31
|
+
packages: Record<string, unknown>;
|
|
32
|
+
snapshots: Record<string, YamlRecord>;
|
|
33
|
+
rest: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Bounded independently of the repository's Git output limit, like yarn-lockfile.ts.
|
|
37
|
+
const MAX_CONTENT_LENGTH = 8 * 1024 * 1024;
|
|
38
|
+
const IMPORTER_DEPENDENCY_FIELDS = ["dependencies", "devDependencies", "optionalDependencies"];
|
|
39
|
+
const SNAPSHOT_EDGE_FIELDS = ["dependencies", "optionalDependencies"];
|
|
40
|
+
const MODELLED_FIELDS = new Set(["lockfileVersion", "importers", "packages", "snapshots"]);
|
|
41
|
+
|
|
42
|
+
const isRecord = (value: unknown): value is YamlRecord => !!value && typeof value === "object" && !Array.isArray(value);
|
|
43
|
+
|
|
44
|
+
/** The packages key for a snapshot key: its resolution without the peer suffix. */
|
|
45
|
+
function packageKey(snapshot: string): string {
|
|
46
|
+
const index = snapshot.indexOf("(");
|
|
47
|
+
return index === -1 ? snapshot : snapshot.slice(0, index);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The snapshot an edge `name: reference` points to, or undefined for a local reference. */
|
|
51
|
+
function snapshotKey(name: string, reference: string): string | undefined {
|
|
52
|
+
if (/^(?:link|file|workspace):/.test(reference)) return undefined;
|
|
53
|
+
// An alias edge names the real package: `string-width-cjs: string-width@4.2.3`.
|
|
54
|
+
return packageKey(reference).indexOf("@", 1) > 0 ? reference : `${name}@${reference}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function parseLockfile(content: string | undefined): Lockfile | undefined {
|
|
58
|
+
if (content === undefined || content.length > MAX_CONTENT_LENGTH) return undefined;
|
|
59
|
+
let raw: unknown;
|
|
60
|
+
try { raw = parse(content, { maxAliasCount: 0 }); } catch { return undefined; }
|
|
61
|
+
if (!isRecord(raw) || String(raw.lockfileVersion) !== "9.0") return undefined;
|
|
62
|
+
const importers = raw.importers;
|
|
63
|
+
if (!isRecord(importers) || Object.keys(importers).length !== 1 || !isRecord(importers["."])) return undefined;
|
|
64
|
+
const root = importers["."];
|
|
65
|
+
if (Object.keys(root).some((field) => !IMPORTER_DEPENDENCY_FIELDS.includes(field))) return undefined;
|
|
66
|
+
const importer: Lockfile["importer"] = Object.create(null);
|
|
67
|
+
for (const field of IMPORTER_DEPENDENCY_FIELDS) {
|
|
68
|
+
const record = root[field];
|
|
69
|
+
if (record === undefined) continue;
|
|
70
|
+
if (!isRecord(record)) return undefined;
|
|
71
|
+
for (const [name, entry] of Object.entries(record)) {
|
|
72
|
+
if (!isRecord(entry) || typeof entry.version !== "string" || Object.hasOwn(importer, name)) return undefined;
|
|
73
|
+
importer[name] = { field, entry, version: entry.version };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const packages = raw.packages ?? {};
|
|
77
|
+
const snapshots = raw.snapshots ?? {};
|
|
78
|
+
if (!isRecord(packages) || !isRecord(snapshots) || !Object.values(snapshots).every(isRecord)) return undefined;
|
|
79
|
+
const rest = JSON.stringify(Object.entries(raw).filter(([field]) => !MODELLED_FIELDS.has(field)).sort(([a], [b]) => a.localeCompare(b)));
|
|
80
|
+
return { importer, packages, snapshots: snapshots as Record<string, YamlRecord>, rest };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The snapshot keys reachable from `root`, or undefined when an edge is local or dangling. */
|
|
84
|
+
function closure(lock: Lockfile, root: string): Set<string> | undefined {
|
|
85
|
+
const seen = new Set<string>();
|
|
86
|
+
const queue = [root];
|
|
87
|
+
while (queue.length > 0) {
|
|
88
|
+
const key = queue.pop()!;
|
|
89
|
+
if (seen.has(key)) continue;
|
|
90
|
+
const entry = lock.snapshots[key];
|
|
91
|
+
if (!entry) return undefined;
|
|
92
|
+
seen.add(key);
|
|
93
|
+
for (const field of SNAPSHOT_EDGE_FIELDS) {
|
|
94
|
+
const edges = entry[field];
|
|
95
|
+
if (edges === undefined) continue;
|
|
96
|
+
if (!isRecord(edges)) return undefined;
|
|
97
|
+
for (const [name, reference] of Object.entries(edges)) {
|
|
98
|
+
const next = typeof reference === "string" ? snapshotKey(name, reference) : undefined;
|
|
99
|
+
if (next === undefined) return undefined;
|
|
100
|
+
if (!seen.has(next)) queue.push(next);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return seen;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The direct dependencies (names from the root package.json, old and new) whose request or
|
|
109
|
+
* installed tree differs between two pnpm-lock.yaml contents, or undefined when the change cannot
|
|
110
|
+
* be attributed.
|
|
111
|
+
*/
|
|
112
|
+
export function pnpmLockAffectedDependencies(oldContent: string | undefined, newContent: string | undefined, directDependencies: readonly string[]): string[] | undefined {
|
|
113
|
+
const before = parseLockfile(oldContent);
|
|
114
|
+
const after = parseLockfile(newContent);
|
|
115
|
+
if (!before || !after || before.rest !== after.rest) return undefined;
|
|
116
|
+
const changedPackages = new Set<string>();
|
|
117
|
+
for (const key of new Set([...Object.keys(before.packages), ...Object.keys(after.packages)])) {
|
|
118
|
+
if (JSON.stringify(before.packages[key]) !== JSON.stringify(after.packages[key])) changedPackages.add(key);
|
|
119
|
+
}
|
|
120
|
+
const changed = new Set<string>();
|
|
121
|
+
for (const key of new Set([...Object.keys(before.snapshots), ...Object.keys(after.snapshots)])) {
|
|
122
|
+
if (changedPackages.has(packageKey(key)) || JSON.stringify(before.snapshots[key]) !== JSON.stringify(after.snapshots[key])) changed.add(key);
|
|
123
|
+
}
|
|
124
|
+
const names = new Set([...directDependencies, ...Object.keys(before.importer), ...Object.keys(after.importer)]);
|
|
125
|
+
const affected = new Set<string>();
|
|
126
|
+
const attributed = new Set<string>();
|
|
127
|
+
for (const name of names) {
|
|
128
|
+
const requests = [before.importer[name], after.importer[name]];
|
|
129
|
+
if (JSON.stringify(requests[0]) !== JSON.stringify(requests[1])) affected.add(name);
|
|
130
|
+
for (const [index, lock] of [before, after].entries()) {
|
|
131
|
+
const request = requests[index];
|
|
132
|
+
if (!request) continue;
|
|
133
|
+
const root = snapshotKey(name, request.version);
|
|
134
|
+
const reached = root === undefined ? undefined : closure(lock, root);
|
|
135
|
+
if (!reached) return undefined;
|
|
136
|
+
for (const key of reached) {
|
|
137
|
+
if (!changed.has(key)) continue;
|
|
138
|
+
affected.add(name);
|
|
139
|
+
attributed.add(key);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if ([...changed].some((key) => !attributed.has(key))) return undefined;
|
|
144
|
+
const attributedPackages = new Set([...attributed].map(packageKey));
|
|
145
|
+
if ([...changedPackages].some((key) => !attributedPackages.has(key))) return undefined;
|
|
146
|
+
return [...affected].sort();
|
|
147
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diffci.com/diffci",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.23",
|
|
4
4
|
"description": "Fail-closed, change-aware verification for AI coding agents with conservative affected-test selection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -43,6 +43,13 @@
|
|
|
43
43
|
"diffci": "dist-client/src/client/cli.js",
|
|
44
44
|
"diffci-mcp": "dist-client/src/client/mcp.js"
|
|
45
45
|
},
|
|
46
|
+
"exports": {
|
|
47
|
+
"./package.json": "./package.json",
|
|
48
|
+
"./*": {
|
|
49
|
+
"types": "./dist-client/src/client/*.d.ts",
|
|
50
|
+
"default": "./dist-client/src/client/*.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
46
53
|
"files": [
|
|
47
54
|
"dist-client/src/client",
|
|
48
55
|
"dist-client/src/preflight",
|
|
@@ -59,7 +66,7 @@
|
|
|
59
66
|
"test": "node scripts/run-tests.mjs"
|
|
60
67
|
},
|
|
61
68
|
"dependencies": {
|
|
62
|
-
"@diffci.com/core": "git+https://github.com/DiffCI/core.git#
|
|
69
|
+
"@diffci.com/core": "git+https://github.com/DiffCI/core.git#2fc16bcf8710599f87739dbff9a7b3df16405db6",
|
|
63
70
|
"yaml": "^2.9.0"
|
|
64
71
|
},
|
|
65
72
|
"devDependencies": {
|