缺陷 / 高 / 工具系统
electron/harness/tools/registry.ts
工具定义中 timeoutMs 是可选字段。当工具未设置 timeoutMs 时,setTimeout(fn, undefined) 实际上等同于 setTimeout(fn, 0),导致:
timeoutMs
setTimeout(fn, undefined)
setTimeout(fn, 0)
// 修改前 const timer = setTimeout(() => reject(...), tool.timeoutMs); // 修改后 const timeout = tool.timeoutMs ?? this.defaultTimeoutMs ?? 120_000; if (typeof timeout !== 'number' || timeout <= 0) { throw new Error(`Invalid timeoutMs: ${tool.timeoutMs}`); } const timer = setTimeout(() => reject(...), timeout);
并在 ToolDef 类型定义时强制类型检查。
文件: electron/harness/tools/registry.ts
修复: 对 tool.definition.timeoutMs 添加类型与有效性校验(typeof === 'number' && > 0),无效时回退到默认值 120_000ms,防止 setTimeout(fn, undefined) 被解释为 setTimeout(fn, 0) 立即触发超时。
tool.definition.timeoutMs
typeof === 'number' && > 0
120_000ms
验证: tsc --noEmit 类型检查通过。
tsc --noEmit
No dependencies set.
The note is not visible to the blocked user.
问题类型
缺陷 / 高 / 工具系统
文件位置
electron/harness/tools/registry.ts问题描述
工具定义中
timeoutMs是可选字段。当工具未设置timeoutMs时,setTimeout(fn, undefined)实际上等同于setTimeout(fn, 0),导致:影响
建议修复
并在 ToolDef 类型定义时强制类型检查。
修复说明
文件:
electron/harness/tools/registry.ts修复: 对
tool.definition.timeoutMs添加类型与有效性校验(typeof === 'number' && > 0),无效时回退到默认值120_000ms,防止setTimeout(fn, undefined)被解释为setTimeout(fn, 0)立即触发超时。验证:
tsc --noEmit类型检查通过。