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(ci): check crate facades for wholesale re-exports
Steven Enamakel64647d11e7dc
diff --git a/scripts/ci/check-crate-chain.mjs b/scripts/ci/check-crate-chain.mjsindex b49590ffb7..e54fdb0954 100644--- a/scripts/ci/check-crate-chain.mjs+++ b/scripts/ci/check-crate-chain.mjs@@ -14,6 +14,15 @@// nothing else. So `__host`, `core_host` and `openhuman_core::` in// `crates/openhuman-{app,cli,tui}/src` fail the check.//+// A third check covers the facades. No layer re-exports the layer below+// wholesale (`pub use openhuman_embed as embed`, `pub use openhuman_tinyhumans+// as tinyhumans`, a glob, or `pub use …::embed;`): each one names the items it+// passes up, so `__host` cannot leak to a host through a re-exported crate.+// `__host` itself may be forwarded by tinyhumans (rpc's only route to it, doc+// hidden) and must be `pub(crate)` inside rpc; any `pub use` of `__host` or+// `core_host` in rpc, or a reach for either through `openhuman_rpc::` from a+// host, root test or example, fails.+//// Usage: check-crate-chain.mjs [repo-root]// Exit 0 when the chain holds, 1 on a violation, 2 when the inputs could not// be read or parsed (the check refuses to pass vacuously).@@ -53,6 +62,65 @@ export const FORBIDDEN_HOST_PATTERNS = [{ name: 'openhuman_core::', regex: /\bopenhuman_core::/ },];+/** Layer crates whose `src/` must not re-export the layer below wholesale. */+export const LAYER_SOURCE_DIRS = ['crates/openhuman-tinyhumans/src', 'crates/openhuman-rpc/src'];++/** Wholesale re-exports of a lower layer (matched across lines, comments stripped). */+export const WHOLESALE_REEXPORT_PATTERNS = [+ {+ name: 'pub use openhuman_embed as …',+ regex: /\bpub(?:\([^)]*\))?\s+use\s+openhuman_embed\s+as\b/,+ },+ {+ name: 'pub use openhuman_tinyhumans as …',+ regex: /\bpub(?:\([^)]*\))?\s+use\s+openhuman_tinyhumans\s+as\b/,+ },+ {+ name: 'pub use openhuman_embed::*',+ regex: /\bpub(?:\([^)]*\))?\s+use\s+openhuman_(?:embed|tinyhumans)(?:::embed)?::\*/,+ },+ {+ name: 'pub use openhuman_tinyhumans::embed (the crate, not a list)',+ regex: /\bpub(?:\([^)]*\))?\s+use\s+openhuman_tinyhumans::embed\s*(?:as\s+\w+\s*)?;/,+ },+];++/** `pub use` of the internal list from rpc (it may only be `pub(crate)`). */+export const RPC_INTERNAL_REEXPORT_PATTERNS = [+ {+ name: 'pub use … __host / core_host',+ regex: /\bpub\s+use\b[^;]*\b(?:__host|core_host)\b/,+ },+];++/** Hosts, root tests and examples must not reach the internal list through rpc. */+export const HOST_RPC_INTERNAL_PATTERNS = [+ {+ name: 'openhuman_rpc::…__host / core_host',+ regex: /\bopenhuman_rpc\s*::[^;]*\b(?:__host|core_host)\b/,+ },+];++/** Blank out Rust comments, keeping line structure. */+export function stripRustComments(text) {+ return text+ .replace(/\/\*[\s\S]*?\*\//g, m => m.replace(/[^\n]/g, ' '))+ .replace(/\/\/[^\n]*/g, '');+}++/** `{ file, line, pattern }` for each multi-line pattern match in one source text. */+export function findPatternHits(text, file, patterns) {+ const code = stripRustComments(text);+ const hits = [];+ for (const { name, regex } of patterns) {+ const global = new RegExp(regex.source, 'g');+ for (const m of code.matchAll(global)) {+ hits.push({ file, line: code.slice(0, m.index).split('\n').length, pattern: name });+ }+ }+ return hits;+}+/** Whether a package name belongs to this repository's OpenHuman crates. */export function isOpenhumanPackage(name) {return name === 'openhuman' || name.startsWith('openhuman-');@@ -239,10 +307,33 @@ export function checkRepository(root) {);}}- return { checked, edgeViolations, sourceViolations };+ const facadeViolations = [];+ for (const dir of LAYER_SOURCE_DIRS) {+ const abs = join(root, dir);+ if (!existsSync(abs)) throw new Error(`missing layer source directory ${dir}`);+ const patterns = dir.includes('openhuman-rpc')+ ? [...WHOLESALE_REEXPORT_PATTERNS, ...RPC_INTERNAL_REEXPORT_PATTERNS]+ : WHOLESALE_REEXPORT_PATTERNS;+ for (const file of rustFiles(abs)) {+ facadeViolations.push(+ ...findPatternHits(readFileSync(file, 'utf8'), relative(root, file), patterns)+ );+ }+ }+ const reachDirs = [...HOST_SOURCE_DIRS, 'tests', 'examples', ...HOST_SOURCE_DIRS.map(d => d.replace(/src$/, 'tests'))];+ for (const dir of reachDirs) {+ const abs = join(root, dir);+ if (!existsSync(abs)) continue;+ for (const file of rustFiles(abs)) {+ facadeViolations.push(+ ...findPatternHits(readFileSync(file, 'utf8'), relative(root, file), HOST_RPC_INTERNAL_PATTERNS)+ );+ }+ }+ return { checked, edgeViolations, sourceViolations, facadeViolations };}-export function formatReport({ checked, edgeViolations, sourceViolations }) {+export function formatReport({ checked, edgeViolations, sourceViolations, facadeViolations = [] }) {const lines = [`Crate chain: core -> embed -> tinyhumans -> rpc -> app/cli/tui`];lines.push(`Checked ${checked.length} manifests: ${checked.join(', ')}`);if (edgeViolations.length > 0) {@@ -267,7 +358,16 @@ export function formatReport({ checked, edgeViolations, sourceViolations }) {"embed's public facade instead.");}- if (edgeViolations.length === 0 && sourceViolations.length === 0) {+ if (facadeViolations.length > 0) {+ lines.push('', 'Facades that re-export a lower layer wholesale or leak `__host`:');+ for (const v of facadeViolations) lines.push(` - ${v.file}:${v.line}: ${v.pattern}`);+ lines.push(+ '',+ 'Each layer re-exports a curated `pub use` list of the items the layers above',+ 'use, never the crate below it. `__host` stays out of every public path in rpc.'+ );+ }+ if (edgeViolations.length === 0 && sourceViolations.length === 0 && facadeViolations.length === 0) {lines.push('OK: every crate depends only on the layer below it.');}return lines.join('\n');@@ -283,7 +383,10 @@ function main() {process.exit(2);}const report = formatReport(result);- const ok = result.edgeViolations.length === 0 && result.sourceViolations.length === 0;+ const ok =+ result.edgeViolations.length === 0 &&+ result.sourceViolations.length === 0 &&+ result.facadeViolations.length === 0;(ok ? console.log : console.error)(report);process.exit(ok ? 0 : 1);}