testAgentRunsAnOlderBuild

tcmts.cli.test.e2e.builds.testAgentRunsAnOlderBuild · #l3iqqach · term

An agent shows a test fails before the fix: tcm_test's bin takes a kept build's name ({"tcm": "previous"}), and tcm_cli's build runs a command with one, on a repro's codebase with cwd.

import { fakeBuild } from "#codebase/tcmts/cli/builds/test";
import { okIn, tcmBin, tempDir, withChildren } from "#codebase/tcmts/cli/test/e2e/harness";
import { sessionOf } 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 testAgentRunsAnOlderBuild = () =>
  withChildren(async (keep) => {
    const root = tempDir("builds mcp");
    fakeBuild(root, "known-good", "aaaaaaaa2222", 1);
    fakeBuild(root, "known-good-previous", "bbbbbbbb3333", 5);
    const dir = tempDir("builds mcp codebase");
    const repro = tempDir("builds mcp repro");
    okIn(dir, "init");
    fs.writeFileSync(
      path.join(dir, "scratch.ts"),
      `// tcm: namespace faketcm
export const main = (...args: string[]) => console.log(\`fixed: \${args.join(" ")}\`);
export const manifest = { name: "faketcm", bin: { tcm: "main" }, suites: { tcm: ["e2e"] } };
`,
    );
    okIn(dir, "add");
    fs.writeFileSync(
      path.join(dir, "scratch.ts"),
      `// tcm: namespace faketcm.e2e
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
export const testFixed = () => {
  const r = spawnSync(process.execPath, [process.env.TCM_BIN!, "go"], { encoding: "utf8" });
  assert.match(r.stdout, /^fixed: go/);
};
`,
    );
    okIn(dir, "add");
    const s = sessionOf(dir, keep, [tcmBin(), "mcp", "--direct"], { TCM_BUILDS: root });
    await s.request("initialize", {
      protocolVersion: "2025-06-18",
      capabilities: {},
      clientInfo: { name: "test", version: "0" },
    });
    // the codebase's own build passes; the one before the fix doesn't
    assert.match((await s.call("tcm_test", {})).text, /suites: 1 passed, 0 failed/);
    const before = await s.call("tcm_test", { bin: { tcm: "previous" } });
    assert.equal(before.isError, true);
    assert.match(before.text, /faketcm\.e2e\.testFixed[\s\S]*suites: 0 passed, 1 failed/);
    // a command, with a kept build, on a repro's codebase
    const ran = await s.call("tcm_cli", { args: ["view", "x"], build: "previous", cwd: repro });
    assert.equal(ran.isError, false, ran.text);
    assert.match(ran.text, /"says":"known-good-previous","args":\["view","x"\]/);
    assert.ok(ran.text.includes(JSON.stringify(repro).slice(1, -1)), ran.text);
    const unknown = await s.call("tcm_cli", { args: ["status"], build: "older" });
    assert.equal(unknown.isError, true);
    assert.match(unknown.text, /no build older: kept are known-good, previous/);
    s.close();
  })

uses