testOptionsProblem

tcmts.cli.mcp.testOptionsProblem · #z7u2igap · term

import { optionsProblem, schema } from "#codebase/tcmts/cli/mcp";
import assert from "node:assert/strict";

export const testOptionsProblem = () => {
  const s = schema(
    {
      args: { type: "array", items: { type: "string" } },
      live: { type: "boolean" },
      patches: {
        type: "array",
        items: schema({ name: { type: "string" }, edits: { type: "array" } }, ["name"]),
      },
    },
    ["args"],
  );
  assert.equal(optionsProblem("tcm_cli", s, { args: ["status"], live: true }), undefined);
  assert.equal(
    optionsProblem("tcm_cli", s, { args: ["add"], cwd: "repro" }, "ycaei6cxabc"),
    "tcm_cli has no `cwd` option in this build (#ycaei6cx): known are args, live, patches. Nothing was done.",
  );
  // inside an array of objects, by where it is; two at once
  const p = optionsProblem("tcm_patch", s, {
    patches: [{ name: "a" }, { name: "b", imports: [], all: true }],
    cwd: ".",
  })!;
  assert.equal(
    p,
    "tcm_patch has no `patches[1].imports`, `patches[1].all` or `cwd` options in this build: known in patches[1] are edits, name; known are args, live, patches. Nothing was done.",
  );
  // (what a schema leaves open stays open; a value of another shape is the tool's to say)
  assert.equal(optionsProblem("t", { type: "object", properties: {} }, { anything: 1 }), undefined);
  assert.equal(optionsProblem("tcm_cli", s, { args: "status", patches: [1] }), undefined);
}

uses