Files
reverse-engineering-anything/tests/acceptance/asarSelectedCompanionCli.test.ts
T
morluto 7bcefead69 test: strengthen and prune audited test coverage (#8573)
* test: strengthen and prune audited test coverage

* test: require delivered DeepSeek skill instructions

* test: keep schema fixture types private

* test: verify Gemini receives skill instructions

* test: bind Qwen skill evidence to its tool result

* test: report NativeAOT verifier checks precisely

* fix: verify Ghidra cleanup paths reliably

* fix: verify Command Code skill activation

* test: tighten cleanup and fixture checks

* test: verify packet capture evidence is recorded

* fix: report HTTP3 capture provenance accurately

* test: preserve resource coverage through MCP

* test: prune repeated assertions and retain cancellation identity

* fix: validate client verifier fixture paths

* test: skip Copilot verifier cases on Windows

* test: keep verifier setup target relative
2026-11-02 02:13:32 +08:00

88 lines
3.4 KiB
TypeScript

import {
mkdir,
readFile,
rename,
rm,
symlink,
writeFile,
} from "node:fs/promises";
import { createHash } from "node:crypto";
import { join } from "node:path";
import { createPackageWithOptions, extractFile } from "@electron/asar";
import { expect, onTestFinished } from "vitest";
import {
artifactExtractionResultSchema,
artifactInventoryResultSchema,
} from "../../src/domain/artifactGraph.js";
import { artifactInspectionResultSchema } from "../../src/domain/artifactInspection.js";
import { parseEvidence } from "../../src/domain/evidence.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
import { cliTest } from "../support/cli/cliFixture.js";
cliTest.skipIf(process.platform === "win32")(
"public ASAR inspection and extraction use the selected alias companion",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-asar-selected-cli-");
const source = join(root, "source");
const selected = join(root, "app.asar");
const canonical = join(root, "content-addressed-archive");
const bytes = Buffer.from("selected native companion");
await mkdir(source);
await writeFile(join(source, "native.node"), bytes);
await writeFile(join(source, "packed.txt"), "packed bytes");
await createPackageWithOptions(source, selected, { unpack: "*.node" });
await rename(selected, canonical);
await symlink(canonical, selected);
await mkdir(`${canonical}.unpacked`);
await writeFile(
join(`${canonical}.unpacked`, "native.node"),
"different canonical bytes",
);
expect(extractFile(selected, "native.node").equals(bytes)).toBe(true);
const inspected = await cli.run({
arguments: ["inspect-artifact", selected, "--json"],
});
expect(inspected.exitCode, inspected.stdout + inspected.stderr).toBe(0);
expect(parseEvidence(inspected.json).subject?.local_path).toBe(selected);
const inspection = artifactInspectionResultSchema.parse(
parseEvidence(inspected.json).normalized_result,
);
const inventoryEvidence = inspection.substeps.find(
({ operation }) => operation === "inventory_artifact",
)?.evidence;
if (inventoryEvidence === undefined)
throw new Error("Missing inventory Evidence");
const inventory = artifactInventoryResultSchema.parse(
inventoryEvidence.normalized_result,
);
const occurrence = inventory.occurrences.find(
({ logical_path }) => logical_path === "native.node",
);
expect(occurrence?.hash_status).toBe("verified");
expect(
inventory.nodes.find(
({ artifact_id }) => artifact_id === occurrence?.artifact_id,
)?.sha256,
).toBe(createHash("sha256").update(bytes).digest("hex"));
const extracted = await cli.run({
arguments: ["extract-artifact", selected, "--json"],
});
expect(extracted.exitCode, extracted.stdout + extracted.stderr).toBe(0);
expect(parseEvidence(extracted.json).subject?.local_path).toBe(selected);
const result = artifactExtractionResultSchema.parse(
parseEvidence(extracted.json).normalized_result,
);
onTestFinished(() =>
rm(result.output_root, { recursive: true, force: true }),
);
expect(
(await readFile(join(result.output_root, "native.node"))).equals(bytes),
).toBe(true);
expect(await readFile(join(result.output_root, "packed.txt"), "utf8")).toBe(
"packed bytes",
);
},
);