fix(model): report a file that is not a model as unrecognized (#15444)

This commit is contained in:
morluto authored and GitHub committed 2026-12-01 06:28:37 +00:00
1 parent 1b0612c73e
commit 6dae75eae0
2 files changed
+34 -1

No files matched your search

+7 -1
View File
@@ -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);
+27
View File
@@ -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 }) => {