@rightkit/release 0.6.52 → 0.6.55
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/README.md +6 -1
- package/adapter-env.mjs +16 -105
- package/admission-host.mjs +14 -1
- package/bin/darwin/rightkit-swap +0 -0
- package/bin/rightkit-gate.mjs +585 -404
- package/broker-admission.mjs +122 -2
- package/build-launch.mjs +52 -58
- package/build-release.mjs +2 -2
- package/cargo-ledger.mjs +24 -5
- package/cargo-target-shim.mjs +54 -23
- package/cargo-target.mjs +2 -2
- package/carried-adapter-run.mjs +7 -8
- package/carried-cargo-run.mjs +1 -1
- package/ci-compile-admission.mjs +1 -1
- package/clippy-route.mjs +65 -18
- package/compile-inputs.mjs +91 -15
- package/cross-targets.mjs +5 -3
- package/deps-cargo-lock.mjs +1 -1
- package/deterministic-scans.mjs +789 -259
- package/development.mjs +33 -7
- package/direct-receipt.mjs +3 -5
- package/feature-coverage.mjs +45 -9
- package/feature-partition.mjs +204 -0
- package/feature-sets.mjs +113 -0
- package/gate-acceptance.mjs +187 -115
- package/gate-seam.mjs +352 -0
- package/gate-serve.mjs +34 -2
- package/gate-stages.mjs +6 -2
- package/ghsa-audit.mjs +19 -4
- package/heavy-command.mjs +5 -4
- package/install-tauri-authenticode.mjs +73 -4
- package/ios-dev.mjs +3 -3
- package/ios-package-recipe.mjs +6 -6
- package/linux-setup.mjs +3 -2
- package/local-publish.mjs +113 -17
- package/lock-identity.mjs +24 -100
- package/managed-cargo.mjs +3 -3
- package/managed-root-guard.mjs +2 -2
- package/managed-roots.mjs +3 -3
- package/native-adapters.mjs +41 -244
- package/native-helpers.mjs +1 -1
- package/ownership-mandatory-set.json +16 -0
- package/pack-digest.mjs +1 -1
- package/package-recipe-targets.mjs +19 -11
- package/package.json +2 -2
- package/publication-gate.mjs +29 -6
- package/publish-cargo.mjs +4 -5
- package/publish-local-cargo.mjs +77 -1
- package/qualification-verify.mjs +76 -49
- package/receipt-signature.mjs +104 -0
- package/recipe-build.mjs +15 -2
- package/release-switch-registry.json +4 -0
- package/release-switch-scan.mjs +13 -10
- package/rightkit-versions.json +184 -170
- package/scan-digest.mjs +43 -14
- package/seam-broker.mjs +168 -0
- package/snapshot-check.mjs +4 -1
- package/snapshot-dependency-reuse.mjs +1 -1
- package/snapshot-metadata.mjs +24 -35
- package/snapshot.mjs +328 -49
- package/stage-commands.mjs +59 -5
- package/stage-ledger.mjs +2 -2
- package/{carried-cargo.mjs → stage-seam.mjs} +118 -70
- package/stage-sidecar.mjs +9 -7
- package/tauri-bundle-marker.mjs +5 -2
- package/tauri-locked.mjs +1 -1
- package/tool-build.mjs +8 -6
- package/unit-gate.mjs +40 -10
- package/broker-handshake.mjs +0 -160
- package/broker-wire.mjs +0 -278
- package/build-ownership.mjs +0 -1578
- package/cargo-shapes.mjs +0 -332
- package/cargo-width.mjs +0 -49
- package/carrier-census.mjs +0 -124
- package/clippy-equivalence.mjs +0 -202
- package/freshness-census.mjs +0 -405
- package/handle-revocation.mjs +0 -100
- package/handle-revocation.rust-vector.json +0 -1
- package/handle-revocation.vectors.json +0 -53
- package/legion-freeze-consumer.mjs +0 -241
- package/linux-qualifier.mjs +0 -83
- package/native-tool-planning.mjs +0 -94
- package/owner-process-proof.mjs +0 -14
- package/ownership-mark.mjs +0 -191
- package/ownership-recover.mjs +0 -78
- package/pnpm-adapter-grammar.mjs +0 -226
- package/provenance-verify.mjs +0 -413
- package/snapshot-broker.mjs +0 -808
- package/snapshot-request.mjs +0 -722
- package/unit-list-compile.mjs +0 -356
package/unit-list-compile.mjs
DELETED
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
// Shared compile planning: preserve every publisher requirement while coalescing only provably identical
|
|
2
|
-
// invocations or compatible cargo check/clippy requests. Execution is supplied by the existing snapshot scan runner.
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { scanCrateForSecrets } from "./publish-cargo.mjs";
|
|
7
|
-
|
|
8
|
-
const digest = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
9
|
-
const bodyOf = ({ workspace, cwd, executable, internal, argv, env, phase }) => ({ workspace, cwd, executable, ...(internal === undefined ? {} : { internal }), argv, env, phase });
|
|
10
|
-
|
|
11
|
-
// NN27 (GATE-CONTRACT GC-A27): never two compiler passes over one crate, target and feature set. A publisher `cargo check` is proved by a
|
|
12
|
-
// passing plan row (clippy or check) over the same crate, features, target and all-targets selection with the same compiler-relevant
|
|
13
|
-
// environment: clippy runs the same compile and only adds lints. Output and failure flags (--message-format, --locked, --keep-going,
|
|
14
|
-
// -j, lint arguments after `--`) do not change what compiled. Tests and docs never reuse: their environment or target selection differs.
|
|
15
|
-
const COMPILE_ENV = ["CC", "CXX", "AR", "LD", "RUSTC", "RUSTFLAGS", "RUSTC_WRAPPER", "RUSTC_WORKSPACE_WRAPPER", "CARGO_TARGET_DIR", "CARGO_BUILD_TARGET", "MACOSX_DEPLOYMENT_TARGET", "CARGO_ENCODED_RUSTFLAGS"];
|
|
16
|
-
/** `as`: "check" (what a check or clippy proves) or "clippy" (a clippy with its lint arguments, provable only by the same clippy). */
|
|
17
|
-
export function compileProofKey(scan, as = "check") {
|
|
18
|
-
if (!scan || !Array.isArray(scan.args)) return null;
|
|
19
|
-
const argv = scan.args[0] === "cargo" ? scan.args.slice(1) : scan.args;
|
|
20
|
-
const sub = argv[0];
|
|
21
|
-
if (sub !== "check" && sub !== "clippy") return null;
|
|
22
|
-
if (as === "clippy" && sub !== "clippy") return null;
|
|
23
|
-
const sep = argv.indexOf("--");
|
|
24
|
-
const lints = as === "clippy" ? (sep < 0 ? [] : argv.slice(sep + 1)) : null;
|
|
25
|
-
const packages = []; const features = []; let noDefault = false; let allFeatures = false; let target = null; let allTargets = false;
|
|
26
|
-
for (let i = 1; i < argv.length; i += 1) {
|
|
27
|
-
const a = argv[i];
|
|
28
|
-
if (a === "--") break;
|
|
29
|
-
if (a === "-p" || a === "--package") packages.push(argv[++i]);
|
|
30
|
-
else if (a === "--features" || a === "-F") features.push(...String(argv[++i] ?? "").split(/[ ,]+/).filter(Boolean));
|
|
31
|
-
else if (a.startsWith("--features=")) features.push(...a.slice(11).split(/[ ,]+/).filter(Boolean));
|
|
32
|
-
else if (a === "--no-default-features") noDefault = true;
|
|
33
|
-
else if (a === "--all-features") allFeatures = true;
|
|
34
|
-
else if (a === "--target") target = argv[++i];
|
|
35
|
-
else if (a === "--all-targets") allTargets = true;
|
|
36
|
-
else if (a === "--locked" || a === "--keep-going" || a === "--no-deps" || a.startsWith("--message-format") || a === "--profile" || a.startsWith("--profile=") || a === "-j" || a === "--jobs" || a.startsWith("-j") || a.startsWith("--jobs=")) { if (a === "--profile" || a === "-j" || a === "--jobs") i += 1; }
|
|
37
|
-
else return null; // anything else could change what compiles: no proof either way
|
|
38
|
-
}
|
|
39
|
-
if (packages.length !== 1 || !packages[0]) return null;
|
|
40
|
-
const env = Object.fromEntries(COMPILE_ENV.map((k) => [k, scan.env?.[k] ?? null]));
|
|
41
|
-
return JSON.stringify({ as, ...(lints ? { lints } : {}), cwd: scan.cwd ?? ".", package: packages[0], features: [...new Set(features)].sort(), noDefault, allFeatures, target, allTargets, env });
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** One in-memory plan; env is execution-only and must never be written to a report. */
|
|
45
|
-
export function planUnitListCompile(requirementsByUnit, { normalizedCwds = new Map() } = {}) {
|
|
46
|
-
if (!Array.isArray(requirementsByUnit) || !requirementsByUnit.length) throw new Error("unit list needs compile requirements");
|
|
47
|
-
const ids = new Set(); const exact = new Map();
|
|
48
|
-
for (const entry of requirementsByUnit) {
|
|
49
|
-
if (typeof entry?.selector !== "string" || !Array.isArray(entry.requirements) || !entry.requirements.length) throw new Error("each unit needs a nonempty canonical compile plan");
|
|
50
|
-
for (const [order, r] of entry.requirements.entries()) {
|
|
51
|
-
const body = bodyOf(r);
|
|
52
|
-
if (typeof r.id !== "string" || ids.has(r.id) || typeof r.workspace !== "string" || !r.workspace || typeof r.cwd !== "string" || !r.cwd || (typeof r.executable !== "string" && !(r.executable === null && r.internal === "scanCrateForSecrets")) || !Array.isArray(r.argv) || !r.argv.every((x) => typeof x === "string") || !r.env || typeof r.env !== "object" || Array.isArray(r.env) || !["test", "compile", "check"].includes(r.phase) || digest(body) !== r.coverageKey) throw new Error(`invalid or duplicate canonical requirement ${r.id ?? "<missing>"}`);
|
|
53
|
-
ids.add(r.id);
|
|
54
|
-
const member = { selector: entry.selector, id: r.id, coverageKey: r.coverageKey, order };
|
|
55
|
-
if (exact.has(r.coverageKey)) exact.get(r.coverageKey).members.push(member);
|
|
56
|
-
else exact.set(r.coverageKey, { ...body, cwd: normalizedCwds.get(r.id) ?? body.cwd, members: [member] });
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const groups = new Map(); const jobs = [];
|
|
60
|
-
for (const job of exact.values()) {
|
|
61
|
-
const at = job.argv.indexOf("-p");
|
|
62
|
-
const crate = at >= 0 ? job.argv[at + 1] : undefined;
|
|
63
|
-
const rest = at < 0 ? [] : [...job.argv.slice(0, at), ...job.argv.slice(at + 2)];
|
|
64
|
-
// Tests, docs, Cargo features, and commands with multiple selectors never unify.
|
|
65
|
-
const batchable = job.executable === "cargo" && job.phase === "compile" && ["check", "clippy"].includes(job.argv[0]) && at > 0 && typeof crate === "string" && !crate.startsWith("-") && job.argv.indexOf("-p", at + 1) < 0 && !rest.some((x) => /^(?:--features(?:=|$)|-F)/.test(x));
|
|
66
|
-
if (!batchable) { jobs.push(job); continue; }
|
|
67
|
-
for (const member of job.members) member.package = crate;
|
|
68
|
-
const key = JSON.stringify({ workspace: job.workspace, cwd: job.cwd, executable: job.executable, env: job.env, phase: job.phase, rest, at });
|
|
69
|
-
let group = groups.get(key);
|
|
70
|
-
if (!group) { group = { ...job, argv: [...job.argv], members: [...job.members], packages: [crate], at }; groups.set(key, group); jobs.push(group); }
|
|
71
|
-
else if (!group.packages.includes(crate)) { group.packages.push(crate); group.members.push(...job.members); }
|
|
72
|
-
else group.members.push(...job.members);
|
|
73
|
-
}
|
|
74
|
-
return jobs.map((job) => {
|
|
75
|
-
if (!job.packages) return job;
|
|
76
|
-
const { at, packages, ...rest } = job;
|
|
77
|
-
return { ...rest, batchAt: at, argv: [...job.argv.slice(0, at), ...packages.flatMap((name) => ["-p", name]), ...job.argv.slice(at + 2)] };
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Prove that moving a narrow package-selected Cargo invocation to its workspace root preserves discovery. */
|
|
82
|
-
export function proveWorkspaceCwd({ requirement: r, snapshot, checkout, toolchainOf, exists = fs.existsSync }) {
|
|
83
|
-
const no = (reason) => ({ cwd: r.cwd, normalized: false, reason });
|
|
84
|
-
if (r.executable !== "cargo" || r.phase !== "compile" || !["check", "clippy"].includes(r.argv[0]) || r.workspace === r.cwd) return no("not a movable Cargo check or clippy");
|
|
85
|
-
const workspace = path.resolve(snapshot, r.workspace); const cwd = path.resolve(snapshot, r.cwd);
|
|
86
|
-
const relative = path.relative(workspace, cwd);
|
|
87
|
-
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) return no("working directory is outside workspace");
|
|
88
|
-
// Only the publisher's package-selected, path-free shape can move. Cargo's configuration and toolchain
|
|
89
|
-
// lookups depend on cwd; inspect every intermediate directory in both trees, including crate itself.
|
|
90
|
-
const args = r.argv; let packages = 0;
|
|
91
|
-
for (let i = 1; i < args.length; i += 1) {
|
|
92
|
-
const a = args[i];
|
|
93
|
-
if (a === "-p") { if (!/^[a-zA-Z0-9_-]+$/.test(args[++i] ?? "")) return no("invalid package selector"); packages += 1; }
|
|
94
|
-
else if (["--target", "--jobs", "--profile", "-D"].includes(a)) { if (!/^[a-zA-Z0-9_.-]+$/.test(args[++i] ?? "")) return no("cwd-sensitive argument"); }
|
|
95
|
-
else if (!["--", "--no-deps", "--all-targets", "--all-features", "--no-default-features", "--locked", "--frozen", "--offline", "--message-format=json-render-diagnostics"].includes(a)) return no(`unproven argument ${a}`);
|
|
96
|
-
}
|
|
97
|
-
if (packages !== 1) return no("requires exactly one package selector");
|
|
98
|
-
for (const [key, value] of Object.entries(r.env)) {
|
|
99
|
-
if (typeof value !== "string") return no(`non-string environment ${key}`);
|
|
100
|
-
if (/^(?:PATH|Path)$/.test(key) && value.split(path.delimiter).some((part) => !path.isAbsolute(part))) return no(`cwd-sensitive environment ${key}`);
|
|
101
|
-
if (/^(?:RUSTFLAGS|RUSTDOCFLAGS|CARGO_ENCODED_RUSTFLAGS|CARGO_TARGET_.*_RUSTFLAGS)$/.test(key) && value && !/^(?:-D\s*warnings|-A\s*warnings)$/.test(value.trim())) return no(`unproven compiler flags in ${key}`);
|
|
102
|
-
if (/^(?:CARGO_|RUST|CC(?:_|$)|CXX(?:_|$)|AR(?:_|$)|PKG_CONFIG)/.test(key) && (/[\\/]/.test(value) && !path.isAbsolute(value) || /(?:^|\s)\.{1,2}[\\/]/.test(value))) return no(`cwd-sensitive environment ${key}`);
|
|
103
|
-
}
|
|
104
|
-
for (const root of [snapshot, checkout]) {
|
|
105
|
-
let at = path.resolve(root, r.workspace);
|
|
106
|
-
for (const part of relative.split(path.sep)) {
|
|
107
|
-
at = path.join(at, part);
|
|
108
|
-
for (const file of [".cargo/config", ".cargo/config.toml", "rust-toolchain", "rust-toolchain.toml"]) if (exists(path.join(at, file))) return no(`cwd override ${path.relative(root, path.join(at, file))}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (typeof toolchainOf !== "function") return no("effective toolchain is unverified");
|
|
112
|
-
let toolchains;
|
|
113
|
-
try { toolchains = [snapshot, checkout].flatMap((root) => [r.workspace, r.cwd].map((dir) => toolchainOf(path.resolve(root, dir)))); } catch { return no("effective toolchain probe failed"); }
|
|
114
|
-
const locations = ["snapshot workspace", "snapshot unit", "checkout workspace", "checkout unit"];
|
|
115
|
-
for (const [i, probe] of toolchains.entries()) if (!(typeof probe === "string" ? probe : probe?.toolchain)) return no(`effective toolchain unavailable at ${locations[i]} (${typeof probe?.error === "string" && /^(?:spawn-error|exit-(?:\d+|unknown))$/.test(probe.error) ? probe.error : "empty-result"})`);
|
|
116
|
-
if (new Set(toolchains.map((probe) => typeof probe === "string" ? probe : probe.toolchain)).size !== 1) return no("effective toolchain differs across workspace and unit");
|
|
117
|
-
return { cwd: r.workspace, normalized: true, reason: "matching Cargo config and effective toolchain" };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** Run the publisher's own file-only crate scan against the guarded snapshot. */
|
|
121
|
-
export async function runPublisherSecretRequirement({ requirement, snapshot, commit, tree, verifySnapshot }) {
|
|
122
|
-
if (requirement?.internal !== "scanCrateForSecrets" || requirement.phase !== "check" || requirement.executable !== null || requirement.argv?.length !== 1 || requirement.argv[0] !== requirement.cwd || digest(bodyOf(requirement)) !== requirement.coverageKey || !/^crates\/rightkit-[a-z0-9-]+$/.test(requirement.cwd) || typeof verifySnapshot !== "function" || !/^[0-9a-f]{40,64}$/.test(commit ?? "") || !/^[0-9a-f]{40,64}$/.test(tree ?? "")) throw new Error("invalid publisher secret scan or snapshot binding");
|
|
123
|
-
const root = fs.realpathSync(snapshot); const directory = fs.realpathSync(path.join(root, requirement.cwd));
|
|
124
|
-
if (!directory.startsWith(`${root}${path.sep}`)) throw new Error("crate secret scan escapes the snapshot");
|
|
125
|
-
if (await verifySnapshot() !== true) throw new Error("snapshot verification failed before secret scan");
|
|
126
|
-
const findings = scanCrateForSecrets(directory);
|
|
127
|
-
if (await verifySnapshot() !== true) throw new Error("snapshot verification failed after secret scan");
|
|
128
|
-
const evidence = { id: requirement.id, coverageKey: requirement.coverageKey, commit, tree, status: findings.length ? "fail" : "pass", findings };
|
|
129
|
-
return { ...evidence, evidenceHash: digest(evidence) };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Serial admission keeps at most one Cargo command per workspace in flight and never floods the broker.
|
|
134
|
-
* `run` uses the real scoped snapshot scan runner; `verify` must validate its receipt and command binding.
|
|
135
|
-
* Neither execution environment nor raw receipt is placed in the returned report.
|
|
136
|
-
*/
|
|
137
|
-
export async function executeUnitListCompile({ jobs, dependencies = {}, initialFailures = new Set(), run, verify, concurrency = 1 }) {
|
|
138
|
-
if (!Array.isArray(jobs) || typeof run !== "function" || typeof verify !== "function") throw new Error("snapshot scan runner and receipt verifier are required");
|
|
139
|
-
const pending = jobs.map((job) => ({ ...job, members: job.members.map((member) => ({ ...member })) }));
|
|
140
|
-
const all = pending.flatMap((job) => job.members);
|
|
141
|
-
const expected = new Map();
|
|
142
|
-
for (const member of all) expected.set(member.selector, (expected.get(member.selector) ?? 0) + 1);
|
|
143
|
-
const guardBlocked = new Set(initialFailures);
|
|
144
|
-
let added = true;
|
|
145
|
-
while (added) {
|
|
146
|
-
added = false;
|
|
147
|
-
for (const [selector, deps] of Object.entries(dependencies)) if (!guardBlocked.has(selector) && deps.some((dep) => guardBlocked.has(dep))) { guardBlocked.add(selector); added = true; }
|
|
148
|
-
}
|
|
149
|
-
const done = new Map(); const results = [];
|
|
150
|
-
const record = (member, status, evidenceHash) => {
|
|
151
|
-
const rows = done.get(member.selector) ?? new Map(); rows.set(member.order, status); done.set(member.selector, rows);
|
|
152
|
-
results.push({ selector: member.selector, id: member.id, coverageKey: member.coverageKey, status, ...(evidenceHash ? { evidenceHash } : {}) });
|
|
153
|
-
};
|
|
154
|
-
while (pending.some((job) => job.members.length)) {
|
|
155
|
-
let progress = false;
|
|
156
|
-
// Decide readiness for every unit before executing anything in this round. Otherwise visiting
|
|
157
|
-
// one unit's test first starts its share of a batch before another unit's test has even run.
|
|
158
|
-
for (const job of pending) for (const member of [...job.members]) {
|
|
159
|
-
const dependencyFailed = (dependencies[member.selector] ?? []).some((dep) => {
|
|
160
|
-
const rows = done.get(dep);
|
|
161
|
-
return expected.has(dep) && rows?.size === expected.get(dep) && [...rows.values()].some((status) => status !== "passed");
|
|
162
|
-
});
|
|
163
|
-
if (guardBlocked.has(member.selector) || dependencyFailed) {
|
|
164
|
-
record(member, "blocked"); job.members.splice(job.members.indexOf(member), 1); progress = true;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
const frontier = [];
|
|
168
|
-
for (const job of pending) {
|
|
169
|
-
const active = [];
|
|
170
|
-
for (const member of job.members) {
|
|
171
|
-
const own = done.get(member.selector) ?? new Map();
|
|
172
|
-
const deps = dependencies[member.selector] ?? [];
|
|
173
|
-
const previousReady = Array.from({ length: member.order }, (_, i) => own.has(i)).every(Boolean);
|
|
174
|
-
const depsReady = deps.every((dep) => expected.has(dep) && (done.get(dep)?.size ?? 0) === expected.get(dep));
|
|
175
|
-
if (previousReady && depsReady) active.push(member);
|
|
176
|
-
}
|
|
177
|
-
if (!active.length) continue;
|
|
178
|
-
// Two identical requirements of one unit are never executed out of sequence.
|
|
179
|
-
const selectors = new Set(); const ready = active.filter((m) => !selectors.has(m.selector) && selectors.add(m.selector));
|
|
180
|
-
frontier.push({ job, ready });
|
|
181
|
-
}
|
|
182
|
-
// Prefer a whole ready group, waiting for members whose earlier independent requirements are
|
|
183
|
-
// themselves runnable. If such waits form a cycle, execute the ready subset to make progress.
|
|
184
|
-
let admitted = frontier.filter(({ job, ready }) => ready.length === job.members.length);
|
|
185
|
-
if (!admitted.length && frontier.length && !progress) admitted = [frontier[0]];
|
|
186
|
-
// NN17/NN39: the admitted jobs are independent (one ready requirement per unit, its earlier ones done), so they run `concurrency` at a time;
|
|
187
|
-
// 1 is the serial order this loop had. Every result is still verified per member before anything later is admitted.
|
|
188
|
-
const runAdmitted = async ({ job, ready }) => {
|
|
189
|
-
let invocation = { ...job, members: ready };
|
|
190
|
-
if (job.batchAt !== undefined) {
|
|
191
|
-
const names = [...new Set(ready.map((m) => m.package))];
|
|
192
|
-
const at = job.batchAt; let end = at;
|
|
193
|
-
while (job.argv[end] === "-p" && typeof job.argv[end + 1] === "string") end += 2;
|
|
194
|
-
invocation = { ...invocation, argv: [...job.argv.slice(0, at), ...names.flatMap((name) => ["-p", name]), ...job.argv.slice(end)] };
|
|
195
|
-
}
|
|
196
|
-
let result;
|
|
197
|
-
try { result = await run(invocation); } catch { result = null; }
|
|
198
|
-
for (const member of ready) {
|
|
199
|
-
let status = "failed"; let proof = null;
|
|
200
|
-
try {
|
|
201
|
-
const memberResult = result?.byMember instanceof Map ? result.byMember.get(member.id) : result;
|
|
202
|
-
const checked = await verify({ job: invocation, result: memberResult, member });
|
|
203
|
-
if (memberResult?.status === "pass" && checked?.ok === true && typeof checked.evidenceHash === "string" && /^[0-9a-f]{64}$/.test(checked.evidenceHash)) { status = "passed"; proof = checked.evidenceHash; }
|
|
204
|
-
} catch { /* An exception cannot attest a pass. */ }
|
|
205
|
-
record(member, status, proof); job.members.splice(job.members.indexOf(member), 1);
|
|
206
|
-
}
|
|
207
|
-
progress = true;
|
|
208
|
-
};
|
|
209
|
-
const queue = [...admitted];
|
|
210
|
-
await Promise.all(Array.from({ length: Math.max(1, Math.min(Number(concurrency) || 1, queue.length)) }, async () => { while (queue.length) await runAdmitted(queue.shift()); }));
|
|
211
|
-
if (!progress) throw new Error("unit requirements have an unresolved or cyclic dependency");
|
|
212
|
-
}
|
|
213
|
-
return results;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/** Bridge the authenticated publisher jobs to runScans' initialized Class B scheduler. */
|
|
217
|
-
export function publisherUnionScheduler({ reuseProofs = true, concurrency = 1, jobs, dependencies = {}, initialFailures = new Set(), requirements, adapt, verify, signal = null, onCoverage = () => {} }) {
|
|
218
|
-
if (!Array.isArray(requirements) || requirements.some((r) => r.internal) || typeof adapt !== "function" || typeof verify !== "function") throw new Error("publisher scheduler needs external requirements, adapter and verifier; internal scans must already be verified");
|
|
219
|
-
const byId = new Map(requirements.map((r) => [r.id, r]));
|
|
220
|
-
if (byId.size !== requirements.length) throw new Error("duplicate publisher requirement IDs");
|
|
221
|
-
const plannedIds = jobs.flatMap((job) => job.members.map((member) => member.id));
|
|
222
|
-
if (plannedIds.length !== requirements.length || new Set(plannedIds).size !== plannedIds.length || plannedIds.some((id) => !byId.has(id))) throw new Error("publisher job coverage differs from authenticated requirements");
|
|
223
|
-
return async ({ scans, execute, executeGroup, canGroup, project, notRun }) => {
|
|
224
|
-
const byScan = new Map(scans.map((scan, index) => [scan.id, index]));
|
|
225
|
-
if (byScan.size !== scans.length || requirements.some((r) => !byScan.has(r.id))) throw new Error("publisher plan does not contain each requirement exactly once");
|
|
226
|
-
const slots = new Array(scans.length); const executed = new Map(); const attempts = new Map();
|
|
227
|
-
// Origin scans have no publisher per-unit sequencing; batch only members the scan runner
|
|
228
|
-
// itself marks compatible, and retain its signed bisection/attribution results.
|
|
229
|
-
for (let i = 0; i < scans.length; i += 1) if (!byId.has(scans[i].id) && !slots[i]) {
|
|
230
|
-
const peers = typeof executeGroup === "function" && typeof canGroup === "function" ? scans.map((s, j) => j > i && !slots[j] && !byId.has(s.id) && canGroup(scans[i], s) ? j : -1).filter((j) => j >= 0) : [];
|
|
231
|
-
if (!peers.length) slots[i] = await execute(scans[i]);
|
|
232
|
-
else {
|
|
233
|
-
const indices = [i, ...peers]; const rows = await executeGroup(indices.map((j) => scans[j]));
|
|
234
|
-
for (const [n, j] of indices.entries()) slots[j] = rows[n];
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
// Passing plan rows that prove a compile (NN27), with the evidence a publisher verify needs on a broker host.
|
|
238
|
-
const proofs = new Map();
|
|
239
|
-
for (let i = 0; i < scans.length; i += 1) {
|
|
240
|
-
if (byId.has(scans[i].id) || slots[i]?.status !== "pass") continue;
|
|
241
|
-
if (scans[i].root === "cargoLive" && !/^[0-9a-f]{64}$/.test(slots[i].snapshotEvidence?.receiptSha256 ?? "")) continue;
|
|
242
|
-
for (const as of ["check", "clippy"]) { const key = compileProofKey(scans[i], as); if (key !== null && !proofs.has(key)) proofs.set(key, { id: scans[i].id, row: slots[i] }); }
|
|
243
|
-
}
|
|
244
|
-
// A quiet suite needs the broker drained for its quiet lease: a job with a quiet member runs alone (exclusive), the others share.
|
|
245
|
-
let shared = 0; let exclusive = false; const waiters = [];
|
|
246
|
-
const wake = () => { const ready = waiters.splice(0); for (const w of ready) w(); };
|
|
247
|
-
const acquire = async (alone) => {
|
|
248
|
-
for (;;) {
|
|
249
|
-
if (alone ? (!exclusive && shared === 0) : !exclusive) { if (alone) exclusive = true; else shared += 1; return; }
|
|
250
|
-
await new Promise((resolve) => waiters.push(resolve));
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
const release = (alone) => { if (alone) exclusive = false; else shared -= 1; wake(); };
|
|
254
|
-
const result = await executeUnitListCompile({ concurrency, jobs, dependencies, initialFailures,
|
|
255
|
-
run: async (job) => {
|
|
256
|
-
const alone = job.members.some((member) => scans[byScan.get(member.id)]?.quiet === true);
|
|
257
|
-
await acquire(alone);
|
|
258
|
-
try { return await runJob(job); } finally { release(alone); }
|
|
259
|
-
},
|
|
260
|
-
verify: async ({ job, result: row, member }) => verify({ job, row, member, attempts: attempts.get(member.id) ?? [], requirement: byId.get(member.id) }),
|
|
261
|
-
});
|
|
262
|
-
async function runJob(job) {
|
|
263
|
-
{
|
|
264
|
-
const byMember = new Map();
|
|
265
|
-
const budget = { remaining: Math.min(2 * job.members.length - 1, 31) };
|
|
266
|
-
const runMembers = async (members) => {
|
|
267
|
-
if (budget.remaining <= 0 || signal?.aborted) {
|
|
268
|
-
for (const member of members) { const history = attempts.get(member.id) ?? []; history.push({ status: "not-run", code: signal?.aborted ? "CANCELLED" : "BATCH_BUDGET" }); attempts.set(member.id, history); }
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
// NN27: a member whose compile a passing plan row already proved reuses that row; only the rest compile.
|
|
272
|
-
const proved = [];
|
|
273
|
-
const rest = members.filter((member) => {
|
|
274
|
-
const own = { ...scans[byScan.get(member.id)], cwd: job.cwd }; // the job's cwd is the workspace when proveWorkspaceCwd moved it
|
|
275
|
-
const ownArgv = own.args?.[0] === "cargo" ? own.args.slice(1) : own.args ?? [];
|
|
276
|
-
const key = compileProofKey(own, ownArgv[0] === "clippy" ? "clippy" : "check");
|
|
277
|
-
const proof = key === null || !reuseProofs ? undefined : proofs.get(key);
|
|
278
|
-
if (!proof) return true;
|
|
279
|
-
proved.push([member, proof]); return false;
|
|
280
|
-
});
|
|
281
|
-
for (const [member, proof] of proved) {
|
|
282
|
-
const row = { ...proof.row, provedBy: proof.id };
|
|
283
|
-
const history = attempts.get(member.id) ?? [];
|
|
284
|
-
history.push({ id: proof.id, status: row.status, command: row.command, provedBy: proof.id, ...(row.snapshotEvidence ? { snapshotEvidence: row.snapshotEvidence } : {}) });
|
|
285
|
-
attempts.set(member.id, history); executed.set(member.id, row); byMember.set(member.id, row);
|
|
286
|
-
}
|
|
287
|
-
if (!rest.length) return;
|
|
288
|
-
members = rest;
|
|
289
|
-
budget.remaining -= 1;
|
|
290
|
-
const representative = byId.get(members[0].id);
|
|
291
|
-
if (!representative) throw new Error("unknown publisher requirement");
|
|
292
|
-
let argv = job.argv;
|
|
293
|
-
if (job.batchAt !== undefined) {
|
|
294
|
-
const at = job.batchAt; let end = at;
|
|
295
|
-
while (argv[end] === "-p" && typeof argv[end + 1] === "string") end += 2;
|
|
296
|
-
argv = [...argv.slice(0, at), ...[...new Set(members.map((m) => m.package))].flatMap((name) => ["-p", name]), ...argv.slice(end)];
|
|
297
|
-
}
|
|
298
|
-
const one = members.length === 1 && JSON.stringify(argv) === JSON.stringify(representative.argv);
|
|
299
|
-
const scan = one ? scans[byScan.get(representative.id)] : adapt({ ...representative, id: `publisher-batch:${digest(members.map((m) => m.id)).slice(0, 24)}`, cwd: job.cwd, argv, coverageKey: digest(members.map((m) => m.coverageKey)) });
|
|
300
|
-
const row = await execute(scan);
|
|
301
|
-
for (const member of members) {
|
|
302
|
-
const history = attempts.get(member.id) ?? [];
|
|
303
|
-
history.push({ id: row.id, status: row.status, ...(row.code ? { code: row.code } : {}), command: row.command, ...(row.authenticatedFailure ? { authenticatedFailure: row.authenticatedFailure } : {}), ...(row.snapshotEvidence ? { snapshotEvidence: row.snapshotEvidence } : {}) });
|
|
304
|
-
attempts.set(member.id, history);
|
|
305
|
-
}
|
|
306
|
-
const attributable = (row.code === "EXIT" && !row.snapshotEvidence) || (row.code === "BROKER_COMPILE_FAILURE" && row.authenticatedFailure?.retryable === true && row.authenticatedFailure?.failureClass === "compile" && row.snapshotEvidence?.receiptSha256);
|
|
307
|
-
if (members.length > 1 && job.batchAt !== undefined && row.status === "fail" && attributable) {
|
|
308
|
-
const half = Math.ceil(members.length / 2);
|
|
309
|
-
await runMembers(members.slice(0, half)); await runMembers(members.slice(half));
|
|
310
|
-
}
|
|
311
|
-
// Split outcomes attribute the failure; they cannot turn the required combined
|
|
312
|
-
// invocation into a pass or unblock a selected dependent.
|
|
313
|
-
for (const member of members) { executed.set(member.id, row); byMember.set(member.id, row); }
|
|
314
|
-
};
|
|
315
|
-
await runMembers(job.members);
|
|
316
|
-
return { byMember };
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
onCoverage(result);
|
|
320
|
-
for (const item of result) {
|
|
321
|
-
const index = byScan.get(item.id); const scan = scans[index]; const row = executed.get(item.id);
|
|
322
|
-
slots[index] = !row || (item.status !== "passed" && row.status === "pass")
|
|
323
|
-
? notRun(scan, item.status === "blocked" ? "a prerequisite did not pass" : "publisher evidence did not verify")
|
|
324
|
-
: project(row, scan);
|
|
325
|
-
}
|
|
326
|
-
return slots;
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/** Build publisher requirements from one verified snapshot and its Cargo/npm discovery results. */
|
|
331
|
-
export async function publisherRequirementsForUnits({ selected, snapshot, rustUnits, npmUnits, platform, env }) {
|
|
332
|
-
if (!Array.isArray(selected) || !Array.isArray(rustUnits) || !Array.isArray(npmUnits)) throw new Error("verified unit discovery is required");
|
|
333
|
-
const readJson = (file) => JSON.parse(fs.readFileSync(path.join(snapshot, file), "utf8"));
|
|
334
|
-
const config = readJson("ci/gate.config.json");
|
|
335
|
-
const assetGated = readJson("ci/asset-gated.json");
|
|
336
|
-
const { compileRequirements } = await import("./local-publish.mjs");
|
|
337
|
-
const out = [];
|
|
338
|
-
for (const row of selected) {
|
|
339
|
-
const cargo = /^cargo:(rightkit-[a-z0-9-]+)$/.exec(row.selector);
|
|
340
|
-
const npm = /^npm:(@rightkit\/[a-z0-9-]+)$/.exec(row.selector);
|
|
341
|
-
if (!cargo && !npm) throw new Error(`unsupported selector ${row.selector}`);
|
|
342
|
-
const kind = cargo ? "cargo" : "npm"; const unit = (cargo ?? npm)[1];
|
|
343
|
-
const dir = cargo ? `crates/${unit}` : `packages/${unit.slice("@rightkit/".length)}`;
|
|
344
|
-
if (row.dir !== dir) throw new Error(`${row.selector}: selected directory differs from canonical directory`);
|
|
345
|
-
const discovered = (cargo ? rustUnits : npmUnits).find((u) => u.dir === dir);
|
|
346
|
-
if (!discovered) throw new Error(`${row.selector}: selected unit is absent from authenticated workspace discovery`);
|
|
347
|
-
if (cargo && (discovered.crate ?? discovered.name) !== unit) throw new Error(`${row.selector}: discovered Cargo identity differs`);
|
|
348
|
-
const manifest = npm ? readJson(`${dir}/package.json`) : null;
|
|
349
|
-
if (npm && manifest?.name !== unit) throw new Error(`${row.selector}: npm manifest identity differs`);
|
|
350
|
-
if (npm && manifest.private === true && !manifest.scripts?.build && !manifest.scripts?.test) throw new Error(`${row.selector}: private unit has no own build or test script; recursive workspace build cannot prove its coverage`);
|
|
351
|
-
// Class A's full pass (rustfmt over every Rust file of this snapshot) precedes these requirements in the same run: no per-crate fmt (GC-A24).
|
|
352
|
-
const planned = compileRequirements({ kind, unit, dir, config, manifest, platform, workspace: cargo ? discovered.cargoDir : ".", env, assetGated, formatProven: true });
|
|
353
|
-
out.push({ selector: row.selector, dir, ...planned });
|
|
354
|
-
}
|
|
355
|
-
return out;
|
|
356
|
-
}
|