@rightkit/release 0.6.45 → 0.6.47
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/affected-units.mjs +190 -0
- package/bin/rightkit-gate.mjs +629 -132
- package/build-ownership.mjs +206 -41
- package/cargo-width.mjs +49 -0
- package/ci-compile-admission.mjs +57 -0
- package/committed-cargo-workspace.mjs +58 -0
- package/cross-targets.mjs +18 -2
- package/dependency-identity.mjs +98 -0
- package/deterministic-scans.mjs +256 -57
- package/gate-acceptance.mjs +1443 -0
- package/gate-coverage.mjs +17 -6
- package/gate-serve.mjs +239 -0
- package/handle-revocation.mjs +100 -0
- package/handle-revocation.rust-vector.json +1 -0
- package/handle-revocation.vectors.json +53 -0
- package/local-publish.mjs +109 -34
- package/managed-cargo.mjs +11 -0
- package/node-check-cache.mjs +95 -0
- package/owner-process-proof.mjs +14 -0
- package/ownership-mark.mjs +10 -1
- package/ownership-recover.mjs +78 -0
- package/package.json +2 -1
- package/performance-diagnostic.mjs +19 -0
- package/provenance-verify.mjs +35 -0
- package/publication-gate.mjs +62 -29
- package/publish-cargo.mjs +19 -4
- package/qualification-verify.mjs +12 -2
- package/rightkit-drift.mjs +4 -3
- package/rightkit-versions.json +1 -1
- package/snapshot-broker.mjs +1 -1
- package/snapshot-check.mjs +91 -12
- package/snapshot-dependency-reuse.mjs +230 -0
- package/snapshot-metadata.mjs +1 -1
- package/snapshot-request.mjs +12 -5
- package/snapshot.mjs +41 -6
- package/stage-sidecar.mjs +20 -4
- package/stamp-relay.mjs +37 -0
- package/unit-gate.mjs +25 -5
- package/unit-list-compile.mjs +277 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Shared planning for RightKit unit runs (rightkit#1505; reconciled scope 2026-11-04): fixed workspace inventory,
|
|
2
|
+
// automatic changed-unit plus dependent selection, dependency-first ordering and result classification. Pure: the
|
|
3
|
+
// caller supplies the inventory and changed paths; nothing here reads a tree, runs git or starts a process, so the
|
|
4
|
+
// selection a run used can be replayed from its report alone.
|
|
5
|
+
|
|
6
|
+
/** The aggregate report a multi-unit door run writes beside the per-unit receipts. */
|
|
7
|
+
export const UNIT_LIST_REPORT_SCHEMA = "rightkit.unit-list-report/1";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Repository paths that shape every unit of a kind (or all units), so a change there selects the whole kind with the
|
|
11
|
+
* reason named. Paths not listed and outside a unit directory select nothing and are reported as unmatched, never
|
|
12
|
+
* silently widened: docs and unrelated files must not turn a routine compile into a full sweep.
|
|
13
|
+
*/
|
|
14
|
+
export const SHARED_PATH_RULES = Object.freeze([
|
|
15
|
+
{ paths: ["Cargo.toml", "Cargo.lock", "rust-toolchain.toml", "deny.toml", ".cargo/audit.toml"], kind: "cargo", reason: "shared-rust-workspace" },
|
|
16
|
+
{ paths: ["pnpm-lock.yaml", "pnpm-workspace.yaml", "package.json"], kind: "npm", reason: "shared-npm-workspace" },
|
|
17
|
+
{ paths: ["ci/gate.config.json", "ci/asset-gated.json", "ci/known-red.json", ".rightkit/fixture-files.json"], kind: null, reason: "shared-gate-config" },
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const selectorOf = (unit) => `${unit.kind}:${unit.name}`;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Build the runnable inventory from caller-read manifests.
|
|
24
|
+
* `cargo`: [{ dir: "crates/<x>", name, deps: [<crate name>...] }] with deps already resolved to sibling crate names
|
|
25
|
+
* (crate-workspaces.mjs pathDependencies). `npm`: [{ dir: "packages/<x>", name: "@rightkit/<x>", deps: ["@rightkit/<y>"...] }].
|
|
26
|
+
* Entries whose name cannot form a unit selector are skipped and named in `skipped`.
|
|
27
|
+
*/
|
|
28
|
+
export function buildInventory({ cargo = [], npm = [] } = {}) {
|
|
29
|
+
const units = [];
|
|
30
|
+
const skipped = [];
|
|
31
|
+
for (const c of cargo) {
|
|
32
|
+
if (typeof c?.name !== "string" || !/^rightkit-[a-z0-9-]+$/.test(c.name) || typeof c.dir !== "string") { skipped.push({ dir: c?.dir ?? null, name: c?.name ?? null, why: "not a cargo:rightkit-<name> unit" }); continue; }
|
|
33
|
+
units.push({ selector: `cargo:${c.name}`, kind: "cargo", name: c.name, dir: c.dir, deps: [...new Set(c.deps ?? [])].filter((d) => typeof d === "string").map((d) => `cargo:${d}`) });
|
|
34
|
+
}
|
|
35
|
+
for (const p of npm) {
|
|
36
|
+
if (typeof p?.name !== "string" || !/^@rightkit\/[a-z0-9-]+$/.test(p.name) || typeof p.dir !== "string") { skipped.push({ dir: p?.dir ?? null, name: p?.name ?? null, why: "not an npm:@rightkit/<name> unit" }); continue; }
|
|
37
|
+
units.push({ selector: `npm:${p.name}`, kind: "npm", name: p.name, dir: p.dir, deps: [...new Set(p.deps ?? [])].filter((d) => typeof d === "string").map((d) => `npm:${d}`) });
|
|
38
|
+
}
|
|
39
|
+
const known = new Set(units.map((u) => u.selector));
|
|
40
|
+
for (const u of units) {
|
|
41
|
+
const missing = u.deps.filter((d) => !known.has(d));
|
|
42
|
+
if (missing.length) throw new Error(`${u.selector} has unresolved internal dependencies: ${missing.join(", ")}`);
|
|
43
|
+
u.deps = u.deps.filter((d) => d !== u.selector);
|
|
44
|
+
}
|
|
45
|
+
units.sort((a, b) => a.selector.localeCompare(b.selector));
|
|
46
|
+
return { units, skipped };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Reverse-dependency map of an inventory: selector -> Set of selectors that depend on it directly. */
|
|
50
|
+
export function reverseGraph(inventory) {
|
|
51
|
+
const reverse = new Map(inventory.units.map((u) => [u.selector, new Set()]));
|
|
52
|
+
for (const u of inventory.units) for (const d of u.deps) reverse.get(d)?.add(u.selector);
|
|
53
|
+
return reverse;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Dependency-first order over `selected` (a Set of selectors): every unit appears after the selected units it depends
|
|
58
|
+
* on. Deterministic (alphabetical tiebreak) and cycle-tolerant: a dependency cycle is broken at the back edge and the
|
|
59
|
+
* units in it keep alphabetical order, because a cycle must narrow the guarantee, never hang the planner.
|
|
60
|
+
*/
|
|
61
|
+
export function dependencyFirstOrder(inventory, selected) {
|
|
62
|
+
const bySelector = new Map(inventory.units.map((u) => [u.selector, u]));
|
|
63
|
+
const state = new Map(); // 1 = visiting, 2 = done
|
|
64
|
+
const order = [];
|
|
65
|
+
const visit = (sel) => {
|
|
66
|
+
if (state.get(sel)) return;
|
|
67
|
+
state.set(sel, 1);
|
|
68
|
+
for (const dep of [...(bySelector.get(sel)?.deps ?? [])].sort()) if (selected.has(dep)) visit(dep);
|
|
69
|
+
state.set(sel, 2);
|
|
70
|
+
order.push(sel);
|
|
71
|
+
};
|
|
72
|
+
for (const sel of [...selected].sort()) visit(sel);
|
|
73
|
+
return order;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Select the units a change owes: units whose directory changed, units a shared path selects, and every transitive
|
|
78
|
+
* dependent of those. Returns dependency-first `selected` rows ({ selector, kind, name, dir, reason, via }) where
|
|
79
|
+
* reason is "changed", a SHARED_PATH_RULES reason, or "dependent" (via names the nearest selected dependency), plus
|
|
80
|
+
* the changed paths no rule claimed (`unmatched`), so a caller can print exactly what selected nothing.
|
|
81
|
+
*/
|
|
82
|
+
export function selectAffectedUnits({ changedPaths = [], inventory, sharedRules = SHARED_PATH_RULES }) {
|
|
83
|
+
const reasons = new Map(); // selector -> { reason, via }
|
|
84
|
+
const unmatched = [];
|
|
85
|
+
const byDir = [...inventory.units].sort((a, b) => b.dir.length - a.dir.length);
|
|
86
|
+
const claim = (selector, reason, via = null) => { if (!reasons.has(selector)) reasons.set(selector, { reason, via }); };
|
|
87
|
+
for (const raw of changedPaths) {
|
|
88
|
+
const file = String(raw).split("\\").join("/");
|
|
89
|
+
const owner = byDir.find((u) => file === u.dir || file.startsWith(`${u.dir}/`));
|
|
90
|
+
if (owner) { claim(owner.selector, "changed"); continue; }
|
|
91
|
+
const rule = sharedRules.find((r) => r.paths.includes(file));
|
|
92
|
+
if (rule) {
|
|
93
|
+
const unsupported = inventory.skipped?.filter((u) => rule.kind === null || (rule.kind === "cargo" ? u.dir?.startsWith("crates/") : u.dir?.startsWith("packages/"))) ?? [];
|
|
94
|
+
if (unsupported.length) throw new Error(`${file} affects unsupported units: ${unsupported.map((u) => u.name ?? u.dir).join(", ")}; classify their gate ownership`);
|
|
95
|
+
for (const u of inventory.units) if (rule.kind === null || u.kind === rule.kind) claim(u.selector, rule.reason);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const skippedOwner = inventory.skipped?.find((u) => u.dir && (file === u.dir || file.startsWith(`${u.dir}/`)));
|
|
99
|
+
if (skippedOwner) throw new Error(`${file} belongs to unsupported unit ${skippedOwner.name ?? skippedOwner.dir}; select it through its own gate`);
|
|
100
|
+
unmatched.push(file);
|
|
101
|
+
}
|
|
102
|
+
// Transitive dependents, breadth-first so `via` names a nearest selected dependency.
|
|
103
|
+
const reverse = reverseGraph(inventory);
|
|
104
|
+
const queue = [...reasons.keys()];
|
|
105
|
+
while (queue.length) {
|
|
106
|
+
const sel = queue.shift();
|
|
107
|
+
for (const dependent of [...reverse.get(sel) ?? []].sort()) {
|
|
108
|
+
if (!reasons.has(dependent)) { reasons.set(dependent, { reason: "dependent", via: sel }); queue.push(dependent); }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const bySelector = new Map(inventory.units.map((u) => [u.selector, u]));
|
|
112
|
+
const selected = dependencyFirstOrder(inventory, new Set(reasons.keys())).map((sel) => ({ ...bySelector.get(sel), ...reasons.get(sel) }));
|
|
113
|
+
return { selected, unmatched: [...new Set(unmatched)].sort() };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Resolve changes through the union of old and current edges, then keep current runnable units. */
|
|
117
|
+
export function selectAffectedAcrossInventories({ changedPaths, oldInventory, inventory }) {
|
|
118
|
+
const old = selectAffectedUnits({ changedPaths, inventory: oldInventory });
|
|
119
|
+
const current = selectAffectedUnits({ changedPaths, inventory });
|
|
120
|
+
const reasons = new Map([...current.selected, ...old.selected].map((row) => [row.selector, { reason: row.reason, via: row.via }]));
|
|
121
|
+
const reverse = new Map();
|
|
122
|
+
for (const unit of [...oldInventory.units, ...inventory.units]) for (const dep of unit.deps) {
|
|
123
|
+
if (!reverse.has(dep)) reverse.set(dep, new Set());
|
|
124
|
+
reverse.get(dep).add(unit.selector);
|
|
125
|
+
}
|
|
126
|
+
const queue = [...reasons.keys()];
|
|
127
|
+
while (queue.length) {
|
|
128
|
+
const sel = queue.shift();
|
|
129
|
+
for (const dependent of [...(reverse.get(sel) ?? [])].sort()) if (!reasons.has(dependent)) {
|
|
130
|
+
reasons.set(dependent, { reason: "dependent", via: sel });
|
|
131
|
+
queue.push(dependent);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const bySelector = new Map(inventory.units.map((unit) => [unit.selector, unit]));
|
|
135
|
+
const surviving = new Set([...reasons.keys()].filter((sel) => bySelector.has(sel)));
|
|
136
|
+
return {
|
|
137
|
+
selected: dependencyFirstOrder(inventory, surviving).map((sel) => ({ ...bySelector.get(sel), ...reasons.get(sel) })),
|
|
138
|
+
unmatched: current.unmatched.filter((p) => old.unmatched.includes(p)),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Classify one run's outcomes over the selected units. `outcomes` maps selector -> { ran, code } (code 0 = pass).
|
|
144
|
+
* A unit that did not run because a selected dependency failed or was itself blocked is "blocked" (and names it in
|
|
145
|
+
* `blockedBy`); one that did not run for any other reason is "not-run". Passed/failed keep their exit code. This is
|
|
146
|
+
* the honest four-way split the complete report prints: no blocked unit reads as passed, none as failed.
|
|
147
|
+
*/
|
|
148
|
+
export function classifyUnitResults({ selected, inventory, outcomes }) {
|
|
149
|
+
const bySelector = new Map(inventory.units.map((u) => [u.selector, u]));
|
|
150
|
+
const selectedSet = new Set(selected.map((s) => s.selector));
|
|
151
|
+
const status = new Map();
|
|
152
|
+
for (const row of selected) {
|
|
153
|
+
const o = outcomes.get(row.selector);
|
|
154
|
+
if (o?.ran) status.set(row.selector, o.code === 0 ? "passed" : "failed");
|
|
155
|
+
}
|
|
156
|
+
const blockedByOf = (sel, seen = new Set()) => {
|
|
157
|
+
if (seen.has(sel)) return null;
|
|
158
|
+
seen.add(sel);
|
|
159
|
+
for (const dep of bySelector.get(sel)?.deps ?? []) {
|
|
160
|
+
if (!selectedSet.has(dep)) continue;
|
|
161
|
+
const s = status.get(dep);
|
|
162
|
+
if (s === "failed" || s === "blocked") return dep;
|
|
163
|
+
if (!outcomes.get(dep)?.ran) { const deeper = blockedByOf(dep, seen); if (deeper) return dep; }
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
};
|
|
167
|
+
return selected.map((row) => {
|
|
168
|
+
const o = outcomes.get(row.selector);
|
|
169
|
+
if (o?.ran) return { selector: row.selector, status: status.get(row.selector), code: o.code };
|
|
170
|
+
const blockedBy = blockedByOf(row.selector);
|
|
171
|
+
if (blockedBy) { status.set(row.selector, "blocked"); return { selector: row.selector, status: "blocked", blockedBy }; }
|
|
172
|
+
return { selector: row.selector, status: "not-run" };
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** The aggregate report object (UNIT_LIST_REPORT_SCHEMA): selection reasons and classified results in run order. */
|
|
177
|
+
export function unitListReport({ commit, stage, base = null, selected, results, unmatched = [] }) {
|
|
178
|
+
const bySelector = new Map(results.map((r) => [r.selector, r]));
|
|
179
|
+
const counts = { passed: 0, failed: 0, blocked: 0, "not-run": 0 };
|
|
180
|
+
for (const r of results) counts[r.status] = (counts[r.status] ?? 0) + 1;
|
|
181
|
+
return {
|
|
182
|
+
schema: UNIT_LIST_REPORT_SCHEMA, commit, stage, ...(base ? { base } : {}),
|
|
183
|
+
ok: results.every((r) => r.status === "passed"),
|
|
184
|
+
counts,
|
|
185
|
+
units: selected.map((s) => ({ selector: s.selector, reason: s.reason, ...(s.via ? { via: s.via } : {}), ...(bySelector.get(s.selector) ?? { status: "not-run" }) })),
|
|
186
|
+
...(unmatched.length ? { unmatchedPaths: unmatched } : {}),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { selectorOf };
|