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
style: format storage-bypass scripts and tests
Steven Enamakelba03ac9b1208
diff --git a/scripts/__tests__/self-hosted-lanes.test.mjs b/scripts/__tests__/self-hosted-lanes.test.mjsindex 2c09f138ee..493851b8ca 100644--- a/scripts/__tests__/self-hosted-lanes.test.mjs+++ b/scripts/__tests__/self-hosted-lanes.test.mjs@@ -164,9 +164,14 @@ test("core doctests remain outside PR coverage; embed doctests and tui tests runassert.equal(cov.env.OH_COV_TUI, "1");const runs = allRuns(plan).join("\n");assert.doesNotMatch(runs, /cargo test -p openhuman --doc/);- assert.doesNotMatch(runs, /cargo test -p openhuman-(embed|tinyhumans)\b(?! --doc)/);+ assert.doesNotMatch(+ runs,+ /cargo test -p openhuman-(embed|tinyhumans)\b(?! --doc)/,+ );assert.match(runs, /cargo test -p openhuman-embed --doc/);- const doc = plan.lanes.find(l => l.name === "rust-lint").checks.find(c => c.name === "embed-rustdoc");+ const doc = plan.lanes+ .find((l) => l.name === "rust-lint")+ .checks.find((c) => c.name === "embed-rustdoc");assert.equal(doc.env.RUSTDOCFLAGS, "-D warnings");assert.match(doc.run, /cargo doc -p openhuman-embed --no-deps/);assert.match(runs, /node scripts\/run-embed-examples.mjs/);@@ -268,7 +273,7 @@ test("the storage area arms only the storage-drivers lane, with the sqlite and f"static:orch-ip-gate","static:feature-forwarding","static:crate-chain",- "static:storage-bypass",+ "static:storage-bypass","static:module-pins","static:submodule-monotonic",],@@ -662,28 +667,49 @@ test("module boundaries run for Rust and scripts changes in both profiles", () =areas: { ...NONE, [area]: true },env: profile === "ex63" ? EX63_ENV : {},});- const check = plan.lanes.flatMap(lane => lane.checks).find(check => check.name === "module-boundaries");+ const check = plan.lanes+ .flatMap((lane) => lane.checks)+ .find((check) => check.name === "module-boundaries");assert.equal(check.when, true, `${profile}:${area}`);- assert.equal(check.run, "bash scripts/ci-cancel-aware.sh node scripts/ci/check-module-boundaries.mjs");+ assert.equal(+ check.run,+ "bash scripts/ci-cancel-aware.sh node scripts/ci/check-module-boundaries.mjs",+ );}}});-test("module boundary policy and checker changes arm their own scripts lane", () => {- const filters = fs.readFileSync(path.join(repoRoot, ".github/ci-paths-filter.yml"), "utf8");+ const filters = fs.readFileSync(+ path.join(repoRoot, ".github/ci-paths-filter.yml"),+ "utf8",+ );const scripts = filters.split(/^scripts:\s*$/m)[1].split(/^\S[^\n]*:/m)[0];- for (const file of ["scripts/ci/check-module-boundaries.mjs", "scripts/ci/module-boundaries.json"]) {- assert.ok(scripts.includes(`'${file}'`), `${file} must arm the scripts area`);+ for (const file of [+ "scripts/ci/check-module-boundaries.mjs",+ "scripts/ci/module-boundaries.json",+ ]) {+ assert.ok(+ scripts.includes(`'${file}'`),+ `${file} must arm the scripts area`,+ );}});-test("storage-bypass runs under cancellation supervision in both profiles", () => {for (const profile of ["hosted", "ex63"]) {- const plan = buildPlan({ profile, areas: NONE, env: profile === "ex63" ? EX63_ENV : {} });- const check = plan.lanes.flatMap(lane => lane.checks).find(check => check.name === "storage-bypass");+ const plan = buildPlan({+ profile,+ areas: NONE,+ env: profile === "ex63" ? EX63_ENV : {},+ });+ const check = plan.lanes+ .flatMap((lane) => lane.checks)+ .find((check) => check.name === "storage-bypass");assert.equal(check.when, true);- assert.equal(check.run, "bash scripts/ci-cancel-aware.sh node scripts/ci/check-storage-bypass.mjs");+ assert.equal(+ check.run,+ "bash scripts/ci-cancel-aware.sh node scripts/ci/check-storage-bypass.mjs",+ );}});diff --git a/scripts/__tests__/storage-bypass-debt.test.mjs b/scripts/__tests__/storage-bypass-debt.test.mjsindex da3abd5774..0600baa882 100644--- a/scripts/__tests__/storage-bypass-debt.test.mjs+++ b/scripts/__tests__/storage-bypass-debt.test.mjs@@ -4,18 +4,33 @@ import { mkdtempSync, rmSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { execFileSync } from "node:child_process";-import { validateCoverageDebt, validateAllowances, historicalFindings } from "../ci/storage-bypass-debt.mjs";-import { compare, scan, CURATED_VENDOR_ROOTS } from "../ci/check-storage-bypass.mjs";+import {+ validateCoverageDebt,+ validateAllowances,+ historicalFindings,+} from "../ci/storage-bypass-debt.mjs";+import {+ compare,+ scan,+ CURATED_VENDOR_ROOTS,+} from "../ci/check-storage-bypass.mjs";const row = {- rule: "json-write", path: "crates/openhuman-embed/src/state.rs", text: "tokio::fs::write(path, bytes);", occurrence: 1,- classification: "unmigrated", reason: "Existing native backend migration debt at this exact source site.",+ rule: "json-write",+ path: "crates/openhuman-embed/src/state.rs",+ text: "tokio::fs::write(path, bytes);",+ occurrence: 1,+ classification: "unmigrated",+ reason: "Existing native backend migration debt at this exact source site.",issue: "https://github.com/tinyhumansai/openhuman/issues/7428",};const history = { baseline: [], extension: null, findings: [row] };test("initial extension admits only exact existing canonical coverage", () => {assert.deepEqual(validateCoverageDebt([row], [], [row], history), []);const added = { ...row, path: "crates/openhuman-embed/src/new.rs" };- assert.match(validateCoverageDebt([added], [], [added], history).join("\n"), /branch-added writer/);+ assert.match(+ validateCoverageDebt([added], [], [added], history).join("\n"),+ /branch-added writer/,+ );});test("moving or copying a recorded writer cannot reuse its identity", () => {const moved = { ...row, path: "crates/openhuman-rpc/src/state.rs" };@@ -27,48 +42,111 @@ test("extension records may shrink but never grow after establishment", () => {const old = { ...history, extension: [row] };assert.deepEqual(validateCoverageDebt([], [], [], old), []);const added = { ...row, text: "tokio::fs::write(other, bytes);" };- assert.match(validateCoverageDebt([row, added], [], [row, added], old).join("\n"), /Extension growth forbidden/);+ assert.match(+ validateCoverageDebt([row, added], [], [row, added], old).join("\n"),+ /Extension growth forbidden/,+ );});test("removing a debt record does not grandfather a surviving writer", () => {assert.equal(compare([row], []).added.length, 1);});test("original core debt cannot move into the extension or grow", () => {const core = { ...row, path: "crates/openhuman-core/src/state.rs" };- assert.match(validateCoverageDebt([core], [], [core], history).join("\n"), /cannot conceal original core debt/);- assert.match(validateCoverageDebt([core], [core], [], history).join("\n"), /Core baseline growth forbidden/);+ assert.match(+ validateCoverageDebt([core], [], [core], history).join("\n"),+ /cannot conceal original core debt/,+ );+ assert.match(+ validateCoverageDebt([core], [core], [], history).join("\n"),+ /Core baseline growth forbidden/,+ );});test("reasons, exact occurrence and issue links are mandatory", () => {- for (const bad of [{ reason: "" }, { issue: "" }, { classification: "approved" }, { occurrence: 2 }]) {- assert.ok(validateCoverageDebt([row], [], [{ ...row, ...bad }], history).length);+ for (const bad of [+ { reason: "" },+ { issue: "" },+ { classification: "approved" },+ { occurrence: 2 },+ ]) {+ assert.ok(+ validateCoverageDebt([row], [], [{ ...row, ...bad }], history).length,+ );}});test("an initial allowance cannot exempt a newly introduced branch writer", () => {const record = { ...row, site: row.text };- assert.match(validateAllowances([row], [record], { rawFindings: [], allowances: null }).join("\n"), /branch-added writer/);- assert.deepEqual(validateAllowances([row], [record], { rawFindings: [row], allowances: null }), []);+ assert.match(+ validateAllowances([row], [record], {+ rawFindings: [],+ allowances: null,+ }).join("\n"),+ /branch-added writer/,+ );+ assert.deepEqual(+ validateAllowances([row], [record], {+ rawFindings: [row],+ allowances: null,+ }),+ [],+ );});test("later allowances cannot grow or excuse a copied site", () => {const record = { ...row, site: row.text };const copy = { ...record, path: "crates/openhuman-embed/src/copy.rs" };- assert.match(validateAllowances([{ ...row, path: copy.path }], [copy], { rawFindings: [row], allowances: [record] }).join("\n"), /growth forbidden/);+ assert.match(+ validateAllowances([{ ...row, path: copy.path }], [copy], {+ rawFindings: [row],+ allowances: [record],+ }).join("\n"),+ /growth forbidden/,+ );});test("curated vendor coverage excludes native drivers but not host adapter writes", () => {- assert.ok(CURATED_VENDOR_ROOTS.every(p => !p.includes("tinystoragedrivers")));- assert.ok(CURATED_VENDOR_ROOTS.some(p => p.includes("tinymcp")));- assert.ok(CURATED_VENDOR_ROOTS.some(p => p.includes("run_ledger")));- assert.equal(scan("crates/openhuman-embed/src/adapter.rs", "tokio::fs::write(path, bytes);").length, 1);+ assert.ok(+ CURATED_VENDOR_ROOTS.every((p) => !p.includes("tinystoragedrivers")),+ );+ assert.ok(CURATED_VENDOR_ROOTS.some((p) => p.includes("tinymcp")));+ assert.ok(CURATED_VENDOR_ROOTS.some((p) => p.includes("run_ledger")));+ assert.equal(+ scan(+ "crates/openhuman-embed/src/adapter.rs",+ "tokio::fs::write(path, bytes);",+ ).length,+ 1,+ );});test("new serializer and helper rules ignore quoted and commented fixture text", () => {- assert.deepEqual(scan("x.rs", 'let fixture = "serde_json::to_writer(file, value);";\n/* fn write_atomic(path) {} */'), []);+ assert.deepEqual(+ scan(+ "x.rs",+ 'let fixture = "serde_json::to_writer(file, value);";\n/* fn write_atomic(path) {} */',+ ),+ [],+ );});test("missing canonical base history fails closed", () => {const root = mkdtempSync(join(tmpdir(), "storage-history-"));try {execFileSync("git", ["init"], { cwd: root, stdio: "ignore" });- assert.throws(() => historicalFindings(root, { scan, withoutAllowed: (_, x) => x, isTestFile: () => false, CURATED_VENDOR_ROOTS: [] }));- } finally { rmSync(root, { recursive: true, force: true }); }+ assert.throws(() =>+ historicalFindings(root, {+ scan,+ withoutAllowed: (_, x) => x,+ isTestFile: () => false,+ CURATED_VENDOR_ROOTS: [],+ }),+ );+ } finally {+ rmSync(root, { recursive: true, force: true });+ }});test("quoted database opener examples do not count as host persistence", () => {- assert.deepEqual(scan("crates/openhuman-embed/src/example.rs", 'let example = r#"OtherStore::open(root.join("cache.db"))"#;'), []);+ assert.deepEqual(+ scan(+ "crates/openhuman-embed/src/example.rs",+ 'let example = r#"OtherStore::open(root.join("cache.db"))"#;',+ ),+ [],+ );});diff --git a/scripts/__tests__/storage-bypass.test.mjs b/scripts/__tests__/storage-bypass.test.mjsindex 23d6620882..66200abfc8 100644--- a/scripts/__tests__/storage-bypass.test.mjs+++ b/scripts/__tests__/storage-bypass.test.mjs@@ -152,13 +152,27 @@ test("an embed Tokio file writer cannot bypass the host storage scan", () => {);assert.equal(status, 1);assert.match(out, /New storage-bypass sites/);- assert.match(out, /json-write: crates\/openhuman-embed\/src\/preferences\.rs:1/);+ assert.match(+ out,+ /json-write: crates\/openhuman-embed\/src\/preferences\.rs:1/,+ );});test("every host crate rejects a new raw state writer", () => {- for (const name of ["core", "embed", "tinyhumans", "rpc", "app", "cli", "tui"]) {+ for (const name of [+ "core",+ "embed",+ "tinyhumans",+ "rpc",+ "app",+ "cli",+ "tui",+ ]) {const rel = `crates/openhuman-${name}/src/new_state.rs`;- const result = run({ [rel]: "async fn save() { tokio::fs::write(path, bytes).await; }\n" }, []);+ const result = run(+ { [rel]: "async fn save() { tokio::fs::write(path, bytes).await; }\n" },+ [],+ );assert.equal(result.status, 1, name);assert.ok(result.out.includes(rel), name);}@@ -166,15 +180,22 @@ test("every host crate rejects a new raw state writer", () => {test("file mutations, temporary builders and serializers are findings", () => {for (const source of [- "tokio::fs::rename(old, new);", "std::fs::copy(old, new);",- "std::fs::hard_link(old, new);", "tempfile::Builder::new();",- "serde_json::to_writer(file, value);", "serde_json::to_writer_pretty(file, value);",- ]) assert.ok(scan("x.rs", source).length > 0, source);+ "tokio::fs::rename(old, new);",+ "std::fs::copy(old, new);",+ "std::fs::hard_link(old, new);",+ "tempfile::Builder::new();",+ "serde_json::to_writer(file, value);",+ "serde_json::to_writer_pretty(file, value);",+ ])+ assert.ok(scan("x.rs", source).length > 0, source);});test("known filesystem writer helpers are reviewed at their definition", () => {for (const name of ["write_private", "create_private", "write_atomic"]) {- assert.ok(scan("x.rs", `pub fn ${name}(path: &Path) { helper(path); }`).length > 0, name);+ assert.ok(+ scan("x.rs", `pub fn ${name}(path: &Path) { helper(path); }`).length > 0,+ name,+ );}});@@ -182,11 +203,16 @@ test("vendored openers with database and stream path arguments are findings", ()for (const source of ['let store = OtherStore::open(root.join("cache.db"));','let store = OtherStore::open(root.join("messages.jsonl"));',- ]) assert.ok(scan("x.rs", source).length > 0, source);+ ])+ assert.ok(scan("x.rs", source).length > 0, source);});test("baseline regeneration cannot accept an additional core writer", () => {- const result = run({ [`${SRC}/foo/store.rs`]: "std::fs::write(p, b);\n" }, [], ["--write-baseline"]);+ const result = run(+ { [`${SRC}/foo/store.rs`]: "std::fs::write(p, b);\n" },+ [],+ ["--write-baseline"],+ );assert.equal(result.status, 1);assert.deepEqual(result.after, []);});diff --git a/scripts/ci/check-storage-bypass.mjs b/scripts/ci/check-storage-bypass.mjsindex fa6507bac8..f6382d2122 100755--- a/scripts/ci/check-storage-bypass.mjs+++ b/scripts/ci/check-storage-bypass.mjs@@ -24,7 +24,11 @@// node scripts/ci/check-storage-bypass.mjs --root <dir> (tests)import { stripRustComments } from "./check-crate-chain.mjs";-import { validateCoverageDebt, validateAllowances, historicalFindings } from "./storage-bypass-debt.mjs";+import {+ validateCoverageDebt,+ validateAllowances,+ historicalFindings,+} from "./storage-bypass-debt.mjs";import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";import { dirname, relative, resolve, sep } from "node:path";import { fileURLToPath } from "node:url";@@ -64,7 +68,8 @@ export const RULES = [},{rule: "file-mutation",- pattern: /\b(?:fs::(?:rename|copy|hard_link)|tempfile::Builder::new|serde_json::to_writer(?:_pretty)?)\s*\(/,+ pattern:+ /\b(?:fs::(?:rename|copy|hard_link)|tempfile::Builder::new|serde_json::to_writer(?:_pretty)?)\s*\(/,hint: "review the filesystem publication or serializer destination through the owning storage port",},{@@ -74,7 +79,8 @@ export const RULES = [},{rule: "vendored-open",- pattern: /\b(?:[A-Za-z_][\w]*::)*(?:[A-Za-z_][\w]*Store|[A-Za-z_][\w]*Ledger)::open(?:_file)?\s*\(/,+ pattern:+ /\b(?:[A-Za-z_][\w]*::)*(?:[A-Za-z_][\w]*Store|[A-Za-z_][\w]*Ledger)::open(?:_file)?\s*\(/,hint: "a persistent path passed to an owning store opener needs captured native routing",},];@@ -87,10 +93,20 @@ const SRC = "crates/openhuman-core/src/";* still a finding, and removing the allowed line does not free a quota for* another.*/-export const auditedReasons = JSON.parse(await readFile(new URL("./storage-bypass-allow-reasons.json", import.meta.url), "utf8"));+export const auditedReasons = JSON.parse(+ await readFile(+ new URL("./storage-bypass-allow-reasons.json", import.meta.url),+ "utf8",+ ),+);export const ALLOW = new Map();for (const { path, ...entry } of auditedReasons) {- if (!entry.reason?.trim() || !/^https:\/\/github\.com\/tinyhumansai\/openhuman\/issues\/\d+$/.test(entry.issue ?? "")) {+ if (+ !entry.reason?.trim() ||+ !/^https:\/\/github\.com\/tinyhumansai\/openhuman\/issues\/\d+$/.test(+ entry.issue ?? "",+ )+ ) {throw new Error(`Invalid storage allowance reason: ${path}`);}ALLOW.set(path, [...(ALLOW.get(path) ?? []), entry]);@@ -147,10 +163,16 @@ export function scan(rel, source) {// count a match only when it starts on this line.const searchable = `${code}\n${codeOf(lines[index + 1] ?? "")}`;for (const { rule, pattern } of RULES) {- const input = originalCore({ path: rel, rule }) ? searchable : `${masked[index]}\n${masked[index + 1] ?? ""}`;+ const input = originalCore({ path: rel, rule })+ ? searchable+ : `${masked[index]}\n${masked[index + 1] ?? ""}`;const hit = pattern.exec(input);if (!hit || hit.index >= code.length) continue;- if (rule === "vendored-open" && !/"[^"\n]*\.(?:db|jsonl)"/.test(searchable.slice(hit.index))) continue;+ if (+ rule === "vendored-open" &&+ !/"[^"\n]*\.(?:db|jsonl)"/.test(searchable.slice(hit.index))+ )+ continue;const text = raw.trim();const key = `${rule}\0${text}`;const occurrence = (occurrences.get(key) ?? 0) + 1;@@ -161,7 +183,8 @@ export function scan(rel, source) {return found;}-export const originalCore = f => f.path.startsWith(SRC) && ["sqlite-open", "json-write"].includes(f.rule);+export const originalCore = (f) =>+ f.path.startsWith(SRC) && ["sqlite-open", "json-write"].includes(f.rule);export const identity = ({ rule, path, text, occurrence }) =>`${rule}\0${path}\0${text}\0${occurrence}`;@@ -179,7 +202,12 @@ export function compare(findings, baseline) {async function rustFiles(dir) {const out = [];if (dir.endsWith(".rs")) {- try { await readFile(dir); return [dir]; } catch { return []; }+ try {+ await readFile(dir);+ return [dir];+ } catch {+ return [];+ }}let entries;try {@@ -198,8 +226,10 @@ async function rustFiles(dir) {export async function collectFindings(root, { includeAllowed = false } = {}) {const findings = [];const scanRoot = resolve(root, "crates");- const roots = (await readdir(scanRoot, { withFileTypes: true })).filter(e => e.isDirectory()).map(e => resolve(scanRoot, e.name, "src"));- roots.push(...CURATED_VENDOR_ROOTS.map(p => resolve(root, p)));+ const roots = (await readdir(scanRoot, { withFileTypes: true }))+ .filter((e) => e.isDirectory())+ .map((e) => resolve(scanRoot, e.name, "src"));+ roots.push(...CURATED_VENDOR_ROOTS.map((p) => resolve(root, p)));for (const path of (await Promise.all(roots.map(rustFiles))).flat()) {const rel = relative(root, path).split(sep).join("/");if (isTestFile(rel)) continue;@@ -223,15 +253,29 @@ async function main() {}let extension = [];- try { extension = JSON.parse(await readFile(resolve(repoRoot, "scripts/ci/storage-bypass-extension.json"), "utf8")); }- catch (error) { if (error.code !== "ENOENT") throw error; }+ try {+ extension = JSON.parse(+ await readFile(+ resolve(repoRoot, "scripts/ci/storage-bypass-extension.json"),+ "utf8",+ ),+ );+ } catch (error) {+ if (error.code !== "ENOENT") throw error;+ }const raw = await collectFindings(repoRoot, { includeAllowed: true });let debtErrors = validateCoverageDebt(findings, baseline, extension);- if (rootFlag === -1) debtErrors.push(...validateAllowances(raw, auditedReasons));+ if (rootFlag === -1)+ debtErrors.push(...validateAllowances(raw, auditedReasons));// Fixture roots without Git history exercise source scanning; CI always checks// the real checkout against its canonical merge base and retained records.if (rootFlag === -1) {- const history = historicalFindings(repoRoot, { scan, withoutAllowed, isTestFile, CURATED_VENDOR_ROOTS });+ const history = historicalFindings(repoRoot, {+ scan,+ withoutAllowed,+ isTestFile,+ CURATED_VENDOR_ROOTS,+ });debtErrors = validateCoverageDebt(findings, baseline, extension, history);debtErrors.push(...validateAllowances(raw, auditedReasons, history));}diff --git a/scripts/ci/storage-bypass-debt.mjs b/scripts/ci/storage-bypass-debt.mjsindex 9e1617f70e..8ef86a657d 100644--- a/scripts/ci/storage-bypass-debt.mjs+++ b/scripts/ci/storage-bypass-debt.mjs@@ -3,36 +3,69 @@ import { execFileSync } from "node:child_process";const CORE = "crates/openhuman-core/src/";const BASELINE = "scripts/ci/storage-bypass-baseline.json";const EXTENSION = "scripts/ci/storage-bypass-extension.json";-const key = x => JSON.stringify([x.rule, x.path, x.text, x.occurrence]);-const original = x => x.path.startsWith(CORE) && ["sqlite-open", "json-write"].includes(x.rule);+const key = (x) => JSON.stringify([x.rule, x.path, x.text, x.occurrence]);+const original = (x) =>+ x.path.startsWith(CORE) && ["sqlite-open", "json-write"].includes(x.rule);/** Exact existing-debt records never authorize another site or later growth. */export function validateCoverageDebt(findings, baseline, extension, history) {- if (!Array.isArray(baseline) || !Array.isArray(extension)) return ["Storage debt manifests must be arrays"];+ if (!Array.isArray(baseline) || !Array.isArray(extension))+ return ["Storage debt manifests must be arrays"];const errors = [];const actual = new Set(findings.map(key));const seen = new Set();- for (const record of baseline) if (!original(record)) errors.push(`Core baseline cannot accept extended coverage: ${record.path}`);+ for (const record of baseline)+ if (!original(record))+ errors.push(+ `Core baseline cannot accept extended coverage: ${record.path}`,+ );for (const record of extension) {const id = key(record);if (seen.has(id)) errors.push(`Duplicate extension record: ${record.path}`);seen.add(id);- if (original(record)) errors.push(`Extension cannot conceal original core debt: ${record.path}`);- if (!actual.has(id)) errors.push(`Stale extension record: ${record.path}: ${record.text}`);- if (!["classic", "machine", "scratch", "external-export", "read-only", "unmigrated"].includes(record.classification)- || typeof record.reason !== "string" || record.reason.trim().length < 20- || !/^https:\/\/github\.com\/tinyhumansai\/openhuman\/issues\/\d+$/.test(record.issue ?? "")) {+ if (original(record))+ errors.push(+ `Extension cannot conceal original core debt: ${record.path}`,+ );+ if (!actual.has(id))+ errors.push(`Stale extension record: ${record.path}: ${record.text}`);+ if (+ ![+ "classic",+ "machine",+ "scratch",+ "external-export",+ "read-only",+ "unmigrated",+ ].includes(record.classification) ||+ typeof record.reason !== "string" ||+ record.reason.trim().length < 20 ||+ !/^https:\/\/github\.com\/tinyhumansai\/openhuman\/issues\/\d+$/.test(+ record.issue ?? "",+ )+ ) {errors.push(`Incomplete audited extension record: ${record.path}`);}}if (history) {const oldCore = new Set(history.baseline.map(key));- for (const record of baseline) if (!oldCore.has(key(record))) errors.push(`Core baseline growth forbidden: ${record.path}: ${record.text}`);- const oldExtension = history.extension === null ? null : new Set(history.extension.map(key));+ for (const record of baseline)+ if (!oldCore.has(key(record)))+ errors.push(+ `Core baseline growth forbidden: ${record.path}: ${record.text}`,+ );+ const oldExtension =+ history.extension === null ? null : new Set(history.extension.map(key));const oldSites = new Set(history.findings.map(key));for (const record of extension) {- if (oldExtension && !oldExtension.has(key(record))) errors.push(`Extension growth forbidden: ${record.path}: ${record.text}`);- if (!oldExtension && !oldSites.has(key(record))) errors.push(`Initial extension cannot approve a branch-added writer: ${record.path}: ${record.text}`);+ if (oldExtension && !oldExtension.has(key(record)))+ errors.push(+ `Extension growth forbidden: ${record.path}: ${record.text}`,+ );+ if (!oldExtension && !oldSites.has(key(record)))+ errors.push(+ `Initial extension cannot approve a branch-added writer: ${record.path}: ${record.text}`,+ );}}return errors;@@ -40,13 +73,34 @@ export function validateCoverageDebt(findings, baseline, extension, history) {/** Re-scan canonical merge-base source, including the recorded curated gitlinks. */export function historicalFindings(root, scanner) {- const git = (args, cwd = root) => execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });- let ref = process.env.GITHUB_BASE_REF ? `origin/${process.env.GITHUB_BASE_REF}` : "upstream/main";+ const git = (args, cwd = root) =>+ execFileSync("git", args, {+ cwd,+ encoding: "utf8",+ stdio: ["ignore", "pipe", "pipe"],+ });+ let ref = process.env.GITHUB_BASE_REF+ ? `origin/${process.env.GITHUB_BASE_REF}`+ : "upstream/main";if (!process.env.GITHUB_BASE_REF) {- try { git(["rev-parse", "--verify", ref]); } catch { ref = "origin/main"; }+ try {+ git(["rev-parse", "--verify", ref]);+ } catch {+ ref = "origin/main";+ }}const base = git(["merge-base", ref, "HEAD"]).trim();- const files = git(["ls-tree", "-r", "-z", "--name-only", base, "--", "crates"]).split("\0").filter(p => /^crates\/[^/]+\/src\/.*\.rs$/.test(p));+ const files = git([+ "ls-tree",+ "-r",+ "-z",+ "--name-only",+ base,+ "--",+ "crates",+ ])+ .split("\0")+ .filter((p) => /^crates\/[^/]+\/src\/.*\.rs$/.test(p));const findings = [];const rawFindings = [];const add = (path, source) => {@@ -65,8 +119,14 @@ export function historicalFindings(root, scanner) {const commit = /^160000 commit ([a-f0-9]{40})\t/.exec(entry)?.[1];if (!commit) throw new Error(`Missing canonical gitlink for ${module}`);const cwd = `${root}/${module}`;- const names = git(["ls-tree", "-r", "-z", "--name-only", commit, "--", inside], cwd).split("\0").filter(p => p.endsWith(".rs"));- for (const file of names) add(`${module}/${file}`, git(["show", `${commit}:${file}`], cwd));+ const names = git(+ ["ls-tree", "-r", "-z", "--name-only", commit, "--", inside],+ cwd,+ )+ .split("\0")+ .filter((p) => p.endsWith(".rs"));+ for (const file of names)+ add(`${module}/${file}`, git(["show", `${commit}:${file}`], cwd));}const json = (path, optional = false) => {if (!git(["ls-tree", "--name-only", base, "--", path]).trim()) {@@ -74,10 +134,18 @@ export function historicalFindings(root, scanner) {throw new Error(`Canonical baseline missing: ${path}`);}const value = JSON.parse(git(["show", `${base}:${path}`]));- if (!Array.isArray(value)) throw new Error(`Canonical manifest must be an array: ${path}`);+ if (!Array.isArray(value))+ throw new Error(`Canonical manifest must be an array: ${path}`);return value;};- return { base, findings, rawFindings, baseline: json(BASELINE), extension: json(EXTENSION, true), allowances: json("scripts/ci/storage-bypass-allow-reasons.json", true) };+ return {+ base,+ findings,+ rawFindings,+ baseline: json(BASELINE),+ extension: json(EXTENSION, true),+ allowances: json("scripts/ci/storage-bypass-allow-reasons.json", true),+ };}/** Initial audited exclusions must exist in canonical source; later exclusions cannot grow. */@@ -85,15 +153,30 @@ export function validateAllowances(raw, records, history) {const errors = [];const current = new Set(raw.map(key));const oldSites = history ? new Set(history.rawFindings.map(key)) : null;- const oldRecords = history?.allowances === null ? null : history ? new Set(history.allowances.map(x => key({ ...x, text: x.site, occurrence: 1 }))) : null;+ const oldRecords =+ history?.allowances === null+ ? null+ : history+ ? new Set(+ history.allowances.map((x) =>+ key({ ...x, text: x.site, occurrence: 1 }),+ ),+ )+ : null;const seen = new Set();for (const record of records) {const id = key({ ...record, text: record.site, occurrence: 1 });- if (seen.has(id)) errors.push(`Duplicate audited allowance: ${record.path}`);+ if (seen.has(id))+ errors.push(`Duplicate audited allowance: ${record.path}`);seen.add(id);- if (!current.has(id)) errors.push(`Stale audited allowance: ${record.path}: ${record.site}`);- if (oldRecords && !oldRecords.has(id)) errors.push(`Audited allowance growth forbidden: ${record.path}`);- if (history && !oldRecords && !oldSites.has(id)) errors.push(`Initial allowance cannot approve a branch-added writer: ${record.path}`);+ if (!current.has(id))+ errors.push(`Stale audited allowance: ${record.path}: ${record.site}`);+ if (oldRecords && !oldRecords.has(id))+ errors.push(`Audited allowance growth forbidden: ${record.path}`);+ if (history && !oldRecords && !oldSites.has(id))+ errors.push(+ `Initial allowance cannot approve a branch-added writer: ${record.path}`,+ );}return errors;}