fix(studio): allow sixty seconds for AI generation

This commit is contained in:
Clintchiz committed 2026-10-19 14:29:15 +05:30
1 parent fac1c4461f
commit 27dcb561db
7 files changed
+60 -12

No files matched your search

+45 -1
View File
@@ -1,7 +1,11 @@
import { expect, test } from "bun:test";
import { CORE_DESIGN_SYSTEMS } from "@wrnexus/design-system";
import { designRevision, DEFAULT_DESIGN_BRIEF } from "@wrnexus/design-studio";
import { apimartProvider, studioAI } from "../app/lib/studio-ai.ts";
import {
AI_TIMEOUT_MS,
apimartProvider,
studioAI,
} from "../app/lib/studio-ai.ts";
import { addStudioGuide } from "../app/lib/studio-guide.ts";
const proposals = ["2px", "4px", "8px"].map((value, index) => ({
@@ -110,6 +114,8 @@ test("metadata and errors never contain the key or raw upstream response", async
);
const text = await meta!.text();
expect(text).toContain("gpt-6-luna");
expect(JSON.parse(text).timeoutMs).toBe(AI_TIMEOUT_MS);
expect(AI_TIMEOUT_MS).toBe(60_000);
expect(text).not.toContain("test-secret");
const failure = await handler(await request());
const body = await failure!.text();
@@ -118,6 +124,44 @@ test("metadata and errors never contain the key or raw upstream response", async
expect(body).toContain("WRN-STUDIO-PROVIDER");
});
test("a completion beyond the old 20-second deadline produces three validated alternatives", async () => {
const handler = studioAI(
"test-secret",
mockFetch(async (_url, init) => {
await Bun.sleep(21_000);
expect(init?.signal?.aborted).toBe(false);
return completion();
}),
);
const original = JSON.stringify(system);
const response = await handler(await request());
expect(response!.status).toBe(200);
const batch = await response!.json();
expect(batch.alternatives).toHaveLength(3);
expect(batch.provenance.provider).toBe("APIMart");
expect(JSON.stringify(system)).toBe(original);
}, 30_000);
test("cancellation still aborts the upstream request and keeps the draft unchanged", async () => {
const controller = new AbortController();
const handler = studioAI(
"test-secret",
mockFetch(async (_url, init) => {
controller.abort();
expect(init?.signal?.aborted).toBe(true);
throw new DOMException("Cancelled", "AbortError");
}),
);
const original = JSON.stringify(system);
const base = await request();
const response = await handler(
new Request(base, { signal: controller.signal }),
);
expect(response!.status).toBe(408);
expect(await response!.text()).toContain("draft is unchanged");
expect(JSON.stringify(system)).toBe(original);
});
test("same-origin checks, body bounds and local fallback remain enforced", async () => {
let calls = 0;
const handler = studioAI(