35 lines
1.6 KiB
TypeScript
35 lines
1.6 KiB
TypeScript
const sourceText = await Bun.file(new URL("./src/gc-remote.ts", import.meta.url)).text();
|
|
|
|
function assertCondition(condition: unknown, message: string, detail: unknown = {}): void {
|
|
if (!condition) throw new Error(`${message}: ${JSON.stringify(detail)}`);
|
|
}
|
|
|
|
function functionBody(name: string): string {
|
|
const marker = `def ${name}():`;
|
|
const start = sourceText.indexOf(marker);
|
|
if (start < 0) return "";
|
|
const next = sourceText.indexOf("\ndef ", start + marker.length);
|
|
return sourceText.slice(start, next < 0 ? sourceText.length : next);
|
|
}
|
|
|
|
for (const name of ["execute_registry_retention", "execute_registry_garbage_collect_only"]) {
|
|
const body = functionBody(name);
|
|
const suspendIndex = body.indexOf("patch_cronjob_suspend(name, True)");
|
|
const waitIndex = body.indexOf("idle_after_suspend = wait_no_active_hwlab_ci(180)");
|
|
const refusalIndex = body.indexOf("refusing registry maintenance because hwlab-ci did not become idle after suspend");
|
|
const preRefusalIndex = body.indexOf("refusing registry maintenance while hwlab-ci PipelineRun/TaskRun is active");
|
|
assertCondition(
|
|
suspendIndex >= 0 && waitIndex > suspendIndex && refusalIndex > waitIndex && preRefusalIndex < 0,
|
|
"registry maintenance must suspend poller CronJobs before refusing on active hwlab-ci objects",
|
|
{ name, suspendIndex, waitIndex, refusalIndex, preRefusalIndex },
|
|
);
|
|
}
|
|
|
|
console.log(JSON.stringify({
|
|
ok: true,
|
|
checks: [
|
|
"registry retention suspends poller CronJobs before active-CI idle wait",
|
|
"registry GC-only suspends poller CronJobs before active-CI idle wait",
|
|
],
|
|
}));
|