diff --git a/src/model/SafetensorsHeader.ts b/src/model/SafetensorsHeader.ts index bc2e5563f44..5222796e62d 100644 --- a/src/model/SafetensorsHeader.ts +++ b/src/model/SafetensorsHeader.ts @@ -9,7 +9,9 @@ import type { ModelTensor, } from "../domain/model/modelArtifact.js"; import { ModelHeaderReader } from "./ModelHeaderReader.js"; +import { unrecognizedInput } from "../domain/parseFailure.js"; import { + MODEL_FORMAT, MODEL_HEADER_BYTES, MODEL_JSON_NESTING, modelCapacityFailure, @@ -316,8 +318,12 @@ export const readSafetensorsHeader = async ( (brace !== 0x7b || length > BigInt(MODEL_HEADER_BYTES)) ) rejectPickle(); + // Neither GGUF magic nor a safetensors JSON header: another format's bytes, not a damaged model. if (brace !== 0x7b) - rejectModel("File does not contain a GGUF or safetensors header"); + throw unrecognizedInput( + MODEL_FORMAT, + "File does not contain a GGUF or safetensors header", + ); reader.requireFileExtent(8, length); const size = Number(length); reader.guarantee(size - 1); diff --git a/tests/acceptance/modelArtifactCli.test.ts b/tests/acceptance/modelArtifactCli.test.ts index 94169309644..c6cf1461672 100644 --- a/tests/acceptance/modelArtifactCli.test.ts +++ b/tests/acceptance/modelArtifactCli.test.ts @@ -44,6 +44,33 @@ const modelMcp = createSharedMcpSession(async (registerCleanup) => { }); afterAll(() => modelMcp.close()); +cliTest( + "reports a file that is not a model as unrecognized on both adapters", + async ({ cli }) => { + const root = await createTestTempDirectory("rea-model-unrecognized-"); + const path = join(root, "notes.txt"); + await writeFile(path, "plain text notes, not model weights\n"); + const expected = { + code: "unsupported_target", + details: { + operation: "inspect_model_artifact", + // Bytes of another format are unrecognized, not a damaged model. + failure_kind: "unrecognized", + reason: "File does not contain a GGUF or safetensors header", + }, + }; + const result = await cli.run({ + arguments: ["inspect-model-artifact", path, "--json"], + }); + expect(result.exitCode, result.stderr).toBe(1); + expect(result.json).toMatchObject(expected); + const call = await modelMcp.session.call(); + expect( + parseMcpToolError(await call("inspect_model_artifact", { path })).error, + ).toMatchObject(expected); + }, +); + cliTest( "preserves lowercase hyphenated GGUF architecture metadata from the published writer", async ({ cli }) => {