mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-04 14:39:42 +02:00
fix(attachments): address review findings on attachment history drawer (#121)
Follow-up fixes applied during review of PR #121 (all confirmed minor/nit; no blockers). Security posture verified sound (externalPath never leaves toState()/the list route; re-registration runs the guard). - fix(recovery): restoreAttachmentHistory now skips malformed/legacy saved items (null, non-object, missing source/fileName) instead of throwing inside the Session constructor — a corrupt __attachmentHistory entry could otherwise abort the entire mux-recovery loop. (P1) - fix(routes): the attachment-list route degrades a single failing entry to {missing:true} instead of failing the whole drawer. (INT-4) - fix(ui): give the attachments header button a positioning context so the unread badge anchors to the icon, not the header bar. (F1/CSS-1) - fix(ui): cancel the debounced history refresh on drawer close and guard it against a stale session/closed drawer. (F3) - fix(ui): re-show ("Card") of a detected item now uses the item's own timestamp so the cardId is stable — focuses the existing card instead of stacking duplicates. (F4) - fix(ui): Escape now closes the drawer, matching every other panel. (UX-1) - fix(ui): badge shows "99+" past 99 (was an inconsistent 100/99 cap). (BADGE-1) - style: drop the duplicate @keyframes notif-badge-pulse (dead CSS). (INT-1/CSS-3) - style: empty-state used three undefined CSS custom properties (--text-primary/--border-color/--bg-tertiary) → use the defined --text/--border-light/--bg-input tokens. (CSS-2) - test: add constructor restore round-trip + malformed-item resilience tests. Deferred (noted for author): broadcasting the full 100-item history in every session-state SSE event (payload bloat), "unread" badge semantics, making the header button opt-in, and app.inject route tests for the two new endpoints. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -113,4 +113,52 @@ describe('session attachment history', () => {
|
||||
expect(publicState.attachmentHistory?.[0].id).not.toContain('/mnt/c/private/board-update.pdf');
|
||||
expect(persistedHistory?.[0].externalPath).toBe('/mnt/c/private/board-update.pdf');
|
||||
});
|
||||
|
||||
it('round-trips persisted history (incl. externalPath) through constructor restore', () => {
|
||||
const a = new Session({ workingDir: '/tmp' });
|
||||
a.upsertAttachmentHistory(
|
||||
buildExternalAttachmentHistoryItem({
|
||||
sessionId: a.id,
|
||||
externalPath: '/mnt/c/docs/deck.docx',
|
||||
fileName: 'deck.docx',
|
||||
extension: 'docx',
|
||||
size: 10,
|
||||
timestamp: 5,
|
||||
})
|
||||
);
|
||||
const persisted = a.getAttachmentHistoryForPersist();
|
||||
|
||||
const b = new Session({ workingDir: '/tmp', attachmentHistory: persisted });
|
||||
// Private copy keeps externalPath (needed to re-register/serve the file)...
|
||||
expect(b.getAttachmentHistoryForPersist()?.[0].externalPath).toBe('/mnt/c/docs/deck.docx');
|
||||
// ...but the public copy stays sanitized after restore.
|
||||
expect(JSON.stringify(b.toState().attachmentHistory)).not.toContain('/mnt/c/docs/deck.docx');
|
||||
});
|
||||
|
||||
it('ignores malformed saved history items during restore instead of throwing', () => {
|
||||
const valid: SessionAttachmentHistoryItem = {
|
||||
id: 'detected:ok.png',
|
||||
sessionId: 's',
|
||||
fileName: 'ok.png',
|
||||
extension: 'png',
|
||||
attachmentType: 'image',
|
||||
size: 1,
|
||||
mtimeMs: 0,
|
||||
timestamp: 1,
|
||||
source: 'detected',
|
||||
relativePath: 'ok.png',
|
||||
};
|
||||
// null, a non-object, and an item missing required fields must be skipped —
|
||||
// historyKey() would otherwise throw inside the constructor and abort recovery.
|
||||
const malformed = [null, 'nope', { partial: true }, valid] as unknown as SessionAttachmentHistoryItem[];
|
||||
|
||||
let session!: Session;
|
||||
expect(() => {
|
||||
session = new Session({ workingDir: '/tmp', attachmentHistory: malformed });
|
||||
}).not.toThrow();
|
||||
|
||||
const persisted = session.getAttachmentHistoryForPersist();
|
||||
expect(persisted).toHaveLength(1);
|
||||
expect(persisted?.[0].fileName).toBe('ok.png');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user