Skip to content

OTHER-3: Sprout image-cleanup consolidation - #296

Merged
simpros merged 1 commit into
mainfrom
feat-other-3-image-cleanup
Nov 19, 2026
Merged

simpros merged 1 commit into
mainfrom
feat-other-3-image-cleanup

Conversation

@simpros

@simpros simpros commented Nov 19, 2026

Copy link
Copy Markdown
Owner

OTHER-3

Why the change

CI teardown's registry cleanup duplicated its HTTP plumbing, delete path, status mapping and GHCR scanning per ref, silently skipped unresolvable refs and never reported what it deleted; this ships one shared forge HTTP layer, one delete primitive, one outcome reducer, and per-repository registry walks that warn instead of guessing.

Special things to note

  • image-cleanup.ts shrinks only modestly (606 → 593) because forge-http.ts takes 28 shared lines out; total duplication drops, and forge-note.ts loses its own copies. The shared readErrorBody truncates remote error bodies at 300 characters (forge-note previously 500); warning and error templates are byte-identical.
  • Warning order is preserved for the normal app+seed run (one repository); only network requests are reordered by the GitLab delete Promise.all and the concurrent teardown note. Page-cap exhaustion now yields a new warning rather than a false registry tag already absent.
  • ci-teardown-tags.test.ts keeps all 11 original tests and assertions unchanged and adds three: the unresolved-image-ref warning proof plus one request-count proof per forge (GitLab 3 → 3, GHCR 6 → 4).

Change outline

apps/cli/src/
├── identity.ts                     pullRequestRecord shared by PR id + head SHA
└── commands/
    ├── forge-http.ts        new    fetchFor / stripTrailingSlash / readErrorBody / githubHeaders
    ├── image-cleanup.ts            deleteResource, recordOutcome, bounded registry walks
    ├── forge-note.ts               re-pointed at forge-http (behaviour unchanged)
    ├── ci-identity.ts              unresolved-ref warning + cheap shared-seed path
    ├── ci-teardown.ts              concurrent tail + deleted-count stdout line
    ├── seed-image.ts               isSharedSeedTarget predicate
    ├── ci-teardown-tags.test.ts    +1 silent-skip proof, +2 request-count proofs
    ├── ci-identity.test.ts         asserts the new warning
    └── ci-note-wiring.test.ts      teardown case accepts the new warning
// forge-http.ts
fetchFor(deps: CliDeps): (url: string, init?: RequestInit) => Promise<Response>;
stripTrailingSlash(url: string): string;
readErrorBody(res: Response): Promise<string>;
githubHeaders(token: string): Record<string, string>;

// image-cleanup.ts
deleteResource(doFetch, url, headers): Promise<DeleteOutcome>;
recordOutcome(tally: CleanupTally, ref: string, outcome: DeleteOutcome): void;

findGithubVersions(doFetch, target, pkg, wanted: ReadonlySet<string>):
  Promise<Result<{ versions: Map<string, GithubVersion>; exhausted: boolean }>>;

listGitlabRepositories(doFetch, target, wanted: ReadonlySet<string>):
  Promise<Result<{ repositories: Map<string, number>; exhausted: boolean }>>;

// seed-image.ts
isSharedSeedTarget(seed: Pick<SproutSeed, "inputs">): seed is { inputs: string[] };
runCiTeardown
├─ teardownPreview(...)                          // gateway error owns exit code
├─ resolveCiPushedImageRefs                      // warns when the app ref is unresolvable
│   └─ isSharedSeedTarget? → [appRef]            // no seed file reads/hashes
├─ cleanupPushedImageRefs(images.refs)           // starts as soon as refs resolve
│   ├─ gitlab: bounded repo index → Promise.all(deleteResource)
│   │            → recordOutcome in input order
│   └─ ghcr:  group by repository (warns unsupported refs)
│              → Promise.all(resolve package)
│              → one version walk per package (Map<tag, version>)
│              → sequential deleteResource + recordOutcome
└─ publishTeardownNote                           // concurrent; catch → Result, never throws

print: resolution warnings → cleanup warnings → deleted <n> registry tag(s) → note warning

@simpros

simpros commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Round 1 · head abe585af

APPROVE

Clean consolidation of the forge HTTP/delete/outcome plumbing with bounded per-repository registry walks, an honest page-cap warning instead of a false "already absent", and no behavioral regressions found; 387 CLI tests and typecheck pass at abe585a.

Full review report

Verdict

APPROVE

Summary: Clean consolidation of the forge HTTP/delete/outcome plumbing with bounded per-repository registry walks, an honest page-cap warning instead of a false "already absent", and no behavioral regressions found; 387 CLI tests and typecheck pass at abe585a.

Notes (non-blocking)

  • parseImageRef dropped the tag.includes("/") guard; it is redundant because colon > lastIndexOf("/") already guarantees the tag has no slash.
  • isSharedSeedTarget early return in resolveCiPushedImageRefs is equivalent to the old allowReuse check and avoids needless seed file reads/hashes (no spurious "seed tag not resolved" warning for unreadable shared seeds).
  • ci-teardown.ts: the concurrent note/cleanup flow handles rejections (note is caught into a Result; images/cleanup rejections go through the try/catch). Warning order is preserved.
  • GHCR: two tags sharing one version in the same group would yield a second delete returning 404 -> "already absent" warning; edge case, harmless.
  • The new deleted N registry tag(s) stdout line is user-visible; consider mentioning it in docs/ci-integration.md if teardown output is documented.
  • readErrorBody truncation unified to 300 chars (forge-note was 500); noted in the PR body.

@simpros
simpros merged commit a89391b into main Nov 19, 2026
2 checks passed
@simpros
simpros deleted the feat-other-3-image-cleanup branch November 19, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant