From 6cd055bfca0c81f7af5abc0626feeb82bea3ca3d Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:48:32 -0500 Subject: [PATCH] test: restore audited startup, launcher, and BEAM contracts (#12884) --- src/config/mcpStartupBudgets.test.ts | 22 ++++++------ src/erlang/BeamProvider.ts | 15 ++++++-- .../setup/launcherAliasesCli.test.ts | 18 ++++++---- tests/boundary/mcp/erlangBeamMcp.test.ts | 34 ++++++++++++++++--- 4 files changed, 65 insertions(+), 24 deletions(-) diff --git a/src/config/mcpStartupBudgets.test.ts b/src/config/mcpStartupBudgets.test.ts index d6ec6694d9..d173142567 100644 --- a/src/config/mcpStartupBudgets.test.ts +++ b/src/config/mcpStartupBudgets.test.ts @@ -11,16 +11,18 @@ import { it("resolves default budgets with the launch setting for each startup phase", () => { const budgets = resolveMcpStartupBudgets({}); - expect(budgets).toMatchObject({ - initialize: { setting: "REA_MCP_INITIALIZE_BUDGET_MS" }, - toolsList: { setting: "REA_MCP_TOOLS_LIST_BUDGET_MS" }, - firstCatalog: { setting: "REA_MCP_FIRST_CATALOG_BUDGET_MS" }, - doctor: { setting: "REA_MCP_DOCTOR_DEADLINE_MS" }, - }); - for (const budget of Object.values(budgets)) - expect(budget.milliseconds, budget.setting).toBe( - budget.defaultMilliseconds, - ); + for (const [phase, setting, milliseconds] of [ + ["initialize", "REA_MCP_INITIALIZE_BUDGET_MS", 15_000], + ["toolsList", "REA_MCP_TOOLS_LIST_BUDGET_MS", 5_000], + ["firstCatalog", "REA_MCP_FIRST_CATALOG_BUDGET_MS", 20_000], + ["doctor", "REA_MCP_DOCTOR_DEADLINE_MS", 30_000], + ] as const) + expect(budgets[phase]).toMatchObject({ + setting, + milliseconds, + defaultMilliseconds: milliseconds, + source: "default", + }); }); it("admits distinct overrides for all four startup phases", () => { diff --git a/src/erlang/BeamProvider.ts b/src/erlang/BeamProvider.ts index ed1dd40091..3f674421bd 100644 --- a/src/erlang/BeamProvider.ts +++ b/src/erlang/BeamProvider.ts @@ -19,6 +19,7 @@ import { AnalysisAccessDeniedError, AnalysisInputError, AnalysisResourceConstraintError, + type ResourceConstraintRecovery, } from "../domain/analysisErrorCore.js"; import { MAX_INSPECT_ERLANG_BEAM_ATOMS, @@ -27,6 +28,7 @@ import { type InspectErlangBeamInput, } from "../domain/erlang/beam.js"; import { err, ok } from "../domain/result.js"; +import { fixedAllowanceOptions } from "../domain/fixedAllowanceRemediation.js"; import type { LimitRef } from "../domain/parseFailure.js"; import { isParseLimit, @@ -93,8 +95,6 @@ const parserBudgetRemediation = ({ name, maximum }: LimitRef) => { return maximum >= MAX_INSPECT_ERLANG_BEAM_ATOMS ? `The file exceeds the ${String(MAX_INSPECT_ERLANG_BEAM_ATOMS)}-atom ceiling this operation accepts; select a smaller artifact.` : `Raise max_atoms above ${String(maximum)} or select a smaller artifact; the limit is the caller-selected atom budget.`; - case "max_table_rows": - return `The file exceeds the ${String(maximum)}-row ceiling this operation accepts; select a smaller artifact.`; case "max_chunks": return maximum >= MAX_INSPECT_ERLANG_BEAM_CHUNKS ? `The file exceeds the ${String(MAX_INSPECT_ERLANG_BEAM_CHUNKS)}-chunk ceiling this operation accepts; select a smaller artifact.` @@ -122,11 +122,20 @@ const beamFailurePrimary = ( if (origin === "owned-or-classified" && isParseLimit(cause, "beam")) { const { limit } = cause.failure; const remediationAction = parserBudgetRemediation(limit); + const recovery: ResourceConstraintRecovery = + limit.name === "max_table_rows" + ? fixedAllowanceOptions("BEAM table row ceiling", "parser", { + limit: limit.maximum, + unit: "rows", + }) + : remediationAction === undefined + ? {} + : { remediationAction }; return parseLimitConstraint(OPERATION, "capacity", cause, { reportedLimitContext: reportedLimits, legacyMaximumKey: limit.name, - ...(remediationAction === undefined ? {} : { remediationAction }), retryable: false, + ...recovery, }); } if ( diff --git a/tests/acceptance/setup/launcherAliasesCli.test.ts b/tests/acceptance/setup/launcherAliasesCli.test.ts index 2b09aee9ae..423c206ce2 100644 --- a/tests/acceptance/setup/launcherAliasesCli.test.ts +++ b/tests/acceptance/setup/launcherAliasesCli.test.ts @@ -11,6 +11,15 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { cliTest } from "../../support/cli/cliFixture.js"; import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; +const registrationPathWithoutRuntime = async (root: string) => { + const restrictedPath = join(root, "path-without-runtime"); + await mkdir(restrictedPath); + // Linux process ownership requires procps; no JavaScript runtime is exposed. + if (process.platform === "linux") + await symlink("/bin/ps", join(restrictedPath, "ps")); + return restrictedPath; +}; + cliTest.skipIf(process.platform === "win32")( "migrates an owned shebang registration and starts its generated MCP command without a runtime on PATH", async ({ cli }) => { @@ -18,11 +27,7 @@ cliTest.skipIf(process.platform === "win32")( const profile = join(home, ".qwen"); const config = join(profile, "settings.json"); const entrypoint = resolve("scripts/rea.mjs"); - const restrictedPath = join(home, "path-without-runtime"); - await mkdir(restrictedPath); - // Linux process ownership requires procps; no JavaScript runtime is exposed. - if (process.platform === "linux") - await symlink("/bin/ps", join(restrictedPath, "ps")); + const restrictedPath = await registrationPathWithoutRuntime(home); const retainedEnvironment = { PATH: restrictedPath, CALLER_SETTING: "keep exactly", @@ -151,6 +156,7 @@ cliTest.skipIf(process.platform === "win32").for([ const root = await createTestTempDirectory("rea-launcher-registration-"); const home = join(root, "home"); const config = join(home, ".cursor/mcp.json"); + const restrictedPath = await registrationPathWithoutRuntime(root); await mkdir(join(home, ".cursor"), { recursive: true }); const unrelated = { command: "other-server", args: [] }; await writeFile(config, JSON.stringify({ mcpServers: { unrelated } })); @@ -163,7 +169,7 @@ cliTest.skipIf(process.platform === "win32").for([ HOME: home, USERPROFILE: home, XDG_CONFIG_HOME: join(home, ".config"), - PATH: process.env.PATH ?? "", + PATH: restrictedPath, }, }); diff --git a/tests/boundary/mcp/erlangBeamMcp.test.ts b/tests/boundary/mcp/erlangBeamMcp.test.ts index c11922408a..96a52ff453 100644 --- a/tests/boundary/mcp/erlangBeamMcp.test.ts +++ b/tests/boundary/mcp/erlangBeamMcp.test.ts @@ -12,6 +12,7 @@ import { writeFile } from "node:fs/promises"; import { join } from "node:path"; import { expect } from "vitest"; import { toolContract } from "../../../src/contracts/toolContracts.js"; +import { analysisRefusalRemediation } from "../../../src/domain/analysisRefusal.js"; import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; @@ -96,7 +97,17 @@ mcpTest( const root = await createTestTempDirectory("rea-beam-capacity-"); const rowLimit = MAX_INSPECT_ERLANG_BEAM_TABLE_ROWS; const halfRowLimit = Math.floor(rowLimit / 2); - const rowRemediation = `The file exceeds the ${String(rowLimit)}-row ceiling this operation accepts; select a smaller artifact.`; + const rowRefusal = { + kind: "fixed_ceiling", + operation: "inspect_erlang_beam", + ceiling: { + name: "BEAM table row ceiling", + kind: "parser", + limit: rowLimit, + unit: "rows", + }, + } as const; + const rowRemediation = analysisRefusalRemediation(rowRefusal); try { for (const [label, bytes, settings, budget, remediation] of [ [ @@ -106,14 +117,14 @@ mcpTest( ]), { max_atoms: 1 }, { max_atoms: 1 }, - "Raise max_atoms above 1", + expect.stringContaining("Raise max_atoms above 1"), ], [ "chunks", erlangBeamFixture(), { max_chunks: 1 }, { max_chunks: 1 }, - "Raise max_chunks above 1", + expect.stringContaining("Raise max_chunks above 1"), ], [ "single-table-rows", @@ -144,8 +155,21 @@ mcpTest( expect(error, label).toMatchObject({ code: "resource_constraint", retryable: false, - remediation: { action: expect.stringContaining(remediation) }, - details: { resource: "capacity", reported_limits: budget }, + remediation: { action: remediation }, + details: { + resource: "capacity", + reported_limits: budget, + ...("max_table_rows" in budget + ? { + refusal: { + kind: "fixed_ceiling", + allowance_kind: "parser", + limit: rowLimit, + unit: "rows", + }, + } + : {}), + }, }); } const malformed = join(root, "malformed-atoms.beam");