Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
merge: 同步主干并保留附件恢复与图片预览测试
Dashca294fdadef1
diff --cc apps/mobile/app/sessions/new.tsxindex 9967ee3bdf,542c175089..e57134285a--- a/apps/mobile/app/sessions/new.tsx+++ b/apps/mobile/app/sessions/new.tsx@@@ -911,8 -919,8 +914,9 @@@ export default function NewRemoteSessiodiscardAllPendingUploads,waitForPendingUploads,getPendingUploadCount,+ hasAttachmentInput,getUploadedSource,+ getUploadedAttachmentId,releaseUploadedSources,} = useMobileLocalAttachments({getAccessToken: () => auth.getAccessToken(),diff --cc apps/mobile/src/__tests__/useMobileLocalAttachmentsAbandon.test.tsxindex 7a1afe5e91,dcd8f56cff..95e78a2234--- a/apps/mobile/src/__tests__/useMobileLocalAttachmentsAbandon.test.tsx+++ b/apps/mobile/src/__tests__/useMobileLocalAttachmentsAbandon.test.tsx@@@ -13,8 -14,7 +14,9 @@@ const runtime = vi.hoisted(() => (uploads: [] as Array<{ name: string; resolve: () => void }>,discarded: [] as unknown[],pickPhotos: vi.fn(),+ pickCamera: vi.fn(),+ pickDocument: vi.fn(),+ durablePreviewUri: null as string | null,}));vi.mock('react-native', () => ({ Platform: { OS: 'ios' } }));@@@ -65,8 -61,7 +67,9 @@@ beforeEach(() =>runtime.uploads = [];runtime.discarded = [];runtime.pickPhotos.mockReset();+ runtime.pickCamera.mockReset();+ runtime.pickDocument.mockReset();+ runtime.durablePreviewUri = null;root = createRoot(document.createElement('div'));});afterEach(() => act(() => root.unmount()));@@@ -105,17 -107,89 +115,101 @@@ const imageCandidate = (name: string, oconst flush = () => new Promise((resolve) => { setTimeout(resolve, 0); });describe('useMobileLocalAttachments abandonment on scope change', () => {+ it.each(['paste', 'upload'])('reports %s input synchronously before React commits the tray', async kind => {+ const harness = mount('session-a');+ expect(harness.first.hasAttachmentInput()).toBe(false);+ act(() => {+ if (kind === 'paste') harness.first.beginPastePlaceholders(1);+ else harness.first.enqueueUploads([imageCandidate('a.png', vi.fn())], { token: 'token' });+ expect(harness.first.hasAttachmentInput()).toBe(true);+ });+ act(() => harness.first.discardAllPendingUploadsForScopeChange());+ expect(harness.first.hasAttachmentInput()).toBe(false);+ });+++ // PR #6291: unit integration through the real selection/upload and expansion+ // hooks. Count-only tests miss a completion and addition in the same render.+ it('reopens for a new selection during completion but not for paste materialization or retry', async () => {+ const harness = mount('session-a');+ act(() => harness.latest().enqueueUploads([imageCandidate('first.png', vi.fn())], { token: 'token' }));+ await act(async () => { await flush(); });+ expect(harness.expansion().active).toBe(true);+ act(() => harness.expansion().collapse());+ await act(async () => {+ runtime.uploads[0].resolve();+ await harness.latest().waitForPendingUploads();+ harness.latest().enqueueUploads([imageCandidate('next.png', vi.fn())], { token: 'token' });+ await flush();+ });+ expect(harness.latest().pendingUploads).toHaveLength(1);+ expect(harness.expansion().active).toBe(true);+ act(() => harness.expansion().collapse());+ act(() => harness.latest().beginPastePlaceholders(1));+ expect(harness.expansion().active).toBe(true);+ act(() => harness.expansion().collapse());+ // Keep this upload at the token boundary, without native file conversion.+ harness.options.getAccessToken = () => new Promise(() => {});+ harness.rerender('session-a');+ await act(async () => { await harness.latest().addPastedImages(['file:///cache/paste.png']); });+ expect(harness.latest().pastePlaceholderCount).toBe(0);+ expect(harness.expansion().active).toBe(false);+ act(() => harness.latest().beginPastePlaceholders(1));+ expect(harness.expansion().active).toBe(true);+ act(() => harness.expansion().collapse());+ act(() => {+ harness.latest().failPastePlaceholders();+ harness.latest().beginPastePlaceholders(1);+ });+ expect(harness.expansion().active).toBe(true);+ act(() => harness.latest().failPastePlaceholders());+ act(() => harness.expansion().collapse());+ // Direct paste (without a loading event) is a new selection as well.+ await act(async () => { await harness.latest().addPastedImages(['file:///cache/direct.png']); });+ expect(harness.expansion().active).toBe(true);+ act(() => harness.latest().discardAllPendingUploads());+ await act(async () => {+ harness.latest().enqueueUploads([imageCandidate('failed.png', vi.fn())], { token: Promise.resolve(null) });+ await harness.latest().waitForPendingUploads();+ });+ expect(harness.latest().pendingUploads[0].failed).toBe(true);+ act(() => harness.expansion().collapse());+ act(() => harness.latest().retryPendingUpload(harness.latest().pendingUploads[0].localId));+ expect(harness.latest().pendingUploads[0].failed).toBeFalsy();+ expect(harness.expansion().active).toBe(false);+ });++ // PR #6291: the real upload hook must publish the local-id handoff before+ // reclaiming a pasted source. Tray-only tests cannot prove this ordering.+ it('keeps upload identity resolvable after source cleanup and releases it with the attachment', async () => {+ const harness = mount('session-a');+ runtime.durablePreviewUri = 'file:///durable/pasted.png';+ let localId = '';+ let attachmentAtCleanup: string | undefined;+ let deliveriesAtCleanup = 0;+ const cleanup = vi.fn(async () => {+ attachmentAtCleanup = harness.latest().getUploadedAttachmentId(localId);+ deliveriesAtCleanup = vi.mocked(harness.options.onUploaded).mock.calls.length;+ });+ act(() => harness.first.enqueueUploads([{+ ...imageCandidate('pasted.png', vi.fn()), cleanupLocalUris: cleanup,+ }], { token: 'token' }));+ await act(async () => { await flush(); });+ localId = harness.latest().pendingUploads[0].localId;+ expect(harness.latest().getUploadedAttachmentId(localId)).toBeUndefined();+ await act(async () => { runtime.uploads[0].resolve(); await harness.latest().waitForPendingUploads(); });+ expect(cleanup).toHaveBeenCalledOnce();+ expect(attachmentAtCleanup).toBe('att-pasted.png');+ expect(deliveriesAtCleanup).toBe(1);+ expect(harness.options.onUploaded).toHaveBeenCalledWith(+ expect.objectContaining({ id: 'att-pasted.png' }),+ expect.objectContaining({ uri: 'file:///durable/pasted.png' }), localId,+ );+ expect(harness.latest().pendingUploads).toEqual([]);+ expect(harness.latest().getUploadedAttachmentId(localId)).toBe('att-pasted.png');+ act(() => harness.latest().releaseUploadedSources(['att-pasted.png']));+ expect(harness.latest().getUploadedAttachmentId(localId)).toBeUndefined();+ });+it('puts selected photos in the tray and closes the context panel before their originals load', async () => {const harness = mount('session-a');runtime.pickPhotos.mockResolvedValue([{