Files
Steffen Becker 554f0f6674 feat: each tab edits its own document
Every document-scoped key now goes through docKey(), which hangs it off the
tab's document id; the first document keeps the empty id, so existing browser
copies read back unchanged. A fresh tab takes up the most recently used
document no live tab holds, else starts a new one — one signed timestamp per
document (edentext-live@id) says which, written only by the tab holding it.
Snapshots and embedded fonts get a database per document. The picture store
stays shared and content-addressed, so its sweep now drops only keys no stored
document names any more, instead of the open document's own.
2026-09-07 23:50:11 +02:00

27 lines
933 B
TypeScript

import { describe, it, expect } from 'vitest';
import { pickSlot } from '../../src/lib/storage/docScope';
const NOW = 1_700_000_000_000;
const MIN = 60_000;
describe('pickSlot', () => {
it('gives the first tab of any browser the unsuffixed slot', () => {
expect(pickSlot({}, NOW)).toBe('');
});
it('mints a new document while every one is held', () => {
const id = pickSlot({ '': NOW - 1000 }, NOW);
expect(id).not.toBe('');
expect(pickSlot({ '': NOW - 1000, [id]: NOW }, NOW)).not.toBe(id);
});
it('takes up the most recent document no tab holds', () => {
// Negative = a tab signed off; the stamp still says how recently it was used.
expect(pickSlot({ '': -(NOW - 9 * MIN), d2: -(NOW - 2 * MIN) }, NOW)).toBe('d2');
});
it('counts a marker nobody has refreshed in ten minutes as abandoned', () => {
expect(pickSlot({ '': NOW - 11 * MIN, d2: NOW - 1 * MIN }, NOW)).toBe('');
});
});