Seats are banked in a cookie the server sets, and a lost seat comes back by name to the address it was last used from
A seat lived in the browser's storage alone, and Safari clears that after a week away, or at a word from the person on another device. Now every seat taken is banked as well in an HttpOnly cookie the server writes, which such clearing leaves alone, and the hall takes its seats back from the bank on arrival. For a browser that lost even the cookie, the ledger notes the address each seat was last used from, as a salted hash, and a name given in the hall or at the table gets its seats back from the same address, with a new token; where the address differs, two people at the table share it, or the host gave the seat to a bot, the table is only counted, and the host's phrase or the keeper's link is the way back. The keeper's script finds a name across tables. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CCLa2PaEeCj8njQZSWGqHx
This commit is contained in:
1 parent
a66b0fe3f5
commit
29a15e7c89
9 files changed
+358
-14
No files matched your search
@@ -263,3 +263,58 @@ describe('the host and the other seats', () => {
|
||||
expect(() => rooms.claim(phrase)).toThrow(/unknown or has expired/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('a seat a browser lost', () => {
|
||||
it('notes the address a seat is used from, once per change, without waking the table, and a restart keeps it', () => {
|
||||
const { rooms, room, bo } = table();
|
||||
const seq = room.seq;
|
||||
rooms.seen(room, bo, 'home');
|
||||
rooms.seen(room, bo, 'home');
|
||||
expect(room.seats.find((s) => s.id === 'B')?.addr).toBe('home');
|
||||
expect(room.seq).toBe(seq);
|
||||
rooms.seen(room, 'no-such-token', 'elsewhere');
|
||||
expect(new Store(dir).read(room.id).filter((l) => l.t === 'seen')).toHaveLength(1);
|
||||
expect(new Rooms(game, new Store(dir)).get(room.id).seats.find((s) => s.id === 'B')?.addr).toBe('home');
|
||||
});
|
||||
|
||||
it('gives the seat back, under its name, to the address it was last used from, with a new token', () => {
|
||||
const { rooms, room, bo } = table();
|
||||
rooms.seen(room, bo, 'home');
|
||||
const found = rooms.findSeats('bo', 'home');
|
||||
expect(found.elsewhere).toBe(0);
|
||||
expect(found.seated).toHaveLength(1);
|
||||
const { roomId, seat, token } = found.seated[0];
|
||||
expect([roomId, seat]).toEqual([room.id, 'B']);
|
||||
expect(rooms.seatOf(room, token).name).toBe('Bo');
|
||||
expect(() => rooms.seatOf(room, bo)).toThrow(/opens no seat/);
|
||||
});
|
||||
|
||||
it('only counts the table when the address differs, or another person at it shares the address, or a bot stands in', async () => {
|
||||
const { rooms, room, ann, bo } = table();
|
||||
rooms.seen(room, bo, 'home');
|
||||
expect(rooms.findSeats('Bo', 'away')).toEqual({ seated: [], elsewhere: 1 });
|
||||
// Ann and Bo play from one address: a name alone cannot tell them apart, so neither is re-seated by it.
|
||||
rooms.seen(room, ann, 'home');
|
||||
expect(rooms.findSeats('Bo', 'home')).toEqual({ seated: [], elsewhere: 1 });
|
||||
expect(rooms.findSeats('Dee', 'home')).toEqual({ seated: [], elsewhere: 0 });
|
||||
expect(rooms.seatOf(room, bo).id).toBe('B');
|
||||
// The host gave Bo's seat to a bot: it is the host's phrase that gives it back, not Bo's name.
|
||||
rooms.seen(room, ann, 'office');
|
||||
rooms.standIn(room, ann, 'B');
|
||||
await answered();
|
||||
expect(rooms.findSeats('Bo', 'home')).toEqual({ seated: [], elsewhere: 1 });
|
||||
expect(rooms.tablesForKeeper('bo')).toEqual([{ roomId: room.id, seat: 'B', standIn: true, players: ['Ann'], updatedAt: room.updatedAt }]);
|
||||
expect(rooms.tablesForKeeper('Dee')).toEqual([]);
|
||||
});
|
||||
|
||||
it('looks only at the table named when one is, and passes over a table that is over', () => {
|
||||
const { rooms, room, bo } = table();
|
||||
rooms.seen(room, bo, 'home');
|
||||
const other = rooms.create('Bo', 2);
|
||||
rooms.seen(other.room, other.token, 'home');
|
||||
expect(rooms.findSeats('Bo', 'home', other.room.id).seated.map((s) => s.roomId)).toEqual([other.room.id]);
|
||||
expect(rooms.findSeats('Bo', 'home').seated.map((s) => s.roomId).sort()).toEqual([other.room.id, room.id].sort());
|
||||
room.over = true;
|
||||
expect(rooms.findSeats('Bo', 'home').seated.map((s) => s.roomId)).toEqual([other.room.id]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user