1ff1a9965b
- controller 删 `pendingUserItemId` / `beginTurnCommand` / `endTurnCommand`:忙态改由 `beginTurnBusy` / `endTurnBusy` 持有,宿主认领判据 = `turnRunning` 或收口计数变过(一轮在同一次 consume 里开始并结束) - controller 删 `startTurn` 的乐观追加与 `messageAppended` 重跑参数、`DirectProjectTurnInput.messageText` 与首轮的 `directInitialTurnText`;controller 不再需要 `assets` - 投影删 `awaiting-start` 展示态(只剩 `running` / `finished`)、`localSentTimes` / `sameIdentitySentAt`、本地用户气泡与它开回合的路径;带身份的拒单提示在会话末尾自成一组,不挂进上一轮,也不开运行态标记 - 时间口径:起点只认 `turn.started.at`、终点只认 `turn.completed.at`,用户气泡时钟取宿主落盘 / 观测时间;两边都空的回合整条「本轮结束于 … 」隐藏,不再出现 0.0 秒 - 用例:改造 `directTurnPresentation`(本地用户消息不进回合、拒单提示自成一组、两态判据、失败说明按身份归位)、`directProjectTurn` / `directProjectTurnStatus` / appSurface 窗口期用例,`directProjectTurn` 补 `afterEach(cleanup)` - 注释与文档:ADR「命令接单化」后续更新、实施计划新增「删掉本地乐观用户气泡」、decision-log 与 pitfalls 同日条目、Codex 原始历史方案的口径句、`codex_app_server` 用户条目时间注释
73 lines
2.6 KiB
TypeScript
73 lines
2.6 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { act, cleanup, renderHook, waitFor } from '@testing-library/react';
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import {
|
|
MAX_CHAT_COMPOSER_ATTACHMENTS,
|
|
useDirectProjectChatController,
|
|
} from '../src/view/project-development/chat/controller/useDirectProjectChatController';
|
|
import type { DirectCodexTurnAttachment } from '../src/view/project-development/chat/conversation/directCodexTurnAttachments';
|
|
|
|
// jsdom 的 Blob/File 没实现 `arrayBuffer`,而附件导入链路要按字节读文件。
|
|
if (typeof Blob.prototype.arrayBuffer !== 'function') {
|
|
Blob.prototype.arrayBuffer = () =>
|
|
Promise.resolve(new Uint8Array([120]).buffer);
|
|
}
|
|
|
|
function files(count: number, prefix: string) {
|
|
return Array.from(
|
|
{ length: count },
|
|
(_, index) =>
|
|
new File(['x'], `${prefix}-${index}.png`, { type: 'image/png' }),
|
|
);
|
|
}
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
vi.restoreAllMocks();
|
|
window.__TAURI__ = undefined;
|
|
});
|
|
|
|
describe('聊天输入盒的附件上限', () => {
|
|
it('并发导入也守得住上限:在飞的条数先占名额', async () => {
|
|
let uploadSeq = 0;
|
|
const invoke = vi.fn(async (command: string, args?: unknown) => {
|
|
if (command !== 'upload_local_asset') {
|
|
throw new Error(`unexpected invoke ${command}`);
|
|
}
|
|
const fileName = (args as { fileName?: string }).fileName ?? 'file';
|
|
return { localPath: `assets/upload-${(uploadSeq += 1)}-${fileName}` };
|
|
});
|
|
window.__TAURI__ = { core: { invoke: invoke as never } };
|
|
|
|
const { result } = renderHook(() =>
|
|
useDirectProjectChatController({
|
|
enabled: false,
|
|
ensureConversationReadAllowed: async () => true,
|
|
ensureConversationWriteAllowed: async () => true,
|
|
onRuntimeError: () => undefined,
|
|
projectId: 'project-1',
|
|
projectPath: 'C:/project',
|
|
refreshManifest: () => undefined,
|
|
}),
|
|
);
|
|
|
|
// 两次并发导入各带 5 个文件:第一次占住 5 个名额,第二次只剩 3 个名额。
|
|
const imported: DirectCodexTurnAttachment[][] = [[], []];
|
|
await act(async () => {
|
|
const first = result.current.uploadFiles(files(5, 'first'), 0);
|
|
const second = result.current.uploadFiles(files(5, 'second'), 0);
|
|
[imported[0], imported[1]] = await Promise.all([first, second]);
|
|
});
|
|
|
|
await waitFor(() => {
|
|
expect(result.current.attachmentsImporting).toBe(false);
|
|
});
|
|
expect(imported[0]).toHaveLength(5);
|
|
expect(imported[1]).toHaveLength(3);
|
|
expect(imported[0].length + imported[1].length).toBe(
|
|
MAX_CHAT_COMPOSER_ATTACHMENTS,
|
|
);
|
|
});
|
|
});
|