fix(editor): five locals in stepHistory and MoreTabs, sync tag in tests

This commit is contained in:
bchanot committed 2026-11-14 18:52:41 +01:00
1 parent 08fab77d0e
commit bb35e86dbb
5 files changed
+48 -35

No files matched your search

@@ -58,9 +58,9 @@ const back = () => act(async () => navigate(-1))
/** The session tag of USER in this tab: entries and flags carry it (criterion 22). */
let TAG: string
beforeEach(async () => {
beforeEach(() => {
useLocaleStore.setState({ locale: 'fr' })
TAG = await resolveSessionTag(USER)
TAG = resolveSessionTag(USER)
})
afterEach(() => {
cleanup()
+2 -2
View File
@@ -56,8 +56,8 @@ const foreign = (patch: Partial<HistoryEntry>) => ({
/** The session tag of USER in this tab (criterion 22). */
let TAG: string
beforeEach(async () => {
TAG = await resolveSessionTag(USER)
beforeEach(() => {
TAG = resolveSessionTag(USER)
useLocaleStore.setState({ locale: 'fr' })
serverHas(emptyText(), 3, false)
})
+20 -20
View File
@@ -28,8 +28,8 @@ afterEach(() => {
})
describe('resolveSessionTag', () => {
it('draws a 128-bit hex tag, stored with the account fingerprint, never the id', async () => {
const tag = await resolveSessionTag('account-a')
it('draws a 128-bit hex tag, stored with the account fingerprint, never the id', () => {
const tag = resolveSessionTag('account-a')
expect(tag).toMatch(/^[0-9a-f]{32}$/)
const record = stored()
expect(record?.tag).toBe(tag)
@@ -37,37 +37,37 @@ describe('resolveSessionTag', () => {
expect(sessionStorage.getItem(STORAGE_KEY)).not.toContain('account-a')
})
it('reuses the tag for the same account, after a reload too', async () => {
const tag = await resolveSessionTag('account-a')
expect(await resolveSessionTag('account-a')).toBe(tag)
it('reuses the tag for the same account, after a reload too', () => {
const tag = resolveSessionTag('account-a')
expect(resolveSessionTag('account-a')).toBe(tag)
reload()
expect(await resolveSessionTag('account-a')).toBe(tag)
expect(resolveSessionTag('account-a')).toBe(tag)
})
it('rotates on another account and clears the flags of the old tag', async () => {
const old = await resolveSessionTag('account-a')
it('rotates on another account and clears the flags of the old tag', () => {
const old = resolveSessionTag('account-a')
const flag = leftDraftKey({ sheetId: 'S', tag: old })
sessionStorage.setItem(flag, '{}')
reload()
const tag = await resolveSessionTag('account-b')
const tag = resolveSessionTag('account-b')
expect(tag).not.toBe(old)
expect(sessionStorage.getItem(flag)).toBeNull()
reload()
expect(await resolveSessionTag('account-a')).not.toBe(old)
expect(resolveSessionTag('account-a')).not.toBe(old)
})
it('keeps the tag in memory when the storage refuses: a reload restores nothing', async () => {
it('keeps the tag in memory when the storage refuses: a reload restores nothing', () => {
vi.spyOn(sessionStorage, 'getItem').mockImplementation(() => {
throw new Error('blocked')
})
vi.spyOn(sessionStorage, 'setItem').mockImplementation(() => {
throw new Error('blocked')
})
const tag = await resolveSessionTag('account-a')
const tag = resolveSessionTag('account-a')
expect(tag).toMatch(/^[0-9a-f]{32}$/)
expect(await resolveSessionTag('account-a')).toBe(tag)
expect(resolveSessionTag('account-a')).toBe(tag)
reload()
expect(await resolveSessionTag('account-a')).not.toBe(tag)
expect(resolveSessionTag('account-a')).not.toBe(tag)
})
it('works without crypto.subtle (http): kept on reload, rotated per account', () => {
@@ -93,9 +93,9 @@ describe('resolveSessionTag', () => {
expect(typeof resolveSessionTag('account-a')).toBe('string')
})
it('reads a tampered record as none', async () => {
it('reads a tampered record as none', () => {
sessionStorage.setItem(STORAGE_KEY, '{"tag":"x","account":"y"}')
const tag = await resolveSessionTag('account-a')
const tag = resolveSessionTag('account-a')
expect(tag).toMatch(/^[0-9a-f]{32}$/)
expect(stored()?.tag).toBe(tag)
})
@@ -137,14 +137,14 @@ describe('the sweep of flags keyed by an account id (older shape)', () => {
})
describe('forgetSessionTag and the sign-out', () => {
it('rotates the tag of the same account and clears its flags', async () => {
const old = await resolveSessionTag('account-a')
it('rotates the tag of the same account and clears its flags', () => {
const old = resolveSessionTag('account-a')
const flag = leftDraftKey({ sheetId: 'S', tag: old })
sessionStorage.setItem(flag, '{}')
forgetSessionTag()
expect(stored()).toBeNull()
expect(sessionStorage.getItem(flag)).toBeNull()
expect(await resolveSessionTag('account-a')).not.toBe(old)
expect(resolveSessionTag('account-a')).not.toBe(old)
})
it('follows the account: a sign-out forgets, a sign-in resolves', async () => {
@@ -158,6 +158,6 @@ describe('forgetSessionTag and the sign-out', () => {
expect(useSessionTagStore.getState().held).toBeNull()
expect(stored()).toBeNull()
stop()
expect(await resolveSessionTag('account-a')).not.toBe(old)
expect(resolveSessionTag('account-a')).not.toBe(old)
})
})