Skip to content

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

style: reformat storage-bypass check and tests

Steven Enamakel6de2a77a47ba
diff --git a/scripts/__tests__/storage-bypass.test.mjs b/scripts/__tests__/storage-bypass.test.mjs
index fa97110678..6080bb382d 100644
--- a/scripts/__tests__/storage-bypass.test.mjs
+++ b/scripts/__tests__/storage-bypass.test.mjs
@@ -11,28 +11,49 @@ import { fileURLToPath } from "node:url";
import { ALLOW, allowed, compare, scan } from "../ci/check-storage-bypass.mjs";
-const repoRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
+const repoRoot = path.join(
+ path.dirname(fileURLToPath(import.meta.url)),
+ "..",
+ "..",
+);
const script = path.join(repoRoot, "scripts", "ci", "check-storage-bypass.mjs");
const SRC = "crates/openhuman-core/src";
function run(files, baseline, args = []) {
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "openhuman-storage-bypass-"));
+ const root = fs.mkdtempSync(
+ path.join(os.tmpdir(), "openhuman-storage-bypass-"),
+ );
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);
}
- const written = path.join(root, "scripts", "ci", "storage-bypass-baseline.json");
+ const written = path.join(
+ root,
+ "scripts",
+ "ci",
+ "storage-bypass-baseline.json",
+ );
if (baseline) {
fs.mkdirSync(path.dirname(written), { recursive: true });
fs.writeFileSync(written, `${JSON.stringify(baseline, null, 2)}\n`);
}
- const result = spawnSync(process.execPath, [script, "--root", root, ...args], {
- encoding: "utf8",
- });
- const after = fs.existsSync(written) ? JSON.parse(fs.readFileSync(written, "utf8")) : null;
+ const result = spawnSync(
+ process.execPath,
+ [script, "--root", root, ...args],
+ {
+ encoding: "utf8",
+ },
+ );
+ const after = fs.existsSync(written)
+ ? JSON.parse(fs.readFileSync(written, "utf8"))
+ : null;
fs.rmSync(root, { recursive: true, force: true });
- return { status: result.status, out: `${result.stdout}${result.stderr}`, after };
+ return {
+ status: result.status,
+ out: `${result.stdout}${result.stderr}`,
+ after,
+ };
}
test("flags a database open and a raw file write", () => {
@@ -55,14 +76,30 @@ test("flags a database open and a raw file write", () => {
test("ignores comments and doc lines", () => {
const found = scan(
"x.rs",
- ["// Connection::open(&p)", "//! fs::write(p, b)", "let s = 1; // File::create(p)"].join("\n"),
+ [
+ "// Connection::open(&p)",
+ "//! fs::write(p, b)",
+ "let s = 1; // File::create(p)",
+ ].join("\n"),
);
assert.deepEqual(found, []);
});
test("compare reports added and stale sites", () => {
- const finding = { rule: "sqlite-open", path: "a.rs", line: 3, text: "x", occurrence: 1 };
- const other = { rule: "json-write", path: "b.rs", line: 4, text: "y", occurrence: 1 };
+ const finding = {
+ rule: "sqlite-open",
+ path: "a.rs",
+ line: 3,
+ text: "x",
+ occurrence: 1,
+ };
+ const other = {
+ rule: "json-write",
+ path: "b.rs",
+ line: 4,
+ text: "y",
+ occurrence: 1,
+ };
const { added, stale } = compare([finding], [other]);
assert.deepEqual(added, [finding]);
assert.deepEqual(stale, [other]);
@@ -72,7 +109,8 @@ test("every allowlisted path carries a reason and known rules", () => {
for (const [file, entry] of ALLOW) {
assert.ok(file.startsWith(`${SRC}/`), file);
assert.ok(entry.reason.length > 20, file);
- for (const rule of entry.rules) assert.ok(["sqlite-open", "json-write"].includes(rule));
+ for (const rule of entry.rules)
+ assert.ok(["sqlite-open", "json-write"].includes(rule));
}
assert.ok(allowed(`${SRC}/config/workspace/state.rs`, "sqlite-open"));
assert.ok(!allowed(`${SRC}/config/workspace/state.rs`, "json-write"));
@@ -85,7 +123,10 @@ test("a new database open fails the check", () => {
);
assert.equal(status, 1);
assert.match(out, /New storage-bypass sites/);
- assert.match(out, /sqlite-open: crates\/openhuman-core\/src\/foo\/store\.rs:1/);
+ assert.match(
+ out,
+ /sqlite-open: crates\/openhuman-core\/src\/foo\/store\.rs:1/,
+ );
});
test("the storage module, tests and allowlisted fallbacks are not flagged", () => {
@@ -103,7 +144,13 @@ test("the storage module, tests and allowlisted fallbacks are not flagged", () =
test("a fixed site left in the baseline fails until removed", () => {
const { status, out } = run({ [`${SRC}/foo/store.rs`]: "fn f() {}\n" }, [
- { rule: "sqlite-open", path: `${SRC}/foo/store.rs`, line: 1, text: "x", occurrence: 1 },
+ {
+ rule: "sqlite-open",
+ path: `${SRC}/foo/store.rs`,
+ line: 1,
+ text: "x",
+ occurrence: 1,
+ },
]);
assert.equal(status, 1);
assert.match(out, /Fixed sites still in the baseline/);
diff --git a/scripts/ci/check-storage-bypass.mjs b/scripts/ci/check-storage-bypass.mjs
index ec68b727be..0e52eab2a9 100755
--- a/scripts/ci/check-storage-bypass.mjs
+++ b/scripts/ci/check-storage-bypass.mjs
@@ -33,7 +33,10 @@ const repoRoot =
? resolve(dirname(fileURLToPath(import.meta.url)), "../..")
: resolve(process.argv[rootFlag + 1]);
const scanRoot = resolve(repoRoot, "crates/openhuman-core/src");
-const baselinePath = resolve(repoRoot, "scripts/ci/storage-bypass-baseline.json");
+const baselinePath = resolve(
+ repoRoot,
+ "scripts/ci/storage-bypass-baseline.json",
+);
const writeBaseline = process.argv.includes("--write-baseline");
export const RULES = [
@@ -44,20 +47,34 @@ export const RULES = [
},
{
rule: "json-write",
- pattern: /\b(?:fs::write|File::create|OpenOptions::new|NamedTempFile::new_in)\s*\(/,
+ pattern:
+ /\b(?:fs::write|File::create|OpenOptions::new|NamedTempFile::new_in)\s*\(/,
hint: "persist through the storage port, or allowlist it with a reason in ALLOW",
},
];
const SRC = "crates/openhuman-core/src/";
-const FALLBACK = "legacy fallback of a store that already runs on the storage port";
+const FALLBACK =
+ "legacy fallback of a store that already runs on the storage port";
/** path -> { rules, reason }: sites a rule does not apply to. */
export const ALLOW = new Map([
- [`${SRC}security/approval/store.rs`, { rules: ["sqlite-open"], reason: FALLBACK }],
- [`${SRC}security/devices/store.rs`, { rules: ["sqlite-open"], reason: FALLBACK }],
- [`${SRC}desktop/notifications/store.rs`, { rules: ["sqlite-open"], reason: FALLBACK }],
- [`${SRC}integrations/task_sources/store.rs`, { rules: ["sqlite-open"], reason: FALLBACK }],
+ [
+ `${SRC}security/approval/store.rs`,
+ { rules: ["sqlite-open"], reason: FALLBACK },
+ ],
+ [
+ `${SRC}security/devices/store.rs`,
+ { rules: ["sqlite-open"], reason: FALLBACK },
+ ],
+ [
+ `${SRC}desktop/notifications/store.rs`,
+ { rules: ["sqlite-open"], reason: FALLBACK },
+ ],
+ [
+ `${SRC}integrations/task_sources/store.rs`,
+ { rules: ["sqlite-open"], reason: FALLBACK },
+ ],
[`${SRC}cron/policy.rs`, { rules: ["sqlite-open"], reason: FALLBACK }],
[
`${SRC}config/workspace/state.rs`,
@@ -67,9 +84,18 @@ export const ALLOW = new Map([
"vault watcher state is absolute local paths and their mtimes: per-machine filesystem state that is meaningless on, and must not be shared through, another host's database",
},
],
- [`${SRC}platform/cost/tracker.rs`, { rules: ["json-write"], reason: FALLBACK }],
- [`${SRC}agent/orchestration/subagent_sessions/store.rs`, { rules: ["json-write"], reason: FALLBACK }],
- [`${SRC}integrations/composio/file_store.rs`, { rules: ["json-write"], reason: FALLBACK }],
+ [
+ `${SRC}platform/cost/tracker.rs`,
+ { rules: ["json-write"], reason: FALLBACK },
+ ],
+ [
+ `${SRC}agent/orchestration/subagent_sessions/store.rs`,
+ { rules: ["json-write"], reason: FALLBACK },
+ ],
+ [
+ `${SRC}integrations/composio/file_store.rs`,
+ { rules: ["json-write"], reason: FALLBACK },
+ ],
[
`${SRC}desktop/control/ops.rs`,
{
@@ -202,7 +228,9 @@ async function main() {
try {
baseline = JSON.parse(await readFile(baselinePath, "utf8"));
} catch (error) {
- console.error(`Unable to read ${relative(repoRoot, baselinePath)}: ${error.message}`);
+ console.error(
+ `Unable to read ${relative(repoRoot, baselinePath)}: ${error.message}`,
+ );
return 1;
}
@@ -217,13 +245,20 @@ async function main() {
console.error(`New storage-bypass sites (${added.length}):`);
for (const f of added) {
const hint = RULES.find((r) => r.rule === f.rule)?.hint ?? "";
- console.error(` ${f.rule}: ${f.path}:${f.line}: ${f.text}\n -> ${hint}`);
+ console.error(
+ ` ${f.rule}: ${f.path}:${f.line}: ${f.text}\n -> ${hint}`,
+ );
}
}
if (stale.length) {
- console.error(`\nFixed sites still in the baseline (${stale.length}); remove them:`);
- for (const f of stale) console.error(` ${f.rule}: ${f.path}: ${f.text} [${f.occurrence}]`);
- console.error("\nTighten the baseline with --write-baseline once nothing new was added.");
+ console.error(
+ `\nFixed sites still in the baseline (${stale.length}); remove them:`,
+ );
+ for (const f of stale)
+ console.error(` ${f.rule}: ${f.path}: ${f.text} [${f.occurrence}]`);
+ console.error(
+ "\nTighten the baseline with --write-baseline once nothing new was added.",
+ );
}
return 1;
}