mirror of
https://github.com/morluto/rea
synced 2026-10-27 14:42:18 -04:00
edccb430c4
* chore: restack environment fidelity onto main Keep probe comparison, paging, and tied-create behavior on main after #5600. Capture parsing keeps field-path errors and records whether a probe kept request and response bodies. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(environment): keep served collection order with the fidelity checks The tied-create collection order lives with the checks that match encoded parents. The write simulation reads field checks from that attribution, and taint uses the same segment match. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(environment): translate an object's keys only when it is keyed by learned ids Differ.object mapped every key through the probe's id map, so a field named like a learned id was compared with another field, and a real rename could pass as a mapped key. Keys now translate only for an object keyed by learned ids as learning reads one: a key both sides share needs every key evidently an id, and otherwise each entry is an entity or each key evidently an id. Any other object compares field by field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
95 lines
3.0 KiB
TypeScript
95 lines
3.0 KiB
TypeScript
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { describe, expect } from "vitest";
|
|
|
|
import { timedCaptureEvidence } from "../../fixtures/analysisView.js";
|
|
import { environmentStateServeFixture } from "../../fixtures/environmentServe.js";
|
|
import {
|
|
BOOK_NOT_FOUND,
|
|
BOOK_ROWS,
|
|
book,
|
|
} from "../../fixtures/environmentStateWrites.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
/** The books environment and a probe of the application re-seeded under other ids, written as Evidence files. */
|
|
const writeCompareFiles = async (root: string) => {
|
|
const fixture = environmentStateServeFixture(timedCaptureEvidence(BOOK_ROWS));
|
|
const first = book(101, "First Book", "2026-10-20T09:00:00Z");
|
|
const second = book(102, "Second Book", "2026-10-20T10:00:00Z");
|
|
const probe = timedCaptureEvidence([
|
|
["GET", "/api/books", [first, second]],
|
|
["DELETE", "/api/books/102", "", 204],
|
|
["GET", "/api/books/102", BOOK_NOT_FOUND, 404],
|
|
]);
|
|
const paths = {
|
|
manifest: join(root, "manifest.json"),
|
|
capture: join(root, "capture.json"),
|
|
probe: join(root, "probe.json"),
|
|
};
|
|
await writeFile(paths.manifest, JSON.stringify(fixture.manifest));
|
|
await writeFile(paths.capture, JSON.stringify(fixture.capture));
|
|
await writeFile(paths.probe, JSON.stringify(probe));
|
|
return paths;
|
|
};
|
|
|
|
describe("rea environment-compare", () => {
|
|
cliTest(
|
|
"compares the served environment with a probe of the re-seeded application and prints the report",
|
|
async ({ cli }) => {
|
|
const files = await writeCompareFiles(
|
|
await createTestTempDirectory("rea-environment-compare-cli-"),
|
|
);
|
|
const result = await cli.run({
|
|
arguments: [
|
|
"environment-compare",
|
|
files.manifest,
|
|
"--evidence",
|
|
files.capture,
|
|
"--probe",
|
|
files.probe,
|
|
"--json",
|
|
],
|
|
timeoutMs: 30_000,
|
|
});
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.json).toMatchObject({
|
|
status: "complete",
|
|
environment: { state: "served" },
|
|
summary: { probes: 1, steps: 3, equal: 3, agreement: 1 },
|
|
probes: [{ label: "probe.json", ids_mapped: 2 }],
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"refuses a probe that is not capture Evidence and names it",
|
|
async ({ cli }) => {
|
|
const files = await writeCompareFiles(
|
|
await createTestTempDirectory("rea-environment-compare-refusal-cli-"),
|
|
);
|
|
const result = await cli.run({
|
|
arguments: [
|
|
"environment-compare",
|
|
files.manifest,
|
|
"--evidence",
|
|
files.capture,
|
|
"--probe",
|
|
files.manifest,
|
|
"--json",
|
|
],
|
|
timeoutMs: 30_000,
|
|
});
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.json).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
operation: "environment-compare",
|
|
issues: [{ path: ["probe", 0] }],
|
|
},
|
|
});
|
|
},
|
|
);
|
|
});
|