mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
test(jeb): verify configured deadlines at the real protocol boundary (#11883)
This commit is contained in:
1 parent
0eb54a801b
commit
dbfb9bade2
4 files changed
+61
-115
No files matched your search
@@ -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,
|
||||
|
||||
+19
-75
@@ -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 () => {
|
||||
|
||||
@@ -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(
|
||||
[
|
||||
|
||||
@@ -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<void>((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 () => {
|
||||
|
||||
Reference in new issue
Block a user