Files
ThothII/docker/ensure-pi-trust.test.mjs

22 lines
924 B
JavaScript

import assert from "node:assert/strict";
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { ensurePiTrust } from "./ensure-pi-trust.mjs";
test("adds the canonical harness path and preserves existing trust entries", () => {
const root = mkdtempSync(join(tmpdir(), "thothii-pi-trust-"));
const agentDir = join(root, "agent");
ensurePiTrust("/first/harness", agentDir);
writeFileSync(
join(agentDir, "trust.json"),
`${JSON.stringify({ "/existing/project": true }, null, 2)}\n`,
);
assert.equal(ensurePiTrust("/app/harness/../harness", agentDir), true);
const trust = JSON.parse(readFileSync(join(agentDir, "trust.json"), "utf8"));
assert.deepEqual(trust, { "/existing/project": true, "/app/harness": true });
assert.equal(ensurePiTrust("/app/harness", agentDir), false);
});