diff --git a/src/jeb/JebMcpEndpoint.test.ts b/src/jeb/JebMcpEndpoint.test.ts index 3415f7d650..e92b1d9f60 100644 --- a/src/jeb/JebMcpEndpoint.test.ts +++ b/src/jeb/JebMcpEndpoint.test.ts @@ -14,8 +14,7 @@ describe("JEB MCP endpoint", () => { expect(parseJebMcpEndpoint(value).ok, value).toBe(false); }); - it("accepts only the declared MCP route", () => { - expect(parseJebMcpEndpoint("http://127.0.0.1:8425/mcp").ok).toBe(true); + it("refuses paths outside the declared MCP route", () => { for (const path of ["/mcp/extra", "/not-mcp", "/"]) expect(parseJebMcpEndpoint(`http://127.0.0.1:8425${path}`).ok, path).toBe( false, diff --git a/src/jeb/JebProvider.test.ts b/src/jeb/JebProvider.test.ts index bfa1160a88..e68f01d6b8 100644 --- a/src/jeb/JebProvider.test.ts +++ b/src/jeb/JebProvider.test.ts @@ -9,12 +9,8 @@ import { } from "./JebMcpDeadline.js"; import { JebProvider } from "./JebProvider.js"; import { decodeJebToolResult } from "./JebMcpConnection.js"; -import type { - JebMcpConnection, - JebMcpConnectionTimeouts, -} from "./JebMcpConnection.js"; +import type { JebMcpConnection } from "./JebMcpConnection.js"; import { - AnalysisCapabilityUnavailableError, AnalysisInputError, AnalysisProtocolError, AnalysisCancelledError, @@ -88,28 +84,18 @@ describe("JebProvider live availability", () => { input: { count: 10, index: 0 }, }); if (failure.ok) throw new Error("Expected transport failure"); - expect(failure.error.diagnostics).toMatchObject({ endpoint }); + expect(projectAnalysisError(failure.error)).toMatchObject({ + code: "capability_unavailable", + details: { + reason: "connection closed", + diagnostics: { endpoint }, + }, + }); } finally { await provider.close(); } }); - it("passes its validated environment timeout to the production connection", async () => { - let configured: JebMcpConnectionTimeouts | undefined; - const provider = createJebAnalysisProvider( - { REA_JEB_MCP_TIMEOUT_MS: "900000" }, - (_endpoint, timeouts) => { - configured = timeouts; - return scriptedConnection({}); - }, - ); - expect(configured).toEqual({ - requestTimeoutMs: 900_000, - discoveryTimeoutMs: 900_000, - }); - await provider.close(); - }); - it("keeps the selected JEB deadline source", () => { expect(selectedJebMcpTimeout(undefined)).toEqual({ ms: 60_000, @@ -168,16 +154,12 @@ describe("JebProvider live availability", () => { await provider.close(); }); - it("reports only the operations advertised by the live engine", async () => { + it("reports the advertised operations from a fresh readiness probe", async () => { const connection = scriptedConnection({ - get_client_information: { - success: true, - version: "5.48.0", - gui_client: false, - }, - list_units: { success: true, units: [] }, - decompile_code_item: { success: true, text: "" }, + get_client_information: { success: true, version: "5.48.0" }, }); + let tools = ["get_client_information", "list_units", "decompile_code_item"]; + connection.listTools = async () => tools; const provider = providerWith(connection); expect(await provider.inspectAvailability()).toMatchObject({ status: "available", @@ -187,16 +169,7 @@ describe("JebProvider live availability", () => { "decompile_jeb_item", ], }); - expect(connection.calls).toEqual([["get_client_information", {}]]); - }); - - it("refreshes live operation support rather than reusing a readiness snapshot", async () => { - const connection = scriptedConnection({ - get_client_information: { success: true, version: "5.48.0" }, - }); - let tools = ["get_client_information", "open_project"]; - connection.listTools = async () => tools; - const provider = providerWith(connection); + tools = ["get_client_information", "open_project"]; expect(await provider.inspectAvailability()).toMatchObject({ supportedOperations: ["inspect_jeb_client", "open_jeb_project"], }); @@ -204,7 +177,11 @@ describe("JebProvider live availability", () => { expect(await provider.inspectAvailability()).toMatchObject({ supportedOperations: ["inspect_jeb_client"], }); - expect(connection.calls).toHaveLength(2); + expect(connection.calls).toEqual([ + ["get_client_information", {}], + ["get_client_information", {}], + ["get_client_information", {}], + ]); }); }); @@ -285,13 +262,12 @@ describe("JebProvider observations and failures", () => { expect(result.value.provider.version).toBe("5.48.0.202610071539"); }); - it("reports unavailable when the engine endpoint is unreachable", async () => { + it("reports readiness unavailable when the engine endpoint is unreachable", async () => { const provider = providerWith( scriptedConnection({ get_client_information: new Error( "connect ECONNREFUSED 127.0.0.1:8425", ), - list_units: new Error("connect ECONNREFUSED 127.0.0.1:8425"), }), ); const availability = await provider.inspectAvailability(); @@ -303,38 +279,6 @@ describe("JebProvider observations and failures", () => { "Start a JEB client serving MCP", ); expect(availability.remediation).toContain("REA_JEB_MCP_URL"); - const result = await provider.execute({ - operation: "list_jeb_units", - input: { count: 10, index: 0 }, - }); - expect(result.ok).toBe(false); - if (result.ok) return; - expect(result.error).toBeInstanceOf(AnalysisCapabilityUnavailableError); - expect(result.error.message).toContain("ECONNREFUSED"); - expect(projectAnalysisError(result.error)).toMatchObject({ - details: { diagnostics: { endpoint: "http://127.0.0.1:8425/mcp" } }, - }); - }); - - it("maps transport failures during an operation to provider unavailability", async () => { - const provider = providerWith( - scriptedConnection({ - get_client_information: { - success: true, - version: "5.48.0", - gui_client: false, - }, - list_units: new Error("connect ECONNREFUSED 127.0.0.1:8425"), - }), - ); - const result = await provider.execute({ - operation: "list_jeb_units", - input: { count: 10, index: 0 }, - }); - expect(result.ok).toBe(false); - if (result.ok) return; - expect(result.error).toBeInstanceOf(AnalysisCapabilityUnavailableError); - expect(result.error.message).toContain("ECONNREFUSED"); }); it("preserves engine refusal reasons without inferring unsupported target formats", async () => { diff --git a/tests/boundary/cli/jebCli.test.ts b/tests/boundary/cli/jebCli.test.ts index 0ac208ab4b..14df1ee590 100644 --- a/tests/boundary/cli/jebCli.test.ts +++ b/tests/boundary/cli/jebCli.test.ts @@ -38,28 +38,19 @@ it("validates decompile item input before contacting the engine", async () => { }); }); -it.each([ - { setting: "REA_JEB_MCP_URL", value: "http://localhost:8425/mcp" }, - { setting: "REA_JEB_MCP_TIMEOUT_MS", value: "1.5" }, -])( - "reports invalid $setting without breaking other commands", - async ({ setting, value }) => { - const environment = { [setting]: value }; - const jeb = await serveCli(["inspect-jeb-client", "--json"], environment); - expect(JSON.parse(jeb.stdout)).toMatchObject({ - code: "configuration_invalid", - details: { settings: [{ setting }] }, - }); - const capabilities = await serveCli( - ["capabilities", "--json"], - environment, - ); - expect(capabilities.exitCode).toBe(0); - expect(JSON.parse(capabilities.stdout)).toMatchObject({ - capabilities: expect.any(Array), - }); - }, -); +it("reports an invalid JEB endpoint without breaking other commands", async () => { + const environment = { REA_JEB_MCP_URL: "http://localhost:8425/mcp" }; + const jeb = await serveCli(["inspect-jeb-client", "--json"], environment); + expect(JSON.parse(jeb.stdout)).toMatchObject({ + code: "configuration_invalid", + details: { settings: [{ setting: "REA_JEB_MCP_URL" }] }, + }); + const capabilities = await serveCli(["capabilities", "--json"], environment); + expect(capabilities.exitCode).toBe(0); + expect(JSON.parse(capabilities.stdout)).toMatchObject({ + capabilities: expect.any(Array), + }); +}); it.each( [ diff --git a/tests/boundary/providers/jebMcpTimeout.test.ts b/tests/boundary/providers/jebMcpTimeout.test.ts index b6f7dc3d79..0e655212df 100644 --- a/tests/boundary/providers/jebMcpTimeout.test.ts +++ b/tests/boundary/providers/jebMcpTimeout.test.ts @@ -1,9 +1,9 @@ import { withVerifierCleanup } from "../../../scripts/lib/verifier-cleanup.mjs"; -import { expect, it } from "vitest"; -import { JebProvider } from "../../../src/jeb/JebProvider.js"; -import { createStreamableHttpJebMcpConnection } from "../../../src/jeb/JebMcpConnection.js"; +import { expect, it, vi } from "vitest"; +import { createJebAnalysisProvider } from "../../../src/composition/jeb.js"; import { AnalysisTimeoutError } from "../../../src/domain/analysisErrorCore.js"; import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js"; +import { testWaitDeadline } from "../../support/testWait.js"; import { startJebMcpFixture, jebPrimaryResponses, @@ -21,40 +21,51 @@ it.each([ const gate = new Promise((resolve) => { release = resolve; }); + const timeoutMs = 100; + let reached = false; + const holdReply = async () => { + // Advance the request's clock only after it reaches the selected + // protocol phase. The real HTTP handshake uses no fake elapsed time. + reached = true; + vi.advanceTimersByTime(timeoutMs); + await gate; + }; const fixture = await startJebMcpFixture( async (tool) => { - await gate; + await holdReply(); return jebPrimaryResponses[tool]!; }, stage === "catalog" ? async () => { - await gate; + await holdReply(); return { tools: [] }; } : undefined, ); - const provider = new JebProvider({ - environment: { REA_JEB_MCP_URL: fixture.endpoint }, - connectionFactory: (endpoint) => - createStreamableHttpJebMcpConnection(endpoint, { - discoveryTimeoutMs: 100, - requestTimeoutMs: 100, - }), + const provider = createJebAnalysisProvider({ + REA_JEB_MCP_URL: fixture.endpoint, + REA_JEB_MCP_TIMEOUT_MS: String(timeoutMs), }); await withVerifierCleanup(async () => { + const signal = AbortSignal.timeout(testWaitDeadline()); + vi.useFakeTimers({ + toFake: ["setTimeout", "clearTimeout", "performance"], + }); const result = await provider.execute( operation === "inspect_jeb_client" ? { operation, input: {} } : { operation, input: { count: 2, index: 0 } }, + { signal }, ); + expect(reached).toBe(true); if (result.ok) throw new Error("Timed-out MCP request passed"); expect(result.error).toBeInstanceOf(AnalysisTimeoutError); - expect(result.error).toMatchObject({ operation, timeoutMs: 100 }); + expect(result.error).toMatchObject({ operation, timeoutMs }); const projected = projectAnalysisError(result.error); expect(projected.message).toContain( stage === "catalog" ? "catalog discovery" : "tools/call", ); - expect(projected.message).toContain("100 ms"); + expect(projected.message).toContain(`${timeoutMs} ms`); expect(projected.remediation.action).toContain("REA_JEB_MCP_TIMEOUT_MS"); expect(projected.remediation.action).toContain("2147483647"); expect(projected.remediation.action).toContain("60000"); @@ -63,7 +74,7 @@ it.each([ ); expect(projected.details?.limit).toMatchObject({ setting: "jeb.mcp_timeout_ms", - effective_value: 100, + effective_value: timeoutMs, source: "setting", update_mode: "runtime", pending_restart: false, @@ -71,7 +82,8 @@ it.each([ expect(result.error.cause).toBeDefined(); expect(result.error.cleanupIncomplete).toBe(false); }, [ - async () => { + () => { + vi.useRealTimers(); release(); }, async () => {