Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

2.0 KB
Raw Blame
import { test } from "node:test";
import assert from "node:assert/strict";
import { rosterAdmits, withLiveTurnMembership } from "../src/resolution/scope-membership.ts";
import type { ScopeId } from "../src/types.ts";

const room = "group:C0NEW" as ScopeId;
const otherRoom = "group:C0OTHER" as ScopeId;
const stored = async (principalId: string, scope: ScopeId) =>
  scope === otherRoom && principalId === "[email protected]";

test("a verified live turn proves the speaker's membership in its own scope while the store lags", async () => {
  const check = withLiveTurnMembership(stored, { actorId: "[email protected]", scopeId: room, verified: true });
  assert.equal(await check("[email protected]", room), true);
  assert.equal(await check("[email protected]", room), true);
  assert.equal(await check("[email protected]", room), false);
});

test("the live turn says nothing about other scopes or unverified turns", async () => {
  const verified = withLiveTurnMembership(stored, { actorId: "[email protected]", scopeId: room, verified: true });
  assert.equal(await verified("[email protected]", otherRoom), false);
  assert.equal(await verified("[email protected]", otherRoom), true);
  const unverified = withLiveTurnMembership(stored, { actorId: "[email protected]", scopeId: room, verified: false });
  assert.equal(await unverified("[email protected]", room), false);
  const noStore = withLiveTurnMembership(undefined, { actorId: "[email protected]", scopeId: room, verified: true });
  assert.equal(await noStore("[email protected]", otherRoom), false);
});

test("a roster admits its members and its own conversation, never another conversation's actor", () => {
  const project = "group:web-project-p1" as ScopeId;
  assert.equal(rosterAdmits(["alice"], "alice", project), true);
  assert.equal(rosterAdmits(["alice"], "bob", project), false);
  assert.equal(rosterAdmits(["alice"], "system:group:web-project-p1", project), true);
  assert.equal(rosterAdmits(["alice"], "system:group:web-project-p2", project), false);
});