fix: 修复 Chrome 90 智能体文档上传失败
- 复用兼容 UUID 生成逻辑,移除对 crypto.randomUUID 的依赖 - 补充旧浏览器缺失 randomUUID 时的上传回归测试
This commit is contained in:
@@ -16,6 +16,7 @@ vi.mock('./mediaApi', () => mediaApi);
|
||||
describe('useChatDocumentUploads', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
vi.unstubAllGlobals();
|
||||
Object.values(mediaApi).forEach((mock) => mock.mockReset());
|
||||
});
|
||||
|
||||
@@ -68,6 +69,44 @@ describe('useChatDocumentUploads', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('uses getRandomValues when randomUUID is unavailable', async () => {
|
||||
const getRandomValues = vi.fn((values: Uint8Array) => {
|
||||
values.fill(171);
|
||||
return values;
|
||||
});
|
||||
vi.stubGlobal('crypto', { getRandomValues });
|
||||
mediaApi.uploadAgentChatDocument.mockImplementation(
|
||||
async (file, _context, uploadId) => ({
|
||||
data: {
|
||||
attachmentRef: 'document:chrome-90',
|
||||
mimeType: file.type,
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
status: 'READY',
|
||||
uploadId,
|
||||
},
|
||||
errorCode: 0,
|
||||
}),
|
||||
);
|
||||
|
||||
const uploads = useChatDocumentUploads();
|
||||
await uploads.addFiles(
|
||||
[new File(['document'], 'chrome-90.pdf', { type: 'application/pdf' })],
|
||||
{ agentId: 'agent-1', mode: 'FORMAL', sessionId: 'session-1' },
|
||||
);
|
||||
|
||||
expect(getRandomValues).toHaveBeenCalled();
|
||||
expect(mediaApi.uploadAgentChatDocument).toHaveBeenCalledWith(
|
||||
expect.any(File),
|
||||
{ agentId: 'agent-1', mode: 'FORMAL', sessionId: 'session-1' },
|
||||
expect.stringMatching(/^[a-f0-9]{32}$/),
|
||||
);
|
||||
expect(uploads.items.value[0]).toMatchObject({
|
||||
status: 'ready',
|
||||
uploadId: expect.stringMatching(/^[a-f0-9]{32}$/),
|
||||
});
|
||||
});
|
||||
|
||||
it('exposes a server read failure without continuing to poll', async () => {
|
||||
mediaApi.uploadAgentChatDocument.mockResolvedValue({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user