mirror of
https://github.com/morluto/rea.git
synced 2026-10-27 01:45:32 +00:00
Validate completed reports before cancellation projection, retain valid Evidence and captured command diagnostics, and convert raw cleanup partials at their application owner. Record partial Evidence consistently across MCP handlers. Keep page inspection separate from unfinished bundle analysis. Refs #4261
79 lines
2.7 KiB
TypeScript
79 lines
2.7 KiB
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
|
|
import { BrowserObservationError } from "../domain/browserObservationError.js";
|
|
import { parseEvidence } from "../domain/evidence.js";
|
|
import { browserScenarioInputSchema } from "../domain/browserScenario.js";
|
|
import { err } from "../domain/result.js";
|
|
import { scriptScenarioFixture } from "../../tests/fixtures/webScriptCapture.js";
|
|
import type { BrowserScenarioCapturePort } from "./BrowserScenarioCapturePort.js";
|
|
import { captureBrowserScenario } from "./BrowserScenarioCaptureService.js";
|
|
|
|
const scenario = browserScenarioInputSchema.parse({
|
|
browser: { mode: "launch", executable_path: "/fixture/chrome" },
|
|
start_url: { url: "https://fixture.test/", query: [] },
|
|
actions: [{ step_id: "settle", action: "wait_for_timeout", duration_ms: 1 }],
|
|
});
|
|
const capture = scriptScenarioFixture();
|
|
|
|
it("converts a retained raw scenario capture into partial Evidence", async () => {
|
|
const failure = new AnalysisCancelledError("capture_browser_scenario", {
|
|
partialObservation: {
|
|
kind: "browser-scenario-observation",
|
|
capture,
|
|
},
|
|
});
|
|
const provider: BrowserScenarioCapturePort = {
|
|
identity: () => ({
|
|
id: "scenario-fixture",
|
|
name: "Scenario fixture",
|
|
version: "1",
|
|
}),
|
|
captureScenario: async () => err(failure),
|
|
};
|
|
const result = await captureBrowserScenario(provider, scenario);
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) {
|
|
expect(result.error).toBe(failure);
|
|
expect(parseEvidence(result.error.partialObservation)).toMatchObject({
|
|
operation: "capture_browser_scenario",
|
|
normalized_result: capture,
|
|
});
|
|
}
|
|
});
|
|
|
|
it("converts a raw scenario capture retained after cleanup failure", async () => {
|
|
const failure = new BrowserObservationError(
|
|
"capture_browser_scenario",
|
|
"cleanup_failed",
|
|
{
|
|
cleanup: {
|
|
reason: "browser close failed",
|
|
resources: ["browser process"],
|
|
},
|
|
partialObservation: {
|
|
kind: "browser-scenario-observation",
|
|
capture,
|
|
},
|
|
},
|
|
);
|
|
const provider: BrowserScenarioCapturePort = {
|
|
identity: () => ({
|
|
id: "scenario-fixture",
|
|
name: "Scenario fixture",
|
|
version: "1",
|
|
}),
|
|
captureScenario: async () => err(failure),
|
|
};
|
|
const result = await captureBrowserScenario(provider, scenario);
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) {
|
|
expect(result.error).toBe(failure);
|
|
expect(result.error.cleanupIncomplete).toBe(true);
|
|
expect(parseEvidence(result.error.partialObservation)).toMatchObject({
|
|
operation: "capture_browser_scenario",
|
|
normalized_result: capture,
|
|
});
|
|
}
|
|
});
|