@diffci.com/diffci 0.3.55 → 0.3.56
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 -3
- package/dist-client/src/client/context.d.ts +2 -0
- package/dist-client/src/client/context.js +19 -0
- package/dist-client/src/client/full-command.js +5 -2
- package/dist-client/src/client/gate.js +24 -10
- package/dist-client/src/client/job-summary.d.ts +1 -1
- package/dist-client/src/client/job-summary.js +2 -1
- package/dist-client/src/client/observe.js +1 -1
- package/dist-client/src/client/report.d.ts +7 -0
- package/dist-client/src/client/report.js +11 -0
- package/dist-client/src/client/workflow-guard.js +27 -6
- package/dist-client/src/client/workflow-templates.d.ts +11 -1
- package/dist-client/src/client/workflow-templates.js +43 -2
- package/node_modules/@diffci.com/core/README.md +4 -4
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +20 -2
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +43 -12
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +51 -8
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +111 -14
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.d.ts +3 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js +44 -6
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +158 -9
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.d.ts +11 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js +208 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js +2 -2
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js.map +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +20 -2
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +38 -12
- package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +55 -8
- package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +86 -14
- package/node_modules/@diffci.com/core/src/repo/adapters/rust-invocation.ts +44 -6
- package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +129 -9
- package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +3 -0
- package/node_modules/@diffci.com/core/src/repo/graph.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/impact.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/yarn-berry-lockfile.ts +178 -0
- package/node_modules/@diffci.com/core/src/repo/yarn-lockfile.ts +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Conservative Berry npm candidates, gated separately on an explicit node-modules linker.
|
|
4
|
+
* Like Classic, a semantic change widens to every direct dependency: the lockfile does not record
|
|
5
|
+
* the installed hoisting layout. Unknown formats, protocols, fields and missing edges fail closed.
|
|
6
|
+
* A lone workspace:. record describes the project itself, not a workspace dependency; when present
|
|
7
|
+
* it must agree with the manifest. All other workspace records and edges are unsupported.
|
|
8
|
+
*/
|
|
9
|
+
import { parseDocument, visit } from "yaml";
|
|
10
|
+
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { isExactVersion, isRegistryRequest } from "./yarn-lockfile.js";
|
|
14
|
+
|
|
15
|
+
type Direct = Readonly<Record<string, string>>;
|
|
16
|
+
type RecordMap = Map<string, unknown>;
|
|
17
|
+
interface Entry { edges: string[]; fingerprint: string }
|
|
18
|
+
interface Lock { entries: Map<string, Entry>; metadata: string; project?: string }
|
|
19
|
+
const NAME = /^(?:@[a-zA-Z0-9][a-zA-Z0-9._-]*\/)?[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
20
|
+
const record = (value: unknown): value is RecordMap => value instanceof Map && [...value.keys()].every((key) => typeof key === "string");
|
|
21
|
+
|
|
22
|
+
function yaml(content: string | undefined): RecordMap | undefined {
|
|
23
|
+
if (!content || content.length > 8 * 1024 * 1024) return undefined;
|
|
24
|
+
const lines = content.split(/\r?\n/);
|
|
25
|
+
if (lines.length > 100_000 || lines.some((line) => line.length > 16_384)) return undefined;
|
|
26
|
+
try {
|
|
27
|
+
const doc = parseDocument(content, { uniqueKeys: true });
|
|
28
|
+
if (doc.errors.length || doc.warnings.length) return undefined;
|
|
29
|
+
let unsupported = false;
|
|
30
|
+
visit(doc, { Node(_key, node, path) { if (node.anchor || node.tag || path.length > 20) unsupported = true; }, Alias() { unsupported = true; } });
|
|
31
|
+
if (unsupported) return undefined;
|
|
32
|
+
const value: unknown = doc.toJS({ mapAsMap: true, maxAliasCount: 0 });
|
|
33
|
+
return record(value) ? value : undefined;
|
|
34
|
+
} catch { return undefined; }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Do not interpolate environment-dependent settings or silently ignore additional configuration.
|
|
38
|
+
* Yarn reads environment keys case-insensitively, including YARN_RC_FILENAME and plugin overrides.
|
|
39
|
+
* The caller must analyze in the environment in which the selected tests will run. */
|
|
40
|
+
export function berryNodeModulesConfig(content: string | undefined, env: NodeJS.ProcessEnv = process.env): boolean {
|
|
41
|
+
if (Object.keys(env).some((key) => /^yarn_/i.test(key) && env[key] !== undefined)) return false;
|
|
42
|
+
const config = yaml(content);
|
|
43
|
+
return !!config && config.size === 1 && config.get("nodeLinker") === "node-modules";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The project file overrides the linker, but inherited config can still inject plugins or change
|
|
47
|
+
* resolution. This first subset requires a standalone checkout without those additional inputs. */
|
|
48
|
+
export function berryRuntimeConfig(repoPath: string | undefined): boolean {
|
|
49
|
+
try {
|
|
50
|
+
const root = realpathSync(repoPath ?? process.cwd());
|
|
51
|
+
const configPath = join(root, ".yarnrc.yml");
|
|
52
|
+
const configStat = lstatSync(configPath);
|
|
53
|
+
if (!configStat.isFile() || configStat.size > 65_536 || !berryNodeModulesConfig(readFileSync(configPath, "utf8"))) return false;
|
|
54
|
+
const extra = new Set([join(root, ".env.yarn"), join(homedir(), ".yarnrc.yml")]);
|
|
55
|
+
let parent = dirname(root);
|
|
56
|
+
while (true) {
|
|
57
|
+
extra.add(join(parent, ".yarnrc.yml"));
|
|
58
|
+
if (dirname(parent) === parent) break;
|
|
59
|
+
parent = dirname(parent);
|
|
60
|
+
}
|
|
61
|
+
extra.delete(join(root, ".yarnrc.yml"));
|
|
62
|
+
for (const path of extra) {
|
|
63
|
+
try { lstatSync(path); return false; }
|
|
64
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") return false; }
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
} catch { return false; }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function descriptor(name: string, request: string): string | undefined {
|
|
71
|
+
const range = request.startsWith("npm:") ? request.slice(4) : request;
|
|
72
|
+
return NAME.test(name) && isRegistryRequest(range) ? `${name}@npm:${range}` : undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function selectors(key: string): string[] | undefined {
|
|
76
|
+
const values = key.split(/, */);
|
|
77
|
+
let packageName: string | undefined;
|
|
78
|
+
for (const value of values) {
|
|
79
|
+
const separator = value.indexOf("@", value.startsWith("@") ? 1 : 0);
|
|
80
|
+
const name = value.slice(0, separator);
|
|
81
|
+
const request = value.slice(separator + 1);
|
|
82
|
+
if (separator < 1 || !request.startsWith("npm:") || descriptor(name, request) !== value || (packageName !== undefined && packageName !== name)) return undefined;
|
|
83
|
+
packageName = name;
|
|
84
|
+
}
|
|
85
|
+
return values;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function dependencies(value: unknown): Map<string, string> | undefined {
|
|
89
|
+
if (value === undefined) return new Map();
|
|
90
|
+
if (!record(value)) return undefined;
|
|
91
|
+
const result = new Map<string, string>();
|
|
92
|
+
for (const [name, request] of value) {
|
|
93
|
+
if (typeof request !== "string") return undefined;
|
|
94
|
+
const key = descriptor(name, request);
|
|
95
|
+
if (!key) return undefined;
|
|
96
|
+
result.set(name, key);
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const sorted = (map: Map<string, unknown>) => [...map].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
102
|
+
function parse(content: string | undefined, direct: Direct, projectName?: string): Lock | undefined {
|
|
103
|
+
const raw = yaml(content);
|
|
104
|
+
if (!raw) return undefined;
|
|
105
|
+
const metadata = raw.get("__metadata");
|
|
106
|
+
const cacheKey = record(metadata) ? metadata.get("cacheKey") : undefined;
|
|
107
|
+
// Known Berry formats only; a future serializer needs a separate review.
|
|
108
|
+
if (!record(metadata) || ![4, 6, 8].includes(metadata.get("version") as number)
|
|
109
|
+
|| [...metadata.keys()].some((key) => key !== "version" && key !== "cacheKey")
|
|
110
|
+
|| (metadata.has("cacheKey") && !["string", "number"].includes(typeof metadata.get("cacheKey")))
|
|
111
|
+
|| (typeof cacheKey === "number" && (!Number.isSafeInteger(cacheKey) || cacheKey < 0))
|
|
112
|
+
|| (metadata.has("cacheKey") && !/^[a-zA-Z0-9]+$/.test(String(metadata.get("cacheKey"))))) return undefined;
|
|
113
|
+
const entries = new Map<string, Entry>();
|
|
114
|
+
let project: string | undefined;
|
|
115
|
+
for (const [key, value] of raw) {
|
|
116
|
+
if (key === "__metadata") continue;
|
|
117
|
+
if (!record(value) || [...value.keys()].some((field) => !["version", "resolution", "checksum", "languageName", "linkType", "dependencies", "bin"].includes(field))) return undefined;
|
|
118
|
+
const deps = dependencies(value.get("dependencies"));
|
|
119
|
+
if (!deps) return undefined;
|
|
120
|
+
if (key.endsWith("@workspace:.")) {
|
|
121
|
+
if (project || !projectName || !NAME.test(projectName) || key !== `${projectName}@workspace:.`
|
|
122
|
+
|| value.get("resolution") !== key || value.get("version") !== "0.0.0-use.local" || value.get("linkType") !== "soft"
|
|
123
|
+
|| value.has("checksum") || value.has("bin")
|
|
124
|
+
|| (value.has("languageName") && !["node", "unknown"].includes(value.get("languageName") as string))
|
|
125
|
+
|| deps.size !== Object.keys(direct).length
|
|
126
|
+
|| Object.entries(direct).some(([name, request]) => deps.get(name) !== descriptor(name, request))) return undefined;
|
|
127
|
+
project = JSON.stringify([key, value.get("languageName")]);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const keys = selectors(key);
|
|
131
|
+
const version = value.get("version");
|
|
132
|
+
if (!keys || typeof version !== "string" || !isExactVersion(version) || value.get("languageName") !== "node" || value.get("linkType") !== "hard") return undefined;
|
|
133
|
+
const name = keys[0]!.slice(0, keys[0]!.indexOf("@", keys[0]!.startsWith("@") ? 1 : 0));
|
|
134
|
+
if (value.get("resolution") !== `${name}@npm:${version}`) return undefined;
|
|
135
|
+
const checksum = value.get("checksum");
|
|
136
|
+
if (checksum !== undefined && (typeof checksum !== "string" || !/^(?:[a-zA-Z0-9]+\/)?[a-f0-9]{128}$/.test(checksum))) return undefined;
|
|
137
|
+
const bin = value.get("bin");
|
|
138
|
+
if (bin !== undefined && (!record(bin) || [...bin.values()].some((path) => typeof path !== "string"))) return undefined;
|
|
139
|
+
const entry: Entry = { edges: [...deps.values()], fingerprint: JSON.stringify([version, value.get("resolution"), checksum ?? null, sorted(deps), bin ? sorted(bin as RecordMap) : null]) };
|
|
140
|
+
for (const selector of keys) {
|
|
141
|
+
if (entries.has(selector) || entries.size >= 100_000) return undefined;
|
|
142
|
+
entries.set(selector, entry);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if ([...entries.values()].some((entry) => entry.edges.some((edge) => !entries.has(edge)))) return undefined;
|
|
146
|
+
return { entries, metadata: JSON.stringify(sorted(metadata)), project };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function reachable(lock: Lock, direct: Direct): Set<Entry> | undefined {
|
|
150
|
+
const queue: Entry[] = [];
|
|
151
|
+
for (const [name, request] of Object.entries(direct)) {
|
|
152
|
+
const key = descriptor(name, request);
|
|
153
|
+
const entry = key ? lock.entries.get(key) : undefined;
|
|
154
|
+
if (!entry) return undefined;
|
|
155
|
+
queue.push(entry);
|
|
156
|
+
}
|
|
157
|
+
const seen = new Set<Entry>();
|
|
158
|
+
while (queue.length) {
|
|
159
|
+
const entry = queue.pop()!;
|
|
160
|
+
if (seen.has(entry)) continue;
|
|
161
|
+
seen.add(entry);
|
|
162
|
+
for (const key of entry.edges) queue.push(lock.entries.get(key)!);
|
|
163
|
+
}
|
|
164
|
+
return seen;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Possible affected roots, or undefined to retain full validation. Call only after linker proof. */
|
|
168
|
+
export function berryLockAffectedDependencies(oldContent: string | undefined, newContent: string | undefined, beforeDirect: Direct, afterDirect: Direct, beforeName?: string, afterName?: string): string[] | undefined {
|
|
169
|
+
const before = parse(oldContent, beforeDirect, beforeName);
|
|
170
|
+
const after = parse(newContent, afterDirect, afterName);
|
|
171
|
+
if (!before || !after || before.metadata !== after.metadata || before.project !== after.project) return undefined;
|
|
172
|
+
const oldReachable = reachable(before, beforeDirect);
|
|
173
|
+
const newReachable = reachable(after, afterDirect);
|
|
174
|
+
if (!oldReachable || !newReachable) return undefined;
|
|
175
|
+
const changed = [...new Set([...before.entries.keys(), ...after.entries.keys()])].filter((key) => before.entries.get(key)?.fingerprint !== after.entries.get(key)?.fingerprint);
|
|
176
|
+
if (changed.some((key) => !oldReachable.has(before.entries.get(key)!) && !newReachable.has(after.entries.get(key)!))) return undefined;
|
|
177
|
+
return changed.length ? [...new Set([...Object.keys(beforeDirect), ...Object.keys(afterDirect)])].sort() : [];
|
|
178
|
+
}
|
|
@@ -39,7 +39,7 @@ const IDENTIFIERS = "[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*";
|
|
|
39
39
|
const EXACT_VERSION = new RegExp(`^${NUMERIC_PART}\\.${NUMERIC_PART}\\.${NUMERIC_PART}(?:-${IDENTIFIERS})?(?:\\+${IDENTIFIERS})?$`);
|
|
40
40
|
const RANGE_VERSION = new RegExp(`^v?(?:${NUMERIC_PART}|[xX*])(?:\\.(?:${NUMERIC_PART}|[xX*])){0,2}$`);
|
|
41
41
|
|
|
42
|
-
function isExactVersion(value: string): boolean {
|
|
42
|
+
export function isExactVersion(value: string): boolean {
|
|
43
43
|
if (!EXACT_VERSION.test(value)) return false;
|
|
44
44
|
const prerelease = /^[^-]+-([^+]+)/.exec(value)?.[1];
|
|
45
45
|
return !prerelease || prerelease.split(".").every((part) => !/^0[0-9]+$/.test(part));
|
|
@@ -56,7 +56,7 @@ function isRangeVersion(value: string): boolean {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/** A deliberately limited registry semver grammar; tags and protocol requests remain unsupported. */
|
|
59
|
-
function isRegistryRequest(value: string): boolean {
|
|
59
|
+
export function isRegistryRequest(value: string): boolean {
|
|
60
60
|
if (!value || value.length > 512 || value !== value.trim()) return false;
|
|
61
61
|
return value.split("||").every((alternative) => {
|
|
62
62
|
const range = alternative.trim();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diffci.com/diffci",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.56",
|
|
4
4
|
"description": "Verification for AI coding agents: runs the tests and checks a change affects, with full fallback and a receipt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"test": "node scripts/run-tests.mjs"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@diffci.com/core": "git+https://github.com/DiffCI/core.git#
|
|
79
|
+
"@diffci.com/core": "git+https://github.com/DiffCI/core.git#49f41b339da3717619364712eebb4d94c29be6aa",
|
|
80
80
|
"saxes": "6.0.0",
|
|
81
81
|
"yaml": "^2.9.0"
|
|
82
82
|
},
|