diff --git a/scripts/g14-gitops-render.mjs b/scripts/g14-gitops-render.mjs index 2008c0a2..1bae54e9 100644 --- a/scripts/g14-gitops-render.mjs +++ b/scripts/g14-gitops-render.mjs @@ -2,7 +2,7 @@ import assert from "node:assert/strict"; import { execFile } from "node:child_process"; import { createHash } from "node:crypto"; -import { mkdir, readFile, writeFile } from "node:fs/promises"; +import { mkdir, readFile, rm, writeFile } from "node:fs/promises"; import path from "node:path"; import { promisify } from "node:util"; import { fileURLToPath } from "node:url"; @@ -3314,6 +3314,13 @@ async function writeFiles(files) { } } +async function cleanStaleGeneratedOutput(args) { + if (args.lane !== "v02") return; + for (const relativePath of ["runtime-v02", "tekton-v02"]) { + await rm(generatedPath(path.join(args.outDir, relativePath)), { recursive: true, force: true }); + } +} + async function checkFiles(files) { const mismatches = []; for (const [filePath, expected] of files) { @@ -3342,7 +3349,10 @@ async function main() { process.exitCode = mismatches.length === 0 ? 0 : 1; return; } - if (args.write) await writeFiles(files); + if (args.write) { + await cleanStaleGeneratedOutput(args); + await writeFiles(files); + } console.log(JSON.stringify({ ok: true, sourceCommit: source.full, sourceShort: source.short, outDir: args.outDir, files: [...files.keys()] }, null, 2)); } diff --git a/scripts/g14-gitops-render.test.ts b/scripts/g14-gitops-render.test.ts index d59688c2..795490f8 100644 --- a/scripts/g14-gitops-render.test.ts +++ b/scripts/g14-gitops-render.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; -import { mkdtemp, readFile, rm } from "node:fs/promises"; +import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import test from "node:test"; @@ -18,6 +18,13 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots assert.equal(head.status, 0, head.stderr || head.stdout); const sourceRevision = head.stdout.trim(); + const staleRuntimeFile = path.join(outDir, "runtime-v02", "stale-gateway-simu.yaml"); + const staleTektonFile = path.join(outDir, "tekton-v02", "stale-router.yaml"); + await mkdir(path.dirname(staleRuntimeFile), { recursive: true }); + await mkdir(path.dirname(staleTektonFile), { recursive: true }); + await writeFile(staleRuntimeFile, "kind: Service\nmetadata:\n name: hwlab-gateway-simu\n"); + await writeFile(staleTektonFile, "hwlab-router\n"); + const render = spawnSync(process.execPath, [ "scripts/g14-gitops-render.mjs", "--lane", "v02", @@ -29,6 +36,8 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots "--source-revision", "HEAD" ], { cwd: process.cwd(), encoding: "utf8" }); assert.equal(render.status, 0, render.stderr || render.stdout); + await assert.rejects(() => readFile(staleRuntimeFile, "utf8"), { code: "ENOENT" }); + await assert.rejects(() => readFile(staleTektonFile, "utf8"), { code: "ENOENT" }); const pipeline = await readFile(path.join(outDir, "tekton-v02", "pipeline.yaml"), "utf8"); const pipelineJson = JSON.parse(pipeline);