fix: recheck hwlab v02 head before reuse
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { gitMirrorFlushJobManifest, gitMirrorStatusSummary, gitMirrorSyncJobManifest, gitMirrorV02SyncRequirement, hwlabG14Help, hwlabG14MonitorStateFileName, parseGitMirrorStatusRefs, parsePipelineTaskRunMetrics, rolloutRecordBody, semanticChangelogBullets, v02CommitAlignment, v02ControlPlaneRefreshScriptHash, v02ControlPlaneRenderScript, v02FalseGreenGuard, v02LatestOnlyTargetValidation, v02PipelineServiceIds, v02PrAutomationCommentBody, v02ReusableGitMirrorPreSyncMarker, v02ReusableRefreshMarker, v02TaskRunPerformanceSummary } from "./src/hwlab-g14";
|
import { gitMirrorFlushJobManifest, gitMirrorStatusSummary, gitMirrorSyncJobManifest, gitMirrorV02SyncRequirement, hwlabG14Help, hwlabG14MonitorStateFileName, parseGitMirrorStatusRefs, parsePipelineTaskRunMetrics, rolloutRecordBody, semanticChangelogBullets, v02CommitAlignment, v02ControlPlaneRefreshScriptHash, v02ControlPlaneRenderScript, v02ExistingPipelineRunReuseDecision, v02FalseGreenGuard, v02LatestOnlyTargetValidation, v02PipelineServiceIds, v02PrAutomationCommentBody, v02ReusableGitMirrorPreSyncMarker, v02ReusableRefreshMarker, v02TaskRunPerformanceSummary } from "./src/hwlab-g14";
|
||||||
|
|
||||||
function assertCondition(condition: unknown, message: string, detail: unknown = {}): void {
|
function assertCondition(condition: unknown, message: string, detail: unknown = {}): void {
|
||||||
if (!condition) throw new Error(`${message}: ${JSON.stringify(detail)}`);
|
if (!condition) throw new Error(`${message}: ${JSON.stringify(detail)}`);
|
||||||
@@ -208,6 +208,31 @@ assertCondition(
|
|||||||
"v0.2 control-plane render must not use the fixed workspace checkout or its clean status",
|
"v0.2 control-plane render must not use the fixed workspace checkout or its clean status",
|
||||||
renderScript,
|
renderScript,
|
||||||
);
|
);
|
||||||
|
const existingPipelineRunReuse = v02ExistingPipelineRunReuseDecision({
|
||||||
|
sourceCommit: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
|
before: { exists: true, status: "True" },
|
||||||
|
latestSourceCommit: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
|
});
|
||||||
|
const existingPipelineRunFailed = v02ExistingPipelineRunReuseDecision({
|
||||||
|
sourceCommit: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
|
before: { exists: true, status: "False" },
|
||||||
|
latestSourceCommit: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
|
});
|
||||||
|
const existingPipelineRunHeadAdvanced = v02ExistingPipelineRunReuseDecision({
|
||||||
|
sourceCommit: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
|
before: { exists: true, status: "True" },
|
||||||
|
latestSourceCommit: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||||
|
});
|
||||||
|
assertCondition(
|
||||||
|
existingPipelineRunReuse.reusable === true
|
||||||
|
&& existingPipelineRunReuse.alreadyUsable === true
|
||||||
|
&& existingPipelineRunFailed.reusable === true
|
||||||
|
&& existingPipelineRunFailed.alreadyUsable === false
|
||||||
|
&& existingPipelineRunHeadAdvanced.reusable === false
|
||||||
|
&& existingPipelineRunHeadAdvanced.reason === "source-head-advanced-before-existing-pipelinerun-reuse",
|
||||||
|
"trigger-current must recheck latest v0.2 head before reusing an existing PipelineRun",
|
||||||
|
{ existingPipelineRunReuse, existingPipelineRunFailed, existingPipelineRunHeadAdvanced },
|
||||||
|
);
|
||||||
assertCondition(
|
assertCondition(
|
||||||
!v02PipelineServiceIds().includes("hwlab-cli"),
|
!v02PipelineServiceIds().includes("hwlab-cli"),
|
||||||
"v0.2 PipelineRun service matrix must not build hwlab-cli because cli is short-connection source tool",
|
"v0.2 PipelineRun service matrix must not build hwlab-cli because cli is short-connection source tool",
|
||||||
@@ -487,6 +512,7 @@ console.log(JSON.stringify({
|
|||||||
"v0.2 control-plane status help exposes targeted PipelineRun/source-commit inspection",
|
"v0.2 control-plane status help exposes targeted PipelineRun/source-commit inspection",
|
||||||
"v0.2 control-plane render uses an isolated temp clone from a CI/CD dedicated bare repo",
|
"v0.2 control-plane render uses an isolated temp clone from a CI/CD dedicated bare repo",
|
||||||
"v0.2 control-plane refresh marker only reuses recent same-contract refreshes",
|
"v0.2 control-plane refresh marker only reuses recent same-contract refreshes",
|
||||||
|
"trigger-current rechecks latest v0.2 head before reusing an existing PipelineRun",
|
||||||
"v0.2 status alignment reports stale-success without coupling CI to dirty workspace state",
|
"v0.2 status alignment reports stale-success without coupling CI to dirty workspace state",
|
||||||
"v0.2 PipelineRun service matrix excludes hwlab-cli",
|
"v0.2 PipelineRun service matrix excludes hwlab-cli",
|
||||||
"v0.2 false-green guard checks build TaskRuns, runtime artifact source commits, and reuse provenance",
|
"v0.2 false-green guard checks build TaskRuns, runtime artifact source commits, and reuse provenance",
|
||||||
|
|||||||
+97
-16
@@ -672,6 +672,36 @@ function v02PipelineRunName(sourceCommit: string): string {
|
|||||||
return `${V02_PIPELINERUN_PREFIX}-${shortSha(sourceCommit)}`;
|
return `${V02_PIPELINERUN_PREFIX}-${shortSha(sourceCommit)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function v02ExistingPipelineRunReuseDecision(input: {
|
||||||
|
sourceCommit: string;
|
||||||
|
before: Record<string, unknown>;
|
||||||
|
latestSourceCommit: string | null;
|
||||||
|
}): Record<string, unknown> {
|
||||||
|
const status = stringOrNull(input.before.status);
|
||||||
|
const exists = input.before.exists === true;
|
||||||
|
const latestSourceCommit = input.latestSourceCommit;
|
||||||
|
const alreadyUsable = exists && (status === "True" || status === "Unknown");
|
||||||
|
if (latestSourceCommit !== null && latestSourceCommit !== input.sourceCommit) {
|
||||||
|
return {
|
||||||
|
reusable: false,
|
||||||
|
alreadyUsable,
|
||||||
|
reason: "source-head-advanced-before-existing-pipelinerun-reuse",
|
||||||
|
sourceCommit: input.sourceCommit,
|
||||||
|
latestSourceCommit,
|
||||||
|
previousPipelineRun: v02PipelineRunName(input.sourceCommit),
|
||||||
|
latestPipelineRun: v02PipelineRunName(latestSourceCommit),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
reusable: exists && status !== null,
|
||||||
|
alreadyUsable,
|
||||||
|
reason: alreadyUsable ? "existing-pipelinerun-reused" : "existing-pipelinerun-terminal-failed",
|
||||||
|
sourceCommit: input.sourceCommit,
|
||||||
|
latestSourceCommit,
|
||||||
|
previousPipelineRun: v02PipelineRunName(input.sourceCommit),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function getPipelineRunCompact(name: string): Record<string, unknown> {
|
function getPipelineRunCompact(name: string): Record<string, unknown> {
|
||||||
const result = g14K3s([
|
const result = g14K3s([
|
||||||
"kubectl",
|
"kubectl",
|
||||||
@@ -2513,7 +2543,7 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record<string, unk
|
|||||||
if (options.action === "status" && options.pipelineRun !== undefined) return v02ControlPlaneStatus({ pipelineRun: options.pipelineRun, mode: "pipeline-run" });
|
if (options.action === "status" && options.pipelineRun !== undefined) return v02ControlPlaneStatus({ pipelineRun: options.pipelineRun, mode: "pipeline-run" });
|
||||||
if (options.action === "status" && options.sourceCommit !== undefined) return v02ControlPlaneStatus({ sourceCommit: options.sourceCommit, mode: "source-commit" });
|
if (options.action === "status" && options.sourceCommit !== undefined) return v02ControlPlaneStatus({ sourceCommit: options.sourceCommit, mode: "source-commit" });
|
||||||
const head = resolveV02Head();
|
const head = resolveV02Head();
|
||||||
const sourceCommit = head.sourceCommit;
|
let sourceCommit = head.sourceCommit;
|
||||||
if (sourceCommit === null) {
|
if (sourceCommit === null) {
|
||||||
return { ok: false, command: `hwlab g14 control-plane ${options.action} --lane v02`, degradedReason: "v02-head-unresolved", sourceRepo: V02_CICD_REPO, workspace: V02_WORKSPACE, headProbe: compactCommandResult(head.result) };
|
return { ok: false, command: `hwlab g14 control-plane ${options.action} --lane v02`, degradedReason: "v02-head-unresolved", sourceRepo: V02_CICD_REPO, workspace: V02_WORKSPACE, headProbe: compactCommandResult(head.result) };
|
||||||
}
|
}
|
||||||
@@ -2550,7 +2580,7 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record<string, unk
|
|||||||
: { triggerCurrent: "bun scripts/cli.ts hwlab g14 control-plane trigger-current --lane v02 --confirm" },
|
: { triggerCurrent: "bun scripts/cli.ts hwlab g14 control-plane trigger-current --lane v02 --confirm" },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const before = getPipelineRunCompact(v02PipelineRunName(sourceCommit));
|
let before = getPipelineRunCompact(v02PipelineRunName(sourceCommit));
|
||||||
if (options.dryRun) {
|
if (options.dryRun) {
|
||||||
const gitMirrorPreSync = preSyncV02GitMirror(sourceCommit, options);
|
const gitMirrorPreSync = preSyncV02GitMirror(sourceCommit, options);
|
||||||
return {
|
return {
|
||||||
@@ -2572,20 +2602,71 @@ function runV02ControlPlane(options: G14ControlPlaneOptions): Record<string, unk
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (before.exists === true && before.status !== null) {
|
if (before.exists === true && before.status !== null) {
|
||||||
const alreadyUsable = before.status === "True" || before.status === "Unknown";
|
const latestHead = resolveV02Head();
|
||||||
return {
|
const reuseDecision = v02ExistingPipelineRunReuseDecision({ sourceCommit, before, latestSourceCommit: latestHead.sourceCommit });
|
||||||
ok: alreadyUsable,
|
if (reuseDecision.reusable === true) {
|
||||||
command: "hwlab g14 control-plane trigger-current --lane v02",
|
const alreadyUsable = reuseDecision.alreadyUsable === true;
|
||||||
lane: "v02",
|
return {
|
||||||
mode: "confirmed-trigger",
|
ok: alreadyUsable,
|
||||||
sourceCommit,
|
command: "hwlab g14 control-plane trigger-current --lane v02",
|
||||||
pipelineRun: v02PipelineRunName(sourceCommit),
|
lane: "v02",
|
||||||
before,
|
mode: "confirmed-trigger",
|
||||||
skipped: true,
|
sourceCommit,
|
||||||
reason: alreadyUsable ? "existing-pipelinerun-reused" : "existing-pipelinerun-terminal-failed",
|
pipelineRun: v02PipelineRunName(sourceCommit),
|
||||||
degradedReason: alreadyUsable ? undefined : "existing-pipelinerun-terminal-failed",
|
before,
|
||||||
latestOnlyPolicy: "same source commit is idempotent; existing PipelineRun is never deleted or recreated by default",
|
skipped: true,
|
||||||
};
|
reuseDecision,
|
||||||
|
reason: reuseDecision.reason,
|
||||||
|
degradedReason: alreadyUsable ? undefined : "existing-pipelinerun-terminal-failed",
|
||||||
|
latestOnlyPolicy: "same source commit is idempotent; existing PipelineRun is never deleted or recreated by default; source head is rechecked before reuse",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (latestHead.sourceCommit !== null && latestHead.sourceCommit !== sourceCommit) {
|
||||||
|
printProgressEvent("hwlab.v02.trigger.progress", {
|
||||||
|
stage: "source-head-recheck",
|
||||||
|
status: "advanced",
|
||||||
|
sourceCommit,
|
||||||
|
latestSourceCommit: latestHead.sourceCommit,
|
||||||
|
previousPipelineRun: v02PipelineRunName(sourceCommit),
|
||||||
|
latestPipelineRun: v02PipelineRunName(latestHead.sourceCommit),
|
||||||
|
});
|
||||||
|
sourceCommit = latestHead.sourceCommit;
|
||||||
|
before = getPipelineRunCompact(v02PipelineRunName(sourceCommit));
|
||||||
|
if (before.exists === true && before.status !== null) {
|
||||||
|
const advancedAlreadyUsable = before.status === "True" || before.status === "Unknown";
|
||||||
|
return {
|
||||||
|
ok: advancedAlreadyUsable,
|
||||||
|
command: "hwlab g14 control-plane trigger-current --lane v02",
|
||||||
|
lane: "v02",
|
||||||
|
mode: "confirmed-trigger",
|
||||||
|
sourceCommit,
|
||||||
|
pipelineRun: v02PipelineRunName(sourceCommit),
|
||||||
|
before,
|
||||||
|
skipped: true,
|
||||||
|
reuseDecision: {
|
||||||
|
...reuseDecision,
|
||||||
|
advancedSourceCommit: sourceCommit,
|
||||||
|
advancedPipelineRun: v02PipelineRunName(sourceCommit),
|
||||||
|
advancedPipelineRunStatus: before.status ?? null,
|
||||||
|
},
|
||||||
|
reason: advancedAlreadyUsable ? "advanced-existing-pipelinerun-reused" : "advanced-existing-pipelinerun-terminal-failed",
|
||||||
|
degradedReason: advancedAlreadyUsable ? undefined : "advanced-existing-pipelinerun-terminal-failed",
|
||||||
|
latestOnlyPolicy: "same source commit is idempotent; existing PipelineRun is never deleted or recreated by default; source head is rechecked before reuse",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
command: "hwlab g14 control-plane trigger-current --lane v02",
|
||||||
|
lane: "v02",
|
||||||
|
mode: "confirmed-trigger",
|
||||||
|
sourceCommit,
|
||||||
|
pipelineRun: v02PipelineRunName(sourceCommit),
|
||||||
|
before,
|
||||||
|
reuseDecision,
|
||||||
|
degradedReason: "existing-pipelinerun-reuse-rejected",
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printProgressEvent("hwlab.v02.trigger.progress", { stage: "control-plane-refresh", status: "started", sourceCommit, pipelineRun: v02PipelineRunName(sourceCommit) });
|
printProgressEvent("hwlab.v02.trigger.progress", { stage: "control-plane-refresh", status: "started", sourceCommit, pipelineRun: v02PipelineRunName(sourceCommit) });
|
||||||
const controlPlaneRefresh = refreshV02ControlPlaneBeforeTrigger(sourceCommit, options.timeoutSeconds);
|
const controlPlaneRefresh = refreshV02ControlPlaneBeforeTrigger(sourceCommit, options.timeoutSeconds);
|
||||||
|
|||||||
Reference in New Issue
Block a user