diff --git a/docs/design/limits-and-recovery.md b/docs/design/limits-and-recovery.md index 074f64d2b4..aaa687a713 100644 --- a/docs/design/limits-and-recovery.md +++ b/docs/design/limits-and-recovery.md @@ -294,9 +294,12 @@ to parse that sentence to identify an editable setting. A deadline controlled by something other than a registered setting reports `details.limit` with `control_kind` instead of `setting`. -`control_kind: "parameter"` names the per-call `parameter` and its `cli_flag` +`control_kind: "parameter"` names the per-call contract field in `parameter` (`native_command_timeout_ms`, `native_ui_deadline_ms`, -`pwntools_timeout_ms`) and applies on the next call. +`pwntools_timeout_ms`) and applies on the next call. Services and their +remediation text name only that field. A CLI command adds `cli_flag`, the +option that sets the field on that command, from its own field-to-flag +binding; MCP results do not carry it. `control_kind: "environment"` names the `environment` variable REA reads when it starts (`REA_SWIFTC_COMPILE_TIMEOUT_MS`): `applies_at` is `next_startup`, or `next_invocation` for a one-shot invocation. Both carry `effective_value`, diff --git a/scripts/verify/baselines/cli-option-text-outside-cli.json b/scripts/verify/baselines/cli-option-text-outside-cli.json index 6bf50555ac..d4bd3d3f6e 100644 --- a/scripts/verify/baselines/cli-option-text-outside-cli.json +++ b/scripts/verify/baselines/cli-option-text-outside-cli.json @@ -2,8 +2,7 @@ "src/application/Doctor.ts": 1, "src/application/EvidenceBundleFiles.ts": 1, "src/application/decompileDirectory/decompileAll.ts": 1, - "src/application/reverse/ReverseEngineeringService.ts": 2, - "src/application/wasm/WasmArtifactService.ts": 1, + "src/application/reverse/ReverseEngineeringService.ts": 1, "src/domain/analysisErrorPresentation.ts": 2, "src/domain/javascript/javascriptAnalysisResourceControls.ts": 5, "src/domain/javascript/javascriptSemanticResourceLimits.ts": 1, @@ -15,11 +14,9 @@ "src/ghidra/GhidraProviderClient.ts": 2, "src/javascript/analysis/JavaScriptAnalysisWorker.ts": 1, "src/native/AppleDispatchMetadata.ts": 1, - "src/native/NativeCommandAnalysisError.ts": 2, "src/native/NativePlistSource.ts": 1, - "src/native/NativeUiInterruptionControl.ts": 1, "src/native/pwntools/PwntoolsDecoder.ts": 2, - "src/native/pwntools/PwntoolsFailures.ts": 5, + "src/native/pwntools/PwntoolsFailures.ts": 4, "src/rust/RustBinaryProvider.ts": 6, "src/sqlite/SqliteDatabaseWorkerExecution.ts": 1 } diff --git a/src/application/reverse/ReverseEngineeringService.ts b/src/application/reverse/ReverseEngineeringService.ts index 15dba731d6..954d811f5b 100644 --- a/src/application/reverse/ReverseEngineeringService.ts +++ b/src/application/reverse/ReverseEngineeringService.ts @@ -1,5 +1,5 @@ import { HOST_PLATFORM } from "../../platform/HostPlatform.js"; -import { MAX_NODE_TIMER_DELAY_MS } from "../../domain/analysisResourceLimits.js"; +import { nativeDeadlineRecovery } from "../../domain/native/nativeDeadlines.js"; import { Budget } from "../../domain/budget.js"; import { ArtifactResourceScope, @@ -1459,17 +1459,20 @@ const runtimeControlPreparationError = ( return windowsNativeSpawnControlError(cause); }; -const reverseCommandTimeoutGuidance = ( - provider: string, - timeoutMs: number, -): { readonly userMessage: string; readonly remediationAction: string } => ({ - userMessage: `This ${provider} command reached its ${String(timeoutMs)} ms server/provider deadline (command_timeout_ms) during target preflight or the one-shot command (deadlineExpired). This is not a Ghidra or Hopper startup deadline and not a debugger session deadline.`, - remediationAction: `${ - timeoutMs < MAX_NODE_TIMER_DELAY_MS - ? `Increase command_timeout_ms above ${String(timeoutMs)} (integer milliseconds from 1 to ${String(MAX_NODE_TIMER_DELAY_MS)}; omitted means ${String(DEFAULT_REVERSE_COMMAND_TIMEOUT_MS)}), or use --command-timeout-ms on the CLI.` - : `command_timeout_ms is already at the maximum ${String(MAX_NODE_TIMER_DELAY_MS)} ms; no higher deadline is supported.` - } The new value applies on the next call; no restart is required. The combined output allowance is separately selected by max_output_bytes (default ${String(DEFAULT_REVERSE_COMMAND_OUTPUT_BYTES)} bytes). Allow execution, cleanup and delivery headroom in the outer MCP client deadline. Confirm outstanding work and cleanup before retrying.`, -}); +/** + * The deadline failure names `command_timeout_ms` and binds it as the + * per-call control; each adapter names the option that sets it. + */ +const reverseCommandTimeoutGuidance = (provider: string, timeoutMs: number) => + nativeDeadlineRecovery({ + timeoutMs, + parameter: "command_timeout_ms", + defaultMs: DEFAULT_REVERSE_COMMAND_TIMEOUT_MS, + phase: `${provider} command deadline`, + unchanged: `No restart is required. The combined output allowance is separately selected by max_output_bytes (default ${String(DEFAULT_REVERSE_COMMAND_OUTPUT_BYTES)} bytes).`, + detail: + " It covers target preflight and the one-shot command (deadlineExpired); it is not a Ghidra or Hopper startup deadline or a debugger session deadline.", + }); export const digestFile = async ( path: string, diff --git a/src/application/wasm/WasmArtifactService.ts b/src/application/wasm/WasmArtifactService.ts index 773175a89d..68a01680f1 100644 --- a/src/application/wasm/WasmArtifactService.ts +++ b/src/application/wasm/WasmArtifactService.ts @@ -74,7 +74,17 @@ export class WasmArtifactService { }, { retryable: false, - remediationAction: `Raise max_artifact_paths to at least ${String(input.value[field].length)} (maximum ${String(MAX_WASM_ARTIFACT_PATHS)}), or use --max-artifact-paths on the CLI; then retry the same selection. The value applies on the next inspection without restart. File and command byte budgets remain independent.`, + remediationAction: `Raise max_artifact_paths to at least ${String(input.value[field].length)} (maximum ${String(MAX_WASM_ARTIFACT_PATHS)}); then retry the same selection. The value applies on the next inspection without restart. File and command byte budgets remain independent.`, + limit: { + control_kind: "parameter", + parameter: "max_artifact_paths", + effective_value: maximumPaths, + unit: "count", + minimum: 1, + maximum: MAX_WASM_ARTIFACT_PATHS, + default_value: DEFAULT_WASM_ARTIFACT_PATHS, + applies_at: "next_call", + }, }, ), ); diff --git a/src/cli/contractCliDescription.ts b/src/cli/contractCliDescription.ts index ff30f3609f..bf08462887 100644 --- a/src/cli/contractCliDescription.ts +++ b/src/cli/contractCliDescription.ts @@ -686,11 +686,14 @@ export interface ContractCliDescription { readonly evidenceTargets: ContractCliEvidenceTargets | undefined; /** * Contract fields the CLI spells differently, so input issues reported - * after argv parsing can name the CLI key. + * after argv parsing can name the CLI key, and the flag of each contract + * field (or `field.member`) the command takes as an option, so a failure + * that names a per-call control can name the flag that sets it. */ readonly inputBinding: { readonly operation: string; readonly fields: Readonly>; + readonly flags: Readonly>; }; /** The command adds `--detail` and `--evidence_output`. */ readonly evidenceDelivery: boolean; @@ -2406,6 +2409,18 @@ export const describeContractCommand = < ...(evidenceTargets?.targets ?? []), ].flatMap(({ field, key }) => (key === field ? [] : [[field, key]])), ), + flags: Object.fromEntries( + parameters.flatMap(({ field, key, member, positional, delivery }) => + positional || delivery + ? [] + : [ + [ + member === undefined ? field : [field, ...member].join("."), + `--${kebabCase(key)}`, + ], + ], + ), + ), }, evidenceDelivery, admit: (values) => { diff --git a/src/cli/contractCommand.ts b/src/cli/contractCommand.ts index 2323cf2796..7908d9626d 100644 --- a/src/cli/contractCommand.ts +++ b/src/cli/contractCommand.ts @@ -384,7 +384,11 @@ export const runOnEvidenceTargets = error: "Analysis failed", ...projectAnalysisError(retainSources(source.error), "invocation"), }, - { operation: evidenceTargets.source, fields: { path: key } }, + { + operation: evidenceTargets.source, + fields: { path: key }, + flags: {}, + }, ); sources[field] = source.value; } diff --git a/src/cli/projectCliAnalysisResult.ts b/src/cli/projectCliAnalysisResult.ts index 8610850681..10ecfcab4e 100644 --- a/src/cli/projectCliAnalysisResult.ts +++ b/src/cli/projectCliAnalysisResult.ts @@ -4,6 +4,8 @@ import type { Result } from "../domain/result.js"; interface CliInputFieldBinding { readonly operation: string; readonly fields: Readonly>; + /** Each contract field, or `field.member`, the command takes as a flag. */ + readonly flags: Readonly>; } /** Flatten a finalized outcome only when returning the command's JSON output. */ @@ -17,19 +19,39 @@ export const isObject = ( value !== null && typeof value === "object" && !Array.isArray(value); /** - * Rename only the actionable parameter paths owned by this operation binding - * in a contract command's output: a direct failure, a delivered failure or a - * refused publication. Any other output is returned unchanged. + * Name a contract command's input fields by their CLI spelling in its + * output: a direct failure, a delivered failure or a refused publication. + * Issue paths owned by this operation take the CLI key, and a per-call + * control a failure reports (`details.limit.parameter`, which services name + * by contract field) gains `cli_flag`, the option that sets it on this + * command. Any other output is returned unchanged. */ export const projectCliInputFields = ( output: Output, binding: CliInputFieldBinding, ): Output => { const error = output as JsonValue; - if (!isObject(error)) return output; - const details = error.details; + if (!isObject(error) || !isObject(error.details)) return output; + const issues = renamedIssues(error, error.details, binding); + const limit = flaggedLimit(error.details.limit, binding); + if (issues === undefined && limit === undefined) return output; + return { + ...error, + details: { + ...error.details, + ...(issues === undefined ? {} : { issues }), + ...(limit === undefined ? {} : { limit }), + }, + } as Output; +}; + +/** Issue paths renamed to CLI keys, or undefined when none changes. */ +const renamedIssues = ( + error: Record, + details: Record, + binding: CliInputFieldBinding, +): JsonValue[] | undefined => { if ( - !isObject(details) || details.operation !== binding.operation || !Array.isArray(details.issues) || (error.code !== "invalid_request" && @@ -38,8 +60,7 @@ export const projectCliInputFields = ( details.execution_failure === "invalid_request" )) ) - return output; - + return undefined; let changed = false; const issues = details.issues.map((issue) => { if (!isObject(issue) || !Array.isArray(issue.path)) return issue; @@ -53,7 +74,29 @@ export const projectCliInputFields = ( }); // Keep retained output, partial Evidence and cleanup history by reference; // their source fields are not CLI parameter names. - return changed - ? ({ ...error, details: { ...details, issues } } as Output) - : output; + return changed ? issues : undefined; +}; + +/** + * The reported per-call control with the flag that sets it, or undefined + * when the command takes no flag for it. The longest bound prefix of the + * parameter path names the flag: a flattened member option, else the option + * of the whole field (such as `--producer-limits` JSON). + */ +const flaggedLimit = ( + limit: JsonValue | undefined, + binding: CliInputFieldBinding, +): Record | undefined => { + if ( + !isObject(limit) || + limit.control_kind !== "parameter" || + typeof limit.parameter !== "string" + ) + return undefined; + const segments = limit.parameter.split("."); + for (let length = segments.length; length > 0; length -= 1) { + const flag = binding.flags[segments.slice(0, length).join(".")]; + if (flag !== undefined) return { ...limit, cli_flag: flag }; + } + return undefined; }; diff --git a/src/domain/analysisSettings.ts b/src/domain/analysisSettings.ts index a8258da2d1..5e876ba50f 100644 --- a/src/domain/analysisSettings.ts +++ b/src/domain/analysisSettings.ts @@ -102,8 +102,6 @@ export type AnalysisControlLimit = { | { readonly control_kind: "parameter"; readonly parameter: string; - /** CLI spelling of the same per-call parameter. */ - readonly cli_flag: string; readonly applies_at: "next_call"; } | { diff --git a/src/domain/native/nativeDeadlines.ts b/src/domain/native/nativeDeadlines.ts index c4f83b1739..f95cce3bda 100644 --- a/src/domain/native/nativeDeadlines.ts +++ b/src/domain/native/nativeDeadlines.ts @@ -75,7 +75,6 @@ export const readNativeDeadline = ( export const nativeDeadlineRecovery = (input: { readonly timeoutMs: number; readonly parameter: string; - readonly cliFlag: string; readonly defaultMs: number; readonly phase: string; readonly unchanged: string; @@ -87,15 +86,14 @@ export const nativeDeadlineRecovery = (input: { } => { const atMaximum = input.timeoutMs >= MAX_NODE_TIMER_DELAY_MS; const adjustment = atMaximum - ? `${input.parameter} (${input.cliFlag} on the CLI) is already at the maximum ${String(MAX_NODE_TIMER_DELAY_MS)} ms; do not increase it.` - : `Increase ${input.parameter} above ${String(input.timeoutMs)} (integer milliseconds from 1 to ${String(MAX_NODE_TIMER_DELAY_MS)}; omitted means ${String(input.defaultMs)}), or pass ${input.cliFlag} on the CLI. A change applies on the next call.`; + ? `${input.parameter} is already at the maximum ${String(MAX_NODE_TIMER_DELAY_MS)} ms; do not increase it.` + : `Increase ${input.parameter} above ${String(input.timeoutMs)} (integer milliseconds from 1 to ${String(MAX_NODE_TIMER_DELAY_MS)}; omitted means ${String(input.defaultMs)}). A change applies on the next call.`; return { userMessage: `This request reached REA's ${input.phase} of ${String(input.timeoutMs)} ms (${input.parameter}). This is a server/provider deadline, not the MCP client deadline.${input.detail ?? ""}`, remediationAction: `${adjustment} ${input.unchanged} Allow execution, cleanup, and delivery headroom in the outer MCP client deadline. Confirm outstanding work and cleanup before retrying.`, limit: { control_kind: "parameter", parameter: input.parameter, - cli_flag: input.cliFlag, effective_value: input.timeoutMs, unit: "ms", minimum: 1, diff --git a/src/native/NativeCommandAnalysisError.test.ts b/src/native/NativeCommandAnalysisError.test.ts index 1fa6abd82e..005e6ace80 100644 --- a/src/native/NativeCommandAnalysisError.test.ts +++ b/src/native/NativeCommandAnalysisError.test.ts @@ -123,7 +123,6 @@ describe("translateNativeCommandFailure", () => { expect(projectAnalysisError(error).details?.limit).toEqual({ control_kind: "parameter", parameter: "native_command_timeout_ms", - cli_flag: "--native-command-timeout-ms", effective_value: 60_000, unit: "ms", minimum: 1, diff --git a/src/native/NativeCommandAnalysisError.ts b/src/native/NativeCommandAnalysisError.ts index a852d942f7..529ead3ff9 100644 --- a/src/native/NativeCommandAnalysisError.ts +++ b/src/native/NativeCommandAnalysisError.ts @@ -115,7 +115,6 @@ export const translateNativeCommandFailure = ( nativeDeadlineRecovery({ timeoutMs, parameter: "native_command_timeout_ms", - cliFlag: "--native-command-timeout-ms", defaultMs: DEFAULT_NATIVE_COMMAND_TIMEOUT_MS, phase: "macOS native command deadline", unchanged: `The ${String(NATIVE_COMMAND_OUTPUT_BUDGET_BYTES)}-byte command output allowance and the ${String(NATIVE_FAILURE_DIAGNOSTIC_BYTES)}-byte failure-diagnostic excerpt have no runtime override.`, @@ -201,7 +200,6 @@ export const translateNativeCommandFailure = ( nativeDeadlineRecovery({ timeoutMs, parameter: "native_command_timeout_ms", - cliFlag: "--native-command-timeout-ms", defaultMs: DEFAULT_NATIVE_COMMAND_TIMEOUT_MS, phase: "macOS native command deadline", unchanged: `The ${String(NATIVE_COMMAND_OUTPUT_BUDGET_BYTES)}-byte command output allowance and the ${String(NATIVE_FAILURE_DIAGNOSTIC_BYTES)}-byte failure-diagnostic excerpt have no runtime override.`, diff --git a/src/native/NativeUiInterruptionControl.ts b/src/native/NativeUiInterruptionControl.ts index 4a7d386b32..cd79c0740b 100644 --- a/src/native/NativeUiInterruptionControl.ts +++ b/src/native/NativeUiInterruptionControl.ts @@ -92,7 +92,6 @@ export class NativeUiInterruptionControl { ...nativeDeadlineRecovery({ timeoutMs: this.#deadlineMs, parameter: "native_ui_deadline_ms", - cliFlag: "--native-ui-deadline-ms", defaultMs: DEFAULT_NATIVE_UI_DEADLINE_MS, phase: "native UI observation deadline", detail: " A partial observation may already be retained.", diff --git a/src/native/pwntools/PwntoolsFailures.test.ts b/src/native/pwntools/PwntoolsFailures.test.ts index c0953bfccf..3f3502cbd4 100644 --- a/src/native/pwntools/PwntoolsFailures.test.ts +++ b/src/native/pwntools/PwntoolsFailures.test.ts @@ -121,7 +121,6 @@ it("distinguishes the wall deadline from caller-selected producer resource budge expect(projected.details?.limit).toMatchObject({ control_kind: "parameter", parameter: "pwntools_timeout_ms", - cli_flag: "--pwntools-timeout-ms", effective_value: 4_500, default_value: 30_000, }); diff --git a/src/native/pwntools/PwntoolsFailures.ts b/src/native/pwntools/PwntoolsFailures.ts index c95e40b3a3..09fc17d10c 100644 --- a/src/native/pwntools/PwntoolsFailures.ts +++ b/src/native/pwntools/PwntoolsFailures.ts @@ -227,7 +227,6 @@ const pwntoolsCommandContext = ( const deadline = nativeDeadlineRecovery({ timeoutMs, parameter: "pwntools_timeout_ms", - cliFlag: "--pwntools-timeout-ms", defaultMs: PWNTOOLS_LIMITS.command_timeout_ms, phase: "pwntools command deadline", unchanged: budgetRecovery, diff --git a/tests/boundary/cli/cliControlFlag.test.ts b/tests/boundary/cli/cliControlFlag.test.ts new file mode 100644 index 0000000000..a282a2bc44 --- /dev/null +++ b/tests/boundary/cli/cliControlFlag.test.ts @@ -0,0 +1,157 @@ +import { Cli } from "incur"; +import { expect, it } from "vitest"; +import { z } from "zod"; + +import { registerContractCommand } from "../../../src/cli/contractCommand.js"; +import { describeContractCommand } from "../../../src/cli/contractCliDescription.js"; +import { projectCliInputFields } from "../../../src/cli/projectCliAnalysisResult.js"; +import type { CliInstance } from "../../../src/cli/types.js"; +import { AnalysisTimeoutError } from "../../../src/domain/analysisErrorCore.js"; +import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js"; +import { nativeDeadlineRecovery } from "../../../src/domain/native/nativeDeadlines.js"; +import { silentLogger } from "../../../src/logger.js"; + +const contract = { + name: "inspect_control_fixture", + inputSchema: z.strictObject({ + path: z.string(), + worker_timeout_ms: z.number().int().optional(), + }), +}; + +/** The failure a service reports: it names the contract field only. */ +const deadlineFailure = () => + projectAnalysisError( + new AnalysisTimeoutError(contract.name, 5, { + ...nativeDeadlineRecovery({ + timeoutMs: 5, + parameter: "worker_timeout_ms", + defaultMs: 1_000, + phase: "fixture deadline", + unchanged: "", + }), + }), + ); + +it("names the service's per-call control by field over MCP and by flag on the CLI", async () => { + const mcp = deadlineFailure(); + expect(mcp.details?.limit).toMatchObject({ + control_kind: "parameter", + parameter: "worker_timeout_ms", + }); + expect(mcp.details?.limit).not.toHaveProperty("cli_flag"); + expect(JSON.stringify(mcp)).not.toContain("--"); + + const cli = Cli.create("rea-control-flag", { version: "1", sync: false }); + registerContractCommand( + cli as unknown as CliInstance, + silentLogger, + contract, + { + command: "inspect-control-fixture", + description: "Control fixture", + positionals: ["path"], + }, + async () => deadlineFailure(), + ); + const command = Cli.toCommands.get(cli)?.get("inspect-control-fixture"); + if (command === undefined) throw new Error("command is not registered"); + const parse = (key: "args" | "options", value: unknown) => + (Reflect.get(command, key) as { parse(v: unknown): unknown }).parse(value); + // A failed command sets the shared worker's exit status. + const previousExitCode = process.exitCode; + let output: ReturnType; + try { + output = (await ( + Reflect.get(command, "run") as (value: unknown) => Promise + )({ + args: parse("args", { path: "fixture.bin" }), + options: parse("options", { workerTimeoutMs: 5 }), + })) as ReturnType; + } finally { + process.exitCode = previousExitCode; + } + expect(output.details?.limit).toEqual({ + ...(mcp.details?.limit as object), + cli_flag: "--worker-timeout-ms", + }); + expect(output.remediation).toEqual(mcp.remediation); +}); + +it("names a member control by its member flag, else by its field's flag", () => { + const failure = (parameter: string) => ({ + code: "provider_timeout", + details: { limit: { control_kind: "parameter", parameter } }, + }); + const binding = { + operation: "fixture", + fields: {}, + flags: { + producer_limits: "--producer-limits", + "pool_policy.uri_limit": "--uri-limit", + }, + }; + expect( + projectCliInputFields(failure("producer_limits.output_bytes"), binding), + ).toMatchObject({ details: { limit: { cli_flag: "--producer-limits" } } }); + expect( + projectCliInputFields(failure("pool_policy.uri_limit"), binding), + ).toMatchObject({ details: { limit: { cli_flag: "--uri-limit" } } }); + // A control the command does not take as a flag keeps the field only. + const unbound = failure("analysis_timeout_ms"); + expect(projectCliInputFields(unbound, binding)).toBe(unbound); + const success = { details: { limit: { parameter: "producer_limits" } } }; + expect(projectCliInputFields(success, binding)).toBe(success); +}); + +it("binds a nested flattened member to its own flag", () => { + const description = describeContractCommand( + { + name: "inspect_nested_fixture", + inputSchema: z.strictObject({ + path: z.string(), + protobuf: z + .strictObject({ + schema: z + .strictObject({ message_type: z.string().optional() }) + .optional(), + }) + .optional(), + }), + }, + { + command: "inspect-nested-fixture", + description: "Nested fixture", + positionals: ["path"], + flatten: { + protobuf: { + schema: { + flatten: { + message_type: { + name: "protobufMessage", + description: "Message type", + }, + }, + }, + }, + }, + }, + ); + expect(description.inputBinding.flags).toEqual({ + "protobuf.schema.message_type": "--protobuf-message", + }); + expect( + projectCliInputFields( + { + code: "resource_limit_exceeded", + details: { + limit: { + control_kind: "parameter", + parameter: "protobuf.schema.message_type", + }, + }, + }, + description.inputBinding, + ), + ).toMatchObject({ details: { limit: { cli_flag: "--protobuf-message" } } }); +}); diff --git a/tests/boundary/cli/projectCliAnalysisResult.test.ts b/tests/boundary/cli/projectCliAnalysisResult.test.ts index 7049e8ff64..fd522bfdbb 100644 --- a/tests/boundary/cli/projectCliAnalysisResult.test.ts +++ b/tests/boundary/cli/projectCliAnalysisResult.test.ts @@ -15,6 +15,7 @@ import { const binding = { operation: "inspect_keyed_archive", fields: { path: "archive" }, + flags: {}, }; it("projects bound input fields without changing canonical facts or nested identities", () => { diff --git a/tests/boundary/cli/reverseEngineeringCommands.test.ts b/tests/boundary/cli/reverseEngineeringCommands.test.ts index 07b9894fff..801a0bdbbc 100644 --- a/tests/boundary/cli/reverseEngineeringCommands.test.ts +++ b/tests/boundary/cli/reverseEngineeringCommands.test.ts @@ -328,6 +328,22 @@ it("preserves an operation timeout and unknown partial Evidence after cleanup re expect(timeout).toBeInstanceOf(AnalysisTimeoutError); expect(timeout?.cleanupIncomplete).toBe(false); expect(owner.stop).toHaveBeenCalledOnce(); + // The service names the contract field; the CLI adds the flag that sets it. + expect(timeout?.limit).toMatchObject({ + control_kind: "parameter", + parameter: "command_timeout_ms", + }); + expect( + JSON.stringify((result as { remediation?: unknown }).remediation), + ).not.toContain("--"); + expect(result).toMatchObject({ + details: { + limit: { + parameter: "command_timeout_ms", + cli_flag: "--command-timeout-ms", + }, + }, + }); } finally { await service.close().catch(() => undefined); await rm(directory, { recursive: true, force: true }); diff --git a/tests/boundary/cli/wasmAcquiredInputsCli.test.ts b/tests/boundary/cli/wasmAcquiredInputsCli.test.ts index 9b9cdd2b3d..cb806720b1 100644 --- a/tests/boundary/cli/wasmAcquiredInputsCli.test.ts +++ b/tests/boundary/cli/wasmAcquiredInputsCli.test.ts @@ -210,3 +210,40 @@ cliTest( } }, ); + +cliTest( + "names max_artifact_paths by field and the CLI flag that sets it before reading selections", + async ({ cli }) => { + const directory = await createTestTempDirectory("rea-wasm-paths-"); + const invocation = await cli.run({ + arguments: [ + "inspect-wasm-artifact", + "./selected.wasm", + "--glue_paths", + "./first.js", + "--glue_paths", + "./second.js", + "--max-artifact-paths", + "1", + "--format", + "json", + ], + environment: { HOME: directory, XDG_CONFIG_HOME: directory }, + cwd: directory, + }); + expect(invocation.exitCode, invocation.stderr).toBe(1); + const cliError = analysisErrorProjectionSchema.parse(invocation.json); + expect(cliError).toMatchObject({ + code: "resource_constraint", + details: { + limit: { + control_kind: "parameter", + parameter: "max_artifact_paths", + effective_value: 1, + cli_flag: "--max-artifact-paths", + }, + }, + }); + expect(JSON.stringify(cliError.remediation)).not.toContain("--"); + }, +);