feat(editor): session tag in history, confirm before leaving

This commit is contained in:
bchanot committed 2026-11-14 14:47:43 +01:00
1 parent 4018344ffc
commit 07bebbc855
19 files changed
+844 -76

No files matched your search

@@ -29,7 +29,7 @@ const entry = (patch: Partial<HistoryEntry> = {}): HistoryEntry => ({
view: view('general'),
below: null,
sheetId: 'S',
userId: 'U',
tag: 'T',
...patch,
})
const stateOf = (value: unknown) => ({ [ENTRY_KEY]: value })
@@ -145,19 +145,34 @@ describe('readEntry and ownership', () => {
expect(readEntry(stateOf({ ...entry(), view: 'x' }))).toBeNull()
})
it('restores only for the sheet and the account that wrote it', () => {
const mine = { sheetId: 'S', userId: 'U' }
it('restores only for the sheet and the session tag that wrote it', () => {
const mine = { sheetId: 'S', tag: 'T' }
expect(ownedEntry(stateOf(entry()), mine)).not.toBeNull()
expect(ownedEntry(stateOf(entry()), { ...mine, sheetId: 'T' })).toBeNull()
expect(ownedEntry(stateOf(entry()), { ...mine, userId: 'V' })).toBeNull()
expect(ownedEntry(stateOf(entry()), { ...mine, sheetId: 'X' })).toBeNull()
expect(ownedEntry(stateOf(entry()), { ...mine, tag: 'V' })).toBeNull()
})
it('refuses an owner without a sheet or an account', () => {
const blank = entry({ sheetId: '', userId: '' })
expect(ownedEntry(stateOf(blank), { sheetId: '', userId: '' })).toBeNull()
expect(
ownedEntry(stateOf(entry()), { sheetId: 'S', userId: '' }),
).toBeNull()
it('refuses an owner without a sheet or a tag: no tag yet restores nothing', () => {
const blank = entry({ sheetId: '', tag: '' })
expect(ownedEntry(stateOf(blank), { sheetId: '', tag: '' })).toBeNull()
expect(ownedEntry(stateOf(entry()), { sheetId: 'S', tag: '' })).toBeNull()
})
it('reads an entry of the older shape (an account id, no tag) as foreign', () => {
const { id, view, below, sheetId } = entry()
const older = { id, view, below, sheetId, userId: 'T' }
expect(readEntry(stateOf(older))).toBeNull()
expect(ownedEntry(stateOf(older), { sheetId: 'S', tag: 'T' })).toBeNull()
})
it('never writes an account id in the entry', () => {
expect(Object.keys(readEntry(stateOf(entry()))!).sort()).toEqual([
'below',
'id',
'sheetId',
'tag',
'view',
])
})
it('keeps only navigation: nothing typed survives the read', () => {
@@ -362,11 +377,11 @@ describe('final review: read-back values are capped', () => {
const onFindings = (key: ElementKey) =>
view('findings', { finding: { key, citations: false } })
it('drops an entry whose id, sheet or account is over 128 characters', () => {
it('drops an entry whose id, sheet or tag is over 128 characters', () => {
expect(readEntry(stateOf(entry({ id: atCap })))).not.toBeNull()
expect(readEntry(stateOf(entry({ id: long })))).toBeNull()
expect(readEntry(stateOf(entry({ sheetId: long })))).toBeNull()
expect(readEntry(stateOf(entry({ userId: long })))).toBeNull()
expect(readEntry(stateOf(entry({ tag: long })))).toBeNull()
})
it('drops a key with an over-long id or a path deeper than the tree allows', () => {