* fix(core): trace dropped fetch body update when entry rotates out (#1390) FetchRequestLogState.onFetchRequestBodyUpdate silently dropped a deferred response-body update when the matching entry had already been evicted by log rotation (>= maxFetchRequests newer requests appended between the append and the fire-and-forget body read). The user saw an empty Response Body with no way to distinguish "body never came back" from "body dropped after eviction". Plumb an optional pino logger into FetchRequestLogState (defaulting to the silent logger) and emit a logger.debug at the early-return site so the drop is traceable. The web client wires the existing remote logger from createWebEnvironment into the state manager. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(core): emit dropped-body trace at warn level so it is observable (#1390) Review feedback: the web remote logger (createRemoteLogger) defaults to level 'info' with no override at the environmentFactory call site, so a logger.debug at the drop site is filtered out by both the pino level gate and transmit.level — the diagnostic never reaches /api/log and the drop stays invisible in the shipped web app, defeating the issue's goal. Promote the trace to logger.warn (>= info, so it transmits by default). A response body lost to log rotation is unexpected data loss, not routine diagnostic noise, so warn is the appropriate severity. Update the comment to explain the level choice and switch the test stub from debug to warn, extracting a small typed makeWarnLogger helper per review. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(web): configurable Network Log Size per server + body-dropped toast (#1390) Turn the otherwise-invisible "response body dropped after rotation" case into an actionable signal: 1. Per-server `maxFetchRequests` setting (default 1000, 0 = unlimited), editable as "Network Log Size" in the first (Options) accordion section of the Server Settings form. Plumbed through the full settings pipeline: InspectorServerSettings + StoredMCPServer types, the serverList disk converters (read defaults to 1000, write omits the default to keep diffs minimal — 0 is a meaningful non-default), and the node server's GET-sanitize + write-side validateSettings (non-negative number). Applied live to the active connection on settings-modal close via a new FetchRequestLogState.setMaxFetchRequests (shrinking trims immediately), and at connect time for the next session. 2. FetchRequestLogState now emits a `fetchRequestBodyDropped` event, but only for genuine rotation drops (log at capacity with a finite cap) — not for benign post-clear stragglers or unlimited logs, which previously also hit the warn path. App shows a deduped, persistent toast (stable per-server id, no auto-close) explaining what happened and the likely causes, with a link that opens this server's settings on the Options section (modal remounts via key) so the user can raise the limit if it's just a high-traffic server. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(web): don't treat a cleared Network Log Size field as unlimited (#1390) Review feedback: clearing the NumberInput emits "", and `parseInt("") || 0` coerced that to 0 (unlimited). Since the value applies live on modal close, a user who cleared the field to retype and then closed the modal would silently switch the log to unlimited. Fall back to the current value on an empty/NaN parse and reserve 0 for an explicit numeric entry. Adds a cleared-input test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ef921ba052
commit
53dc4549be
1 changed files with 717 additions and 13 deletions
|
|
@ -122,11 +122,25 @@ vi.mock("@inspector/core/mcp/state/messageLogState.js", () => ({
|
|||
return { destroy: vi.fn(), clearMessages: messageLogClear };
|
||||
}),
|
||||
}));
|
||||
vi.mock("@inspector/core/mcp/state/fetchRequestLogState.js", () => ({
|
||||
FetchRequestLogState: vi.fn(function () {
|
||||
return { destroy: vi.fn(), getFetchRequests: vi.fn(() => []) };
|
||||
}),
|
||||
}));
|
||||
// Extends EventTarget so the App's `fetchRequestBodyDropped` subscription is
|
||||
// real; the test fires `dispatchEvent(new CustomEvent("fetchRequestBodyDropped",
|
||||
// { detail }))` on the tracked instance to drive the body-dropped toast.
|
||||
vi.mock("@inspector/core/mcp/state/fetchRequestLogState.js", () => {
|
||||
class FakeFetchRequestLogState extends EventTarget {
|
||||
destroy = vi.fn();
|
||||
getFetchRequests = vi.fn(() => []);
|
||||
setMaxFetchRequests = vi.fn();
|
||||
}
|
||||
const instances: FakeFetchRequestLogState[] = [];
|
||||
return {
|
||||
FetchRequestLogState: vi.fn(function () {
|
||||
const inst = new FakeFetchRequestLogState();
|
||||
instances.push(inst);
|
||||
return inst;
|
||||
}),
|
||||
__fetchLogInstances: instances,
|
||||
};
|
||||
});
|
||||
vi.mock("@inspector/core/mcp/state/stderrLogState.js", () => ({
|
||||
StderrLogState: vi.fn(function () {
|
||||
return { destroy: vi.fn() };
|
||||
|
|
@ -387,6 +401,7 @@ vi.mock("./components/views/InspectorView/InspectorView", () => ({
|
|||
|
||||
import App from "./App";
|
||||
import * as McpIndex from "@inspector/core/mcp/index.js";
|
||||
import * as FetchLogModule from "@inspector/core/mcp/state/fetchRequestLogState.js";
|
||||
import { useManagedRequestorTasks } from "@inspector/core/react/useManagedRequestorTasks.js";
|
||||
import { useMessageLog } from "@inspector/core/react/useMessageLog.js";
|
||||
import { useInspectorClient } from "@inspector/core/react/useInspectorClient.js";
|
||||
|
|
@ -413,6 +428,10 @@ const clientInstances = (
|
|||
McpIndex as unknown as { __clientInstances: EventTarget[] }
|
||||
).__clientInstances;
|
||||
|
||||
const fetchLogInstances = (
|
||||
FetchLogModule as unknown as { __fetchLogInstances: EventTarget[] }
|
||||
).__fetchLogInstances;
|
||||
|
||||
describe("App session-scoped state reset on disconnect", () => {
|
||||
beforeEach(() => {
|
||||
clientInstances.length = 0;
|
||||
|
|
@ -623,6 +642,71 @@ describe("App tool progress toasts", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("App network-log body-dropped toast", () => {
|
||||
beforeEach(() => {
|
||||
clientInstances.length = 0;
|
||||
fetchLogInstances.length = 0;
|
||||
notificationsMock.show.mockClear();
|
||||
notificationsMock.hide.mockClear();
|
||||
});
|
||||
|
||||
it("shows a deduped toast when the fetch log emits fetchRequestBodyDropped", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(<App />);
|
||||
|
||||
await user.click(screen.getByText("connect"));
|
||||
await waitFor(() => expect(fetchLogInstances).toHaveLength(1));
|
||||
|
||||
act(() => {
|
||||
fetchLogInstances[0].dispatchEvent(
|
||||
new CustomEvent("fetchRequestBodyDropped", {
|
||||
detail: { id: "req-1", maxFetchRequests: 1000 },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
expect(notificationsMock.show).toHaveBeenCalledTimes(1);
|
||||
const shown = notificationsMock.show.mock.calls[0][0];
|
||||
expect(shown.title).toBe("Network log: response body dropped");
|
||||
// Stable per-server id + no auto-close so a storm dedupes into one toast.
|
||||
expect(typeof shown.id).toBe("string");
|
||||
expect(shown.autoClose).toBe(false);
|
||||
});
|
||||
|
||||
it("opens the settings modal (Options/Network Log Size) from the toast link", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(<App />);
|
||||
|
||||
await user.click(screen.getByText("connect"));
|
||||
await waitFor(() => expect(fetchLogInstances).toHaveLength(1));
|
||||
|
||||
act(() => {
|
||||
fetchLogInstances[0].dispatchEvent(
|
||||
new CustomEvent("fetchRequestBodyDropped", {
|
||||
detail: { id: "req-1", maxFetchRequests: 500 },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
// The toast message is a React node carrying the "Adjust" link; render it
|
||||
// and click the link to exercise the onAdjust handler (hide toast + open
|
||||
// settings modal for the active server).
|
||||
const message = notificationsMock.show.mock.calls[0][0].message;
|
||||
renderWithMantine(message);
|
||||
await user.click(
|
||||
screen.getByRole("button", {
|
||||
name: /Adjust Network Log Size for this server/,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(notificationsMock.hide).toHaveBeenCalled();
|
||||
// The settings modal is now open on the Options section, showing the field.
|
||||
await waitFor(() =>
|
||||
expect(screen.getByLabelText(/Network Log Size/)).toBeInTheDocument(),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("App pending server-initiated request modal", () => {
|
||||
beforeEach(() => {
|
||||
clientInstances.length = 0;
|
||||
|
|
@ -1127,6 +1211,7 @@ const settingsWithRoots = (
|
|||
connectionTimeout: 0,
|
||||
requestTimeout: 0,
|
||||
taskTtl: 60000,
|
||||
maxFetchRequests: 1000,
|
||||
roots,
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue