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); } assertCondition( sourceText.includes('if (subaction === "snapshot" || subaction === "growth")') && sourceText.includes('if (subaction === "trend")') && sourceText.includes('supportedActions: ["plan", "snapshot", "trend", "run", "status"]'), "gc remote must expose snapshot/growth and trend actions", ); assertCondition( sourceText.includes("historyLimit: number") && sourceText.includes("saveSnapshot: boolean") && sourceText.includes("--history-limit") && sourceText.includes("--no-save"), "gc remote snapshot must expose bounded history and no-save options", ); const snapshotBody = functionBody("collect_growth_snapshot"); assertCondition( snapshotBody.includes('"action": "gc remote snapshot"') && snapshotBody.includes('"diagnosticStateMutation"') && snapshotBody.includes("disk_source_snapshot()") && snapshotBody.includes("ci_storage_snapshot()") && snapshotBody.includes("registry_growth_snapshot()") && snapshotBody.includes("containerd_breakdown_snapshot()"), "growth snapshot must include disk sources, CI PVC ownership, registry, containerd and diagnostic-state disclosure", snapshotBody.slice(0, 1200), ); const storageBody = functionBody("ci_storage_snapshot"); assertCondition( storageBody.includes('"hwlab"') && storageBody.includes('"agentrun"') && storageBody.includes('"byOwnerGroup"') && storageBody.includes("hwlab g14 control-plane cleanup-runs") && storageBody.includes("agentrun control-plane cleanup-runs") && storageBody.includes("hostPath") && storageBody.includes("activeMountPods") && storageBody.includes("estimatedBytes") && storageBody.includes('phase in set(["Succeeded", "Failed"])'), "CI storage snapshot must keep HWLAB and AgentRun owner handoff plus reclaim visibility", storageBody.slice(0, 1600), ); const registryBody = functionBody("registry_growth_snapshot"); assertCondition( registryBody.includes('"dryRun": "daily or before/after every v0.2 CI/CD burst"') && registryBody.includes('"maintenanceRun": "weekly, or when root >=80%, or when registry growth exceeds the agreed daily threshold"') && registryBody.includes("plan_registry_retention()") && registryBody.includes("protected tags") && registryBody.includes("newest N tags per repo"), "registry growth snapshot must disclose dry-run cadence, maintenance trigger and retention protections", registryBody, ); const containerdBody = functionBody("containerd_breakdown_snapshot"); assertCondition( containerdBody.includes('"state": "observation-only"') && containerdBody.includes('"cleanupSupported": False') && containerdBody.includes("reference-safe image/content classifier"), "containerd section must stay observation-only until a safe classifier exists", containerdBody, ); const trendBody = functionBody("growth_trend_payload"); assertCondition( trendBody.includes('"latestDelta"') && trendBody.includes('"windowDelta"') && trendBody.includes('"short-window-rate-noisy"') && trendBody.includes('"topGrowingBytes"') && trendBody.includes('"registryCounters"'), "growth trend must expose latest/window delta and registry counters", trendBody, ); const compactPointBody = functionBody("compact_growth_point"); assertCondition( compactPointBody.includes('"sourceCount"') && compactPointBody.includes('"registry"') && compactPointBody.includes('"ciStorage"') && compactPointBody.includes('"containerd"') && sourceText.includes("[compact_growth_point(item) for item in history[-min(len(history), 3):]]"), "growth trend must default to compact history points unless --full is requested", compactPointBody, ); console.log(JSON.stringify({ ok: true, checks: [ "gc remote exposes snapshot/growth and trend actions", "snapshot history is bounded and can be disabled with --no-save", "snapshot includes source sizes, owner-aware CI PVCs, registry cadence and containerd observation", "HWLAB and AgentRun retention handoff commands are explicit", "trend includes latest/window deltas and registry counters", "trend returns compact history points by default", ], }));