repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by bugabinga
extensions/chrome-cdp/__tests__/debug.test.ts
Rawimport assert from "node:assert/strict";
import { randomUUID } from "node:crypto";
import { readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { test } from "vitest";
import { DebugLog } from "../debug.ts";
test("private debug log redacts non-CDP methods and refuses readable files", async () => {
const path = join(tmpdir(), `debug-${randomUUID()}.jsonl`);
try {
await writeFile(path, "", { mode: 0o644 });
await assert.rejects(DebugLog.open(path), /group or others/);
await rm(path);
const log = await DebugLog.open(path);
log.record({
event: "cdp.send",
method: "https://secret.example/key",
sessionId: "secret/path",
});
await log.close();
const [row] = (await readFile(path, "utf8"))
.trim()
.split("\n")
.map((line) => JSON.parse(line));
assert.equal(row.method, undefined);
assert.equal(row.sessionId, undefined);
assert.equal(row.event, "cdp.send");
} finally {
await rm(path, { force: true });
}
});