* 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
|
|
@ -309,6 +309,56 @@ describe("PromptsScreen", () => {
|
|||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("re-clicking the active arg-bearing prompt is a no-op (early return)", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onUiChange = vi.fn();
|
||||
const onGetPrompt = vi.fn();
|
||||
renderWithMantine(
|
||||
<ControlledPromptsScreen
|
||||
onUiChange={onUiChange}
|
||||
onGetPrompt={onGetPrompt}
|
||||
/>,
|
||||
);
|
||||
// First click selects "summarize" (arg-bearing → form, no auto-fetch).
|
||||
await user.click(screen.getByText("summarize"));
|
||||
const callsAfterSelect = onUiChange.mock.calls.length;
|
||||
// Re-clicking the already-selected sidebar entry must early-return:
|
||||
// no further onUiChange (selection unchanged) and no fetch. The form
|
||||
// pane now also shows "summarize", so target the sidebar entry (first).
|
||||
await user.click(screen.getAllByText("summarize")[0]);
|
||||
expect(onUiChange.mock.calls.length).toBe(callsAfterSelect);
|
||||
expect(onGetPrompt).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("routes sidebar search text through onUiChange", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onUiChange = vi.fn();
|
||||
renderWithMantine(<ControlledPromptsScreen onUiChange={onUiChange} />);
|
||||
await user.type(screen.getByPlaceholderText("Search prompts..."), "sum");
|
||||
expect(onUiChange).toHaveBeenCalled();
|
||||
const last = onUiChange.mock.calls.at(-1)?.[0] as PromptsUiState;
|
||||
expect(last.search).toBe("sum");
|
||||
});
|
||||
|
||||
it("renders nothing in the preview when an ok state carries no result", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(
|
||||
<ControlledPromptsScreen
|
||||
// previewActive but status ok with no messages result — the
|
||||
// renderPreview path falls through to `return null`.
|
||||
getPromptState={{ status: "ok", promptName: "summarize" }}
|
||||
/>,
|
||||
);
|
||||
await user.click(screen.getByText("summarize"));
|
||||
await user.type(screen.getByPlaceholderText("Enter topic..."), "x");
|
||||
await user.click(screen.getByRole("button", { name: "Get Prompt" }));
|
||||
// No messages panel and no form (preview branch is active but empty).
|
||||
expect(screen.queryByText("Messages")).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByRole("button", { name: "Get Prompt" }),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("threads onCompleteArgument with a ref/prompt envelope", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onCompleteArgument = vi
|
||||
|
|
|
|||
|
|
@ -131,7 +131,11 @@ export function PromptsScreen({
|
|||
// Re-clicking the active prompt in the sidebar shouldn't wipe the
|
||||
// user's typed argument values or trigger a re-fetch — sidebar is
|
||||
// for navigation, ✕ is for dismiss. Closing-then-reselecting is
|
||||
// its own thing (the close handler clears submittedFor).
|
||||
// its own thing (the close handler clears submittedFor). PromptControls
|
||||
// already swallows a re-click on the active item (it only fires
|
||||
// onSelectPrompt when the name differs), so this is a redundant guard
|
||||
// that never fires through the UI.
|
||||
/* v8 ignore next -- unreachable: PromptControls never re-emits the active name */
|
||||
if (name === selectedPromptName) return;
|
||||
// Auto-fetch no-argument prompts the moment they're selected — the
|
||||
// form pane would otherwise just render a bare Get Prompt button
|
||||
|
|
@ -148,6 +152,10 @@ export function PromptsScreen({
|
|||
}
|
||||
|
||||
function handleSubmit() {
|
||||
// Defensive guard: handleSubmit is only wired to the argument form's
|
||||
// onGetPrompt, which renders solely when `selectedPrompt` is truthy, so
|
||||
// this never fires through the UI.
|
||||
/* v8 ignore next -- unreachable: form only renders with a selected prompt */
|
||||
if (!selectedPrompt) return;
|
||||
onUiChange({ ...ui, submittedFor: selectedPrompt.name });
|
||||
onGetPrompt(selectedPrompt.name, argumentValues);
|
||||
|
|
@ -182,6 +190,10 @@ export function PromptsScreen({
|
|||
getPromptState.promptName === selectedPrompt.name;
|
||||
|
||||
function renderPreview() {
|
||||
// Defensive guard: renderPreview is only invoked from the `previewActive`
|
||||
// branch below, and `previewActive` already requires a truthy
|
||||
// `getPromptState`, so neither arm of this condition is reachable here.
|
||||
/* v8 ignore next -- unreachable: only called when previewActive && getPromptState */
|
||||
if (!previewActive || !getPromptState) return null;
|
||||
if (getPromptState.status === "pending") {
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in a new issue