feat(core): surface mid-session transport failures via lastError (#1489)
Closes #1323. Adds an `error`-event-driven `lastError` on useInspectorClient and a mid-session failure toast in App.tsx; the transport onerror is scoped to non-handshake (status !== connecting) so handshake failures stay on the connect() rejection path. Follow-up: #1490.
This commit is contained in:
parent
bb32d1db5f
commit
b4716a1405
1 changed files with 398 additions and 7 deletions
|
|
@ -707,6 +707,60 @@ describe("App network-log body-dropped toast", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("App mid-session error toast", () => {
|
||||
beforeEach(() => {
|
||||
clientInstances.length = 0;
|
||||
notificationsMock.show.mockClear();
|
||||
vi.mocked(useInspectorClient).mockReturnValue(DEFAULT_USE_INSPECTOR_CLIENT);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.mocked(useInspectorClient).mockReturnValue(DEFAULT_USE_INSPECTOR_CLIENT);
|
||||
});
|
||||
|
||||
it("toasts the lastError with a generic title when no server is active", () => {
|
||||
// `lastError` is set but nothing has been connected, so the active-server
|
||||
// name ref is empty and the toast falls back to "Connection lost".
|
||||
vi.mocked(useInspectorClient).mockReturnValue({
|
||||
...DEFAULT_USE_INSPECTOR_CLIENT,
|
||||
lastError: "stdio subprocess crashed",
|
||||
});
|
||||
renderWithMantine(<App />);
|
||||
|
||||
expect(notificationsMock.show).toHaveBeenCalledTimes(1);
|
||||
const shown = notificationsMock.show.mock.calls[0][0];
|
||||
expect(shown.title).toBe("Connection lost");
|
||||
expect(shown.message).toBe("stdio subprocess crashed");
|
||||
expect(shown.color).toBe("red");
|
||||
});
|
||||
|
||||
it("names the active server in the toast after a session has connected", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(<App />);
|
||||
|
||||
// Connect first so the active-server name ref is populated with SERVER_A.
|
||||
await user.click(screen.getByText("connect"));
|
||||
await waitFor(() => expect(clientInstances).toHaveLength(1));
|
||||
|
||||
// The transport now dies mid-session: `lastError` becomes set and the
|
||||
// client's `disconnect` event clears the active server. The name ref
|
||||
// survives, so the toast still names the server (PlotRocket).
|
||||
vi.mocked(useInspectorClient).mockReturnValue({
|
||||
...DEFAULT_USE_INSPECTOR_CLIENT,
|
||||
lastError: "SSE stream dropped",
|
||||
});
|
||||
act(() => {
|
||||
clientInstances[0].dispatchEvent(new CustomEvent("disconnect"));
|
||||
});
|
||||
|
||||
await waitFor(() => expect(notificationsMock.show).toHaveBeenCalled());
|
||||
const shown = notificationsMock.show.mock.calls.at(-1)?.[0];
|
||||
expect(shown.title).toBe('Connection to "PlotRocket" lost');
|
||||
expect(shown.message).toBe("SSE stream dropped");
|
||||
expect(shown.color).toBe("red");
|
||||
});
|
||||
});
|
||||
|
||||
describe("App pending server-initiated request modal", () => {
|
||||
beforeEach(() => {
|
||||
clientInstances.length = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue