Files
OmniRoute/tests/unit/cli-catalog-counts.test.ts
Diego Rodrigues de Sa e Souza 624aba2498 feat(cli): add Grok Build CLI tool setup (~/.grok/config.toml) (#7241)
* feat(cli): add Grok Build CLI tool setup (~/.grok/config.toml)

Registers xAI's Grok Build TUI coding agent as a configurable CLI tool in
/dashboard/cli-code, so OmniRoute can write itself in as a custom model
provider in ~/.grok/config.toml.

Mechanism: Grok Build reads a TOML config that can hold several user-defined
[model.*] sections plus a [models].default pointer. Unlike the sibling Forge
handler (which owns its whole config file and can full-replace it), this one
surgically upserts ONLY the [model.omniroute] section and rewrites
[models].default, leaving every other section byte-intact. Apply records the
previous default in an `# omniroute-prev-default` marker comment so Reset can
restore the user's original default instead of guessing.

Built on OmniRoute's existing CLI-tools infrastructure rather than replaying
the upstream shape: getCliRuntimeStatus() for detection (no ad-hoc
`which grok` exec), Zod validation via cliModelConfigSchema, the write guard,
createBackup(), the cliToolState DB module, and sanitizeErrorMessage() for
every error path (Hard Rule #12).

Security: GET reaches getCliRuntimeStatus(), which spawns a child process to
locate and healthcheck the `grok` binary. That is the same transitive-spawn
surface that classified /api/skills/collect/, so the route is registered in
LOCAL_ONLY_API_PREFIXES and loopback-enforced before any auth check
(Hard Rules #15 + #17). Writing a local CLI's config file is inherently a
local-machine operation, so this costs no real capability.

Co-authored-by: rixzkiye <rizkiyemubarok05@gmail.com>
Inspired-by: https://github.com/decolua/9router/pull/2571

* chore(changelog): fragment for #7241

* fix(cli): shrink cliTools.ts/cliRuntime.ts under the file-size ratchet + fix stale catalog counts

The grok-build registry/runtime entries pushed cliTools.ts (916->932) and
cliRuntime.ts (1128->1137) past their frozen file-size caps. Extract the
grok-build entries into cliToolsGrokBuild.ts (registry, typed) and
cliRuntimeGrokBuild.ts (runtime metadata, deliberately untyped/no
cliCatalog import so it doesn't drag that schema file into the
typecheck:core curated allowlist's transitive graph). The amp runtime
entry rides along in the same runtime file for the extra headroom needed
to clear cliRuntime.ts's cap with zero slack.

Also update the two catalog-cardinality canaries (cli-tools-schema.test.ts,
cli-catalog-counts.test.ts) and EXPECTED_CODE_COUNT to include grok-build:
20->21 visible code entries, 24->25 total code entries, 32->33 grand total.

Fixes CI reds on #7241 surviving a release/v3.8.49 merge: Fast Quality
Gates (check:file-size) and Unit Tests fast-path (1/4, 2/4).

* test(stryker): register grok-build route-guard test in tap.testFiles

check:mutation-test-coverage --strict flagged
tests/unit/route-guard-grok-build-settings-local-only.test.ts as a covering
unit test for src/server/authz/routeGuard.ts missing from
stryker.conf.json's tap.testFiles allowlist (only became reachable once the
Fast Quality Gates job got past the file-size fix earlier in this branch).

---------

Co-authored-by: rixzkiye <rizkiyemubarok05@gmail.com>
2026-07-17 10:40:41 -03:00

121 lines
3.7 KiB
TypeScript

/**
* F1: cli-catalog-counts.test.ts
* Assert catalog cardinality per plan 14 D15 / §3.1-§3.2.
*/
import test from "node:test";
import assert from "node:assert/strict";
const { CLI_TOOLS } = await import("../../src/shared/constants/cliTools.ts");
const { EXPECTED_CODE_COUNT, EXPECTED_AGENT_COUNT } =
await import("../../src/shared/schemas/cliCatalog.ts");
const all = Object.values(CLI_TOOLS);
const codeAll = all.filter((t) => t.category === "code");
const agentAll = all.filter((t) => t.category === "agent");
const codeVisible = codeAll.filter((t) => t.baseUrlSupport !== "none");
test(`CLI_TOOLS has exactly ${EXPECTED_CODE_COUNT} code entries with baseUrlSupport !== 'none'`, () => {
assert.equal(
codeVisible.length,
EXPECTED_CODE_COUNT,
`Expected ${EXPECTED_CODE_COUNT} visible code entries, got ${codeVisible.length}: ${codeVisible.map((t) => t.id).join(", ")}`
);
});
test(`CLI_TOOLS has exactly ${EXPECTED_AGENT_COUNT} agent entries`, () => {
assert.equal(
agentAll.length,
EXPECTED_AGENT_COUNT,
`Expected ${EXPECTED_AGENT_COUNT} agent entries, got ${agentAll.length}: ${agentAll.map((t) => t.id).join(", ")}`
);
});
test("CLI_TOOLS total code entries (including none) equals 25 (21 visible + 4 none)", () => {
// code-none entries: antigravity, kiro, cursor (app), hermes (simple guide)
const codeNone = codeAll.filter((t) => t.baseUrlSupport === "none");
assert.equal(
codeNone.length,
4,
`Expected 4 code entries with baseUrlSupport='none', got ${codeNone.length}: ${codeNone.map((t) => t.id).join(", ")}`
);
assert.equal(codeAll.length, 25, `Expected 25 total code entries, got ${codeAll.length}`);
});
test("CLI_TOOLS total (code + agent) = 33", () => {
assert.equal(all.length, 33, `Expected 33 total entries, got ${all.length}`);
});
test("All code-none entries have configType mitm OR are legacy excluded entries", () => {
const codeNone = codeAll.filter((t) => t.baseUrlSupport === "none");
const allowedIds = new Set(["antigravity", "kiro", "cursor", "hermes"]);
for (const entry of codeNone) {
assert.ok(
allowedIds.has(entry.id),
`Unexpected code entry with baseUrlSupport='none': ${entry.id}`
);
}
});
test("All agent entries have baseUrlSupport 'full' or 'partial' (no agent is 'none')", () => {
for (const entry of agentAll) {
assert.notEqual(
entry.baseUrlSupport,
"none",
`Agent entry '${entry.id}' has unexpected baseUrlSupport='none'`
);
}
});
test("The 21 visible code entries match D15 list exactly (+ crush + codewhale + grok-build)", () => {
const d15List = new Set([
"claude",
"codex",
"cline",
"kilo",
"roo",
"continue",
"qwen",
"aider",
"forge",
"jcode",
"deepseek-tui",
"codewhale",
"opencode",
"droid",
"copilot",
"cursor-cli",
"smelt",
"pi",
"custom",
"crush",
"grok-build",
]);
const visibleIds = new Set(codeVisible.map((t) => t.id));
for (const id of d15List) {
assert.ok(visibleIds.has(id), `D15 entry '${id}' not found in visible code list`);
}
for (const id of visibleIds) {
assert.ok(d15List.has(id), `Visible code entry '${id}' not in D15 list`);
}
});
test("The 8 agent entries match D15 list exactly (+ omp + letta, #6318)", () => {
const d15Agents = new Set([
"hermes-agent",
"openclaw",
"goose",
"interpreter",
"warp",
"agent-deck",
"omp",
"letta",
]);
const agentIds = new Set(agentAll.map((t) => t.id));
for (const id of d15Agents) {
assert.ok(agentIds.has(id), `D15 agent '${id}' not found in agent entries`);
}
for (const id of agentIds) {
assert.ok(d15Agents.has(id), `Agent entry '${id}' not in D15 agent list`);
}
});