Repository navigation
fix(lab): surface CL-05 partial-read failures #1715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6e23061
test(lab): cover compatibility follow-up regressions
Wibias 5f59416
fix(lab): surface partial compatibility reads
Wibias a4cdf38
test(lab): verify load-more retry recovery
Wibias ae5498e
test(lab): avoid hardcoded retry error text
Wibias 05fcadf
fix(gui): allowlist HTTP protocol token
Wibias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| /** @jsxImportSource react */ | ||
| import { afterEach, beforeEach, expect, test } from "bun:test"; | ||
| import { Window } from "happy-dom"; | ||
| import { act } from "react"; | ||
| import type { Root } from "react-dom/client"; | ||
| import { LanguageProvider } from "../src/i18n/provider"; | ||
| import CompatibilityMatrix from "../src/pages/CompatibilityMatrix"; | ||
| import { clearClientResourceStoresForTests } from "../src/client-resource"; | ||
|
|
||
| const originalFetch = globalThis.fetch; | ||
| let restoreGlobals: (() => void) | undefined; | ||
| let previousLanguageDescriptor: PropertyDescriptor | undefined; | ||
| let testWindow: Window; | ||
|
|
||
| const API_BASE = "http://127.0.0.1:4096"; | ||
|
|
||
| const STATUS_AVAILABLE = { | ||
| projectionAvailable: true, | ||
| subjectCount: 1, | ||
| verdictCount: 1, | ||
| observationCount: 0, | ||
| eventCount: 2, | ||
| builtAtMs: 1_700_000_000_000, | ||
| }; | ||
|
|
||
| const SUBJECTS = { | ||
| subjects: [{ subjectId: "subject-alpha", subjectKind: "protocol" }], | ||
| hasMore: false, | ||
| }; | ||
|
|
||
| const SUBJECT_DETAIL = { | ||
| subject: { | ||
| subjectKind: "protocol", | ||
| subjectSchemaVersion: 1, | ||
| inboundProtocol: "openai-chat", | ||
| }, | ||
| }; | ||
|
|
||
| const EVENT_DETAIL = { | ||
| event: { | ||
| eventKind: "observation", | ||
| eventId: "e1", | ||
| recordedAt: 1_700_000_000_040, | ||
| producer: "lab", | ||
| producerVersion: "1", | ||
| subjectId: "subject-alpha", | ||
| evidenceLayer: "protocol_conformance", | ||
| suiteId: "responses-core", | ||
| outcome: "pass", | ||
| excluded: false, | ||
| exclusionReason: null, | ||
| }, | ||
| }; | ||
|
|
||
| function verdictPage(eventIds: string[]) { | ||
| return { | ||
| verdicts: [{ | ||
| projectionKey: "k1", | ||
| subjectId: "subject-alpha", | ||
| evidenceLayer: "protocol_conformance", | ||
| suiteId: "responses-core", | ||
| suiteVersion: "1", | ||
| suiteManifestDigest: "digest-a", | ||
| projectionSpecVersion: "cl-02.v1", | ||
| verdict: "VERIFIED", | ||
| asOf: 1_700_000_000_100, | ||
| scenarioManifestDigests: [], | ||
| claimSourceDigest: null, | ||
| contributingEventIds: eventIds, | ||
| contradictingEventIds: [], | ||
| notes: [], | ||
| }], | ||
| hasMore: true, | ||
| nextCursor: "cursor-2", | ||
| }; | ||
| } | ||
|
|
||
| type FetchOptions = { | ||
| failLoadMore?: boolean; | ||
| partialEvents?: boolean; | ||
| }; | ||
|
|
||
| function installLabFetch(opts: FetchOptions = {}) { | ||
| globalThis.fetch = (async (input: RequestInfo | URL) => { | ||
| const url = String(input); | ||
| if (url.endsWith("/api/lab/status")) return Response.json(STATUS_AVAILABLE); | ||
| if (url.includes("/api/lab/verdicts")) { | ||
| if (url.includes("cursor=cursor-2")) { | ||
| if (opts.failLoadMore) return new Response("unavailable", { status: 503 }); | ||
| return Response.json({ verdicts: [], hasMore: false }); | ||
| } | ||
| return Response.json(verdictPage(opts.partialEvents ? ["e1", "missing-event"] : ["e1"])); | ||
| } | ||
| if (url.includes("/api/lab/subjects/subject-alpha")) return Response.json(SUBJECT_DETAIL); | ||
| if (url.includes("/api/lab/subjects")) return Response.json(SUBJECTS); | ||
| if (url.includes("/api/lab/observations")) return Response.json({ observations: [], hasMore: false }); | ||
| if (url.includes("/api/lab/events/e1")) return Response.json(EVENT_DETAIL); | ||
| if (url.includes("/api/lab/events/missing-event")) return new Response("gone", { status: 404 }); | ||
| if (url.includes("/api/lab/artifacts/")) return new Response("gone", { status: 404 }); | ||
| if (url.includes("/api/lab/production-signals")) return new Response("gone", { status: 404 }); | ||
| return new Response("{}", { status: 404 }); | ||
| }) as typeof fetch; | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| clearClientResourceStoresForTests(); | ||
| testWindow = new Window({ url: "http://localhost/#models/compatibility" }); | ||
| previousLanguageDescriptor = Object.getOwnPropertyDescriptor(globalThis.navigator, "language"); | ||
| Object.defineProperty(globalThis.navigator, "language", { configurable: true, value: "en-US" }); | ||
| const keys = ["document", "window", "localStorage", "IS_REACT_ACT_ENVIRONMENT"] as const; | ||
| const previous = Object.fromEntries( | ||
| keys.map(key => [key, Object.getOwnPropertyDescriptor(globalThis, key)]), | ||
| ) as Record<(typeof keys)[number], PropertyDescriptor | undefined>; | ||
| Object.defineProperties(globalThis, { | ||
| document: { configurable: true, value: testWindow.document }, | ||
| window: { configurable: true, value: testWindow }, | ||
| localStorage: { configurable: true, value: testWindow.localStorage }, | ||
| IS_REACT_ACT_ENVIRONMENT: { configurable: true, value: true }, | ||
| }); | ||
| restoreGlobals = () => { | ||
| for (const key of keys) { | ||
| const descriptor = previous[key]; | ||
| if (descriptor) Object.defineProperty(globalThis, key, descriptor); | ||
| else delete (globalThis as Record<string, unknown>)[key]; | ||
| } | ||
| if (previousLanguageDescriptor) { | ||
| Object.defineProperty(globalThis.navigator, "language", previousLanguageDescriptor); | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| restoreGlobals?.(); | ||
| globalThis.fetch = originalFetch; | ||
| clearClientResourceStoresForTests(); | ||
| testWindow.close(); | ||
| }); | ||
|
|
||
| async function waitFor(predicate: () => boolean, timeoutMs = 3000): Promise<void> { | ||
| const start = Date.now(); | ||
| while (!predicate()) { | ||
| if (Date.now() - start > timeoutMs) throw new Error("waitFor timed out"); | ||
| await act(async () => { | ||
| await new Promise<void>(resolve => testWindow.setTimeout(resolve, 10)); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| async function renderMatrix(): Promise<{ root: Root; container: HTMLDivElement }> { | ||
| const { createRoot } = await import("react-dom/client"); | ||
| const container = testWindow.document.createElement("div"); | ||
| testWindow.document.body.appendChild(container); | ||
| const root = createRoot(container); | ||
| await act(async () => { | ||
| root.render(<LanguageProvider><CompatibilityMatrix apiBase={API_BASE} /></LanguageProvider>); | ||
| }); | ||
| return { root, container }; | ||
| } | ||
|
|
||
| test("load-more failures stay visible while the loaded rows remain retryable", async () => { | ||
| installLabFetch({ failLoadMore: true }); | ||
| const { root, container } = await renderMatrix(); | ||
| await waitFor(() => container.querySelector(".lab-load-more button") !== null); | ||
| const button = container.querySelector(".lab-load-more button") as HTMLButtonElement; | ||
| await act(async () => { button.click(); }); | ||
| await waitFor(() => container.querySelector(".notice-err")?.textContent?.includes("HTTP 503") ?? false); | ||
| expect(container.textContent).toContain("Verified"); | ||
| expect(container.querySelector(".lab-load-more button")).not.toBeNull(); | ||
| await act(async () => root.unmount()); | ||
| }); | ||
|
|
||
| test("verdict detail reports when referenced evidence events are only partially available", async () => { | ||
| installLabFetch({ partialEvents: true }); | ||
| const { root, container } = await renderMatrix(); | ||
| await waitFor(() => container.querySelector('button[data-verdict-detail="k1"]') !== null); | ||
| const button = container.querySelector('button[data-verdict-detail="k1"]') as HTMLButtonElement; | ||
| await act(async () => { button.click(); }); | ||
| await waitFor(() => container.querySelector(".lab-detail-pane")?.textContent?.includes("Evidence events (1/2)") ?? false); | ||
| expect(container.querySelector(".lab-detail-pane")?.textContent).toContain("Evidence events (1/2)"); | ||
| await act(async () => root.unmount()); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.