Preserve uncertainty across skipped tab reinsertion

This commit is contained in:
Brennan Benson
2026-11-09 14:54:49 -08:00
parent 47ffbd3b40
commit b49c634587
2 changed files with 13 additions and 0 deletions
@@ -39,6 +39,15 @@ describe('addressed tab row references', () => {
expect(readTabRowChanges(start, start)).toBeNull()
})
it('requires resync when a removed row is reinserted across skipped writes', () => {
const a = { id: 'a', contentType: 'terminal', entityId: 't0', groupId: 'g' }
const b = { id: 'b', contentType: 'terminal', entityId: 't0', groupId: 'h' }
const start = { workspace: [a, b] }
const removed = replaceTabBuckets(start, [['workspace', [b]]])
const reinserted = replaceTabBuckets(removed, [['workspace', [b, a]]])
expect(readTabRowChanges(reinserted, start)).toBe('unknown')
})
it('requires resync for unavailable or reordered histories', () => {
const first = { id: 'first' }
const second = { id: 'second' }
@@ -46,6 +46,10 @@ export function readTabRowChanges<T extends Row>(
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the net endpoints belong to the supplied T snapshots.
const change = untypedChange as TabRowChange<T>
const earlier = bucket.get(tabId)
// Reinsertion may change which duplicate entity owns the assignment.
if (earlier && earlier.after === undefined && change.after !== undefined) {
return 'unknown'
}
bucket.set(tabId, { before: earlier ? earlier.before : change.before, after: change.after })
}
}