Files
Genarrative/apps/ai-game-creator-shell/tests/clientOperation.test.ts
T
kdletters 21efc4cdc4 建立 AGC 稳定版生命周期基础合同
新增 ClientOperation 状态、身份和 stale-result 规则

让认证 refresh 与首页创建记录统一 operation phase 和 scope

为 dev-stack 与 AGC Vite marker 增加工作树和实例身份门禁

补充稳定版切换主规范、里程碑计划和开发运维踩坑文档
2026-09-14 12:50:51 +08:00

43 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
cancelClientOperation,
clientOperationCanRetry,
createClientOperation,
isCurrentClientOperation,
transitionClientOperation,
} from '../src/services/clientOperation';
describe('AGC client operation contract', () => {
it('keeps operation/request identity and deadline across phase transitions', () => {
const operation = createClientOperation(
'home-create',
{ prompt: '做一个游戏' },
{ scope: { projectPath: 'C:\\games\\demo' }, deadlineMs: 15_000 },
);
const network = transitionClientOperation(operation, 'network');
const project = transitionClientOperation(network, 'project', {
scope: { projectPath: 'C:\\games\\created' },
});
expect(project.operationId).toBe(operation.operationId);
expect(project.requestId).toBe(operation.requestId);
expect(project.deadlineAt).toBe(operation.startedAt + 15_000);
expect(project.scope.projectPath).toBe('C:\\games\\created');
expect(project.cancellable).toBe(true);
expect(isCurrentClientOperation(project, operation.operationId)).toBe(true);
});
it('marks cancellation as stale and does not make it retryable', () => {
const operation = createClientOperation('auth-refresh', null);
const failed = transitionClientOperation(operation, 'retryable-failure');
expect(clientOperationCanRetry(failed)).toBe(true);
const cancelled = cancelClientOperation(failed);
expect(cancelled.cancelled).toBe(true);
expect(isCurrentClientOperation(cancelled, operation.operationId)).toBe(
false,
);
expect(clientOperationCanRetry(cancelled)).toBe(false);
});
});