@diffci.com/diffci 0.3.25 → 0.3.26

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 (25) hide show
  1. package/dist-client/src/client/cli.js +23 -1
  2. package/dist-client/src/client/enforce-policy.js +4 -0
  3. package/dist-client/src/client/gate.d.ts +3 -1
  4. package/dist-client/src/client/gate.js +1 -0
  5. package/dist-client/src/client/observe.js +14 -0
  6. package/dist-client/src/client/outcome-log.d.ts +80 -0
  7. package/dist-client/src/client/outcome-log.js +145 -0
  8. package/dist-client/src/client/report.d.ts +8 -0
  9. package/dist-client/src/client/verify.d.ts +3 -1
  10. package/dist-client/src/client/verify.js +1 -0
  11. package/node_modules/@diffci.com/core/dist/git/ci-config-paths.d.ts +18 -0
  12. package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js +136 -0
  13. package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js.map +1 -0
  14. package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +2 -1
  15. package/node_modules/@diffci.com/core/dist/git/git-diff.js +17 -4
  16. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  17. package/node_modules/@diffci.com/core/dist/planner/path-baseline.js +2 -1
  18. package/node_modules/@diffci.com/core/dist/planner/path-baseline.js.map +1 -1
  19. package/node_modules/@diffci.com/core/dist/repo/impact.js +1 -1
  20. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  21. package/node_modules/@diffci.com/core/src/git/ci-config-paths.ts +131 -0
  22. package/node_modules/@diffci.com/core/src/git/git-diff.ts +18 -4
  23. package/node_modules/@diffci.com/core/src/planner/path-baseline.ts +2 -1
  24. package/node_modules/@diffci.com/core/src/repo/impact.ts +1 -1
  25. package/package.json +2 -2
@@ -0,0 +1,131 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ * Which changed paths are CI pipeline definitions (2026-11-05).
4
+ *
5
+ * WHY. A pipeline definition decides which commands CI runs, so changing one can change a test outcome
6
+ * without touching anything a test imports. Only `.github/workflows/` was recognised. A GitLab
7
+ * pipeline file fell through to the unknown-file path, where reference resolution narrowed it to the
8
+ * files that name it: a test reading `.gitlab-ci.yml` became the only selected test, and a file pulled
9
+ * in by `include: local:` (read only by `.gitlab-ci.yml`) selected no tests at all.
10
+ *
11
+ * GitLab has no fixed directory, so this recognises the conventional names and also follows
12
+ * `include` from the root `.gitlab-ci.yml`. Anything it cannot follow (a variable in the path, an
13
+ * unparsable file) makes every YAML file count as pipeline config.
14
+ */
15
+ import { parse as parseYaml } from "yaml";
16
+
17
+ const GITLAB_ROOT = ".gitlab-ci.yml";
18
+ const YAML = /\.ya?ml$/i;
19
+ const MAX_INCLUDE_DEPTH = 10;
20
+
21
+ /** Recognised by name alone, with no file content. */
22
+ export function isConventionalCiConfigPath(path: string): boolean {
23
+ if (path.startsWith(".github/workflows/")) return true;
24
+ const base = path.slice(path.lastIndexOf("/") + 1).toLowerCase();
25
+ if (/(?:^|\.)gitlab-ci\.ya?ml$/.test(base)) return true; // .gitlab-ci.yml, test.gitlab-ci.yml
26
+ return path.startsWith(".gitlab/") && YAML.test(path); // .gitlab/ci/*.yml and similar
27
+ }
28
+
29
+ export interface GitlabIncludes {
30
+ /** Local files reached from the root through `include`, without the leading slash. */
31
+ paths: Set<string>;
32
+ /** Local include patterns with `*`, as regular expressions over repository paths. */
33
+ patterns: RegExp[];
34
+ /** An include could not be followed, so any YAML file may be pipeline config. */
35
+ unresolved: boolean;
36
+ }
37
+
38
+ function globToRegExp(glob: string): RegExp {
39
+ let source = "";
40
+ for (let i = 0; i < glob.length; i++) {
41
+ const char = glob[i]!;
42
+ if (char === "*" && glob[i + 1] === "*") {
43
+ source += ".*";
44
+ i++;
45
+ if (glob[i + 1] === "/") i++;
46
+ } else if (char === "*") source += "[^/]*";
47
+ else source += char.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
48
+ }
49
+ return new RegExp(`^${source}$`);
50
+ }
51
+
52
+ /** The local include targets one parsed pipeline document names. Remote, project, template and
53
+ * component includes live outside the repository, so a diff of this repository cannot change them. */
54
+ function localIncludeTargets(doc: unknown): { targets: string[]; unresolved: boolean } {
55
+ if (doc === null || typeof doc !== "object" || Array.isArray(doc)) return { targets: [], unresolved: false };
56
+ const include = (doc as Record<string, unknown>).include;
57
+ if (include === undefined) return { targets: [], unresolved: false };
58
+ const entries = Array.isArray(include) ? include : [include];
59
+ const targets: string[] = [];
60
+ let unresolved = false;
61
+ for (const entry of entries) {
62
+ let target: unknown;
63
+ if (typeof entry === "string") {
64
+ if (/^https?:\/\//i.test(entry)) continue; // shorthand for `remote:`
65
+ target = entry;
66
+ } else if (entry !== null && typeof entry === "object") {
67
+ const record = entry as Record<string, unknown>;
68
+ if (!("local" in record)) continue;
69
+ target = record.local;
70
+ } else {
71
+ unresolved = true;
72
+ continue;
73
+ }
74
+ if (typeof target !== "string" || target === "" || target.includes("$")) {
75
+ unresolved = true;
76
+ continue;
77
+ }
78
+ targets.push(target.replace(/^\/+/, ""));
79
+ }
80
+ return { targets, unresolved };
81
+ }
82
+
83
+ /**
84
+ * Follows `include` from `.gitlab-ci.yml` at one commit. `read` returns a file's content at that
85
+ * commit, or undefined when it does not exist. `files` lists the repository's files at that commit; it
86
+ * is called only for a wildcard include, whose matches may include further files.
87
+ */
88
+ export function gitlabLocalIncludes(read: (path: string) => string | undefined, files: () => readonly string[] = () => []): GitlabIncludes {
89
+ const result: GitlabIncludes = { paths: new Set(), patterns: [], unresolved: false };
90
+ const queue: Array<{ path: string; depth: number }> = [{ path: GITLAB_ROOT, depth: 0 }];
91
+ const seen = new Set<string>([GITLAB_ROOT]);
92
+ while (queue.length > 0) {
93
+ const { path, depth } = queue.shift()!;
94
+ const content = read(path);
95
+ if (content === undefined) continue; // a missing include fails the GitLab pipeline itself
96
+ let doc: unknown;
97
+ try {
98
+ doc = parseYaml(content);
99
+ } catch {
100
+ result.unresolved = true;
101
+ continue;
102
+ }
103
+ const { targets, unresolved } = localIncludeTargets(doc);
104
+ if (unresolved) result.unresolved = true;
105
+ for (const target of targets) {
106
+ const matches = target.includes("*")
107
+ ? (() => { const pattern = globToRegExp(target); result.patterns.push(pattern); return files().filter((f) => pattern.test(f)); })()
108
+ : [target];
109
+ for (const match of matches) {
110
+ if (match !== GITLAB_ROOT) result.paths.add(match);
111
+ if (seen.has(match)) continue;
112
+ seen.add(match);
113
+ if (depth + 1 >= MAX_INCLUDE_DEPTH) { result.unresolved = true; continue; }
114
+ queue.push({ path: match, depth: depth + 1 });
115
+ }
116
+ }
117
+ }
118
+ return result;
119
+ }
120
+
121
+ /** A predicate over changed paths: conventional names, plus whatever either commit's includes reach. */
122
+ export function ciConfigPredicate(includes: readonly GitlabIncludes[] = []): (path: string) => boolean {
123
+ const paths = new Set(includes.flatMap((i) => [...i.paths]));
124
+ const patterns = includes.flatMap((i) => i.patterns);
125
+ const anyYaml = includes.some((i) => i.unresolved);
126
+ return (path) =>
127
+ isConventionalCiConfigPath(path)
128
+ || paths.has(path)
129
+ || patterns.some((pattern) => pattern.test(path))
130
+ || (anyYaml && YAML.test(path));
131
+ }
@@ -16,6 +16,7 @@ import { npmLockAffectedDependencies } from "../repo/npm-lockfile.js";
16
16
  import { pnpmLockAffectedDependencies } from "../repo/pnpm-lockfile.js";
17
17
  import { yarnLockAffectedDependencies } from "../repo/yarn-lockfile.js";
18
18
  import { LOCKFILE } from "../repo/lockfiles.js";
19
+ import { ciConfigPredicate, gitlabLocalIncludes, isConventionalCiConfigPath } from "./ci-config-paths.js";
19
20
 
20
21
  export const EMPTY_TREE_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
21
22
  export const ZERO_SHA = "0000000000000000000000000000000000000000";
@@ -441,6 +442,14 @@ function readFileAtSha(sha: string, path: string, repoPath: string | undefined):
441
442
  return result.stdout;
442
443
  }
443
444
 
445
+ /** Every file path at a commit, for wildcard GitLab includes. Empty when the listing fails, which only
446
+ * loses matches inside a wildcard include's own includes; the wildcard itself still matches changes. */
447
+ function listFilesAtSha(sha: string, repoPath: string | undefined): string[] {
448
+ const result = runGit(["ls-tree", "-r", "--full-tree", "--name-only", "-z", sha], repoPath);
449
+ if (result.status !== 0) return [];
450
+ return result.stdout.split("").filter(Boolean);
451
+ }
452
+
444
453
  /** Root entries include directories and gitlinks, which recursive file inventories can omit. */
445
454
  function readRootPathsAtSha(sha: string, repoPath: string | undefined): ReadonlySet<string> | undefined {
446
455
  const result = runGit(["ls-tree", "--full-tree", "--name-only", "-z", sha], repoPath);
@@ -452,7 +461,8 @@ function readRootPathsAtSha(sha: string, repoPath: string | undefined): Readonly
452
461
  return roots.size === paths.length ? roots : undefined;
453
462
  }
454
463
 
455
- export function computeAnalysis(files: ChangedFile[]): GitDeltaAnalysis {
464
+ /** `isCiConfig` defaults to names alone; analyzeGitDelta also passes what GitLab `include` reaches. */
465
+ export function computeAnalysis(files: ChangedFile[], isCiConfig: (path: string) => boolean = isConventionalCiConfigPath): GitDeltaAnalysis {
456
466
  const paths = files.flatMap((f) =>
457
467
  f.oldPath ? [f.path, f.oldPath] : [f.path],
458
468
  );
@@ -462,7 +472,7 @@ export function computeAnalysis(files: ChangedFile[]): GitDeltaAnalysis {
462
472
  config: matching((p) => CONFIG_PATTERNS.some((pattern) => pattern.test(p))),
463
473
  dependencyManifest: matching((p) => p === "package.json"),
464
474
  lockfile: matching((p) => LOCKFILE.test(p)),
465
- workflow: matching((p) => p.startsWith(".github/workflows/")),
475
+ workflow: matching(isCiConfig),
466
476
  infrastructure: matching((p) => infrastructureRole(p) === "definition"),
467
477
  database: matching((p) => p.startsWith("database/")),
468
478
  };
@@ -616,7 +626,11 @@ export async function analyzeGitDelta(
616
626
  f.oldPath ? [f.path, f.oldPath] : [f.path],
617
627
  );
618
628
 
619
- const analysis = computeAnalysis(filesWithBinary);
629
+ // A GitLab pipeline can pull in any local file through `include`; follow it at both commits, since
630
+ // dropping an include changes the pipeline as much as adding one (2026-11-05).
631
+ const isCiConfig = ciConfigPredicate([baseSha, headSha].map((sha) =>
632
+ gitlabLocalIncludes((path) => readFileAtSha(sha, path, repoPath), () => listFilesAtSha(sha, repoPath))));
633
+ const analysis = computeAnalysis(filesWithBinary, isCiConfig);
620
634
  // Stage 1B fix (2026-08-21): narrow the path-based dependencyManifestChanged signal to whether a
621
635
  // behaviorally-relevant field actually changed - only attempted when the root package.json itself
622
636
  // was modified (not added/deleted/renamed, which stay unambiguously true - see
@@ -781,7 +795,7 @@ export async function analyzeGitDelta(
781
795
  if (narrowed.size > 0) {
782
796
  // Do not let the generic path rules undo the content-level narrowing. Other changes in the same
783
797
  // delta must still force full validation.
784
- const remaining = computeAnalysis(filesWithBinary.filter((f) => !narrowed.has(f)));
798
+ const remaining = computeAnalysis(filesWithBinary.filter((f) => !narrowed.has(f)), isCiConfig);
785
799
  analysis.configChanged = remaining.configChanged;
786
800
  analysis.workflowChanged = remaining.workflowChanged;
787
801
  analysis.signalPaths = { ...analysis.signalPaths, config: remaining.signalPaths?.config, workflow: remaining.signalPaths?.workflow,
@@ -37,6 +37,7 @@
37
37
  * the rules described someone else's repository.
38
38
  */
39
39
  import type { ChangedFile } from "../git/types.js";
40
+ import { isConventionalCiConfigPath } from "../git/ci-config-paths.js";
40
41
  import type { RepositoryProfile } from "../repo/types.js";
41
42
  import { repositoryLayout, UNKNOWN_REPOSITORY_LAYOUT } from "../repo/layout.js";
42
43
 
@@ -145,7 +146,7 @@ export function runPathBaseline(
145
146
  if (changedPaths.some((p) => p === "package.json" || p === "package-lock.json" || /^(yarn\.lock|pnpm-lock\.yaml|bun\.lockb?)$/.test(p))) {
146
147
  return runEverything("config/dependency -> full fallback", "config/dependency change triggers full fallback");
147
148
  }
148
- if (changedPaths.some((p) => p.startsWith(".github/workflows/"))) {
149
+ if (changedPaths.some(isConventionalCiConfigPath)) {
149
150
  return runEverything("workflow change -> full fallback", "workflow change triggers full fallback");
150
151
  }
151
152
  if (changedPaths.some((p) => DATABASE_DIRECTORIES.has(firstSegment(p)))) {
@@ -459,7 +459,7 @@ export class ImpactAnalyzer {
459
459
  { reason: "CONFIG_GLOBAL", message: "Configuration file(s) changed; full validation required", signal: "config", check: (a) => a.configChanged },
460
460
  { reason: "DEPENDENCY_MANIFEST", message: "Dependency manifest changed; full validation required", signal: "dependencyManifest", check: (a) => a.dependencyManifestChanged },
461
461
  { reason: "LOCKFILE_GLOBAL", message: "Lockfile changed; full validation required", signal: "lockfile", check: (a) => a.lockfileChanged },
462
- { reason: "WORKFLOW_GLOBAL", message: "GitHub workflow definition(s) changed; full validation required", signal: "workflow", check: (a) => a.workflowChanged },
462
+ { reason: "WORKFLOW_GLOBAL", message: "CI workflow definition(s) changed; full validation required", signal: "workflow", check: (a) => a.workflowChanged },
463
463
  { reason: "INFRASTRUCTURE_GLOBAL", message: "Infrastructure definition(s) changed; full validation required", signal: "infrastructure", check: (a) => a.infrastructureChanged },
464
464
  { reason: "DATABASE_GLOBAL", message: "Database definition(s) changed; full validation required", signal: "database", check: (a) => a.databaseChanged },
465
465
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diffci.com/diffci",
3
- "version": "0.3.25",
3
+ "version": "0.3.26",
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#7fe80905e10a59dca840a1551269f471eaf2973e",
69
+ "@diffci.com/core": "git+https://github.com/DiffCI/core.git#2fe58684ecd2621a7beb64952862acdb2def0503",
70
70
  "yaml": "^2.9.0"
71
71
  },
72
72
  "devDependencies": {