test: run v1.5-ported integration tests under node-env vitest project (#1307) (#1312)

* feat(test): run v1.5-ported integration tests under node-env vitest (#1307)

Adds an `integration` vitest project alongside `unit` and `storybook` so
the 13 v1.5-ported tests that need real HTTP/stdio servers (or fail under
happy-dom's SDK mock resolution) run again under node env with 30s
timeouts. Restores test-servers/ as a buildable package so the stdio
subprocess spawns a real .js file. Drops the v1.5-source `coverage.exclude`
globs and fills coverage gaps across the v1.5-ported core/ modules; two
large files (inspectorClient.ts, remote/node/server.ts) keep narrow
per-file excludes tracked in #1310.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(core): address PR #1312 review — TS6-safe tsconfig, real transport_error path

- Drop `baseUrl` / `paths` / `typeRoots` / `declaration*` from
  test-servers/tsconfig.json. They were only needed for type
  resolution, and we already pass `--noCheck` from `test-servers:build`.
  Under TS 6+ the deprecated `baseUrl` exited with code 2, which
  silently skipped vitest in the `&&` chains of test:integration /
  test:coverage / validate.
- Rework the "send() throws after closed" test to drive `closed` via
  an actual transport_error SSE event instead of mutating private
  state through a cast — matches the real path the branch guards.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cliff Hall 2026-05-16 15:15:17 -04:00 • committed by GitHub
commit 88b55b093b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,6 +50,78 @@ async function startRemoteServer(
}
describe("Storage adapters", () => {
describe("createRemoteStorageAdapter (unit, mocked fetch)", () => {
function makeAdapter(fetchFn: typeof fetch, authToken?: string) {
return createRemoteStorageAdapter({
baseUrl: "http://remote.example/",
storeId: "test",
fetchFn,
authToken,
})!;
}
it("getItem returns null on 404 and parses stored blob otherwise", async () => {
const fetchFn = vi
.fn<typeof fetch>()
.mockResolvedValueOnce(new Response("not found", { status: 404 }))
.mockResolvedValueOnce(
new Response(JSON.stringify({ state: { hi: 1 }, version: 0 })),
)
.mockResolvedValueOnce(new Response("{}"));
const adapter = makeAdapter(fetchFn as typeof fetch);
expect(await adapter.getItem("anything")).toBeNull();
const blob = await adapter.getItem("anything");
expect(blob).toBeTruthy();
// Empty object response → treated as "not initialized" → null.
expect(await adapter.getItem("anything")).toBeNull();
});
it("getItem throws on non-404 error responses", async () => {
const fetchFn = vi
.fn<typeof fetch>()
.mockResolvedValueOnce(new Response("boom", { status: 500 }));
const adapter = makeAdapter(fetchFn as typeof fetch);
await expect(adapter.getItem("x")).rejects.toThrow(/500/);
});
it("setItem throws when the POST fails", async () => {
const fetchFn = vi
.fn<typeof fetch>()
.mockResolvedValueOnce(new Response("nope", { status: 500 }));
const adapter = makeAdapter(fetchFn as typeof fetch);
await expect(
adapter.setItem("name", { state: { a: 1 }, version: 0 }),
).rejects.toThrow(/500/);
});
it("removeItem tolerates 404 but rethrows on other failures", async () => {
const fetchFn = vi
.fn<typeof fetch>()
.mockResolvedValueOnce(new Response(null, { status: 204 }))
.mockResolvedValueOnce(new Response(null, { status: 404 }))
.mockResolvedValueOnce(new Response("boom", { status: 500 }));
const adapter = makeAdapter(fetchFn as typeof fetch);
await expect(adapter.removeItem("x")).resolves.toBeUndefined();
await expect(adapter.removeItem("x")).resolves.toBeUndefined();
await expect(adapter.removeItem("x")).rejects.toThrow(/500/);
});
it("sends the x-mcp-remote-auth header on all three verbs when authToken is set", async () => {
const fetchFn = vi
.fn<typeof fetch>()
.mockResolvedValue(new Response("{}"));
const adapter = makeAdapter(fetchFn as typeof fetch, "secret");
await adapter.getItem("x");
await adapter.setItem("x", { state: {}, version: 0 });
await adapter.removeItem("x");
for (const call of fetchFn.mock.calls) {
const headers = call[1]?.headers as Record<string, string> | undefined;
expect(headers?.["x-mcp-remote-auth"]).toBe("Bearer secret");
}
});
});
describe("FileStorageAdapter", () => {
let tempDir: string | null = null;
@ -146,6 +218,24 @@ describe("Storage adapters", () => {
const parsed = JSON.parse(fileContent);
expect(Object.keys(parsed.state.servers).length).toBe(0);
});
it("removeItem deletes the underlying file", async () => {
tempDir = mkdtempSync(join(tmpdir(), "inspector-storage-test-"));
const filePath = join(tempDir!, "test-store.json");
const storage = createFileStorageAdapter({ filePath });
// createJSONStorage returns a PersistStorage<S> wrapper that delegates to
// our adapter's removeItem callback (line 25 of file-storage.ts).
const store = createOAuthStore(storage);
store.getState().setServerState("https://example.com", {
tokens: { access_token: "t", token_type: "Bearer" },
});
await vi.waitFor(() => expect(existsSync(filePath)).toBe(true), {
timeout: 2000,
interval: 20,
});
await storage!.removeItem("inspector-oauth-store");
expect(existsSync(filePath)).toBe(false);
});
});
describe("RemoteStorageAdapter", () => {