Cotton code
40 lines · 1.9 KB · TypeScriptRaw
import { env, runInDurableObject } from "cloudflare:test";import { describe, expect, it } from "vitest";import { Store } from "../src/store.ts";/** * SAME-NAME TAG GROUPS, COUNTED WITHOUT A KEY (21 Nov 2026): the old 409 loop * made a note's `#` group again on each pass. A group's name is sealed; its * blind tokens are the same for the same name, so the object counts them by * those, never reading a name. A deleted group, a filter group, a group of * another table and a hand-made group are not tag groups. Invented rows. */describe("the same-name tag groups of notes, counted by their blind tokens", () => {  it("counts each name held more than once, and the later groups a merge bins", async () => {    const stub = env.BUSINESS.get(env.BUSINESS.idFromName("groups-duplicates"));    await runInDurableObject(stub, (_instance, state) => {      const store = new Store(state.storage.sql, () => new Date("2026-11-21T10:00:00Z"));      let version = 0;      let n = 0;      const group = (tokens: string[] | null, data: Record<string, unknown>): void => {        const id = `g-${n++}`;        store.insert("record_group", id, { table_id: "note", sealed_enc: "s1:x", ...data }, null, ++version);        if (tokens) store.setBlind("record_group", id, tokens);      };      const work = ["101", "-202"];      const home = ["303", "404"];      for (let i = 0; i < 4; i++) group(work, {});      for (let i = 0; i < 2; i++) group(home, {});      group(["505"], {});      group(work, { deleted_at: "2026-11-20T00:00:00Z" });      group(work, { table_id: "photo" });      group(work, { filter: "{}" });      group(null, { name: "#Garden" });      group(null, { name: "#garden" });      group(null, { name: "Errands" });      group(null, { name: "Errands" });      expect(store.duplicateNoteGroups()).toEqual({ note_groups: 9, names_held_twice: 3, later_groups: 5, largest: 4 });    });  });});