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