testSlotWorkAndBudget

tcmts.cli.running.test.testSlotWorkAndBudget · #6dtvm2d4 · term

A slot's work is read as its kind, the codebase it's of (a directory with spaces in it too) and the branch, when it says them; and the machine's slots are TCM_SLOTS when that's set, else what its cores and memory make.

import { defaultSlots } from "#codebase/tcmts/cli/budget";
import { slotBudget, slotWork } from "#codebase/tcmts/cli/running";
import assert from "node:assert/strict";

export const testSlotWorkAndBudget = () => {
  assert.deepEqual(
    slotWork("tcm test of /Users/ada/Application Support/x/codebase on session/2026-11-04-d04041"),
    {
      kind: "tcm test",
      root: "/Users/ada/Application Support/x/codebase",
      branch: "session/2026-11-04-d04041",
    },
  );
  assert.deepEqual(slotWork("app build of /x/codebase"), {
    kind: "app build",
    root: "/x/codebase",
  });
  assert.deepEqual(slotWork("a process starting"), { kind: "a process starting" });
  const was = process.env.TCM_SLOTS;
  try {
    process.env.TCM_SLOTS = "3";
    assert.deepEqual([slotBudget().size, slotBudget().env], [3, "TCM_SLOTS"]);
    delete process.env.TCM_SLOTS;
    const b = slotBudget();
    assert.equal(b.env, undefined);
    assert.equal(b.size, defaultSlots(b.cpus, b.performance, b.memory));
    assert.equal(b.size, Math.max(2, Math.min(b.byCores, b.byMemory)));
  } finally {
    if (was === undefined) delete process.env.TCM_SLOTS;
    else process.env.TCM_SLOTS = was;
  }
}

uses