import { describe, expect, test } from "bun:test"; import { registerParticipant, registeredGithubLogin } from "./participants"; import { SCHEMA_VERSION, type Thread } from "./types"; function emptySession(): Thread { return { schemaVersion: SCHEMA_VERSION, id: "ses_1", workspace: { repoRoot: "/repo", branch: "main" }, artifact: { type: "plan", content: "# Plan\n", meta: {} }, revisions: [], annotations: [], message: null, status: "pending", createdAt: "2026-01-01T00:00:00.000Z", }; } describe("registerParticipant", () => { test("adds a new author with a display name", () => { // Act const next = registerParticipant(emptySession(), "SHA256:ana", "Ana"); // Assert expect(next.participants).toEqual([{ id: "SHA256:ana", provider: "ssh", name: "Ana" }]); }); test("records presence without a name (renders anonymous)", () => { // Act const next = registerParticipant(emptySession(), "SHA256:ana"); // Assert expect(next.participants).toEqual([{ id: "SHA256:ana", provider: "ssh" }]); }); test("a nameless revisit never erases a name a past visit set", () => { // Arrange const named = registerParticipant(emptySession(), "SHA256:ana", "Ana"); // Act const next = registerParticipant(named, "SHA256:ana"); // Assert expect(next).toBe(named); expect(next.participants).toEqual([{ id: "SHA256:ana", provider: "ssh", name: "Ana" }]); }); test("a later name updates the existing identity in place", () => { // Arrange const present = registerParticipant(emptySession(), "SHA256:ana"); // Act const next = registerParticipant(present, "SHA256:ana", "Ana"); // Assert expect(next.participants).toEqual([{ id: "SHA256:ana", provider: "ssh", name: "Ana" }]); }); test("records a verified github source with its login handle", () => { // Act const next = registerParticipant(emptySession(), "SHA256:ana", "Ana", { provider: "github", handle: "ana", }); // Assert expect(next.participants).toEqual([ { id: "SHA256:ana", provider: "github", name: "Ana", handle: "ana" }, ]); }); test("a later nameless write preserves the github provider and handle", () => { // Arrange const verified = registerParticipant(emptySession(), "SHA256:ana", "Ana", { provider: "github", handle: "ana", }); // Act const next = registerParticipant(verified, "SHA256:ana"); // Assert expect(next.participants).toEqual([ { id: "SHA256:ana", provider: "github", name: "Ana", handle: "ana" }, ]); }); }); describe("registeredGithubLogin", () => { test("returns the handle a fingerprint verified on a past visit", () => { const session = registerParticipant(emptySession(), "SHA256:ana", "Ana", { provider: "github", handle: "ana-gh", }); expect(registeredGithubLogin(session, "SHA256:ana")).toBe("ana-gh"); }); test("returns undefined for an ssh-only or unknown participant", () => { const session = registerParticipant(emptySession(), "SHA256:ana", "Ana"); expect(registeredGithubLogin(session, "SHA256:ana")).toBeUndefined(); expect(registeredGithubLogin(session, "SHA256:unknown")).toBeUndefined(); }); });