* 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>
155 lines
4.5 KiB
TypeScript
155 lines
4.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
reconcileCapturedWebScript,
|
|
reconcileWebScript,
|
|
stableWebResources,
|
|
stableWebScriptKey,
|
|
} from "./webInventory.js";
|
|
import {
|
|
createWebTextArtifact,
|
|
webTextArtifactSchema,
|
|
} from "./webContentArtifact.js";
|
|
|
|
describe("web content artifacts", () => {
|
|
it("binds UTF-8 content, size, digest, and URI", () => {
|
|
const artifact = createWebTextArtifact(
|
|
"const marker = '😀';",
|
|
"text/javascript",
|
|
);
|
|
expect(webTextArtifactSchema.parse(artifact)).toEqual(artifact);
|
|
expect(artifact.bytes).toBe(Buffer.byteLength(artifact.text));
|
|
expect(artifact.uri).toBe(`rea://web-content/sha256/${artifact.sha256}`);
|
|
});
|
|
|
|
it("rejects altered content that reuses an artifact digest", () => {
|
|
const artifact = createWebTextArtifact("original", "text/javascript");
|
|
expect(
|
|
webTextArtifactSchema.safeParse({ ...artifact, text: "altered!" })
|
|
.success,
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("stable web inventory", () => {
|
|
const script = {
|
|
url: "https://app.example.test/assets/app.js",
|
|
cdp_hash: "stable-cdp-hash",
|
|
length: 1_024,
|
|
is_module: true,
|
|
language: "JavaScript",
|
|
source_map_url: "https://app.example.test/assets/app.js.map",
|
|
};
|
|
|
|
it("excludes transient CDP and target identity from script keys", () => {
|
|
expect(stableWebScriptKey(script)).toBe(stableWebScriptKey({ ...script }));
|
|
expect(stableWebScriptKey({ ...script, length: 1_025 })).not.toBe(
|
|
stableWebScriptKey(script),
|
|
);
|
|
});
|
|
|
|
it("sorts resources deterministically and reconciles only exact URLs", () => {
|
|
const inputs = [
|
|
{
|
|
url: "https://app.example.test/assets/vendor.js",
|
|
origin: "https://app.example.test",
|
|
type: "Script",
|
|
mime_type: "text/javascript",
|
|
content_size: 200,
|
|
},
|
|
{
|
|
url: script.url,
|
|
origin: "https://app.example.test",
|
|
type: "Script",
|
|
mime_type: "text/javascript",
|
|
content_size: 1_024,
|
|
},
|
|
];
|
|
const forward = stableWebResources(inputs);
|
|
const reverse = stableWebResources([...inputs].reverse());
|
|
|
|
expect(reverse).toEqual(forward);
|
|
expect(reconcileWebScript(script, forward)).toEqual({
|
|
status: "exact",
|
|
resource_key: forward.find(({ url }) => url === script.url)?.resource_key,
|
|
});
|
|
expect(
|
|
reconcileWebScript({ ...script, url: `${script.url}?v=2` }, forward),
|
|
).toEqual({ status: "unmatched", reason: "no_exact_sanitized_url" });
|
|
});
|
|
|
|
it("reports duplicate resource observations as ambiguous", () => {
|
|
const duplicate = {
|
|
url: script.url,
|
|
origin: "https://app.example.test",
|
|
type: "Script",
|
|
mime_type: "text/javascript",
|
|
content_size: 1_024,
|
|
};
|
|
const resources = stableWebResources([
|
|
duplicate,
|
|
{ ...duplicate, content_size: 2_048 },
|
|
]);
|
|
|
|
expect(reconcileWebScript(script, resources)).toEqual({
|
|
status: "ambiguous",
|
|
candidate_resource_keys: resources
|
|
.map(({ resource_key }) => resource_key)
|
|
.sort(),
|
|
});
|
|
});
|
|
|
|
it("deduplicates identical resource observations by stable identity", () => {
|
|
const duplicate = {
|
|
url: script.url,
|
|
origin: "https://app.example.test",
|
|
type: "Script",
|
|
mime_type: "text/javascript",
|
|
content_size: 1_024,
|
|
};
|
|
|
|
expect(stableWebResources([duplicate, duplicate])).toEqual(
|
|
stableWebResources([duplicate]),
|
|
);
|
|
});
|
|
|
|
it("reconciles raw URLs independently of stable inventory sort order", () => {
|
|
const app = {
|
|
url: script.url,
|
|
origin: "https://app.example.test",
|
|
type: "Script",
|
|
mime_type: "text/javascript",
|
|
content_size: 1_024,
|
|
rawUrl: `${script.url}?token=secret`,
|
|
};
|
|
const vendor = {
|
|
url: "https://app.example.test/assets/vendor.js",
|
|
origin: "https://app.example.test",
|
|
type: "Script",
|
|
mime_type: "text/javascript",
|
|
content_size: 2_048,
|
|
rawUrl: "https://app.example.test/assets/vendor.js?v=1",
|
|
};
|
|
|
|
for (const rawResources of [
|
|
[app, vendor],
|
|
[vendor, app],
|
|
]) {
|
|
const resources = stableWebResources(
|
|
rawResources.map(({ rawUrl: _rawUrl, ...resource }) => resource),
|
|
);
|
|
expect(
|
|
reconcileCapturedWebScript(
|
|
{ ...script, rawUrl: app.rawUrl },
|
|
rawResources,
|
|
resources,
|
|
),
|
|
).toEqual({
|
|
status: "exact",
|
|
resource_key: resources.find(({ url }) => url === script.url)
|
|
?.resource_key,
|
|
});
|
|
}
|
|
});
|
|
});
|