读图压缩加无收益守卫:JPEG 重编码变大时不落盘、外链直指原图
- executor.readImageAsBlocks:sharp 产物 >= 原图时跳过 .imgcache 落盘,image_rel 指向原文件(与浏览器端压缩同款守卫,截图/线稿等低内容熵图不再越压越大) - engine.mintImageUrl:image_rel 可能直指原文件后,签发公网链前补 realpath 复核(同 mint_public_link),防任务目录内指向外部的符号链接图片被签上公网 - smoke:vision 断言放宽为 image_rel 非空且文件存在(小尺寸测试图必然走无收益分支) - ARCHITECTURE:read_file 条目同步守卫与 realpath 复核说明
This commit is contained in:
+6
-6
@@ -130,8 +130,8 @@ async function main() {
|
||||
.map(m => { try { return JSON.parse(m.content); } catch (_) { return null; } })
|
||||
.find(j => j && Array.isArray(j.__blocks__));
|
||||
ok(!!imgTool && imgTool.__blocks__.some(b =>
|
||||
b.type === 'image_ref' && String(b.rel).startsWith('.imgcache/')),
|
||||
'tool 消息含压缩图的 image_ref 内容块(外链发送时现签,库里不存 base64)',
|
||||
b.type === 'image_ref' && String(b.rel || '').length > 0),
|
||||
'tool 消息含 image_ref 内容块(压缩产物或无收益直指原图;外链发送时现签,库里不存 base64)',
|
||||
imgTool ? JSON.stringify(imgTool.__blocks__.map(b => b.type)) : '无多模态块');
|
||||
const cacheInPanel = await api('GET', '/api/sessions/' + si.id + '/files');
|
||||
ok(!cacheInPanel.some(f => String(f.filename).startsWith('.imgcache/')), '.imgcache 不进前端文件列表');
|
||||
@@ -229,16 +229,16 @@ async function main() {
|
||||
ok(fpath.includes('g.txt'), 'find_path 命中', fpath);
|
||||
const esc = await executeTool(ctx, 'read_file', { path: '../outside.txt' }).catch(e => 'ERR:' + e.message);
|
||||
ok(String(esc).includes('越界'), 'read_file 拒绝越界', String(esc));
|
||||
// read_file 读图:非 vision → 文本提示;vision → {text, image_rel}(依赖 sharp,产物落 .imgcache/)
|
||||
// read_file 读图:非 vision → 文本提示;vision → {text, image_rel}(依赖 sharp;小图压缩无收益时 image_rel 直指原文件,不落 .imgcache)
|
||||
const unitPng = await require('sharp')({ create: { width: 4, height: 4, channels: 3, background: { r: 10, g: 120, b: 200 } } }).png().toBuffer();
|
||||
fs.writeFileSync(path.join(ctx.taskDir, 'pic.png'), unitPng);
|
||||
const imgNoVision = await executeTool(ctx, 'read_file', { path: 'pic.png' });
|
||||
ok(typeof imgNoVision === 'string' && imgNoVision.includes('不支持视觉识别'), 'read_file 非 vision 图片返回文本提示', String(imgNoVision).slice(0, 80));
|
||||
const ctxVision = Object.assign({}, ctx, { vision: true });
|
||||
const imgVision = await executeTool(ctxVision, 'read_file', { path: 'pic.png' });
|
||||
ok(imgVision && typeof imgVision === 'object' && String(imgVision.image_rel).startsWith('.imgcache/'),
|
||||
'read_file vision 图片返回压缩产物 image_rel', imgVision && imgVision.text ? String(imgVision.text).slice(0, 90) : String(imgVision).slice(0, 90));
|
||||
ok(fs.existsSync(path.join(ctx.taskDir, imgVision.image_rel)), '压缩产物已落盘 .imgcache/');
|
||||
ok(imgVision && typeof imgVision === 'object' && String(imgVision.image_rel).length > 0,
|
||||
'read_file vision 图片返回 image_rel(压缩产物或无收益原图)', imgVision && imgVision.text ? String(imgVision.text).slice(0, 90) : String(imgVision).slice(0, 90));
|
||||
ok(fs.existsSync(path.join(ctx.taskDir, imgVision.image_rel)), 'image_rel 指向的文件存在');
|
||||
|
||||
// ---- 8. 配置读写 API(阶段 2)----
|
||||
console.log('\n[8] 配置读写');
|
||||
|
||||
Reference in New Issue
Block a user