@@ -14,6 +14,14 @@ const PNG_1X1_BASE64 =
1414 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+yf7kAAAAASUVORK5CYII=" ;
1515const tempDirs = useAutoCleanupTempDirTracker ( afterEach ) ;
1616
17+ function createIsomBrandBuffer ( brand : "hevc" | "msf1" ) : Buffer {
18+ const buffer = Buffer . alloc ( 24 ) ;
19+ buffer . writeUInt32BE ( buffer . length , 0 ) ;
20+ buffer . write ( "ftyp" , 4 , "ascii" ) ;
21+ buffer . write ( brand , 8 , "ascii" ) ;
22+ return buffer ;
23+ }
24+
1725async function runCap ( ...argv : string [ ] ) : Promise < void > {
1826 const program = new Command ( ) ;
1927 await registerCapabilityCli ( program , [ "node" , "openclaw" , ...argv ] ) ;
@@ -1284,6 +1292,54 @@ describe("capability cli", () => {
12841292 expect ( inputs [ 0 ] ?. mimeType ) . toBe ( "image/jpeg" ) ;
12851293 } ) ;
12861294
1295+ it ( "normalizes sniffed HEIC sequences to JPEG before local model probes" , async ( ) => {
1296+ const source = createIsomBrandBuffer ( "hevc" ) ;
1297+ const tempInput = path . join ( tempDirs . make ( "openclaw-model-run-heic-sequence-" ) , "opaque.bin" ) ;
1298+ await fs . writeFile ( tempInput , source ) ;
1299+
1300+ await runCapability ( "model" , "run" , "--prompt" , "describe this" , "--file" , tempInput , "--json" ) ;
1301+
1302+ expect ( mocks . convertHeicToJpeg ) . toHaveBeenCalledWith ( source ) ;
1303+ const call = firstCompletionCall ( ) ;
1304+ expect ( call ?. context ?. messages ?. [ 0 ] ?. content ) . toEqual ( [
1305+ { type : "text" , text : "describe this" } ,
1306+ {
1307+ type : "image" ,
1308+ data : Buffer . from ( "jpeg-normalized" ) . toString ( "base64" ) ,
1309+ mimeType : "image/jpeg" ,
1310+ } ,
1311+ ] ) ;
1312+ expect ( firstJsonOutput ( ) ?. inputs ) . toEqual ( [ { path : tempInput , mimeType : "image/jpeg" } ] ) ;
1313+ } ) ;
1314+
1315+ it ( "normalizes sniffed HEIF sequences to JPEG before gateway model probes" , async ( ) => {
1316+ const source = createIsomBrandBuffer ( "msf1" ) ;
1317+ const tempInput = path . join ( tempDirs . make ( "openclaw-model-run-heif-sequence-" ) , "opaque.bin" ) ;
1318+ await fs . writeFile ( tempInput , source ) ;
1319+
1320+ await runCapability (
1321+ "model" ,
1322+ "run" ,
1323+ "--prompt" ,
1324+ "describe this" ,
1325+ "--file" ,
1326+ tempInput ,
1327+ "--gateway" ,
1328+ "--json" ,
1329+ ) ;
1330+
1331+ expect ( mocks . convertHeicToJpeg ) . toHaveBeenCalledWith ( source ) ;
1332+ expect ( firstGatewayCall ( ) ?. params ?. attachments ) . toEqual ( [
1333+ {
1334+ type : "image" ,
1335+ fileName : "opaque.bin" ,
1336+ mimeType : "image/jpeg" ,
1337+ content : Buffer . from ( "jpeg-normalized" ) . toString ( "base64" ) ,
1338+ } ,
1339+ ] ) ;
1340+ expect ( firstJsonOutput ( ) ?. inputs ) . toEqual ( [ { path : tempInput , mimeType : "image/jpeg" } ] ) ;
1341+ } ) ;
1342+
12871343 it ( "rejects non-image files for model probes" , async ( ) => {
12881344 const tempInput = path . join ( os . tmpdir ( ) , `openclaw-model-run-audio-${ Date . now ( ) } .mp3` ) ;
12891345 await fs . writeFile ( tempInput , Buffer . from ( "not really audio" ) ) ;
0 commit comments