import React from "react"; import { describe, it, expect, vi, afterEach } from "vitest"; import { render } from "ink-testing-library"; import type { InspectorClient } from "@inspector/core/mcp/index.js"; import { AuthRecoveryRequiredError } from "@inspector/core/auth/challenge.js"; // ScrollView passthrough so the results JSX actually mounts (and is covered). vi.mock("ink-scroll-view", () => import("./helpers/inkScrollViewMock.js")); // Form double that fires onSubmit when the user presses Enter ("\r"). vi.mock("ink-form", () => import("./helpers/inkFormMock.js")); import { ResourceTestModal } from "../src/components/ResourceTestModal.js"; // These modals render position="absolute", which produces an EMPTY frame under // ink-testing-library. So we assert on BEHAVIOR — the injected client fake's // readResourceFromTemplate, onClose, and the state transitions they drive — // rather than on lastFrame(). React still EXECUTES the inner results/error JSX, // so its coverage is collected even though it isn't visible. const tick = async () => { // Flush several macrotask cycles so an effect -> setState -> re-render chain // settles before assertions, even on slow/loaded CI (a single tick can race). for (let i = 0; i < 8; i++) await new Promise((resolve) => setTimeout(resolve, 4)); }; const ESC = String.fromCharCode(27); const UP = `${ESC}[A`; const DOWN = `${ESC}[B`; const PAGE_UP = `${ESC}[5~`; const PAGE_DOWN = `${ESC}[6~`; type Template = { name: string; uriTemplate: string; description?: string; }; const makeTemplate = (over: Partial