feat(signals): decode recordings with bounded sigrok output (#2339)
Decode caller-selected protocols from existing recordings through shared CLI/MCP Evidence. Page literal output lines after complete decoding; preserve explicit full output, source identity and failed cleanup ownership. Verified real sigrok-cli 0.7.2 workflows, published UART/SPI/I2C recordings, independent UART values, selector limits, SDK schemas and cleanup regressions. Co-authored-by: Olorinm <59321404+Olorinm@users.noreply.github.com> Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
import { createEvidence } from "../../../src/domain/evidence.js";
|
||||
import { AnalysisCancelledError } from "../../../src/domain/analysisErrorCore.js";
|
||||
import { ProviderCleanupError } from "../../../src/domain/providerCleanupError.js";
|
||||
import { SignalRecordingService } from "../../../src/application/signals/SignalRecordingService.js";
|
||||
import { err } from "../../../src/domain/result.js";
|
||||
import { expect, it, onTestFinished } from "vitest";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
|
||||
it("advertises valid target-free signal decoding schemas and actionable missing-tool diagnostics", async () => {
|
||||
const harness = await createApplicationMcpHarness({
|
||||
serverOptions: { environment: {} },
|
||||
});
|
||||
onTestFinished(harness.close);
|
||||
const tool = (await harness.client.listTools()).tools.find(
|
||||
({ name }) => name === "decode_signal_recording",
|
||||
);
|
||||
if (tool?.outputSchema === undefined) throw new Error("Signal tool missing");
|
||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||
const inputSchema: Record<string, unknown> = tool.inputSchema;
|
||||
const outputSchema: Record<string, unknown> = tool.outputSchema;
|
||||
expect(ajv.validateSchema(inputSchema)).toBe(true);
|
||||
expect(ajv.validateSchema(outputSchema)).toBe(true);
|
||||
const input = {
|
||||
path: process.platform === "win32" ? "C:\\recording.vcd" : "/recording.vcd",
|
||||
decoders: "uart",
|
||||
};
|
||||
expect(ajv.validate(inputSchema, input)).toBe(true);
|
||||
expect(ajv.validate(inputSchema, { ...input, driver: "demo" })).toBe(false);
|
||||
const result = await harness.client.callTool({
|
||||
name: tool.name,
|
||||
arguments: input,
|
||||
});
|
||||
expect(parseMcpToolError(result)).toMatchObject({
|
||||
error: {
|
||||
code: "capability_unavailable",
|
||||
details: {
|
||||
operation: tool.name,
|
||||
reason: expect.stringContaining("REA_SIGROK_COMMAND"),
|
||||
},
|
||||
},
|
||||
});
|
||||
await harness.client.ping();
|
||||
});
|
||||
|
||||
it.each(["cancelled", "cleanup"])(
|
||||
"retains completed Evidence after %s failure",
|
||||
async (kind) => {
|
||||
const input = {
|
||||
path:
|
||||
process.platform === "win32" ? "C:\\recording.vcd" : "/recording.vcd",
|
||||
decoders: "uart",
|
||||
};
|
||||
const evidence = createEvidence(
|
||||
undefined,
|
||||
{ id: "fixture", name: "Completed decoder fixture", version: "1" },
|
||||
{
|
||||
operation: "decode_signal_recording",
|
||||
parameters: input,
|
||||
result: { annotations_text: "10-20 uart-1: 42\n" },
|
||||
confidence: "observed",
|
||||
},
|
||||
);
|
||||
const failure =
|
||||
kind === "cancelled"
|
||||
? new AnalysisCancelledError("decode_signal_recording", {
|
||||
partialObservation: evidence,
|
||||
})
|
||||
: new ProviderCleanupError(
|
||||
"sigrok-recording",
|
||||
["private-workspace"],
|
||||
{},
|
||||
{
|
||||
operation: "decode_signal_recording",
|
||||
partialObservation: evidence,
|
||||
},
|
||||
);
|
||||
const signalRecording = new SignalRecordingService({
|
||||
decode: async () => err(failure),
|
||||
close: async () => {},
|
||||
});
|
||||
const harness = await createApplicationMcpHarness({
|
||||
serverOptions: { signalRecording },
|
||||
});
|
||||
onTestFinished(harness.close);
|
||||
const response = await harness.client.callTool({
|
||||
name: "decode_signal_recording",
|
||||
arguments: input,
|
||||
});
|
||||
expect(response.isError).toBe(true);
|
||||
expect(parseMcpToolError(response)).toMatchObject({
|
||||
error: {
|
||||
details: {
|
||||
partial_observation: {
|
||||
kind: "retained-evidence",
|
||||
evidence_id: evidence.evidence_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const bundle = await harness.client.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: {},
|
||||
});
|
||||
expect(bundle.isError).not.toBe(true);
|
||||
expect(JSON.stringify(bundle.structuredContent)).toContain(
|
||||
evidence.evidence_id,
|
||||
);
|
||||
expect(harness.session.evidenceById(evidence.evidence_id)).toEqual(
|
||||
evidence,
|
||||
);
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user