mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
* refactor(verify): run Hopper and Kuna verifier commands through the supervised owner Replace bare execFile in the Hopper and Kuna real-provider verifiers with createVerifierCommands, and run pre-workspace toolchain probes through runOwnedCommand. Close the owner before lineage verification and keep the diagnostic workspace when cleanup, lineage, or the run fails. Replace isError-only and FAT64 prose refusals with the projected error code and structured issue or target details. * fix(verify): release a clean Kuna workspace after a verification failure A failed check whose provider, command, and lineage cleanup all completed still removes the root. The workspace stays only when that cleanup is unconfirmed, which is the contract the Kuna verifier failure-path tests already require. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(verify): keep the Kuna report when workspace release fails release() closes cleanup registration before it removes the root, so retain() after a failed release throws and skips the JSON report. Register retention only when release has not started; a failed release already keeps the workspace. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(verify): keep both Hopper verification and lineage failures When verification has already failed and lineage observation then fails, the retained-workspace error carried only the earlier cause. Aggregate both failures in the Hopper, FAT, and caller verifiers so the cleanup reason stays with the workspace. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(verify): keep Hopper manifests inside the repository realpath() accepted REA_HOPPER_CONFORMANCE_MANIFEST_PATH as any filesystem path. Resolve the manifest against the repository and reject a lexical or symlink escape before it is read. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(verify): acquire command owners before verifier workspaces * fix(verify): create the command owner before the verifier workspace If command-owner setup fails after a workspace is allocated, the temporary root is never released. Create the owner first and close it when workspace allocation fails. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(verify): supervise Hopper helper CLI processes * fix(verify): run Hopper helper CLIs through the command owner Boundary and Linux owner-exit checks still launched the REA CLI with execFile, so a timeout could not stop those processes. Both helpers now require the verifier command owner and run those CLIs through it. Co-authored-by: morluto <morluto@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
241 lines
6.8 KiB
JavaScript
241 lines
6.8 KiB
JavaScript
import { execFile } from "node:child_process";
|
|
import { mkdir, readFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { promisify } from "node:util";
|
|
import assert from "node:assert/strict";
|
|
import { createHash } from "node:crypto";
|
|
import {
|
|
artifactCli,
|
|
artifactMcpResult,
|
|
artifactMcpCall,
|
|
withArtifactMcp,
|
|
} from "../../lib/artifact-e2e.mjs";
|
|
import { requireMcpToolError } from "../../lib/mcp-verifier-results.mjs";
|
|
import {
|
|
assertKeyedArchiveIntegerResult,
|
|
verifyKeyedArchiveIntegerArchives,
|
|
} from "./keyed-archive-integers.mjs";
|
|
import {
|
|
VerifierFixture,
|
|
withVerifierFixture,
|
|
} from "../../lib/verifier-fixture.mjs";
|
|
|
|
if (process.platform !== "darwin")
|
|
throw new Error(
|
|
"Real Foundation keyed archive verification requires macOS and Xcode Swift tools",
|
|
);
|
|
const fixture = await VerifierFixture.open({ prefix: "rea-keyed-fixture-" });
|
|
const root = fixture.path;
|
|
let report;
|
|
await withVerifierFixture(fixture, async () => {
|
|
const archive = join(root, "model.plist");
|
|
await promisify(execFile)("/usr/bin/xcrun", [
|
|
"swift",
|
|
"-module-cache-path",
|
|
join(root, "modules"),
|
|
fileURLToPath(
|
|
new URL(
|
|
"../../../tests/conformance/native/keyed-archive.swift",
|
|
import.meta.url,
|
|
),
|
|
),
|
|
archive,
|
|
]);
|
|
const graph = await artifactCli("inspect-keyed-archive", archive);
|
|
const digest = createHash("sha256")
|
|
.update(await readFile(archive))
|
|
.digest("hex");
|
|
assert.equal(graph.archive_sha256, digest);
|
|
assert.equal(graph.target_sha256, digest);
|
|
await withArtifactMcp(archive, async (client) => {
|
|
assert.deepEqual(
|
|
await artifactMcpResult(client, "inspect_keyed_archive"),
|
|
graph,
|
|
);
|
|
const page = await artifactMcpResult(client, "inspect_keyed_archive", {
|
|
offset: 1,
|
|
limit: 1,
|
|
});
|
|
assert.deepEqual(page.objects, [graph.objects[1]]);
|
|
assert.equal(page.next_offset, 2);
|
|
const invalid = await artifactMcpCall(client, {
|
|
name: "inspect_keyed_archive",
|
|
arguments: { path: "../other.plist" },
|
|
});
|
|
// Standalone archives reject a path other than the admitted basename.
|
|
// KeyedArchiveReader throws AnalysisInputError; classification is invalid_request.
|
|
assert.partialDeepStrictEqual(requireMcpToolError(invalid), {
|
|
code: "invalid_request",
|
|
details: {
|
|
operation: "inspect_keyed_archive",
|
|
issues: [{ path: ["path"], reason: "invalid_value" }],
|
|
},
|
|
});
|
|
});
|
|
const xml = join(root, "model.xml.plist");
|
|
await promisify(execFile)("/usr/bin/plutil", [
|
|
"-convert",
|
|
"xml1",
|
|
"-o",
|
|
xml,
|
|
archive,
|
|
]);
|
|
const xmlGraph = await artifactCli("inspect-keyed-archive", xml);
|
|
const expected = JSON.parse(
|
|
await readFile(
|
|
new URL(
|
|
"../../../tests/fixtures/golden/keyed-archive/graph.json",
|
|
import.meta.url,
|
|
),
|
|
"utf8",
|
|
),
|
|
);
|
|
assert.deepEqual(
|
|
Object.fromEntries(
|
|
Object.entries(xmlGraph).filter(
|
|
([key]) =>
|
|
!["archive_path", "archive_sha256", "target_sha256"].includes(key),
|
|
),
|
|
),
|
|
expected,
|
|
);
|
|
assert.deepEqual(
|
|
graph.references.map(({ source, path, target, status }) => ({
|
|
source,
|
|
path,
|
|
target,
|
|
status,
|
|
})),
|
|
xmlGraph.references.map(({ source, path, target, status }) => ({
|
|
source,
|
|
path,
|
|
target,
|
|
status,
|
|
})),
|
|
);
|
|
if (
|
|
graph?.archive_format !== "binary-plist" ||
|
|
!graph.references.some(
|
|
(link) =>
|
|
link.source !== null &&
|
|
link.source === link.target &&
|
|
link.status === "resolved",
|
|
) ||
|
|
!graph.objects.some((item) => item.class_name?.includes("ReaArchiveRecord"))
|
|
)
|
|
throw new Error(
|
|
`Real Foundation archive graph drifted: ${JSON.stringify(graph)}`,
|
|
);
|
|
const record = graph.objects.find((item) =>
|
|
item.class_name?.includes("ReaArchiveRecord"),
|
|
);
|
|
if (
|
|
graph.references.filter(
|
|
(link) => link.target === record.id && link.source !== record.id,
|
|
).length < 2
|
|
)
|
|
throw new Error("Real shared object identity was not preserved");
|
|
const uidRoot = join(root, "uid-root.plist");
|
|
await promisify(execFile)("/usr/bin/xcrun", [
|
|
"swift",
|
|
"-module-cache-path",
|
|
join(root, "modules"),
|
|
fileURLToPath(
|
|
new URL(
|
|
"../../../tests/conformance/native/keyed-archive-uid-root.swift",
|
|
import.meta.url,
|
|
),
|
|
),
|
|
uidRoot,
|
|
]);
|
|
const uidRootXml = join(root, "uid-root.xml.plist");
|
|
await promisify(execFile)("/usr/bin/plutil", [
|
|
"-convert",
|
|
"xml1",
|
|
"-o",
|
|
uidRootXml,
|
|
uidRoot,
|
|
]);
|
|
for (const path of [uidRoot, uidRootXml]) {
|
|
const uidGraph = await artifactCli("inspect-keyed-archive", path);
|
|
assert.deepEqual(
|
|
uidGraph.references.map(({ source, path, target, status }) => ({
|
|
source,
|
|
path,
|
|
target,
|
|
status,
|
|
})),
|
|
[
|
|
{ source: null, path: ["CF$UID"], target: 1, status: "resolved" },
|
|
{ source: null, path: ["UID"], target: 1, status: "resolved" },
|
|
],
|
|
);
|
|
const selected = await artifactCli("inspect-keyed-archive", path, [
|
|
"--root",
|
|
"UID",
|
|
]);
|
|
assert.deepEqual(
|
|
selected.references,
|
|
uidGraph.references.filter(({ path }) => path[0] === "UID"),
|
|
);
|
|
await withArtifactMcp(path, async (client) => {
|
|
assert.deepEqual(
|
|
await artifactMcpResult(client, "inspect_keyed_archive", {
|
|
root: "UID",
|
|
}),
|
|
selected,
|
|
);
|
|
});
|
|
}
|
|
const integers = join(root, "integers");
|
|
await mkdir(integers);
|
|
await promisify(execFile)("/usr/bin/xcrun", [
|
|
"swift",
|
|
"-module-cache-path",
|
|
join(root, "modules"),
|
|
fileURLToPath(
|
|
new URL(
|
|
"../../../tests/conformance/native/keyed-archive-integers.swift",
|
|
import.meta.url,
|
|
),
|
|
),
|
|
integers,
|
|
]);
|
|
for (const fixture of await verifyKeyedArchiveIntegerArchives(integers)) {
|
|
const cliResult = assertKeyedArchiveIntegerResult(
|
|
await artifactCli("inspect-keyed-archive", fixture.archivePath),
|
|
fixture.format,
|
|
fixture.digest,
|
|
fixture.archive,
|
|
);
|
|
await withArtifactMcp(fixture.archivePath, async (client) => {
|
|
const mcpResult = assertKeyedArchiveIntegerResult(
|
|
await artifactMcpResult(client, "inspect_keyed_archive"),
|
|
fixture.format,
|
|
fixture.digest,
|
|
fixture.archive,
|
|
);
|
|
assert.deepEqual(mcpResult, cliResult);
|
|
});
|
|
}
|
|
report = {
|
|
ok: true,
|
|
mocked: false,
|
|
cli: true,
|
|
stdio_mcp: true,
|
|
xml_golden: true,
|
|
uid_named_root: true,
|
|
numeric_formats: ["xml", "binary"],
|
|
numeric_cli: true,
|
|
numeric_stdio_mcp: true,
|
|
format: graph.archive_format,
|
|
objects: graph.total_objects,
|
|
references: graph.total_references,
|
|
shared_identity: true,
|
|
cyclic_identity: true,
|
|
target_classes_instantiated_by_reader: false,
|
|
};
|
|
});
|
|
process.stdout.write(`${JSON.stringify(report)}\n`);
|