Skip to content

Commit 60197f5

Browse files
test(claude): cover connection-owned store reads against a swap-to-FIFO refusal
Co-Authored-By: Epinephrine <[email protected]>
1 parent cfe7646 commit 60197f5

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

‎tests/clients/desktop-remote-store.test.ts‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { removeDesktop3pStandardPivot, writeDesktop3pConfig } from "../../src/claude/desktop-3p";
22
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
3-
import { existsSync, mkdirSync, mkdtempSync, realpathSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
3+
import { spawnSync } from "node:child_process";
4+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, realpathSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
45
import { join } from "node:path";
56
import { tmpdir } from "node:os";
67
import * as configIO from "../../src/config";
8+
import { repoPath } from "../helpers/repo-root";
79
import { saveConfig, loadConfig, readConfigDiagnostics, atomicWriteFile } from "../../src/config";
810
import { withClientLifecycleSync, type ClientLifecycleHeld } from "../../src/client/lifecycle-lock";
911
import { serviceApiTokenFingerprint, writeServiceApiTokenFile, replaceServiceApiTokenFile, writeTokenBackup, serviceApiTokenBackupPath, removeServiceApiTokenFileIfOwned } from "../../src/lib/service-secrets";
@@ -359,4 +361,37 @@ describe("connection-owned Desktop projection store", () => {
359361
expect(readDesktopDisconnectReceipt()).toMatchObject({ kind: "valid", value: { phase: "complete" } });
360362
expect(inspectRemoteDesktopCleanup().kind).toBe("absent");
361363
});
364+
365+
test.skipIf(process.platform === "win32")("a regular-to-FIFO swap during a store read is refused and classified unsafe", () => {
366+
const target = join(library, "original.json");
367+
const fifo = join(dir, "store-read-replacement");
368+
writeFileSync(target, "{}\n");
369+
expect(spawnSync("mkfifo", [fifo], { timeout: 5000 }).status).toBe(0);
370+
// Bound the parent even if a regression reintroduces a blocking open: the child swaps the
371+
// regular profile for the FIFO at the shared reader's open, then performs the store read.
372+
// "unsafe" is the store's classification of the reader refusal; "conflict" would mean only
373+
// the post-read identity recheck fired, and a hang is killed by the child timeout.
374+
const code = `import { spyOn } from "bun:test";
375+
import * as fs from "node:fs";
376+
import { StoreIO } from ${JSON.stringify(repoPath("src/claude/desktop-remote-store-io.ts"))};
377+
import { DesktopStoreError } from ${JSON.stringify(repoPath("src/claude/desktop-remote-store-state.ts"))};
378+
const open = fs.openSync;
379+
spyOn(fs, "openSync").mockImplementation((path, flags, mode) => {
380+
if (path === ${JSON.stringify(target)}) fs.renameSync(${JSON.stringify(fifo)}, path);
381+
return open(path, flags, mode);
382+
});
383+
try {
384+
new StoreIO().read(${JSON.stringify(target)});
385+
console.log("read_not_refused");
386+
} catch (error) {
387+
console.log(error instanceof DesktopStoreError ? error.reason : "unexpected_error");
388+
}`;
389+
const child = spawnSync(process.execPath, ["--no-env-file", "-e", code], {
390+
env: { ...process.env }, encoding: "utf8", timeout: 10000, maxBuffer: 1024 * 1024,
391+
});
392+
expect(child.error).toBeUndefined();
393+
expect(child.status).toBe(0);
394+
expect(child.stdout.trim()).toBe("unsafe");
395+
expect(lstatSync(target).isFIFO()).toBe(true);
396+
}, 20000);
362397
});

0 commit comments

Comments
 (0)