Files
OmniRoute/tests/unit/ui/playViewCombinedError.test.tsx
Diego Rodrigues de Sa e Souza 2e872c50aa fix(dashboard): surface combined-pipeline error in Compression Studio Run (#12061) (#13288)
Merged as part of the 39-PR owner batch of 2026-09-11, validated as a unit.

Boarded into one consolidated worktree cut from `release/v3.8.51` with the other 38 — zero conflicts between them.

- ESLint over every changed file: no errors (the only finding was one suppression entry the batch emptied, pruned on #13243)
- `typecheck:core` clean; `check:dashboard-typecheck` OK (206 pre-existing, within baseline); `check:changelog-integrity` OK
- complexity 2821 / baseline 3218 and cognitive-complexity 1272 / baseline 1437 — both under baseline
- 256 assertions green: 246 under node:test and 10 under vitest, which is where `tests/unit/**/*.test.tsx` actually runs
- `check-file-size`: `chatCore.ts` rebaselined 6144 → 6146 for #13278 and #13276, annotated and landed on #13243

⚠️ base-red inherited: #12732 — the provider count (356 in the docs vs the 358 the modules define) and `open-sse/utils/stream.ts` at 3115 > frozen 3098 both reproduce on the pure tip with zero contribution from this batch.
2026-09-11 22:05:34 -03:00

105 lines
3.6 KiB
TypeScript

// @vitest-environment jsdom
// Regression for #12061: when the COMBINED-pipeline preview request fails
// (while per-lane requests succeed), PlayView must surface a visible error
// instead of silently rendering nothing for the combined result section.
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { createRoot, type Root } from "react-dom/client";
import { act } from "react";
let container: HTMLElement;
let root: Root;
beforeEach(() => {
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
(globalThis as any).ResizeObserver ||= class {
observe() {}
unobserve() {}
disconnect() {}
};
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
// Per-lane requests (body.engineId set) succeed; the combined pipeline
// request (body.pipeline set) fails -- e.g. an auth/backend error on the
// combined-stack call specifically.
vi.stubGlobal(
"fetch",
vi.fn(async (_u: string, init: any) => {
const body = JSON.parse(init.body);
if (body.pipeline) {
return { ok: false, status: 500, json: async () => ({ error: "internal error" }) } as any;
}
const engine = body.engineId ?? "combo";
return {
ok: true,
json: async () => ({
original: "o",
compressed: "c",
originalTokens: 10,
compressedTokens: 6,
savingsPct: 40,
mode: "stacked",
durationMs: 1,
engineBreakdown: [
{ engine, originalTokens: 10, compressedTokens: 6, savingsPercent: 40, techniquesUsed: [] },
],
diff: [],
preservedBlocks: [],
ruleRemovals: [],
validation: { valid: true, errors: [], warnings: [], fallbackApplied: false },
}),
} as any;
})
);
});
afterEach(() => {
act(() => root.unmount());
container.remove();
document.body.innerHTML = "";
vi.restoreAllMocks();
});
describe("PlayView combined-pipeline run failure (#12061)", () => {
it("shows a visible error for the combined result instead of nothing", async () => {
const { PlayView } = await import(
"@/app/(dashboard)/dashboard/compression/studio/PlayView"
);
await act(async () => {
root.render(
<PlayView text="TEST INPUT" onText={() => {}} laneEngines={["rtk", "caveman"]} />
);
});
const runBtn = container.querySelector('[data-testid="play-run"]') as HTMLButtonElement;
expect(runBtn).toBeTruthy();
await act(async () => {
runBtn.dispatchEvent(new MouseEvent("click", { bubbles: true }));
});
await act(async () => {
await Promise.resolve();
await Promise.resolve();
await Promise.resolve();
});
// Per-lane previews succeeded -- lanes should show savings, not "error".
const laneRows = Array.from(container.querySelectorAll('[data-testid="play-lane"]'));
expect(laneRows.length).toBe(2);
for (const row of laneRows) {
expect(row.textContent ?? "").not.toMatch(/error/i);
}
// The combined section (success branch) never renders since the
// combined request failed.
const combinedSection = container.querySelector('[data-testid="play-combined"]');
expect(combinedSection).toBeNull();
const hasErrorTestId = !!container.querySelector(
'[data-testid="play-run-error"], [data-testid="play-combined-error"], [data-testid="play-error"]'
);
const text = container.textContent ?? "";
const hasHumanReadableError = /error|failed|falhou|erro/i.test(text);
expect(hasErrorTestId || hasHumanReadableError).toBe(true);
});
});