Files
rea/src/domain/browserScenarioDiffEvidence.ts
T
morlutoandDevin e91c8c39c2 refactor(test): colocate pure-domain tests and reduce test debt (#471)
* refactor(test): colocate pure-domain tests and reduce test debt

Move focused immutable domain/contracts/adapter tests from
tests/composition/** beside their production owners under src/** as
colocated *.test.ts/*.fixture.ts, and relocate persistence-shaped
composition tests under tests/boundary/filesystem/**. Update import
paths, the Vitest project topology (shared worker context for pure
domain/contracts and recording-port service projects), the test
migration ledger, testing docs, and AGENTS.md to match.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* docs: remove test migration ledger

The cutover is complete and the ledger is no longer referenced anywhere
in source, scripts, or the docs gate. Drop the standalone artifact.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* docs: clean up stale migration artifacts

Remove empty directories left by the test migration and replace the
"final cutover" language in docs/testing.md with standing PR guidance
that no longer references the completed migration.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: repair CI failures from schema, knip, and stale generated artifacts

Three root causes fixed:

1. catalog-schemas.mjs: valuesAt only traversed anyOf from Zod's
   toJSONSchema, not oneOf. The webScreenshotDiffSchema change to a
   discriminated union produces oneOf, so the product catalog generator
   could not derive the web_screenshot_diff schema version. Add oneOf
   traversal.

2. conformancePackage.ts: the test rewrite removed the only imports of
   ScenarioManifest, ReplayPlan, ShimPlan, and ExpectedEvidence, making
   them unused exports that knip flags. Remove the dead type aliases.

3. Regenerate stale artifacts (product catalog, MCP tool catalog, skill
   metadata, conformance manifest) that drifted from the source changes.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-08-10 14:57:44 +08:00

124 lines
3.5 KiB
TypeScript

import type {
BrowserScenarioCapture,
BrowserScenarioCompleteness,
BrowserScenarioCompletenessSection,
BrowserScenarioStep,
BrowserStepArtifacts,
} from "./browserScenarioCapture.js";
import type {
BrowserScenarioArtifactKind,
BrowserScenarioEvidenceState,
} from "./browserScenarioDiffValues.js";
/** Capture-state input consumed by browser scenario artifact comparison. */
export type CaptureState<Value> =
| { readonly state: "captured"; readonly value: Value }
| { readonly state: "not_requested" }
| { readonly state: "missing"; readonly reason: string }
| {
readonly state: "truncated";
readonly observed: number;
readonly retained: number;
readonly reason: string;
};
const includesCompletenessSection = (
completeness: BrowserScenarioCompleteness,
collection: "missing_sections" | "truncated_sections",
section: BrowserScenarioCompletenessSection,
): boolean => {
const sections: readonly BrowserScenarioCompletenessSection[] =
completeness[collection];
return sections.includes(section);
};
/** Project one captured artifact through its step-level completeness ledger. */
export const artifactEvidenceState = <Value>(
artifact: BrowserScenarioArtifactKind,
state: CaptureState<Value>,
step: BrowserScenarioStep,
): BrowserScenarioEvidenceState => {
if (state.state !== "captured") return state.state;
const section = artifact === "action_state" ? "action" : artifact;
if (
includesCompletenessSection(
step.completeness,
"truncated_sections",
section,
)
)
return "truncated";
return includesCompletenessSection(
step.completeness,
"missing_sections",
section,
)
? "missing"
: "captured";
};
const EVENT_SECTIONS = [
"events",
"frames",
"workers",
"popups",
"websockets",
] as const;
/** Project event evidence through capture- and step-level completeness. */
export const eventEvidenceState = (
capture: BrowserScenarioCapture,
step: BrowserScenarioStep,
): BrowserScenarioEvidenceState => {
const listed = (collection: "missing_sections" | "truncated_sections") =>
EVENT_SECTIONS.some(
(section) =>
includesCompletenessSection(
capture.completeness,
collection,
section,
) ||
includesCompletenessSection(step.completeness, collection, section),
);
if (capture.events.dropped > 0 || listed("truncated_sections"))
return "truncated";
return listed("missing_sections") ? "missing" : "captured";
};
/** Select stable action fields for normalized comparison. */
export const actionState = (step: BrowserScenarioStep) => ({
action: step.action,
status: step.status,
before_url: step.before_url,
after_url: step.after_url,
error: step.error,
});
/** Select events attributed to one scenario step without sequence metadata. */
export const eventsFor = (
capture: BrowserScenarioCapture,
stepIndex: number,
): readonly unknown[] =>
capture.events.items.flatMap(
({ sequence: _sequence, step_index: eventStepIndex, ...event }) =>
eventStepIndex === stepIndex ? [event] : [],
);
/** Wrap one value as captured comparison evidence. */
export const captured = <Value>(value: Value): CaptureState<Value> => ({
state: "captured",
value,
});
/** Retain stable screenshot identity without embedding image bytes. */
export const screenshotProjection = (
screenshot: Extract<
BrowserStepArtifacts["screenshot"],
{ state: "captured" }
>["value"],
) => ({
sha256: screenshot.sha256,
bytes: screenshot.bytes,
media_type: screenshot.media_type,
});