import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import {
agentToken,
BASE,
body,
call,
MODERN,
patClient,
readSse,
seedToken,
seedWorld,
teardown,
toolText,
} from "./mcp-helpers";
import type { RpcReply, World } from "./mcp-helpers";
let world: World;
beforeAll(async () => {
world = await seedWorld();
}, 120_000);
afterAll(async () => {
await teardown(world);
});
describe("multi-agent coordination", () => {
test("two concurrent agents claiming overlapping files see each other's claims", async () => {
const [tokenA, tokenB] = await Promise.all([
agentToken(world, "agent-a", { contents: "write" }),
agentToken(world, "agent-b", { contents: "write" }),
]);
const a = patClient(tokenA, "agent-a");
const b = patClient(tokenB, "agent-b");
await Promise.all([a.client.connect(a.transport), b.client.connect(b.transport)]);
const [resultA, resultB] = await Promise.all([
call(a.client, "claim_files", { owner: world.owner, repo: world.repo, paths: ["src/"], ttl_seconds: 120 }),
call(b.client, "claim_files", {
owner: world.owner,
repo: world.repo,