mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 23:15:58 +00:00
Keep Mach-O UUID interpretation at reconciliation, environment values at the details owner, and inventory scope admission at the public operation. Remove the obsolete UUID scalar, duplicate DSH dispatch, two intermediate inventory exports, and unused body-cutoff predicate. Keep test resource scopes explicit and cover oversized bodies through the real comparison workflow. Correct stale DSH invalid-result assertions and model DMG cancellation with the command owner, retaining an opaque AbortError control and mount cleanup checks.
147 lines
4.7 KiB
TypeScript
147 lines
4.7 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
analysisViewCaptureEvidence,
|
|
environmentManifestCaptureFixture,
|
|
} from "../../../tests/fixtures/analysisView.js";
|
|
import {
|
|
environmentServeSource,
|
|
environmentStateServeFixture,
|
|
} from "../../../tests/fixtures/environmentServe.js";
|
|
import { compareEnvironment } from "./environmentCompare.js";
|
|
import { REPLAY_BODY_LIMIT_BYTES } from "./environmentSource.js";
|
|
|
|
const responseCapture = (
|
|
text: string,
|
|
base64?: string,
|
|
mimeType = "application/octet-stream",
|
|
status = 200,
|
|
): ReturnType<typeof analysisViewCaptureEvidence> => {
|
|
const capture = environmentManifestCaptureFixture([
|
|
{
|
|
startedDateTime: "2026-10-17T18:00:00.000Z",
|
|
request: { method: "GET", url: "http://app.example/api/blob" },
|
|
response: {
|
|
status,
|
|
content: {
|
|
mimeType,
|
|
text,
|
|
...(base64 === undefined ? {} : { encoding: "base64" }),
|
|
},
|
|
},
|
|
},
|
|
]);
|
|
if (base64 !== undefined) {
|
|
const bytes = Buffer.from(base64, "base64");
|
|
capture.records[0]!.binary_fields = [
|
|
{
|
|
pointer: "/response/content/text",
|
|
representation: "har-base64-content",
|
|
state: "retained",
|
|
content_base64: base64,
|
|
bytes: bytes.length,
|
|
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
},
|
|
];
|
|
}
|
|
return analysisViewCaptureEvidence(capture);
|
|
};
|
|
|
|
const compare = (
|
|
recorded: ReturnType<typeof analysisViewCaptureEvidence>,
|
|
probe: ReturnType<typeof analysisViewCaptureEvidence>,
|
|
) => {
|
|
const fixture = environmentStateServeFixture(recorded);
|
|
const report = compareEnvironment({
|
|
source: environmentServeSource(fixture),
|
|
captureValue: recorded,
|
|
probes: [{ label: "probe", value: probe }],
|
|
operation: "environment-compare",
|
|
});
|
|
if (!report.ok) throw report.error;
|
|
return report.value;
|
|
};
|
|
|
|
describe("environment comparison response representation", () => {
|
|
it("distinguishes binary byte ff from its base64 spelling as literal text", () => {
|
|
const binary = responseCapture("/w==", "/w==");
|
|
const literal = responseCapture("/w==");
|
|
const result = compare(binary, literal);
|
|
expect(result.probes[0]?.results[0]?.equal).toBe(false);
|
|
expect(result.probes[0]?.results[0]?.categories).toEqual(["value"]);
|
|
});
|
|
|
|
it("compares equal retained binary bytes and valid UTF-8 base64 as text", () => {
|
|
expect(
|
|
compare(responseCapture("/w==", "/w=="), responseCapture("/w==", "/w=="))
|
|
.probes[0]?.results[0]?.equal,
|
|
).toBe(true);
|
|
expect(
|
|
compare(responseCapture("aGVsbG8=", "aGVsbG8="), responseCapture("hello"))
|
|
.probes[0]?.results[0]?.equal,
|
|
).toBe(true);
|
|
});
|
|
|
|
it.each([
|
|
{ representation: "binary", status: 200 },
|
|
{ representation: "binary", status: 503 },
|
|
{ representation: "text", status: 200 },
|
|
{ representation: "text", status: 503 },
|
|
] as const)(
|
|
"compares a retained $representation body beyond the replay limit by status only ($status)",
|
|
({ representation, status }) => {
|
|
const recorded = responseCapture("different recorded body");
|
|
const text =
|
|
representation === "binary"
|
|
? Buffer.alloc(REPLAY_BODY_LIMIT_BYTES + 8, 0xff).toString("base64")
|
|
: "é".repeat(REPLAY_BODY_LIMIT_BYTES / 2 + 4);
|
|
const probe = responseCapture(
|
|
text,
|
|
representation === "binary" ? text : undefined,
|
|
representation === "binary" ? "application/octet-stream" : "text/plain",
|
|
status,
|
|
);
|
|
const result = compare(recorded, probe);
|
|
const equal = status === 200;
|
|
expect(result.probes).toMatchObject([
|
|
{
|
|
steps: 1,
|
|
equal: equal ? 1 : 0,
|
|
normalised: { large_bodies: 1, unobserved_bodies: 0 },
|
|
results: [
|
|
{
|
|
live_status: status,
|
|
env_status: 200,
|
|
equal,
|
|
categories: equal ? [] : ["status"],
|
|
differences: equal
|
|
? []
|
|
: [
|
|
{
|
|
category: "status",
|
|
pointer: "",
|
|
live: "503",
|
|
env: "200",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
expect(result.summary).toMatchObject({
|
|
steps: 1,
|
|
equal: equal ? 1 : 0,
|
|
categories: { status: equal ? 0 : 1, value: 0 },
|
|
normalised: { large_bodies: 1, unobserved_bodies: 0 },
|
|
});
|
|
},
|
|
);
|
|
|
|
it("does not conflate a JSON string value with identical plain text", () => {
|
|
const json = responseCapture('"hello"', undefined, "application/json");
|
|
const text = responseCapture("hello");
|
|
expect(compare(json, text).probes[0]?.results[0]?.equal).toBe(false);
|
|
});
|
|
});
|