25 lines
1019 B
TypeScript
25 lines
1019 B
TypeScript
/**
|
|||
|
|
* Turn liveness registry unit tests (src/server/turn-liveness.ts): one turn
|
||
|
|
* per chat, ever — begin/end round trip, double-begin rejection, restart
|
||
|
|
* after end. The 30-minute stale-eviction TTL is not tested (it is a leak
|
||
|
|
* guard, not a behavior).
|
||
|
|
*/
|
||
|
|
|
||
|
|
import assert from "node:assert/strict";
|
||
|
|
import { describe, it } from "node:test";
|
||
|
|
import { beginTurn, endTurn, isTurnRunning } from "../src/server/turn-liveness.ts";
|
||
|
|
|
||
|
|
describe("turn liveness registry", () => {
|
||
|
|
it("begin/end round trip; a second begin is rejected until the turn ends", () => {
|
||
|
|
const id = "chat_liveness_unit";
|
||
|
|
assert.equal(isTurnRunning(id), false, "initially idle");
|
||
|
|
assert.equal(beginTurn(id), true, "first turn accepted");
|
||
|
|
assert.equal(isTurnRunning(id), true, "in flight");
|
||
|
|
assert.equal(beginTurn(id), false, "no two turns for one chat");
|
||
|
|
endTurn(id);
|
||
|
|
assert.equal(isTurnRunning(id), false, "cleared at finish");
|
||
|
|
assert.equal(beginTurn(id), true, "a new turn may start after the last ended");
|
||
|
|
endTurn(id);
|
||
|
|
});
|
||
|
|
});
|