Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

style: reformat crate chain checker and tests to double quotes

Steven Enamakel799011d5672c
diff --git a/scripts/__tests__/check-crate-chain.test.mjs b/scripts/__tests__/check-crate-chain.test.mjs
index 297469d4c1..d97125cc41 100644
--- a/scripts/__tests__/check-crate-chain.test.mjs
+++ b/scripts/__tests__/check-crate-chain.test.mjs
@@ -1,10 +1,10 @@
-import assert from "node:assert/strict";
-import { spawnSync } from "node:child_process";
-import { mkdirSync, mkdtempSync, 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 assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, 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,
@@ -20,27 +20,24 @@ import {
parsePackageName,
parseWorkspaceDependencies,
parseWorkspaceMembers,
-} from "../ci/check-crate-chain.mjs";
+} from '../ci/check-crate-chain.mjs';
-const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
-const CHECKER = resolve(REPO_ROOT, "scripts/ci/check-crate-chain.mjs");
+const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
+const CHECKER = resolve(REPO_ROOT, 'scripts/ci/check-crate-chain.mjs');
// ── parsing ────────────────────────────────────────────────────────────────
-test("reads the package name and workspace members", () => {
- assert.equal(
- parsePackageName('[package]\nname = "openhuman-tui" # the TUI\n'),
- "openhuman-tui",
- );
+test('reads the package name and workspace members', () => {
+ assert.equal(parsePackageName('[package]\nname = "openhuman-tui" # the TUI\n'), 'openhuman-tui');
assert.deepEqual(
parseWorkspaceMembers(
- '[workspace]\nmembers = [\n "crates/a",\n # "crates/old",\n "crates/b",\n]\n',
+ '[workspace]\nmembers = [\n "crates/a",\n # "crates/old",\n "crates/b",\n]\n'
),
- ["crates/a", "crates/b"],
+ ['crates/a', 'crates/b']
);
});
-test("normal dependencies include target tables and sub-tables, not dev/build ones", () => {
+test('normal dependencies include target tables and sub-tables, not dev/build ones', () => {
const deps = parseNormalDependencies(`
[package]
name = "openhuman-cli"
@@ -65,257 +62,208 @@ openhuman-core = { path = "../openhuman-core", package = "openhuman" }
openhuman-tui = { path = "../openhuman-tui" }
`);
assert.deepEqual(
- deps.map((d) => d.package),
- [
- "openhuman-rpc",
- "openhuman",
- "serde",
- "openhuman-embed",
- "openhuman-tinyhumans",
- ],
+ deps.map(d => d.package),
+ ['openhuman-rpc', 'openhuman', 'serde', 'openhuman-embed', 'openhuman-tinyhumans']
);
assert.equal(deps[0].workspace, true);
});
-test("a commented-out dependency is not an edge", () => {
+test('a commented-out dependency is not an edge', () => {
const deps = parseNormalDependencies(
- '[dependencies]\n# openhuman-core = { path = "x" }\nlog = "0.4"\n',
+ '[dependencies]\n# openhuman-core = { path = "x" }\nlog = "0.4"\n'
);
assert.deepEqual(
- deps.map((d) => d.key),
- ["log"],
+ deps.map(d => d.key),
+ ['log']
);
});
-test("workspace dependencies resolve their package rename", () => {
+test('workspace dependencies resolve their package rename', () => {
const ws = parseWorkspaceDependencies(`
[workspace.dependencies]
openhuman-core = { path = "crates/openhuman-core", package = "openhuman" }
openhuman-rpc = { path = "crates/openhuman-rpc", default-features = false }
`);
- assert.equal(ws.get("openhuman-core"), "openhuman");
- assert.equal(ws.get("openhuman-rpc"), "openhuman-rpc");
+ assert.equal(ws.get('openhuman-core'), 'openhuman');
+ assert.equal(ws.get('openhuman-rpc'), 'openhuman-rpc');
});
// ── the chain ──────────────────────────────────────────────────────────────
-test("each layer may name only the layer directly below it", () => {
- assert.deepEqual(CHAIN["openhuman-embed"], ["openhuman"]);
- assert.deepEqual(CHAIN["openhuman-cli"], ["openhuman-rpc"]);
+test('each layer may name only the layer directly below it', () => {
+ assert.deepEqual(CHAIN['openhuman-embed'], ['openhuman']);
+ assert.deepEqual(CHAIN['openhuman-cli'], ['openhuman-rpc']);
assert.deepEqual(
checkManifestEdges({
- crate: "openhuman-tui",
- deps: [
- { key: "openhuman-rpc", package: "openhuman-rpc", workspace: false },
- ],
+ crate: 'openhuman-tui',
+ deps: [{ key: 'openhuman-rpc', package: 'openhuman-rpc', workspace: false }],
}),
- [],
+ []
);
});
-test("a host depending on the core is a violation, even through a workspace alias", () => {
- const workspaceDeps = new Map([["openhuman-core", "openhuman"]]);
+test('a host depending on the core is a violation, even through a workspace alias', () => {
+ const workspaceDeps = new Map([['openhuman-core', 'openhuman']]);
const violations = checkManifestEdges({
- crate: "openhuman-tui",
+ crate: 'openhuman-tui',
deps: [
- { key: "openhuman-rpc", package: "openhuman-rpc", workspace: true },
- { key: "openhuman-core", package: "openhuman-core", workspace: true },
- {
- key: "openhuman-tinyhumans",
- package: "openhuman-tinyhumans",
- workspace: false,
- },
+ { key: 'openhuman-rpc', package: 'openhuman-rpc', workspace: true },
+ { key: 'openhuman-core', package: 'openhuman-core', workspace: true },
+ { key: 'openhuman-tinyhumans', package: 'openhuman-tinyhumans', workspace: false },
],
workspaceDeps,
});
assert.deepEqual(
- violations.map((v) => v.dependency),
- ["openhuman", "openhuman-tinyhumans"],
+ violations.map(v => v.dependency),
+ ['openhuman', 'openhuman-tinyhumans']
);
});
-test("the core may not depend on any OpenHuman crate", () => {
+test('the core may not depend on any OpenHuman crate', () => {
const [violation] = checkManifestEdges({
- crate: "openhuman",
- deps: [
- { key: "openhuman-rpc", package: "openhuman-rpc", workspace: false },
- ],
+ crate: 'openhuman',
+ deps: [{ key: 'openhuman-rpc', package: 'openhuman-rpc', workspace: false }],
});
assert.match(violation.reason, /may not depend on any OpenHuman crate/);
});
-test("an unknown OpenHuman crate fails until it is placed in the chain", () => {
- const [violation] = checkManifestEdges({ crate: "openhuman-new", deps: [] });
+test('an unknown OpenHuman crate fails until it is placed in the chain', () => {
+ const [violation] = checkManifestEdges({ crate: 'openhuman-new', deps: [] });
assert.match(violation.reason, /unknown OpenHuman crate/);
});
-test("host source naming core internals by path is flagged, with file and line", () => {
+test('host source naming core internals by path is flagged, with file and line', () => {
const hits = findForbiddenPaths(
- "use openhuman_rpc::embed::config;\nlet x = openhuman_core::config::Config::default();\nuse crate::core_host::agent;\nuse openhuman_embed::__host::core;\n",
- "src/lib.rs",
+ 'use openhuman_rpc::embed::config;\nlet x = openhuman_core::config::Config::default();\nuse crate::core_host::agent;\nuse openhuman_embed::__host::core;\n',
+ 'src/lib.rs'
);
assert.deepEqual(
- hits.map((h) => `${h.line}:${h.pattern}`),
- ["2:openhuman_core::", "3:core_host", "4:__host"],
+ hits.map(h => `${h.line}:${h.pattern}`),
+ ['2:openhuman_core::', '3:core_host', '4:__host']
);
});
-test("a test name that merely contains openhuman_core is not a path", () => {
+test('a test name that merely contains openhuman_core is not a path', () => {
assert.deepEqual(
- findForbiddenPaths(
- "fn binary_path_result_contains_openhuman_core() {}",
- "x.rs",
- ),
- [],
+ findForbiddenPaths('fn binary_path_result_contains_openhuman_core() {}', 'x.rs'),
+ []
);
});
-test("a layer re-exporting the layer below wholesale is flagged", () => {
- const flagged = (text) =>
- findPatternHits(text, "lib.rs", WHOLESALE_REEXPORT_PATTERNS).map(
- (h) => h.pattern,
- );
- assert.deepEqual(flagged("pub use openhuman_embed as embed;\n"), [
- "pub use openhuman_embed as …",
- ]);
- assert.deepEqual(flagged("pub use openhuman_tinyhumans as tinyhumans;\n"), [
- "pub use openhuman_tinyhumans as …",
+test('a layer re-exporting the layer below wholesale is flagged', () => {
+ const flagged = text =>
+ findPatternHits(text, 'lib.rs', WHOLESALE_REEXPORT_PATTERNS).map(h => h.pattern);
+ assert.deepEqual(flagged('pub use openhuman_embed as embed;\n'), [
+ 'pub use openhuman_embed as …',
]);
- assert.deepEqual(flagged("pub use openhuman_tinyhumans::embed;\n"), [
- "pub use openhuman_tinyhumans::embed (the crate, not a list)",
+ assert.deepEqual(flagged('pub use openhuman_tinyhumans as tinyhumans;\n'), [
+ 'pub use openhuman_tinyhumans as …',
]);
- assert.deepEqual(flagged("pub use openhuman_embed::*;\n"), [
- "pub use openhuman_embed::*",
+ assert.deepEqual(flagged('pub use openhuman_tinyhumans::embed;\n'), [
+ 'pub use openhuman_tinyhumans::embed (the crate, not a list)',
]);
+ assert.deepEqual(flagged('pub use openhuman_embed::*;\n'), ['pub use openhuman_embed::*']);
// Curated lists, private aliases and comments are fine.
- assert.deepEqual(
- flagged("pub use openhuman_embed::{Runtime, RuntimeBuilder};\n"),
- [],
- );
- assert.deepEqual(flagged("use openhuman_embed as embed;\n"), []);
- assert.deepEqual(flagged("// pub use openhuman_embed as embed;\n"), []);
- assert.deepEqual(flagged("/* pub use openhuman_embed::*; */\n"), []);
+ assert.deepEqual(flagged('pub use openhuman_embed::{Runtime, RuntimeBuilder};\n'), []);
+ assert.deepEqual(flagged('use openhuman_embed as embed;\n'), []);
+ assert.deepEqual(flagged('// pub use openhuman_embed as embed;\n'), []);
+ assert.deepEqual(flagged('/* pub use openhuman_embed::*; */\n'), []);
});
-test("rpc may not re-export the internal list on a public path", () => {
- const flagged = (text) =>
- findPatternHits(text, "lib.rs", RPC_INTERNAL_REEXPORT_PATTERNS).map(
- (h) => `${h.line}`,
- );
- assert.deepEqual(
- flagged("pub use openhuman_tinyhumans::__host as core_host;\n"),
- ["1"],
- );
+test('rpc may not re-export the internal list on a public path', () => {
+ const flagged = text =>
+ findPatternHits(text, 'lib.rs', RPC_INTERNAL_REEXPORT_PATTERNS).map(h => `${h.line}`);
+ assert.deepEqual(flagged('pub use openhuman_tinyhumans::__host as core_host;\n'), ['1']);
assert.deepEqual(
flagged(
- "pub mod embed {\n pub use openhuman_tinyhumans::embed::{\n config,\n __host,\n };\n}\n",
+ 'pub mod embed {\n pub use openhuman_tinyhumans::embed::{\n config,\n __host,\n };\n}\n'
),
- ["2"],
- );
- assert.deepEqual(
- flagged("pub(crate) use openhuman_tinyhumans::__host as core_host;\n"),
- [],
+ ['2']
);
+ assert.deepEqual(flagged('pub(crate) use openhuman_tinyhumans::__host as core_host;\n'), []);
});
-test("a host reaching the internal list through openhuman_rpc is flagged", () => {
- const flagged = (text) =>
- findPatternHits(text, "main.rs", HOST_RPC_INTERNAL_PATTERNS).map(
- (h) => `${h.line}`,
- );
- assert.deepEqual(flagged("use openhuman_rpc::embed::__host::config;\n"), [
- "1",
+test('a host reaching the internal list through openhuman_rpc is flagged', () => {
+ const flagged = text =>
+ findPatternHits(text, 'main.rs', HOST_RPC_INTERNAL_PATTERNS).map(h => `${h.line}`);
+ assert.deepEqual(flagged('use openhuman_rpc::embed::__host::config;\n'), ['1']);
+ assert.deepEqual(flagged('use openhuman_rpc::{\n embed::config,\n core_host,\n};\n'), [
+ '1',
]);
- assert.deepEqual(
- flagged("use openhuman_rpc::{\n embed::config,\n core_host,\n};\n"),
- ["1"],
- );
- assert.deepEqual(flagged("use openhuman_rpc::embed::config;\n"), []);
+ assert.deepEqual(flagged('use openhuman_rpc::embed::config;\n'), []);
});
// ── the real repository ────────────────────────────────────────────────────
-test("the checked-in manifests and host sources hold the chain", () => {
+test('the checked-in manifests and host sources hold the chain', () => {
const result = checkRepository(REPO_ROOT);
+ assert.ok(result.checked.length >= 7, `checked only ${result.checked.join(', ')}`);
assert.ok(
- result.checked.length >= 7,
- `checked only ${result.checked.join(", ")}`,
- );
- assert.ok(
- result.checked.includes("openhuman-app"),
- "the desktop shell is outside the workspace and must still be checked",
+ result.checked.includes('openhuman-app'),
+ 'the desktop shell is outside the workspace and must still be checked'
);
assert.deepEqual(result.edgeViolations, [], formatReport(result));
assert.deepEqual(result.sourceViolations, [], formatReport(result));
assert.deepEqual(result.facadeViolations, [], formatReport(result));
});
-test("the CLI exits 1 and names the edge when a host reaches past rpc", () => {
- const dir = mkdtempSync(join(tmpdir(), "crate-chain-"));
+test('the CLI exits 1 and names the edge when a host reaches past rpc', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'crate-chain-'));
try {
writeFileSync(
- join(dir, "Cargo.toml"),
- '[workspace]\nmembers = ["crates/openhuman-core", "crates/openhuman-tui"]\n',
+ join(dir, 'Cargo.toml'),
+ '[workspace]\nmembers = ["crates/openhuman-core", "crates/openhuman-tui"]\n'
);
const crate = (name, toml) => {
- mkdirSync(join(dir, "crates", name, "src"), { recursive: true });
- writeFileSync(join(dir, "crates", name, "Cargo.toml"), toml);
+ mkdirSync(join(dir, 'crates', name, 'src'), { recursive: true });
+ writeFileSync(join(dir, 'crates', name, 'Cargo.toml'), toml);
};
- crate("openhuman-core", '[package]\nname = "openhuman"\n');
+ crate('openhuman-core', '[package]\nname = "openhuman"\n');
crate(
- "openhuman-tui",
- '[package]\nname = "openhuman-tui"\n[dependencies]\nopenhuman-core = { path = "../openhuman-core", package = "openhuman" }\n',
+ 'openhuman-tui',
+ '[package]\nname = "openhuman-tui"\n[dependencies]\nopenhuman-core = { path = "../openhuman-core", package = "openhuman" }\n'
);
crate(
- "openhuman-app",
- '[package]\nname = "openhuman-app"\n[dependencies]\nopenhuman-rpc = { path = "../openhuman-rpc" }\n',
+ 'openhuman-app',
+ '[package]\nname = "openhuman-app"\n[dependencies]\nopenhuman-rpc = { path = "../openhuman-rpc" }\n'
);
- crate("openhuman-cli", '[package]\nname = "openhuman-cli"\n');
+ crate('openhuman-cli', '[package]\nname = "openhuman-cli"\n');
writeFileSync(
- join(dir, "crates/openhuman-cli/src/main.rs"),
- "fn main() { openhuman_core::run(); }\n",
+ join(dir, 'crates/openhuman-cli/src/main.rs'),
+ 'fn main() { openhuman_core::run(); }\n'
);
- for (const layer of ["openhuman-tinyhumans", "openhuman-rpc"]) {
- mkdirSync(join(dir, "crates", layer, "src"), { recursive: true });
+ for (const layer of ['openhuman-tinyhumans', 'openhuman-rpc']) {
+ mkdirSync(join(dir, 'crates', layer, 'src'), { recursive: true });
}
writeFileSync(
- join(dir, "crates/openhuman-rpc/src/lib.rs"),
- "pub use openhuman_tinyhumans as tinyhumans;\n",
+ join(dir, 'crates/openhuman-rpc/src/lib.rs'),
+ 'pub use openhuman_tinyhumans as tinyhumans;\n'
);
- const result = spawnSync("node", [CHECKER, dir], { encoding: "utf8" });
+ const result = spawnSync('node', [CHECKER, dir], { encoding: 'utf8' });
assert.equal(result.status, 1, result.stdout + result.stderr);
+ assert.match(result.stderr, /openhuman-tui -> openhuman: may only depend on openhuman-rpc/);
+ assert.match(result.stderr, /crates\/openhuman-cli\/src\/main\.rs:1: openhuman_core::/);
assert.match(
result.stderr,
- /openhuman-tui -> openhuman: may only depend on openhuman-rpc/,
- );
- assert.match(
- result.stderr,
- /crates\/openhuman-cli\/src\/main\.rs:1: openhuman_core::/,
- );
- assert.match(
- result.stderr,
- /crates\/openhuman-rpc\/src\/lib\.rs:1: pub use openhuman_tinyhumans as/,
+ /crates\/openhuman-rpc\/src\/lib\.rs:1: pub use openhuman_tinyhumans as/
);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
-test("the CLI exits 2 instead of passing when it cannot read the repository", () => {
- const dir = mkdtempSync(join(tmpdir(), "crate-chain-empty-"));
+test('the CLI exits 2 instead of passing when it cannot read the repository', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'crate-chain-empty-'));
try {
- const result = spawnSync("node", [CHECKER, dir], { encoding: "utf8" });
+ const result = spawnSync('node', [CHECKER, dir], { encoding: 'utf8' });
assert.equal(result.status, 2, result.stdout + result.stderr);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
-test("the real repository passes through the CLI", () => {
- const result = spawnSync("node", [CHECKER], { encoding: "utf8" });
+test('the real repository passes through the CLI', () => {
+ const result = spawnSync('node', [CHECKER], { encoding: 'utf8' });
assert.equal(result.status, 0, result.stdout + result.stderr);
- assert.match(
- result.stdout,
- /OK: every crate depends only on the layer below it/,
- );
+ assert.match(result.stdout, /OK: every crate depends only on the layer below it/);
});
diff --git a/scripts/ci/check-crate-chain.mjs b/scripts/ci/check-crate-chain.mjs
index a0beda772d..8d71e9d8a4 100644
--- a/scripts/ci/check-crate-chain.mjs
+++ b/scripts/ci/check-crate-chain.mjs
@@ -27,11 +27,11 @@
// 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).
-import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
-import { dirname, join, relative, resolve } from "node:path";
-import { fileURLToPath, pathToFileURL } from "node:url";
+import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
+import { dirname, join, relative, resolve } from 'node:path';
+import { fileURLToPath, pathToFileURL } from 'node:url';
-import { stripComments } from "../lib/feature-forwarding.mjs";
+import { stripComments } from '../lib/feature-forwarding.mjs';
/**
* Package name -> the OpenHuman packages it may name as normal dependencies.
@@ -40,68 +40,60 @@ import { stripComments } from "../lib/feature-forwarding.mjs";
*/
export const CHAIN = {
openhuman: [],
- "openhuman-embed": ["openhuman"],
- "openhuman-tinyhumans": ["openhuman-embed"],
- "openhuman-rpc": ["openhuman-tinyhumans"],
- "openhuman-app": ["openhuman-rpc"],
- "openhuman-cli": ["openhuman-rpc"],
- "openhuman-tui": ["openhuman-rpc"],
+ 'openhuman-embed': ['openhuman'],
+ 'openhuman-tinyhumans': ['openhuman-embed'],
+ 'openhuman-rpc': ['openhuman-tinyhumans'],
+ 'openhuman-app': ['openhuman-rpc'],
+ 'openhuman-cli': ['openhuman-rpc'],
+ 'openhuman-tui': ['openhuman-rpc'],
};
/** The host crates whose `src/` must not reach core internals by path. */
export const HOST_SOURCE_DIRS = [
- "crates/openhuman-app/src",
- "crates/openhuman-cli/src",
- "crates/openhuman-tui/src",
+ 'crates/openhuman-app/src',
+ 'crates/openhuman-cli/src',
+ 'crates/openhuman-tui/src',
];
/** Paths a host must never name (see the header). */
export const FORBIDDEN_HOST_PATTERNS = [
- { name: "__host", regex: /\b__host\b/ },
- { name: "core_host", regex: /\bcore_host\b/ },
- { name: "openhuman_core::", regex: /\bopenhuman_core::/ },
+ { name: '__host', regex: /\b__host\b/ },
+ { name: 'core_host', regex: /\bcore_host\b/ },
+ { 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",
-];
+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 …",
+ name: 'pub use openhuman_embed as …',
regex: /\bpub(?:\([^)]*\))?\s+use\s+openhuman_embed\s+as\b/,
},
{
- name: "pub use openhuman_tinyhumans as …",
+ 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_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*)?;/,
+ 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/,
- },
+ { 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",
+ name: 'openhuman_rpc::…__host / core_host',
regex: /\bopenhuman_rpc\s*::[^;]*\b(?:__host|core_host)\b/,
},
];
@@ -109,8 +101,8 @@ export const HOST_RPC_INTERNAL_PATTERNS = [
/** 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, "");
+ .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. */
@@ -118,13 +110,9 @@ 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");
+ 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,
- });
+ hits.push({ file, line: code.slice(0, m.index).split('\n').length, pattern: name });
}
}
return hits;
@@ -132,7 +120,7 @@ export function findPatternHits(text, file, patterns) {
/** Whether a package name belongs to this repository's OpenHuman crates. */
export function isOpenhumanPackage(name) {
- return name === "openhuman" || name.startsWith("openhuman-");
+ return name === 'openhuman' || name.startsWith('openhuman-');
}
function tableBody(text, start) {
@@ -159,23 +147,21 @@ export function parseWorkspaceMembers(toml) {
const body = tableBody(text, header.index + header[0].length);
const at = body.search(/^[ \t]*members[ \t]*=[ \t]*\[/m);
if (at === -1) return [];
- const open = body.indexOf("[", at);
- const close = body.indexOf("]", open);
- return [...body.slice(open + 1, close).matchAll(/"([^"]+)"/g)].map(
- (m) => m[1],
- );
+ const open = body.indexOf('[', at);
+ const close = body.indexOf(']', open);
+ return [...body.slice(open + 1, close).matchAll(/"([^"]+)"/g)].map(m => m[1]);
}
/** One dependency entry's value text (inline table or string), joined across lines. */
function entryValue(body, valueStart) {
- if (body[valueStart] !== "{") {
- const end = body.indexOf("\n", valueStart);
+ if (body[valueStart] !== '{') {
+ const end = body.indexOf('\n', valueStart);
return end === -1 ? body.slice(valueStart) : body.slice(valueStart, end);
}
let depth = 0;
for (let i = valueStart; i < body.length; i++) {
- if (body[i] === "{") depth++;
- else if (body[i] === "}") {
+ if (body[i] === '{') depth++;
+ else if (body[i] === '}') {
depth--;
if (depth === 0) return body.slice(valueStart, i + 1);
}
@@ -192,14 +178,11 @@ function entryValue(body, valueStart) {
*/
export function parseDependencyEntries(body) {
const entries = [];
- for (const match of body.matchAll(
- /^[ \t]*([A-Za-z0-9_-]+)((?:\.workspace)?)[ \t]*=[ \t]*/gm,
- )) {
+ for (const match of body.matchAll(/^[ \t]*([A-Za-z0-9_-]+)((?:\.workspace)?)[ \t]*=[ \t]*/gm)) {
const key = match[1];
const value = entryValue(body, match.index + match[0].length);
const pkg = value.match(/package[ \t]*=[ \t]*"([^"]+)"/);
- const workspace =
- match[2] === ".workspace" || /workspace[ \t]*=[ \t]*true/.test(value);
+ const workspace = match[2] === '.workspace' || /workspace[ \t]*=[ \t]*true/.test(value);
entries.push({ key, package: pkg ? pkg[1] : key, workspace });
}
return entries;
@@ -216,13 +199,11 @@ export function parseNormalDependencies(toml) {
for (const header of text.matchAll(/^[ \t]*\[([^\]\n]+)\][ \t]*$/gm)) {
const table = header[1].trim();
const body = tableBody(text, header.index + header[0].length);
- if (table === "dependencies" || /^target\..+\.dependencies$/.test(table)) {
+ if (table === 'dependencies' || /^target\..+\.dependencies$/.test(table)) {
deps.push(...parseDependencyEntries(body));
continue;
}
- const sub = table.match(
- /^(?:target\..+\.)?dependencies\.([A-Za-z0-9_-]+)$/,
- );
+ const sub = table.match(/^(?:target\..+\.)?dependencies\.([A-Za-z0-9_-]+)$/);
if (sub) {
const pkg = body.match(/^[ \t]*package[ \t]*=[ \t]*"([^"]+)"/m);
const workspace = /^[ \t]*workspace[ \t]*=[ \t]*true/m.test(body);
@@ -238,43 +219,34 @@ export function parseWorkspaceDependencies(toml) {
const header = text.match(/^[ \t]*\[workspace\.dependencies\][ \t]*$/m);
if (!header) return new Map();
const body = tableBody(text, header.index + header[0].length);
- return new Map(
- parseDependencyEntries(body).map((entry) => [entry.key, entry.package]),
- );
+ return new Map(parseDependencyEntries(body).map(entry => [entry.key, entry.package]));
}
/**
* Violations of {@link CHAIN} for one manifest. Each is
* `{ crate, dependency, reason }`.
*/
-export function checkManifestEdges({
- crate,
- deps,
- workspaceDeps = new Map(),
- chain = CHAIN,
-}) {
+export function checkManifestEdges({ crate, deps, workspaceDeps = new Map(), chain = CHAIN }) {
const violations = [];
if (!Object.prototype.hasOwnProperty.call(chain, crate)) {
violations.push({
crate,
dependency: null,
- reason: "unknown OpenHuman crate: add it to CHAIN",
+ reason: 'unknown OpenHuman crate: add it to CHAIN',
});
return violations;
}
const allowed = new Set(chain[crate]);
for (const dep of deps) {
- const pkg = dep.workspace
- ? (workspaceDeps.get(dep.key) ?? dep.package)
- : dep.package;
+ const pkg = dep.workspace ? (workspaceDeps.get(dep.key) ?? dep.package) : dep.package;
if (!isOpenhumanPackage(pkg)) continue;
if (!allowed.has(pkg)) {
violations.push({
crate,
dependency: pkg,
reason: allowed.size
- ? `may only depend on ${[...allowed].join(", ")} among OpenHuman crates`
- : "may not depend on any OpenHuman crate",
+ ? `may only depend on ${[...allowed].join(', ')} among OpenHuman crates`
+ : 'may not depend on any OpenHuman crate',
});
}
}
@@ -282,11 +254,7 @@ export function checkManifestEdges({
}
/** `{ file, line, pattern }` for every forbidden path in one source text. */
-export function findForbiddenPaths(
- text,
- file,
- patterns = FORBIDDEN_HOST_PATTERNS,
-) {
+export function findForbiddenPaths(text, file, patterns = FORBIDDEN_HOST_PATTERNS) {
const hits = [];
text.split(/\r?\n/).forEach((line, index) => {
for (const { name, regex } of patterns) {
@@ -301,75 +269,63 @@ function rustFiles(dir) {
for (const entry of readdirSync(dir)) {
const path = join(dir, entry);
if (statSync(path).isDirectory()) out.push(...rustFiles(path));
- else if (entry.endsWith(".rs")) out.push(path);
+ else if (entry.endsWith('.rs')) out.push(path);
}
return out;
}
/** Run both checks against a repository checkout. */
export function checkRepository(root) {
- const rootToml = readFileSync(join(root, "Cargo.toml"), "utf8");
+ const rootToml = readFileSync(join(root, 'Cargo.toml'), 'utf8');
const members = parseWorkspaceMembers(rootToml);
if (members.length === 0) {
- throw new Error("parsed zero workspace members from the root Cargo.toml");
+ throw new Error('parsed zero workspace members from the root Cargo.toml');
}
const workspaceDeps = parseWorkspaceDependencies(rootToml);
// The desktop shell is its own Cargo world, excluded from the workspace.
- const manifestDirs = [...members, "crates/openhuman-app"];
+ const manifestDirs = [...members, 'crates/openhuman-app'];
const edgeViolations = [];
const checked = [];
for (const dir of manifestDirs) {
- const manifest = join(root, dir, "Cargo.toml");
- if (!existsSync(manifest))
- throw new Error(`missing manifest ${relative(root, manifest)}`);
- const toml = readFileSync(manifest, "utf8");
+ const manifest = join(root, dir, 'Cargo.toml');
+ if (!existsSync(manifest)) throw new Error(`missing manifest ${relative(root, manifest)}`);
+ const toml = readFileSync(manifest, 'utf8');
const crate = parsePackageName(toml);
- if (!crate)
- throw new Error(`no [package] name in ${relative(root, manifest)}`);
+ if (!crate) throw new Error(`no [package] name in ${relative(root, manifest)}`);
if (!isOpenhumanPackage(crate)) continue;
checked.push(crate);
edgeViolations.push(
- ...checkManifestEdges({
- crate,
- deps: parseNormalDependencies(toml),
- workspaceDeps,
- }),
+ ...checkManifestEdges({ crate, deps: parseNormalDependencies(toml), workspaceDeps })
);
}
const sourceViolations = [];
for (const dir of HOST_SOURCE_DIRS) {
const abs = join(root, dir);
- if (!existsSync(abs))
- throw new Error(`missing host source directory ${dir}`);
+ if (!existsSync(abs)) throw new Error(`missing host source directory ${dir}`);
for (const file of rustFiles(abs)) {
sourceViolations.push(
- ...findForbiddenPaths(readFileSync(file, "utf8"), relative(root, file)),
+ ...findForbiddenPaths(readFileSync(file, 'utf8'), relative(root, file))
);
}
}
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")
+ 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,
- ),
+ ...findPatternHits(readFileSync(file, 'utf8'), relative(root, file), patterns)
);
}
}
const reachDirs = [
...HOST_SOURCE_DIRS,
- "tests",
- "examples",
- ...HOST_SOURCE_DIRS.map((d) => d.replace(/src$/, "tests")),
+ 'tests',
+ 'examples',
+ ...HOST_SOURCE_DIRS.map(d => d.replace(/src$/, 'tests')),
];
for (const dir of reachDirs) {
const abs = join(root, dir);
@@ -377,60 +333,48 @@ export function checkRepository(root) {
for (const file of rustFiles(abs)) {
facadeViolations.push(
...findPatternHits(
- readFileSync(file, "utf8"),
+ readFileSync(file, 'utf8'),
relative(root, file),
- HOST_RPC_INTERNAL_PATTERNS,
- ),
+ HOST_RPC_INTERNAL_PATTERNS
+ )
);
}
}
return { checked, edgeViolations, sourceViolations, facadeViolations };
}
-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(", ")}`);
+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) {
- lines.push("", "Normal-dependency edges that break the chain:");
+ lines.push('', 'Normal-dependency edges that break the chain:');
for (const v of edgeViolations) {
- lines.push(` - ${v.crate} -> ${v.dependency ?? "?"}: ${v.reason}`);
+ lines.push(` - ${v.crate} -> ${v.dependency ?? '?'}: ${v.reason}`);
}
lines.push(
- "",
- "Reach the layer below through its curated facade instead. Hosts name",
- "`openhuman-rpc` only (`openhuman_rpc::embed`, `openhuman_rpc::tinyhumans`);",
- "a test-only need belongs in [dev-dependencies].",
+ '',
+ 'Reach the layer below through its curated facade instead. Hosts name',
+ '`openhuman-rpc` only (`openhuman_rpc::embed`, `openhuman_rpc::tinyhumans`);',
+ 'a test-only need belongs in [dev-dependencies].'
);
}
if (sourceViolations.length > 0) {
- lines.push("", "Host source reaching core internals by path:");
- for (const v of sourceViolations)
- lines.push(` - ${v.file}:${v.line}: ${v.pattern}`);
+ lines.push('', 'Host source reaching core internals by path:');
+ for (const v of sourceViolations) lines.push(` - ${v.file}:${v.line}: ${v.pattern}`);
lines.push(
- "",
- "Hosts use the curated facade (`openhuman_rpc::embed::…`). `__host` /",
- "`core_host` are internal to the library layers; add what the host needs to",
- "embed's public facade instead.",
+ '',
+ 'Hosts use the curated facade (`openhuman_rpc::embed::…`). `__host` /',
+ '`core_host` are internal to the library layers; add what the host needs to',
+ "embed's public facade instead."
);
}
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(
- "",
- "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.",
+ '',
+ '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 (
@@ -438,15 +382,14 @@ export function formatReport({
sourceViolations.length === 0 &&
facadeViolations.length === 0
) {
- lines.push("OK: every crate depends only on the layer below it.");
+ lines.push('OK: every crate depends only on the layer below it.');
}
- return lines.join("\n");
+ return lines.join('\n');
}
function main() {
const root = resolve(
- process.argv[2] ??
- resolve(dirname(fileURLToPath(import.meta.url)), "../.."),
+ process.argv[2] ?? resolve(dirname(fileURLToPath(import.meta.url)), '../..')
);
let result;
try {
@@ -464,9 +407,6 @@ function main() {
process.exit(ok ? 0 : 1);
}
-if (
- process.argv[1] &&
- import.meta.url === pathToFileURL(resolve(process.argv[1])).href
-) {
+if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
main();
}