@diffci.com/diffci 0.3.22 → 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.
Files changed (28) hide show
  1. package/dist-client/src/client/cli.js +7 -1
  2. package/dist-client/src/client/command-batches.d.ts +1 -0
  3. package/dist-client/src/client/command-batches.js +3 -2
  4. package/dist-client/src/client/selected-coverage.d.ts +21 -1
  5. package/dist-client/src/client/selected-coverage.js +83 -10
  6. package/dist-client/src/client/verify-savings.d.ts +3 -1
  7. package/dist-client/src/client/verify-savings.js +1 -0
  8. package/dist-client/src/client/verify.js +32 -16
  9. package/dist-client/src/client/workflow-guard.js +14 -0
  10. package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +3 -0
  11. package/node_modules/@diffci.com/core/dist/git/git-diff.js +93 -8
  12. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  13. package/node_modules/@diffci.com/core/dist/git/types.d.ts +6 -2
  14. package/node_modules/@diffci.com/core/dist/planner/test-command.js +13 -6
  15. package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
  16. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +1 -0
  17. package/node_modules/@diffci.com/core/dist/repo/impact.js +17 -1
  18. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  19. package/node_modules/@diffci.com/core/dist/repo/pnpm-lockfile.d.ts +6 -0
  20. package/node_modules/@diffci.com/core/dist/repo/pnpm-lockfile.js +161 -0
  21. package/node_modules/@diffci.com/core/dist/repo/pnpm-lockfile.js.map +1 -0
  22. package/node_modules/@diffci.com/core/package.json +1 -1
  23. package/node_modules/@diffci.com/core/src/git/git-diff.ts +78 -7
  24. package/node_modules/@diffci.com/core/src/git/types.ts +6 -2
  25. package/node_modules/@diffci.com/core/src/planner/test-command.ts +13 -6
  26. package/node_modules/@diffci.com/core/src/repo/impact.ts +16 -1
  27. package/node_modules/@diffci.com/core/src/repo/pnpm-lockfile.ts +147 -0
  28. package/package.json +2 -2
@@ -0,0 +1,161 @@
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
+ // Bounded independently of the repository's Git output limit, like yarn-lockfile.ts.
27
+ const MAX_CONTENT_LENGTH = 8 * 1024 * 1024;
28
+ const IMPORTER_DEPENDENCY_FIELDS = ["dependencies", "devDependencies", "optionalDependencies"];
29
+ const SNAPSHOT_EDGE_FIELDS = ["dependencies", "optionalDependencies"];
30
+ const MODELLED_FIELDS = new Set(["lockfileVersion", "importers", "packages", "snapshots"]);
31
+ const isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
32
+ /** The packages key for a snapshot key: its resolution without the peer suffix. */
33
+ function packageKey(snapshot) {
34
+ const index = snapshot.indexOf("(");
35
+ return index === -1 ? snapshot : snapshot.slice(0, index);
36
+ }
37
+ /** The snapshot an edge `name: reference` points to, or undefined for a local reference. */
38
+ function snapshotKey(name, reference) {
39
+ if (/^(?:link|file|workspace):/.test(reference))
40
+ return undefined;
41
+ // An alias edge names the real package: `string-width-cjs: string-width@4.2.3`.
42
+ return packageKey(reference).indexOf("@", 1) > 0 ? reference : `${name}@${reference}`;
43
+ }
44
+ function parseLockfile(content) {
45
+ if (content === undefined || content.length > MAX_CONTENT_LENGTH)
46
+ return undefined;
47
+ let raw;
48
+ try {
49
+ raw = parse(content, { maxAliasCount: 0 });
50
+ }
51
+ catch {
52
+ return undefined;
53
+ }
54
+ if (!isRecord(raw) || String(raw.lockfileVersion) !== "9.0")
55
+ return undefined;
56
+ const importers = raw.importers;
57
+ if (!isRecord(importers) || Object.keys(importers).length !== 1 || !isRecord(importers["."]))
58
+ return undefined;
59
+ const root = importers["."];
60
+ if (Object.keys(root).some((field) => !IMPORTER_DEPENDENCY_FIELDS.includes(field)))
61
+ return undefined;
62
+ const importer = Object.create(null);
63
+ for (const field of IMPORTER_DEPENDENCY_FIELDS) {
64
+ const record = root[field];
65
+ if (record === undefined)
66
+ continue;
67
+ if (!isRecord(record))
68
+ return undefined;
69
+ for (const [name, entry] of Object.entries(record)) {
70
+ if (!isRecord(entry) || typeof entry.version !== "string" || Object.hasOwn(importer, name))
71
+ return undefined;
72
+ importer[name] = { field, entry, version: entry.version };
73
+ }
74
+ }
75
+ const packages = raw.packages ?? {};
76
+ const snapshots = raw.snapshots ?? {};
77
+ if (!isRecord(packages) || !isRecord(snapshots) || !Object.values(snapshots).every(isRecord))
78
+ 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, rest };
81
+ }
82
+ /** The snapshot keys reachable from `root`, or undefined when an edge is local or dangling. */
83
+ function closure(lock, root) {
84
+ const seen = new Set();
85
+ const queue = [root];
86
+ while (queue.length > 0) {
87
+ const key = queue.pop();
88
+ if (seen.has(key))
89
+ continue;
90
+ const entry = lock.snapshots[key];
91
+ if (!entry)
92
+ return undefined;
93
+ seen.add(key);
94
+ for (const field of SNAPSHOT_EDGE_FIELDS) {
95
+ const edges = entry[field];
96
+ if (edges === undefined)
97
+ continue;
98
+ if (!isRecord(edges))
99
+ return undefined;
100
+ for (const [name, reference] of Object.entries(edges)) {
101
+ const next = typeof reference === "string" ? snapshotKey(name, reference) : undefined;
102
+ if (next === undefined)
103
+ return undefined;
104
+ if (!seen.has(next))
105
+ queue.push(next);
106
+ }
107
+ }
108
+ }
109
+ return seen;
110
+ }
111
+ /**
112
+ * The direct dependencies (names from the root package.json, old and new) whose request or
113
+ * installed tree differs between two pnpm-lock.yaml contents, or undefined when the change cannot
114
+ * be attributed.
115
+ */
116
+ export function pnpmLockAffectedDependencies(oldContent, newContent, directDependencies) {
117
+ const before = parseLockfile(oldContent);
118
+ const after = parseLockfile(newContent);
119
+ if (!before || !after || before.rest !== after.rest)
120
+ return undefined;
121
+ const changedPackages = new Set();
122
+ for (const key of new Set([...Object.keys(before.packages), ...Object.keys(after.packages)])) {
123
+ if (JSON.stringify(before.packages[key]) !== JSON.stringify(after.packages[key]))
124
+ changedPackages.add(key);
125
+ }
126
+ const changed = new Set();
127
+ for (const key of new Set([...Object.keys(before.snapshots), ...Object.keys(after.snapshots)])) {
128
+ if (changedPackages.has(packageKey(key)) || JSON.stringify(before.snapshots[key]) !== JSON.stringify(after.snapshots[key]))
129
+ changed.add(key);
130
+ }
131
+ const names = new Set([...directDependencies, ...Object.keys(before.importer), ...Object.keys(after.importer)]);
132
+ const affected = new Set();
133
+ const attributed = new Set();
134
+ for (const name of names) {
135
+ const requests = [before.importer[name], after.importer[name]];
136
+ if (JSON.stringify(requests[0]) !== JSON.stringify(requests[1]))
137
+ affected.add(name);
138
+ for (const [index, lock] of [before, after].entries()) {
139
+ const request = requests[index];
140
+ if (!request)
141
+ continue;
142
+ const root = snapshotKey(name, request.version);
143
+ const reached = root === undefined ? undefined : closure(lock, root);
144
+ if (!reached)
145
+ return undefined;
146
+ for (const key of reached) {
147
+ if (!changed.has(key))
148
+ continue;
149
+ affected.add(name);
150
+ attributed.add(key);
151
+ }
152
+ }
153
+ }
154
+ if ([...changed].some((key) => !attributed.has(key)))
155
+ return undefined;
156
+ const attributedPackages = new Set([...attributed].map(packageKey));
157
+ if ([...changedPackages].some((key) => !attributedPackages.has(key)))
158
+ return undefined;
159
+ return [...affected].sort();
160
+ }
161
+ //# sourceMappingURL=pnpm-lockfile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pnpm-lockfile.js","sourceRoot":"","sources":["../../src/repo/pnpm-lockfile.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAW7B,qFAAqF;AACrF,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAC3C,MAAM,0BAA0B,GAAG,CAAC,cAAc,EAAE,iBAAiB,EAAE,sBAAsB,CAAC,CAAC;AAC/F,MAAM,oBAAoB,GAAG,CAAC,cAAc,EAAE,sBAAsB,CAAC,CAAC;AACtE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,iBAAiB,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;AAE3F,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAuB,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAExH,mFAAmF;AACnF,SAAS,UAAU,CAAC,QAAgB;IAClC,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAA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WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YAChD,MAAM,OAAO,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACrE,IAAI,CAAC,OAAO;gBAAE,OAAO,SAAS,CAAC;YAC/B,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;gBAC1B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;oBAAE,SAAS;gBAChC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACnB,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACvE,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;IACpE,IAAI,CAAC,GAAG,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACvF,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9B,CAAC"}
@@ -33,7 +33,7 @@
33
33
  "scripts": {
34
34
  "build": "tsc -p tsconfig.json",
35
35
  "typecheck": "tsc -p tsconfig.check.json --noEmit",
36
- "test": "node scripts/run-tests.mjs",
36
+ "test": "tsx --test \"tests/**/*.test.ts\"",
37
37
  "benchmark": "node --import tsx scripts/benchmark.ts",
38
38
  "audit:boundary": "node scripts/audit-boundary.mjs",
39
39
  "agent:check": "node scripts/check-agent-packaging.mjs",
@@ -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
 
@@ -359,6 +360,9 @@ export interface PackageJsonChange {
359
360
  testScriptAddedPaths: string[];
360
361
  /** Dependency names whose entry changed, when `kind` is `dependencies`. */
361
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;
362
366
  }
363
367
 
364
368
  /**
@@ -374,8 +378,8 @@ export interface PackageJsonChange {
374
378
  * workspaces and unparseable JSON.
375
379
  */
376
380
  export function packageJsonChange(oldContent: string | undefined, newContent: string | undefined): PackageJsonChange {
377
- const result = (kind: PackageJsonChange["kind"], testScriptAddedPaths: string[] = [], changedDependencies: string[] = []): PackageJsonChange =>
378
- ({ kind, testScriptAddedPaths, changedDependencies });
381
+ const result = (kind: PackageJsonChange["kind"], testScriptAddedPaths: string[] = [], changedDependencies: string[] = [], specifiersOnly = false): PackageJsonChange =>
382
+ ({ kind, testScriptAddedPaths, changedDependencies, specifiersOnly });
379
383
  if (!hasRelevantPackageJsonChange(oldContent, newContent)) return result("metadata");
380
384
  let oldJson: Record<string, unknown>;
381
385
  let newJson: Record<string, unknown>;
@@ -391,17 +395,24 @@ export function packageJsonChange(oldContent: string | undefined, newContent: st
391
395
  const closure = new Set([...testScriptClosure(oldScripts), ...testScriptClosure(newScripts)]);
392
396
  const added = new Set<string>();
393
397
  const dependencies = new Set<string>();
398
+ let specifiersOnly = true;
394
399
  for (const field of new Set([...Object.keys(oldJson), ...Object.keys(newJson)])) {
395
- if (PACKAGE_JSON_METADATA_FIELDS.has(field) || PACKAGE_JSON_DATA_FIELDS.has(field)) continue;
400
+ if (PACKAGE_JSON_METADATA_FIELDS.has(field)) continue;
396
401
  if (JSON.stringify(oldJson[field]) === JSON.stringify(newJson[field])) continue;
402
+ if (PACKAGE_JSON_DATA_FIELDS.has(field)) { specifiersOnly = false; continue; }
397
403
  if (DEPENDENCY_FIELDS.has(field)) {
398
404
  const before = scriptRecord(oldJson[field]);
399
405
  const after = scriptRecord(newJson[field]);
400
406
  if (!before || !after) return result("behavioral");
401
- for (const name of new Set([...Object.keys(before), ...Object.keys(after)])) if (before[name] !== after[name]) dependencies.add(name);
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
+ }
402
412
  continue;
403
413
  }
404
414
  if (field !== "scripts") return result("behavioral");
415
+ specifiersOnly = false;
405
416
  for (const name of new Set([...Object.keys(oldScripts), ...Object.keys(newScripts)])) {
406
417
  if (oldScripts[name] === newScripts[name] || !closure.has(name)) continue;
407
418
  const edit = oldScripts[name] !== undefined && newScripts[name] !== undefined ? testListEdit(oldScripts[name]!, newScripts[name]!) : undefined;
@@ -409,7 +420,9 @@ export function packageJsonChange(oldContent: string | undefined, newContent: st
409
420
  for (const path of edit.added) added.add(path);
410
421
  }
411
422
  }
412
- return result(dependencies.size > 0 ? "dependencies" : "data", [...added].sort(), [...dependencies].sort());
423
+ return dependencies.size > 0
424
+ ? result("dependencies", [...added].sort(), [...dependencies].sort(), specifiersOnly)
425
+ : result("data", [...added].sort());
413
426
  }
414
427
 
415
428
  /** packageJsonChange's kind, with a dependency change reported as behavioral. */
@@ -428,6 +441,17 @@ function readFileAtSha(sha: string, path: string, repoPath: string | undefined):
428
441
  return result.stdout;
429
442
  }
430
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
+
431
455
  export function computeAnalysis(files: ChangedFile[]): GitDeltaAnalysis {
432
456
  const paths = files.flatMap((f) =>
433
457
  f.oldPath ? [f.path, f.oldPath] : [f.path],
@@ -642,6 +666,7 @@ export async function analyzeGitDelta(
642
666
  narrowed.add(changedPackageJson);
643
667
  if (packageChange!.kind !== "metadata" && !referenceResolvedPaths.includes("package.json")) referenceResolvedPaths.push("package.json");
644
668
  if (packageChange!.testScriptAddedPaths.length > 0) analysis.testScriptAddedPaths = packageChange!.testScriptAddedPaths;
669
+ if (packageChange!.specifiersOnly) analysis.packageJsonSpecifiersOnly = true;
645
670
  }
646
671
  }
647
672
  }
@@ -660,8 +685,13 @@ export async function analyzeGitDelta(
660
685
  const afterDirect = yarnDirectDependencies(newPackageJson);
661
686
  // A second package manager or alternate Yarn install layout is outside this model, even when
662
687
  // its configuration did not change in this delta.
663
- const unsupportedLayout = ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "bun.lock", "bun.lockb", ".yarnrc", ".yarnrc.yml", ".pnp.js", ".pnp.cjs"]
664
- .some((path) => [baseSha, headSha].some((sha) => readFileAtSha(sha, path, repoPath) !== undefined));
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
+ });
665
695
  const affected = beforeDirect && afterDirect && !unsupportedLayout
666
696
  ? yarnLockAffectedDependencies(readFileAtSha(baseSha, "yarn.lock", repoPath), readFileAtSha(headSha, "yarn.lock", repoPath), beforeDirect, afterDirect)
667
697
  : undefined;
@@ -675,6 +705,47 @@ export async function analyzeGitDelta(
675
705
  narrowed.add(changedPackageJson);
676
706
  if (packageChange!.kind !== "metadata" && !referenceResolvedPaths.includes("package.json")) referenceResolvedPaths.push("package.json");
677
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;
678
749
  }
679
750
  }
680
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. */
@@ -120,11 +120,18 @@ function configAllowsPath(config: TestRunnerConfig, path: string): boolean {
120
120
  * exits 0 having silently skipped the one that mattered (DentalPresence ebac4289f73a: a seeded bug in
121
121
  * `src/app/ingest/[...path]/route.ts` went uncaught while 120 other tests passed).
122
122
  *
123
- * WHAT. `node --test` gets each metacharacter as a one-character class (`[` becomes `[[]`), the only
124
- * escape its glob accepts: it sets `windowsPathsNoEscape` on every platform, so a backslash never
125
- * escapes. Vitest and bun match file arguments as substrings, so their paths pass through unchanged.
126
- * Other runners, and brace lists that no class can escape (brace expansion runs first), are refused,
127
- * which leaves the caller to run the full suite.
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`.
128
135
  */
129
136
  const PATTERN_CHARACTERS = /[[\]*?{}()+^$|]/;
130
137
  const LITERAL_PATH_FRAMEWORKS: ReadonlySet<KnownTestFramework> = new Set(["vitest", "bun:test"]);
@@ -132,7 +139,7 @@ const LITERAL_PATH_FRAMEWORKS: ReadonlySet<KnownTestFramework> = new Set(["vites
132
139
  /** `path` as a `node --test` glob that matches only itself, or undefined when none can. */
133
140
  export function nodeTestGlobForPath(path: string): string | undefined {
134
141
  if (/\{[^}]*(?:,|\.\.)[^}]*\}/.test(path)) return undefined;
135
- return path.replace(/[[\]*?{}()]/g, (character) => `[${character}]`);
142
+ return path.replace(/[[\]*?{}()]/g, (character) => `@([${character}])`);
136
143
  }
137
144
 
138
145
  function unrunnablePaths(framework: KnownTestFramework, paths: readonly string[]): string[] {
@@ -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
- if (this.resolveByReference(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence)) return;
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.22",
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",
@@ -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#68c3f0aa2193cbe18ae86f03c63762b4ba85f484",
69
+ "@diffci.com/core": "git+https://github.com/DiffCI/core.git#2fc16bcf8710599f87739dbff9a7b3df16405db6",
70
70
  "yaml": "^2.9.0"
71
71
  },
72
72
  "devDependencies": {