test: close ≥90% per-file coverage gaps for mid-session auth
The mid-session auth work passed `validate`/CI but failed the local-only
`npm run test:coverage` per-file gate (≥90% lines/statements/functions/
branches) on 12 files. Add targeted unit/integration tests so every changed
file clears the gate; annotate provably-dead defensive branches with justified
`/* v8 ignore */` comments rather than relaxing the gate.
Files brought to ≥90 on all four dimensions:
- core/auth: mcpAuth, oauthUx, utils, challenge, node/runner-interactive-oauth
- core/mcp: oauthManager, inspectorClient, node/authChallengeFetch,
remote/remoteClientTransport, remote/node/{remote-session,server}
- clients/web/src/utils: oauthResume, browserTabVisibility
`npm run test:coverage` now passes (3575 tests, 0 threshold failures);
`npm run validate` green across all four clients.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DZyeWManYTvcXxjcrhxSQc
This commit is contained in:
parent
a066873e37
commit
f4b6095719
1 changed files with 3447 additions and 37 deletions
|
|
@ -182,6 +182,29 @@ describe("RemoteSession", () => {
|
|||
await expect(wait).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("endSend is a no-op when no send is active", () => {
|
||||
const session = new RemoteSession("s-endsend-noop");
|
||||
expect(session.hasActiveSend()).toBe(false);
|
||||
// No matching beginSend() — activeSendCount is already 0.
|
||||
session.endSend();
|
||||
expect(session.hasActiveSend()).toBe(false);
|
||||
});
|
||||
|
||||
it("waitForRequestResponse with timeoutMs=0 never schedules a timer and still resolves", async () => {
|
||||
const session = new RemoteSession("s-no-timeout");
|
||||
const wait = session.waitForRequestResponse(7, 0);
|
||||
session.onMessage({ jsonrpc: "2.0", id: 7, result: {} });
|
||||
await expect(wait).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("cancelRequestWait rejects a timeoutMs=0 wait without a timer to clear", async () => {
|
||||
const session = new RemoteSession("s-no-timeout-cancel");
|
||||
const wait = session.waitForRequestResponse(8, 0);
|
||||
const rejection = expect(wait).rejects.toThrow(/cancelled/);
|
||||
session.cancelRequestWait(8);
|
||||
await rejection;
|
||||
});
|
||||
|
||||
it("handleTransportAuthError rejects active request waits during send", async () => {
|
||||
const session = new RemoteSession("s-auth");
|
||||
session.beginSend();
|
||||
|
|
@ -279,6 +302,28 @@ describe("RemoteSession", () => {
|
|||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("setAuthState throws when no auth provider handle is set", () => {
|
||||
const session = new RemoteSession("no-auth-provider");
|
||||
expect(() =>
|
||||
session.setAuthState({
|
||||
oauthTokens: { access_token: "x", token_type: "Bearer" },
|
||||
}),
|
||||
).toThrow(/Session has no OAuth auth provider/);
|
||||
});
|
||||
|
||||
it("cancelRequestWait is a no-op when the requestId has no pending wait", () => {
|
||||
const session = new RemoteSession("s-cancel-noop");
|
||||
// No wait was ever registered for this id — should not throw.
|
||||
expect(() => session.cancelRequestWait(123)).not.toThrow();
|
||||
});
|
||||
|
||||
it("handleTransportAuthError returns false for a non-AuthChallengeError", () => {
|
||||
const session = new RemoteSession("s-not-auth-error");
|
||||
expect(session.handleTransportAuthError(new Error("plain error"))).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("setAuthState updates the session auth provider", async () => {
|
||||
const { createRemoteAuthProvider } =
|
||||
await import("@inspector/core/mcp/remote/node/tokenAuthProvider.js");
|
||||
|
|
|
|||
Loading…
Reference in a new issue