Skip to content

Commit 092f199

Browse files
committed
test(storage): cover restore test-stream route gate cases
Address CodeRabbit on #571: assert JSON 404 when the stream hook is null under OPENCODEX_CLEANUP_TEST_HOOKS=1, and that the enabled stream path returns the text/plain chunked response.
1 parent c573bd9 commit 092f199

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎tests/storage-restore-job-responsive.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,37 @@ describe("storage trash restore job responsiveness", () => {
8585
}
8686
});
8787

88+
test("test-stream route returns JSON 404 when hooks are enabled but stream is null", async () => {
89+
process.env.OPENCODEX_CLEANUP_TEST_HOOKS = "1";
90+
// enableTestStream omitted → getRestoreTrashTestStreamResponse() returns null
91+
setRestoreTrashJobTestHooks({ blockMs: 0 });
92+
const server = startServer(0);
93+
try {
94+
const res = await fetch(new URL("/api/storage/trash/restore/test-stream", server.url));
95+
expect(res.status).toBe(404);
96+
expect(res.headers.get("content-type") ?? "").toContain("application/json");
97+
expect(await res.json()).toEqual({ error: "not_available" });
98+
} finally {
99+
await server.stop(true);
100+
}
101+
});
102+
103+
test("test-stream route serves the enabled hook stream", async () => {
104+
process.env.OPENCODEX_CLEANUP_TEST_HOOKS = "1";
105+
setRestoreTrashJobTestHooks({ enableTestStream: true });
106+
const server = startServer(0);
107+
try {
108+
const res = await fetch(new URL("/api/storage/trash/restore/test-stream", server.url));
109+
expect(res.status).toBe(200);
110+
expect(res.headers.get("content-type") ?? "").toContain("text/plain");
111+
const body = await res.text();
112+
expect(body).toContain("chunk-0");
113+
expect(body).toContain("chunk-7");
114+
} finally {
115+
await server.stop(true);
116+
}
117+
}, { timeout: 10_000 });
118+
88119
test("blocked worker keeps /healthz and streaming response responsive", async () => {
89120
const blockMs = 1200;
90121
setRestoreTrashJobTestHooks({ blockMs, enableTestStream: true });

0 commit comments

Comments
 (0)