diff --git a/scripts/hwlab-g14-contract-test.ts b/scripts/hwlab-g14-contract-test.ts index 7a587abf..ea14c6a7 100644 --- a/scripts/hwlab-g14-contract-test.ts +++ b/scripts/hwlab-g14-contract-test.ts @@ -1,4 +1,4 @@ -import { activeV02PipelineRuns, g14ObservabilityQueryAssertion, gitMirrorFlushJobManifest, gitMirrorStatusSummary, gitMirrorSyncJobManifest, gitMirrorV02SyncRequirement, hwlabG14Help, hwlabG14MonitorStateFileName, parseGitMirrorStatusRefs, parseK8sCpuMillicores, parseK8sMemoryMiB, parsePipelineTaskRunMetrics, parseV02TriggerSnapshot, rolloutRecordBody, semanticChangelogBullets, summarizeV02CdStatus, v02CloseoutVerdict, v02CommitAlignment, v02ControlPlaneRefreshScriptHash, v02ControlPlaneRenderScript, v02ExistingPipelineRunReuseDecision, v02FalseGreenGuard, v02GitMirrorPreSyncWaitMs, v02LatestOnlyTargetValidation, v02PipelineServiceIds, v02PrAutomationCommentBody, v02ReusableGitMirrorPreSyncMarker, v02ReusableRefreshMarker, v02TaskRunPerformanceSummary } from "./src/hwlab-g14"; +import { activeV02PipelineRuns, g14ObservabilityQueryAssertion, gitMirrorFlushJobManifest, gitMirrorStatusSummary, gitMirrorSyncJobManifest, gitMirrorV02SyncRequirement, hwlabG14Help, hwlabG14MonitorStateFileName, parseGitMirrorStatusRefs, parseK8sCpuMillicores, parseK8sMemoryMiB, parsePipelineTaskRunMetrics, parseV02TriggerSnapshot, rolloutRecordBody, semanticChangelogBullets, summarizeV02CdStatus, v02CloseoutVerdict, v02CommitAlignment, v02ControlPlaneRefreshScriptHash, v02ControlPlaneRenderScript, v02ExistingPipelineRunReuseDecision, v02FalseGreenGuard, v02GitMirrorPreSyncWaitMs, v02LatestOnlyTargetValidation, v02PipelineServiceIds, v02PrAutomationCommentBody, v02ReusableGitMirrorPreSyncMarker, v02ReusableRefreshMarker, v02StatusHistoryPolicy, v02TaskRunPerformanceSummary } from "./src/hwlab-g14"; import { runCommand } from "./src/command"; function assertCondition(condition: unknown, message: string, detail: unknown = {}): void { @@ -36,6 +36,7 @@ const hwlabHelpUsage = Array.isArray(hwlabG14Help().usage) ? hwlabG14Help().usag 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 status --lane v02 --history")) && hwlabHelpUsage.some((line) => line.includes("control-plane closeout --lane v02 --pipeline-run")) && 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")) @@ -557,6 +558,29 @@ assertCondition( "v0.2 active PipelineRun helper must accept the status.activePipelineRuns array shape", activeRunSummary, ); +const hiddenHistoryPolicy = v02StatusHistoryPolicy({ + activePipelineRuns: [], + history: { + included: false, + note: "recent PipelineRun history is hidden by default so old manifest/service-id failures do not pollute the current-target verdict; rerun with --history to inspect it", + command: "hwlab g14 control-plane status --lane v02 --history", + }, +}); +const explicitHistoryPolicy = v02StatusHistoryPolicy({ + activePipelineRuns: [], + recentPipelineRuns: { items: [{ name: "hwlab-v02-ci-poll-aaaaaaaaaaaa", status: "False" }] }, + history: { included: true }, +}); +assertCondition( + hiddenHistoryPolicy.included === false + && hiddenHistoryPolicy.recentPipelineRunsVisible === false + && hiddenHistoryPolicy.activePipelineRunsVisible === true + && String(hiddenHistoryPolicy.command).includes("--history") + && explicitHistoryPolicy.included === true + && explicitHistoryPolicy.recentPipelineRunsVisible === true, + "v0.2 status must hide historical PipelineRun lists by default and expose them only via --history", + { hiddenHistoryPolicy, explicitHistoryPolicy }, +); const falseGreenPassed = v02FalseGreenGuard({ sourceCommit: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", diff --git a/scripts/src/hwlab-g14.ts b/scripts/src/hwlab-g14.ts index b66e3f02..35cb63f5 100644 --- a/scripts/src/hwlab-g14.ts +++ b/scripts/src/hwlab-g14.ts @@ -138,6 +138,7 @@ interface G14ControlPlaneOptions { limit: number; sourceCommit?: string; pipelineRun?: string; + history: boolean; } type V02StatusTargetMode = "latest-source-head" | "source-commit" | "pipeline-run"; @@ -146,6 +147,7 @@ interface V02ControlPlaneStatusTarget { sourceCommit?: string | null; pipelineRun?: string | null; mode?: V02StatusTargetMode; + includeHistory?: boolean; } interface G14ToolsImageOptions { @@ -382,6 +384,7 @@ function parseControlPlaneOptions(args: string[]): G14ControlPlaneOptions { limit: positiveIntegerOption(args, "--limit", 20, 200), sourceCommit: sourceCommitRaw === undefined ? undefined : validateFullShaOption(sourceCommitRaw, "--source-commit"), pipelineRun: pipelineRunRaw === undefined ? undefined : validateV02PipelineRunOption(pipelineRunRaw), + history: args.includes("--history"), }; } @@ -2938,6 +2941,7 @@ function createV02PipelineRun(sourceCommit: string, timeoutSeconds: number): Com function v02ControlPlaneStatus(target: V02ControlPlaneStatusTarget = {}): Record { const targetMode: V02StatusTargetMode = target.mode ?? (target.pipelineRun !== undefined && target.pipelineRun !== null ? "pipeline-run" : target.sourceCommit !== undefined ? "source-commit" : "latest-source-head"); + const includeHistory = target.includeHistory === true; const strictHeadAlignment = targetMode === "latest-source-head"; const bundle = v02ControlPlaneStatusBundle({ ...target, mode: targetMode }); const sections = parseShellSections(statusText(bundle)); @@ -3135,7 +3139,16 @@ function v02ControlPlaneStatus(target: V02ControlPlaneStatusTarget = {}): Record falseGreenGuard, webAssets, activePipelineRuns, - recentPipelineRuns, + history: { + included: includeHistory, + activePipelineRunCount: activePipelineRuns.length, + recentPipelineRunCount: Array.isArray(recentPipelineRuns.items) ? recentPipelineRuns.items.length : 0, + note: includeHistory + ? "recentPipelineRuns is included because --history was requested; historical runs are diagnostic evidence, not the default current-target verdict" + : "recent PipelineRun history is hidden by default so old manifest/service-id failures do not pollute the current-target verdict; rerun with --history to inspect it", + command: statusCommand.includes("--history") ? statusCommand : `${statusCommand} --history`, + }, + ...(includeHistory ? { recentPipelineRuns } : {}), query: { ok: isCommandSuccess(bundle), exitCode: bundle.exitCode, @@ -3155,17 +3168,17 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record): Record record(item)).filter((item) => String(item.status ?? "") === "Unknown"); } +export function v02StatusHistoryPolicy(status: Record): Record { + const history = record(status.history); + return { + included: history.included === true, + recentPipelineRunsVisible: Object.hasOwn(status, "recentPipelineRuns"), + activePipelineRunsVisible: Object.hasOwn(status, "activePipelineRuns"), + note: history.note ?? null, + command: history.command ?? null, + }; +} + function v02PrCommentSignature(input: V02PrCommentInput): string { const summary = input.preflight ?? {}; const cd = input.cd ?? {}; @@ -7634,6 +7658,7 @@ export function hwlabG14Help(): Record { "bun scripts/cli.ts hwlab g14 monitor-prs --lane v02 --once --dry-run", "bun scripts/cli.ts hwlab g14 record-rollout --pr [--source-commit sha]", "bun scripts/cli.ts hwlab g14 control-plane status --lane v02", + "bun scripts/cli.ts hwlab g14 control-plane status --lane v02 --history", "bun scripts/cli.ts hwlab g14 control-plane status --lane v02 --pipeline-run hwlab-v02-ci-poll-", "bun scripts/cli.ts hwlab g14 control-plane status --lane v02 --source-commit ", "bun scripts/cli.ts hwlab g14 control-plane closeout --lane v02 --pipeline-run hwlab-v02-ci-poll-",