Files
pikasTech-unidesk/scripts/agentrun-cli-contract-test.ts
T
2026-06-11 00:41:20 +00:00

101 lines
4.9 KiB
TypeScript

import { readFileSync } from "node:fs";
import { agentRunHelp } from "./src/agentrun";
import { rootHelp } from "./src/help";
function assertCondition(condition: unknown, message: string, detail: unknown = {}): void {
if (!condition) throw new Error(`${message}: ${JSON.stringify(detail)}`);
}
const agentRunUsage = Array.isArray((agentRunHelp() as { usage?: unknown }).usage)
? ((agentRunHelp() as { usage: unknown[] }).usage).map(String)
: [];
assertCondition(
agentRunUsage.some((line) => line.includes("control-plane cleanup-runs --min-age-minutes 30 --limit 200 --dry-run"))
&& agentRunUsage.some((line) => line.includes("control-plane cleanup-runs --min-age-minutes 30 --limit 200 --confirm"))
&& agentRunUsage.some((line) => line.includes("control-plane cleanup-released-pvs --limit 200 --dry-run"))
&& agentRunUsage.some((line) => line.includes("control-plane cleanup-released-pvs --limit 200 --confirm")),
"AgentRun help must expose controlled CI workspace retention commands",
agentRunUsage,
);
assertCondition(
agentRunUsage.some((line) => line.includes("control-plane status --pipeline-run agentrun-v01-ci-<short-sha>"))
&& agentRunUsage.some((line) => line.includes("control-plane status --source-commit <full-sha>")),
"AgentRun help must expose targeted control-plane status drill-down options",
agentRunUsage,
);
assertCondition(
agentRunUsage.some((line) => line.includes("queue submit --json-stdin --dry-run"))
&& agentRunUsage.some((line) => line.includes("queue dispatch <taskId> --json-stdin --dry-run"))
&& agentRunUsage.some((line) => line.includes("queue commander --reader-id cli --limit 20")),
"AgentRun help must expose stdin-first queue dry-run and compact commander usage",
agentRunUsage,
);
assertCondition(
!agentRunUsage.some((line) => line.includes("agentrun v01")),
"AgentRun help must hide the v01 lane from user-facing CLI entrypoints",
agentRunUsage,
);
assertCondition(
agentRunUsage.some((line) => line.includes("queue show <taskId> --full"))
&& agentRunUsage.some((line) => line.includes("runs show <runId>"))
&& agentRunUsage.some((line) => line.includes("runs result <runId> --command-id <commandId>"))
&& agentRunUsage.some((line) => line.includes("commands show <commandId> --run-id <runId>"))
&& agentRunUsage.some((line) => line.includes("runner jobs --run-id <runId> --command-id <commandId>"))
&& agentRunUsage.some((line) => line.includes("runner job-status <runnerJobId> --run-id <runId>"))
&& !agentRunUsage.some((line) => line.includes("queue lifecycle")),
"AgentRun help must expose queue progressive disclosure through existing show/run/command/runner commands without a lifecycle command",
agentRunUsage,
);
const submitStdinIndex = agentRunUsage.findIndex((line) => line.includes("queue submit --json-stdin"));
const submitFileIndex = agentRunUsage.findIndex((line) => line.includes("queue submit --json-file"));
const dispatchStdinIndex = agentRunUsage.findIndex((line) => line.includes("queue dispatch <taskId> --json-stdin"));
const dispatchFileIndex = agentRunUsage.findIndex((line) => line.includes("queue dispatch <taskId> --json-file"));
assertCondition(
submitStdinIndex >= 0
&& dispatchStdinIndex >= 0
&& submitFileIndex > submitStdinIndex
&& dispatchFileIndex > dispatchStdinIndex
&& !agentRunUsage.some((line) => line.includes("queue submit --json-file <task.json> --dry-run"))
&& !agentRunUsage.some((line) => line.includes("queue dispatch <taskId> --json-file <dispatch.json> --dry-run")),
"AgentRun help must present heredoc/stdin before reusable file fallbacks",
agentRunUsage,
);
const globalHelp = JSON.stringify(rootHelp());
assertCondition(
globalHelp.includes("agentrun aipod-specs|queue|runs|commands|runner|sessions|control-plane|git-mirror"),
"global help must index AgentRun v0.1 entrypoints",
rootHelp(),
);
const agentRunSource = readFileSync("scripts/src/agentrun.ts", "utf8");
const runtimeJsonFallback = "\"node <<'NODE' || printf '{}\\\\n'\"";
assertCondition(
agentRunSource.includes(runtimeJsonFallback)
&& agentRunSource.includes("const sourceCommit = params.find((entry) => entry?.name === 'revision')?.value || null;"),
"AgentRun control-plane status must degrade empty runtime JSON snippets instead of failing the whole status probe",
);
console.log(JSON.stringify({
ok: true,
checks: [
"AgentRun command help exposes cleanup-runs and cleanup-released-pvs",
"AgentRun command help exposes targeted control-plane status drill-down options",
"AgentRun command help exposes queue dry-run and compact commander usage",
"AgentRun command help hides the v01 lane from user-facing CLI entrypoints",
"AgentRun command help exposes queue progressive disclosure without queue lifecycle",
"AgentRun command help presents heredoc/stdin before reusable file fallbacks",
"global help indexes AgentRun v0.1 entrypoints",
"AgentRun control-plane status degrades empty runtime JSON snippets",
],
}));