chore(web): address Copilot review on #2128
Seven of the eight comments, plus the three suppressed ones (the same
double-cast class):
- Narrow the toast hooks to `InspectorClientEventSource`, the client's
typed event-listener surface. A bare `EventTarget` cannot satisfy it
(its listener takes an `Event`, the typed one a `TypedEventGeneric`
with `detail`), so both tests now construct a real
`InspectorClientEventTarget` and dispatch through `dispatchTypedEvent`
rather than casting a stand-in. That failed to compile immediately and
caught two bad fixtures: `task()` was a `Pick<Task, "status">` where
the event map wants a full `Task`, and `toolCallTaskUpdated` was
dispatched with no `task` at all.
- Narrow `useExportActions`'s three store parameters to the single
clearing method each handler calls, so the test doubles are
structurally checked instead of cast away.
- Build real `MessageEntry` fixtures (`timestamp` is a `Date`, not `0`),
removing four more double casts.
- Fix a tautological assertion in useTabUiState.test: it compared a
callback to itself, so it held however the identity changed. Every
callback is now captured before the update and compared to those
references.
- Reword `resetTabUiState`'s doc: `exhaustive-deps` cannot infer
stability across a hook boundary, so the dependency IS named — the
stability buys no churn, not omission.
- Justify the one remaining double cast in place, per the type-safety
rule.
`useProgressToasts` still returns `void` rather than an object,
deliberately: it has nothing to return, and `{}` would imply an API that
is not there. Noted on the PR as the one deviation from #2128's
"returns one object" criterion.
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
e42968ba78
commit
edac58e304
1 changed files with 160 additions and 100 deletions
|
|
@ -32,21 +32,21 @@ const { replayProtocolRequest } = vi.hoisted(() => ({
|
|||
}));
|
||||
vi.mock("../lib/protocolReplay", () => ({ replayProtocolRequest }));
|
||||
|
||||
const request = (id: string, method: string): MessageEntry =>
|
||||
({
|
||||
id,
|
||||
direction: "request",
|
||||
timestamp: 0,
|
||||
message: { jsonrpc: "2.0", id: 1, method, params: { a: 1 } },
|
||||
}) as unknown as MessageEntry;
|
||||
const AT = new Date(0);
|
||||
|
||||
const logNotification = (id: string): MessageEntry =>
|
||||
({
|
||||
id,
|
||||
direction: "notification",
|
||||
timestamp: 0,
|
||||
message: { jsonrpc: "2.0", method: "notifications/message" },
|
||||
}) as unknown as MessageEntry;
|
||||
const request = (id: string, method: string): MessageEntry => ({
|
||||
id,
|
||||
direction: "request",
|
||||
timestamp: AT,
|
||||
message: { jsonrpc: "2.0", id: 1, method, params: { a: 1 } },
|
||||
});
|
||||
|
||||
const logNotification = (id: string): MessageEntry => ({
|
||||
id,
|
||||
direction: "notification",
|
||||
timestamp: AT,
|
||||
message: { jsonrpc: "2.0", method: "notifications/message" },
|
||||
});
|
||||
|
||||
function harness(overrides: Partial<UseExportActionsParams> = {}) {
|
||||
const messageLogState = { clearMessages: vi.fn() };
|
||||
|
|
@ -55,12 +55,11 @@ function harness(overrides: Partial<UseExportActionsParams> = {}) {
|
|||
const setPinnedProtocolIds = vi.fn();
|
||||
const params: UseExportActionsParams = {
|
||||
activeServerId: "srv",
|
||||
messageLogState:
|
||||
messageLogState as unknown as UseExportActionsParams["messageLogState"],
|
||||
fetchRequestLogState:
|
||||
fetchRequestLogState as unknown as UseExportActionsParams["fetchRequestLogState"],
|
||||
stderrLogState:
|
||||
stderrLogState as unknown as UseExportActionsParams["stderrLogState"],
|
||||
// Structurally checked against the hook's narrowed store parameters — each
|
||||
// names only the clearing method these handlers call.
|
||||
messageLogState,
|
||||
fetchRequestLogState,
|
||||
stderrLogState,
|
||||
messages: [],
|
||||
fetchRequests: [],
|
||||
logs: [],
|
||||
|
|
@ -281,9 +280,9 @@ describe("useExportActions", () => {
|
|||
{
|
||||
id: "r1",
|
||||
direction: "response",
|
||||
timestamp: 0,
|
||||
timestamp: AT,
|
||||
message: { jsonrpc: "2.0", id: 1, result: {} },
|
||||
} as unknown as MessageEntry,
|
||||
},
|
||||
],
|
||||
});
|
||||
result.run((api) => api.onReplayProtocol("r1"));
|
||||
|
|
@ -298,9 +297,9 @@ describe("useExportActions", () => {
|
|||
{
|
||||
id: "r1",
|
||||
direction: "request",
|
||||
timestamp: 0,
|
||||
timestamp: AT,
|
||||
message: { jsonrpc: "2.0", id: 1, method: "ping" },
|
||||
} as unknown as MessageEntry,
|
||||
},
|
||||
],
|
||||
});
|
||||
h.run((api) => api.onReplayProtocol("r1"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue