Files
Jyotisha/frontend/tests/helpers/report-export-code-stub.ts
ClaudeandClaude Opus 5.5 ce165ed00c
Independent Staging Quality Gate / validate-python (push) Successful in 7m38s
Independent Staging Quality Gate / validate-frontend (push) Failing after 6m16s
Independent Staging Quality Gate / publish (push) Skipped
fix(export): fetch the export code when the sheet opens; the click writes the file synchronously and never blocks on the code (BUG-2359)
Mobile Safari and WeChat drop a download started after an await. The export
sheet now asks for its code on open; the click marks and downloads at once,
then confirms the code in the background (confirm_report_export: edition,
scope, exported_at). With no code at hand the file is exported unmarked, no
error toast, and the server logs one [ops-signal] export_unmarked line
(monitor threshold 3 per window, Feishu wording added).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
2026-11-26 13:14:49 +08:00

23 lines
1.3 KiB
TypeScript

// BUG-2359: the export sheet asks POST /api/report-exports for a code when it opens, then confirms
// it (or reports an unmarked file) after the click. Component tests answer those requests; every
// other fetch is left alone. `offline` makes the code request fail like a dropped network.
export const STUB_EXPORT_CODE = "0f1e2d3c4b5a69788796a5b4";
export type ExportCodeStub = { restore: () => void; bodies: Record<string, unknown>[] };
export function installReportExportCodeStub(options: { offline?: boolean } = {}): ExportCodeStub {
const original = globalThis.fetch;
const bodies: Record<string, unknown>[] = [];
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
if (String(input) === "/api/report-exports") {
const body = JSON.parse(String(init?.body ?? "{}")) as Record<string, unknown>;
bodies.push(body);
if (options.offline && body.action === "issue") throw new TypeError("Failed to fetch");
if (body.action === "issue") return new Response(JSON.stringify({ exportId: STUB_EXPORT_CODE }), { status: 200 });
return new Response(null, { status: body.action === "unmarked" ? 204 : 200 });
}
return original(input, init);
}) as typeof fetch;
return { restore: () => { globalThis.fetch = original; }, bodies };
}