Stop a folder wipe from restoring the pre-wipe library catalog.
The in-memory catalog could outlive the write, so delete-all came back as thousands of empty tiles and a stale badge. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { folderImageCount, libraryAfterWipe, mergeLibraryRows, replaceLibraryRows } from '../shared/studio2/viewer.mjs'
|
||||
|
||||
test('folderImageCount trusts a server count of 0', () => {
|
||||
assert.equal(folderImageCount({ id: 'inbox', imageCount: 0 }, 1762), 0)
|
||||
assert.equal(folderImageCount({ id: 'inbox', imageCount: 4 }, 1), 4)
|
||||
assert.equal(folderImageCount(undefined, 3), 3)
|
||||
})
|
||||
|
||||
test('libraryAfterWipe replaces state and does not keep wiped folder rows from a stale list', () => {
|
||||
const previous = {
|
||||
folders: [{ id: 'inbox', imageCount: 2 }],
|
||||
stills: [{ id: 'new-1', folderId: 'inbox' }, { id: 'new-2', folderId: 'inbox' }],
|
||||
clips: [],
|
||||
tracks: [],
|
||||
suppressedIds: ['already-gone']
|
||||
}
|
||||
const stale = {
|
||||
folders: [{ id: 'inbox', imageCount: 0 }, { id: 'other', imageCount: 1 }],
|
||||
stills: [
|
||||
{ id: 'ghost', folderId: 'inbox' },
|
||||
{ id: 'new-1', folderId: 'inbox' },
|
||||
{ id: 'kept', folderId: 'other' }
|
||||
],
|
||||
clips: [{ id: 'clip-ghost', folderId: 'inbox' }],
|
||||
tracks: []
|
||||
}
|
||||
const next = libraryAfterWipe(previous, stale, 'inbox')
|
||||
assert.deepEqual(next.stills.map(item => item.id), ['kept'])
|
||||
assert.deepEqual(next.clips, [])
|
||||
assert.equal(next.folders[0].imageCount, 0)
|
||||
assert.equal(next.suppressedIds.includes('new-1'), true)
|
||||
assert.equal(next.suppressedIds.includes('ghost'), true)
|
||||
assert.equal(next.suppressedIds.includes('already-gone'), true)
|
||||
const page = mergeLibraryRows(next.stills, stale.stills, next.suppressedIds)
|
||||
assert.deepEqual(page.map(item => item.id), ['kept'])
|
||||
assert.deepEqual(replaceLibraryRows(stale.stills, next.suppressedIds).map(item => item.id), ['kept'])
|
||||
})
|
||||
Reference in New Issue
Block a user