8701f43f75
- 删除渲染层传输层:services/clientApi.ts、clientHttp 的 fetchClientHttp 与超时封装整体退场,账户、认证、素材直传、错误上报与游戏分发发布改走 Rust typed command。 - 新增宿主封装:accountHost、editorAssetHost、platformSessionRetry、agentRuntimeErrorDetail 与 features/app-shell/workspacePreferences;渲染层不再读写 access token / refresh cookie,localStorage 只剩测试态旧键迁移 shim。 - 修复 DirectProject 失败文案 v2 映射与「查看详情」按需读取,画布标签面板高度夹紧、框选每帧重算、文档预览入口与场景标题栏 key、资源筛选面板样式。 - 补齐与调整回归:accountHost、agentRuntimeErrorDetail、clientAuthHost、clientHttp、platformSession、platformSessionRetry、resourceFilterPanelStyle、directThreadChatSubscription 等定向用例,并清理测试 harness 中无调用方的残留。
110 lines
3.2 KiB
TypeScript
110 lines
3.2 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { act, cleanup, renderHook, waitFor } from '@testing-library/react';
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { useDirectThreadChatSubscription } from '../src/view/project-development/chat/controller/useDirectThreadChatSubscription';
|
|
import { createTauriEventFake, type TauriEventFake } from './tauriEventFake';
|
|
|
|
const BOOTSTRAP = {
|
|
subscriptionId: 'direct-subscription-1',
|
|
lastCompletedItemId: null,
|
|
events: [],
|
|
};
|
|
|
|
let eventFake: TauriEventFake | null = null;
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
eventFake?.restore();
|
|
eventFake = null;
|
|
delete window.__TAURI__;
|
|
delete window.__TAURI_INTERNALS__;
|
|
});
|
|
|
|
function installEventFake(
|
|
invoke: (command: string, args?: Record<string, unknown>) => Promise<unknown>,
|
|
) {
|
|
eventFake = createTauriEventFake({ invoke });
|
|
eventFake.install();
|
|
return eventFake;
|
|
}
|
|
|
|
describe('useDirectThreadChatSubscription', () => {
|
|
it('卸载时幂等注销 native subscriber', async () => {
|
|
const unsubscribeCalls: Record<string, unknown>[] = [];
|
|
const invoke = vi.fn(
|
|
async (command: string, args?: Record<string, unknown>) => {
|
|
if (command === 'subscribe_direct_project_thread') return BOOTSTRAP;
|
|
if (command === 'consume_direct_project_thread') return { events: [] };
|
|
if (command === 'unsubscribe_direct_project_thread') {
|
|
unsubscribeCalls.push(args ?? {});
|
|
}
|
|
return null;
|
|
},
|
|
);
|
|
installEventFake(invoke);
|
|
|
|
const { unmount } = renderHook(() =>
|
|
useDirectThreadChatSubscription({
|
|
enabled: true,
|
|
projectPath: 'C:/projects/demo',
|
|
}),
|
|
);
|
|
await waitFor(() =>
|
|
expect(invoke).toHaveBeenCalledWith('subscribe_direct_project_thread', {
|
|
projectPath: 'C:/projects/demo',
|
|
}),
|
|
);
|
|
|
|
unmount();
|
|
await act(async () => {
|
|
await Promise.resolve();
|
|
});
|
|
|
|
expect(unsubscribeCalls).toEqual([
|
|
{ subscriptionId: BOOTSTRAP.subscriptionId },
|
|
]);
|
|
});
|
|
|
|
it('bootstrap 迟到于卸载时仍注销已登记的 native subscriber', async () => {
|
|
let resolveBootstrap!: (value: typeof BOOTSTRAP) => void;
|
|
const unsubscribeCalls: Record<string, unknown>[] = [];
|
|
const invoke = vi.fn(
|
|
async (command: string, args?: Record<string, unknown>) => {
|
|
if (command === 'subscribe_direct_project_thread') {
|
|
return new Promise<typeof BOOTSTRAP>((resolve) => {
|
|
resolveBootstrap = resolve;
|
|
});
|
|
}
|
|
if (command === 'unsubscribe_direct_project_thread') {
|
|
unsubscribeCalls.push(args ?? {});
|
|
}
|
|
return { events: [] };
|
|
},
|
|
);
|
|
installEventFake(invoke);
|
|
|
|
const { unmount } = renderHook(() =>
|
|
useDirectThreadChatSubscription({
|
|
enabled: true,
|
|
projectPath: 'C:/projects/demo',
|
|
}),
|
|
);
|
|
await waitFor(() =>
|
|
expect(invoke).toHaveBeenCalledWith('subscribe_direct_project_thread', {
|
|
projectPath: 'C:/projects/demo',
|
|
}),
|
|
);
|
|
|
|
unmount();
|
|
await act(async () => {
|
|
resolveBootstrap(BOOTSTRAP);
|
|
await Promise.resolve();
|
|
});
|
|
|
|
expect(unsubscribeCalls).toEqual([
|
|
{ subscriptionId: BOOTSTRAP.subscriptionId },
|
|
]);
|
|
});
|
|
});
|