Skip to content

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

fix(ci): make the Rust layout gate warn early, cover core/, and ratchet its pins

M3gA-Mind66752a6b0c2b
diff --git a/scripts/__tests__/check-openhuman-rust-layout.test.mjs b/scripts/__tests__/check-openhuman-rust-layout.test.mjs
new file mode 100644
index 0000000000..53d76a63c0
--- /dev/null
+++ b/scripts/__tests__/check-openhuman-rust-layout.test.mjs
@@ -0,0 +1,107 @@
+// Unit tests for scripts/ci/check-openhuman-rust-layout.mjs.
+//
+// The gate reads a fixed tree relative to the cwd and hard-codes its legacy
+// pins, so each test copies the script into a throwaway tree, swaps its pin
+// list for the test's own, and runs it there. Each clause of the line limit —
+// scope, warn band, ratchet, duplicate pins — has a test that goes red without
+// it.
+
+import assert from "node:assert/strict";
+import { spawnSync } from "node:child_process";
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+import test from "node:test";
+import { fileURLToPath } from "node:url";
+
+const repoRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
+const scriptRel = path.join("scripts", "ci", "check-openhuman-rust-layout.mjs");
+const scriptSource = fs.readFileSync(path.join(repoRoot, scriptRel), "utf8");
+const SRC = "crates/openhuman-core/src";
+const PINS_RE = /const LEGACY_LIMIT_ENTRIES = \[[\s\S]*?\n\];/;
+
+/** A Rust file of exactly `n` lines, as the gate counts them. */
+const lines = (n) => "//\n".repeat(n);
+
+/**
+ * Run the gate over a throwaway tree.
+ *
+ * @param {Record<string,number>} files path under `SRC` -> line count
+ * @param {Array<[string, number]>} pins legacy pins, paths under `SRC`
+ */
+function run(files, pins = []) {
+ const entries = pins.map(([file, limit]) => [`${SRC}/${file}`, limit]);
+ assert.match(scriptSource, PINS_RE, "fixture: the gate's pin list was not found");
+ const source = scriptSource.replace(
+ PINS_RE,
+ `const LEGACY_LIMIT_ENTRIES = ${JSON.stringify(entries)};`,
+ );
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "openhuman-rust-layout-"));
+ for (const dir of [SRC, "crates/openhuman-cli", "tests", "examples", "scripts/ci"])
+ fs.mkdirSync(path.join(root, dir), { recursive: true });
+ fs.writeFileSync(path.join(root, "crates/openhuman-core/Cargo.toml"), "");
+ fs.writeFileSync(path.join(root, "crates/openhuman-cli/Cargo.toml"), "");
+ for (const [file, n] of Object.entries(files)) {
+ const abs = path.join(root, SRC, file);
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
+ fs.writeFileSync(abs, lines(n));
+ }
+ fs.writeFileSync(path.join(root, scriptRel), source);
+ const result = spawnSync(process.execPath, [scriptRel], { cwd: root, encoding: "utf8" });
+ fs.rmSync(root, { recursive: true, force: true });
+ return { status: result.status, out: `${result.stdout}${result.stderr}` };
+}
+
+test("passes at exactly the limit and at exactly a pin", () => {
+ const { status, out } = run({ "a.rs": 750, "big.rs": 900 }, [["big.rs", 900]]);
+ assert.equal(status, 0, out);
+});
+
+test("fails one line over the limit", () => {
+ const { status, out } = run({ "a.rs": 751 });
+ assert.equal(status, 1);
+ assert.match(out, /a\.rs: 751 lines \(limit 750\)/);
+});
+
+test("warns, without failing, on a file inside the warn band", () => {
+ const { status, out } = run({ "near.rs": 740, "far.rs": 725 });
+ assert.equal(status, 0, out);
+ assert.match(out, /near\.rs: 740 lines, 10 below the 750-line limit/);
+ assert.doesNotMatch(out, /far\.rs/);
+});
+
+test("enforces the limit under core/, which used to be pruned by name", () => {
+ const { status, out } = run({ "core/observability.rs": 800, "lib.rs": 800 });
+ assert.equal(status, 1);
+ assert.match(out, /core\/observability\.rs: 800 lines \(limit 750\)/);
+ assert.match(out, /lib\.rs: 800 lines \(limit 750\)/);
+});
+
+test("a pinned file that shrank must lower its pin", () => {
+ const { status, out } = run({ "big.rs": 850 }, [["big.rs", 900]]);
+ assert.equal(status, 1);
+ assert.match(out, /big\.rs: 850 lines, below its legacy pin 900; lower the pin to 850/);
+});
+
+test("a pinned file that fits the limit must drop its pin", () => {
+ const { status, out } = run({ "big.rs": 700 }, [["big.rs", 900]]);
+ assert.equal(status, 1);
+ assert.match(out, /big\.rs: 700 lines now fits the 750-line limit; remove its legacy exception/);
+});
+
+test("a file pinned twice fails, because a Map keeps only the last pin", () => {
+ const { status, out } = run({ "big.rs": 900 }, [
+ ["big.rs", 800],
+ ["big.rs", 900],
+ ]);
+ assert.equal(status, 1);
+ assert.match(out, /big\.rs: duplicate legacy exception/);
+});
+
+test("the real pin list has no duplicate entry", () => {
+ const files = [...scriptSource.match(PINS_RE)[0].matchAll(/"(crates\/[^"]+\.rs)"/g)].map(
+ (m) => m[1],
+ );
+ assert.ok(files.length > 0, "fixture: no pins parsed");
+ assert.equal(new Set(files).size, files.length);
+});
diff --git a/scripts/ci/README.md b/scripts/ci/README.md
index e2e10d2b08..577242e51b 100644
--- a/scripts/ci/README.md
+++ b/scripts/ci/README.md
@@ -6,7 +6,7 @@ authoritative spec; this is an index so a CI failure log points somewhere.
| File | Checks |
| --- | --- |
-| `check-openhuman-rust-layout.mjs` (`pnpm rust:layout`) | Every file under `crates/openhuman-core/src` (except `api`, `bin`, `core`, `lib.rs`, `main.rs`, `rpc`) stays under a 750-line ceiling, with pinned legacy exceptions; forbids inline `#[cfg(test)] mod` blocks and `tests.rs`/`test.rs` filenames; and asserts every root `tests/*.rs` / `examples/*.rs` has a matching `[[test]]`/`[[example]]` entry in `crates/openhuman-core/Cargo.toml`. |
+| `check-openhuman-rust-layout.mjs` (`pnpm rust:layout`) | Every file under `crates/openhuman-core/src` stays under a 750-line ceiling, warning (without failing) past 725; oversized files are pinned at their exact size in `LEGACY_LIMIT_ENTRIES`, once each, and a pinned file that shrinks must lower or drop its pin; forbids inline `#[cfg(test)] mod` blocks and `tests.rs`/`test.rs` filenames; and asserts every root `tests/*.rs` / `examples/*.rs` has a matching `[[test]]`/`[[example]]` entry in `crates/openhuman-core/Cargo.toml`. |
| `check-feature-forwarding.mjs` | The Tauri shell (`crates/openhuman-app/Cargo.toml`, which sets `default-features = false`) forwards exactly the gates in `product-features.txt` — no more, no less — and the library chain that re-declares the core's gates (`openhuman-embed` → `openhuman-tinyhumans` → `openhuman-cli`) forwards every one of them, by target and not just by name. Logic lives in `scripts/lib/feature-forwarding.mjs` (openhuman#4919, openhuman#6364). |
| `product-features.txt` / `product-features.sh` | Source of truth for the shipped desktop product's Cargo feature gates, distinct from `[features] default` (the contributor build). The `.sh` prints them comma-separated for `cargo --features "$(scripts/ci/product-features.sh)"`. |
| `check-module-pins.mjs` + `module-pin-exemptions.json` | A loadable module's registry pin (`crates/openhuman-core/src/modules/registry.rs`) and its `vendor/*` submodule pin must describe the same release (openhuman#5727). The exemptions file records known, expected drift — not a way to silence the gate. Logic lives in `scripts/lib/module-pins.mjs`. |
diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjs
index f1fdbd7c5f..9b9b854126 100644
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@ -10,70 +10,65 @@ const CORE_MANIFEST = "crates/openhuman-core/Cargo.toml";
// which hosts the binary and every integration suite; the core is a library.
const CLI_MANIFEST = "crates/openhuman-cli/Cargo.toml";
const LINE_LIMIT = 750;
+// Files past this size are reported (without failing) so an author sees the
+// margin in their own PR's log instead of a later PR turning `main` red.
+const WARN_AT = 725;
-// These stateful assembly functions still need semantic decomposition. Pinning
-// their current size makes the gate monotonic: they cannot grow, no new
-// exception can appear, and deleting an entry is the only way to relax it.
-const LEGACY_LIMITS = new Map([
+// Files over `LINE_LIMIT` that still need semantic decomposition. Each pin is
+// the file's exact size and is a ratchet, enforced below: a file may not grow
+// past its pin, and a file that shrinks must lower its pin in the same change
+// (or drop the entry once it fits `LINE_LIMIT`), so recovered lines cannot be
+// spent again. No new exception can appear, and one file may be listed only
+// once (a Map keeps the last duplicate, which silently discards the other pin).
+const LEGACY_LIMIT_ENTRIES = [
// These orchestration files crossed the general limit in the already-merged
- // runtime compatibility work. Pin their exact post-merge sizes so follow-up
- // changes cannot grow them while they are split along semantic seams.
- // 847 -> 821: the argument prologue moved to
- // `spawn_async_subagent_args.rs`. Pinned at its exact new size, so the
- // 26 lines recovered cannot be spent again. Still exempt because the rest of
- // that function's phases close over locals whose types are not nameable from
- // this module (see that fragment's header); taking it under 750 needs a
- // visibility change in `subagent_sessions`, which is follow-up, not this PR.
+ // runtime compatibility work. They are being split along semantic seams.
+ // `spawn_async_subagent_execute.rs`: 847 -> 821 when the argument prologue
+ // moved to `spawn_async_subagent_args.rs`, 821 -> 809 via
+ // `AbortReport::deliver`. Still exempt because the rest of that function's
+ // phases close over locals whose types are not nameable from this module
+ // (see that fragment's header); taking it under 750 needs a visibility
+ // change in `subagent_sessions`.
[
"crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_execute.rs",
- // 821 -> 809: the terminal progress sends go through `AbortReport::deliver`
- // (one call instead of an `if let` around `tx.send`). Pinned at the new size.
- 809,
+ 800,
],
// `spawn_subagent_tool_impl.rs` had its entry DELETED, not lowered: the
// parameter schema moved to `spawn_subagent_parameters.rs` and the file is
- // 740 lines, under the general 750 limit, so it needs no exception at all.
+ // under the general 750 limit, so it needs no exception at all.
["crates/openhuman-core/src/agent/multimodal.rs", 772],
// The session-todo integration added transcript metadata construction to
// this already-exempt composition seam. Keep its allowance exact.
["crates/openhuman-core/src/agent/session_host/runtime_session.rs", 1990],
- ["crates/openhuman-core/src/agent/subagent_host/lifecycle.rs", 1304],
- ["crates/openhuman-core/src/agent/subagent_host/ops/runner.rs", 1793],
// Session-host factory still assembles the product's deliberately coupled
// provider, security, memory, tool and prompt policy. Generic session
// state moved to tinyagents-runtime; this remaining composition is split in
// a follow-up without reintroducing an old harness/session exception.
- ["crates/openhuman-core/src/agent/session_host/builder/factory.rs", 1245],
- ["crates/openhuman-core/src/agent/subagent_host/lifecycle.rs", 1318],
- ["crates/openhuman-core/src/agent/subagent_host/ops/runner.rs", 1793],
- ["crates/openhuman-core/src/tools/ops.rs", 1502],
- // Existing browser assembly file is slightly over the general limit; pin
- // its merged-base size so this PR does not grow the established seam.
- ["crates/openhuman-core/src/tools/impl/browser/browser.rs", 756],
- ["crates/openhuman-core/src/web_chat/progress_bridge.rs", 1547],
+ ["crates/openhuman-core/src/agent/session_host/builder/factory.rs", 1215],
+ ["crates/openhuman-core/src/agent/subagent_host/lifecycle.rs", 1313],
+ ["crates/openhuman-core/src/agent/subagent_host/ops/runner.rs", 1427],
+ ["crates/openhuman-core/src/tools/ops.rs", 1342],
+ ["crates/openhuman-core/src/web_chat/progress_bridge.rs", 1305],
// These established external test modules grew with upstream coverage. Pin
// their current sizes while follow-up work separates their test concerns.
["crates/openhuman-core/src/agent/prompts/mod_tests_builder_sections_tests.rs", 779],
- ["crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs", 799],
- ["crates/openhuman-core/src/tools/ops_tests_default_registry_tests.rs", 752],
-]);
+ // `core/` was pruned from the line limit by name until these pins; its
+ // oversized files are pinned at the size they had when enforcement began.
+ ["crates/openhuman-core/src/core/all.rs", 1840],
+ ["crates/openhuman-core/src/core/all_tests.rs", 2709],
+ ["crates/openhuman-core/src/core/cli.rs", 803],
+ ["crates/openhuman-core/src/core/events.rs", 2005],
+ ["crates/openhuman-core/src/core/events_tests.rs", 1062],
+ ["crates/openhuman-core/src/core/observability.rs", 3631],
+ ["crates/openhuman-core/src/core/runtime/builder.rs", 841],
+ ["crates/openhuman-core/src/core/runtime/context.rs", 1024],
+];
+const LEGACY_LIMITS = new Map(LEGACY_LIMIT_ENTRIES);
-function rustFiles(directory) {
- return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
- const file = path.join(directory, entry.name);
- if (
- directory === ROOT &&
- ["api", "bin", "core", "lib.rs", "main.rs", "rpc"].includes(entry.name)
- )
- return [];
- if (entry.isDirectory()) return rustFiles(file);
- return entry.isFile() && entry.name.endsWith(".rs") ? [file] : [];
- });
-}
-
-// Every Rust file under every crate, no exclusions — used for the naming and
-// inline-test-module checks, which apply repository-wide. The line-limit
-// check above stays scoped to `ROOT` exactly as before.
+// Every Rust file under a directory, no exclusions. The line limit applies to
+// every file under `ROOT` (an oversized file is pinned in
+// `LEGACY_LIMIT_ENTRIES`, never skipped); the naming and inline-test-module
+// checks apply to every crate.
function allRustFiles(directory) {
return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
const file = path.join(directory, entry.name);
@@ -89,7 +84,8 @@ const INLINE_TEST_MODULE_RE =
/^\s*#\[cfg\([^\n]*\btest\b[^\n]*\)\]\s*\n(?:\s*#\[[^\n]+\]\s*\n)*\s*(?:pub(?:\([^)]*\))?\s+)?mod\s+\w+\s*\{/m;
const failures = [];
-for (const file of rustFiles(ROOT)) {
+const warnings = [];
+for (const file of allRustFiles(ROOT)) {
const source = fs.readFileSync(file, "utf8");
const lineCount = source.split("\n").length - (source.endsWith("\n") ? 1 : 0);
const portableFile = file.split(path.sep).join("/");
@@ -98,6 +94,16 @@ for (const file of rustFiles(ROOT)) {
failures.push(
`${file}: ${lineCount} lines (limit ${legacyLimit ?? LINE_LIMIT})`,
);
+ } else if (legacyLimit !== undefined && lineCount < legacyLimit) {
+ failures.push(
+ lineCount <= LINE_LIMIT
+ ? `${file}: ${lineCount} lines now fits the ${LINE_LIMIT}-line limit; remove its legacy exception`
+ : `${file}: ${lineCount} lines, below its legacy pin ${legacyLimit}; lower the pin to ${lineCount}`,
+ );
+ } else if (legacyLimit === undefined && lineCount > WARN_AT) {
+ warnings.push(
+ `${file}: ${lineCount} lines, ${LINE_LIMIT - lineCount} below the ${LINE_LIMIT}-line limit`,
+ );
}
}
@@ -115,6 +121,15 @@ for (const file of allRustFiles(CRATES_ROOT)) {
}
}
+// A Map silently keeps the last of two entries for one file, so a duplicate
+// hides whichever pin was written first.
+const seenLegacy = new Set();
+for (const [file] of LEGACY_LIMIT_ENTRIES) {
+ if (seenLegacy.has(file))
+ failures.push(`${file}: duplicate legacy exception; keep one entry`);
+ seenLegacy.add(file);
+}
+
for (const file of LEGACY_LIMITS.keys()) {
if (!fs.existsSync(file))
failures.push(`${file}: stale legacy exception; remove it from the gate`);
@@ -162,6 +177,11 @@ for (const [directory, table] of [
}
}
+if (warnings.length) {
+ console.warn("OpenHuman Rust layout check: files near the line limit:");
+ warnings.forEach((warning) => console.warn(` - ${warning}`));
+}
+
if (failures.length) {
console.error("OpenHuman Rust layout check failed:");
failures.forEach((failure) => console.error(` - ${failure}`));