@rightkit/release 0.6.57 → 0.6.62
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 +4 -0
- package/acceptance-admission.mjs +104 -0
- package/acceptance-launch.mjs +234 -0
- package/acceptance-lines.mjs +1254 -0
- package/acceptance-result.mjs +77 -0
- package/acceptance-rows.mjs +47 -0
- package/admission-files.mjs +2 -0
- package/affected-units.mjs +17 -0
- package/app-check.mjs +6 -2
- package/app-closure.mjs +3 -1
- package/bin/rightkit-gate.mjs +552 -124
- package/broker-admission.mjs +45 -2
- package/broker-pins.mjs +11 -1
- package/broker-toolchain.mjs +113 -0
- package/cargo-profile-contract.mjs +7 -2
- package/class-a-cache-history.mjs +170 -0
- package/cli/right-release.mjs +0 -0
- package/code-closure.mjs +24 -0
- package/config-inspect.mjs +6 -0
- package/consumer-contracts.mjs +3 -1
- package/contract-nn.json +166 -0
- package/deterministic-scans.mjs +835 -112
- package/feature-coverage.mjs +109 -82
- package/feature-partition.mjs +76 -0
- package/forbidden-literals.mjs +78 -0
- package/gate/calls.mjs +121 -0
- package/gate/compile.mjs +190 -0
- package/gate/crate-results.mjs +127 -0
- package/gate/run-calls.mjs +241 -0
- package/gate/tests.mjs +234 -0
- package/gate-coverage.mjs +12 -3
- package/gate-release-admission.mjs +200 -0
- package/gate-seam.mjs +100 -4
- package/gate-serve.mjs +179 -34
- package/gate-stages.mjs +59 -0
- package/legacy-contract-receipt.mjs +809 -0
- package/local-publish.mjs +2 -4
- package/local-runtime.mjs +2 -2
- package/nsis-payload.mjs +4 -3
- package/ownership-applicability.mjs +5 -0
- package/ownership-class-rules.mjs +19 -8
- package/ownership-mandatory-set.json +15 -21
- package/ownership-mandatory-set.mjs +19 -4
- package/package.json +14 -8
- package/probe-memo.mjs +252 -0
- package/publication-artifacts.mjs +56 -2
- package/publish-local-npm.mjs +3 -0
- package/publish-update.mjs +2 -2
- package/receipt-signature.mjs +40 -0
- package/release.mjs +47 -29
- package/resident-answers.mjs +66 -0
- package/rightkit-ownership.json +20 -11
- package/rightkit-versions.json +349 -183
- package/runtime-bundle-stage.mjs +146 -0
- package/scan-digest.mjs +28 -4
- package/seam-broker.mjs +8 -1
- package/shell-contract.mjs +23 -2
- package/snapshot-changes.mjs +106 -0
- package/snapshot-check.mjs +17 -13
- package/snapshot-dependency-reuse.mjs +186 -14
- package/snapshot-git.mjs +17 -1
- package/snapshot-metadata.mjs +155 -3
- package/snapshot.mjs +89 -12
- package/spawn-ledger.mjs +21 -2
- package/stage-sidecar.mjs +231 -19
- package/suite-trust-roots.mjs +2 -2
- package/test-env.mjs +26 -0
- package/tool-version-memo.mjs +46 -0
- package/win-package-recipe.mjs +11 -0
- package/bin/darwin/rightkit-swap +0 -0
- package/gate-acceptance.mjs +0 -3362
package/feature-coverage.mjs
CHANGED
|
@@ -13,71 +13,89 @@
|
|
|
13
13
|
// 3. `unlintedFeatures` (ci/gate.config.json rust.<crate>): a feature the gate never lints, named with its reason; it counts as covered, and
|
|
14
14
|
// a name the crate does not declare, or that a set enables, is an error. Coverage is judged over every set whatever its hosts (feature-sets.mjs).
|
|
15
15
|
//
|
|
16
|
-
//
|
|
16
|
+
// Reads manifests with smol-toml, loaded on first parse, so importing this module (scan-digest.mjs-style callers, the credentialed receipt verifiers) needs no install.
|
|
17
17
|
import { hasHostScopedSets, unlintedFeatures } from "./feature-sets.mjs";
|
|
18
|
+
import { createRequire } from "node:module";
|
|
18
19
|
|
|
19
|
-
/**
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* A manifest the feature readers cannot read. `kind`: "parser-missing" (smol-toml cannot load), "malformed" (not valid TOML, or a [features] entry
|
|
22
|
+
* that is not a list of strings), "missing" (no manifest text). Planning and coverage never fall back to a guess: a plan cannot be built from it and
|
|
23
|
+
* coverage reports it as a problem (astra62 review 6, 2026-11-18; the old text walk is gone).
|
|
24
|
+
*/
|
|
25
|
+
export class FeatureManifestError extends Error {
|
|
26
|
+
constructor(kind, detail) { super(`FEATURE_MANIFEST_${kind.toUpperCase().replace(/-/g, "_")}: ${detail}`); this.name = "FeatureManifestError"; this.kind = kind; }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let smolTomlParse;
|
|
30
|
+
/** The decoded manifest (smol-toml, loaded on first use as in cargo-contract.mjs, so importing this module needs no install). Throws FeatureManifestError. */
|
|
31
|
+
export function decodedManifest(text, where = "Cargo.toml") {
|
|
32
|
+
if (typeof text !== "string") throw new FeatureManifestError("missing", `${where} could not be read`);
|
|
33
|
+
let parse;
|
|
34
|
+
try { parse = (smolTomlParse ??= createRequire(import.meta.url)("smol-toml").parse); } catch (e) { throw new FeatureManifestError("parser-missing", `${where}: smol-toml cannot be loaded (${e.message}); install @rightkit/release's dependencies where the gate runs`); }
|
|
35
|
+
try { return parse(text.replace(/^/, "")); } catch (e) { throw new FeatureManifestError("malformed", `${where} is not valid TOML: ${String(e?.message ?? e).split("\n")[0]}`); }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const isTable = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
39
|
+
|
|
40
|
+
function featuresOfDoc(doc, where) {
|
|
41
|
+
const table = doc.features === undefined ? {} : doc.features;
|
|
42
|
+
if (!isTable(table)) throw new FeatureManifestError("malformed", `${where}: [features] is not a table`);
|
|
21
43
|
const out = new Map();
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let inFeatures = false;
|
|
26
|
-
// Walk the text once, string- and comment-aware, so a `[features]` mentioned in a string or comment, or a `#` inside a quoted member, is never misread.
|
|
27
|
-
const skipLine = () => { while (i < n && src[i] !== "\n") i += 1; };
|
|
28
|
-
const readString = () => {
|
|
29
|
-
const quote = src[i]; i += 1; let value = "";
|
|
30
|
-
while (i < n && src[i] !== quote && src[i] !== "\n") { if (quote === '"' && src[i] === "\\" && i + 1 < n) { value += src[i + 1]; i += 2; } else { value += src[i]; i += 1; } }
|
|
31
|
-
if (src[i] === quote) i += 1;
|
|
32
|
-
return value;
|
|
33
|
-
};
|
|
34
|
-
const skipSpace = () => { while (i < n && /\s/.test(src[i])) i += 1; };
|
|
35
|
-
while (i < n) {
|
|
36
|
-
skipSpace();
|
|
37
|
-
if (i >= n) break;
|
|
38
|
-
if (src[i] === "#") { skipLine(); continue; }
|
|
39
|
-
if (src[i] === "[") {
|
|
40
|
-
const double = src[i + 1] === "[";
|
|
41
|
-
const close = src.indexOf("]", i);
|
|
42
|
-
const header = close < 0 ? "" : src.slice(i + (double ? 2 : 1), close).trim().replace(/\s+/g, "");
|
|
43
|
-
inFeatures = !double && header === "features";
|
|
44
|
-
i = close < 0 ? n : close + (double ? 2 : 1);
|
|
45
|
-
skipLine();
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
// A key: bare or quoted, then `=`.
|
|
49
|
-
let key = "";
|
|
50
|
-
if (src[i] === '"' || src[i] === "'") key = readString();
|
|
51
|
-
else { while (i < n && !/[\s=]/.test(src[i])) { key += src[i]; i += 1; } }
|
|
52
|
-
skipSpace();
|
|
53
|
-
if (src[i] !== "=") { skipLine(); continue; }
|
|
54
|
-
i += 1; skipSpace();
|
|
55
|
-
if (src[i] === "[") {
|
|
56
|
-
i += 1; const members = [];
|
|
57
|
-
for (;;) {
|
|
58
|
-
skipSpace();
|
|
59
|
-
if (i >= n) break;
|
|
60
|
-
if (src[i] === "#") { skipLine(); continue; }
|
|
61
|
-
if (src[i] === "]") { i += 1; break; }
|
|
62
|
-
if (src[i] === '"' || src[i] === "'") members.push(readString());
|
|
63
|
-
else i += 1; // a comma
|
|
64
|
-
}
|
|
65
|
-
if (inFeatures && key !== "") out.set(key, members);
|
|
66
|
-
skipLine();
|
|
67
|
-
} else {
|
|
68
|
-
// Any other value (a string, a number, an inline table) is not a feature definition; read to the end of the line.
|
|
69
|
-
if (src[i] === '"' || src[i] === "'") readString();
|
|
70
|
-
skipLine();
|
|
71
|
-
}
|
|
44
|
+
for (const [name, members] of Object.entries(table)) {
|
|
45
|
+
if (!Array.isArray(members) || members.some((m) => typeof m !== "string")) throw new FeatureManifestError("malformed", `${where}: feature "${name}" is not a list of strings`);
|
|
46
|
+
out.set(name, [...members]);
|
|
72
47
|
}
|
|
73
48
|
return out;
|
|
74
49
|
}
|
|
75
50
|
|
|
76
|
-
|
|
77
|
-
|
|
51
|
+
// Dev-dependencies cannot be optional (Cargo refuses it). build_dependencies is the spelling Cargo accepted before edition 2024.
|
|
52
|
+
function optionalDependenciesOfDoc(doc, where) {
|
|
53
|
+
const tables = [doc.dependencies, doc["build-dependencies"], doc.build_dependencies, ...(isTable(doc.target) ? Object.values(doc.target).flatMap((t) => (isTable(t) ? [t.dependencies, t["build-dependencies"], t.build_dependencies] : [null])) : [])];
|
|
54
|
+
const optional = new Set();
|
|
55
|
+
for (const t of tables) {
|
|
56
|
+
if (t === undefined) continue;
|
|
57
|
+
if (!isTable(t)) throw new FeatureManifestError("malformed", `${where}: a dependency table is not a table`);
|
|
58
|
+
for (const [name, spec] of Object.entries(t)) if (isTable(spec) && spec.optional === true) optional.add(name);
|
|
59
|
+
}
|
|
60
|
+
return optional;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The [features] table of a Cargo.toml: a Map of feature name to its members ("other", "dep:x", "x/feat", "x?/feat"), `default` included. Throws FeatureManifestError. */
|
|
64
|
+
export function manifestFeatures(text, where = "Cargo.toml") { return featuresOfDoc(decodedManifest(text, where), where); }
|
|
65
|
+
|
|
66
|
+
/** The feature names (never `default`) a Cargo.toml's [features] table declares. Throws FeatureManifestError. */
|
|
67
|
+
export const declaredFeatureNames = (text, where) => [...manifestFeatures(text, where).keys()].filter((name) => name !== "default");
|
|
78
68
|
|
|
79
|
-
/**
|
|
80
|
-
|
|
69
|
+
/**
|
|
70
|
+
* The features Cargo gives a crate, from its decoded manifest: the [features] table plus each optional dependency that is its own implicit feature
|
|
71
|
+
* (Cargo gives an optional dependency a feature of its name unless a feature names it as `dep:<name>`), kept as `name = ["dep:name"]` and listed in
|
|
72
|
+
* `implicit`. Lint generation, feature coverage, unlinted validation and the NN27 check elision all read this one model (GC-A20; Adrian 2026-11-18).
|
|
73
|
+
* Throws FeatureManifestError.
|
|
74
|
+
*/
|
|
75
|
+
export function crateFeatureModel(text, where = "Cargo.toml") {
|
|
76
|
+
const doc = decodedManifest(text, where);
|
|
77
|
+
const features = featuresOfDoc(doc, where);
|
|
78
|
+
const referenced = new Set([...features.values()].flat().filter((v) => v.startsWith("dep:")).map((v) => v.slice(4)));
|
|
79
|
+
const implicit = new Set([...optionalDependenciesOfDoc(doc, where)].filter((name) => !referenced.has(name) && !features.has(name)));
|
|
80
|
+
for (const name of implicit) features.set(name, [`dep:${name}`]);
|
|
81
|
+
return { features, implicit };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* NN27: every feature `--all-features` turns on for this crate (crateFeatureModel, `default` left out), or null when the manifest cannot be read;
|
|
86
|
+
* a null drops no check.
|
|
87
|
+
*/
|
|
88
|
+
export function allFeatureNamesOf(text) {
|
|
89
|
+
try { return [...crateFeatureModel(text).features.keys()].filter((name) => name !== "default"); } catch { return null; }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The features one cargo feature-flag set (`--all-features`, `--no-default-features`, `--features a,b`, `--features=a`, `-F a`) enables, closure included.
|
|
94
|
+
* `implicit`: the crate's implicit optional-dependency features (crateFeatureModel). A strong dependency feature `x/feat` turns on the optional
|
|
95
|
+
* dependency x and with it its implicit feature x; a weak one `x?/feat` does not; `dep:x` never names a feature
|
|
96
|
+
* (https://doc.rust-lang.org/cargo/reference/features.html#dependency-features; astra62 review 6).
|
|
97
|
+
*/
|
|
98
|
+
export function featuresEnabledBy(features, set, implicit = new Set()) {
|
|
81
99
|
const names = new Set(features.keys());
|
|
82
100
|
let all = false; let noDefault = false; const asked = [];
|
|
83
101
|
const words = Array.isArray(set) ? set : [];
|
|
@@ -95,32 +113,35 @@ export function featuresEnabledBy(features, set) {
|
|
|
95
113
|
if (!noDefault && names.has("default")) queue.push("default");
|
|
96
114
|
while (queue.length) {
|
|
97
115
|
const name = queue.pop();
|
|
98
|
-
if (enabled.has(name)) continue;
|
|
99
|
-
|
|
100
|
-
|
|
116
|
+
if (enabled.has(name) || name.startsWith("dep:")) continue;
|
|
117
|
+
if (name.includes("/")) {
|
|
118
|
+
const dep = name.slice(0, name.indexOf("/"));
|
|
119
|
+
if (!dep.endsWith("?") && implicit.has(dep)) queue.push(dep);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
101
122
|
enabled.add(name);
|
|
102
123
|
for (const member of features.get(name) ?? []) queue.push(member);
|
|
103
124
|
}
|
|
104
125
|
return enabled;
|
|
105
126
|
}
|
|
106
127
|
|
|
107
|
-
/** A crate's features that none of `sets` enables and the crate does not list in `unlinted` (`unlintedFeatures`): `[]` when every
|
|
108
|
-
export function uncoveredFeatures(manifestText, sets, unlinted = {}) {
|
|
109
|
-
const features =
|
|
128
|
+
/** A crate's features that none of `sets` enables and the crate does not list in `unlinted` (`unlintedFeatures`): `[]` when every feature, implicit ones included, is covered. Throws FeatureManifestError. */
|
|
129
|
+
export function uncoveredFeatures(manifestText, sets, unlinted = {}, where = "Cargo.toml") {
|
|
130
|
+
const { features, implicit } = crateFeatureModel(manifestText, where);
|
|
110
131
|
const declared = [...features.keys()].filter((name) => name !== "default" && !Object.hasOwn(unlinted, name));
|
|
111
132
|
const covered = new Set();
|
|
112
|
-
for (const set of sets) for (const f of featuresEnabledBy(features, set)) covered.add(f);
|
|
133
|
+
for (const set of sets) for (const f of featuresEnabledBy(features, set, implicit)) covered.add(f);
|
|
113
134
|
return declared.filter((name) => !covered.has(name)).sort();
|
|
114
135
|
}
|
|
115
136
|
|
|
116
137
|
/**
|
|
117
|
-
* The problem lines of a crate's `unlintedFeatures` (feature-sets.mjs): a feature it names must be
|
|
118
|
-
*
|
|
138
|
+
* The problem lines of a crate's `unlintedFeatures` (feature-sets.mjs): a feature it names must be one of the crate's features and enabled by none of
|
|
139
|
+
* the planned sets, or the entry is stale and the gate would lint a feature the config says it never lints. Throws FeatureManifestError.
|
|
119
140
|
*/
|
|
120
141
|
export function unlintedFeatureProblems({ name, manifestText, sets, unlinted = {} }) {
|
|
121
|
-
const features =
|
|
142
|
+
const { features, implicit } = crateFeatureModel(manifestText, `crate ${name} Cargo.toml`);
|
|
122
143
|
const enabled = new Set();
|
|
123
|
-
for (const set of sets) for (const f of featuresEnabledBy(features, set)) enabled.add(f);
|
|
144
|
+
for (const set of sets) for (const f of featuresEnabledBy(features, set, implicit)) enabled.add(f);
|
|
124
145
|
const problems = [];
|
|
125
146
|
for (const feature of Object.keys(unlinted).sort()) {
|
|
126
147
|
if (feature === "default" || !features.has(feature)) problems.push(`UNLINTED_FEATURE_UNKNOWN ${name}: unlintedFeatures names "${feature}", which the crate's Cargo.toml does not declare; remove it from ci/gate.config.json rust.${name}.unlintedFeatures`);
|
|
@@ -131,21 +152,27 @@ export function unlintedFeatureProblems({ name, manifestText, sets, unlinted = {
|
|
|
131
152
|
|
|
132
153
|
/**
|
|
133
154
|
* The FEATURE_UNCOVERED lines of one crate (`name`, its manifest text, every feature set its plan runs on any host, its `unlintedFeatures`),
|
|
134
|
-
* and the lines of an `unlintedFeatures` entry that is stale.
|
|
155
|
+
* and the lines of an `unlintedFeatures` entry that is stale. A manifest that cannot be read is itself a problem line, never an empty answer.
|
|
135
156
|
*/
|
|
136
157
|
export function featureCoverageProblems({ name, manifestText, sets, unlinted = {} }) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
158
|
+
try {
|
|
159
|
+
const missing = uncoveredFeatures(manifestText, sets, unlinted, `crate ${name} Cargo.toml`);
|
|
160
|
+
const planned = sets.map((s) => (s.length ? s.join(" ") : "default features")).join("; ");
|
|
161
|
+
return [
|
|
162
|
+
...missing.map((feature) => `FEATURE_UNCOVERED ${name}: feature "${feature}" is enabled by none of the planned feature sets (${planned}); add a set that enables it to ci/gate.config.json rust.${name}.featureSets, or --all-features where the features do not conflict, or name it with a reason in rust.${name}.unlintedFeatures`),
|
|
163
|
+
...unlintedFeatureProblems({ name, manifestText, sets, unlinted }),
|
|
164
|
+
];
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error instanceof FeatureManifestError) return [`${error.message}; feature coverage of ${name} cannot be judged`];
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
143
169
|
}
|
|
144
170
|
|
|
145
171
|
/**
|
|
146
|
-
* `crateFeatures` (ci/gate.config.json `rust`) with the generated lint plan for one crate: when the crate declares no `featureSets` and
|
|
147
|
-
*
|
|
148
|
-
* `manifestOf(name)` returns the crate's Cargo.toml text
|
|
172
|
+
* `crateFeatures` (ci/gate.config.json `rust`) with the generated lint plan for one crate: when the crate declares no `featureSets` and has a
|
|
173
|
+
* feature beyond `default` (declared or implicit, crateFeatureModel), `autoAllFeatures: true` is set on its entry. rustCratePlan reads that marker
|
|
174
|
+
* (scan-digest.mjs). `manifestOf(name)` returns the crate's Cargo.toml text. A manifest that cannot be read throws FeatureManifestError naming the
|
|
175
|
+
* crate: no plan is built from a guess. Pure.
|
|
149
176
|
*/
|
|
150
177
|
export function effectiveCrateFeatures({ crateFeatures = {}, units, manifestOf }) {
|
|
151
178
|
const out = { ...crateFeatures };
|
|
@@ -155,10 +182,10 @@ export function effectiveCrateFeatures({ crateFeatures = {}, units, manifestOf }
|
|
|
155
182
|
const unlinted = Object.keys(unlintedFeatures(own, name));
|
|
156
183
|
hasHostScopedSets(own, name);
|
|
157
184
|
if (Array.isArray(own.featureSets) && own.featureSets.length) continue;
|
|
158
|
-
let text
|
|
159
|
-
try { text = manifestOf(name); } catch {
|
|
160
|
-
|
|
161
|
-
const declared =
|
|
185
|
+
let text;
|
|
186
|
+
try { text = manifestOf(name); } catch (error) { throw new FeatureManifestError("missing", `crate ${name} Cargo.toml could not be read (${error?.message ?? error})`); }
|
|
187
|
+
const { features } = crateFeatureModel(text, `crate ${name} Cargo.toml`);
|
|
188
|
+
const declared = [...features.keys()].filter((feature) => feature !== "default");
|
|
162
189
|
if (!declared.length) continue;
|
|
163
190
|
// A feature named in `unlintedFeatures` is never added to a generated set: the generated set lists every other feature instead of --all-features.
|
|
164
191
|
if (unlinted.length) {
|
package/feature-partition.mjs
CHANGED
|
@@ -202,3 +202,79 @@ function moduleDigest() {
|
|
|
202
202
|
export function partitionCacheKey({ rest, crates, target = null, cwd = ".", inputs, toolVersion = null }) {
|
|
203
203
|
return sha256(`${FEATURE_PARTITION_SCHEMA}\0${JSON.stringify({ rest, crates: [...crates].sort(), target, cwd, inputs, toolVersion, code: moduleDigest() })}`);
|
|
204
204
|
}
|
|
205
|
+
|
|
206
|
+
// ---- several targets in one command (GATE-CONTRACT NN42) ---------------------------------------------------------------------------------
|
|
207
|
+
//
|
|
208
|
+
// NN42: the cross targets of one stage go in one command naming every `--target`. Cargo resolves features once per call for host and for
|
|
209
|
+
// target dependencies, never per triple, so a call naming two targets builds each with the union of both targets' features (HeardRight on the
|
|
210
|
+
// Dell, 2026-11-10: the macOS-only sqlcipher-system reached the Linux target). From 2026-11-10 the gate therefore named one target per call,
|
|
211
|
+
// always, which NN42 fails. Both hold when targets share a call exactly where that changes nothing: two targets may share one when every
|
|
212
|
+
// package both of them build resolves with the same features for each alone. Then the union is each one's own resolution.
|
|
213
|
+
|
|
214
|
+
export const TARGET_SPLIT_NOTE = "class B targets: ";
|
|
215
|
+
|
|
216
|
+
/** treeArgs for several targets: every `--target` named, as the compile command will name them. */
|
|
217
|
+
export function treeArgsForTargets({ rest, packages, targets }) {
|
|
218
|
+
if (!Array.isArray(targets) || !targets.length || targets.some((t) => typeof t !== "string" || !t)) throw new TypeError("treeArgsForTargets: targets must be target triples");
|
|
219
|
+
const args = treeArgs({ rest, packages, target: targets[0] });
|
|
220
|
+
const at = args.indexOf("--target");
|
|
221
|
+
return [...args.slice(0, at), ...targets.flatMap((t) => ["--target", t]), ...args.slice(at + 2)];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** The first package two targets both build and resolve differently: `{ package, aFeatures, bFeatures }` (each a sorted list of feature lists), or null. */
|
|
225
|
+
export function targetDifference(a, b) {
|
|
226
|
+
for (const pkg of [...a.keys()].sort()) {
|
|
227
|
+
const fb = b.get(pkg); if (!fb) continue;
|
|
228
|
+
const fa = a.get(pkg);
|
|
229
|
+
if (!sameSet(fa, fb)) return { package: pkg, aFeatures: [...fa].sort(), bFeatures: [...fb].sort() };
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The targets grouped so that any two in one group resolve every package they share alike. `featuresByTarget`: Map target -> parseTreeFeatures
|
|
236
|
+
* map of that target alone. Greedy and in the given order: a target joins the first group it agrees with on every member, else it starts one.
|
|
237
|
+
* Returns `{ classes: [[target, ...], ...], differences: [{ a, b, package, aFeatures, bFeatures }] }`, one difference for each pair that a
|
|
238
|
+
* group boundary separates and that does differ (the reason those two do not share a command).
|
|
239
|
+
*/
|
|
240
|
+
export function compatibleTargetClasses(featuresByTarget) {
|
|
241
|
+
const classes = []; const differences = [];
|
|
242
|
+
const noted = new Set();
|
|
243
|
+
const note = (a, b, d) => { const k = [a, b].sort().join("\0"); if (noted.has(k)) return; noted.add(k); differences.push({ a, b, ...d }); };
|
|
244
|
+
for (const [target, features] of featuresByTarget) {
|
|
245
|
+
let joined = false;
|
|
246
|
+
for (const cls of classes) {
|
|
247
|
+
let clash = null;
|
|
248
|
+
for (const other of cls) { const d = targetDifference(featuresByTarget.get(other), features); if (d) { clash = { other, d }; break; } }
|
|
249
|
+
if (!clash) { cls.push(target); joined = true; break; }
|
|
250
|
+
note(clash.other, target, clash.d);
|
|
251
|
+
}
|
|
252
|
+
if (!joined) classes.push([target]);
|
|
253
|
+
}
|
|
254
|
+
// Every pair of targets left in different groups is named when it differs, so a reader sees for each pair why it does not share a command.
|
|
255
|
+
for (let i = 0; i < classes.length; i += 1) for (let j = i + 1; j < classes.length; j += 1) for (const a of classes[i]) for (const b of classes[j]) {
|
|
256
|
+
const d = targetDifference(featuresByTarget.get(a), featuresByTarget.get(b));
|
|
257
|
+
if (d) note(a, b, d);
|
|
258
|
+
}
|
|
259
|
+
return { classes, differences };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Whether cargo's own resolution of several targets in ONE call (`group`, a parseTreeFeatures map of the call naming them all) is each
|
|
264
|
+
* target's resolution alone, for every package that target builds: null when it is, else `{ target, package, aloneFeatures, groupFeatures }`.
|
|
265
|
+
*/
|
|
266
|
+
export function groupTargetDifference(group, featuresByTarget, targets) {
|
|
267
|
+
for (const target of targets) {
|
|
268
|
+
const alone = featuresByTarget.get(target);
|
|
269
|
+
for (const pkg of [...alone.keys()].sort()) {
|
|
270
|
+
const g = group.get(pkg);
|
|
271
|
+
if (!g || !sameSet(alone.get(pkg), g)) return { target, package: pkg, aloneFeatures: [...alone.get(pkg)].sort(), groupFeatures: g ? [...g].sort() : null };
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** The note the gate prints for two targets that stay separate commands; the contract test reads it back (targetSplitNotesOf). */
|
|
278
|
+
export function targetSplitNote({ sub, cwd, crates = null, a, b, package: pkg, aFeatures, bFeatures }) {
|
|
279
|
+
return `${TARGET_SPLIT_NOTE}${JSON.stringify({ sub, cwd, ...(Array.isArray(crates) ? { crates } : {}), a, b, package: pkg, aFeatures, bFeatures })}`;
|
|
280
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Release-time absence scan: fail when any file under the scanned targets contains one of a set of
|
|
2
|
+
// forbidden byte strings (secret names, secret values read from the environment). The app declares
|
|
3
|
+
// WHAT is forbidden and WHERE to look; nothing here names a product, a secret or a path.
|
|
4
|
+
//
|
|
5
|
+
// Used by an app's own check script (`scripts/assert-...mjs`), which holds only its configuration:
|
|
6
|
+
//
|
|
7
|
+
// import { runForbiddenLiteralScan } from "@rightkit/release/forbidden-literals.mjs";
|
|
8
|
+
// runForbiddenLiteralScan({ root, defaults: [...], literals: [...], envNames: [...],
|
|
9
|
+
// failure: "reusable model bearer material found in", ok: "...: ok" });
|
|
10
|
+
//
|
|
11
|
+
// Symlinks are never followed. A scan target that does not exist is an error, never a pass.
|
|
12
|
+
import { existsSync, lstatSync, readFileSync, readdirSync } from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
|
|
15
|
+
/** Every regular file under `target` (a file, or a directory walked recursively), symlinks skipped. */
|
|
16
|
+
export function filesWithin(target) {
|
|
17
|
+
if (!existsSync(target)) throw new Error(`scan target does not exist: ${target}`);
|
|
18
|
+
const stat = lstatSync(target);
|
|
19
|
+
if (stat.isSymbolicLink()) return [];
|
|
20
|
+
if (stat.isFile()) return [target];
|
|
21
|
+
if (!stat.isDirectory()) return [];
|
|
22
|
+
return readdirSync(target, { withFileTypes: true }).flatMap((entry) => {
|
|
23
|
+
const child = path.join(target, entry.name);
|
|
24
|
+
if (entry.isSymbolicLink()) return [];
|
|
25
|
+
return entry.isDirectory() ? filesWithin(child) : entry.isFile() ? [child] : [];
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The files under `targets` that contain any needle.
|
|
31
|
+
* @param {{ targets: string[], needles: Buffer[] }} input
|
|
32
|
+
* @returns {string[]} the offending file paths
|
|
33
|
+
*/
|
|
34
|
+
export function scanForbiddenLiterals({ targets, needles }) {
|
|
35
|
+
const found = [];
|
|
36
|
+
for (const file of targets.flatMap(filesWithin)) {
|
|
37
|
+
const bytes = readFileSync(file);
|
|
38
|
+
if (needles.some((needle) => needle.length > 0 && bytes.includes(needle))) found.push(file);
|
|
39
|
+
}
|
|
40
|
+
return found;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The whole CLI behaviour. Exits 1 on a finding or an error; prints `ok` on success.
|
|
45
|
+
* @param {{
|
|
46
|
+
* root: string, // repo-relative paths in messages are printed relative to this
|
|
47
|
+
* defaults: string[], // scan targets (absolute) used when no argv targets are given
|
|
48
|
+
* literals: string[], // forbidden literal strings
|
|
49
|
+
* envNames?: string[], // env vars whose CURRENT non-empty value is also forbidden
|
|
50
|
+
* failure: string, // message prefix printed with the relative file path
|
|
51
|
+
* ok: string, // message printed on success
|
|
52
|
+
* argv?: string[], // extra targets (default: process.argv.slice(2))
|
|
53
|
+
* }} config
|
|
54
|
+
*/
|
|
55
|
+
export function runForbiddenLiteralScan(config) {
|
|
56
|
+
const targets = (config.argv ?? process.argv.slice(2)).map((entry) => path.resolve(entry));
|
|
57
|
+
const needles = config.literals.map((literal) => Buffer.from(literal));
|
|
58
|
+
for (const name of config.envNames ?? []) {
|
|
59
|
+
const value = process.env[name]?.trim();
|
|
60
|
+
if (value) needles.push(Buffer.from(value));
|
|
61
|
+
}
|
|
62
|
+
let failed = false;
|
|
63
|
+
try {
|
|
64
|
+
const offenders = scanForbiddenLiterals({
|
|
65
|
+
targets: targets.length > 0 ? targets : config.defaults,
|
|
66
|
+
needles,
|
|
67
|
+
});
|
|
68
|
+
for (const file of offenders) {
|
|
69
|
+
console.error(`${config.failure} ${path.relative(config.root, file)}`);
|
|
70
|
+
failed = true;
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
if (failed) process.exit(1);
|
|
77
|
+
console.log(config.ok);
|
|
78
|
+
}
|
package/gate/calls.mjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// The Cargo calls of one run (design section 7, docs/design/2026-11-10-gate-fresh-design.md). Pure: selection + config in, call list out.
|
|
2
|
+
//
|
|
3
|
+
// Crates build together (Adrian, 2026-11-04: "RK has to build all it's necessary crates together. today, the agent built each one
|
|
4
|
+
// separately."). A call names every selected crate it applies to; there are no per-crate rows, no batching step and no feature
|
|
5
|
+
// partition. A crate-specific feature set is the one thing that is a call of its own, because `--features` names one crate's features.
|
|
6
|
+
//
|
|
7
|
+
// Input crate: { name, platforms?: ["darwin"|"win32"|"linux"], hasLib: boolean, declaresFeatures: boolean, config?: <ci/gate.config.json rust.<name>> }
|
|
8
|
+
// A docs call is sent with RUSTDOCFLAGS set to DOC_DENY (compile.mjs callEnv): a rustdoc warning fails here as it fails in CI.
|
|
9
|
+
// Output call: { id, stage: "lint"|"test-build"|"docs", round, crates: [{ name, targets }], args: [...], cwd?: <dir for a consumer manifest> }
|
|
10
|
+
import { featureSetEntries, unlintedFeatures } from "../feature-sets.mjs";
|
|
11
|
+
|
|
12
|
+
/** What a docs call sets RUSTDOCFLAGS to. The same value CI uses (deterministic-scans.mjs DOC_RUSTDOCFLAGS; a test keeps them equal) and the only one the broker admits. */
|
|
13
|
+
export const DOC_DENY = "-D warnings";
|
|
14
|
+
|
|
15
|
+
/** process.platform word of a target triple. */
|
|
16
|
+
|
|
17
|
+
export const osOfTriple = (triple) => (/-apple-/.test(triple) ? "darwin" : /-windows-/.test(triple) ? "win32" : /-linux-/.test(triple) ? "linux" : null);
|
|
18
|
+
|
|
19
|
+
const runsOn = (crate, os) => !Array.isArray(crate.platforms) || crate.platforms.includes(os);
|
|
20
|
+
const packages = (names) => names.flatMap((n) => ["-p", n]);
|
|
21
|
+
const key = (list) => list.join(" ");
|
|
22
|
+
|
|
23
|
+
/** The sets of `list` planned on `host` as [{ features, scoped }]; `scoped` (a host-scoped set) gets no other-OS lint. */
|
|
24
|
+
function setsOn(list, host, which, name) {
|
|
25
|
+
if (list === undefined) return undefined;
|
|
26
|
+
return featureSetEntries(list, which, name).filter((s) => s.hosts === null || s.hosts.includes(host)).map((s) => ({ features: s.features, scoped: s.hosts !== null }));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The lint sets and lint-only sets of one crate on this host, mirroring what the config has always meant:
|
|
31
|
+
* - `featureSets` absent: default features; and `--all-features` too when the crate declares features and names none unlinted;
|
|
32
|
+
* - `featureSets` present: exactly those sets (lint, test build and docs each);
|
|
33
|
+
* - `checkFeatureSets`: lint only; absent means one `--all-features` lint unless a lint set already is `--all-features` or the crate names unlinted features.
|
|
34
|
+
*/
|
|
35
|
+
export function cratePlan(crate, host) {
|
|
36
|
+
const cfg = crate.config ?? {};
|
|
37
|
+
const declared = setsOn(cfg.featureSets, host, "featureSets", crate.name);
|
|
38
|
+
const noAllFeatures = Object.keys(unlintedFeatures(cfg, crate.name)).length > 0;
|
|
39
|
+
const full = declared ?? [{ features: [], scoped: false }];
|
|
40
|
+
const hasAll = (sets) => sets.some((s) => s.features.includes("--all-features"));
|
|
41
|
+
let lintOnly = setsOn(cfg.checkFeatureSets, host, "checkFeatureSets", crate.name);
|
|
42
|
+
if (lintOnly === undefined) lintOnly = hasAll(full) || noAllFeatures || !crate.declaresFeatures ? [] : [{ features: ["--all-features"], scoped: false }];
|
|
43
|
+
lintOnly = lintOnly.filter((s) => s.features.length > 0 && !full.some((f) => key(f.features) === key(s.features)));
|
|
44
|
+
return { full, lintOnly };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Every call of a run.
|
|
49
|
+
* `crates`: the selected crates of ONE Cargo workspace. `host`: process.platform. `hostTriple`: this host's target. `otherTriples`: the other OS targets linted here.
|
|
50
|
+
* Order: the together calls first (they do the compile work), then the single-crate feature calls, then consumer manifests.
|
|
51
|
+
*/
|
|
52
|
+
export function planCalls({ crates, host, hostTriple, otherTriples = [] }) {
|
|
53
|
+
const here = crates.filter((c) => runsOn(c, host)).sort((a, b) => a.name.localeCompare(b.name));
|
|
54
|
+
const plans = new Map(here.map((c) => [c.name, cratePlan(c, host)]));
|
|
55
|
+
const calls = [];
|
|
56
|
+
const lintTargets = (crate, scoped) => [hostTriple, ...(scoped ? [] : otherTriples.filter((t) => runsOn(crate, osOfTriple(t))))];
|
|
57
|
+
const lintCalls = (round, members, features) => {
|
|
58
|
+
// One call per target triple, naming every crate that builds for it. Never several targets in one call: Cargo resolves features for
|
|
59
|
+
// host dependencies and target dependencies, not per triple, so a call naming two targets gives each the union of both targets'
|
|
60
|
+
// features (HeardRight on the Dell, 2026-11-10: the macOS-only `sqlcipher-system` was switched on for the Linux target and its C code
|
|
61
|
+
// then wanted OpenSSL headers). A crate is never asked for a target it cannot build.
|
|
62
|
+
const triples = [...new Set(members.flatMap((m) => m.targets))];
|
|
63
|
+
for (const triple of triples) {
|
|
64
|
+
const group = members.filter((m) => m.targets.includes(triple)).map((m) => ({ name: m.name, targets: [triple] }));
|
|
65
|
+
calls.push({
|
|
66
|
+
id: `lint:${round}:${osOfTriple(triple) ?? triple}`, stage: "lint", round, crates: group,
|
|
67
|
+
args: ["clippy", ...packages(group.map((m) => m.name)), ...features, "--all-targets", "--no-deps", "--target", triple, "--locked", "--message-format=json", "--", "-D", "warnings"],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const buildCalls = (round, names, features, libs) => {
|
|
72
|
+
if (names.length) calls.push({ id: `test-build:${round}`, stage: "test-build", round, crates: names.map((name) => ({ name, targets: [hostTriple] })), args: ["test", ...packages(names), ...features, "--target", hostTriple, "--locked"] });
|
|
73
|
+
if (libs.length) calls.push({ id: `docs:${round}`, stage: "docs", round, crates: libs.map((name) => ({ name, targets: [hostTriple] })), args: ["doc", ...packages(libs), ...features, "--no-deps", "--lib", "--target", hostTriple, "--locked", "--message-format=json"] });
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Together rounds: the feature flags that mean the same for every crate (none, --all-features).
|
|
77
|
+
for (const [round, flags] of [["default", []], ["all-features", ["--all-features"]]]) {
|
|
78
|
+
const full = here.filter((c) => plans.get(c.name).full.some((s) => key(s.features) === key(flags)));
|
|
79
|
+
const lintOnly = here.filter((c) => plans.get(c.name).lintOnly.some((s) => key(s.features) === key(flags)));
|
|
80
|
+
const scopedOf = (c) => [...plans.get(c.name).full, ...plans.get(c.name).lintOnly].find((s) => key(s.features) === key(flags)).scoped;
|
|
81
|
+
lintCalls(round, [...full, ...lintOnly].map((c) => ({ name: c.name, targets: lintTargets(c, scopedOf(c)) })), flags);
|
|
82
|
+
buildCalls(round, full.map((c) => c.name), flags, full.filter((c) => c.hasLib).map((c) => c.name));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Crate-specific sets: one crate per call.
|
|
86
|
+
for (const c of here) {
|
|
87
|
+
const { full, lintOnly } = plans.get(c.name);
|
|
88
|
+
const specific = (s) => s.features.length > 0 && key(s.features) !== "--all-features";
|
|
89
|
+
full.filter(specific).forEach((s) => {
|
|
90
|
+
const round = `${c.name}[${s.features.slice(1).join(" ") || s.features.join(" ")}]`;
|
|
91
|
+
lintCalls(round, [{ name: c.name, targets: lintTargets(c, s.scoped) }], s.features);
|
|
92
|
+
buildCalls(round, [c.name], s.features, c.hasLib ? [c.name] : []);
|
|
93
|
+
});
|
|
94
|
+
lintOnly.filter(specific).forEach((s) => {
|
|
95
|
+
const round = `${c.name}[${s.features.slice(1).join(" ") || s.features.join(" ")}]`;
|
|
96
|
+
lintCalls(round, [{ name: c.name, targets: lintTargets(c, s.scoped) }], s.features);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Consumer manifests: small separate workspaces that exercise a crate the way an app would.
|
|
101
|
+
// The same manifest with the same arguments is one call, whichever crates declare it; each of them gets its result. A consumer call is judged
|
|
102
|
+
// whole (run-calls.mjs): its own package is not one of the named crates, so the call passes for them only when the whole call succeeded.
|
|
103
|
+
const consumers = new Map();
|
|
104
|
+
for (const c of here) {
|
|
105
|
+
for (const row of c.config?.consumerRows ?? []) {
|
|
106
|
+
const dir = String(row.manifestPath).replace(/[\\/]Cargo\.toml$/, "");
|
|
107
|
+
const args = ["clippy", ...(row.args ?? []), "--all-targets", "--no-deps", "--target", hostTriple, ...(row.locked === false ? [] : ["--locked"]), "--message-format=json", "--", "-D", "warnings"];
|
|
108
|
+
const same = `${dir}\0${key(args)}`;
|
|
109
|
+
if (!consumers.has(same)) { const call = { id: `lint:consumer:${dir}${consumers.size ? `:${consumers.size + 1}` : ""}`, stage: "lint", round: `consumer:${dir}`, cwd: dir, consumer: true, crates: [], args }; consumers.set(same, call); calls.push(call); }
|
|
110
|
+
consumers.get(same).crates.push({ name: c.name, targets: [hostTriple], consumer: dir });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return calls;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** What the plan does not lint, for the run summary: { crate: { feature: reason } } and crates that do not run on this host. */
|
|
117
|
+
export function planNotes({ crates, host }) {
|
|
118
|
+
const notLinted = {};
|
|
119
|
+
for (const c of crates) { const u = unlintedFeatures(c.config ?? {}, c.name); if (Object.keys(u).length) notLinted[c.name] = u; }
|
|
120
|
+
return { notLinted, notOnThisHost: crates.filter((c) => !runsOn(c, host)).map((c) => c.name).sort() };
|
|
121
|
+
}
|