Skip to content

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

ci: add a per-crate #[ignore] ratchet that runs before clippy

M3gA-Mind1400966bc113
diff --git a/.github/workflows/ci-lite.yml b/.github/workflows/ci-lite.yml
index 2cf5409275..c2385b18aa 100644
--- a/.github/workflows/ci-lite.yml
+++ b/.github/workflows/ci-lite.yml
@@ -130,6 +130,11 @@ jobs:
- 'scripts/ci/check-openhuman-rust-layout.mjs'
- 'scripts/ci/check-agent-runtime-boundary.mjs'
- 'scripts/ci/agent-runtime-boundary-baseline.json'
+ # The ignored-test ratchet lives in rust-quality. Its checker and
+ # its baseline must arm that lane themselves, or a PR that raises
+ # the baseline skips the only gate that reads it.
+ - 'scripts/ci/check-ignored-tests.mjs'
+ - 'scripts/ci/ignored-test-baseline.json'
- 'scripts/ci/list-feature-gated-rust-tests.mjs'
- 'Cargo.toml'
- 'crates/openhuman-core/**'
@@ -194,6 +199,11 @@ jobs:
- 'scripts/ci/check-module-pins.mjs'
- 'scripts/ci/check-submodule-monotonic.mjs'
- 'scripts/ci/module-pin-exemptions.json'
+ # The ignored-test ratchet has node --test coverage in
+ # scripts/__tests__/ — editing the gate must run the tests that
+ # pin its clauses, or the counter's anchoring and its
+ # cfg_attr guard can be loosened with nothing watching.
+ - 'scripts/ci/check-ignored-tests.mjs'
# Test-wiring surface: a change here can orphan a test or add an
# untested controller domain → run the inventory guard.
inventory:
@@ -373,6 +383,16 @@ jobs:
if: needs.changes.outputs['rust-core'] == 'true'
run: pnpm agent:runtime-boundary
+ - name: Enforce the ignored-test ratchet
+ # Counts `#[ignore]` attributes in the source tree per crate and refuses
+ # any increase. Deliberately static: `#[ignore]` is a source attribute,
+ # so this needs no build, no feature-set choice and no dependence on the
+ # dispatch-only full-suite lane (#5021) — which is why it can sit here,
+ # ahead of clippy, rather than waiting for a lane that runs tests.
+ # Covers openhuman-app too, hence both filters.
+ if: needs.changes.outputs['rust-core'] == 'true' || needs.changes.outputs['rust-tauri'] == 'true'
+ run: pnpm rust:ignored-tests
+
- name: Enforce Linux TLS dependency policy
if: needs.changes.outputs['rust-core'] == 'true' || needs.changes.outputs['rust-tauri'] == 'true'
run: bash scripts/check-linux-tls-dependencies.sh
diff --git a/package.json b/package.json
index 93a122208c..60402ed4b8 100644
--- a/package.json
+++ b/package.json
@@ -58,6 +58,7 @@
"rust:check": "pnpm --filter openhuman-app rust:check",
"rust:clippy": "cargo clippy -p openhuman -p openhuman-cli -p openhuman-tinyhumans -- -D warnings && pnpm --filter openhuman-app rust:clippy",
"rust:layout": "node scripts/ci/check-openhuman-rust-layout.mjs",
+ "rust:ignored-tests": "node scripts/ci/check-ignored-tests.mjs",
"dep:audit": "bash scripts/dep-audit/run.sh",
"agent:runtime-boundary": "node scripts/ci/check-agent-runtime-boundary.mjs",
"typecheck": "pnpm --filter openhuman-app compile",
diff --git a/scripts/__tests__/ignored-test-ratchet.test.mjs b/scripts/__tests__/ignored-test-ratchet.test.mjs
new file mode 100644
index 0000000000..47c662079d
--- /dev/null
+++ b/scripts/__tests__/ignored-test-ratchet.test.mjs
@@ -0,0 +1,155 @@
+// Unit tests for scripts/ci/check-ignored-tests.mjs — the per-crate `#[ignore]`
+// ratchet that runs in the `rust-quality` lane.
+//
+// Each test pins one clause the gate would be useless without. Delete that
+// clause and exactly one test here goes red. Two of them exist because the
+// naive version of this gate got them wrong:
+//
+// - `counts attributes, not prose` — an unanchored `#\[ignore` match also hits
+// doc comments that merely DISCUSS ignoring (nine such lines in the real
+// tree), so deleting a comment would have earned ratchet credit.
+// - `rejects cfg_attr(..., ignore)` — a form the counter cannot see would
+// shrink the number while the test stays skipped, i.e. it leaks in the one
+// direction that never reddens.
+
+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 script = path.join(repoRoot, "scripts", "ci", "check-ignored-tests.mjs");
+
+/**
+ * Build a throwaway tree, then run the gate over it.
+ *
+ * @param {Record<string,string>} files repo-relative path -> contents
+ * @param {Record<string,number>|null} baseline written to the baseline path, or
+ * omitted entirely to exercise the missing-baseline path
+ * @param {string[]} args extra argv
+ */
+function run(files, baseline, args = []) {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "openhuman-ignore-ratchet-"));
+ // The gate lists `crates/` to discover buckets, so it must always exist.
+ fs.mkdirSync(path.join(root, "crates"), { recursive: true });
+ for (const [rel, body] of Object.entries(files)) {
+ const abs = path.join(root, rel);
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
+ fs.writeFileSync(abs, body);
+ }
+ if (baseline) {
+ const abs = path.join(root, "scripts", "ci", "ignored-test-baseline.json");
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
+ fs.writeFileSync(abs, `${JSON.stringify(baseline, null, 2)}\n`);
+ }
+ const result = spawnSync(process.execPath, [script, "--root", root, ...args], {
+ encoding: "utf8",
+ });
+ fs.rmSync(root, { recursive: true, force: true });
+ return { status: result.status, out: `${result.stdout}${result.stderr}` };
+}
+
+const IGNORED_TEST = '#[test]\n#[ignore = "needs a daemon"]\nfn skipped() {}\n';
+
+test("passes when every bucket matches its baseline", () => {
+ const { status, out } = run(
+ { "crates/demo/src/lib.rs": IGNORED_TEST },
+ { demo: 1 },
+ );
+ assert.equal(status, 0, out);
+ assert.match(out, /ratchet holds \(1 /);
+});
+
+test("fails when a crate gains an ignored test", () => {
+ const { status, out } = run(
+ { "crates/demo/src/lib.rs": IGNORED_TEST + IGNORED_TEST },
+ { demo: 1 },
+ );
+ assert.equal(status, 1);
+ assert.match(out, /demo: 2 '#\[ignore\]' attributes, baseline 1 \(\+1\)/);
+ assert.match(out, /only goes down/);
+});
+
+test("fails when a crate loses one, demanding the baseline be tightened", () => {
+ const { status, out } = run({ "crates/demo/src/lib.rs": IGNORED_TEST }, { demo: 2 });
+ assert.equal(status, 1);
+ assert.match(out, /demo: 1 '#\[ignore\]' attributes, baseline 2 \(-1\)/);
+ assert.match(out, /Tighten the baseline/);
+});
+
+test("a crate absent from the baseline is held at zero, not grandfathered", () => {
+ const { status, out } = run({ "crates/fresh/src/lib.rs": IGNORED_TEST }, {});
+ assert.equal(status, 1);
+ assert.match(out, /fresh: 1 '#\[ignore\]' attributes, baseline 0 \(\+1\)/);
+});
+
+test("counts attributes, not prose that mentions them", () => {
+ const { status, out } = run(
+ {
+ "crates/demo/src/lib.rs":
+ "// We deliberately do not `#[ignore]` this one.\n" +
+ "/// See the argument about #[ignore] in the module docs.\n" +
+ "//! Nothing here is #[ignore]d.\n" +
+ IGNORED_TEST,
+ },
+ { demo: 1 },
+ );
+ assert.equal(status, 0, out);
+});
+
+test("rejects cfg_attr(..., ignore), which the counter cannot see", () => {
+ const { status, out } = run(
+ { "crates/demo/src/lib.rs": "#[test]\n#[cfg_attr(unix, ignore)]\nfn skipped() {}\n" },
+ { demo: 0 },
+ );
+ assert.equal(status, 1);
+ assert.match(out, /cfg_attr\(\.\.\., ignore\)\]' is not countable/);
+ assert.match(out, /crates\/demo\/src\/lib\.rs:2/);
+});
+
+test("the root tests/ tree is its own bucket, not folded into a crate", () => {
+ const { status, out } = run(
+ { "tests/thing_e2e.rs": IGNORED_TEST, "crates/demo/src/lib.rs": "pub fn ok() {}\n" },
+ { demo: 0, tests: 0 },
+ );
+ assert.equal(status, 1);
+ assert.match(out, /^ {2}tests: 1 /m);
+ assert.doesNotMatch(out, /demo: /);
+});
+
+test("a baselined bucket that vanished must be removed from the baseline", () => {
+ const { status, out } = run({ "crates/demo/src/lib.rs": IGNORED_TEST }, { demo: 1, gone: 3 });
+ assert.equal(status, 1);
+ assert.match(out, /gone: baselined but no longer scanned/);
+});
+
+test("skips target/ and node_modules/, which hold generated copies", () => {
+ const { status, out } = run(
+ {
+ "crates/demo/src/lib.rs": IGNORED_TEST,
+ "crates/demo/target/debug/build/generated.rs": IGNORED_TEST + IGNORED_TEST,
+ "crates/demo/node_modules/pkg/vendored.rs": IGNORED_TEST,
+ },
+ { demo: 1 },
+ );
+ assert.equal(status, 0, out);
+});
+
+test("--write-baseline records what it scanned", () => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "openhuman-ignore-ratchet-w-"));
+ fs.mkdirSync(path.join(root, "crates", "demo", "src"), { recursive: true });
+ fs.writeFileSync(path.join(root, "crates", "demo", "src", "lib.rs"), IGNORED_TEST);
+ fs.mkdirSync(path.join(root, "scripts", "ci"), { recursive: true });
+ const written = spawnSync(process.execPath, [script, "--root", root, "--write-baseline"], {
+ encoding: "utf8",
+ });
+ assert.equal(written.status, 0, `${written.stdout}${written.stderr}`);
+ const baseline = JSON.parse(
+ fs.readFileSync(path.join(root, "scripts", "ci", "ignored-test-baseline.json"), "utf8"),
+ );
+ assert.deepEqual(baseline, { demo: 1, tests: 0 });
+ fs.rmSync(root, { recursive: true, force: true });
+});
diff --git a/scripts/ci/check-ignored-tests.mjs b/scripts/ci/check-ignored-tests.mjs
new file mode 100644
index 0000000000..56213581d5
--- /dev/null
+++ b/scripts/ci/check-ignored-tests.mjs
@@ -0,0 +1,147 @@
+#!/usr/bin/env node
+//
+// Per-crate `#[ignore]` ratchet. The count may only go down.
+//
+// What this counts is `#[ignore]` ATTRIBUTES PRESENT IN THE SOURCE TREE — not
+// tests libtest skips at runtime. The two numbers differ and the difference is
+// not fully explained: `openhuman-core` has 96 attributes in source while a
+// scoped `--lib` run reported 83 ignored. Feature gating accounts for exactly
+// one of those (`core/jsonrpc_tests.rs`), so the rest is open. The static count
+// is the right thing to ratchet anyway: it is what a reviewer actually adds in
+// a diff, and it is deterministic without a build or a feature-set choice —
+// which is why this gate can run in `rust-quality` before clippy instead of
+// waiting on the full-suite lane (#5021).
+//
+// Usage:
+// node scripts/ci/check-ignored-tests.mjs
+// node scripts/ci/check-ignored-tests.mjs --write-baseline
+
+import { readdir, readFile, writeFile } from "node:fs/promises";
+import { dirname, join, relative, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+
+// `--root <dir>` points the scan and the baseline at a throwaway tree, which is
+// how scripts/__tests__/ignored-test-ratchet.test.mjs exercises the failure
+// paths without mutating the real crates.
+const rootFlag = process.argv.indexOf("--root");
+const repoRoot = rootFlag === -1
+ ? resolve(dirname(fileURLToPath(import.meta.url)), "../..")
+ : resolve(process.argv[rootFlag + 1]);
+const baselinePath = resolve(repoRoot, "scripts/ci/ignored-test-baseline.json");
+const writeBaselineMode = process.argv.includes("--write-baseline");
+
+// Anchored at line start on purpose. An unanchored `#\[ignore` match also hits
+// doc comments and prose that merely DISCUSS ignoring — there are nine such
+// lines today, including two files that argue at length about ignored tests.
+// Counting those would let a PR earn ratchet credit by deleting a comment,
+// which rewards the wrong action while looking rigorous.
+const IGNORE_ATTRIBUTE = /^\s*#\s*\[\s*ignore\b/;
+
+// `#[cfg_attr(<cond>, ignore)]` is an ignore this gate cannot count, and it
+// would fail SILENTLY in the direction that never reddens: the number goes
+// down, the test still does not run. No such form exists today, so the honest
+// move is to reject the first one rather than let the ratchet start leaking.
+// Delete this guard only by teaching the counter to handle the form.
+const UNCOUNTABLE_IGNORE = /#\s*\[\s*cfg_attr\s*\([^\]]*\bignore\b/;
+
+async function rustFilesUnder(root) {
+ const found = [];
+ const walk = async (dir) => {
+ let entries;
+ try {
+ entries = await readdir(dir, { withFileTypes: true });
+ } catch {
+ return; // A bucket that does not exist contributes nothing.
+ }
+ for (const entry of entries) {
+ const path = join(dir, entry.name);
+ if (entry.isDirectory()) {
+ if (entry.name === "target" || entry.name === "node_modules") continue;
+ await walk(path);
+ } else if (entry.name.endsWith(".rs")) {
+ found.push(path);
+ }
+ }
+ };
+ await walk(root);
+ return found.sort();
+}
+
+// One bucket per crate, plus the root `tests/` tree. Root tests are compiled by
+// openhuman-cli through explicit `[[test]] path = "../../tests/..."` entries,
+// but they are their own reviewable surface, so folding them into the cli count
+// would hide movement in both.
+const buckets = new Map();
+const uncountable = [];
+
+const crateDirs = (await readdir(resolve(repoRoot, "crates"), { withFileTypes: true }))
+ .filter((entry) => entry.isDirectory())
+ .map((entry) => entry.name)
+ .sort();
+
+for (const [bucket, root] of [
+ ...crateDirs.map((name) => [name, resolve(repoRoot, "crates", name)]),
+ ["tests", resolve(repoRoot, "tests")],
+]) {
+ let count = 0;
+ for (const path of await rustFilesUnder(root)) {
+ const lines = (await readFile(path, "utf8")).split("\n");
+ for (const [index, line] of lines.entries()) {
+ if (IGNORE_ATTRIBUTE.test(line)) count += 1;
+ if (UNCOUNTABLE_IGNORE.test(line)) {
+ uncountable.push(`${relative(repoRoot, path)}:${index + 1}: ${line.trim()}`);
+ }
+ }
+ }
+ buckets.set(bucket, count);
+}
+
+const actual = Object.fromEntries([...buckets].sort(([a], [b]) => a.localeCompare(b)));
+
+if (writeBaselineMode) {
+ await writeFile(baselinePath, `${JSON.stringify(actual, null, 2)}\n`);
+ const total = Object.values(actual).reduce((sum, n) => sum + n, 0);
+ console.log(`Wrote ${total} '#[ignore]' attributes across ${Object.keys(actual).length} buckets to ${relative(repoRoot, baselinePath)}.`);
+ process.exit(0);
+}
+
+let baseline;
+try {
+ baseline = JSON.parse(await readFile(baselinePath, "utf8"));
+} catch (error) {
+ console.error(`Unable to read ${relative(repoRoot, baselinePath)}: ${error.message}`);
+ process.exit(1);
+}
+
+const failures = [];
+if (uncountable.length) {
+ failures.push(
+ `'#[cfg_attr(..., ignore)]' is not countable by this gate, so it would shrink the count without un-skipping the test:\n${uncountable.map((item) => ` ${item}`).join("\n")}\n Use a plain '#[ignore = \"reason\"]', or teach scripts/ci/check-ignored-tests.mjs to count this form.`,
+ );
+}
+
+// A bucket absent from the baseline is 0, so a new crate that arrives carrying
+// ignored tests reddens instead of being grandfathered in.
+for (const [bucket, count] of Object.entries(actual)) {
+ const allowed = baseline[bucket] ?? 0;
+ if (count > allowed) {
+ failures.push(`${bucket}: ${count} '#[ignore]' attributes, baseline ${allowed} (+${count - allowed}). This ratchet only goes down — un-skip the test, or delete it.`);
+ } else if (count < allowed) {
+ failures.push(`${bucket}: ${count} '#[ignore]' attributes, baseline ${allowed} (${count - allowed}). Tighten the baseline in the same PR so the count cannot drift back up.`);
+ }
+}
+for (const bucket of Object.keys(baseline)) {
+ if (!(bucket in actual)) {
+ failures.push(`${bucket}: baselined but no longer scanned. Remove it from ${relative(repoRoot, baselinePath)}.`);
+ }
+}
+
+if (failures.length) {
+ console.error("Ignored-test ratchet: '#[ignore]' attributes present in the source tree no longer match the baseline.\n");
+ for (const failure of failures) console.error(` ${failure}`);
+ console.error(`\nRe-baseline deliberately, never as a reflex:\n pnpm rust:ignored-tests --write-baseline\nThen say in the PR body which tests moved and why. Raising a number needs a reason a reviewer can check.`);
+ process.exit(1);
+}
+
+const total = Object.values(actual).reduce((sum, n) => sum + n, 0);
+console.log(`Ignored-test ratchet holds (${total} '#[ignore]' attributes in source, matching the per-bucket baseline).`);
diff --git a/scripts/ci/ignored-test-baseline.json b/scripts/ci/ignored-test-baseline.json
new file mode 100644
index 0000000000..5317ba3a38
--- /dev/null
+++ b/scripts/ci/ignored-test-baseline.json
@@ -0,0 +1,10 @@
+{
+ "openhuman-app": 5,
+ "openhuman-cli": 0,
+ "openhuman-core": 96,
+ "openhuman-embed": 2,
+ "openhuman-rpc": 0,
+ "openhuman-tinyhumans": 0,
+ "openhuman-tui": 0,
+ "tests": 32
+}