* test(web): audit branch-coverage outliers, raise per-file gate to 70 (#1271) The web per-file coverage gate had drifted red: the recently-landed EMA auth feature (core/auth/ema/*) and ClientSettings components shipped undertested, and the prior 50% branch floor let business-logic branches go untested. CI does not run the coverage gate, so this accumulated. Add tests to bring every failing file above the gate and push branch coverage well past 70 across the board, then raise the per-file branches threshold 50 -> 70 in clients/web/vite.config.ts. - EMA core (emaFlow, resourceContext, jwt, wire): 50-88% -> 86-100% branch - EMA OIDC/transport (idpOidc, tokenEndpoint, transportProvider): -> 97-100% - oauthManager / discovery: 73-83% -> 88-92% - ClientSettingsModal/Form, ConnectionInfoContent: 0-88% -> 96-100% - useClientSettingsDraft / useEmaIdpLoginState hooks: 20% -> 100% - TaskStatusBadge / SortableServerCard outliers: 50% -> 100% Coverable branches reached by mocking useComputedColorScheme (dark theme), dnd-kit useSortable (isDragging), and fetch/OIDC paths. Remaining sub-100 branches are genuinely-unreachable defensive guards or happy-dom-inherent (portal / useMediaQuery / typeof window) and documented in test comments. No source files changed. Global web branch coverage 88.73% -> 90.63%. AGENTS.md updated; cli/tui/launcher stay at 50 (out of scope). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: raise per-file coverage gate to 90/90/90/90 across all clients Follows the #1271 web branch-coverage audit (50 -> 70) by raising the whole per-file gate to >=90 on all four dimensions — lines, statements, functions, branches — for web, cli, tui, and launcher (core/ is measured under the web suite). A codebase-wide audit added real tests for every outlier and brought global coverage up across the board. Config: all four vitest/vite coverage configs set to 90/90/90/90. Two pure-type modules (core/mcp/import/types.ts, clients/web/server/ types.ts) added to the web coverage exclude list, matching the existing type-only exclusions. Tests: ~50 test files extended/created across core (auth, ema, mcp, remote, state, storage, react), web components/screens/server, and the cli/tui clients. Highlights: full EMA OAuth flow + transport coverage, inspectorClient/remote server backfill, every Mantine control's handler branches, and the cli unsupported-method / argv-fallback paths. Genuinely-unreachable branches are annotated at the source with justified `/* v8 ignore -- <reason> */` comments rather than lowering the gate: happy-dom-inherent paths (Mantine portal, useMediaQuery, typeof window SSR guards), React StrictMode effect replay, and provably-dead defensive guards (?? fallbacks the types make impossible, Select.onChange values outside the allowed list). No runtime logic changed; the only structural edits are two behavior-preserving refactors (ResourceTemplatePanel hoists the field value to a local so the ignore applies in JSX; ToolsScreen swaps a ternary for an if) and prettier line-wrapping. Also fixed a flaky real-timer debounce assertion in PromptArgumentsForm (asserted an exact sibling-typing interleaving that raced the 300ms debounce; now asserts the load-bearing fact — a non-empty fire-time sibling capture). AGENTS.md updated to describe the uniform 90 gate and the v8-ignore policy. All four client coverage gates, root validate, storybook (370), and smoke pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(web): make connect-crash SSE reader stop on the terminal event `readSseEvents` looped until the server closed the stream (`done`). The server closes the events stream immediately after writing the terminal `transport_error`, but under the heavy parallel scheduler pressure of a full `coverage` run (v8 instrumentation across all workers) that close can lag far enough behind the event to trip the 30s test timeout — a hang, not a wrong result. This made the test intermittently fail under `npm run coverage` (it passed in isolation and under CI's lighter `test:integration`). Stop reading as soon as the terminal `transport_error` event arrives (cancelling the reader) instead of waiting only for `done`. That event is always the last one the session queue emits, so nothing is lost, and the test no longer depends on stream-close timing. The `done` break is kept for any stream that closes first. Verified green across two consecutive full `npm run test:coverage` runs (3094 tests) where it previously hung, plus isolation (~0.5s). 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
d04a7fb9c8
commit
c96db0402e
2 changed files with 8793 additions and 63 deletions
|
|
@ -300,6 +300,167 @@ describe("ResourceTemplatePanel", () => {
|
|||
expect(screen.queryByText("alphabet")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("surfaces an empty dropdown when the completion request rejects", async () => {
|
||||
const user = userEvent.setup();
|
||||
// Focus call resolves with options; the debounced keystroke call
|
||||
// rejects. The rejection (not aborted) must reset the dropdown to [].
|
||||
const onCompleteArgument = vi
|
||||
.fn<
|
||||
(
|
||||
argName: string,
|
||||
value: string,
|
||||
context: Record<string, string>,
|
||||
) => Promise<string[]>
|
||||
>()
|
||||
.mockResolvedValueOnce(["alpha", "alphabet"])
|
||||
.mockRejectedValueOnce(new Error("completion failed"));
|
||||
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={singleVarTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
completionsSupported
|
||||
onCompleteArgument={onCompleteArgument}
|
||||
/>,
|
||||
);
|
||||
|
||||
const input = screen.getByRole("textbox", { name: "userId" });
|
||||
await user.click(input);
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
expect(await screen.findByText("alpha")).toBeInTheDocument();
|
||||
|
||||
await user.type(input, "z");
|
||||
await new Promise((r) => setTimeout(r, 400));
|
||||
expect(screen.queryByText("alpha")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("alphabet")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("cancels a pending debounce timer when the input is re-focused", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onCompleteArgument = vi
|
||||
.fn<
|
||||
(
|
||||
argName: string,
|
||||
value: string,
|
||||
context: Record<string, string>,
|
||||
) => Promise<string[]>
|
||||
>()
|
||||
.mockResolvedValue([]);
|
||||
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={titledTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
completionsSupported
|
||||
onCompleteArgument={onCompleteArgument}
|
||||
/>,
|
||||
);
|
||||
|
||||
const tableInput = screen.getByRole("textbox", { name: "tableName" });
|
||||
const rowInput = screen.getByRole("textbox", { name: "rowId" });
|
||||
|
||||
// Type into tableName → schedules a debounce timer. Move focus away
|
||||
// and back before the 300ms fires so handleVariableFocus sees a
|
||||
// pending timer for "tableName" and clears it.
|
||||
await user.type(tableInput, "u");
|
||||
await user.click(rowInput);
|
||||
await user.click(tableInput);
|
||||
onCompleteArgument.mockClear();
|
||||
await new Promise((r) => setTimeout(r, 400));
|
||||
const tableCalls = onCompleteArgument.mock.calls.filter(
|
||||
([n]) => n === "tableName",
|
||||
);
|
||||
// Only the focus-fire call (value "u"), never the cancelled debounce.
|
||||
expect(tableCalls.every(([, v]) => v === "u")).toBe(true);
|
||||
});
|
||||
|
||||
it("drops a stale in-flight response when a faster keystroke arrives", async () => {
|
||||
const user = userEvent.setup();
|
||||
const calls: Array<{
|
||||
value: string;
|
||||
resolve: (values: string[]) => void;
|
||||
}> = [];
|
||||
const onCompleteArgument = vi.fn(
|
||||
(_argName: string, value: string) =>
|
||||
new Promise<string[]>((resolve) => {
|
||||
calls.push({ value, resolve });
|
||||
}),
|
||||
);
|
||||
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={singleVarTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
completionsSupported
|
||||
onCompleteArgument={onCompleteArgument}
|
||||
/>,
|
||||
);
|
||||
|
||||
// Focus → first call (value=""). Type "h" → second call after
|
||||
// debounce. Type "i" → third call after debounce, which aborts the
|
||||
// "h" controller.
|
||||
const input = screen.getByRole("textbox", { name: "userId" });
|
||||
await user.type(input, "h");
|
||||
await new Promise((r) => setTimeout(r, 350));
|
||||
await user.type(input, "i");
|
||||
await new Promise((r) => setTimeout(r, 350));
|
||||
|
||||
const hi = calls.find((c) => c.value === "hi");
|
||||
const h = calls.find((c) => c.value === "h");
|
||||
expect(hi).toBeDefined();
|
||||
expect(h).toBeDefined();
|
||||
// Resolve the stale "h" after it was aborted — its signal.aborted
|
||||
// guard drops the response so it can't overwrite the fresh one.
|
||||
h?.resolve(["from-stale-h"]);
|
||||
hi?.resolve(["from-fresh-hi"]);
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
|
||||
expect(await screen.findByText("from-fresh-hi")).toBeInTheDocument();
|
||||
expect(screen.queryByText("from-stale-h")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("aborts in-flight completion requests on unmount", async () => {
|
||||
const user = userEvent.setup();
|
||||
// A request that never settles, so it is still in flight at unmount.
|
||||
const onCompleteArgument = vi.fn(() => new Promise<string[]>(() => {}));
|
||||
|
||||
const { unmount } = renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={singleVarTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
completionsSupported
|
||||
onCompleteArgument={onCompleteArgument}
|
||||
/>,
|
||||
);
|
||||
|
||||
// Focus fires a completion immediately, leaving an in-flight request.
|
||||
await user.click(screen.getByRole("textbox", { name: "userId" }));
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
expect(onCompleteArgument).toHaveBeenCalled();
|
||||
|
||||
// The unmount-cleanup effect iterates the in-flight controllers and
|
||||
// aborts each — this must not throw.
|
||||
expect(() => unmount()).not.toThrow();
|
||||
});
|
||||
|
||||
it("does not fire completions on focus when completions are unsupported", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onCompleteArgument = vi.fn();
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={singleVarTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
completionsSupported={false}
|
||||
onCompleteArgument={onCompleteArgument}
|
||||
/>,
|
||||
);
|
||||
// Focusing the plain TextInput hits the early `!useAutocomplete`
|
||||
// return in handleVariableFocus.
|
||||
await user.click(screen.getByLabelText("userId"));
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
expect(onCompleteArgument).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not call onCompleteArgument when completions are unsupported", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onCompleteArgument = vi.fn();
|
||||
|
|
|
|||
|
|
@ -143,6 +143,8 @@ export function ResourceTemplatePanel({
|
|||
|
||||
const runCompletion = useCallback(
|
||||
async (varName: string, value: string, context: Record<string, string>) => {
|
||||
/* v8 ignore next -- unreachable: runCompletion is only invoked when
|
||||
useAutocomplete is true, which already requires onCompleteArgument. */
|
||||
if (!onCompleteArgument) return;
|
||||
requestsRef.current.get(varName)?.abort();
|
||||
const controller = new AbortController();
|
||||
|
|
@ -203,6 +205,8 @@ export function ResourceTemplatePanel({
|
|||
}
|
||||
|
||||
function handleVariableFocus(varName: string) {
|
||||
/* v8 ignore next -- unreachable: the plain (non-autocomplete) TextInput
|
||||
has no onFocus, so this handler only runs when useAutocomplete is true. */
|
||||
if (!useAutocomplete) return;
|
||||
// Fire immediately so the dropdown isn't empty when the user first
|
||||
// clicks in. Cancel any pending debounce for this variable so a
|
||||
|
|
@ -214,6 +218,8 @@ export function ResourceTemplatePanel({
|
|||
clearTimeout(existing);
|
||||
timersRef.current.delete(varName);
|
||||
}
|
||||
/* v8 ignore next -- the `?? ""` fallback is unreachable: `variables` (and
|
||||
its ref) is seeded with every declared variable, so the key is present. */
|
||||
const value = variablesRef.current[varName] ?? "";
|
||||
void runCompletion(varName, value, buildContext(varName));
|
||||
}
|
||||
|
|
@ -237,13 +243,15 @@ export function ResourceTemplatePanel({
|
|||
</HeaderRow>
|
||||
{description && <DescriptionText>{description}</DescriptionText>}
|
||||
<Stack gap="sm">
|
||||
{variableNames.map((varName) =>
|
||||
useAutocomplete ? (
|
||||
{variableNames.map((varName) => {
|
||||
/* v8 ignore next -- `?? ""` fallback unreachable: `variables` is seeded with every declared variable, so the key is always present. */
|
||||
const fieldValue = variables[varName] ?? "";
|
||||
return useAutocomplete ? (
|
||||
<Autocomplete
|
||||
key={varName}
|
||||
label={varName}
|
||||
placeholder={`Enter ${varName}`}
|
||||
value={variables[varName] ?? ""}
|
||||
value={fieldValue}
|
||||
data={completions[varName] ?? []}
|
||||
// The server already filtered the values for the typed
|
||||
// prefix; passing options through verbatim avoids hiding
|
||||
|
|
@ -258,7 +266,7 @@ export function ResourceTemplatePanel({
|
|||
key={varName}
|
||||
label={varName}
|
||||
placeholder={`Enter ${varName}`}
|
||||
value={variables[varName] ?? ""}
|
||||
value={fieldValue}
|
||||
onChange={(e) =>
|
||||
handleVariableChange(varName, e.currentTarget.value)
|
||||
}
|
||||
|
|
@ -271,8 +279,8 @@ export function ResourceTemplatePanel({
|
|||
) : null
|
||||
}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
<FooterRow>
|
||||
<AnnotationGroup>
|
||||
|
|
|
|||
Loading…
Reference in a new issue