From 096eb0cb9d0b6fe1083b9f177eb99cf63283b0e9 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 5 Jun 2026 09:58:34 +0000 Subject: [PATCH] fix: target hwlab v02 pipelinerun cleanup --- scripts/hwlab-g14-contract-test.ts | 6 +++-- scripts/src/hwlab-g14.ts | 43 +++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/scripts/hwlab-g14-contract-test.ts b/scripts/hwlab-g14-contract-test.ts index 3aef1e80..9b308e6f 100644 --- a/scripts/hwlab-g14-contract-test.ts +++ b/scripts/hwlab-g14-contract-test.ts @@ -37,8 +37,10 @@ assertCondition( hwlabHelpUsage.some((line) => line.includes("control-plane status --lane v02 --pipeline-run")) && hwlabHelpUsage.some((line) => line.includes("control-plane status --lane v02 --source-commit")) && hwlabHelpUsage.some((line) => line.includes("control-plane closeout --lane v02 --pipeline-run")) - && hwlabHelpUsage.some((line) => line.includes("control-plane closeout --lane v02 --source-commit")), - "v0.2 control-plane help must expose targeted PipelineRun/source-commit status and closeout inspection", + && hwlabHelpUsage.some((line) => line.includes("control-plane closeout --lane v02 --source-commit")) + && hwlabHelpUsage.some((line) => line.includes("control-plane cleanup-runs --lane v02 --pipeline-run")) + && hwlabHelpUsage.some((line) => line.includes("control-plane cleanup-runs --lane v02 --source-commit")), + "v0.2 control-plane help must expose targeted PipelineRun/source-commit status, closeout inspection, and cleanup", hwlabHelpUsage, ); assertCondition( diff --git a/scripts/src/hwlab-g14.ts b/scripts/src/hwlab-g14.ts index bad0a6f2..ca3361f0 100644 --- a/scripts/src/hwlab-g14.ts +++ b/scripts/src/hwlab-g14.ts @@ -360,13 +360,13 @@ function parseControlPlaneOptions(args: string[]): G14ControlPlaneOptions { if (allowLiveDbRead && actionRaw !== "runtime-migration") throw new Error("--allow-live-db-read is only valid for control-plane runtime-migration"); const sourceCommitRaw = optionValue(args, "--source-commit"); const pipelineRunRaw = optionValue(args, "--pipeline-run"); - if ((sourceCommitRaw !== undefined || pipelineRunRaw !== undefined) && actionRaw !== "status" && actionRaw !== "closeout") { - throw new Error("--source-commit and --pipeline-run are only valid for control-plane status/closeout"); + if ((sourceCommitRaw !== undefined || pipelineRunRaw !== undefined) && actionRaw !== "status" && actionRaw !== "closeout" && actionRaw !== "cleanup-runs") { + throw new Error("--source-commit and --pipeline-run are only valid for control-plane status/closeout/cleanup-runs"); } if (actionRaw === "closeout" && sourceCommitRaw === undefined && pipelineRunRaw === undefined) { throw new Error("control-plane closeout requires --source-commit or --pipeline-run hwlab-v02-ci-poll-"); } - if (sourceCommitRaw !== undefined && pipelineRunRaw !== undefined) throw new Error("control-plane status/closeout accepts only one of --source-commit or --pipeline-run"); + if (sourceCommitRaw !== undefined && pipelineRunRaw !== undefined) throw new Error("control-plane status/closeout/cleanup-runs accepts only one of --source-commit or --pipeline-run"); return { action: actionRaw, lane, @@ -2206,9 +2206,10 @@ function listCleanupPipelineRuns(options: G14ControlPlaneOptions): Record line.trim()) .filter(Boolean) @@ -2219,10 +2220,22 @@ function listCleanupPipelineRuns(options: G14ControlPlaneOptions): Record item.name.length > 0 && prefixes.some((prefix) => item.name.startsWith(prefix))) + .filter((item) => targetPipelineRun === undefined || item.name === targetPipelineRun) .filter((item) => item.status === "True" || item.status === "False") .filter((item) => typeof item.ageMinutes === "number" && item.ageMinutes >= options.minAgeMinutes) .sort((a, b) => String(a.createdAt).localeCompare(String(b.createdAt))) .slice(0, options.limit); + if (targetPipelineRun !== undefined && candidates.length === 0) { + return [{ + name: targetPipelineRun, + createdAt: null, + ageMinutes: null, + status: null, + reason: "target-pipelinerun-not-found-or-not-terminal", + selected: false, + }]; + } + return candidates; } function listOwnedWorkspacePvcs(pipelineRunNames: string[]): Record[] { @@ -2412,7 +2425,9 @@ function runV02RuntimeMigration(options: G14ControlPlaneOptions, sourceCommit: s function runControlPlaneCleanup(options: G14ControlPlaneOptions): Record { const candidates = listCleanupPipelineRuns(options); - const candidateNames = candidates.map((item) => String(item.name)); + const candidateNames = candidates + .filter((item) => item.selected !== false) + .map((item) => String(item.name)); const ownedPvcs = listOwnedWorkspacePvcs(candidateNames); if (options.dryRun) { return { @@ -2422,12 +2437,24 @@ function runControlPlaneCleanup(options: G14ControlPlaneOptions): Record { "bun scripts/cli.ts hwlab g14 control-plane trigger-current --lane v02 --confirm --wait", "bun scripts/cli.ts hwlab g14 control-plane cleanup-runs --lane v02 --min-age-minutes 30 --limit 20 --dry-run", "bun scripts/cli.ts hwlab g14 control-plane cleanup-runs --lane v02 --min-age-minutes 30 --limit 20 --confirm", + "bun scripts/cli.ts hwlab g14 control-plane cleanup-runs --lane v02 --pipeline-run hwlab-v02-ci-poll- --dry-run", + "bun scripts/cli.ts hwlab g14 control-plane cleanup-runs --lane v02 --source-commit --confirm", "bun scripts/cli.ts hwlab g14 control-plane cleanup-released-pvs --lane all --limit 20 --dry-run", "bun scripts/cli.ts hwlab g14 control-plane cleanup-released-pvs --lane all --limit 20 --confirm", "bun scripts/cli.ts hwlab g14 control-plane runtime-migration --lane v02 --dry-run",