Files
outline/shared/collaboration/documentName.test.ts
T
Tom Moor cca21437f5 Flatten collaborative state of large documents (#14587)
* feat: Flatten collaborative state of large documents

Replace edit history in large collaborative state with fresh state once a
document is idle with no open sessions, and when state is over the maximum
length on save. Each replacement increments a state generation that is part of
the collaboration room name, so old state never merges into the new state.

* fix: Refuse to load state of another generation and lock editor during reset

* Remove excessive tests

* fix: Reset rooms on all instances and check state generation during authentication

* refactor: Schedule state flattening only for changed rooms, from PersistenceExtension

* fix: Refuse API text updates applied to state of an earlier generation
2026-11-29 15:49:34 -05:00

37 lines
1.2 KiB
TypeScript

import { buildDocumentName, parseDocumentName } from "./documentName";
const id = "6f2c3a4e-0f0a-4b5e-9a39-3a5f7c6d2b10";
describe("buildDocumentName", () => {
it("omits the first generation", () => {
expect(buildDocumentName(id, 0)).toBe(`document.${id}`);
});
it("includes later generations", () => {
expect(buildDocumentName(id, 2)).toBe(`document.${id}.2`);
});
});
describe("parseDocumentName", () => {
it("parses names with and without a generation", () => {
expect(parseDocumentName(`document.${id}`)).toEqual({
documentId: id,
stateGeneration: 0,
});
expect(parseDocumentName(`document.${id}.3`)).toEqual({
documentId: id,
stateGeneration: 3,
});
});
it("refuses names that are not canonical", () => {
expect(parseDocumentName(`document.${id}.0`)).toBeUndefined();
expect(parseDocumentName(`document.${id}.01`)).toBeUndefined();
expect(parseDocumentName(`document.${id}.-1`)).toBeUndefined();
expect(parseDocumentName(`document.${id}.1.5`)).toBeUndefined();
expect(parseDocumentName(`document.${id}.x`)).toBeUndefined();
expect(parseDocumentName(`collection.${id}`)).toBeUndefined();
expect(parseDocumentName("document.")).toBeUndefined();
});
});