Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): classify a duplicate after the composer cap as a duplicate (R4-L1)
Ma800bb17789c
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/composerMergeZipProperties.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/composerMergeZipProperties.test.tsxindex 4b7c410d6..35272c9dc 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/composerMergeZipProperties.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/composerMergeZipProperties.test.tsx@@ -243,6 +243,78 @@ describe('composer merge invariants (R1-M6)', () => {{ numRuns: PROPERTY_RUNS })})++ it('image merge: a duplicate arriving AFTER the cap is reached is a duplicate (R4-L1)', () => {+ // The composer is full. The payload's FIRST item is unique — it is+ // dropped — and the SECOND is a byte-identical copy of an image the+ // composer already holds. Nothing was lost by the second item, so it is a+ // DUPLICATE, not another drop: stopping the scan at the cap would+ // classify it without looking at it and report a lost attachment.+ const held = Array.from({ length: COMPOSER_MAX_IMAGE_ATTACHMENTS }, (_, index) => ({+ ...({} as ComposerImageAttachment),+ id: `held-${index}`,+ name: `held-${index}.png`,+ mimeType: 'image/png' as const,+ dataBase64: `aGQt${index}`,+ sizeBytes: index,+ previewDataUrl: `data:image/png;base64,aGQt${index}`,+ }))+ const outcome = mergeComposerImageAttachments(held, [+ {+ id: 'unique',+ name: 'unique.png',+ mimeType: 'image/png' as const,+ dataBase64: 'dW5pcXVl',+ sizeBytes: 7,+ previewDataUrl: 'data:image/png;base64,dW5pcXVl',+ },+ // A byte-identical copy of the FIRST held image.+ {+ id: 'held-0',+ name: 'held-0.png',+ mimeType: 'image/png' as const,+ dataBase64: 'aGQt0',+ sizeBytes: 0,+ previewDataUrl: 'data:image/png;base64,aGQt0',+ },+ ])+ expect(outcome.kept).toBe(0)+ expect(outcome.duplicates).toBe(1)+ expect(outcome.dropped).toBe(1)+ expect(outcome.next).toEqual(held)+ })++ it('reference merge: a duplicate arriving AFTER the cap is reached is a duplicate (R4-L1)', () => {+ const held = Array.from({ length: FILE_REFERENCE_MAX_COUNT }, (_, index) => ({+ ...({} as ComposerReferenceAttachment),+ id: `held-${index}`,+ type: 'plugin' as const,+ namespace: 'ns',+ name: `held-${index}`,+ label: `held ${index}`,+ }))+ const outcome = mergeComposerReferenceAttachments(held, [+ {+ id: 'unique',+ type: 'plugin' as const,+ namespace: 'ns',+ name: 'unique',+ label: 'unique',+ },+ // A copy of the FIRST held reference.+ {+ id: 'held-0',+ type: 'plugin' as const,+ namespace: 'ns',+ name: 'held-0',+ label: 'held 0',+ },+ ])+ expect(outcome.kept).toBe(0)+ expect(outcome.duplicates).toBe(1)+ expect(outcome.dropped).toBe(1)+ expect(outcome.next).toEqual(held)+ })})describe('zip path normalization invariants (R1-M6)', () => {diff --git a/desktop-app/ui/src/hooks/domain/useComposerAttachments.ts b/desktop-app/ui/src/hooks/domain/useComposerAttachments.tsindex 7a8f0d76c..e500ac7bd 100644--- a/desktop-app/ui/src/hooks/domain/useComposerAttachments.ts+++ b/desktop-app/ui/src/hooks/domain/useComposerAttachments.ts@@ -30,6 +30,7 @@ export function mergeComposerImageAttachments(const accepted = [...existing]let kept = 0let duplicates = 0+ let dropped = 0for (const attachment of incoming) {// Dedupe BEFORE capacity (R2-L1): a byte-identical copy of an attachment// the composer already holds is not "dropped at the cap" — nothing is@@ -45,13 +46,21 @@ export function mergeComposerImageAttachments(duplicates += 1continue}- if (accepted.length >= COMPOSER_MAX_IMAGE_ATTACHMENTS) break+ if (accepted.length >= COMPOSER_MAX_IMAGE_ATTACHMENTS) {+ // The cap leaves no room: this attachment is dropped, but the loop+ // CONTINUES (R4-L1). Stopping here would classify every LATER item as a+ // drop without looking at it, so a duplicate that arrives after the cap+ // was reached would be reported as a lost attachment when nothing was+ // lost at all.+ dropped += 1+ continue+ }accepted.push(attachment.addedOrder != null ? attachment : { ...attachment, addedOrder: nextOrder() })kept += 1}- return { next: accepted, kept, duplicates, dropped: incoming.length - kept - duplicates }+ return { next: accepted, kept, duplicates, dropped }}export interface ComposerReferenceMergeOutcome {@@ -79,18 +88,25 @@ export function mergeComposerReferenceAttachments(const accepted = [...existing]let kept = 0let duplicates = 0+ let dropped = 0for (const attachment of incoming) {if (accepted.some(candidate => candidate.id === attachment.id)) {duplicates += 1continue}- if (accepted.length >= FILE_REFERENCE_MAX_COUNT) break+ if (accepted.length >= FILE_REFERENCE_MAX_COUNT) {+ // The cap leaves no room: dropped, but the loop CONTINUES (R4-L1), so a+ // duplicate arriving after the cap was reached is still classified as a+ // duplicate rather than as a lost attachment.+ dropped += 1+ continue+ }accepted.push(attachment.addedOrder != null ? attachment : { ...attachment, addedOrder: nextOrder() })kept += 1}- return { next: accepted, kept, duplicates, dropped: incoming.length - kept - duplicates }+ return { next: accepted, kept, duplicates, dropped }}interface UseComposerAttachmentsParams {