Files
reverse-engineering-anything/tests/boundary/providers/native/artifactProvider.extractionDestination.test.ts
T
APZNandgensokyo-dev ad518cff65 feat(artifacts): select extraction entries and output destination (#4031)
* feat(artifacts): select extraction entries and output destination

Refs morluto/rea#3490

* fix(artifacts): omit absent selection from execution parameters

* fix(artifacts): protect source directories and verify public selection

* fix(artifacts): keep optional selection inputs JSON-safe

* fix(artifacts): separate reader ownership from selected destinations

Validate complete reader inventory independently from collisions among selected output entries. Use occurrence-parent ownership instead of filename prefixes so independently owned PyInstaller entries remain selectable while nested-reader members remain refused. Validate advertised MCP schemas through the shared acceptance helper and add real PyInstaller/ASAR and excluded-entry regressions.

* fix(artifacts): advertise absolute extraction destinations

Reuse the shared host-absolute local path schema instead of an opaque refinement so SDK-converted JSON Schema preserves the runtime constraint. Extend the advertised-path and MCP-handler regression matrix for extract_artifact.output_root.

* fix(contracts): advertise unique extraction occurrence IDs

---------

Co-authored-by: gensokyo-dev <gensokyo-dev@users.noreply.github.com>
2026-11-06 03:28:05 +08:00

62 lines
2.0 KiB
TypeScript

import {
lstat,
mkdir,
readFile,
readdir,
symlink,
writeFile,
} from "node:fs/promises";
import { join } from "node:path";
import { expect, it } from "vitest";
import { parseBinaryTarget } from "../../../../src/application/BinaryTargetResolver.js";
import {
CPU,
machoImage,
} from "../../../../src/artifacts/apple/MachoImage.fixture.js";
import { withArtifactClient } from "../../../support/artifactClientScope.js";
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
it.each(["direct", "symlink"] as const)(
"refuses a %s output path inside the source without modifying caller files",
async (kind) => {
const root = await createTestTempDirectory(
"rea-extraction-source-boundary-",
);
const source = join(root, "source.app");
await mkdir(source);
await writeFile(join(source, "payload.txt"), "caller bytes");
await writeFile(
join(source, "Info.plist"),
'<plist version="1.0"><dict><key>CFBundleExecutable</key><string>Main</string></dict></plist>',
);
await writeFile(join(source, "Main"), machoImage({ cpu: CPU.arm64 }));
const target = await parseBinaryTarget(source);
if (!target.ok) throw target.error;
let parent = source;
if (kind === "symlink") {
parent = join(root, "alias");
await symlink(
source,
parent,
process.platform === "win32" ? "junction" : "dir",
);
}
const output = join(parent, "output");
const result = await withArtifactClient(target.value, (client) =>
client.execute("extract_artifact", { output_root: output }),
);
expect(result).toMatchObject({ ok: false, error: { reason: "path" } });
expect((await readdir(source)).sort()).toEqual([
"Info.plist",
"Main",
"payload.txt",
]);
expect(await readFile(join(source, "payload.txt"), "utf8")).toBe(
"caller bytes",
);
await expect(lstat(output)).rejects.toMatchObject({ code: "ENOENT" });
},
);