Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions webui/src/views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4088,6 +4088,8 @@ export type EventStreamStatus = {
retryIntervalMs: number;
};

const DIAGNOSTIC_BUNDLE_CONFIRM = "PRIVATE";

export function DiagnosticsView(props: {
app: unknown;
capabilities: unknown;
Expand All @@ -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;
Expand Down Expand Up @@ -4137,8 +4140,24 @@ export function DiagnosticsView(props: {
<div class="section-title">
<h2>Diagnostics</h2>
</div>
<div class="row-actions">
<button class="btn" type="button" onClick={() => void props.run(captureBundle, "Diagnostic bundle downloaded")}>
<p class="hint">
Private bundle: contains your API key, exact settings values, filesystem
paths, content and peer identifiers, recent logs, and diagnostic artifacts.
Not anonymized and not for sharing.
</p>
<div class="form-row danger-row">
<input
class="form-control"
value={bundleConfirm}
placeholder={`Type ${DIAGNOSTIC_BUNDLE_CONFIRM}`}
onInput={(event) => setBundleConfirm(event.currentTarget.value)}
/>
<button
class="btn"
type="button"
disabled={bundleConfirm !== DIAGNOSTIC_BUNDLE_CONFIRM}
onClick={() => void props.run(captureBundle, "Diagnostic bundle downloaded")}
>
<FileText size={15} />
Capture bundle
</button>
Expand Down
132 changes: 92 additions & 40 deletions webui/tests/unit/diagnostics-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>) => { await operation(); });

render(
<DiagnosticsView
app={{}}
capabilities={{}}
runtimeDiagnostics={null}
eventStreamStatus={{
mode: "polling",
enabled: true,
connected: false,
reconnectAttempts: 0,
pollIntervalMs: 1_000,
retryIntervalMs: 1_000
}}
client={client}
run={run}
/>
);

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(
<DiagnosticsView
app={{}}
capabilities={{}}
runtimeDiagnostics={null}
eventStreamStatus={{
mode: "polling",
enabled: true,
connected: false,
reconnectAttempts: 0,
pollIntervalMs: 1_000,
retryIntervalMs: 1_000
}}
client={client}
run={async (operation) => { 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();
});
});
Loading