The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(scripts): check feature forwarding through the library chain
obchain8191a921dee6
diff --git a/scripts/__tests__/feature-forwarding.test.mjs b/scripts/__tests__/feature-forwarding.test.mjsindex 5c329ca6ef..e6726264ca 100644--- a/scripts/__tests__/feature-forwarding.test.mjs+++ b/scripts/__tests__/feature-forwarding.test.mjs@@ -1,18 +1,23 @@import assert from 'node:assert/strict';import { execFileSync, spawnSync } from 'node:child_process';-import { readFileSync, rmSync, writeFileSync } from 'node:fs';+import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { dirname, join, resolve } from 'node:path';import { test } from 'node:test';import { fileURLToPath } from 'node:url';import {+ CHAIN_GATES_NOT_FORWARDED,+ CHAIN_LOCAL_GATES,checkProductForwarding,+ diffChainForwarding,diffForwarding,+ formatChainReport,INTENTIONALLY_NOT_FORWARDED,parseCoreDefaultFeatures,parseCoreFeatureGraph,parseCoreFeatureNames,+ parseFeatureTable,parseProductFeatures,parseShellForwardedFeatures,resolveEnabledFeatures,@@ -476,3 +481,335 @@ test('an apostrophe inside a basic string does not open a literal string', () =>'media',]);});++// ── the library chain: core → embed → tinyhumans → cli (#6364) ─────────────++const CORE_CHAIN_FIXTURE = `+[features]+default = ["media"]+media = []+voice = ["dep:cpal"]+e2e-test-support = []+`;++function chainLink(toml, sources, extra = {}) {+ return diffChainForwarding({+ crate: 'openhuman-embed',+ features: parseFeatureTable(toml),+ sources,+ ...extra,+ });+}++function coreSource() {+ return {+ crate: 'openhuman-core',+ gates: [...parseFeatureTable(CORE_CHAIN_FIXTURE).keys()].filter(n => n !== 'default'),+ required: true,+ };+}++test('a layer that forwards every core gate passes', () => {+ const result = chainLink(+ `+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media"]+voice = ["openhuman-core/voice"]+e2e-test-support = ["openhuman-core/e2e-test-support"]+`,+ [coreSource()]+ );+ assert.ok(result.ok, formatChainReport(result));+});++test('a core gate the layer forgets is reported missing, naming crate and gate', () => {+ // The silent direction: `--features voice` still resolves on openhuman-cli,+ // so CI stays green while the gate is off for every embedder.+ const result = chainLink(+ `+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media"]+e2e-test-support = ["openhuman-core/e2e-test-support"]+`,+ [coreSource()]+ );+ assert.equal(result.ok, false);+ assert.deepEqual(result.missing, [{ gate: 'voice', source: 'openhuman-core' }]);+ const report = formatChainReport(result);+ assert.match(report, /openhuman-embed/);+ assert.match(report, /voice \(declared by openhuman-core\)/);+});++test('reproduces #6360: a gate the core dropped but a layer still forwards is flagged', () => {+ const result = chainLink(+ `+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media"]+voice = ["openhuman-core/voice"]+e2e-test-support = ["openhuman-core/e2e-test-support"]+peripheral-rpi = ["openhuman-core/peripheral-rpi"]+`,+ [coreSource()]+ );+ assert.equal(result.ok, false);+ assert.deepEqual(result.unknown, ['peripheral-rpi']);+ assert.match(formatChainReport(result), /no crate below it has/);+});++test('a forward that names the wrong gate is caught, not just a missing one', () => {+ // A name-only check reads this as forwarded. It is not: enabling `voice`+ // would turn `web3` on in the core and leave voice compiled out.+ const result = chainLink(+ `+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media"]+voice = ["openhuman-core/web3"]+e2e-test-support = ["openhuman-core/e2e-test-support"]+`,+ [coreSource()]+ );+ assert.equal(result.ok, false);+ assert.deepEqual(result.misrouted, [+ { gate: 'voice', source: 'openhuman-core', expected: 'openhuman-core/voice' },+ ]);+ assert.match(formatChainReport(result), /expected "openhuman-core\/voice"/);+});++test('an allow-listed omission passes and is reported as intentional', () => {+ const notForwarded = { 'e2e-test-support': 'Destructive test_reset RPC; never for embedders.' };+ const result = chainLink(+ `+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media"]+voice = ["openhuman-core/voice"]+`,+ [coreSource()],+ { notForwarded }+ );+ assert.ok(result.ok, formatChainReport(result, { notForwarded }));+ assert.deepEqual(result.allowed, ['e2e-test-support']);+ assert.match(formatChainReport(result, { notForwarded }), /allowed: e2e-test-support/);+});++test('an allow-list entry for a gate that IS forwarded is flagged as stale', () => {+ const result = chainLink(+ `+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media"]+voice = ["openhuman-core/voice"]+e2e-test-support = ["openhuman-core/e2e-test-support"]+`,+ [coreSource()],+ { notForwarded: { 'e2e-test-support': 'never for embedders' } }+ );+ assert.equal(result.ok, false);+ assert.deepEqual(result.staleExclusion, ['e2e-test-support']);+});++test('a documented crate-local gate passes', () => {+ const result = chainLink(+ `+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media"]+voice = ["openhuman-core/voice"]+e2e-test-support = ["openhuman-core/e2e-test-support"]+jev = ["dep:tinytools-jev"]+`,+ [coreSource()],+ { localGates: { jev: 'This crate owns the gate.' } }+ );+ assert.ok(result.ok, formatChainReport(result));+ assert.deepEqual(result.unknown, []);+});++test('a crate-local entry for a gate the core now declares is flagged as stale', () => {+ // Otherwise the entry would excuse a missing forward for a real core gate.+ const result = chainLink(+ `+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media"]+voice = ["openhuman-core/voice"]+e2e-test-support = ["openhuman-core/e2e-test-support"]+`,+ [coreSource()],+ { localGates: { voice: 'local, honest' } }+ );+ assert.equal(result.ok, false);+ assert.deepEqual(result.staleLocal, ['voice']);+});++test('a forward to a gate the crate below no longer has is named as drift', () => {+ // #6360 verbatim: cargo rejects this, but only for whoever builds that crate+ // first, and the error reads as a dependency problem.+ const result = diffChainForwarding({+ crate: 'openhuman-cli',+ features: parseFeatureTable(`+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media", "openhuman-tinyhumans/media"]+voice = ["openhuman-core/voice", "openhuman-tinyhumans/voice"]+e2e-test-support = ["openhuman-core/e2e-test-support"]+`),+ sources: [+ coreSource(),+ // tinyhumans dropped `voice`; the cli still points at it.+ { crate: 'openhuman-tinyhumans', gates: ['media'], required: false },+ ],+ });+ assert.equal(result.ok, false);+ assert.deepEqual(result.dangling, [{ gate: 'voice', item: 'openhuman-tinyhumans/voice' }]);+ assert.match(formatChainReport(result), /no longer exists/);+});++test('the cli must forward to tinyhumans as well where tinyhumans has the gate', () => {+ const result = diffChainForwarding({+ crate: 'openhuman-cli',+ features: parseFeatureTable(`+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media"]+voice = ["openhuman-core/voice"]+e2e-test-support = ["openhuman-core/e2e-test-support"]+`),+ sources: [+ coreSource(),+ { crate: 'openhuman-tinyhumans', gates: ['media', 'voice'], required: false },+ ],+ });+ assert.equal(result.ok, false);+ assert.deepEqual(+ result.misrouted.map(m => m.expected),+ ['openhuman-tinyhumans/media', 'openhuman-tinyhumans/voice']+ );+});++test('an optional source never demands a gate the crate below it does not have', () => {+ // `e2e-test-support` is core-only: requiring `openhuman-tinyhumans/e2e-test-support`+ // would be a forward to a gate that does not exist, i.e. a cargo error.+ const result = diffChainForwarding({+ crate: 'openhuman-cli',+ features: parseFeatureTable(`+[features]+default = ["openhuman-core/default"]+media = ["openhuman-core/media", "openhuman-tinyhumans/media"]+voice = ["openhuman-core/voice", "openhuman-tinyhumans/voice"]+e2e-test-support = ["openhuman-core/e2e-test-support"]+`),+ sources: [+ coreSource(),+ { crate: 'openhuman-tinyhumans', gates: ['media', 'voice'], required: false },+ ],+ });+ assert.ok(result.ok, formatChainReport(result));+});++test('the checked-in embed, tinyhumans and cli manifests forward the whole chain', () => {+ const read = name => readFileSync(resolve(REPO_ROOT, `crates/${name}/Cargo.toml`), 'utf8');+ const core = parseCoreFeatureNames(+ readFileSync(resolve(REPO_ROOT, 'crates/openhuman-core/Cargo.toml'), 'utf8')+ );+ const embed = parseFeatureTable(read('openhuman-embed'));+ const tinyhumans = parseFeatureTable(read('openhuman-tinyhumans'));+ const cli = parseFeatureTable(read('openhuman-cli'));+ // Guards the guard: empty tables would make every assertion below vacuous.+ assert.ok(core.length > 0, 'expected to parse at least one core gate');+ for (const [name, table] of [+ ['openhuman-embed', embed],+ ['openhuman-tinyhumans', tinyhumans],+ ['openhuman-cli', cli],+ ]) {+ assert.ok(table.size > 0, `expected to parse features from ${name}`);+ }+ const gatesOf = table => [...table.keys()].filter(n => n !== 'default');+ const links = [+ {+ crate: 'openhuman-embed',+ features: embed,+ sources: [{ crate: 'openhuman-core', gates: core, required: true }],+ },+ {+ crate: 'openhuman-tinyhumans',+ features: tinyhumans,+ sources: [{ crate: 'openhuman-embed', gates: gatesOf(embed), required: true }],+ },+ {+ crate: 'openhuman-cli',+ features: cli,+ sources: [+ { crate: 'openhuman-core', gates: core, required: true },+ { crate: 'openhuman-tinyhumans', gates: gatesOf(tinyhumans), required: false },+ ],+ },+ ];+ for (const link of links) {+ const notForwarded = CHAIN_GATES_NOT_FORWARDED[link.crate] ?? {};+ const result = diffChainForwarding({+ ...link,+ notForwarded,+ localGates: CHAIN_LOCAL_GATES[link.crate] ?? {},+ });+ assert.ok(result.ok, formatChainReport(result, { notForwarded }));+ }+});++test('every chain allow-list entry carries a reason', () => {+ // A blank reason is how "excluded on purpose" and "forgotten" start looking+ // the same again — the ambiguity that let #4918 sit unnoticed.+ for (const table of [CHAIN_GATES_NOT_FORWARDED, CHAIN_LOCAL_GATES]) {+ for (const [crate, gates] of Object.entries(table)) {+ for (const [gate, reason] of Object.entries(gates)) {+ assert.equal(typeof reason, 'string', `${crate}/${gate}`);+ assert.ok(reason.trim().length > 10, `${crate}/${gate} needs a real reason`);+ }+ }+ }+});++test('the checker reports the chain and fails when a layer drops a gate', () => {+ // End-to-end through the CLI: a core gate that embed never took must exit 1+ // with the crate and gate named.+ const dir = join(tmpdir(), `feature-chain-${process.pid}`);+ const corePath = join(dir, 'core.toml');+ const embedPath = join(dir, 'embed.toml');+ try {+ mkdirSync(dir, { recursive: true });+ writeFileSync(+ corePath,+ readFileSync(resolve(REPO_ROOT, 'crates/openhuman-core/Cargo.toml'), 'utf8')+ );+ writeFileSync(+ embedPath,+ readFileSync(resolve(REPO_ROOT, 'crates/openhuman-embed/Cargo.toml'), 'utf8').replace(+ /^voice = .*$/m,+ ''+ )+ );+ const result = spawnSync(+ 'node',+ [+ CHECKER,+ corePath,+ resolve(REPO_ROOT, 'crates/openhuman-app/Cargo.toml'),+ resolve(REPO_ROOT, 'scripts/ci/product-features.txt'),+ embedPath,+ resolve(REPO_ROOT, 'crates/openhuman-tinyhumans/Cargo.toml'),+ resolve(REPO_ROOT, 'crates/openhuman-cli/Cargo.toml'),+ ],+ { encoding: 'utf8' }+ );+ assert.equal(result.status, 1, result.stdout + result.stderr);+ assert.match(result.stdout, /Library chain/);+ assert.match(result.stdout, /openhuman-embed/);+ assert.match(result.stdout, /voice \(declared by openhuman-core\)/);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+});diff --git a/scripts/ci/check-feature-forwarding.mjs b/scripts/ci/check-feature-forwarding.mjsindex 8e7ad008bf..755a685629 100644--- a/scripts/ci/check-feature-forwarding.mjs+++ b/scripts/ci/check-feature-forwarding.mjs@@ -14,19 +14,31 @@// `[features] default` — `default` is the contributor set now and is// deliberately smaller.//+// It also checks the library chain the core is re-declared by — embed,+// tinyhumans and cli (#6364). Those three lists were maintained by hand: a gate+// dropped from the core and left behind is a cargo error nobody reads as drift+// (#6360), and a gate ADDED to the core and forgotten is silent, because the+// product lanes only ever resolve names against `openhuman-cli`.+//// Usage: check-feature-forwarding.mjs [core-manifest] [shell-manifest] [product-features]+// [embed-manifest] [tinyhumans-manifest] [cli-manifest]import { readFileSync } from 'node:fs';import { dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import {+ CHAIN_GATES_NOT_FORWARDED,+ CHAIN_LOCAL_GATES,checkProductForwarding,+ diffChainForwarding,diffForwarding,+ formatChainReport,formatProductReport,formatReport,INTENTIONALLY_NOT_FORWARDED,parseCoreDefaultFeatures,parseCoreFeatureNames,+ parseFeatureTable,parseProductFeatures,parseShellForwardedFeatures,} from '../lib/feature-forwarding.mjs';@@ -34,10 +46,14 @@ import {const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../..');function usage() {- return 'Usage: check-feature-forwarding.mjs [core-manifest] [shell-manifest] [product-features]';+ return (+ 'Usage: check-feature-forwarding.mjs [core-manifest] [shell-manifest] [product-features]\n' ++ ' [embed-manifest] [tinyhumans-manifest] [cli-manifest]'+ );}-const [coreArg, shellArg, productArg, extra] = process.argv.slice(2);+const [coreArg, shellArg, productArg, embedArg, tinyhumansArg, cliArg, extra] =+ process.argv.slice(2);if (coreArg === '--help' || coreArg === '-h') {console.log(usage());process.exit(0);@@ -54,14 +70,27 @@ const shellPath = shellArg ? resolve(shellArg) : resolve(REPO_ROOT, 'crates/openconst productPath = productArg? resolve(productArg): resolve(REPO_ROOT, 'scripts/ci/product-features.txt');+const embedPath = embedArg+ ? resolve(embedArg)+ : resolve(REPO_ROOT, 'crates/openhuman-embed/Cargo.toml');+const tinyhumansPath = tinyhumansArg+ ? resolve(tinyhumansArg)+ : resolve(REPO_ROOT, 'crates/openhuman-tinyhumans/Cargo.toml');+const cliPath = cliArg ? resolve(cliArg) : resolve(REPO_ROOT, 'crates/openhuman-cli/Cargo.toml');let coreToml;let shellToml;let productText;+let embedToml;+let tinyhumansToml;+let cliToml;try {coreToml = readFileSync(corePath, 'utf8');shellToml = readFileSync(shellPath, 'utf8');productText = readFileSync(productPath, 'utf8');+ embedToml = readFileSync(embedPath, 'utf8');+ tinyhumansToml = readFileSync(tinyhumansPath, 'utf8');+ cliToml = readFileSync(cliPath, 'utf8');} catch (err) {console.error(`Could not read inputs: ${err.message}`);process.exit(2);@@ -108,4 +137,70 @@ const defaults = diffForwarding({console.log('');console.log(formatReport(defaults, { coreDefaults, shell, allowlist: INTENTIONALLY_NOT_FORWARDED }));-process.exit(product.ok && defaults.ok ? 0 : 1);+// Assertion 4: the library chain (#6364). The core's gates are re-declared by+// embed, then tinyhumans, then cli, and each hop can drop one.+const embedFeatures = parseFeatureTable(embedToml);+const tinyhumansFeatures = parseFeatureTable(tinyhumansToml);+const cliFeatures = parseFeatureTable(cliToml);++// Guard the guard, same as above: a parser that found nothing would turn every+// chain assertion into a rubber stamp.+for (const [path, table] of [+ [embedPath, embedFeatures],+ [tinyhumansPath, tinyhumansFeatures],+ [cliPath, cliFeatures],+]) {+ if (table.size === 0) {+ console.error(+ `FAIL: parsed zero features from ${path}.\n` ++ 'Either the manifest changed shape or the parser is broken — refusing to pass vacuously.'+ );+ process.exit(2);+ }+}++const embedGates = [...embedFeatures.keys()].filter(name => name !== 'default');+const tinyhumansGates = [...tinyhumansFeatures.keys()].filter(name => name !== 'default');++const chain = [+ {+ crate: 'openhuman-embed',+ features: embedFeatures,+ sources: [{ crate: 'openhuman-core', gates: coreFeatureNames, required: true }],+ },+ {+ crate: 'openhuman-tinyhumans',+ features: tinyhumansFeatures,+ sources: [{ crate: 'openhuman-embed', gates: embedGates, required: true }],+ },+ {+ crate: 'openhuman-cli',+ features: cliFeatures,+ sources: [+ { crate: 'openhuman-core', gates: coreFeatureNames, required: true },+ // Optional: the cli forwards to both parents, but only for the gates+ // tinyhumans actually has — `e2e-test-support` is core-only.+ { crate: 'openhuman-tinyhumans', gates: tinyhumansGates, required: false },+ ],+ },+].map(link =>+ diffChainForwarding({+ ...link,+ notForwarded: CHAIN_GATES_NOT_FORWARDED[link.crate] ?? {},+ localGates: CHAIN_LOCAL_GATES[link.crate] ?? {},+ })+);++console.log('');+console.log('Library chain (core -> embed -> tinyhumans -> cli):');+for (const result of chain) {+ console.log(+ formatChainReport(result, {+ notForwarded: CHAIN_GATES_NOT_FORWARDED[result.crate] ?? {},+ })+ );+}++const chainOk = chain.every(result => result.ok);++process.exit(product.ok && defaults.ok && chainOk ? 0 : 1);diff --git a/scripts/lib/feature-forwarding.mjs b/scripts/lib/feature-forwarding.mjsindex dc4e43f3d1..ac417bfeb4 100644--- a/scripts/lib/feature-forwarding.mjs+++ b/scripts/lib/feature-forwarding.mjs@@ -399,3 +399,220 @@ export function formatReport(result, { coreDefaults, shell, allowlist = {} }) {lines.push('', 'OK: every default-ON core gate is forwarded to the desktop shell.');return lines.join('\n');}++// ── the library chain: core → embed → tinyhumans → cli (#6364) ─────────────+//+// The shell is not the only manifest that re-declares the core's gates. The+// library layers forward them 1:1 three more times:+//+// openhuman-embed <gate> = ["openhuman-core/<gate>"]+// openhuman-tinyhumans <gate> = ["openhuman-embed/<gate>"]+// openhuman-cli <gate> = ["openhuman-core/<gate>", "openhuman-tinyhumans/<gate>"]+//+// Nothing enforced those three lists, and they fail in both directions:+//+// - A gate REMOVED from the core and left in a layer is a hard cargo error+// ("package openhuman-cli depends on openhuman with feature peripheral-rpi+// but openhuman does not have that feature") — loud, but only once someone+// builds that crate, and it reads as a dependency problem rather than+// drift. That is #6360.+// - A gate ADDED to the core and forgotten by a layer fails SILENTLY. The+// product lanes pass `--features "$(scripts/ci/product-features.sh)"` to+// `openhuman-cli`, where the name still resolves, so CI stays green while+// the gate is off for every embedder.+//+// Same failure shape as #4901/#4918 one layer down, so it gets the same+// treatment: an explicit list, and an exclusion that must carry a reason.++/**+ * Core gates a layer deliberately does NOT carry, mapped to why.+ *+ * Keyed by the crate that omits the gate. Like `INTENTIONALLY_NOT_FORWARDED`,+ * the reason string is the whole point: it is what lets a reviewer tell+ * "excluded on purpose" from "forgotten" without going archaeology.+ */+export const CHAIN_GATES_NOT_FORWARDED = {+ 'openhuman-embed': {+ 'e2e-test-support':+ 'Exposes the destructive `openhuman.test_reset` RPC for the E2E build only. An embedder must never be able to turn a data wipe on.',+ fantoccini:+ 'Back-compat alias for `browser-native` in the core; the embed facade forwards the canonical name instead of both spellings.',+ landlock:+ 'Back-compat alias for `sandbox-landlock` in the core; the embed facade forwards the canonical name instead of both spellings.',+ 'rss-bench':+ 'Library-side hook for the embedded-RSS benchmark (#5046). Its binaries live in `openhuman-cli`, which forwards the gate directly.',+ },+};++/**+ * Gates a crate declares that belong to it alone, mapped to why.+ *+ * These have no twin upstream, so the chain check would otherwise read them as+ * a stale forward of a deleted core gate — the exact #6360 symptom it exists to+ * catch. An entry here says "this one is local by design".+ */+export const CHAIN_LOCAL_GATES = {+ 'openhuman-tinyhumans': {+ jev: 'This crate owns the gate: the Jev-backed `tool_search` ranker (`tinytools-jev` over the TinyHumans System One proxy).',+ },+ 'openhuman-cli': {+ 'bin-tools': 'CLI argument parsing + logger init for the `openhuman-fleet` binary.',+ 'rss-bench-dhat':+ 'dhat heap profiling for the `library-profile` binary; perturbs RSS, so it is opt-in and has no core twin.',+ },+};++/**+ * The `[features]` table of any manifest, as `name -> [items]`.+ *+ * Same scanner as `parseCoreFeatureGraph` (which now delegates here) — the+ * shape is not core-specific, and the chain check reads three more manifests+ * with it.+ */+export function parseFeatureTable(toml) {+ return parseCoreFeatureGraph(toml);+}++/**+ * Assertion 4: one link of the chain forwards its sources' gates.+ *+ * `sources` are the crates this one sits on top of:+ *+ * `{ crate, gates, required: true }` — every gate must be declared here and+ * must forward to `<crate>/<gate>`. That is core → embed, embed →+ * tinyhumans, core → cli.+ * `{ crate, gates, required: false }` — only gates this crate ALREADY+ * declares have to carry the forward. That is tinyhumans → cli: the cli+ * forwards to both parents, but only for the gates tinyhumans has, and a+ * core-only gate like `e2e-test-support` must not be demanded of it.+ *+ * A forward is checked by TARGET, not just by name: a gate declared as+ * `voice = ["openhuman-core/web3"]` is as broken as a missing one and looks+ * identical to a name-only check.+ */+export function diffChainForwarding({+ crate,+ features,+ sources,+ notForwarded = {},+ localGates = {},+}) {+ const declared = new Set([...features.keys()].filter(name => name !== 'default'));+ const missing = [];+ const misrouted = [];+ const allowed = [];+ for (const source of sources) {+ for (const gate of source.gates) {+ if (gate === 'default') continue;+ if (!declared.has(gate)) {+ // Only a required source can be missing from here: an optional source+ // (tinyhumans → cli) says nothing about gates this crate never took.+ if (!source.required) continue;+ if (Object.prototype.hasOwnProperty.call(notForwarded, gate)) allowed.push(gate);+ else missing.push({ gate, source: source.crate });+ continue;+ }+ const forward = `${source.crate}/${gate}`;+ if (!(features.get(gate) ?? []).includes(forward)) {+ misrouted.push({ gate, source: source.crate, expected: forward });+ }+ }+ }+ // A forward to a gate the crate below does not declare. This is the #6360+ // error verbatim — cargo refuses it — but it surfaces there as a dependency+ // resolution failure on whoever builds that crate first, with nothing naming+ // it as forwarding drift. Catching it here says what it is.+ const dangling = [];+ for (const gate of declared) {+ for (const item of features.get(gate) ?? []) {+ const slash = item.indexOf('/');+ if (slash === -1) continue;+ const source = sources.find(candidate => candidate.crate === item.slice(0, slash));+ if (!source) continue;+ const target = item.slice(slash + 1);+ if (!source.gates.includes(target)) dangling.push({ gate, item });+ }+ }+ const upstream = new Set(sources.flatMap(source => source.gates));+ // Declared here, in no source, and not claimed as local: either a gate the+ // core dropped (the #6360 shape) or a local gate nobody documented.+ const unknown = [...declared].filter(+ gate =>+ !upstream.has(gate) && !Object.prototype.hasOwnProperty.call(localGates, gate)+ );+ // A "local" gate an upstream crate now declares is no longer local, and the+ // entry would hide a genuinely missing forward for it.+ const staleLocal = Object.keys(localGates).filter(gate => upstream.has(gate));+ // Mirrors `diffForwarding`'s stale check: an exclusion for a gate that IS+ // carried here is wrong, and would mask the day it gets dropped.+ const staleExclusion = Object.keys(notForwarded).filter(gate => declared.has(gate));+ return {+ ok:+ missing.length === 0 &&+ misrouted.length === 0 &&+ dangling.length === 0 &&+ unknown.length === 0 &&+ staleLocal.length === 0 &&+ staleExclusion.length === 0,+ crate,+ missing,+ misrouted,+ dangling,+ unknown,+ staleLocal,+ staleExclusion,+ allowed,+ };+}++export function formatChainReport(result, { notForwarded = {} } = {}) {+ const lines = [`${result.crate}:`];+ for (const gate of result.allowed) {+ lines.push(` allowed: ${gate} — ${notForwarded[gate]}`);+ }+ if (result.missing.length > 0) {+ lines.push('', `Gates ${result.crate} does not forward:`);+ for (const { gate, source } of result.missing) lines.push(` - ${gate} (declared by ${source})`);+ lines.push(+ '',+ `Add \`${result.missing[0].gate} = ["${result.missing[0].source}/${result.missing[0].gate}"]\` to that crate's [features] table,`,+ 'or, if the omission is deliberate, add it to CHAIN_GATES_NOT_FORWARDED in',+ 'scripts/lib/feature-forwarding.mjs with a reason. A gate missing here is off',+ 'for every embedder while the CLI product lanes still resolve the name.'+ );+ }+ if (result.misrouted.length > 0) {+ lines.push('', `Gates ${result.crate} declares but does not forward to their source:`);+ for (const { gate, expected } of result.misrouted) lines.push(` - ${gate} (expected "${expected}")`);+ }+ if (result.dangling.length > 0) {+ lines.push('', `Forwards from ${result.crate} to a gate that no longer exists:`);+ for (const { gate, item } of result.dangling) lines.push(` - ${gate} -> "${item}"`);+ lines.push(+ '',+ 'cargo rejects this outright ("depends on <crate> with feature <gate> but',+ '<crate> does not have that feature"), but only for whoever builds that crate',+ 'first, and it reads as a dependency problem rather than forwarding drift (#6360).'+ );+ }+ if (result.unknown.length > 0) {+ lines.push('', `Gates ${result.crate} declares that no crate below it has:`);+ for (const gate of result.unknown) lines.push(` - ${gate}`);+ lines.push(+ '',+ 'Either the gate was removed from the core and this forward is stale (#6360:',+ 'a `cargo check` error, not a gate check), or it is local to this crate and',+ 'belongs in CHAIN_LOCAL_GATES with a reason.'+ );+ }+ if (result.staleLocal.length > 0) {+ lines.push('', 'Stale CHAIN_LOCAL_GATES entries (a crate below now declares the gate):');+ for (const gate of result.staleLocal) lines.push(` - ${gate}`);+ }+ if (result.staleExclusion.length > 0) {+ lines.push('', 'Stale CHAIN_GATES_NOT_FORWARDED entries (the gate IS forwarded):');+ for (const gate of result.staleExclusion) lines.push(` - ${gate}`);+ }+ if (result.ok) lines.push(` OK: forwards every gate of the crates below it.`);+ return lines.join('\n');+}