scripts / multi-image-arguments-smoke.cjs

const assert=require('node:assert/strict');
const {parseMultiImageNames}=require('../dist/multiImageArgs');
const {toolsProvider}=require('../dist/toolsProvider');
(async()=>{
 const paths=['aia-attachments/hash/画像,1.png','nested/image 2.jpg'];
 assert.deepEqual(parseMultiImageNames(paths).images,paths);
 assert.deepEqual(parseMultiImageNames(JSON.stringify(paths)).images,paths);
 const invalid=['a.png,b.png','a.png\nb.png',"['a.png','b.png']",'null','{}','[]','["a"]','["a","b","c","d","e"]','[1,2]','["a",null]','["a",""]','["a","   "]'];
 for(const value of invalid)assert.ok(parseMultiImageNames(value).error);
 let touched=0;
 const multi=(await toolsProvider({getWorkingDirectory(){touched++;throw new Error('must not read images');}}))[3];
 const ctx={signal:new AbortController().signal,status(){},warn(){},callId:1};
 multi.checkParameters({imageNames:JSON.stringify(paths),prompt:'compare',verificationToken:'a'.repeat(32)});
 for(const value of invalid){
  const result=await multi.implementation({imageNames:value,prompt:'compare'},ctx);
  assert.equal(result.error,'invalid_image_names');assert.match(result.retry,/actual JSON array/);
 }
 assert.equal(touched,0,'malformed strings must return a retryable error before any image access/inference');
 assert.throws(()=>multi.checkParameters({imageNames:['one.png'],prompt:'compare'}));
 console.log('PASS: actual/JSON-encoded image-name arrays preserve exact paths; ambiguous strings, nonstrings and invalid counts are not guessed; compatibility errors return retry instructions before file access.');
})().catch(error=>{console.error(error);process.exitCode=1;});