diff --git a/scripts/agentrun-cli-contract-test.ts b/scripts/agentrun-cli-contract-test.ts index b4ee5995..602fccca 100644 --- a/scripts/agentrun-cli-contract-test.ts +++ b/scripts/agentrun-cli-contract-test.ts @@ -1,3 +1,4 @@ +import { readFileSync } from "node:fs"; import { agentRunHelp } from "./src/agentrun"; import { rootHelp } from "./src/help"; @@ -21,15 +22,30 @@ assertCondition( const globalHelp = JSON.stringify(rootHelp()); assertCondition( - globalHelp.includes("agentrun v01 control-plane status|trigger-current|refresh|cleanup-runs|cleanup-released-pvs"), - "global help must index AgentRun cleanup entrypoints", + globalHelp.includes("agentrun v01 queue|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'\""; + +function statusScriptSection(label: string): string { + const start = agentRunSource.indexOf(`printf '${label}='`); + return start >= 0 ? agentRunSource.slice(start, start + 500) : ""; +} + +assertCondition( + statusScriptSection("pipelineRunCondition").includes(runtimeJsonFallback) + && statusScriptSection("ciSummary").includes(runtimeJsonFallback), + "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", - "global help indexes AgentRun cleanup entrypoints", + "global help indexes AgentRun v0.1 entrypoints", + "AgentRun control-plane status degrades empty runtime JSON snippets", ], })); diff --git a/scripts/src/agentrun.ts b/scripts/src/agentrun.ts index ce7ed338..924ee7ca 100644 --- a/scripts/src/agentrun.ts +++ b/scripts/src/agentrun.ts @@ -915,7 +915,7 @@ function statusScript(pipelineRun: string | null): string { pr.length > 0 ? [ `if kubectl -n ${ciNamespace} get pipelinerun ${shQuote(pr)} -o json >/tmp/agentrun-v01-pipelinerun.json 2>/dev/null; then`, - "node <<'NODE'", + "node <<'NODE' || printf '{}\\n'", "const fs = require('node:fs');", "const pr = JSON.parse(fs.readFileSync('/tmp/agentrun-v01-pipelinerun.json', 'utf8'));", "const condition = pr?.status?.conditions?.[0] || {};", @@ -945,7 +945,7 @@ function statusScript(pipelineRun: string | null): string { pr.length > 0 ? [ `if kubectl -n ${ciNamespace} get taskrun -l tekton.dev/pipelineRun=${shQuote(pr)} -o json >/tmp/agentrun-v01-taskruns.json 2>/dev/null; then`, - "node <<'NODE'", + "node <<'NODE' || printf '{}\\n'", "const fs = require('node:fs');", "const data = JSON.parse(fs.readFileSync('/tmp/agentrun-v01-taskruns.json', 'utf8'));", "const items = Array.isArray(data.items) ? data.items : [];",