@diffci.com/diffci 0.3.17 → 0.3.19
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/cli.js +4 -2
- package/dist-client/src/client/hook.js +9 -0
- package/dist-client/src/client/verify.js +24 -3
- package/dist-client/src/client/working-tree.js +12 -0
- package/node_modules/@diffci.com/core/README.md +23 -10
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +76 -5
- 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 -3
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js +1 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js +1 -1
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/type-program.js +1 -1
- package/node_modules/@diffci.com/core/dist/planner/type-program.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +18 -2
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +51 -3
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +72 -13
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/lockfiles.d.ts +9 -0
- package/node_modules/@diffci.com/core/dist/repo/lockfiles.js +11 -0
- package/node_modules/@diffci.com/core/dist/repo/lockfiles.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +23 -1
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.d.ts +24 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js +352 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js.map +1 -0
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +64 -5
- package/node_modules/@diffci.com/core/src/git/types.ts +6 -3
- package/node_modules/@diffci.com/core/src/planner/check-narrowing.ts +1 -1
- package/node_modules/@diffci.com/core/src/planner/script-reads.ts +1 -1
- package/node_modules/@diffci.com/core/src/planner/type-program.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +57 -4
- package/node_modules/@diffci.com/core/src/repo/impact.ts +66 -13
- package/node_modules/@diffci.com/core/src/repo/lockfiles.ts +10 -0
- package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +22 -1
- package/node_modules/@diffci.com/core/src/repo/yarn-lockfile.ts +318 -0
- package/package.json +2 -2
|
@@ -39,13 +39,17 @@ const MAX_READ_BYTES = 1_048_576;
|
|
|
39
39
|
|
|
40
40
|
/** Reads repo-relative text files from a checkout at HEAD, the same tree the dependency graph reads.
|
|
41
41
|
* Binary content (a NUL byte in the first 8 KiB) and files over 1 MiB are unreadable. */
|
|
42
|
+
const TEXT_EXTENSIONS = /\.(?:[cm]?[jt]sx?|vue|go|java|kt|py|rb|sh|json|jsonc|ya?ml|toml|md|mdx|html?|css|sql|txt)$/i;
|
|
43
|
+
|
|
42
44
|
export function repositoryFileReader(repoPath: string): (path: string) => string | undefined {
|
|
43
45
|
return (path) => {
|
|
44
46
|
try {
|
|
45
47
|
const full = join(repoPath, path);
|
|
46
48
|
if (statSync(full).size > MAX_READ_BYTES) return undefined;
|
|
47
49
|
const bytes = readFileSync(full);
|
|
48
|
-
|
|
50
|
+
// Source and text files are text even when they contain a stray NUL (a separator literal): treating
|
|
51
|
+
// one as binary hid it as a reader and made suiteMayRunWorkers fail closed (2026-10-29).
|
|
52
|
+
if (!TEXT_EXTENSIONS.test(path) && bytes.subarray(0, 8192).includes(0)) return undefined;
|
|
49
53
|
return bytes.toString("utf8");
|
|
50
54
|
} catch {
|
|
51
55
|
return undefined;
|
|
@@ -142,6 +146,13 @@ export interface ReferenceResolutionInput {
|
|
|
142
146
|
/** Changed files whose content analyzeGitDelta proved cannot change how tests run
|
|
143
147
|
* (GitDeltaAnalysis.referenceResolvedPaths); a workflow reading them does not block. */
|
|
144
148
|
contentCleared?: ReadonlySet<string>;
|
|
149
|
+
/** The caller has independently modeled this file's implicit effects (e.g. lockfile dependencies).
|
|
150
|
+
* No explicit reader is then acceptable, but every potential reader must be readable and every
|
|
151
|
+
* reader found must still resolve. Defaults to false. */
|
|
152
|
+
allowNoReaders?: boolean;
|
|
153
|
+
/** No code in the repository runs a Worker (suiteMayRunWorkers is false), so a wrangler config with
|
|
154
|
+
* no reader is outside the suite. */
|
|
155
|
+
workerConfigsOutsideSuite?: boolean;
|
|
145
156
|
/** Treat a reader that tooling loads implicitly (wrangler config, Dockerfile, `*.config.*`) as
|
|
146
157
|
* unresolvable. Used for code: such a reader can run the file without anything naming it. */
|
|
147
158
|
implicitReadersUnresolvable?: boolean;
|
|
@@ -277,7 +288,41 @@ function loadsWithoutNaming(path: string): boolean {
|
|
|
277
288
|
return RUNS_FILES_WITHOUT_NAMING.test(posix.basename(path));
|
|
278
289
|
}
|
|
279
290
|
|
|
280
|
-
|
|
291
|
+
/** A Cloudflare Workers deployment config (`wrangler.toml`, `wrangler.product.jsonc`). */
|
|
292
|
+
export function isWorkerConfig(filePath: string): boolean {
|
|
293
|
+
return /^wrangler(?:\.[^./]+)?\.(?:toml|json|jsonc)$/i.test(posix.basename(filePath));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const RUNS_WORKER = /unstable_dev|unstable_startWorker|\bminiflare\b|getPlatformProxy|vitest-pool-workers|\b(?:spawn|exec|execFile|execa|fork)(?:Sync)?\([^)]{0,80}["'`](?:npx\s+)?wrangler\b|["'`]wrangler["'`]\s*,\s*\[/i;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Whether anything in the repository may run a Worker during tests (2026-10-29). Tooling loads a
|
|
300
|
+
* wrangler config without code naming it, but only when wrangler, Miniflare or the Workers test pool
|
|
301
|
+
* runs. If no code file and no test-closure script does, a test can only observe the config by reading
|
|
302
|
+
* it by name - which the reference resolver handles - so the config need not force full validation.
|
|
303
|
+
* Deliberately repository-wide rather than limited to tests' imports: a test helper may spawn wrangler.
|
|
304
|
+
* Missing contents or an unparseable manifest answer true.
|
|
305
|
+
*/
|
|
306
|
+
export function suiteMayRunWorkers(files: readonly string[], read: (path: string) => string | undefined, isCodeFile: (path: string) => boolean): boolean {
|
|
307
|
+
const manifest = read("package.json");
|
|
308
|
+
if (manifest === undefined) return true;
|
|
309
|
+
let scripts: Record<string, string>;
|
|
310
|
+
try {
|
|
311
|
+
const parsed = (JSON.parse(manifest) as { scripts?: unknown }).scripts ?? {};
|
|
312
|
+
if (!parsed || typeof parsed !== "object") return true;
|
|
313
|
+
scripts = Object.fromEntries(Object.entries(parsed).filter((entry): entry is [string, string] => typeof entry[1] === "string"));
|
|
314
|
+
} catch {
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
if ([...testScriptClosure(scripts)].some((name) => /\b(?:wrangler|miniflare)\b/i.test(scripts[name] ?? ""))) return true;
|
|
318
|
+
return files.some((path) => {
|
|
319
|
+
if (!isCodeFile(path) && !/\.config\.[cm]?[jt]s$/.test(path)) return false;
|
|
320
|
+
const content = read(path);
|
|
321
|
+
return content === undefined || RUNS_WORKER.test(content);
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const ENV_TEMPLATE =/^\.env(?:\.[^.]+)*\.(?:example|sample|template|dist)$|^env\.(?:example|sample|template)$/i;
|
|
281
326
|
/** Packages that load `.env.example` without being told its name. */
|
|
282
327
|
const IMPLICIT_ENV_TEMPLATE_LOADERS = /["'](?:dotenv-safe|dotenv-extended|dotenv-mono)["']/;
|
|
283
328
|
|
|
@@ -292,6 +337,7 @@ const IMPLICIT_ENV_TEMPLATE_LOADERS = /["'](?:dotenv-safe|dotenv-extended|dotenv
|
|
|
292
337
|
*/
|
|
293
338
|
function loadedOnlyOutsideTests(filePath: string, input: ReferenceResolutionInput, read: (path: string) => string | undefined): boolean {
|
|
294
339
|
if (/^\.github\/workflows\/[^/]+\.ya?ml$/.test(filePath)) return input.contentCleared?.has(filePath) === true;
|
|
340
|
+
if (isWorkerConfig(filePath)) return input.workerConfigsOutsideSuite === true;
|
|
295
341
|
if (!ENV_TEMPLATE.test(posix.basename(filePath))) return false;
|
|
296
342
|
const manifest = read("package.json");
|
|
297
343
|
return manifest !== undefined && !IMPLICIT_ENV_TEMPLATE_LOADERS.test(manifest);
|
|
@@ -370,7 +416,10 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
370
416
|
const base = posix.basename(candidate);
|
|
371
417
|
if (base === "package.json") {
|
|
372
418
|
const content = read(candidate);
|
|
373
|
-
if (content === undefined)
|
|
419
|
+
if (content === undefined) {
|
|
420
|
+
if (input.allowNoReaders) resolution.unresolvable.push(`${candidate} could not be read`);
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
374
423
|
const named = packageJsonNames(content, pattern, target.path, ancestors, posix.dirname(candidate));
|
|
375
424
|
if (named === "no") continue;
|
|
376
425
|
visited.add(candidate);
|
|
@@ -383,6 +432,10 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
383
432
|
}
|
|
384
433
|
if (input.isDocumentation(candidate)) continue;
|
|
385
434
|
const content = read(candidate);
|
|
435
|
+
if (content === undefined && input.allowNoReaders && (input.isCodeFile(candidate) || DIRECTING_EXTENSIONS.test(candidate) || isImplicitlyLoadedFile(candidate))) {
|
|
436
|
+
resolution.unresolvable.push(`${candidate} could not be read`);
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
386
439
|
if (content === undefined || !contentNamesPath(content, candidate, target.path, pattern, ancestors)) continue;
|
|
387
440
|
visited.add(candidate);
|
|
388
441
|
if (input.implicitReadersUnresolvable && loadsWithoutNaming(candidate)) {
|
|
@@ -426,7 +479,7 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
426
479
|
// script or test-feeding workflow step reaches: the suite cannot observe the file. Finding no such
|
|
427
480
|
// reader at all is different - the file's reader is unknown, so it stays unknown.
|
|
428
481
|
const executableReaders = resolution.readers.some((reader) => reader.kind === "transitive");
|
|
429
|
-
if (resolution.unresolvable.length === 0 && tests.size === 0 && code.size === 0 && !executableReaders && !loadedOnlyOutsideTests(filePath, input, read)) {
|
|
482
|
+
if (resolution.unresolvable.length === 0 && tests.size === 0 && code.size === 0 && !executableReaders && !input.allowNoReaders && !loadedOnlyOutsideTests(filePath, input, read)) {
|
|
430
483
|
resolution.unresolvable.push(`no test or source file names ${filePath}`);
|
|
431
484
|
}
|
|
432
485
|
resolution.phases = resolution.unresolvable.length === 0 ? [...phases].sort() : [];
|
|
@@ -8,7 +8,7 @@ import { refineConfidenceForDelta } from "./graph.js";
|
|
|
8
8
|
import { repositoryLayout, UNKNOWN_REPOSITORY_LAYOUT, type RepositoryLayout } from "./layout.js";
|
|
9
9
|
import { DEFAULT_TEST_FILE_MATCHER, matchesGlob as matchesTestGlob, testDiscoveryErrors, testFileMatcherForProfile } from "./test-discovery.js";
|
|
10
10
|
import { resolveTestFixtureOwners } from "./test-fixture-ownership.js";
|
|
11
|
-
import { infrastructureRole, isImplicitlyLoadedFile, resolveFileReferences, testScriptClosure } from "./file-references.js";
|
|
11
|
+
import { infrastructureRole, isImplicitlyLoadedFile, isWorkerConfig, resolveFileReferences, suiteMayRunWorkers, testScriptClosure } from "./file-references.js";
|
|
12
12
|
import { workflowFeedsTests } from "./workflow-test-steps.js";
|
|
13
13
|
import { modelTestScriptUniverse, type ScriptUniverse } from "./script-universe.js";
|
|
14
14
|
import { compiledProjects, type CompiledProject } from "./compiled-projects.js";
|
|
@@ -251,12 +251,24 @@ export class ImpactAnalyzer {
|
|
|
251
251
|
private layout: RepositoryLayout = UNKNOWN_REPOSITORY_LAYOUT;
|
|
252
252
|
private repositoryFiles: ReadonlySet<string> | undefined;
|
|
253
253
|
private contentCleared: ReadonlySet<string> = new Set();
|
|
254
|
+
private dependencyLockfile: string | undefined;
|
|
254
255
|
private readRepositoryFile: ((path: string) => string | undefined) | undefined;
|
|
255
256
|
private sortedRepositoryFiles: string[] = [];
|
|
256
257
|
private compiledProjectCache: CompiledProject[] | undefined;
|
|
257
258
|
private goEmbedPaths = new Set<string>();
|
|
258
259
|
private selectTestPhases = false;
|
|
259
260
|
private testPhases = new Set<string>();
|
|
261
|
+
private workersOutsideSuite: boolean | undefined;
|
|
262
|
+
|
|
263
|
+
/** True when nothing in the repository runs a Worker (file-references.ts, suiteMayRunWorkers); false,
|
|
264
|
+
* which keeps wrangler configs global, whenever repository contents are unavailable. */
|
|
265
|
+
private workerConfigsOutsideSuite(): boolean {
|
|
266
|
+
if (this.workersOutsideSuite === undefined) {
|
|
267
|
+
this.workersOutsideSuite = Boolean(this.repositoryFiles && this.readRepositoryFile)
|
|
268
|
+
&& !suiteMayRunWorkers(this.sortedRepositoryFiles, this.readRepositoryFile!, isSourceFilePath);
|
|
269
|
+
}
|
|
270
|
+
return this.workersOutsideSuite;
|
|
271
|
+
}
|
|
260
272
|
constructor(alwaysRunChecks: AlwaysRunCheck[] = DEFAULT_ALWAYS_RUN_CHECKS) { this.alwaysRunChecks = alwaysRunChecks; }
|
|
261
273
|
|
|
262
274
|
analyze(delta: GitDelta, graphResult: DependencyGraphResult, profile: RepositoryProfile, options: ImpactAnalyzeOptions = {}): ImpactResult {
|
|
@@ -267,6 +279,7 @@ export class ImpactAnalyzer {
|
|
|
267
279
|
this.repositoryFiles = options.repositoryFiles;
|
|
268
280
|
this.selectTestPhases = options.selectTestPhases === true;
|
|
269
281
|
this.testPhases = new Set();
|
|
282
|
+
this.workersOutsideSuite = undefined;
|
|
270
283
|
this.sortedRepositoryFiles = options.repositoryFiles ? [...options.repositoryFiles].sort() : [];
|
|
271
284
|
this.compiledProjectCache = undefined;
|
|
272
285
|
// One read per file per analysis, however many changed files ask who reads them.
|
|
@@ -278,6 +291,7 @@ export class ImpactAnalyzer {
|
|
|
278
291
|
});
|
|
279
292
|
const referenceResolved = new Set(delta.analysis.referenceResolvedPaths ?? []);
|
|
280
293
|
this.contentCleared = referenceResolved;
|
|
294
|
+
this.dependencyLockfile = delta.analysis.dependencyLockfile;
|
|
281
295
|
const changedImpacts: ChangedImpact[] = delta.files.map((file) => ({ file, category: classifyChangedFile(file, this.isTestFile, this.layout, options.repositoryFiles, referenceResolved), reasons: changedFileReasons(file) }));
|
|
282
296
|
const evidence: ImpactEvidence[] = [];
|
|
283
297
|
const riskSignals: ImpactRiskSignal[] = [];
|
|
@@ -432,7 +446,13 @@ export class ImpactAnalyzer {
|
|
|
432
446
|
if (rule.check(delta.analysis)) {
|
|
433
447
|
// The stable sentence stays a prefix, so consumers that categorise by it keep working; the
|
|
434
448
|
// files that triggered it follow (2026-10-21).
|
|
435
|
-
|
|
449
|
+
let paths = delta.analysis.signalPaths?.[rule.signal] ?? [];
|
|
450
|
+
if (rule.signal === "infrastructure" && paths.length > 0 && this.workerConfigsOutsideSuite()) {
|
|
451
|
+
// A wrangler config cannot reach a suite that never runs a Worker; processChangedPath resolves
|
|
452
|
+
// its readers instead (2026-10-29).
|
|
453
|
+
paths = paths.filter((path) => !isWorkerConfig(path));
|
|
454
|
+
if (paths.length === 0) continue;
|
|
455
|
+
}
|
|
436
456
|
const message = paths.length === 0 ? rule.message
|
|
437
457
|
: `${rule.message}: ${paths.slice(0, 5).join(", ")}${paths.length > 5 ? ` (+${paths.length - 5} more)` : ""}`;
|
|
438
458
|
riskSignals.push({ level: "critical", reason: rule.reason, message, ...(paths.length ? { paths: [...paths] } : {}) });
|
|
@@ -481,20 +501,33 @@ export class ImpactAnalyzer {
|
|
|
481
501
|
const packages = delta.analysis.changedDependencies;
|
|
482
502
|
if (!packages || packages.length === 0) return;
|
|
483
503
|
const { graph } = graphResult;
|
|
504
|
+
const yarnCandidates = delta.analysis.dependencyLockfile === "yarn.lock";
|
|
505
|
+
const changedFile = delta.analysis.dependencyLockfile ?? "package.json";
|
|
506
|
+
const dependencyChange = (name: string) => yarnCandidates
|
|
507
|
+
? `Dependency ${name} may be affected by the Yarn lockfile change` : `Dependency ${name} changed`;
|
|
484
508
|
const fail = (message: string) => {
|
|
485
|
-
riskSignals.push({ level: "critical", reason: "DEPENDENCY_MANIFEST", message, paths: [
|
|
509
|
+
riskSignals.push({ level: "critical", reason: "DEPENDENCY_MANIFEST", message, paths: [changedFile] });
|
|
486
510
|
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
487
511
|
};
|
|
488
512
|
// Typecheck and build tasks still see a dependency change (planner globalRiskTriggers).
|
|
489
|
-
riskSignals.push({ level: "info", reason: "DEPENDENCY_MANIFEST", message:
|
|
513
|
+
riskSignals.push({ level: "info", reason: "DEPENDENCY_MANIFEST", message: yarnCandidates
|
|
514
|
+
? `Dependencies potentially affected by Yarn lockfile change: ${packages.join(", ")}`
|
|
515
|
+
: `Dependencies changed: ${packages.join(", ")}`, paths: [changedFile] });
|
|
490
516
|
if (!this.repositoryFiles || !this.readRepositoryFile) {
|
|
491
|
-
fail(
|
|
517
|
+
fail(`${yarnCandidates ? "Potential dependency impact" : "Dependency change"} (${packages.join(", ")}) cannot be traced without repository contents; full validation required`);
|
|
492
518
|
return;
|
|
493
519
|
}
|
|
494
520
|
const packageRoot = (specifier: string) => {
|
|
495
521
|
const parts = specifier.split("/");
|
|
496
522
|
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]!;
|
|
497
523
|
};
|
|
524
|
+
if (yarnCandidates) {
|
|
525
|
+
// Classic can hoist transitive packages that repository code imports without declaring them.
|
|
526
|
+
// All-root widening covers peers, but cannot attribute these additional importers to a root.
|
|
527
|
+
const undeclared = [...new Set(graphResult.references.filter((ref) => ref.resolution === "external-package")
|
|
528
|
+
.map((ref) => packageRoot(ref.specifier)).filter((name) => !packages.includes(name)))].sort();
|
|
529
|
+
if (undeclared.length) fail(`Yarn lockfile changed and repository imports undeclared dependencies (${undeclared.join(", ")}); full validation required`);
|
|
530
|
+
}
|
|
498
531
|
const scripts = profile.packageJson.scripts;
|
|
499
532
|
const closureBodies = [...testScriptClosure(scripts)].map((name) => scripts[name] ?? "");
|
|
500
533
|
for (const name of packages) {
|
|
@@ -502,30 +535,30 @@ export class ImpactAnalyzer {
|
|
|
502
535
|
.filter((ref) => ref.resolution === "external-package" && packageRoot(ref.specifier) === name)
|
|
503
536
|
.map((ref) => ref.importer))].sort();
|
|
504
537
|
if (importers.length === 0) {
|
|
505
|
-
fail(
|
|
538
|
+
fail(`${dependencyChange(name)} and no repository source imports it; full validation required`);
|
|
506
539
|
continue;
|
|
507
540
|
}
|
|
508
541
|
const quoted = new RegExp(`["'\`]${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:/[^"'\`]*)?["'\`]`);
|
|
509
542
|
const bare = new RegExp(`(?:^|[\\s"'=])${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?=$|[\\s"'/@])`);
|
|
510
543
|
if (closureBodies.some((body) => bare.test(body))) {
|
|
511
|
-
fail(
|
|
544
|
+
fail(`${dependencyChange(name)} and the test script runs it; full validation required`);
|
|
512
545
|
continue;
|
|
513
546
|
}
|
|
514
547
|
const toolingReader = this.sortedRepositoryFiles.find((path) => isImplicitlyLoadedFile(path) && !isLockfile(path) && quoted.test(this.readRepositoryFile!(path) ?? ""));
|
|
515
548
|
if (toolingReader) {
|
|
516
|
-
fail(
|
|
549
|
+
fail(`${dependencyChange(name)} and ${toolingReader} loads it; full validation required`);
|
|
517
550
|
continue;
|
|
518
551
|
}
|
|
519
552
|
for (const importer of importers) {
|
|
520
|
-
evidence.push(makeEvidence("DEPENDENCY",
|
|
521
|
-
if (this.isTestFile(importer)) this.addAffectedTest(
|
|
553
|
+
evidence.push(makeEvidence("DEPENDENCY", changedFile, `${importer} imports ${yarnCandidates ? "potentially affected" : "changed"} dependency ${name}`, importer));
|
|
554
|
+
if (this.isTestFile(importer)) this.addAffectedTest(changedFile, importer, graph, affectedTests, "DEPENDENCY", evidence);
|
|
522
555
|
this.processSourceChange(importer, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
|
|
523
556
|
}
|
|
524
557
|
// Code outside the graph that loads the package reaches the suite only if something runs it.
|
|
525
558
|
for (const path of this.sortedRepositoryFiles) {
|
|
526
559
|
if (!isSourceFilePath(path) || hasNode(graph, path) || !quoted.test(this.readRepositoryFile(path) ?? "")) continue;
|
|
527
560
|
if (!this.resolveByReference(path, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence)) {
|
|
528
|
-
fail(
|
|
561
|
+
fail(`${dependencyChange(name)} and ${path}, which loads it, is outside the dependency graph; full validation required`);
|
|
529
562
|
break;
|
|
530
563
|
}
|
|
531
564
|
}
|
|
@@ -553,6 +586,15 @@ export class ImpactAnalyzer {
|
|
|
553
586
|
return;
|
|
554
587
|
}
|
|
555
588
|
const category = changedImpact.category;
|
|
589
|
+
if (changedPath === this.dependencyLockfile) {
|
|
590
|
+
// Dependency selection does not cover a test that reads the lockfile's bytes. Unlike general
|
|
591
|
+
// data, no reader is acceptable here because the package-manager effect was modeled already.
|
|
592
|
+
if (this.resolveByReference(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, { allowNoReaders: true, implicitReadersUnresolvable: true })) return;
|
|
593
|
+
const message = `Lockfile readers could not be resolved: ${changedPath}; full validation required`;
|
|
594
|
+
riskSignals.push({ level: "critical", reason: "LOCKFILE_GLOBAL", message, paths: [changedPath] });
|
|
595
|
+
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
556
598
|
if (category === "test-fixture") {
|
|
557
599
|
// Resolved per change PATH (a rename's old path resolves independently); an unresolvable side
|
|
558
600
|
// degrades to the unknown-file fallback below rather than being silently dropped.
|
|
@@ -596,6 +638,14 @@ export class ImpactAnalyzer {
|
|
|
596
638
|
this.processAssetChange(changedPath, graph, profile, affectedAssets, affectedEntryPoints, affectedTests, affectedSources, evidence);
|
|
597
639
|
return;
|
|
598
640
|
}
|
|
641
|
+
if (category === "infrastructure" && isWorkerConfig(changedPath) && this.workerConfigsOutsideSuite()) {
|
|
642
|
+
if (this.resolveByReference(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence)) return;
|
|
643
|
+
const message = `Unknown changed file: ${changedPath}`;
|
|
644
|
+
evidence.push(makeEvidence("UNKNOWN_FILE", changedPath, message));
|
|
645
|
+
riskSignals.push({ level: "critical", reason: "UNKNOWN_FILE", message, paths: [changedPath] });
|
|
646
|
+
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
599
649
|
if (category === "config" || category === "workflow" || category === "infrastructure" || category === "database") {
|
|
600
650
|
evidence.push(makeEvidence("CONFIG_GLOBAL", changedPath, `Global ${category} change at ${changedPath}`));
|
|
601
651
|
return;
|
|
@@ -673,9 +723,10 @@ export class ImpactAnalyzer {
|
|
|
673
723
|
affectedTests: Map<string, TestImpact>,
|
|
674
724
|
affectedScripts: Map<string, ImpactEvidence[]>,
|
|
675
725
|
evidence: ImpactEvidence[],
|
|
676
|
-
{ implicitReadersUnresolvable = false }: { implicitReadersUnresolvable?: boolean } = {},
|
|
726
|
+
{ implicitReadersUnresolvable = false, allowNoReaders = false }: { implicitReadersUnresolvable?: boolean; allowNoReaders?: boolean } = {},
|
|
677
727
|
): boolean {
|
|
678
|
-
if (!this.repositoryFiles || !this.readRepositoryFile
|
|
728
|
+
if (!this.repositoryFiles || !this.readRepositoryFile) return false;
|
|
729
|
+
if (isImplicitlyLoadedFile(changedPath) && !(isWorkerConfig(changedPath) && this.workerConfigsOutsideSuite())) return false;
|
|
679
730
|
const layout = this.layout;
|
|
680
731
|
const scripts = profile.packageJson.scripts;
|
|
681
732
|
const resolution = resolveFileReferences(changedPath, {
|
|
@@ -688,7 +739,9 @@ export class ImpactAnalyzer {
|
|
|
688
739
|
workflowFeedsTests: (content, names) => workflowFeedsTests(content, names, scripts),
|
|
689
740
|
contentCleared: this.contentCleared,
|
|
690
741
|
implicitReadersUnresolvable,
|
|
742
|
+
allowNoReaders,
|
|
691
743
|
testPhases: this.selectTestPhases,
|
|
744
|
+
workerConfigsOutsideSuite: this.workerConfigsOutsideSuite(),
|
|
692
745
|
});
|
|
693
746
|
if (resolution.unresolvable.length > 0) {
|
|
694
747
|
evidence.push(makeEvidence("UNKNOWN_FILE", changedPath, `References to ${changedPath} could not be resolved: ${resolution.unresolvable[0]}`));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* The one lockfile-name pattern behind every lockfile signal (2026-10-30, issue #47).
|
|
4
|
+
*
|
|
5
|
+
* Four copies of this regex had drifted apart: the planner's three (`check-narrowing.ts`,
|
|
6
|
+
* `script-reads.ts`, `type-program.ts`) knew npm's shrinkwrap and Bun's text lockfile, while the
|
|
7
|
+
* git-diff signal in `git-diff.ts` did not, so a change to `bun.lock` or `npm-shrinkwrap.json`
|
|
8
|
+
* alone still forced the full suite. Sharing this constant keeps the signals in agreement.
|
|
9
|
+
*/
|
|
10
|
+
export const LOCKFILE = /^(?:package-lock\.json|npm-shrinkwrap\.json|pnpm-lock\.yaml|yarn\.lock|bun\.lockb?)$/;
|
|
@@ -26,8 +26,23 @@ const NON_TEST_ACTIONS = [
|
|
|
26
26
|
"pnpm/action-setup", "oven-sh/setup-bun", "softprops/action-gh-release", "peter-evans/create-pull-request",
|
|
27
27
|
"peter-evans/create-or-update-comment", "aws-actions/configure-aws-credentials", "google-github-actions/auth",
|
|
28
28
|
"google-github-actions/setup-gcloud", "azure/login", "dependabot/fetch-metadata", "cloudflare/wrangler-action",
|
|
29
|
+
// DiffCI's own observer Action only analyses; it runs no repository command (action.yml).
|
|
30
|
+
"diffci/core",
|
|
29
31
|
];
|
|
30
|
-
|
|
32
|
+
/** DiffCI subcommands that run no tests. `verify`, `check`, `pilot` and `enforce-misses` do, so `diffci`
|
|
33
|
+
* followed by anything else stays a test runner (2026-10-29: DiffCI's own observation workflows were
|
|
34
|
+
* 60 of 65 workflow-triggered fallbacks in one dogfood repository's telemetry). */
|
|
35
|
+
const DIFFCI_NON_TEST_COMMAND = /\bdiffci["']?(?:\s+--?[\w-]+(?:=\S+)?)*\s+(?:observe|init|version|telemetry|pilot-packet|verify-workflow|validate-specs|mcp)\b/g;
|
|
36
|
+
|
|
37
|
+
/** `diffci` invoked with a subcommand still present after removing the non-test ones. */
|
|
38
|
+
const DIFFCI_COMMAND = /\bdiffci["']?(?:\s+--?[\w-]+(?:=\S+)?)*\s+[a-z][\w-]*/;
|
|
39
|
+
|
|
40
|
+
/** A job whose `if` is the literal false never runs (a retired workflow kept for its history). */
|
|
41
|
+
function jobDisabled(job: object): boolean {
|
|
42
|
+
const condition = (job as { if?: unknown }).if;
|
|
43
|
+
return condition === false || (typeof condition === "string" && /^\s*(?:\$\{\{\s*)?false(?:\s*\}\})?\s*$/.test(condition));
|
|
44
|
+
}
|
|
45
|
+
const TEST_RUNNERS = /(?:^|[\s/"'`(;&|])(?:vitest|jest|mocha|ava|tap|playwright|cypress|karma|jasmine|pytest|tox|nox|phpunit|rspec|ctest)(?=$|[\s"'`);&|])|(?:node|tsx|bun|deno)(?:\s+--?[\w-]+(?:=\S+)?)*\s+--?test\b|\b(?:go|cargo|dotnet|swift|mix|zig)\s+test\b|\b(?:mvn|mvnw|gradle|gradlew|sbt|bazel|make|just)\b/;
|
|
31
46
|
const PACKAGE_SCRIPT = /\b(?:npm|pnpm|yarn|bun)\s+(?:(?:run|run-script|-w\s+\S+|--workspace[= ]\S+|--prefix[= ]\S+|--if-present|-r|--recursive|--silent|-s)\s+)*([\w:.-]+)/g;
|
|
32
47
|
const INTERPRETER_FILE = /\b(?:node|tsx|ts-node|bash|sh|zsh|pwsh|powershell|python3?|ruby|perl|deno\s+run|bun(?:\s+run)?|npx\s+(?:--\S+\s+)*tsx)\s+(?:-{1,2}[\w-]+(?:=\S+)?\s+)*\.{0,2}\/?[\w./-]+\.(?:m?[jt]s|c[jt]s|sh|ps1|py|rb|pl)\b|(?:^|[\s;&|])\.{1,2}\/[\w./-]+/;
|
|
33
48
|
const PACKAGE_MANAGER_BUILTINS = new Set(["ci", "install", "i", "add", "remove", "uninstall", "publish", "pack", "version", "view", "info", "whoami", "login", "config", "cache", "audit", "outdated", "ls", "list", "exec", "dlx", "init", "create", "link", "prune", "dedupe", "rebuild", "set-script", "pkg", "fund", "doctor", "help", "--version", "-v"]);
|
|
@@ -35,6 +50,10 @@ const PACKAGE_MANAGER_BUILTINS = new Set(["ci", "install", "i", "add", "remove",
|
|
|
35
50
|
/** `strict` asks only whether the command runs a test runner or the test script; otherwise running any
|
|
36
51
|
* repository file also counts, because that file may run tests itself. */
|
|
37
52
|
function commandRunsTests(text: string, scripts: Readonly<Record<string, string>>, seen: Set<string> = new Set(), strict = false): boolean {
|
|
53
|
+
text = text.replace(DIFFCI_NON_TEST_COMMAND, " ");
|
|
54
|
+
// `diffci` runs tests only as a command with a remaining subcommand (verify, check, pilot, ...); as a
|
|
55
|
+
// path segment (`--prefix "$RUNNER_TEMP/diffci"`) it runs nothing.
|
|
56
|
+
if (DIFFCI_COMMAND.test(text)) return true;
|
|
38
57
|
if (TEST_RUNNERS.test(text) || (!strict && INTERPRETER_FILE.test(text))) return true;
|
|
39
58
|
for (const match of text.matchAll(PACKAGE_SCRIPT)) {
|
|
40
59
|
const name = match[1] ?? "";
|
|
@@ -78,6 +97,7 @@ export function workflowFeedsTests(workflowText: string, names: RegExp, scripts:
|
|
|
78
97
|
};
|
|
79
98
|
for (const job of Object.values(jobs as Record<string, unknown>)) {
|
|
80
99
|
if (!job || typeof job !== "object") return true;
|
|
100
|
+
if (jobDisabled(job)) continue;
|
|
81
101
|
const { steps, uses, ...configuration } = job as { steps?: unknown; uses?: unknown };
|
|
82
102
|
if (uses !== undefined) { if (names.test(JSON.stringify(job))) return true; continue; }
|
|
83
103
|
if (!Array.isArray(steps)) return true;
|
|
@@ -99,6 +119,7 @@ export function workflowMayRunTests(workflowText: string | undefined, scripts: R
|
|
|
99
119
|
if (!jobs || typeof jobs !== "object") return true;
|
|
100
120
|
for (const job of Object.values(jobs as Record<string, unknown>)) {
|
|
101
121
|
if (!job || typeof job !== "object") return true;
|
|
122
|
+
if (jobDisabled(job)) continue;
|
|
102
123
|
const record = job as { uses?: unknown; steps?: unknown; container?: unknown; services?: unknown };
|
|
103
124
|
if (record.uses !== undefined) return true;
|
|
104
125
|
if (!Array.isArray(record.steps)) return true;
|