25c5ecdf6e
Project CI / AI game creator shell Rust crates (pull_request) Successful in 2m58s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 6m34s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 5m29s
Project CI / Backend tests (pull_request) Failing after 4m38s
Project CI / Frontend tests (pull_request) Successful in 3m33s
Project CI / Repository checks (pull_request) Failing after 4m4s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m13s
Project CI / Native shell tests (pull_request) Successful in 6m35s
- 78 处内联 window.__TAURI__ 赋值改为 installTauriRuntime,覆盖 appSurface 之外的 37 个测试文件 - 31 处 delete window.__TAURI__ / window.__TAURI__ = undefined 复位改为 resetTauriRuntime - 删除 recentProjectsHook、projectCreationDirectory、projectResourceLiveIntegration、useProjectResourceCardPreviews、resourceVersionReplacementModel、unityProjectOpen 里的本地 asTauriInvoke / asTauriListen 适配器与相关类型别名 - designProjectRestore 的 setup 参数由 ReturnType<typeof vi.fn> 收窄为具体 invoke 签名 - 迁移后仅 tests/tauriRuntimeFake.ts 直接读写 window.__TAURI__
74 lines
2.6 KiB
TypeScript
74 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';
|
|
import { installTauriRuntime, resetTauriRuntime } from './tauriRuntimeFake';
|
|
|
|
// 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();
|
|
resetTauriRuntime();
|
|
});
|
|
|
|
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}` };
|
|
});
|
|
installTauriRuntime({ core: { invoke } });
|
|
|
|
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,
|
|
);
|
|
});
|
|
});
|