testSessionsStartingTogetherKeepTheirBranches

tcmts.cli.test.e2e.mcp.testSessionsStartingTogetherKeepTheirBranches · #qi3mn4tq · term

Sessions' servers starting together each get a branch of their own, and keep it: one starting doesn't clear away another's new branch as left behind (it's claimed, and cleared away, in a write transaction). A named branch another agent's server is on isn't shared: the second server says so and stops.

import { okIn, tcmBin, tempDir, withChildren } from "#codebase/tcmts/cli/test/e2e/harness";
import { hello, session, sessionOf, startedSession } from "#codebase/tcmts/cli/test/e2e/mcp";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

export const testSessionsStartingTogetherKeepTheirBranches = () =>
  withChildren(async (keep) => {
    const dir = tempDir("mcp together");
    const tcm = (...args: string[]) => okIn(dir, ...args);
    tcm("init");
    fs.rmSync(path.join(dir, "scratch.ts"), { force: true });
    const all = await Promise.all(Array.from({ length: 6 }, () => startedSession(dir, keep)));
    assert.equal(new Set(all.map((s) => s.branch)).size, all.length);
    const branches = tcm("branch");
    for (const s of all) {
      assert.match(branches, new RegExp(s.branch));
      const status = await s.call("tcm_status");
      assert.equal(status.isError, false, status.text);
      assert.doesNotMatch(status.text, /was gone/);
    }
    for (const s of all) s.close();

    const a = session(dir, keep, "--branch", "agent/x");
    await a.request("initialize", hello);
    const link = path.join(tempDir("mcp other worktree"), "codebase");
    fs.symlinkSync(dir, link);
    const b = sessionOf(link, keep, [tcmBin(), "mcp", "--branch", "agent/x"], { PWD: link });
    await assert.rejects(
      b.request("initialize", hello),
      /works on agent\/x: two servers don't share a branch/,
    );
    a.close();
  })

uses