chore: sync main for native IDA verification
The native IDA follow-up is being verified on Windows IDA Pro 9.3. IDA Free is not used in this follow-up.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect } from "vitest";
|
||||
import { build } from "plist";
|
||||
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { deeplyNestedXmlPlist } from "../../fixtures/keyedArchiveXmlNesting.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
for (const [name, xml] of [
|
||||
["dictionaries", deeplyNestedXmlPlist(3000)],
|
||||
[
|
||||
"quoted attributes",
|
||||
deeplyNestedXmlPlist(3000).replaceAll("<dict>", '<dict note="/>">'),
|
||||
],
|
||||
[
|
||||
"plist wrappers",
|
||||
"<plist>".repeat(3000) + "<string>x</string>" + "</plist>".repeat(3000),
|
||||
],
|
||||
] as const) {
|
||||
cliTest(
|
||||
`compiled CLI reports deeply nested XML ${name} as the decode limit`,
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-keyed-cli-depth-");
|
||||
const path = join(root, "Deep.plist");
|
||||
await writeFile(path, xml);
|
||||
const output = await cli.run({
|
||||
arguments: ["inspect-keyed-archive", path, "--json"],
|
||||
environment: { REA_LOG_LEVEL: "silent", REA_ANALYSIS_PROVIDER: "auto" },
|
||||
});
|
||||
expect(output.exitCode, output.stderr).toBe(1);
|
||||
expect(output.json).toMatchObject({
|
||||
code: "truncated",
|
||||
category: "truncated",
|
||||
details: {
|
||||
reason: "limit",
|
||||
truncated: true,
|
||||
detail:
|
||||
"Cannot decode selected Foundation keyed archive: Plist exceeds 128 nesting levels",
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
cliTest(
|
||||
"compiled CLI decodes a shallow archive with opaque DOCTYPE markup",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-keyed-cli-doctype-");
|
||||
const path = join(root, "Shallow.plist");
|
||||
const archive = build({
|
||||
$archiver: "NSKeyedArchiver",
|
||||
$version: 100000,
|
||||
$objects: ["$null", "leaf"],
|
||||
$top: { root: { UID: 1 } },
|
||||
});
|
||||
await writeFile(
|
||||
path,
|
||||
archive.replace(
|
||||
/<!DOCTYPE[^>]*>/u,
|
||||
`<!DOCTYPE plist [<!ENTITY first "unused"><!ENTITY second "${"<dict>".repeat(130)}">]>`,
|
||||
),
|
||||
);
|
||||
const output = await cli.run({
|
||||
arguments: ["inspect-keyed-archive", path, "--json"],
|
||||
environment: { REA_LOG_LEVEL: "silent", REA_ANALYSIS_PROVIDER: "auto" },
|
||||
});
|
||||
expect(output.exitCode, output.stderr).toBe(0);
|
||||
expect(parseEvidence(output.json).normalized_result).toMatchObject({
|
||||
archive_format: "xml-plist",
|
||||
objects: expect.arrayContaining([
|
||||
expect.objectContaining({ value: "leaf" }),
|
||||
]),
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,336 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
|
||||
// A recording port checks the experimental producer/consumer representation.
|
||||
// Real provider verification remains in the separate native experiment receipts.
|
||||
const generate = `
|
||||
import {measureNativeEntry} from './experiments/analysis-efficiency/native-entry.mjs';
|
||||
const sha='0'.repeat(64);
|
||||
const duplicate=process.argv[1]==='duplicate';
|
||||
const stale=process.argv[1]==='stale-dos';
|
||||
const collision=process.argv[1];
|
||||
const dos=process.argv[1]==='dos'||stale||collision==='load-collision';
|
||||
const dossier={procedure:{address:'0x1000'},pseudocode:'return;',callers:[],callees:[]};
|
||||
class ToolFailure extends Error {}
|
||||
const build=async digit=>{
|
||||
const parent='ev_'+digit.repeat(63)+'0';
|
||||
let ordinal=0;
|
||||
const call=async(name,args)=>{
|
||||
if(stale)process.stdout.write(name+'\\n');
|
||||
if(name==='open_binary'||name==='close_binary')return {};
|
||||
if(name==='inspect_native_load_image')return {evidence_id:'ev_'+digit.repeat(63)+'6',normalized_result:{status:'verified',target_sha256:stale?'f'.repeat(64):sha,entry:{linear_address:'0x1000'}}};
|
||||
if(name==='resolve_containing_procedure')return {evidence_id:'ev_'+digit.repeat(63)+'7',normalized_result:{found:true}};
|
||||
if(name==='analyze_function')return {evidence_id:parent,subject:{digest:{sha256:sha}},normalized_result:dossier};
|
||||
const id='ev_'+digit.repeat(63)+(collision==='containing-collision'?7:collision==='load-collision'?6:duplicate?1:++ordinal);
|
||||
if(args.view.kind==='summary')return {evidence_id:id};
|
||||
const facet=args.view.facet;
|
||||
const item=facet==='pseudocode'?{text:dossier.pseudocode,unit:'utf16-code-units'}:dossier[facet];
|
||||
return {evidence_id:id,normalized_result:{parent_evidence_id:parent,artifact:{sha256:sha},item,coverage:{exhausted:true},limitations:[],unknowns:[]}};
|
||||
};
|
||||
return measureNativeEntry({seed:dos?undefined:'0x1000',values:{path:'/selected/input','native-question':'entry-views'},call,inputSha:sha,ToolFailure});
|
||||
};
|
||||
process.stdout.write(JSON.stringify([await build('1'),await build('2')]));
|
||||
`;
|
||||
|
||||
it.each([
|
||||
"observed",
|
||||
"missing",
|
||||
"errored",
|
||||
"wrong-target",
|
||||
"wrong-entry",
|
||||
"unreferenced",
|
||||
])(
|
||||
"binds the DOS model grade to its observed load image: %s",
|
||||
async (scenario) => {
|
||||
// Synthetic transcripts exercise grading; they are not real-provider or
|
||||
// resource measurements. Real DOS transcripts are replayed separately.
|
||||
const root = await createTestTempDirectory("rea-dos-grader-");
|
||||
const trial = join(root, "trial");
|
||||
const referenceDirectory = join(root, "reference");
|
||||
await mkdir(trial);
|
||||
await mkdir(referenceDirectory);
|
||||
const sha = "0".repeat(64);
|
||||
const imageId = "ev_" + "1".repeat(64);
|
||||
const procedureId = "ev_" + "2".repeat(64);
|
||||
const procedure = {
|
||||
address: "0x1000",
|
||||
name: "entry",
|
||||
classification: "observed",
|
||||
signature: null,
|
||||
locals: [],
|
||||
body: { ranges: [], total_bytes: 0 },
|
||||
};
|
||||
const loadImage = {
|
||||
status: "verified",
|
||||
target_sha256: sha,
|
||||
entry: { linear_address: "0x1000" },
|
||||
};
|
||||
const reference = {
|
||||
artifact_sha256: sha,
|
||||
entry_address: "0x1000",
|
||||
caller_count: 0,
|
||||
callee_count: 0,
|
||||
pseudocode_prefix: "return;",
|
||||
containing_procedure: { procedure },
|
||||
procedure,
|
||||
load_image: loadImage,
|
||||
};
|
||||
const answer = {
|
||||
...reference,
|
||||
load_image_status: "verified",
|
||||
evidence_ids: [
|
||||
procedureId,
|
||||
...(["missing", "errored", "unreferenced"].includes(scenario)
|
||||
? []
|
||||
: [imageId]),
|
||||
],
|
||||
};
|
||||
const event = (tool: string, status: string, value: unknown) => ({
|
||||
type: "item.completed",
|
||||
item: {
|
||||
type: "mcp_tool_call",
|
||||
tool,
|
||||
status,
|
||||
arguments: {},
|
||||
result: { structured_content: value },
|
||||
},
|
||||
});
|
||||
const events = [
|
||||
event("analyze_function", "completed", { evidence_id: procedureId }),
|
||||
];
|
||||
if (scenario !== "missing")
|
||||
events.push(
|
||||
event(
|
||||
"inspect_native_load_image",
|
||||
scenario === "errored" ? "failed" : "completed",
|
||||
scenario === "errored"
|
||||
? { error: { code: "unsupported_target" } }
|
||||
: {
|
||||
operation: "inspect_native_load_image",
|
||||
evidence_id: imageId,
|
||||
normalized_result: {
|
||||
...loadImage,
|
||||
target_sha256:
|
||||
scenario === "wrong-target" ? "f".repeat(64) : sha,
|
||||
entry: {
|
||||
linear_address:
|
||||
scenario === "wrong-entry" ? "0x2000" : "0x1000",
|
||||
},
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
const resourceLog = join(root, "resource.log");
|
||||
const output = join(root, "review.json");
|
||||
for (const [path, value] of [
|
||||
[
|
||||
join(trial, "summary.json"),
|
||||
{
|
||||
completed_mcp_calls: [
|
||||
{ tool: "close_binary", status: "completed", arguments: {} },
|
||||
],
|
||||
},
|
||||
],
|
||||
[join(trial, "trial-settings.json"), {}],
|
||||
[join(trial, "cleanup.json"), { profile_removed: true }],
|
||||
[join(trial, "answer.txt"), answer],
|
||||
[join(referenceDirectory, "answer.json"), reference],
|
||||
[
|
||||
resourceLog,
|
||||
{
|
||||
resource_scope: "synthetic-grader-fixture",
|
||||
abort: null,
|
||||
resource_counters_verified: true,
|
||||
resource_events_final: {
|
||||
"memory.events": { high: 0, max: 0, oom: 0, oom_kill: 0 },
|
||||
"pids.events": { max: 0 },
|
||||
},
|
||||
},
|
||||
],
|
||||
] as const)
|
||||
await writeFile(path, JSON.stringify(value));
|
||||
await writeFile(
|
||||
join(trial, "events.jsonl"),
|
||||
events.map((value) => JSON.stringify(value)).join("\n"),
|
||||
);
|
||||
const command = execute("python3", [
|
||||
resolve("experiments/analysis-efficiency/review-model.py"),
|
||||
"--domain",
|
||||
"native",
|
||||
"--trial",
|
||||
trial,
|
||||
"--reference",
|
||||
referenceDirectory,
|
||||
"--resource-log",
|
||||
resourceLog,
|
||||
"--output",
|
||||
output,
|
||||
]);
|
||||
if (scenario === "observed") await command;
|
||||
else await expect(command).rejects.toMatchObject({ code: 1 });
|
||||
const report = JSON.parse(await readFile(output, "utf8"));
|
||||
expect(report.all_selected_checks_pass).toBe(scenario === "observed");
|
||||
if (["missing", "errored", "unreferenced"].includes(scenario))
|
||||
expect(report.checks.load_image_source_observed_and_referenced).toBe(
|
||||
false,
|
||||
);
|
||||
if (scenario === "wrong-target")
|
||||
expect(report.checks["load_image.target_sha256"]).toBe(false);
|
||||
if (scenario === "wrong-entry")
|
||||
expect(report.checks["load_image.source_entry"]).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it("retains the DOS load-image source for its facts and derived entry seed", async () => {
|
||||
const { stdout } = await execute(process.execPath, [
|
||||
"--input-type=module",
|
||||
"-e",
|
||||
generate,
|
||||
"dos",
|
||||
]);
|
||||
const [answer] = JSON.parse(stdout);
|
||||
expect(answer).toMatchObject({
|
||||
entry_address: "0x1000",
|
||||
load_image: { status: "verified", entry: { linear_address: "0x1000" } },
|
||||
evidence_ids: { native_load_image: "ev_" + "1".repeat(63) + "6" },
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a stale DOS load image before using its entry and closes the session", async () => {
|
||||
await expect(
|
||||
execute(process.execPath, [
|
||||
"--input-type=module",
|
||||
"-e",
|
||||
generate,
|
||||
"stale-dos",
|
||||
]),
|
||||
).rejects.toMatchObject({
|
||||
stdout: "open_binary\ninspect_native_load_image\nclose_binary\n",
|
||||
stderr: expect.stringContaining(
|
||||
"The DOS load image belongs to a different target",
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["containing-collision", "load-collision"])(
|
||||
"rejects a retained view that reuses an earlier producer identity: %s",
|
||||
async (collision) => {
|
||||
await expect(
|
||||
execute(process.execPath, [
|
||||
"--input-type=module",
|
||||
"-e",
|
||||
generate,
|
||||
collision,
|
||||
]),
|
||||
).rejects.toMatchObject({
|
||||
stderr: expect.stringContaining(
|
||||
"Retained native view reused an Evidence identity",
|
||||
),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects a producer that reuses a view identity across facets", async () => {
|
||||
await expect(
|
||||
execute(process.execPath, [
|
||||
"--input-type=module",
|
||||
"-e",
|
||||
generate,
|
||||
"duplicate",
|
||||
]),
|
||||
).rejects.toMatchObject({
|
||||
stderr: expect.stringContaining(
|
||||
"Retained native view reused an Evidence identity",
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["references", "item", "coverage", "limitations", "unknowns"])(
|
||||
"separates native references while comparing %s exactly",
|
||||
async (change) => {
|
||||
const { stdout: generated } = await execute(process.execPath, [
|
||||
"--input-type=module",
|
||||
"-e",
|
||||
generate,
|
||||
]);
|
||||
const [leftAnswer, rightAnswer] = JSON.parse(generated);
|
||||
if (change === "item")
|
||||
rightAnswer.retained_views[0].item.address = "0x1001";
|
||||
if (change === "coverage")
|
||||
rightAnswer.retained_views[0].coverage.exhausted = false;
|
||||
if (change === "limitations")
|
||||
rightAnswer.retained_views[0].limitations.push("partial");
|
||||
if (change === "unknowns")
|
||||
rightAnswer.retained_views[0].unknowns.push("unresolved");
|
||||
|
||||
const root = await createTestTempDirectory("rea-native-comparison-");
|
||||
const left = join(root, "left");
|
||||
const right = join(root, "right");
|
||||
const summary = {
|
||||
artifact: "sharex.exe",
|
||||
native_question: "entry-views",
|
||||
provider_search_path_sha256: "0".repeat(64),
|
||||
native_workflow_source_sha256: "1".repeat(64),
|
||||
calls: [],
|
||||
failure: null,
|
||||
};
|
||||
for (const [directory, answer] of [
|
||||
[left, leftAnswer],
|
||||
[right, rightAnswer],
|
||||
]) {
|
||||
await mkdir(directory);
|
||||
await writeFile(join(directory, "summary.json"), JSON.stringify(summary));
|
||||
await writeFile(join(directory, "answer.json"), JSON.stringify(answer));
|
||||
}
|
||||
const output = join(root, "comparison.json");
|
||||
const command = execute(process.execPath, [
|
||||
resolve("experiments/analysis-efficiency/compare.mjs"),
|
||||
"--left",
|
||||
left,
|
||||
"--right",
|
||||
right,
|
||||
"--output",
|
||||
output,
|
||||
]);
|
||||
if (change !== "references") {
|
||||
await expect(command).rejects.toMatchObject({
|
||||
code: 1,
|
||||
stdout: expect.stringContaining('"retained_views"'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
const { stdout } = await command;
|
||||
expect(JSON.parse(stdout)).toMatchObject({
|
||||
settings_match: true,
|
||||
facts_match: true,
|
||||
preserved_run_specific_values: [
|
||||
{
|
||||
side: "left",
|
||||
path: ["evidence_ids"],
|
||||
value: leftAnswer.evidence_ids,
|
||||
},
|
||||
{
|
||||
side: "right",
|
||||
path: ["evidence_ids"],
|
||||
value: rightAnswer.evidence_ids,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(leftAnswer.evidence_ids).not.toEqual(rightAnswer.evidence_ids);
|
||||
expect(leftAnswer.evidence_ids.retained_views[0]).toMatchObject({
|
||||
evidence_id: "ev_" + "1".repeat(64),
|
||||
parent_evidence_id: "ev_" + "1".repeat(63) + "0",
|
||||
});
|
||||
expect(leftAnswer.evidence_ids.native_summary).toBe(
|
||||
"ev_" + "1".repeat(63) + "5",
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -312,6 +312,14 @@ it.each([
|
||||
"tests/boundary/process/darwinProcessRunTokenReader.test.ts",
|
||||
{ code: true, apple: true, package: false, runtime: false },
|
||||
],
|
||||
[
|
||||
"tests/boundary/cli/nativePlistCli.test.ts",
|
||||
{ code: true, apple: true, package: false, runtime: false },
|
||||
],
|
||||
[
|
||||
"tests/boundary/filesystem/windowsNpxRegistration.test.ts",
|
||||
{ code: true, package: true, runtime: true, apple: false },
|
||||
],
|
||||
[
|
||||
"src/process/ProcessOwnership.test.ts",
|
||||
{ code: true, package: true, apple: false, evm: false, browser: false },
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
import { parse } from "yaml";
|
||||
import { z } from "zod";
|
||||
|
||||
import { parseTestDurations } from "../../ciTestSequencer.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const script = new URL("../../../scripts/ci/test-report.mjs", import.meta.url);
|
||||
const stepsSchema = z.array(
|
||||
z.object({
|
||||
name: z.string().optional(),
|
||||
run: z.string().optional(),
|
||||
uses: z.string().optional(),
|
||||
if: z.string().optional(),
|
||||
env: z.record(z.string(), z.string()).optional(),
|
||||
with: z.record(z.string(), z.unknown()).optional(),
|
||||
}),
|
||||
);
|
||||
const workflow = async () =>
|
||||
z
|
||||
.object({
|
||||
jobs: z.object({
|
||||
test: z.object({ steps: stepsSchema }),
|
||||
build: z.object({ steps: stepsSchema }),
|
||||
docs: z.object({ steps: stepsSchema }),
|
||||
static: z.object({ steps: stepsSchema }),
|
||||
}),
|
||||
})
|
||||
.parse(
|
||||
parse(
|
||||
await readFile(
|
||||
new URL("../../../.github/workflows/ci.yml", import.meta.url),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
).jobs;
|
||||
|
||||
it("collects failed-shard diagnostics before enforcing the shard result", async () => {
|
||||
const steps = (await workflow()).test!.steps;
|
||||
const merge = steps.findIndex((step) => step.run?.includes("test:ci:merge"));
|
||||
const upload = steps.findIndex((step) => step.with?.name === "test-results");
|
||||
const gate = steps.findIndex(
|
||||
(step) => step.env?.SHARD_RESULT && step.run?.includes("test "),
|
||||
);
|
||||
expect(merge).toBeGreaterThan(0);
|
||||
expect(upload).toBeGreaterThan(merge);
|
||||
expect(gate).toBeGreaterThan(upload);
|
||||
expect(steps[merge]?.if).not.toContain("needs.test-shard.result");
|
||||
const command = steps[gate]?.run;
|
||||
if (command === undefined) throw new Error("Missing shard result gate");
|
||||
for (const result of ["failure", "cancelled", "skipped", ""]) {
|
||||
await expect(
|
||||
execute("bash", ["-c", command], {
|
||||
env: { ...process.env, CODE_REQUIRED: "true", SHARD_RESULT: result },
|
||||
}),
|
||||
).rejects.toMatchObject({ code: 1 });
|
||||
}
|
||||
await expect(
|
||||
execute("bash", ["-c", command], {
|
||||
env: { ...process.env, CODE_REQUIRED: "false", SHARD_RESULT: "skipped" },
|
||||
}),
|
||||
).resolves.toMatchObject({ stderr: "" });
|
||||
});
|
||||
|
||||
it("keeps diagnosis available after merge failure and publishes only complete successful history", async () => {
|
||||
const steps = (await workflow()).test!.steps;
|
||||
const diagnosis = steps.find((step) => step.with?.name === "test-results");
|
||||
expect(diagnosis?.if).toContain("!cancelled()");
|
||||
expect(diagnosis?.if).not.toContain("success()");
|
||||
const history = steps.find((step) => step.with?.name === "test-timings");
|
||||
expect(history?.if).toContain("success()");
|
||||
expect(history?.if).toContain("needs.test-shard.result == 'success'");
|
||||
expect(history?.with?.path).toBe(".cache/ci-test-history/test-results.json");
|
||||
const download = (await workflow()).build!.steps.find(
|
||||
(step) => step.name === "Download previous timing report",
|
||||
);
|
||||
expect(download?.with?.name).toBe(history?.with?.name);
|
||||
});
|
||||
|
||||
it("runs the existing onboarding and Python producer guards from their selected CI owners", async () => {
|
||||
const jobs = await workflow();
|
||||
const scripts = z
|
||||
.object({ scripts: z.record(z.string(), z.string()) })
|
||||
.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
new URL("../../../package.json", import.meta.url),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
).scripts;
|
||||
expect(
|
||||
jobs.docs.steps.some((step) => step.run === "npm run docs:check"),
|
||||
).toBe(true);
|
||||
expect(scripts["docs:check"]).toContain(
|
||||
"tests/conformance/readmeConsistency.test.ts",
|
||||
);
|
||||
const producer = jobs.static.steps.find(
|
||||
(step) => step.run === "npm run test:python",
|
||||
);
|
||||
expect(producer?.if).toBe("needs.changes.outputs.code == 'true'");
|
||||
expect(scripts["test:python"]).toContain(
|
||||
"bridge/native/test_rea_lldb_tracer.py",
|
||||
);
|
||||
});
|
||||
|
||||
it("exports portable timing history and removes it on a failed, partial, or invalid rerun", async () => {
|
||||
const root = await createTestTempDirectory("rea-ci-report-");
|
||||
const summary = join(root, "summary.md");
|
||||
const history = join(root, ".cache/ci-test-history/test-results.json");
|
||||
const report = {
|
||||
success: true,
|
||||
numFailedTests: 0,
|
||||
testResults: [
|
||||
{
|
||||
name: join(root, "tests/slow.test.ts"),
|
||||
startTime: 10,
|
||||
endTime: 110,
|
||||
assertionResults: [{ large: "not timing data" }],
|
||||
},
|
||||
{ name: join(root, "tests/fast.test.ts"), startTime: 20, endTime: 30 },
|
||||
],
|
||||
};
|
||||
const run = async (value: unknown, shards = "success", merge = "success") => {
|
||||
await writeFile(join(root, "test-results.json"), JSON.stringify(value));
|
||||
await writeFile(summary, "");
|
||||
return execute(process.execPath, [fileURLToPath(script)], {
|
||||
cwd: root,
|
||||
env: {
|
||||
...process.env,
|
||||
GITHUB_STEP_SUMMARY: summary,
|
||||
SHARD_RESULT: shards,
|
||||
MERGE_RESULT: merge,
|
||||
},
|
||||
});
|
||||
};
|
||||
await run(report);
|
||||
const contents = await readFile(history, "utf8");
|
||||
expect(contents).not.toContain("assertionResults");
|
||||
expect(contents).not.toContain(root);
|
||||
expect(
|
||||
parseTestDurations(contents, resolve(root, "different-checkout")),
|
||||
).toEqual(
|
||||
new Map([
|
||||
["tests/slow.test.ts", 100],
|
||||
["tests/fast.test.ts", 10],
|
||||
]),
|
||||
);
|
||||
for (const [value, shards, merge] of [
|
||||
[{ ...report, success: false, numFailedTests: 1 }, "failure", "failure"],
|
||||
[report, "cancelled", "success"],
|
||||
[report, "success", "failure"],
|
||||
] as const) {
|
||||
await run(report);
|
||||
await run(value, shards, merge);
|
||||
await expect(readFile(history)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
expect(await readFile(summary, "utf8")).toContain("diagnostic only");
|
||||
}
|
||||
await run(report);
|
||||
await expect(
|
||||
run({
|
||||
...report,
|
||||
testResults: [{ name: "../outside.test.ts", startTime: 1, endTime: 3 }],
|
||||
}),
|
||||
).rejects.toMatchObject({ code: 1 });
|
||||
await expect(readFile(history)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
@@ -1661,8 +1661,9 @@ describe("uninstall configuration preflight", () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
['{"mcpServers": null}', '"mcpServers" must be an object'],
|
||||
['{"mcpServers":null,"keep":1}', '"mcpServers" must be an object'],
|
||||
["[]", "The configuration root must be an object"],
|
||||
['{"mcpServers":"x"}', '"mcpServers" must be an object'],
|
||||
])(
|
||||
"names the structural problem in valid JSON %s",
|
||||
async (content, problem) => {
|
||||
@@ -1679,12 +1680,14 @@ describe("uninstall configuration preflight", () => {
|
||||
},
|
||||
});
|
||||
const result = await runUninstall(false, systemUninstallHost(home));
|
||||
expect(result.status).toBe("failed");
|
||||
expect(result.items).toContainEqual({
|
||||
name: "cursor",
|
||||
status: "failed",
|
||||
detail: `Configuration was not changed: ${problem}. Repair it, then rerun uninstall.`,
|
||||
});
|
||||
expect(await readFile(config, "utf8")).toBe(content);
|
||||
await expect(readFile(`${config}.rea.backup`, "utf8")).rejects.toThrow();
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
|
||||
import { inspectGhidraInstallation } from "../../../src/ghidra/GhidraInstallation.js";
|
||||
import { SUPPORTED_GHIDRA_VERSION } from "../../../src/ghidra/GhidraInstallationPolicy.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const { mockSpawnSync } = vi.hoisted(() => ({ mockSpawnSync: vi.fn() }));
|
||||
|
||||
vi.mock("node:child_process", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("node:child_process")>()),
|
||||
spawnSync: mockSpawnSync,
|
||||
}));
|
||||
|
||||
afterEach(() => mockSpawnSync.mockReset());
|
||||
|
||||
it.each([
|
||||
{ major: 17, fullJdk: true },
|
||||
{ major: 21, fullJdk: true },
|
||||
{ major: 21, fullJdk: false },
|
||||
])(
|
||||
"preserves the reported Unicode Java home and classifies JDK $major (full JDK: $fullJdk)",
|
||||
async ({ major, fullJdk }) => {
|
||||
const root = await createTestTempDirectory("rea-java-probe-");
|
||||
const configuredHome = join(root, "selected-jdk");
|
||||
const reportedHome = join(root, "Réa逆向", `JDK ${String(major)}`);
|
||||
const installDir = join(root, "ghidra");
|
||||
await mkdir(join(installDir, "Ghidra"), { recursive: true });
|
||||
await writeFile(
|
||||
join(installDir, "Ghidra", "application.properties"),
|
||||
`application.version=${SUPPORTED_GHIDRA_VERSION}\napplication.java.min=17\n`,
|
||||
);
|
||||
if (fullJdk) {
|
||||
await mkdir(join(reportedHome, "bin"), { recursive: true });
|
||||
await writeFile(
|
||||
join(
|
||||
reportedHome,
|
||||
"bin",
|
||||
process.platform === "win32" ? "javac.exe" : "javac",
|
||||
),
|
||||
"compiler presence fixture",
|
||||
{ mode: 0o755 },
|
||||
);
|
||||
}
|
||||
const version = `${String(major)}.0.11`;
|
||||
mockSpawnSync.mockReturnValue({
|
||||
stdout: "",
|
||||
stderr: ` java.version = ${version}\n java.home = ${reportedHome}\n sun.arch.data.model = 64\n`,
|
||||
status: 0,
|
||||
});
|
||||
|
||||
const inspection = inspectGhidraInstallation({
|
||||
environment: {},
|
||||
installDir,
|
||||
javaHome: configuredHome,
|
||||
});
|
||||
|
||||
expect(inspection.javaHome).toBe(reportedHome);
|
||||
expect(inspection.javaVersion).toBe(version);
|
||||
expect(inspection.checks.find(({ name }) => name === "java")).toMatchObject(
|
||||
{
|
||||
status: fullJdk ? "passed" : "failed",
|
||||
detail: expect.stringContaining(fullJdk ? "; JDK;" : "; runtime only;"),
|
||||
},
|
||||
);
|
||||
expect(mockSpawnSync).toHaveBeenCalledExactlyOnceWith(
|
||||
join(
|
||||
configuredHome,
|
||||
"bin",
|
||||
process.platform === "win32" ? "java.exe" : "java",
|
||||
),
|
||||
expect.arrayContaining([
|
||||
"-Dstdout.encoding=UTF-8",
|
||||
"-Dstderr.encoding=UTF-8",
|
||||
"-Dsun.stdout.encoding=UTF-8",
|
||||
"-Dsun.stderr.encoding=UTF-8",
|
||||
]),
|
||||
expect.objectContaining({ encoding: "utf8" }),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -6,9 +6,15 @@ import { parse as parseYaml } from "yaml";
|
||||
|
||||
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
|
||||
import { npxRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
|
||||
import { configureClientConfiguration } from "../../../src/application/SetupClientConfiguration.js";
|
||||
import {
|
||||
configureClientConfiguration,
|
||||
inspectClientConfiguration,
|
||||
} from "../../../src/application/SetupClientConfiguration.js";
|
||||
import { supportedClients } from "../../../src/application/SupportedClients.js";
|
||||
import { systemUninstallHost } from "../../../src/application/Uninstall.js";
|
||||
import {
|
||||
runUninstall,
|
||||
systemUninstallHost,
|
||||
} from "../../../src/application/Uninstall.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { clearClientLocationEnvironment } from "../../fixtures/clientEnvironment.js";
|
||||
|
||||
@@ -90,18 +96,75 @@ describe("Hermes configuration paths", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Hermes YAML registration", () => {
|
||||
const hermesClient = async () => {
|
||||
const home = await createTestTempDirectory("rea-hermes-");
|
||||
const client = supportedClients(home, process.platform, {}).find(
|
||||
({ name }) => name === "hermes",
|
||||
);
|
||||
if (client?.markerPath === undefined)
|
||||
throw new Error("missing Hermes client");
|
||||
await mkdir(client.markerPath, { recursive: true });
|
||||
return { home, client };
|
||||
};
|
||||
const hermesClient = async () => {
|
||||
const home = await createTestTempDirectory("rea-hermes-");
|
||||
const client = supportedClients(home, process.platform, {}).find(
|
||||
({ name }) => name === "hermes",
|
||||
);
|
||||
if (client?.markerPath === undefined)
|
||||
throw new Error("missing Hermes client");
|
||||
await mkdir(client.markerPath, { recursive: true });
|
||||
return { home, client };
|
||||
};
|
||||
|
||||
describe("Hermes YAML shape diagnostics", () => {
|
||||
it.each(
|
||||
[
|
||||
"!!set {rea: null}",
|
||||
"!!omap [{rea: {command: rea, args: [mcp]}}]",
|
||||
"!!timestamp 2001-12-15",
|
||||
"!!binary cmVh",
|
||||
].flatMap((value) => [
|
||||
{
|
||||
original: `${value}\n`,
|
||||
problem: "The configuration root must be an object",
|
||||
},
|
||||
{
|
||||
original: `mcp_servers: ${value}\n`,
|
||||
problem: '"mcp_servers" must be an object',
|
||||
},
|
||||
]),
|
||||
)(
|
||||
"blocks setup and uninstall before changes for tagged non-record YAML: $original",
|
||||
async ({ original, problem }) => {
|
||||
const { home, client } = await hermesClient();
|
||||
const cursor = join(home, ".cursor", "mcp.json");
|
||||
const cursorOriginal =
|
||||
'{"mcpServers":{"rea":{"command":"rea","args":["mcp"]}}}';
|
||||
await mkdir(join(home, ".cursor"));
|
||||
await writeFile(cursor, cursorOriginal);
|
||||
await writeFile(client.configPath, original);
|
||||
expect(
|
||||
await inspectClientConfiguration(client, {}, command),
|
||||
).toMatchObject({
|
||||
status: "invalid",
|
||||
remediation: `Configuration ${client.configPath} is malformed: ${problem}`,
|
||||
});
|
||||
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
||||
status: "failed",
|
||||
reason: "readback",
|
||||
});
|
||||
const result = await runUninstall(
|
||||
false,
|
||||
systemUninstallHost(home, undefined, {}),
|
||||
);
|
||||
expect(result.status).toBe("failed");
|
||||
expect(result.items).toContainEqual({
|
||||
name: "hermes",
|
||||
status: "failed",
|
||||
detail: `Configuration was not changed: ${problem}. Repair it, then rerun uninstall.`,
|
||||
});
|
||||
expect(await readFile(client.configPath, "utf8")).toBe(original);
|
||||
expect(await readFile(cursor, "utf8")).toBe(cursorOriginal);
|
||||
await expect(
|
||||
readFile(`${client.configPath}.rea.backup`, "utf8"),
|
||||
).rejects.toThrow();
|
||||
await expect(readFile(`${cursor}.rea.backup`, "utf8")).rejects.toThrow();
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("Hermes YAML registration", () => {
|
||||
it("writes mcp_servers, preserves comments, reads back, and uninstalls", async () => {
|
||||
const { home, client } = await hermesClient();
|
||||
await writeFile(
|
||||
|
||||
@@ -334,13 +334,18 @@ describe("native macOS installer", { timeout: 20_000 }, () => {
|
||||
});
|
||||
|
||||
describe("installer semantic version parsing", { timeout: 20_000 }, () => {
|
||||
it.each(["1.2.3-01"])(
|
||||
it.each([
|
||||
"1.2.3-01",
|
||||
"1.2.3-$(printf unexpected)",
|
||||
'1.2.3-"; printf unexpected; #',
|
||||
])(
|
||||
"rejects malformed semantic versions before invoking npm: %s",
|
||||
async (version) => {
|
||||
const fixture = await createFixture();
|
||||
await expect(
|
||||
runInstaller(fixture, ["--version", version, "--dry-run"]),
|
||||
).rejects.toMatchObject({
|
||||
stdout: "",
|
||||
stderr:
|
||||
"REA installation failed: version must be an exact semantic version.\n",
|
||||
});
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { inspectBundleKeyedArchive } from "../../../src/artifacts/apple/KeyedArchiveReader.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { deeplyNestedXmlPlist } from "../../fixtures/keyedArchiveXmlNesting.js";
|
||||
|
||||
it.each([129, 3000])(
|
||||
"reports XML nesting of %i levels as the keyed archive decode limit",
|
||||
async (depth) => {
|
||||
const root = await createTestTempDirectory("rea-keyed-depth-");
|
||||
await writeFile(join(root, "Deep.plist"), deeplyNestedXmlPlist(depth));
|
||||
const rejected = await inspectBundleKeyedArchive({
|
||||
bundlePath: root,
|
||||
targetSha256: "a".repeat(64),
|
||||
parameters: { path: "Deep.plist" },
|
||||
platform: "linux",
|
||||
}).catch((cause: unknown) => cause);
|
||||
// Recursive decoding exhausts the call stack before the projection limit
|
||||
// can report it, so the limit diagnostic must come from the preflight.
|
||||
expect(rejected).toMatchObject({
|
||||
reason: "limit",
|
||||
message:
|
||||
"Cannot decode selected Foundation keyed archive: Plist exceeds 128 nesting levels",
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -5,7 +5,11 @@ import { describe, expect, it } from "vitest";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { resolveClientConfigTransactionPath } from "../../../src/application/ClientConfigPath.js";
|
||||
import { configureClientConfiguration } from "../../../src/application/SetupClientConfiguration.js";
|
||||
import { readConfigurationFile } from "../../../src/application/ClientConfigurationFiles.js";
|
||||
import {
|
||||
configureClientConfiguration,
|
||||
inspectClientConfiguration,
|
||||
} from "../../../src/application/SetupClientConfiguration.js";
|
||||
import { PRODUCT_IDENTITY } from "../../../src/identity.js";
|
||||
|
||||
const pinnedPackage = PRODUCT_IDENTITY.registrationPackageSpecifier;
|
||||
@@ -330,3 +334,87 @@ describe("JSON client configuration migration and provider paths", () => {
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("JSON client configuration shape diagnostics", () => {
|
||||
it.each([
|
||||
{
|
||||
format: "json" as const,
|
||||
original:
|
||||
'{"__proto__":{"mcpServers":{"rea":{"command":"rea","args":["mcp"]}}}}',
|
||||
serversKey: "mcpServers",
|
||||
},
|
||||
{
|
||||
format: "opencode" as const,
|
||||
original:
|
||||
'{"mcp":{"__proto__":{"servers":{"rea":{"type":"local","command":["rea","mcp"]}}}}}',
|
||||
serversKey: "mcp",
|
||||
},
|
||||
])(
|
||||
"registers an own server instead of trusting inherited $format settings",
|
||||
async ({ format, original, serversKey }) => {
|
||||
const directory = await createTestTempDirectory("rea-setup-prototype-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
const client = {
|
||||
name: format === "json" ? "cursor" : "opencode",
|
||||
configPath,
|
||||
format,
|
||||
};
|
||||
await writeFile(configPath, original);
|
||||
expect(
|
||||
await inspectClientConfiguration(client, {}, ["rea", "mcp"]),
|
||||
).toMatchObject({ status: "update" });
|
||||
expect(
|
||||
await configureClientConfiguration(client, {}, ["rea", "mcp"]),
|
||||
).toMatchObject({ status: "configured" });
|
||||
const document = JSON.parse(await readFile(configPath, "utf8"));
|
||||
expect(Object.hasOwn(document, serversKey)).toBe(true);
|
||||
expect(Object.hasOwn(document[serversKey], "rea")).toBe(true);
|
||||
expect(document[serversKey].rea.command).toEqual(
|
||||
format === "json" ? "rea" : ["rea", "mcp"],
|
||||
);
|
||||
const originalDocument = JSON.parse(original);
|
||||
expect(
|
||||
format === "json" ? document.__proto__ : document[serversKey].__proto__,
|
||||
).toEqual(
|
||||
format === "json"
|
||||
? originalDocument.__proto__
|
||||
: originalDocument[serversKey].__proto__,
|
||||
);
|
||||
expect(await readFile(`${configPath}.rea.backup`, "utf8")).toBe(original);
|
||||
expect(
|
||||
await inspectClientConfiguration(client, {}, ["rea", "mcp"]),
|
||||
).toMatchObject({ status: "already_current" });
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
['{"mcpServers":null,"keep":1}', '"mcpServers" must be an object'],
|
||||
["[]", "The configuration root must be an object"],
|
||||
['{"mcpServers":"x"}', '"mcpServers" must be an object'],
|
||||
] as const)(
|
||||
"names structural shape problems in setup remediation: %s",
|
||||
async (original, problem) => {
|
||||
const directory = await createTestTempDirectory("rea-setup-shape-");
|
||||
const configPath = join(directory, "mcp.json");
|
||||
const client = {
|
||||
name: "cursor",
|
||||
configPath,
|
||||
format: "json" as const,
|
||||
};
|
||||
await writeFile(configPath, original);
|
||||
const read = await readConfigurationFile(configPath, "json");
|
||||
expect(read.ok).toBe(false);
|
||||
if (read.ok) throw new Error("expected malformed configuration");
|
||||
expect(read.error.detail).toBe(
|
||||
`Configuration ${configPath} is malformed: ${problem}`,
|
||||
);
|
||||
expect(
|
||||
await inspectClientConfiguration(client, {}, ["rea", "mcp"]),
|
||||
).toEqual({
|
||||
status: "invalid",
|
||||
remediation: `Configuration ${configPath} is malformed: ${problem}`,
|
||||
});
|
||||
expect(await readFile(configPath, "utf8")).toBe(original);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { workflowGit } from "../../support/workflowGit.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
|
||||
it.skipIf(process.platform === "android")(
|
||||
"reruns test validation after repository or external input changes while reusing preparation",
|
||||
async () => {
|
||||
const config = z
|
||||
.object({
|
||||
tasks: z.record(z.string(), z.record(z.string(), z.unknown())),
|
||||
})
|
||||
.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
new URL("../../../turbo.json", import.meta.url),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const testTask = config.tasks["test:run"];
|
||||
const dependencies = z.array(z.string()).parse(testTask?.dependsOn);
|
||||
const root = await createTestTempDirectory("rea-test-cache-");
|
||||
const external = await createTestTempDirectory("rea-test-dependency-");
|
||||
const dependency = join(external, "provider.json");
|
||||
const scripts: Record<string, string> = { "test:run": "node check.mjs" };
|
||||
const tasks: Record<string, unknown> = { "test:run": testTask };
|
||||
for (const [index, task] of dependencies.entries()) {
|
||||
scripts[task] = `node prepare.mjs ${index}`;
|
||||
tasks[task] = {
|
||||
inputs: ["artifact-input.txt"],
|
||||
outputs: [`prepared-${index}.txt`],
|
||||
};
|
||||
}
|
||||
await writeFile(
|
||||
join(root, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "rea-cache-fixture",
|
||||
version: "1.0.0",
|
||||
private: true,
|
||||
type: "module",
|
||||
packageManager: "npm@11.16.0",
|
||||
scripts,
|
||||
}),
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "package-lock.json"),
|
||||
JSON.stringify({
|
||||
name: "rea-cache-fixture",
|
||||
version: "1.0.0",
|
||||
lockfileVersion: 3,
|
||||
packages: { "": { name: "rea-cache-fixture", version: "1.0.0" } },
|
||||
}),
|
||||
);
|
||||
await writeFile(join(root, "turbo.json"), JSON.stringify({ tasks }));
|
||||
await writeFile(
|
||||
join(root, "artifact-input.txt"),
|
||||
"unchanged preparation input",
|
||||
);
|
||||
await writeFile(join(root, "README_zh.md"), "aligned");
|
||||
await writeFile(dependency, "healthy");
|
||||
await writeFile(
|
||||
join(root, "prepare.mjs"),
|
||||
'import { appendFileSync } from "node:fs"; appendFileSync(`prepared-${process.argv[2]}.txt`, "prepared\\n");',
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "check.mjs"),
|
||||
`import { readFileSync } from "node:fs"; if(readFileSync("README_zh.md","utf8") !== "aligned" || readFileSync(${JSON.stringify(dependency)},"utf8") !== "healthy") throw new Error("current input is invalid");`,
|
||||
);
|
||||
await workflowGit(root, ["init", "--initial-branch=main"]);
|
||||
await workflowGit(root, ["add", "."]);
|
||||
await workflowGit(root, ["commit", "-m", "test: seed cache fixture"]);
|
||||
const run = () =>
|
||||
execute(
|
||||
process.execPath,
|
||||
[
|
||||
join(process.cwd(), "node_modules/turbo/bin/turbo"),
|
||||
"run",
|
||||
"test:run",
|
||||
"--output-logs=errors-only",
|
||||
],
|
||||
{ cwd: root, env: { ...process.env, TURBO_DAEMON: "false" } },
|
||||
);
|
||||
await run();
|
||||
await writeFile(join(root, "README_zh.md"), "wrong command");
|
||||
await expect(run()).rejects.toMatchObject({ code: 1 });
|
||||
await writeFile(join(root, "README_zh.md"), "aligned");
|
||||
await run();
|
||||
await writeFile(dependency, "faulty");
|
||||
await expect(run()).rejects.toMatchObject({ code: 1 });
|
||||
await expect(run()).rejects.toMatchObject({ code: 1 });
|
||||
await writeFile(dependency, "healthy");
|
||||
await run();
|
||||
for (const index of dependencies.keys()) {
|
||||
expect(await readFile(join(root, `prepared-${index}.txt`), "utf8")).toBe(
|
||||
"prepared\n",
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,73 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { observeSettlement } from "../../../src/process/capture/ProcessCaptureLifecycle.js";
|
||||
import { observeOwnedProcessGroups } from "../../../src/process/ProcessOwnershipObservation.js";
|
||||
|
||||
/** Process group id that cannot exist on any supported host. */
|
||||
const ABSENT_GROUP_ID = 4_294_967_295;
|
||||
|
||||
const observeGroup = async (groupId: number) =>
|
||||
observeOwnedProcessGroups("settlement-deadline-probe", [groupId]);
|
||||
|
||||
describe("settlement deadline classification", () => {
|
||||
it("does not report a single empty observation as alive_at_deadline", async () => {
|
||||
expect(
|
||||
(await observeGroup(ABSENT_GROUP_ID)).get(ABSENT_GROUP_ID)?.state,
|
||||
).toBe("empty");
|
||||
|
||||
const settlement = await observeSettlement(
|
||||
"settlement-single-empty",
|
||||
[ABSENT_GROUP_ID],
|
||||
0,
|
||||
() => undefined,
|
||||
"linux",
|
||||
);
|
||||
expect(settlement.state).toBe("unverifiable");
|
||||
});
|
||||
|
||||
it("still reports observed liveness as alive_at_deadline", async () => {
|
||||
const runId = "settlement-live-group";
|
||||
// A detached child leads its own process group and carries the run token,
|
||||
// so the group observes as a genuinely owned live member.
|
||||
const child = spawn("sleep", ["30"], {
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
env: { ...process.env, REA_PROCESS_RUN_ID: runId },
|
||||
});
|
||||
child.unref();
|
||||
try {
|
||||
// Wait until the child is actually listed before asserting on it.
|
||||
const started = Date.now();
|
||||
while (
|
||||
(await observeOwnedProcessGroups(runId, [child.pid!])).get(child.pid!)
|
||||
?.state !== "alive"
|
||||
) {
|
||||
if (Date.now() - started > 5_000)
|
||||
throw new Error("live fixture group never observed as alive");
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
}
|
||||
|
||||
const settlement = await observeSettlement(
|
||||
runId,
|
||||
[child.pid!],
|
||||
0,
|
||||
() => undefined,
|
||||
"linux",
|
||||
);
|
||||
expect(settlement.state).toBe("alive_at_deadline");
|
||||
} finally {
|
||||
child.kill("SIGKILL");
|
||||
}
|
||||
});
|
||||
|
||||
it("still reports two consecutive empty observations as quiesced", async () => {
|
||||
const settlement = await observeSettlement(
|
||||
"settlement-two-empty",
|
||||
[ABSENT_GROUP_ID],
|
||||
1_000,
|
||||
() => undefined,
|
||||
"linux",
|
||||
);
|
||||
expect(settlement.state).toBe("quiesced");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,266 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import {
|
||||
copyFile,
|
||||
mkdtemp,
|
||||
readFile,
|
||||
readdir,
|
||||
rm,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { basename, dirname, join } from "node:path";
|
||||
import { afterEach, expect, test, vi } from "vitest";
|
||||
|
||||
import { AdbProvider } from "../../../../src/adb/AdbProvider.js";
|
||||
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
||||
import {
|
||||
execFileBytes,
|
||||
execFileOutput,
|
||||
} from "../../../../src/process/ExecFileOutput.js";
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
|
||||
// Exercise real filesystem publication; the Android process reply is simulated.
|
||||
vi.mock(
|
||||
"../../../../src/process/ExecFileOutput.js",
|
||||
async (importOriginal) => ({
|
||||
...(await importOriginal<
|
||||
typeof import("../../../../src/process/ExecFileOutput.js")
|
||||
>()),
|
||||
execFileBytes: vi.fn(),
|
||||
execFileOutput: vi.fn(),
|
||||
}),
|
||||
);
|
||||
vi.mock("node:fs/promises", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("node:fs/promises")>();
|
||||
return {
|
||||
...actual,
|
||||
copyFile: vi.fn(actual.copyFile),
|
||||
mkdtemp: vi.fn(actual.mkdtemp),
|
||||
rm: vi.fn(actual.rm),
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
const fixture = async (duringCollection?: (root: string) => Promise<void>) => {
|
||||
const root = await createTestTempDirectory("rea-adb-bugreport-");
|
||||
const binary = join(root, "adb");
|
||||
let reportedPath = "";
|
||||
vi.mocked(execFileOutput).mockImplementation(async (_binary, args) => {
|
||||
expect(args).toEqual(["version"]);
|
||||
return {
|
||||
stdout: `Android Debug Bridge version 1.0.41\nVersion 34.0.5-stub\nInstalled as ${binary}\n`,
|
||||
stderr: "",
|
||||
};
|
||||
});
|
||||
vi.mocked(execFileBytes).mockImplementation(async (_binary, args) => {
|
||||
expect(args.slice(0, 3)).toEqual(["-s", "device", "bugreport"]);
|
||||
const staging = args[3]!;
|
||||
reportedPath = join(staging, "bugreport test.zip");
|
||||
await writeFile(reportedPath, "bugreport-bytes");
|
||||
await duringCollection?.(root);
|
||||
return {
|
||||
stdout: Buffer.from(`Bug report copied to ${reportedPath}\n`),
|
||||
stderr: Buffer.alloc(0),
|
||||
};
|
||||
});
|
||||
const provider = new AdbProvider({ environment: { REA_ADB_PATH: binary } });
|
||||
return {
|
||||
root,
|
||||
provider,
|
||||
reportedPath: () => reportedPath,
|
||||
request: {
|
||||
operation: "collect_adb_bugreport" as const,
|
||||
input: { serial: "device", output_directory: root },
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
test.each(["before", "during"] as const)(
|
||||
"preserves a same-name caller archive created %s collection",
|
||||
async (when) => {
|
||||
const existing = async (root: string) => {
|
||||
await writeFile(join(root, "bugreport test.zip"), "existing evidence");
|
||||
await writeFile(join(root, "bugreport test (1).zip"), "other evidence");
|
||||
};
|
||||
const f = await fixture(when === "during" ? existing : undefined);
|
||||
if (when === "before") await existing(f.root);
|
||||
const result = await f.provider.execute(f.request);
|
||||
if (!result.ok) throw result.error;
|
||||
const localPath = join(f.root, "bugreport test (2).zip");
|
||||
expect(result.value.result).toMatchObject({
|
||||
local_path: localPath,
|
||||
adb_reported_path: f.reportedPath(),
|
||||
bytes: 15,
|
||||
sha256: createHash("sha256").update("bugreport-bytes").digest("hex"),
|
||||
});
|
||||
expect(await readFile(join(f.root, "bugreport test.zip"), "utf8")).toBe(
|
||||
"existing evidence",
|
||||
);
|
||||
expect(await readFile(join(f.root, "bugreport test (1).zip"), "utf8")).toBe(
|
||||
"other evidence",
|
||||
);
|
||||
expect(await readFile(localPath, "utf8")).toBe("bugreport-bytes");
|
||||
expect((await readdir(f.root)).sort()).toEqual([
|
||||
"bugreport test (1).zip",
|
||||
"bugreport test (2).zip",
|
||||
"bugreport test.zip",
|
||||
]);
|
||||
await f.provider.close();
|
||||
},
|
||||
);
|
||||
|
||||
test("retains a completed archive after failed publication and later provider work", async () => {
|
||||
const f = await fixture();
|
||||
const existing = join(f.root, "bugreport test.zip");
|
||||
await writeFile(existing, "existing evidence");
|
||||
const publicationFailure = Object.assign(new Error("no space left"), {
|
||||
code: "ENOSPC",
|
||||
});
|
||||
vi.mocked(copyFile).mockRejectedValueOnce(publicationFailure);
|
||||
const failed = await f.provider.execute(f.request);
|
||||
if (failed.ok) throw new Error("expected publication failure");
|
||||
const retainedPath = f.reportedPath();
|
||||
expect(failed.error._tag).toBe("AnalysisOutputError");
|
||||
expect(failed.error.cause).toBe(publicationFailure);
|
||||
expect(
|
||||
projectAnalysisError(failed.error).details?.partial_observation,
|
||||
).toMatchObject({
|
||||
provider_id: "adb",
|
||||
operation: f.request.operation,
|
||||
result: {
|
||||
serial: "device",
|
||||
local_path: retainedPath,
|
||||
adb_reported_path: retainedPath,
|
||||
digest_status: "unknown",
|
||||
},
|
||||
});
|
||||
expect(await readFile(retainedPath, "utf8")).toBe("bugreport-bytes");
|
||||
expect(await readFile(existing, "utf8")).toBe("existing evidence");
|
||||
|
||||
// New work and terminal cleanup must not reclaim the retained acquisition.
|
||||
const next = await f.provider.execute(f.request);
|
||||
if (!next.ok) throw next.error;
|
||||
expect(next.value.result).toMatchObject({
|
||||
local_path: join(f.root, "bugreport test (1).zip"),
|
||||
bytes: 15,
|
||||
sha256: createHash("sha256").update("bugreport-bytes").digest("hex"),
|
||||
});
|
||||
await f.provider.close();
|
||||
expect(await readFile(retainedPath, "utf8")).toBe("bugreport-bytes");
|
||||
expect(await readFile(existing, "utf8")).toBe("existing evidence");
|
||||
expect(await readFile(join(f.root, "bugreport test (1).zip"), "utf8")).toBe(
|
||||
"bugreport-bytes",
|
||||
);
|
||||
expect((await readdir(f.root)).sort()).toEqual(
|
||||
[
|
||||
basename(dirname(retainedPath)),
|
||||
"bugreport test.zip",
|
||||
"bugreport test (1).zip",
|
||||
].sort(),
|
||||
);
|
||||
});
|
||||
|
||||
test("retains final and producer paths when digest verification is cancelled", async () => {
|
||||
const f = await fixture();
|
||||
const controller = new AbortController();
|
||||
const actualCopy =
|
||||
await vi.importActual<typeof import("node:fs/promises")>(
|
||||
"node:fs/promises",
|
||||
);
|
||||
vi.mocked(copyFile).mockImplementationOnce(async (...args) => {
|
||||
await actualCopy.copyFile(...args);
|
||||
controller.abort();
|
||||
});
|
||||
const result = await f.provider.execute(f.request, {
|
||||
signal: controller.signal,
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("expected cancellation");
|
||||
expect(result.error._tag).toBe("AnalysisCancelledError");
|
||||
expect(result.error.partialObservation).toMatchObject({
|
||||
operation: f.request.operation,
|
||||
result: {
|
||||
local_path: join(f.root, "bugreport test.zip"),
|
||||
adb_reported_path: f.reportedPath(),
|
||||
digest_status: "unknown",
|
||||
},
|
||||
});
|
||||
expect(await readFile(join(f.root, "bugreport test.zip"), "utf8")).toBe(
|
||||
"bugreport-bytes",
|
||||
);
|
||||
expect(await readdir(f.root)).toEqual(["bugreport test.zip"]);
|
||||
await f.provider.close();
|
||||
});
|
||||
|
||||
test("returns staging allocation failures without invoking device collection", async () => {
|
||||
const f = await fixture();
|
||||
vi.mocked(mkdtemp).mockRejectedValueOnce(new Error("staging denied"));
|
||||
const result = await f.provider.execute(f.request);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("expected output failure");
|
||||
expect(result.error._tag).toBe("AnalysisOutputError");
|
||||
expect(execFileBytes).not.toHaveBeenCalled();
|
||||
await f.provider.close();
|
||||
});
|
||||
|
||||
test("retains published evidence and retries failed staging cleanup", async () => {
|
||||
const f = await fixture();
|
||||
vi.mocked(rm).mockRejectedValueOnce(new Error("cleanup denied"));
|
||||
const result = await f.provider.execute(f.request);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("expected cleanup failure");
|
||||
expect(result.error.cleanupResources).toContain(dirname(f.reportedPath()));
|
||||
expect(result.error.partialObservation).toMatchObject({
|
||||
operation: f.request.operation,
|
||||
result: {
|
||||
local_path: join(f.root, "bugreport test.zip"),
|
||||
adb_reported_path: f.reportedPath(),
|
||||
bytes: 15,
|
||||
sha256: createHash("sha256").update("bugreport-bytes").digest("hex"),
|
||||
},
|
||||
});
|
||||
await f.provider.close();
|
||||
expect(await readdir(f.root)).toEqual(["bugreport test.zip"]);
|
||||
});
|
||||
|
||||
test("refuses an archive reported outside the owned staging directory", async () => {
|
||||
const f = await fixture();
|
||||
const existing = join(f.root, "bugreport test.zip");
|
||||
await writeFile(existing, "existing evidence");
|
||||
vi.mocked(execFileBytes).mockResolvedValueOnce({
|
||||
stdout: Buffer.from(`Bug report copied to ${existing}\n`),
|
||||
stderr: Buffer.alloc(0),
|
||||
});
|
||||
const result = await f.provider.execute(f.request);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("expected protocol refusal");
|
||||
expect(result.error._tag).toBe("AnalysisProtocolError");
|
||||
expect(await readFile(existing, "utf8")).toBe("existing evidence");
|
||||
expect(await readdir(f.root)).toEqual(["bugreport test.zip"]);
|
||||
await f.provider.close();
|
||||
});
|
||||
|
||||
test("preserves the primary protocol failure when staging cleanup also fails", async () => {
|
||||
const f = await fixture();
|
||||
vi.mocked(execFileBytes).mockResolvedValueOnce({
|
||||
stdout: Buffer.from("unsupported completion format\n"),
|
||||
stderr: Buffer.alloc(0),
|
||||
});
|
||||
vi.mocked(rm).mockRejectedValueOnce(new Error("cleanup denied"));
|
||||
const result = await f.provider.execute(f.request);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("expected protocol and cleanup failure");
|
||||
expect(result.error.cause).toMatchObject({
|
||||
errors: [
|
||||
{
|
||||
_tag: "AnalysisProtocolError",
|
||||
message: expect.stringContaining("did not report an archive path"),
|
||||
},
|
||||
expect.any(Error),
|
||||
],
|
||||
});
|
||||
expect(result.error.cleanupIncomplete).toBe(true);
|
||||
expect(result.error.cleanupResources).toHaveLength(1);
|
||||
await f.provider.close();
|
||||
expect(await readdir(f.root)).toEqual([]);
|
||||
});
|
||||
Reference in New Issue
Block a user