Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codex/native-profile-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function readBounded(path: string, limit: number, testSeam?: BoundedReadTestSeam
testSeam?.beforeOpen?.(path);
const flags = process.platform === "win32"
? fsConstants.O_RDONLY
: fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW;
: fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK;
fd = openSync(path, flags);
const opened = fstatSync(fd, { bigint: true });
if (!opened.isFile() || opened.size > BigInt(limit)) throw new Error("invalid bounded file");
Expand Down
8 changes: 8 additions & 0 deletions tests/native-profile-store.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { afterEach, describe, expect, test } from "bun:test";
import { execFileSync } from "node:child_process";
import { appendFileSync, mkdirSync, mkdtempSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
Expand Down Expand Up @@ -382,6 +383,13 @@ describe("native-profile recovery journal storage", () => {
expect((caught as NativeProfileError).code).toBe("VAULT_INVALID");
});

test.skipIf(process.platform === "win32")("rejects a vault FIFO without waiting for a writer", () => {
const store = context();
execFileSync("mkfifo", [store.vaultPath]);

expect(() => readNativeProfileVault(store)).toThrow(NativeProfileError);
});

Comment on lines +386 to +392

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Run the FIFO read in a bounded subprocess.

If O_NONBLOCK regresses, readNativeProfileVault(store) can block inside openSync while waiting for a writer. The synchronous call prevents toThrow from completing, so the test process can hang instead of reporting a failure.

Execute the vault read in a child process with an OS-level timeout. Assert that the child reports the expected NativeProfileError before the deadline. Do not rely on a JavaScript timer around the current synchronous call.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/native-profile-store.test.ts` around lines 386 - 392, Update the
skipped FIFO test around readNativeProfileVault to execute the vault read in a
child process with an OS-level timeout, preventing openSync from hanging the
test runner when no writer exists. Assert that the child exits before the
deadline and reports NativeProfileError, rather than wrapping the synchronous
call in toThrow or relying on a JavaScript timer.

test("reads at most journal cap plus one when the opened journal grows after fstat", () => {
const store = context();
const initial = serializeNativeProfileJournal(journal());
Expand Down
Loading