Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

test(daemon): make trace permissions portable on Windows

Gus885c5f12b2ba
diff --git a/src/daemon/src/daemon/createDaemon.test.ts b/src/daemon/src/daemon/createDaemon.test.ts
index 8039e1b99..8d9c43501 100644
--- a/src/daemon/src/daemon/createDaemon.test.ts
+++ b/src/daemon/src/daemon/createDaemon.test.ts
@@ -199,7 +199,10 @@ describe("createDaemon — opt-in raw runtime trace (P0-1)", () => {
const path = join(dir, "runtime-raw-events-%2E%2E%2Fagent_a.jsonl");
expect(readFileSync(path, "utf8")).toBe('{"jsonrpc":"2.0","vendor":"kept"}\n');
- expect(statSync(path).mode & 0o777).toBe(0o600);
+ // Windows cannot express POSIX 0600 via Node mode bits (see credentialProxy.test).
+ if (process.platform !== "win32") {
+ expect(statSync(path).mode & 0o777).toBe(0o600);
+ }
expect(existsSync(join(dir, "runtime-raw-events-agent_b.jsonl"))).toBe(false);
});
@@ -222,7 +225,9 @@ describe("createDaemon — opt-in raw runtime trace (P0-1)", () => {
expect(existsSync(`${a1}.1`)).toBe(true);
expect(readFileSync(a2, "utf8")).toBe("only-a2\n");
for (const path of [a1, `${a1}.1`, a2]) {
- expect(statSync(path).mode & 0o777).toBe(0o600);
+ if (process.platform !== "win32") {
+ expect(statSync(path).mode & 0o777).toBe(0o600);
+ }
expect(statSync(path).size).toBeLessThanOrEqual(20);
}
});
diff --git a/src/daemon/src/util/rotatingFileSink.test.ts b/src/daemon/src/util/rotatingFileSink.test.ts
index 0383f112d..385bf82b8 100644
--- a/src/daemon/src/util/rotatingFileSink.test.ts
+++ b/src/daemon/src/util/rotatingFileSink.test.ts
@@ -9,10 +9,24 @@ vi.mock("node:fs", async (importOriginal) => {
return { ...actual, chmodSync: vi.fn(actual.chmodSync) };
});
+/**
+ * Windows cannot express POSIX 0600 via Node's mode bits (stat typically
+ * reports 0666 after chmod). On win32, prove we invoked chmodSync with the
+ * requested mode; on POSIX, assert the on-disk mode stuck.
+ */
+function expectSecureMode(path: string, mode: number): void {
+ if (process.platform === "win32") {
+ expect(vi.mocked(chmodSync)).toHaveBeenCalledWith(path, mode);
+ return;
+ }
+ expect(statSync(path).mode & 0o777).toBe(mode);
+}
+
describe("createRotatingFileSink (batch E1 — bounded default trace backing)", () => {
let dir: string;
beforeEach(() => {
dir = mkdtempSync(join(tmpdir(), "fsm-sink-"));
+ vi.mocked(chmodSync).mockClear();
});
afterEach(() => {
rmSync(dir, { recursive: true, force: true });
@@ -63,19 +77,24 @@ describe("createRotatingFileSink (batch E1 — bounded default trace backing)",
sink.write("a".repeat(20));
sink.write("latest");
- expect(statSync(path).mode & 0o777).toBe(0o600);
- expect(statSync(`${path}.1`).mode & 0o777).toBe(0o600);
+ expectSecureMode(path, 0o600);
+ // Rotated `.1` keeps the prior active's mode on POSIX; Windows mode bits
+ // are not meaningful after rename, so only assert the active path there.
+ if (process.platform !== "win32") {
+ expect(statSync(`${path}.1`).mode & 0o777).toBe(0o600);
+ }
});
it("secures a pre-existing broad active file before appending", () => {
const path = join(dir, "runtime-raw-events-a1.jsonl");
writeFileSync(path, "old\n");
chmodSync(path, 0o644);
+ vi.mocked(chmodSync).mockClear();
const sink = createRotatingFileSink(path, 100, { mode: 0o600 });
sink.write("new");
- expect(statSync(path).mode & 0o777).toBe(0o600);
+ expectSecureMode(path, 0o600);
expect(readFileSync(path, "utf8")).toBe("old\nnew\n");
});