Files
clawpanel/tests/assistant-media-tools.test.js
晴天 b04deb4e54 fix(release): 0.18.6 收口——审查修复、创作中心与便携迁移加固、设置页提速
按全量代码审查(8 角度 × 对抗验证)修复 10 项确认问题并完成收口:

安全:
- 媒体资产下载仅对与服务商 Base URL 同主机的地址携带 API Key,防止密钥外泄
- 助手媒体工具默认关闭需显式开启;付费图片/视频生成在任何模式下强制确认

数据与容错:
- 媒体数据统一存放 openclaw 数据目录下,便携迁移后配置与历史直接生效
- 视频轮询 429/5xx 瞬时错误不再永久标记失败;失败任务可重新轮询找回
- 创建视频任务无法识别任务 ID 时保留任务记录与原始响应(可能已计费)
- 便携迁移失败时正确显示错误状态;便携命令加入 Web 模式 ALWAYS_LOCAL

性能与体验:
- 任务记录落盘前裁剪 base64 等超大字段,媒体历史文件不再膨胀
- 资产预览 stat 预检 + 64MB 上限 + 缓存淘汰;轮询并行化(后端 jobs 加锁)
- 初始设置页两阶段渲染:本地检测先出首屏,版本网络查询异步补充
- 创作中心删除改用统一确认弹窗(原生 confirm 在 macOS WebView 失效)
- 检查配置/获取模型列表放行 http:// 自建网关;桌面/Web 状态解析对齐
- 统一三处路径包含检查为 utils 共享 helper(Linux 大小写误判修复)
- 补充便携模式 hermes-cli-missing 警告翻译(简/繁/英)

其他:修复 web-headless-reload-policy 陈旧断言(e16ff2b 后 ws-client 已无隐式 reload)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-05 11:43:33 -07:00

32 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
const source = readFileSync(new URL('../src/pages/assistant.js', import.meta.url), 'utf8')
test('晴辰助手注册媒体生成工具组并受设置开关控制', () => {
assert.match(source, /media:\s*\[/, 'TOOL_DEFS 必须包含 media 工具组')
assert.match(source, /tc\.media\s*===\s*true/, '媒体工具必须显式开启(默认关闭,老配置缺省视为关闭)')
assert.doesNotMatch(source, /media:\s*true\s*\}/, '默认配置不得默认开启媒体工具')
assert.match(source, /id="ast-tool-media"/, '助手工具设置页必须提供媒体生成开关')
})
test('晴辰助手媒体工具调用复用媒体中心 API', () => {
for (const name of ['get_media_config', 'generate_image', 'create_video_task', 'poll_video_task', 'list_media_jobs']) {
assert.match(source, new RegExp(`case ['"]${name}['"]`), `executeTool 缺少 ${name}`)
}
assert.match(source, /api\.readMediaConfig\(\)/, 'get_media_config 应复用媒体中心配置')
assert.match(source, /api\.generateImage\(/, 'generate_image 应复用媒体中心图片生成 API')
assert.match(source, /api\.createVideoTask\(/, 'create_video_task 应复用媒体中心视频任务 API')
assert.match(source, /api\.pollVideoTask\(/, 'poll_video_task 应复用媒体中心视频轮询 API')
assert.match(source, /api\.listMediaJobs\(/, 'list_media_jobs 应复用媒体中心历史任务 API')
})
test('晴辰助手将会产生费用的媒体生成工具纳入确认流程', () => {
assert.match(source, /DANGEROUS_TOOLS[\s\S]*generate_image/, '图片生成应进入确认流程')
assert.match(source, /DANGEROUS_TOOLS[\s\S]*create_video_task/, '视频生成应进入确认流程')
// 付费生成必须无条件确认,不受 confirmDanger无限制模式开关影响
assert.match(source, /isPaidMedia\s*=\s*toolName\s*===\s*'generate_image'\s*\|\|\s*toolName\s*===\s*'create_video_task'/, '付费媒体工具必须有独立的无条件确认分支')
assert.match(source, /else if \(isPaidMedia\)/, '付费媒体确认分支必须先于 confirmDanger 模式判断')
})