Files
Genarrative/apps/ai-game-creator-shell/tests/rememberCommand.test.ts
T
k88936 0224ef7b9d 删除 Project Supervisor 聊天遗留的 pendingCommand 死链
- 删除 App.tsx 里 pendingCommand 状态、确认/取消处理与 21 个 execute* 分发分支
- 删除随该链路一起不可达的 21 个 execute* 实现与 requireChatProjectForUserAction
- 删除只服务该链路的 PendingCommand 类型、pendingCommandPresentation.ts 与 resolvePendingCommandProjectPath
- PlanningChatView 去掉 pendingCommand 面板相关 props、渲染分支与导入
- rememberCommand.test.ts 只保留现役 helper(path/remember/needsInitializedChatProject/agent 卡片)的用例
2026-09-21 11:15:02 +08:00

150 lines
5.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
createGameCreationAppManifest,
GAME_CREATION_AGENT_RUN_SCHEMA_VERSION,
type GameCreationAgentRunTrace,
} from '../../../packages/shared/src/contracts/gameCreationApp';
import {
deriveAgentStatusCards,
isAbsoluteProjectPath,
needsInitializedChatProject,
parseRememberInput,
resolveChatProjectPath,
} from '../src/App';
describe('AI 游戏创作聊天记忆命令', () => {
it('recognizes local project absolute paths across desktop platforms', () => {
expect(isAbsoluteProjectPath('/tmp/game')).toBe(true);
expect(isAbsoluteProjectPath('C:\\Games\\demo')).toBe(true);
expect(isAbsoluteProjectPath('D:/Games/demo')).toBe(true);
expect(isAbsoluteProjectPath('relative-game')).toBe(false);
});
it('defaults /remember to long memory and supports short and blackboard scopes', () => {
expect(parseRememberInput('主角喜欢反弹弹幕')).toEqual({
scope: 'long',
content: '主角喜欢反弹弹幕',
});
expect(parseRememberInput('short 本轮先修输入手感')).toEqual({
scope: 'short',
content: '本轮先修输入手感',
});
expect(parseRememberInput('长期 保留厨房主题')).toEqual({
scope: 'long',
content: '保留厨房主题',
});
expect(parseRememberInput('project 覆盖后的长期设定')).toEqual({
scope: 'long',
content: '覆盖后的长期设定',
});
expect(parseRememberInput('blackboard 共享美术约束')).toEqual({
scope: 'blackboard',
content: '共享美术约束',
});
expect(parseRememberInput('黑板 统一使用俯视角')).toEqual({
scope: 'blackboard',
content: '统一使用俯视角',
});
});
it('requires an initialized local project path before chat memory commands', () => {
expect(resolveChatProjectPath(null)).toBeNull();
expect(resolveChatProjectPath({ projectPath: '/tmp/game' })).toBe(
'/tmp/game',
);
expect(resolveChatProjectPath({ projectPath: 'relative-game' })).toBeNull();
expect(
resolveChatProjectPath({ projectPath: '/tmp/bad\u0007game' }),
).toBeNull();
expect(parseRememberInput('long')).toEqual({
scope: 'long',
content: '',
});
expect(parseRememberInput('short 覆盖本轮上下文')).toEqual({
scope: 'short',
content: '覆盖本轮上下文',
});
});
it('requires a project before chat commands write or run local artifacts', () => {
expect(needsInitializedChatProject('game.generate_draft')).toBe(true);
expect(needsInitializedChatProject('asset.upload')).toBe(true);
expect(needsInitializedChatProject('agent.kill')).toBe(true);
expect(needsInitializedChatProject('agent.retry')).toBe(true);
expect(needsInitializedChatProject('agent.resume')).toBe(true);
expect(needsInitializedChatProject('command.run_limited')).toBe(true);
expect(needsInitializedChatProject('preview.open')).toBe(true);
expect(needsInitializedChatProject('preview.start')).toBe(true);
expect(needsInitializedChatProject('canvas.project_sync')).toBe(true);
expect(needsInitializedChatProject('canvas.export_import')).toBe(true);
expect(needsInitializedChatProject('memory.write')).toBe(true);
expect(needsInitializedChatProject('memory.delete')).toBe(true);
expect(needsInitializedChatProject('project.checkpoint')).toBe(true);
expect(needsInitializedChatProject('project.restore')).toBe(true);
expect(needsInitializedChatProject('project.policy_write')).toBe(true);
expect(needsInitializedChatProject('project.create')).toBe(false);
expect(needsInitializedChatProject('canvas.project_open')).toBe(false);
});
it('derives per-agent status cards from manifest and latest trace steps', () => {
const manifest = createGameCreationAppManifest(
'local-project-draft',
'未命名游戏原型',
);
const trace = {
schemaVersion: GAME_CREATION_AGENT_RUN_SCHEMA_VERSION,
runId: 'run-agent-status',
commandId: 'game.generate_draft',
status: 'passed',
passes: 1,
maxPasses: 3,
toolCallCount: 1,
maxToolCalls: 128,
stopReason: 'evaluator-passed',
goal: '像素动作',
coordination: 'filesystem',
steps: [
{
pass: 1,
agent: 'Planner',
phase: 'plan',
taskId: 'design-director',
group: 'design',
role: 'Director',
status: 'completed',
inputPaths: [],
outputPaths: ['.agent/spec.md'],
summary: '拆解完成',
toolCalls: [],
},
],
artifacts: [],
taskGraph: {
goal: '像素动作',
readyTaskIds: [],
activeTaskIds: [],
carriedTaskIds: [],
repairFocus: [],
repairRoutes: [],
tasks: manifest.tasks,
},
passPlans: [],
nextStep: 'manual-playtest',
error: null,
updatedAt: 1,
} satisfies GameCreationAgentRunTrace;
const traced = deriveAgentStatusCards(manifest, trace);
expect(traced[0]).toMatchObject({
id: 'design-director',
title: '拆解创作方向',
status: 'completed',
summary: '拆解完成',
});
const fallback = deriveAgentStatusCards(manifest, null);
expect(fallback[0]?.summary).toBe('创作目标、范围和专业组分工明确');
});
});