import { describe, expect, it } from "bun:test"; import { ulid } from "@chopin/dialect"; import { Sessions } from "../auth/session"; import { Admission } from "../auth/admission"; import { GitHubError } from "../github/client"; import { handler } from "../mcp"; import * as Room from "../plan/room"; import * as Service from "../plan/service"; import * as Rooms from "../rooms"; import { MemoryStorage } from "../storage/memory/adapter"; import { implementationGraphs } from "../tasks/plan-graphs"; import { hosted } from "./hosted"; import type { Server } from "bun"; import type { HostedAuth } from "../auth/routes"; import type { GitHub, GitHubTokenGrant, GitHubUser, InstallationPage, Repository, RepositoryPage, } from "../github/client"; import type { CreateDocumentInput } from "../mcp"; import type { Socket, SocketData } from "../wire"; import type { PlannerInvocation } from "./hosted"; let creation: CreateDocumentInput = { idempotencyKey: "create-plan-1", fingerprint: "request-1", repository: "octo-org/score", baseBranch: "main", baseCommit: "0123456789abcdef0123456789abcdef01234567", title: "Created plan", brief: { goal: "Create a collaborative plan.", constraints: ["Keep the source canonical."], settledDecisions: ["Use hosted storage."], openQuestions: ["Who reviews the rollout?"], repositoryFindings: ["The repository uses Bun."], }, plan: "# Created\n", }; let claimTask = { id: "claim", title: "Claim the graph", context: "The graph and run share one durable sidecar.", goal: "Lock approved work for one external session.", acceptance: ["The graph locks.", "The run is durable."], dependsOn: [], }; function createdDocument(id: string) { return { id, title: creation.title, brief: creation.brief, source: creation.plan, revision: 0, }; } class GitHubBoundary implements GitHub { readonly userTokens: string[] = []; readonly repositoryCalls: Array<{ token: string; owner: string; name: string }> = []; accessible = true; repositoryValue: Repository = { id: "R_score", owner: "octo-org", name: "score", fullName: "octo-org/score", private: true, url: "https://github.test/octo-org/score", defaultBranch: "main", permissions: { pull: true, push: false, admin: false }, }; authorize(): string { return ""; } async exchange(): Promise { return grant("access-token"); } async refresh(): Promise { return grant("refreshed-access-token"); } async user(token: string): Promise { this.userTokens.push(token); if (token === "denied") throw new GitHubError("bad credentials", 401); return { id: `U_${token}`, login: token, avatarUrl: "https://github.test/avatar" }; } async organizationMembership() { return undefined; } async repositories(): Promise { return { repositories: [], nextPage: undefined }; } async installations(): Promise { return { installations: [], nextPage: undefined }; } async installationRepositories(): Promise { return this.repositories(); } async repository(token: string, owner: string, name: string): Promise { this.repositoryCalls.push({ token, owner, name }); if (!this.accessible) throw new GitHubError("repository not found", 404); return this.value(owner, name); } async repositoryAccess(): Promise { throw new Error("installation-gated access must not be used by MCP"); } invalidate(): void {} private value(owner: string, name: string): Repository { return { ...this.repositoryValue, owner, name, fullName: `${owner}/${name}`, url: `https://github.test/${owner}/${name}`, }; } } function grant(accessToken: string): GitHubTokenGrant { return { accessToken, accessExpiresIn: 28_800, refreshToken: "refresh-token", refreshExpiresIn: 15_897_600, }; } function setup() { let now = new Date("2026-08-17T12:00:00.000Z"); let storage = new MemoryStorage(); let github = new GitHubBoundary(); let key = new Uint8Array(32).fill(3); let config = { origin: "https://chopin.test", appSlug: "chopin-test", clientId: "client-id", clientSecret: "client-secret", encryptionKey: key, }; let auth: HostedAuth = { config, storage, github, admission: new Admission(config, github, () => now.getTime()), sessions: new Sessions(storage, true, () => now), clock: () => now, }; return { auth, github, now, storage }; } function request(authorization?: string | Headers): Request { let headers = authorization instanceof Headers ? authorization : authorization ? new Headers({ authorization }) : undefined; return new Request("https://chopin.test/mcp", { headers }); } async function plan(context: ReturnType) { await context.storage.users.put({ id: "U_allowed", login: "allowed", avatarUrl: "", now: context.now, }); let channel = await context.storage.channels.create({ id: crypto.randomUUID(), repositoryId: "R_score", repositoryOwner: "octo-org", repositoryName: "score", title: "Release readiness", createdBy: "U_allowed", now: context.now, }); let lease = await context.storage.leases.acquire("writer", "mcp-test", 60_000); if (!lease) throw new Error("could not acquire test lease"); let server = { publish() {} } as unknown as Server; let backend: Service.Backend = { storage: context.storage, lease: () => lease, fatal: err => { throw err; }, }; return { channel, lease, server, plan: await Service.open(channel.id, backend, server) }; } describe("the hosted MCP adapter", () => { it("offers invoke_planner in hosted and local configuration, passing the caller and any live login", async () => { for (let local of [false, true]) { let context = setup(); if (local) { context.auth.config.local = { installation: "local", credentialsDir: "/tmp/unused", port: 8795, }; } context.github.repositoryValue.permissions.push = true; let opened = await plan(context); let started: PlannerInvocation[] = []; let refusal: "planner-owner-unavailable" | undefined; let adapter = hosted(context.auth, undefined, { async invokePlanner(input) { started.push(input); return refusal; }, }); let caller = (await adapter.caller(request("Bearer allowed")))!; let input = { id: opened.channel.id, instruction: " Review this.\n" }; try { expect(hosted(context.auth).invoke).toBeUndefined(); let listed = await handler(adapter)( new Request("https://chopin.test/mcp", { method: "POST", headers: { authorization: "Bearer allowed" }, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" }), }), ); expect((await listed.json()).result.tools.map((tool: { name: string }) => tool.name)) .toContain("invoke_planner"); await context.storage.users.put({ id: "U_other", login: "other", avatarUrl: "", now: context.now, }); await context.auth.sessions.issue("U_other", grant("another-browser")); expect(await adapter.invoke!.invoke(caller, input)).toEqual({ kind: "invoked", document: { id: opened.channel.id, title: opened.channel.title, url: "https://chopin.test/documents/octo-org/score/release-readiness", }, }); expect(started[0]).toMatchObject({ instruction: input.instruction, user: { id: caller.user.id, login: caller.user.login }, channel: { id: opened.channel.id }, }); expect(started[0]!.session).toBeUndefined(); expect(Object.hasOwn(started[0]!, "checkout")).toBe(false); let session = await context.auth.sessions.issue(caller.user.id, grant("browser-token")); refusal = "planner-owner-unavailable"; expect(await adapter.invoke!.invoke(caller, input)).toEqual({ kind: "refused", code: "planner-owner-unavailable", }); expect(started[1]).toMatchObject({ session: { session: { id: session.id }, user: { id: caller.user.id } }, }); } finally { await Service.close(opened.plan); } } }); it("passes a URL invocation's checkout through unverified for the harness to judge", async () => { let context = setup(); context.github.repositoryValue.permissions.admin = true; let opened = await plan(context); let started: PlannerInvocation[] = []; let adapter = hosted(context.auth, undefined, { async invokePlanner(input) { started.push(input); return undefined; }, }); try { let caller = (await adapter.caller(request("Bearer allowed")))!; let input = { id: "https://chopin.test/documents/octo-org/score/release-readiness", instruction: "Review", checkout: "/does-not-exist", }; expect(await adapter.invoke!.invoke(caller, input)).toMatchObject({ kind: "invoked", document: { id: opened.channel.id, url: input.id }, }); expect(started).toHaveLength(1); expect(started[0]).toMatchObject({ checkout: "/does-not-exist", instruction: input.instruction, repository: { id: "R_score", owner: "octo-org", name: "score" }, }); } finally { await Service.close(opened.plan); } }); it("refuses unavailable, forbidden, archived and deleting documents before starting a Planner", async () => { let context = setup(); let opened = await plan(context); let calls = 0; let deleting = false; let callbacks = { async invokePlanner() { calls++; return undefined; }, isChannelDeleting: () => deleting, }; let adapter = hosted(context.auth, undefined, callbacks); let caller = (await adapter.caller(request("Bearer allowed")))!; let invoke = (id = opened.channel.id) => adapter.invoke!.invoke(caller, { id, instruction: "Review" }); try { expect(await invoke(crypto.randomUUID())).toEqual({ kind: "refused", code: "document-unavailable", }); expect(await invoke()).toEqual({ kind: "refused", code: "repository-forbidden" }); context.github.repositoryValue.permissions.push = true; context.github.repositoryValue.permissions.pull = false; expect(await invoke()).toEqual({ kind: "refused", code: "repository-forbidden" }); context.github.repositoryValue.permissions.pull = true; deleting = true; expect(await invoke()).toEqual({ kind: "refused", code: "document-unavailable" }); deleting = false; await context.storage.channels.archive({ id: opened.channel.id, now: context.now }); expect(await invoke()).toEqual({ kind: "refused", code: "document-archived" }); expect(calls).toBe(0); } finally { await Service.close(opened.plan); } }); it("accepts exactly one bearer token and validates its GitHub identity per request", async () => { let { auth, github } = setup(); let adapter = hosted(auth); let duplicate = new Headers(); duplicate.append("authorization", "Bearer first"); duplicate.append("authorization", "Bearer second"); expect(await adapter.caller(request())).toBeUndefined(); expect(await adapter.caller(request("Basic token"))).toBeUndefined(); expect(await adapter.caller(request(duplicate))).toBeUndefined(); expect(await adapter.caller(request("Bearer denied"))).toBeUndefined(); expect(await adapter.caller(request("Bearer allowed"))).toEqual({ oauthToken: "allowed", user: { id: "U_allowed", login: "allowed", avatarUrl: "https://github.test/avatar", }, }); expect(await adapter.caller(request("bearer allowed"))).toBeDefined(); expect(await adapter.caller(request("Bearer token+/=="))).toBeDefined(); expect(github.userTokens).toEqual(["denied", "allowed", "token+/=="]); }); it("lists every channel under the currently readable repository node id", async () => { let { auth, github, now, storage } = setup(); let adapter = hosted(auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); expect(await adapter.documents.list(caller, "octo-org/score")).toEqual([]); await storage.users.put({ id: "U_allowed", login: "allowed", avatarUrl: "", now }); for (let index = 0; index < 101; index++) { await storage.channels.create({ id: crypto.randomUUID(), repositoryId: "R_score", repositoryOwner: "octo-org", repositoryName: "score", title: `Plan ${String(index).padStart(3, "0")}`, createdBy: "U_allowed", now, }); } await storage.channels.create({ id: crypto.randomUUID(), repositoryId: "R_foreign", repositoryOwner: "elsewhere", repositoryName: "private", title: "Foreign title", createdBy: "U_allowed", now, }); let listed = await adapter.documents.list(caller, "octo-org/score"); if (listed === "forbidden") throw new Error("readable repository was forbidden"); expect(listed).toHaveLength(101); expect(listed.map(document => document.title)).not.toContain("Foreign title"); expect(github.repositoryCalls).toContainEqual({ token: "allowed", owner: "octo-org", name: "score", }); github.repositoryValue = { ...github.repositoryValue, permissions: { pull: false, push: true, admin: false }, }; expect(await adapter.documents.list(caller, "octo-org/score")).toBe("forbidden"); github.accessible = false; expect(await adapter.documents.list(caller, "octo-org/score")).toBe("forbidden"); }); it("archives, lists, reads, and restores documents through storage fallback", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let opened = await plan(context); await Service.close(opened.plan); let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.archive || !adapter.restore) { throw new Error("hosted archive adapter is unavailable"); } let locator = "/documents/octo-org/score/release-readiness"; let archived = await adapter.archive.archive(caller, locator); expect(archived).toMatchObject({ kind: "archived", document: { id: opened.channel.id, title: "Release readiness" }, }); if (archived.kind !== "archived") throw new Error("test document was not archived"); expect(archived.document.archivedAt).toBeString(); expect(await adapter.archive.archive(caller, opened.channel.id)).toEqual({ kind: "unchanged", document: archived.document, }); expect(await adapter.documents.list(caller, "octo-org/score")).toEqual([]); expect(await adapter.documents.list(caller, "octo-org/score", true)).toEqual([ archived.document, ]); expect(await adapter.documents.read(caller, opened.channel.id)).toMatchObject({ id: opened.channel.id, archivedAt: archived.document.archivedAt, }); let restored = await adapter.restore.restore(caller, locator); expect(restored).toEqual({ kind: "restored", document: { id: opened.channel.id, title: "Release readiness" }, }); expect(await adapter.restore.restore(caller, opened.channel.id)).toEqual({ kind: "unchanged", document: { id: opened.channel.id, title: "Release readiness" }, }); }); it("coordinates archive callbacks after direct GitHub authorization", async () => { let context = setup(); let opened = await plan(context); await Service.close(opened.plan); let deleting = false; let transitions: string[] = []; let adapter = hosted(context.auth, undefined, { archiveChannel: async (channelId, now) => { transitions.push(`archive:${channelId}`); return context.storage.channels.archive({ id: channelId, now }); }, isChannelDeleting: channelId => deleting && channelId === opened.channel.id, restoreChannel: async (channelId, now) => { transitions.push(`restore:${channelId}`); return context.storage.channels.restore({ id: channelId, now }); }, }); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.archive || !adapter.rename || !adapter.restore) { throw new Error("hosted archive adapter is unavailable"); } expect(await adapter.archive.archive(caller, opened.channel.id)).toEqual({ kind: "forbidden", }); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: false, push: true, admin: false }, }; expect(await adapter.archive.archive(caller, opened.channel.id)).toEqual({ kind: "unavailable", }); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; expect(await adapter.archive.archive(caller, crypto.randomUUID())).toEqual({ kind: "unavailable", }); deleting = true; expect(await adapter.archive.archive(caller, opened.channel.id)).toEqual({ kind: "unavailable", }); expect( await adapter.rename.rename(caller, { id: opened.channel.id, title: "Unavailable rename", }), ).toEqual({ kind: "unavailable" }); deleting = false; expect(await adapter.archive.archive(caller, opened.channel.id)).toMatchObject({ kind: "archived", }); expect(await adapter.restore.restore(caller, opened.channel.id)).toMatchObject({ kind: "restored", }); expect(transitions).toEqual([ `archive:${opened.channel.id}`, `restore:${opened.channel.id}`, ]); }); it("creates a durable repository channel for a caller with write access", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); if (!adapter.create) throw new Error("hosted creation adapter is unavailable"); let result = await adapter.create.create(caller, creation); expect(result.kind).toBe("created"); if (result.kind !== "created") return; expect(result.document.id[14]).toBe("5"); let expected = { ...createdDocument(result.document.id), url: "/documents/octo-org/score/created-plan", }; expect(result.document).toEqual(expected); let stored = await context.storage.collaboration.load(result.document.id, context.now); if (!stored) throw new Error("created channel was not stored"); expect(await Service.readStored(stored)).toMatchObject({ creation: { brief: creation.brief, origin: expect.objectContaining({ idempotencyKey: creation.idempotencyKey, fingerprint: creation.fingerprint, }), }, }); expect(await adapter.documents.read(caller, result.document.id)).toEqual(expected); expect(await adapter.documents.read(caller, result.document.url)).toEqual(expected); expect(await adapter.documents.read(caller, `/channels/${result.document.id}`)) .toEqual(expected); expect( await adapter.documents.read(caller, `https://chopin.test/channels/${result.document.id}`), ).toEqual(expected); if (!adapter.rename) throw new Error("hosted rename adapter is unavailable"); await adapter.rename.rename(caller, { id: result.document.id, title: "Launch plan" }); expect(await adapter.documents.read(caller, result.document.url)).toEqual({ ...expected, title: "Launch plan", url: "/documents/octo-org/score/launch-plan", }); }); it("renames document metadata with current write access and announces real changes", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; await context.storage.users.put({ id: "U_allowed", login: "allowed", avatarUrl: "", now: context.now, }); let channel = await context.storage.channels.create({ id: crypto.randomUUID(), repositoryId: "R_score", repositoryOwner: "octo-org", repositoryName: "score", title: "Release plan", createdBy: "U_allowed", now: context.now, }); let announcements: string[] = []; let adapter = hosted(context.auth, undefined, { onChannelRenamed: renamed => announcements.push(renamed.title), }); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.rename) throw new Error("hosted rename adapter is unavailable"); let renamed = await adapter.rename.rename(caller, { id: channel.id, title: "Launch plan" }); expect(renamed).toEqual({ kind: "renamed", document: { id: channel.id, title: "Launch plan" }, }); expect((await context.storage.channels.get(channel.id))!.revision).toBe(channel.revision); expect(announcements).toEqual(["Launch plan"]); let repeated = await adapter.rename.rename(caller, { id: channel.id, title: "Launch plan" }); expect(repeated.kind).toBe("unchanged"); expect(announcements).toEqual(["Launch plan"]); await context.storage.channels.archive({ id: channel.id, now: context.now }); expect(await adapter.rename.rename(caller, { id: channel.id, title: "Archived plan" })) .toEqual({ kind: "archived" }); expect(announcements).toEqual(["Launch plan"]); }); it("refuses MCP renames without write access or a unique repository title", async () => { let context = setup(); await context.storage.users.put({ id: "U_allowed", login: "allowed", avatarUrl: "", now: context.now, }); let first = await context.storage.channels.create({ id: crypto.randomUUID(), repositoryId: "R_score", repositoryOwner: "octo-org", repositoryName: "score", title: "Release plan", createdBy: "U_allowed", now: context.now, }); await context.storage.channels.create({ ...first, id: crypto.randomUUID(), title: "Launch plan", now: context.now, }); let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.rename) throw new Error("hosted rename adapter is unavailable"); expect(await adapter.rename.rename(caller, { id: first.id, title: "Blocked" })).toEqual({ kind: "forbidden", }); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; expect(await adapter.rename.rename(caller, { id: first.id, title: "launch PLAN" })).toEqual({ kind: "conflict", }); context.github.accessible = false; expect(await adapter.rename.rename(caller, { id: first.id, title: "Hidden" })).toEqual({ kind: "unavailable", }); }); it("requires repository write access before creating a channel", async () => { let context = setup(); let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); if (!adapter.create) throw new Error("hosted creation adapter is unavailable"); expect(await adapter.create.create(caller, creation)).toEqual({ kind: "forbidden" }); expect((await context.storage.channels.scan("R_score", 10)).channels).toEqual([]); }); it("replays an accepted idempotent creation request", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); if (!adapter.create) throw new Error("hosted creation adapter is unavailable"); let first = await adapter.create.create(caller, creation); expect(first.kind).toBe("created"); if (first.kind !== "created") return; let archived = await context.storage.channels.archive({ id: first.document.id, now: context.now, }); expect(await adapter.create.create(caller, creation)).toEqual({ kind: "replayed", document: { ...createdDocument(first.document.id), archivedAt: archived.channel.archivedAt?.toISOString(), url: "/documents/octo-org/score/created-plan", }, }); expect((await context.storage.channels.get(first.document.id))?.archivedAt) .toEqual(archived.channel.archivedAt); }); it("rejects changed content under an accepted idempotency key", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); if (!adapter.create) throw new Error("hosted creation adapter is unavailable"); await adapter.create.create(caller, creation); expect( await adapter.create.create(caller, { ...creation, fingerprint: "changed-request", title: "Changed title", }), ).toEqual({ kind: "conflict" }); }); it("reports a title the repository already uses as title-taken, not an idempotency conflict", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); if (!adapter.create) throw new Error("hosted creation adapter is unavailable"); await adapter.create.create(caller, creation); expect( await adapter.create.create(caller, { ...creation, idempotencyKey: "another-request", fingerprint: "another-request", title: creation.title.toUpperCase(), }), ).toEqual({ kind: "title-taken" }); }); it("reconstructs a stored checkpoint and journal with the validated plan revision", async () => { let context = setup(); let opened = await plan(context); let mutation = Room.insertDecision(opened.plan.document, { id: ulid(), quote: "Ship the release", by: "allowed", at: "2026-08-17T12:00:00.000Z", notes: [{ by: "allowed", text: "The checks are green" }], }); if (!mutation) throw new Error("test mutation was empty"); await Service.publish(opened.plan, opened.server, opened.channel.id, mutation); let stored = await context.storage.collaboration.load(opened.channel.id, context.now); expect(stored?.updates).toHaveLength(1); let expectedSource = Service.source(opened.plan); let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); expect(await adapter.documents.read(caller, opened.channel.id)).toEqual({ id: opened.channel.id, title: "Release readiness", source: expectedSource, revision: 1, url: "/documents/octo-org/score/release-readiness", }); await Service.close(opened.plan); }); it("reads a child document by its nested canonical URL and refuses a mismatched parent", async () => { let context = setup(); let opened = await plan(context); let child = await context.storage.channels.create({ id: crypto.randomUUID(), repositoryId: "R_score", repositoryOwner: "octo-org", repositoryName: "score", title: "Rollback research", createdBy: "U_allowed", parentChannelId: opened.channel.id, now: context.now, }); let other = await context.storage.channels.create({ id: crypto.randomUUID(), repositoryId: "R_score", repositoryOwner: "octo-org", repositoryName: "score", title: "Unrelated plan", createdBy: "U_allowed", now: context.now, }); let childPlan = await Service.open(child.id, { storage: context.storage, lease: () => opened.lease, fatal: err => { throw err; }, }, opened.server); let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); let url = "/documents/octo-org/score/release-readiness/children/rollback-research"; try { expect(await adapter.documents.read(caller, child.id)).toMatchObject({ id: child.id, url }); expect(await adapter.documents.read(caller, url)).toMatchObject({ id: child.id, url }); expect(await adapter.documents.read(caller, `https://chopin.test${url}`)) .toMatchObject({ id: child.id, url }); expect( await adapter.documents.read( caller, `/documents/octo-org/score/${other.slug}/children/rollback-research`, ), ).toBeUndefined(); } finally { await Service.close(childPlan); await Service.close(opened.plan); } }); it("reads an open plan from its authoritative live document", async () => { let context = setup(); let opened = await plan(context); let mutation = Room.insertDecision(opened.plan.document, { id: ulid(), quote: "Live and not checkpointed", by: "allowed", at: "2026-08-17T12:00:00.000Z", notes: [{ by: "allowed", text: "Read the live document" }], }); if (!mutation) throw new Error("test mutation was empty"); opened.plan.revision = 9; let socket = { data: { room: opened.channel.id, client: "mcp-test" }, } as unknown as Socket; let live = Rooms.join(socket); live.plan = opened.plan; let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); try { expect(await adapter.documents.read(caller, opened.channel.id)).toEqual({ id: opened.channel.id, title: "Release readiness", source: Service.source(opened.plan), revision: 9, url: "/documents/octo-org/score/release-readiness", }); } finally { Rooms.forget(live); await Service.close(opened.plan); } }); it("reads a live created plan with its public brief but not provenance", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); if (!adapter.create) throw new Error("hosted creation adapter is unavailable"); let result = await adapter.create.create(caller, creation); if (result.kind !== "created") throw new Error("test plan was not created"); let lease = await context.storage.leases.acquire("writer", "mcp-test", 60_000); if (!lease) throw new Error("could not acquire test lease"); let server = { publish() {} } as unknown as Server; let opened = await Service.open(result.document.id, { storage: context.storage, lease: () => lease, fatal: error => { throw error; }, }, server); let socket = { data: { room: result.document.id, client: "mcp-test" }, } as unknown as Socket; let live = Rooms.join(socket); live.plan = opened; try { expect(await adapter.documents.read(caller, result.document.id)).toEqual({ ...createdDocument(result.document.id), url: "/documents/octo-org/score/created-plan", }); } finally { Rooms.forget(live); await Service.close(opened); } }); it("reports implemented and delivered lifecycle history for a live hosted plan", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let opened = await plan(context); opened.plan.creation = { brief: creation.brief, origin: { idempotencyKey: creation.idempotencyKey, fingerprint: creation.fingerprint, repository: creation.repository, baseBranch: creation.baseBranch, baseCommit: creation.baseCommit, title: creation.title, }, }; expect( (await implementationGraphs().revise(opened.plan, { planRevision: 0, graphRevision: 0, operations: [{ op: "add", task: claimTask }], })).ok, ).toBe(true); expect((await implementationGraphs().approve(opened.plan)).ok).toBe(true); let socket = { data: { room: opened.channel.id, client: "mcp-test" }, } as unknown as Socket; let live = Rooms.join(socket); live.plan = opened.plan; let serialized: string[] = []; let adapter = hosted(context.auth, { lease: () => opened.lease }, { serializeDocument: async (channelId, action) => { serialized.push(channelId); return action(); }, }); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.implementations) throw new Error("implementation adapter unavailable"); try { let claimed = await adapter.implementations.startImplementation(caller, { id: opened.channel.id, planRevision: 0, graphVersion: 1, graphRevision: 1, repository: "octo-org/score", branch: "tq/017", commit: "deadbeef", client: { name: "Codex", version: "1.2.3", session: "session-1" }, }); expect(claimed).toMatchObject({ kind: "started" }); if (claimed.kind !== "started") throw new Error("implementation was not claimed"); let report = adapter.implementations.reportLifecycle; if (!report) throw new Error("lifecycle adapter unavailable"); for ( let event of [ { id: opened.channel.id, kind: "start" as const, runId: claimed.run.id, taskId: "claim", idempotencyKey: "live-start", }, { id: opened.channel.id, kind: "report_pr" as const, runId: claimed.run.id, taskId: "claim", url: "https://github.com/octo-org/score/pull/49", state: "open" as const, idempotencyKey: "live-pr", }, { id: opened.channel.id, kind: "complete" as const, runId: claimed.run.id, taskId: "claim", summary: "The live graph is durable.", idempotencyKey: "live-complete", }, { id: opened.channel.id, kind: "report_verification" as const, runId: claimed.run.id, passed: true, summary: "The implementation passed review.", reviewerMethod: "Ran the focused implementation suite.", evidence: [{ taskId: "claim", evidence: ["Focused suite passed."] }], tasksNeedingWork: [], idempotencyKey: "live-verification", }, ] ) { let result = await report(caller, event); expect(result).toMatchObject({ kind: "accepted" }); if (event.kind === "report_verification") { expect(result).toMatchObject({ lifecycle: { execution: { state: "idle" }, history: [{ outcome: { kind: "implemented" } }], }, }); } } expect(opened.plan.execution).toBeUndefined(); expect(opened.plan.lifecycle.history[0]?.events.some(event => "runId" in event)).toBe(false); expect( await report(caller, { id: opened.channel.id, kind: "report_pr", runId: claimed.run.id, taskId: "claim", url: "https://github.com/octo-org/score/pull/49", state: "merged", idempotencyKey: "live-merge", }), ).toMatchObject({ kind: "accepted", lifecycle: { history: [{ outcome: { kind: "delivered" } }] }, }); expect(await adapter.implementations.readImplementation(caller, opened.channel.id)) .toMatchObject({ execution: { state: "idle" }, history: [{ outcome: { kind: "delivered" } }], }); expect(serialized).toEqual(Array.from({ length: 6 }, () => opened.channel.id)); } finally { Rooms.forget(live); await Service.close(opened.plan); } }); it("atomically stores one implementation claim for a closed hosted plan", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let opened = await plan(context); opened.plan.creation = { brief: creation.brief, origin: { idempotencyKey: creation.idempotencyKey, fingerprint: creation.fingerprint, repository: creation.repository, baseBranch: creation.baseBranch, baseCommit: creation.baseCommit, title: creation.title, }, }; let graph = await implementationGraphs().revise(opened.plan, { planRevision: 0, graphRevision: 0, operations: [{ op: "add", task: claimTask }], }); expect(graph.ok).toBe(true); expect((await implementationGraphs().approve(opened.plan)).ok).toBe(true); await Service.close(opened.plan); let adapter = hosted(context.auth, { lease: () => opened.lease }); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.implementations) throw new Error("implementation adapter unavailable"); let input = { id: opened.channel.id, planRevision: 0, graphVersion: 1, graphRevision: 1, repository: "octo-org/score", branch: "tq/017", commit: "deadbeef", client: { name: "Codex", version: "1.2.3", session: "session-1" }, }; expect( await adapter.implementations.startImplementation(caller, { ...input, graphVersion: 2, }), ).toEqual({ kind: "refused", reason: "run" }); let claimed = await adapter.implementations.startImplementation(caller, input); expect(claimed).toMatchObject({ kind: "started", run: { user: "allowed", client: { name: "Codex", version: "1.2.3" }, session: "session-1", }, }); if (claimed.kind !== "started") throw new Error("implementation was not claimed"); let stored = await context.storage.collaboration.load(opened.channel.id, context.now); if (!stored) throw new Error("claimed plan was not stored"); expect(await Service.readStored(stored)).toMatchObject({ graph: { versions: [{ state: "locked" }] }, execution: { branch: "tq/017", commit: "deadbeef" }, }); expect(await adapter.implementations.readImplementation(caller, opened.channel.id)) .toMatchObject({ graph: { state: "locked" }, execution: { state: "active", run: { session: "session-1" } }, }); expect( await adapter.implementations.readImplementation( caller, "/documents/octo-org/score/release-readiness", ), ).toMatchObject({ graph: { state: "locked" }, execution: { state: "active", run: { session: "session-1" } }, }); expect( await adapter.implementations.readImplementation( caller, `/channels/${opened.channel.id}`, ), ).toMatchObject({ graph: { state: "locked" } }); expect(await adapter.implementations.startImplementation(caller, input)).toMatchObject({ kind: "active", run: { session: "session-1" }, }); let archived = await context.storage.channels.archive({ id: opened.channel.id, now: context.now, }); expect(await adapter.implementations.readImplementation(caller, opened.channel.id)) .toMatchObject({ document: { archivedAt: archived.channel.archivedAt?.toISOString() }, execution: { state: "active" }, }); expect(await adapter.implementations.startImplementation(caller, input)).toEqual({ kind: "refused", reason: "document-archived", }); let report = adapter.implementations.reportLifecycle; expect(report).toBeTypeOf("function"); if (!report) return; let start = { id: opened.channel.id, kind: "start" as const, runId: claimed.run.id, taskId: "claim", idempotencyKey: "start-claim", }; expect(await report(caller, start)).toMatchObject({ kind: "accepted", lifecycle: { activity: { tasks: [{ id: "claim", state: "in_progress" }] }, }, }); expect(await report(caller, start)).toMatchObject({ kind: "replayed" }); let progressed = await context.storage.collaboration.load(opened.channel.id, context.now); if (!progressed) throw new Error("lifecycle progress was not stored"); expect((await Service.readStored(progressed)).lifecycle).toMatchObject({ events: [{ kind: "start", taskId: "claim", idempotencyKey: "start-claim" }], }); expect( await report(caller, { id: opened.channel.id, kind: "request_revision", runId: claimed.run.id, reason: "The graph needs another delivery step.", idempotencyKey: "request-revision", }), ).toMatchObject({ kind: "accepted", lifecycle: { execution: { state: "idle" }, history: [{ outcome: { kind: "revision_requested" } }], }, }); let released = await context.storage.collaboration.load(opened.channel.id, context.now); if (!released) throw new Error("released lifecycle was not stored"); let durable = await Service.readStored(released); expect(durable).toMatchObject({ graph: { versions: [{ state: "approved" }] }, }); expect(durable.lifecycle?.history[0]?.events.at(-1)).toMatchObject({ kind: "request_revision", reason: "The graph needs another delivery step.", }); expect(durable.lifecycle?.history[0]).not.toHaveProperty("outcome"); expect(durable.execution).toBeUndefined(); }); it("reports deleting, missing, and inaccessible implementation documents as unavailable", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let opened = await plan(context); await Service.close(opened.plan); let deleting = true; let adapter = hosted(context.auth, { lease: () => opened.lease }, { isChannelDeleting: channelId => deleting && channelId === opened.channel.id, }); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.implementations?.reportLifecycle) { throw new Error("implementation adapter unavailable"); } let input = { id: opened.channel.id, planRevision: 0, graphVersion: 1, graphRevision: 1, repository: "octo-org/score", branch: "tq/017", commit: "deadbeef", client: { name: "Codex", version: "1.2.3", session: "session-1" }, }; let report = { id: opened.channel.id, kind: "start" as const, runId: "run-1", taskId: "claim", idempotencyKey: "start-claim", }; expect(await adapter.implementations.startImplementation(caller, input)).toEqual({ kind: "unavailable", }); expect(await adapter.implementations.reportLifecycle(caller, report)).toEqual({ kind: "unavailable", }); deleting = false; let missingId = crypto.randomUUID(); expect( await adapter.implementations.startImplementation(caller, { ...input, id: missingId }), ).toEqual({ kind: "unavailable" }); expect( await adapter.implementations.reportLifecycle(caller, { ...report, id: missingId }), ).toEqual({ kind: "unavailable" }); context.github.accessible = false; expect(await adapter.implementations.startImplementation(caller, input)).toEqual({ kind: "unavailable", }); expect(await adapter.implementations.reportLifecycle(caller, report)).toEqual({ kind: "unavailable", }); }); it("refuses a verified graph but claims a new version for a closed hosted plan", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let opened = await plan(context); opened.plan.creation = { brief: creation.brief, origin: { idempotencyKey: creation.idempotencyKey, fingerprint: creation.fingerprint, repository: creation.repository, baseBranch: creation.baseBranch, baseCommit: creation.baseCommit, title: creation.title, }, }; expect( (await implementationGraphs().revise(opened.plan, { planRevision: 0, graphRevision: 0, operations: [{ op: "add", task: claimTask }], })).ok, ).toBe(true); expect((await implementationGraphs().approve(opened.plan)).ok).toBe(true); await Service.close(opened.plan); let adapter = hosted(context.auth, { lease: () => opened.lease }); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.implementations) throw new Error("implementation adapter unavailable"); let input = { id: opened.channel.id, planRevision: 0, graphVersion: 1, graphRevision: 1, repository: "octo-org/score", branch: "tq/017", commit: "deadbeef", client: { name: "Codex", version: "1.2.3", session: "session-1" }, }; let claimed = await adapter.implementations.startImplementation(caller, input); expect(claimed).toMatchObject({ kind: "started" }); if (claimed.kind !== "started") throw new Error("implementation was not claimed"); let report = adapter.implementations.reportLifecycle; if (!report) throw new Error("lifecycle adapter unavailable"); for ( let event of [ { id: opened.channel.id, kind: "start" as const, runId: claimed.run.id, taskId: "claim", idempotencyKey: "verified-start", }, { id: opened.channel.id, kind: "report_pr" as const, runId: claimed.run.id, taskId: "claim", url: "https://github.com/octo-org/score/pull/49", state: "open" as const, idempotencyKey: "verified-pr", }, { id: opened.channel.id, kind: "complete" as const, runId: claimed.run.id, taskId: "claim", summary: "The graph is durable.", idempotencyKey: "verified-complete", }, { id: opened.channel.id, kind: "report_verification" as const, runId: claimed.run.id, passed: true, summary: "The implementation passed review.", reviewerMethod: "Ran the focused implementation suite.", evidence: [{ taskId: "claim", evidence: ["Focused suite passed."] }], tasksNeedingWork: [], idempotencyKey: "verified-report", }, ] ) { expect(await report(caller, event)).toMatchObject({ kind: "accepted" }); } expect(await adapter.implementations.readImplementation(caller, opened.channel.id)) .toMatchObject({ execution: { state: "idle" }, history: [{ outcome: { kind: "implemented" }, progress: { verification: { passed: true } }, }], }); let verifiedStored = await context.storage.collaboration.load(opened.channel.id, context.now); if (!verifiedStored) throw new Error("verified lifecycle was not stored"); let verifiedDurable = await Service.readStored(verifiedStored); expect(verifiedDurable.execution).toBeUndefined(); expect(verifiedDurable.lifecycle?.history[0]?.events.at(-1)).toMatchObject({ kind: "report_verification", passed: true, }); expect(verifiedDurable.lifecycle?.history[0]?.events.some(event => "runId" in event)).toBe( false, ); expect( await adapter.implementations.startImplementation(caller, { ...input, client: { ...input.client, session: "session-2" }, }), ).toEqual({ kind: "refused", reason: "already-verified" }); let reopened = await Service.open(opened.channel.id, { storage: context.storage, lease: () => opened.lease, fatal: error => { throw error; }, }, opened.server); expect( (await implementationGraphs().revise(reopened, { planRevision: 0, graphRevision: 1, operations: [{ op: "replace", id: "claim", task: claimTask }], })).ok, ).toBe(true); expect((await implementationGraphs().approve(reopened)).ok).toBe(true); await Service.close(reopened); let newer = await adapter.implementations.startImplementation(caller, { ...input, graphVersion: 2, client: { ...input.client, session: "session-2" }, }); expect(newer).toMatchObject({ kind: "started" }); if (newer.kind !== "started") throw new Error("new implementation was not claimed"); let beforeMerge = await context.storage.collaboration.load(opened.channel.id, context.now); if (!beforeMerge) throw new Error("new implementation was not stored"); let beforeMergeState = await Service.readStored(beforeMerge); expect( await report(caller, { id: opened.channel.id, kind: "report_pr", runId: claimed.run.id, taskId: "claim", url: "https://github.com/octo-org/score/pull/49", state: "merged", idempotencyKey: "verified-merge", }), ).toMatchObject({ kind: "accepted", lifecycle: { execution: { state: "active" }, activity: { tasks: [{ id: "claim", state: "queued" }] }, history: [{ outcome: { kind: "delivered" } }], }, }); let mergedStored = await context.storage.collaboration.load(opened.channel.id, context.now); if (!mergedStored) throw new Error("delivered lifecycle was not stored"); let mergedState = await Service.readStored(mergedStored); expect(mergedState.execution).toEqual(beforeMergeState.execution); expect(mergedState.lifecycle?.events).toEqual(beforeMergeState.lifecycle?.events); expect(mergedState.lifecycle?.history[0]?.events.at(-1)).toMatchObject({ kind: "report_pr", state: "merged", }); }); it("makes an inaccessible channel indistinguishable from a missing channel", async () => { let context = setup(); let opened = await plan(context); await Service.close(opened.plan); let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); let missing = await adapter.documents.read(caller, crypto.randomUUID()); context.github.repositoryValue = { ...context.github.repositoryValue, id: "R_replaced", permissions: { pull: true, push: true, admin: true }, }; expect(await adapter.documents.read(caller, opened.channel.id)).toBe(missing); context.github.repositoryValue = { ...context.github.repositoryValue, id: "R_score", permissions: { pull: false, push: true, admin: true }, }; expect(await adapter.documents.read(caller, opened.channel.id)).toBe(missing); expect(missing).toBeUndefined(); }); it("treats malformed durable state as an absent channel", async () => { let context = setup(); let opened = await plan(context); await Service.close(opened.plan); let stored = await context.storage.collaboration.load(opened.channel.id, context.now); if (!stored?.snapshot) throw new Error("test channel has no checkpoint"); await context.storage.collaboration.commit({ channelId: opened.channel.id, lease: opened.lease, expectedRevision: stored.channel.revision, operationId: crypto.randomUUID(), epoch: stored.snapshot.epoch, sidecar: { version: 1, revision: 40 }, events: [], now: context.now, }); let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); expect(await adapter.documents.read(caller, opened.channel.id)).toBeUndefined(); }); it("treats an invalid open questionnaire as absent durable state", async () => { let context = setup(); let opened = await plan(context); await Service.close(opened.plan); let stored = await context.storage.collaboration.load(opened.channel.id, context.now); if (!stored?.snapshot) throw new Error("test channel has no checkpoint"); await context.storage.collaboration.commit({ channelId: opened.channel.id, lease: opened.lease, expectedRevision: stored.channel.revision, operationId: crypto.randomUUID(), epoch: stored.snapshot.epoch, sidecar: { version: 1, revision: 40, documentSeq: 0, questions: [{ id: "question-1", status: "open", definition: {} }], openQuestions: [{ id: "question-1", definition: {}, model: [], revision: -1, }], threads: [], transcript: [], }, events: [], now: context.now, }); let adapter = hosted(context.auth); let caller = await adapter.caller(request("Bearer allowed")); if (!caller) throw new Error("test caller was not authenticated"); expect(await adapter.documents.read(caller, opened.channel.id)).toBeUndefined(); }); it("rewrites a closed document, replays the original result, and conflicts on a changed key", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let opened = await plan(context); await Service.close(opened.plan); let adapter = hosted(context.auth, { lease: () => opened.lease }); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.update) throw new Error("hosted update adapter is unavailable"); let client = { name: "Codex", version: "1.2.3" }; let input = { id: opened.channel.id, revision: 0, plan: "# Revised\n\nUpdated prose.\n", idempotencyKey: "update-1", fingerprint: "same-request", }; let updated = await adapter.update.update(caller, input, client); expect(updated).toMatchObject({ kind: "updated", document: { id: opened.channel.id, source: "# Revised\n\nUpdated prose.\n", revision: 1, url: "/documents/octo-org/score/release-readiness", }, }); expect(await adapter.update.update(caller, { ...input, fingerprint: "changed" }, client)) .toEqual({ kind: "conflict" }); let later = await adapter.update.update(caller, { id: opened.channel.id, revision: 1, plan: "# Later\n", idempotencyKey: "update-2", fingerprint: "later-request", }, client); expect(later).toMatchObject({ kind: "updated", document: { revision: 2, source: "# Later\n" }, }); expect(await adapter.update.update(caller, input, client)).toMatchObject({ kind: "replayed", document: { source: "# Revised\n\nUpdated prose.\n", revision: 1, }, }); }); it("refuses a stale rewrite, a pull-only caller, and a locked implementation", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let opened = await plan(context); opened.plan.creation = { brief: creation.brief, origin: { idempotencyKey: creation.idempotencyKey, fingerprint: creation.fingerprint, repository: creation.repository, baseBranch: creation.baseBranch, baseCommit: creation.baseCommit, title: creation.title, }, }; expect( (await implementationGraphs().revise(opened.plan, { planRevision: 0, graphRevision: 0, operations: [{ op: "add", task: claimTask }], })).ok, ).toBe(true); expect((await implementationGraphs().approve(opened.plan)).ok).toBe(true); await Service.close(opened.plan); let adapter = hosted(context.auth, { lease: () => opened.lease }); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.update || !adapter.implementations) { throw new Error("hosted update adapter is unavailable"); } let client = { name: "Codex", version: "1.2.3" }; expect( await adapter.update.update(caller, { id: opened.channel.id, revision: 9, plan: "# Stale\n", idempotencyKey: "stale", fingerprint: "stale", }, client), ).toEqual({ kind: "revision-conflict", revision: 0 }); expect( await adapter.implementations.startImplementation(caller, { id: opened.channel.id, planRevision: 0, graphVersion: 1, graphRevision: 1, repository: "octo-org/score", branch: "tq/017", commit: "deadbeef", client: { name: "Codex", version: "1.2.3", session: "session-1" }, }), ).toMatchObject({ kind: "started" }); expect( await adapter.update.update(caller, { id: opened.channel.id, revision: 0, plan: "# Locked\n", idempotencyKey: "locked", fingerprint: "locked", }, client), ).toEqual({ kind: "locked" }); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: false, admin: false }, }; expect( await adapter.update.update(caller, { id: opened.channel.id, revision: 0, plan: "# Forbidden\n", idempotencyKey: "forbidden", fingerprint: "forbidden", }, client), ).toEqual({ kind: "forbidden" }); }); it("broadcasts live change marks after a durable rewrite and not a planner cursor", async () => { let context = setup(); context.github.repositoryValue = { ...context.github.repositoryValue, permissions: { pull: true, push: true, admin: false }, }; let frames: Array<{ kind?: string }> = []; let opened = await plan(context); opened.server = { publish(_topic: string, frame: string) { frames.push(JSON.parse(frame) as { kind?: string }); }, } as unknown as Server; opened.plan.server = opened.server; let socket = { data: { room: opened.channel.id, client: "mcp-test" }, } as unknown as Socket; let live = Rooms.join(socket); live.plan = opened.plan; let adapter = hosted(context.auth, { lease: () => opened.lease }); let caller = await adapter.caller(request("Bearer allowed")); if (!caller || !adapter.update) throw new Error("hosted update adapter is unavailable"); try { let updated = await adapter.update.update(caller, { id: opened.channel.id, revision: 0, plan: "# Live rewrite\n", idempotencyKey: "live-update", fingerprint: "live-update", }, { name: "Codex", version: "1.2.3" }); expect(updated).toMatchObject({ kind: "updated", document: { source: "# Live rewrite\n", revision: 1 }, }); expect(frames.map(frame => frame.kind)).toEqual([ "plan:update", "plan:changes", "plan:anchors", ]); expect(frames.some(frame => frame.kind === "plan:awareness")).toBe(false); expect(frames.find(frame => frame.kind === "plan:update")).toMatchObject({ agent: true }); let marked = frames.find(frame => frame.kind === "plan:changes") as | { changes: Array<{ attribution?: unknown }> } | undefined; expect(marked?.changes[0]?.attribution).toMatchObject({ client: { name: "Codex", version: "1.2.3" }, user: caller.user.login, }); expect(Service.source(opened.plan)).toBe("# Live rewrite\n"); } finally { Rooms.forget(live); await Service.close(opened.plan); } }); });