Skip to content

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

fix(ci): report extra storage sites in allowlisted files

Steven Enamakel2fc4054a947b
diff --git a/scripts/__tests__/storage-bypass.test.mjs b/scripts/__tests__/storage-bypass.test.mjs
index 6080bb382d..d09d306ec8 100644
--- a/scripts/__tests__/storage-bypass.test.mjs
+++ b/scripts/__tests__/storage-bypass.test.mjs
@@ -9,7 +9,13 @@ import path from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
-import { ALLOW, allowed, compare, scan } from "../ci/check-storage-bypass.mjs";
+import {
+ ALLOW,
+ allowed,
+ compare,
+ scan,
+ withoutAllowed,
+} from "../ci/check-storage-bypass.mjs";
const repoRoot = path.join(
path.dirname(fileURLToPath(import.meta.url)),
@@ -166,3 +172,19 @@ test("--write-baseline records the current sites", () => {
assert.equal(after.length, 1);
assert.equal(after[0].rule, "json-write");
});
+
+test("an allowlisted file may hold only its known site", () => {
+ const file = `${SRC}/platform/cost/tracker.rs`;
+ const found = scan(
+ file,
+ "std::fs::write(a, b);\nstd::fs::write(c, d);\nConnection::open(p);\n",
+ );
+ const kept = withoutAllowed(file, found);
+ assert.deepEqual(
+ kept.map((f) => [f.rule, f.line]),
+ [
+ ["json-write", 2],
+ ["sqlite-open", 3],
+ ],
+ );
+});
diff --git a/scripts/ci/check-storage-bypass.mjs b/scripts/ci/check-storage-bypass.mjs
index 0e52eab2a9..66543db64b 100755
--- a/scripts/ci/check-storage-bypass.mjs
+++ b/scripts/ci/check-storage-bypass.mjs
@@ -135,6 +135,25 @@ export function allowed(rel, rule) {
return ALLOW.get(rel)?.rules.includes(rule) ?? false;
}
+/** Sites an allowlisted file may hold per rule: the ones it has today. */
+export const ALLOWED_SITES_PER_RULE = 1;
+
+/**
+ * Drops the first [`ALLOWED_SITES_PER_RULE`] allowlisted sites of each rule in
+ * `rel`. A further site in the same file is a new one: it is reported (or must
+ * be baselined), so the allowance covers the known fallback or local-only
+ * write and nothing added beside it.
+ */
+export function withoutAllowed(rel, found) {
+ const kept = new Map();
+ return found.filter((f) => {
+ if (!allowed(rel, f.rule)) return true;
+ const used = kept.get(f.rule) ?? 0;
+ kept.set(f.rule, used + 1);
+ return used >= ALLOWED_SITES_PER_RULE;
+ });
+}
+
function isTestFile(rel) {
return (
rel.startsWith("crates/openhuman-core/src/storage/") ||
@@ -212,7 +231,7 @@ async function main() {
const rel = relative(repoRoot, path).split(sep).join("/");
if (isTestFile(rel)) continue;
const found = scan(rel, await readFile(path, "utf8"));
- findings.push(...found.filter((f) => !allowed(rel, f.rule)));
+ findings.push(...withoutAllowed(rel, found));
}
if (writeBaseline) {