fix(artifacts): prefer artifact magic over implicit database suffix
This commit is contained in:
@@ -157,9 +157,16 @@ export const parseBinaryTarget = async (
|
||||
availableArchitectures: ["x86"],
|
||||
});
|
||||
}
|
||||
// Explicit database selection owns routing; a suffix is only a fallback.
|
||||
const artifactFormat =
|
||||
targetKind === "database"
|
||||
? undefined
|
||||
: await detectArtifactFormat(path, handle, metadata, signal);
|
||||
if (
|
||||
targetKind === "database" ||
|
||||
(targetKind === undefined && path.toLowerCase().endsWith(".hop"))
|
||||
(targetKind === undefined &&
|
||||
artifactFormat === undefined &&
|
||||
path.toLowerCase().endsWith(".hop"))
|
||||
)
|
||||
return ok({
|
||||
path,
|
||||
@@ -168,12 +175,6 @@ export const parseBinaryTarget = async (
|
||||
kind: "database",
|
||||
format: "analysis-database",
|
||||
});
|
||||
const artifactFormat = await detectArtifactFormat(
|
||||
path,
|
||||
handle,
|
||||
metadata,
|
||||
signal,
|
||||
);
|
||||
if (artifactFormat !== undefined) {
|
||||
const identity = {
|
||||
path,
|
||||
|
||||
@@ -45,7 +45,7 @@ cliTest(
|
||||
"classic iNES has the same complete byte inventory through compiled CLI and stdio MCP",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-ines-public-");
|
||||
const path = join(root, "卡带.data");
|
||||
const path = join(root, "卡带.hop");
|
||||
const bytes = inesFixture({
|
||||
trainer: true,
|
||||
trailing: Buffer.from([0, 255, 3, 0]),
|
||||
|
||||
@@ -245,16 +245,19 @@ describe("binary target I/O: package classification", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("classifies a binary plist by its magic under any extension", async () => {
|
||||
const directory = await createTestTempDirectory("rea-bplist-target-");
|
||||
const path = join(directory, "Model.archive");
|
||||
await writeFile(path, buildBinary({ $archiver: "NSKeyedArchiver" }));
|
||||
const result = await parseBinaryTarget(path);
|
||||
expect(result.ok && result.value).toMatchObject({
|
||||
kind: "artifact",
|
||||
format: "plist",
|
||||
});
|
||||
});
|
||||
it.each(["archive", "hop"])(
|
||||
"classifies binary plist magic under a .%s extension",
|
||||
async (suffix) => {
|
||||
const directory = await createTestTempDirectory("rea-bplist-target-");
|
||||
const path = join(directory, `Model.${suffix}`);
|
||||
await writeFile(path, buildBinary({ $archiver: "NSKeyedArchiver" }));
|
||||
const result = await parseBinaryTarget(path);
|
||||
expect(result.ok && result.value).toMatchObject({
|
||||
kind: "artifact",
|
||||
format: "plist",
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("does not trust a ZIP-family extension without ZIP magic", async () => {
|
||||
const directory = await createTestTempDirectory("rea-fake-archive-");
|
||||
@@ -274,6 +277,10 @@ describe("binary target I/O: filesystem and app bundle target resolution", () =>
|
||||
await writeFile(join(directory, "sample.hop"), "database");
|
||||
await writeFile(join(directory, "text"), "hello");
|
||||
const database = await parseBinaryTarget("sample.hop", { cwd: directory });
|
||||
expect(database).toMatchObject({
|
||||
ok: true,
|
||||
value: { kind: "database", format: "analysis-database" },
|
||||
});
|
||||
expect(database.ok && database.value.sha256).toBe(
|
||||
"3549b0028b75d981cdda2e573e9cb49dedc200185876df299f912b79f69dabd8",
|
||||
);
|
||||
|
||||
@@ -28,15 +28,31 @@ import {
|
||||
const sha256 = (bytes: Buffer) =>
|
||||
createHash("sha256").update(bytes).digest("hex");
|
||||
|
||||
it("routes iNES bytes as an archive independently of the file suffix", async () => {
|
||||
const root = await createTestTempDirectory("rea-ines-target-");
|
||||
const path = join(root, "cartridge.data");
|
||||
await writeFile(path, inesFixture());
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (!target.ok) throw target.error;
|
||||
expect(target.value).toMatchObject({ kind: "archive", format: "ines" });
|
||||
});
|
||||
it.each(["data", "hop", "HOP"])(
|
||||
"routes iNES bytes as an archive with a .%s suffix",
|
||||
async (suffix) => {
|
||||
const root = await createTestTempDirectory("rea-ines-target-");
|
||||
const path = join(root, `cartridge.${suffix}`);
|
||||
await writeFile(path, inesFixture());
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (!target.ok) throw target.error;
|
||||
expect(target.value).toMatchObject({ kind: "archive", format: "ines" });
|
||||
},
|
||||
);
|
||||
|
||||
it("honors explicit database selection before parsing NES-signature bytes", async () => {
|
||||
const root = await createTestTempDirectory("rea-ines-database-");
|
||||
for (const bytes of [inesFixture(), Buffer.from("NES\x1a")]) {
|
||||
const path = join(root, "selected.hop");
|
||||
await writeFile(path, bytes);
|
||||
expect(
|
||||
await parseBinaryTarget(path, { targetKind: "database" }),
|
||||
).toMatchObject({
|
||||
ok: true,
|
||||
value: { kind: "database", format: "analysis-database" },
|
||||
});
|
||||
}
|
||||
});
|
||||
it.each([true, false])(
|
||||
"inventories and reconstructs all bytes with trainer=%s",
|
||||
async (trainer) => {
|
||||
|
||||
Reference in New Issue
Block a user