diff --git a/webui/src/views.tsx b/webui/src/views.tsx index a913196e7..cb1e4dced 100644 --- a/webui/src/views.tsx +++ b/webui/src/views.tsx @@ -4088,6 +4088,8 @@ export type EventStreamStatus = { retryIntervalMs: number; }; +const DIAGNOSTIC_BUNDLE_CONFIRM = "PRIVATE"; + export function DiagnosticsView(props: { app: unknown; capabilities: unknown; @@ -4098,6 +4100,7 @@ export function DiagnosticsView(props: { }) { const [crashConfirm, setCrashConfirm] = useState(""); const [shutdownConfirm, setShutdownConfirm] = useState(""); + const [bundleConfirm, setBundleConfirm] = useState(""); const [bundleFileName, setBundleFileName] = useState(""); const diagnostics = props.runtimeDiagnostics ?? {}; const eventStream = props.eventStreamStatus; @@ -4137,8 +4140,24 @@ export function DiagnosticsView(props: {

Diagnostics

-
- diff --git a/webui/tests/unit/diagnostics-view.test.tsx b/webui/tests/unit/diagnostics-view.test.tsx index c06a0f3b9..15591c183 100644 --- a/webui/tests/unit/diagnostics-view.test.tsx +++ b/webui/tests/unit/diagnostics-view.test.tsx @@ -10,51 +10,103 @@ afterEach(() => { vi.unstubAllGlobals(); }); +const bundle = { + schema: "emulebb.diagnostic-bundle.v5", + capturedAt: "2026-10-25T12:34:56Z", + summary: { artifactFileCount: 1, missingArtifactFamilies: [], issueCount: 0 } +}; + +function renderView() { + const client = new RestClient(); + const post = vi.spyOn(client, "post").mockResolvedValue(bundle); + const createObjectURL = vi.fn(() => "blob:diagnostic-bundle"); + const revokeObjectURL = vi.fn(); + vi.stubGlobal("URL", class extends URL { + static createObjectURL = createObjectURL; + static revokeObjectURL = revokeObjectURL; + }); + let downloadedFileName = ""; + vi.spyOn(HTMLAnchorElement.prototype, "click").mockImplementation(function (this: HTMLAnchorElement) { + downloadedFileName = this.download; + }); + const run = vi.fn(async (operation: () => Promise) => { await operation(); }); + + render( + + ); + + return { + post, + createObjectURL, + revokeObjectURL, + run, + downloadedFileName: () => downloadedFileName, + captureButton: () => screen.getByRole("button", { name: "Capture bundle" }), + acknowledgementInput: () => screen.getByPlaceholderText("Type PRIVATE") + }; +} + describe("DiagnosticsView", () => { - it("downloads caller-owned inline diagnostic bundles", async () => { - const bundle = { - schema: "emulebb.diagnostic-bundle.v5", - capturedAt: "2026-10-25T12:34:56Z", - summary: { artifactFileCount: 1, missingArtifactFamilies: [], issueCount: 0 } - }; - const client = new RestClient(); - const post = vi.spyOn(client, "post").mockResolvedValue(bundle); - const createObjectURL = vi.fn(() => "blob:diagnostic-bundle"); - const revokeObjectURL = vi.fn(); - vi.stubGlobal("URL", class extends URL { - static createObjectURL = createObjectURL; - static revokeObjectURL = revokeObjectURL; - }); - let downloadedFileName = ""; - vi.spyOn(HTMLAnchorElement.prototype, "click").mockImplementation(function (this: HTMLAnchorElement) { - downloadedFileName = this.download; - }); - - render( - { await operation(); }} - /> - ); - - fireEvent.click(screen.getByRole("button", { name: "Capture bundle" })); + it("discloses bundle privacy before any capture", () => { + const { captureButton } = renderView(); + + expect(screen.getByText(/Private bundle:/)).toBeInTheDocument(); + expect(screen.getByText(/API key/)).toBeInTheDocument(); + expect(screen.getByText(/not for sharing/)).toBeInTheDocument(); + expect(captureButton()).toBeDisabled(); + }); + + it("blocks capture until the acknowledgement phrase is typed", () => { + const { post, createObjectURL, run, captureButton, acknowledgementInput } = renderView(); + + fireEvent.input(acknowledgementInput(), { target: { value: "private" } }); + + expect(captureButton()).toBeDisabled(); + expect(post).not.toHaveBeenCalled(); + expect(createObjectURL).not.toHaveBeenCalled(); + expect(run).not.toHaveBeenCalled(); + expect(screen.queryByText(/Downloaded:/)).not.toBeInTheDocument(); + }); + + it("downloads caller-owned inline diagnostic bundles after acknowledgement", async () => { + const { post, createObjectURL, revokeObjectURL, run, downloadedFileName, captureButton, acknowledgementInput } = renderView(); + + fireEvent.input(acknowledgementInput(), { target: { value: "PRIVATE" } }); + expect(captureButton()).toBeEnabled(); + + fireEvent.click(captureButton()); await waitFor(() => expect(post).toHaveBeenCalledOnce()); expect(post).toHaveBeenCalledWith("diagnostics/bundles", { confirmCapture: true }); expect(createObjectURL).toHaveBeenCalledOnce(); expect(revokeObjectURL).toHaveBeenCalledWith("blob:diagnostic-bundle"); - expect(downloadedFileName).toBe("emulebb-rust-diagnostic-bundle-20261025T123456Z.json"); - expect(screen.getByText(`Downloaded: ${downloadedFileName}`)).toBeInTheDocument(); + expect(downloadedFileName()).toBe("emulebb-rust-diagnostic-bundle-20261025T123456Z.json"); + expect(screen.getByText(`Downloaded: ${downloadedFileName()}`)).toBeInTheDocument(); + expect(run).toHaveBeenCalledWith(expect.any(Function), "Diagnostic bundle downloaded"); + }); + + it("performs no capture and reports no success when not acknowledged", () => { + const { post, createObjectURL, run, captureButton, acknowledgementInput } = renderView(); + + expect(acknowledgementInput()).toHaveValue(""); + expect(captureButton()).toBeDisabled(); + expect(post).not.toHaveBeenCalled(); + expect(createObjectURL).not.toHaveBeenCalled(); + expect(run).not.toHaveBeenCalled(); + expect(screen.queryByText(/Downloaded:/)).not.toBeInTheDocument(); }); });