Files
Genarrative/apps/ai-game-creator-shell/tests/agentRuntimeErrorDetail.test.ts
T
kdletters 8701f43f75 AGC 渲染层网络与状态下沉 Rust,并修复画布交互与失败文案
- 删除渲染层传输层:services/clientApi.ts、clientHttp 的 fetchClientHttp 与超时封装整体退场,账户、认证、素材直传、错误上报与游戏分发发布改走 Rust typed command。
- 新增宿主封装:accountHost、editorAssetHost、platformSessionRetry、agentRuntimeErrorDetail 与 features/app-shell/workspacePreferences;渲染层不再读写 access token / refresh cookie,localStorage 只剩测试态旧键迁移 shim。
- 修复 DirectProject 失败文案 v2 映射与「查看详情」按需读取,画布标签面板高度夹紧、框选每帧重算、文档预览入口与场景标题栏 key、资源筛选面板样式。
- 补齐与调整回归:accountHost、agentRuntimeErrorDetail、clientAuthHost、clientHttp、platformSession、platformSessionRetry、resourceFilterPanelStyle、directThreadChatSubscription 等定向用例,并清理测试 harness 中无调用方的残留。
2026-09-28 14:15:02 +08:00

84 lines
3.0 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import {
AGENT_RUNTIME_ERROR_DETAIL_MARKER,
extractAgentRuntimeErrorDetailRef,
readAgentRuntimeErrorDetailByRef,
} from '../src/services/agentRuntimeErrorDetail';
/**
* Rust 侧 `record_direct_codex_turn_failure` 现产出的失败文案形状。
*
* 这里的形状由 `direct_codex_failure_text_keeps_the_detail_ref_marker_for_the_renderer`
* 在同一份文案上钉住;两边同时改才算一次协议变更。
*/
const RUST_FAILURE_TEXT =
'direct-codex-failure:v2 stage=code-generation code=runtime-failure retryable=false ' +
'summary=构建失败:入口模块语法错误;建议:修复 game/src 下的语法错误后重新发送需求;' +
'已保存脱敏项目诊断;详情:.agent/runtime/errors/0192f0a1-7f4c-7c31-9d5c-4a51c6b4b9e2.json';
describe('统一错误诊断引用解析', () => {
it('从真实失败文案里取出诊断引用', () => {
expect(extractAgentRuntimeErrorDetailRef(RUST_FAILURE_TEXT)).toBe(
'.agent/runtime/errors/0192f0a1-7f4c-7c31-9d5c-4a51c6b4b9e2.json',
);
});
it('标记与引用必须同时成立,缺一不解析', () => {
expect(AGENT_RUNTIME_ERROR_DETAIL_MARKER).toBe('详情:');
expect(
extractAgentRuntimeErrorDetailRef(
'summary=失败;建议:重试;详情:.agent/runtime/errors/turn-1',
),
).toBeNull();
expect(
extractAgentRuntimeErrorDetailRef(
'summary=构建失败;建议:修复后重试;已保存脱敏项目诊断',
),
).toBeNull();
expect(
extractAgentRuntimeErrorDetailRef(
'详情:.agent/runtime/errors/turn-1.json;建议:重试',
),
).toBe('.agent/runtime/errors/turn-1.json');
});
it('读诊断失败只回落安全文案,不抛出', async () => {
const declined = vi.fn(async () => {
throw new Error('错误诊断引用格式无效');
});
await expect(
readAgentRuntimeErrorDetailByRef(
declined,
'F:/project',
'.agent/runtime/errors/error-1700000000000-1.json',
),
).resolves.toBe('');
const unavailable = vi.fn(async () => {
throw new Error('命令未注册');
});
// 没有引用时连命令都不发:这里用空串代表面板拿不到引用的情形。
await expect(
readAgentRuntimeErrorDetailByRef(unavailable, 'F:/project', ''),
).resolves.toBe('');
expect(unavailable).not.toHaveBeenCalled();
});
it('按项目路径与引用调用只读命令', async () => {
const invoke = vi.fn(async () => '{"code":"runtime-failure"}');
await expect(
readAgentRuntimeErrorDetailByRef(
invoke,
'F:/project',
extractAgentRuntimeErrorDetailRef(RUST_FAILURE_TEXT) ?? '',
),
).resolves.toBe('{"code":"runtime-failure"}');
expect(invoke).toHaveBeenCalledWith('read_agent_runtime_error_detail', {
projectPath: 'F:/project',
detailRef:
'.agent/runtime/errors/0192f0a1-7f4c-7c31-9d5c-4a51c6b4b9e2.json',
});
});
});