移除了所有Hermes相关的命名引用,包括: - 从.gitignore中清理相关构建缓存文件 - 将README中的beaver-home路径配置更新 - 完善backend/README.md文档说明Beaver后端主线实现 - 移除Hermes风格的相关注释和兼容性代码 - 清理nanobot环境变量兼容性处理 - 删除技能迁移和服务迁移相关功能代码 - 更新测试用例中相关命名和函数名 BREAKING CHANGE: 移除了Hermes迁移相关API和CLI命令,不再支持nanobot环境变量兼容性
164 lines
4.6 KiB
TypeScript
164 lines
4.6 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { buildTaskRuntimeView } from '@/lib/task-runtime';
|
|
import type { ProcessArtifact, ProcessEvent, ProcessRun, Session } from '@/types';
|
|
|
|
describe('runtime view builders', () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
vi.setSystemTime(new Date('2026-03-24T12:00:00.000Z'));
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it('builds a runtime view from a root run tree', () => {
|
|
const sessions: Session[] = [
|
|
{
|
|
key: 'web:default',
|
|
path: '需求讨论',
|
|
created_at: '2026-03-24T09:55:00.000Z',
|
|
updated_at: '2026-03-24T10:10:00.000Z',
|
|
},
|
|
];
|
|
|
|
const processRuns: ProcessRun[] = [
|
|
{
|
|
run_id: 'run-root',
|
|
parent_run_id: null,
|
|
session_id: 'web:default',
|
|
actor_type: 'agent',
|
|
actor_id: 'main-agent',
|
|
actor_name: '主 Agent',
|
|
title: '整理竞品研究并给出结论',
|
|
status: 'running',
|
|
started_at: '2026-03-24T10:00:00.000Z',
|
|
metadata: {
|
|
stage_label: '分析结果',
|
|
},
|
|
},
|
|
{
|
|
run_id: 'run-sub-agent',
|
|
parent_run_id: 'run-root',
|
|
session_id: 'web:default',
|
|
actor_type: 'agent',
|
|
actor_id: 'research-agent',
|
|
actor_name: 'Research Agent',
|
|
title: '收集竞品资料',
|
|
status: 'done',
|
|
started_at: '2026-03-24T10:01:00.000Z',
|
|
finished_at: '2026-03-24T10:04:00.000Z',
|
|
summary: '已完成资料收集',
|
|
},
|
|
{
|
|
run_id: 'run-sub-mcp',
|
|
parent_run_id: 'run-root',
|
|
session_id: 'web:default',
|
|
actor_type: 'mcp',
|
|
actor_id: 'search-mcp',
|
|
actor_name: 'Search MCP',
|
|
title: '抓取公开资料',
|
|
status: 'running',
|
|
started_at: '2026-03-24T10:02:00.000Z',
|
|
},
|
|
];
|
|
|
|
const processEvents: ProcessEvent[] = [
|
|
{
|
|
event_id: 'evt-1',
|
|
run_id: 'run-root',
|
|
parent_run_id: null,
|
|
kind: 'run_progress',
|
|
actor_type: 'agent',
|
|
actor_id: 'main-agent',
|
|
actor_name: '主 Agent',
|
|
text: '开始归纳公开信息',
|
|
created_at: '2026-03-24T10:03:00.000Z',
|
|
metadata: {
|
|
stage_label: '分析结果',
|
|
},
|
|
},
|
|
{
|
|
event_id: 'evt-2',
|
|
run_id: 'run-sub-agent',
|
|
parent_run_id: 'run-root',
|
|
kind: 'run_finished',
|
|
actor_type: 'agent',
|
|
actor_id: 'research-agent',
|
|
actor_name: 'Research Agent',
|
|
text: '资料整理完成',
|
|
status: 'done',
|
|
created_at: '2026-03-24T10:04:00.000Z',
|
|
},
|
|
{
|
|
event_id: 'evt-3',
|
|
run_id: 'run-sub-mcp',
|
|
parent_run_id: 'run-root',
|
|
kind: 'run_progress',
|
|
actor_type: 'mcp',
|
|
actor_id: 'search-mcp',
|
|
actor_name: 'Search MCP',
|
|
text: '正在搜索公开网页',
|
|
created_at: '2026-03-24T10:05:00.000Z',
|
|
},
|
|
];
|
|
|
|
const processArtifacts: ProcessArtifact[] = [
|
|
{
|
|
artifact_id: 'artifact-1',
|
|
run_id: 'run-sub-agent',
|
|
actor_type: 'agent',
|
|
actor_id: 'research-agent',
|
|
actor_name: 'Research Agent',
|
|
title: '竞品清单',
|
|
artifact_type: 'markdown',
|
|
content: '- A\n- B',
|
|
created_at: '2026-03-24T10:04:30.000Z',
|
|
},
|
|
];
|
|
|
|
const runtime = buildTaskRuntimeView('run-root', {
|
|
sessions,
|
|
processRuns,
|
|
processEvents,
|
|
processArtifacts,
|
|
});
|
|
|
|
expect(runtime).not.toBeNull();
|
|
expect(runtime?.taskId).toBe('run-root');
|
|
expect(runtime?.title).toBe('整理竞品研究并给出结论');
|
|
expect(runtime?.sourceSessionLabel).toBe('需求讨论');
|
|
expect(runtime?.tasks).toHaveLength(3);
|
|
expect(runtime?.progress.label).toBe('已完成子任务 1 / 3');
|
|
expect(runtime?.stats.artifactCount).toBe(1);
|
|
expect(runtime?.stats.alertCount).toBe(0);
|
|
});
|
|
|
|
it('marks stale waiting tasks as blocked and emits alerts', () => {
|
|
const processRuns: ProcessRun[] = [
|
|
{
|
|
run_id: 'run-blocked',
|
|
parent_run_id: null,
|
|
session_id: 'web:default',
|
|
actor_type: 'agent',
|
|
actor_id: 'main-agent',
|
|
actor_name: '主 Agent',
|
|
title: '等待下游结果',
|
|
status: 'waiting',
|
|
started_at: '2026-03-24T09:00:00.000Z',
|
|
},
|
|
];
|
|
|
|
const runtime = buildTaskRuntimeView('run-blocked', {
|
|
sessions: [],
|
|
processRuns,
|
|
processEvents: [],
|
|
processArtifacts: [],
|
|
});
|
|
|
|
expect(runtime?.status).toBe('blocked');
|
|
expect(runtime?.stats.alertCount).toBe(1);
|
|
});
|
|
});
|