Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: carry over SongBook attachment presence only when explicitly known (#3900)

[._.]/ Adam Eivy399bc7aaa608
diff --git a/client/src/pages/SongBookViewer.jsx b/client/src/pages/SongBookViewer.jsx
index 1e948cb803..978464a73c 100644
--- a/client/src/pages/SongBookViewer.jsx
+++ b/client/src/pages/SongBookViewer.jsx
@@ -346,14 +346,17 @@ export default function SongBookViewer() {
.then((res) => {
attachmentsMutatedRef.current = true;
// Server returns the updated meta list; carry over local present flags.
- // `prev` is the 'failed' sentinel when the presence lookup errored —
- // `.find()` on that string throws, and presence is genuinely unknown,
- // so leave the flag off rather than stamping a false absent (#3900).
+ // `prev` is the 'failed' sentinel when the presence lookup errored, and
+ // `.find()` on that string throws (#3900). Presence carries over only
+ // where it is an explicitly-known boolean — an entry we never resolved
+ // (failed lookup, or a synced entry appended after one) stays unknown
+ // so it renders as a link, not a false "not on this machine".
setAttachments((prev) => {
- const known = Array.isArray(prev) ? prev : null;
- return (res?.attachments || []).map((meta) => (known
- ? { ...meta, present: known.find((a) => a.filename === meta.filename)?.present ?? false }
- : { ...meta }));
+ const known = Array.isArray(prev) ? prev : [];
+ return (res?.attachments || []).map((meta) => {
+ const prior = known.find((a) => a.filename === meta.filename)?.present;
+ return typeof prior === 'boolean' ? { ...meta, present: prior } : { ...meta };
+ });
});
})
.catch((err) => toast.error(err?.message || 'Failed to delete attachment')),
diff --git a/client/src/pages/SongBookViewer.test.jsx b/client/src/pages/SongBookViewer.test.jsx
index 3d34db7fac..045416f0ba 100644
--- a/client/src/pages/SongBookViewer.test.jsx
+++ b/client/src/pages/SongBookViewer.test.jsx
@@ -159,6 +159,31 @@ describe('SongBookViewer', () => {
expect(screen.getByRole('link', { name: 'Drum chart' })).toBeTruthy();
expect(screen.getAllByRole('listitem').length).toBe(3);
});
+
+ it('keeps presence unknown for synced entries when a delete follows an upload', async () => {
+ api.uploadSongAttachment.mockResolvedValue({
+ attachment: { filename: 'cccc3333-new.pdf', label: 'New sheet', mime: 'application/pdf', size: 512, sha256: 'z' },
+ });
+ api.deleteSongAttachment.mockResolvedValue({ attachments: [SYNCED[0], SYNCED[1]] });
+ renderPage();
+ expect(await screen.findByRole('link', { name: 'Sheet music' })).toBeTruthy();
+
+ // Upload first — that replaces the sentinel with an array whose synced
+ // entries still have no resolved presence.
+ const input = document.querySelector('input[type="file"]');
+ fireEvent.change(input, { target: { files: [new File(['x'], 'new.pdf', { type: 'application/pdf' })] } });
+ expect(await screen.findByRole('link', { name: 'New sheet' })).toBeTruthy();
+
+ // Then delete the uploaded file: the survivors must not be stamped absent.
+ fireEvent.click(screen.getByRole('button', { name: 'Delete attachment New sheet' }));
+ const group = screen.getByRole('group', { name: 'Confirm delete New sheet' });
+ fireEvent.click(within(group).getByRole('button', { name: 'Delete' }));
+
+ await waitFor(() => expect(screen.queryByText('New sheet')).toBeNull());
+ expect(screen.getByRole('link', { name: 'Sheet music' })).toBeTruthy();
+ expect(screen.getByRole('link', { name: 'Drum chart' })).toBeTruthy();
+ expect(screen.queryByText('not on this machine')).toBeNull();
+ });
});
describe('instrument-view toggle (#2656)', () => {