test: pin that retiring a game cannot delete a reader's own events

Nothing in the client prunes reader data today — no store filters against the
feed, knownGames only appends, metaFor renders a lane whose game is gone — so a
retired source, page or game leaves completion marks, streaks and hand-entered
events untouched. That was true by construction and pinned nowhere.

The load path is what makes it worth pinning. useCustom reads through
validRecords, which drops a record that fails its schema, and the survivors are
what the next write persists. A record that stops parsing is therefore not
hidden until someone notices — it is deleted from the device, permanently, by
the act of opening the app, with no server-side copy to recover it from.

Which makes CustomEvent.game being z.string() rather than GameId the whole
safety property, and it currently reads like validation someone forgot. Anyone
narrowing it to the enum would be tightening a schema and arming every future
game removal to erase reader data on next launch. The tests state the premise,
the survival, and that one unreadable neighbour still does not take the rest
down; the field says why it is loose.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Lucas Winther
2026-08-19 04:40:04 +02:00
co-authored by Claude Opus 5
parent acadbfa17a
commit 239e970471
3 changed files with 86 additions and 2 deletions
+61
View File
@@ -336,3 +336,64 @@ describe("validRecords — the import gate", () => {
expect(kept).toEqual({});
});
});
describe("retiring a game, a source or a page", () => {
/**
* The reader's own events are the only copy that exists — no server has ever
* seen them (AGENTS.md § Three constraints). We retire things routinely: a
* source moves, a page goes stale, a game shuts down. None of that may cost
* them a row they typed.
*
* The load path is what makes this sharp rather than theoretical.
* `useCustom` reads through `validRecords`, which **drops** a record that
* fails its schema, and the surviving set is what the next write persists.
* So a record that stops parsing is not hidden until someone fixes it — it is
* deleted from the device, permanently, by the act of opening the app.
*
* `CustomEvent.game` is therefore `z.string()` and not `GameId`, which reads
* like missing validation and is the load-bearing decision here. Narrowing it
* to the enum would look like a tightening and would arm every future game
* removal to erase reader data on next launch.
*/
const retired = "a-game-we-no-longer-track";
test("a game id we retire is not one the enum still holds", () => {
// Guards the premise: if this ever became a real id the test below stops
// testing anything.
expect(GameId.options).not.toContain(retired as never);
});
test("keeps an event the reader filed under a game we later dropped", () => {
const orphaned = { ...ownEvent(), game: retired };
// Parses on its own...
expect(CustomEvent.safeParse(orphaned).success).toBe(true);
// ...and survives the gate that decides what stays on the device.
const kept = validRecords({ [orphaned.id]: orphaned }, CustomEvent);
expect(kept[orphaned.id]).toBeDefined();
expect(kept[orphaned.id]?.game).toBe(retired);
});
test("keeps the neighbours of an event that genuinely is unreadable", () => {
// The drop is per record and always has been; this pins that a retired
// lane is not what triggers it, and that one bad row is not contagious.
const good = ownEvent();
const kept = validRecords(
{ [good.id]: good, "myevent:broken": { id: "myevent:broken" } },
CustomEvent,
);
expect(Object.keys(kept)).toEqual([good.id]);
});
test("still names the lane, so a retired game shows a row rather than nothing", () => {
const meta = metaFor(retired, {});
expect(meta.name).toBe("Unknown game");
expect(meta.hue).toMatch(/^#[0-9A-Fa-f]{6}$/);
});
test("still clocks it, so the countdown does not need the game to exist", () => {
const orphaned = CustomEvent.parse({ ...ownEvent(), game: retired });
const c = clockFor(asDisplayEvent(orphaned), "europe", Date.parse("2026-08-25T00:00:00.000Z"));
expect(c.live).toBe(true);
expect(c.endsMs).not.toBeNull();
});
});