refactor(contracts): simplify workflows and drop readiness tool
This commit is contained in:
@@ -93,7 +93,11 @@ const browserParameters = (
|
||||
input: BrowserEvidenceInput,
|
||||
): EvidenceObservation["parameters"] => {
|
||||
if (!("cdp_endpoint" in input)) {
|
||||
if ("before_scenario" in input)
|
||||
if (
|
||||
"before_scenario" in input &&
|
||||
input.before_scenario !== undefined &&
|
||||
input.after_scenario !== undefined
|
||||
)
|
||||
return {
|
||||
comparison_kind: "browser_scenario",
|
||||
before_browser: input.before_scenario.browser,
|
||||
@@ -102,10 +106,14 @@ const browserParameters = (
|
||||
after_start_origin: input.after_scenario.scenario.start_origin,
|
||||
max_changes: input.max_changes,
|
||||
normalization_sha256: commitBrowserScenarioNormalization(
|
||||
input.normalization,
|
||||
input.normalization ?? { rules: [] },
|
||||
).sha256,
|
||||
};
|
||||
if ("max_changes" in input)
|
||||
if (
|
||||
"max_changes" in input &&
|
||||
input.before !== undefined &&
|
||||
input.after !== undefined
|
||||
)
|
||||
return {
|
||||
before_target_id: input.before.inspection.target.target_id,
|
||||
before_capture_ended_at:
|
||||
@@ -114,12 +122,14 @@ const browserParameters = (
|
||||
after_capture_ended_at: input.after.inspection.capture_window.ended_at,
|
||||
max_changes: input.max_changes,
|
||||
};
|
||||
return {
|
||||
before_artifact_uri: input.before.uri,
|
||||
after_artifact_uri: input.after.uri,
|
||||
channel_threshold: input.channel_threshold,
|
||||
maximum_pixels: input.maximum_pixels,
|
||||
};
|
||||
if (isScreenshotComparison(input))
|
||||
return {
|
||||
before_artifact_uri: input.before.uri,
|
||||
after_artifact_uri: input.after.uri,
|
||||
channel_threshold: input.channel_threshold,
|
||||
maximum_pixels: input.maximum_pixels,
|
||||
};
|
||||
throw new Error("Browser comparison input did not match a comparison type");
|
||||
}
|
||||
const scope = {
|
||||
cdp_endpoint: input.cdp_endpoint,
|
||||
@@ -172,6 +182,10 @@ const browserParameters = (
|
||||
};
|
||||
};
|
||||
|
||||
const isScreenshotComparison = (
|
||||
input: BrowserEvidenceInput,
|
||||
): input is CompareWebScreenshotsInput => "channel_threshold" in input;
|
||||
|
||||
const browserPredicate = (operation: BrowserEvidenceOperation): string => {
|
||||
switch (operation) {
|
||||
case "list_browser_targets":
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
AnalysisInputError,
|
||||
AnalysisProtocolError,
|
||||
type AnalysisError,
|
||||
} from "../domain/errors.js";
|
||||
import { createEvidence, type Evidence } from "../domain/evidence.js";
|
||||
import { jsonObjectSchema, jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { createReconstructionReadinessReport } from "../domain/reconstructionReadiness.js";
|
||||
import {
|
||||
reconstructionReadinessInputSchema,
|
||||
type ReconstructionReadinessInput,
|
||||
} from "../domain/reconstructionReadinessSchemas.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER } from "./InvestigationProviders.js";
|
||||
|
||||
const OPERATION = "evaluate_reconstruction_readiness" as const;
|
||||
|
||||
/** Parse one portable readiness request for both CLI and MCP adapters. */
|
||||
export const resolveReconstructionReadinessRequest = (
|
||||
input: unknown,
|
||||
): Result<ReconstructionReadinessInput, AnalysisError> => {
|
||||
const parsed = reconstructionReadinessInputSchema.safeParse(input);
|
||||
return parsed.success
|
||||
? ok(parsed.data)
|
||||
: err(new AnalysisInputError(OPERATION, { cause: parsed.error }));
|
||||
};
|
||||
|
||||
/** Evaluate and wrap one deterministic readiness report in Evidence. */
|
||||
export const evaluateReconstructionReadinessValidated = (
|
||||
input: ReconstructionReadinessInput,
|
||||
): Result<Evidence, AnalysisError> => {
|
||||
try {
|
||||
const report = createReconstructionReadinessReport(input);
|
||||
return ok(
|
||||
createEvidence(undefined, JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER, {
|
||||
predicateType: "rea.reconstruction-readiness-report/v1",
|
||||
operation: OPERATION,
|
||||
parameters: jsonObjectSchema.parse({
|
||||
source_digest: report.source_digest,
|
||||
expected_source_digest: input.replay.expected_source_digest,
|
||||
}),
|
||||
result: jsonValueSchema.parse(report),
|
||||
rawResult: null,
|
||||
confidence: "inferred",
|
||||
authority: "analyst-inference",
|
||||
environment: null,
|
||||
limitations:
|
||||
report.status === "pass"
|
||||
? []
|
||||
: [
|
||||
"Aggregate pass is withheld until every required conformance stage passes.",
|
||||
],
|
||||
evidenceLinks: report.evidence_links,
|
||||
}),
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
if (cause instanceof z.ZodError)
|
||||
return err(new AnalysisInputError(OPERATION, { cause }));
|
||||
return err(
|
||||
new AnalysisProtocolError("Reconstruction readiness evaluation failed", {
|
||||
cause,
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user