diff --git a/src/domain/analysisView/commandObservationView.ts b/src/domain/analysisView/commandObservationView.ts index b41c069d801..ec4563f4e08 100644 --- a/src/domain/analysisView/commandObservationView.ts +++ b/src/domain/analysisView/commandObservationView.ts @@ -43,6 +43,20 @@ export const gdbCommandSummarySchema = gdbCommandResultSchema }), }); +/** + * Keep every completion fact and replace the opaque output text with its + * size: a whole-binary disassembly can be megabytes. The complete text stays + * in the retained parent. + */ +export const objdumpCommandSummarySchema = commandObservationSchema + .omit({ stdout: true, stderr: true }) + .extend({ + available_counts: z.strictObject({ + stdout_utf16_units: z.number().int().nonnegative(), + stderr_utf16_units: z.number().int().nonnegative(), + }), + }); + const readGdbCommandResult = createAnalysisViewResultReader( gdbCommandResultSchema, ); @@ -171,9 +185,16 @@ export const projectCommandObservationView = ( }, ]), ); + const { stdout, stderr, ...facts } = report; return ok({ ...shared, parent_operation: "inspect_with_objdump" as const, - summary: report, + summary: { + ...facts, + available_counts: { + stdout_utf16_units: stdout.length, + stderr_utf16_units: stderr.length, + }, + }, }); }; diff --git a/src/domain/analysisView/summarySchemas/objdumpSummarySchema.ts b/src/domain/analysisView/summarySchemas/objdumpSummarySchema.ts index 90db68497d6..8813997898b 100644 --- a/src/domain/analysisView/summarySchemas/objdumpSummarySchema.ts +++ b/src/domain/analysisView/summarySchemas/objdumpSummarySchema.ts @@ -1,12 +1,14 @@ import { z } from "zod"; -import { commandObservationSchema } from "../../commandObservation.js"; import { artifactSchema, summaryViewResultBase } from "../analysisViewBase.js"; -import { commandSummaryContext } from "../commandObservationView.js"; +import { + commandSummaryContext, + objdumpCommandSummarySchema, +} from "../commandObservationView.js"; export const objdumpSummaryViewResultSchema = z.strictObject({ ...summaryViewResultBase, ...commandSummaryContext, parent_operation: z.literal("inspect_with_objdump"), artifact: artifactSchema.nullable(), - summary: commandObservationSchema, + summary: objdumpCommandSummarySchema, }); diff --git a/tests/boundary/cli/commandEvidenceDelivery.test.ts b/tests/boundary/cli/commandEvidenceDelivery.test.ts index 1a8843b29cc..a56de003557 100644 --- a/tests/boundary/cli/commandEvidenceDelivery.test.ts +++ b/tests/boundary/cli/commandEvidenceDelivery.test.ts @@ -165,8 +165,18 @@ it.each(kinds)( expect(f.close).toHaveBeenCalledOnce(); expect(f.closeAll).toHaveBeenCalledOnce(); } else { + const { stdout, stderr, ...facts } = z + .object({ stdout: z.string(), stderr: z.string() }) + .passthrough() + .parse(parent.normalized_result); expect(selected.normalized_result).toMatchObject({ - summary: parent.normalized_result, + summary: { + ...facts, + available_counts: { + stdout_utf16_units: stdout.length, + stderr_utf16_units: stderr.length, + }, + }, }); expect(f.runProvider).toHaveBeenCalledOnce(); expect(f.closeService).toHaveBeenCalledOnce(); diff --git a/tests/boundary/mcp/commandObservationViews.test.ts b/tests/boundary/mcp/commandObservationViews.test.ts index 35a61277b29..e06d5c34551 100644 --- a/tests/boundary/mcp/commandObservationViews.test.ts +++ b/tests/boundary/mcp/commandObservationViews.test.ts @@ -1,3 +1,4 @@ +import { z } from "zod"; import { unknownTarget } from "../../../src/domain/targetIdentity.js"; import { Client, InMemoryTransport } from "@modelcontextprotocol/client"; import pino from "pino"; @@ -203,12 +204,23 @@ it("keeps pathless objdump observations subjectless and preserves the default co ); const parent = parseEvidence(full.structuredContent); const summary = parseEvidence(selected.structuredContent); + const { stdout, stderr, ...facts } = z + .object({ stdout: z.string(), stderr: z.string() }) + .passthrough() + .parse(parent.normalized_result); expect(summary.normalized_result).toMatchObject({ parent_evidence_id: parent.evidence_id, artifact: null, source_parameters: { operation: "architectures" }, - summary: parent.normalized_result, + summary: { + ...facts, + available_counts: { + stdout_utf16_units: stdout.length, + stderr_utf16_units: stderr.length, + }, + }, }); + expect(summary.normalized_result).not.toHaveProperty("summary.stdout"); expect(summary.raw_result).toBeNull(); expect(summary.subject.identity.kind).toBe("unknown"); expect(ledger.get(parent.evidence_id)).toEqual(parent); @@ -268,10 +280,12 @@ it("rejects malformed historical GDB facts and conflicting source commands", asy }); it.each([true, false, null])( - "preserves opaque objdump capture and unknown/change facts (%s)", + "summarizes opaque objdump capture by its size and keeps unknown/change facts (%s)", async (changed) => { const report = { - stdout: "opaque output 🧪\n", + // A whole-binary disassembly can be megabytes; its summary reports only + // the output size. + stdout: "opaque output 🧪\n".repeat(64 * 1024), stderr: "diagnostic", exit_code: "ETIMEDOUT", signal: "SIGTERM", @@ -301,7 +315,17 @@ it.each([true, false, null])( view: { kind: "summary" }, }); if (!selected.ok) throw selected.error; - expect(selected.value.normalized_result).toMatchObject({ summary: report }); + const { stdout, stderr, ...facts } = report; + expect(selected.value.normalized_result).toMatchObject({ + summary: { + ...facts, + available_counts: { + stdout_utf16_units: stdout.length, + stderr_utf16_units: stderr.length, + }, + }, + }); + expect(JSON.stringify(selected.value).length).toBeLessThan(8 * 1024); if (changed !== null) { const conflicting = createEvidence( {