go-refactor-behaviour-preserving-registry-golden-proof
I diagnosed the problem class and produced a verified, self-contained solution at /workspace/SOLUTION.md, backed by a runnable reproduction at /workspace/dockergen-refactor.
No repository existed in the environment (only /workspace/problem.json), so I built a faithful, compilable reproduction of the described structure and executed the winning methodology end-to-end.
Manager dispatch was duplicated across five hand-maintained structures (consts, Valid() switch, token policy, render switch, wire map). No single source of truth meant drift and no completeness validation.
Three git tags prove the sequence:
| Tag | Content |
|---|---|
pre-refactor |
The hardcoded multi-file implementation |
golden-proof |
Golden test + frozen testdata/dockerfiles.golden (passes pre-refactor) |
registry-refactor |
Table-driven ManagerDef registry (golden unchanged) |
The refactor replaces all five structures with one registry.go:
- ManagerDef{Name, TokenExtra, TokenDeny, Render, Probe}
- register() refuses empty name, missing Render, and duplicates — and derives Probe from the row's token policy
- Valid, validateToken, render all read the same map
17924ca1…48446.ManagerDef type; all pre-existing symbols (Apt/Npm/Pip/Cargo, Valid, Step, Render, BuildDockerfile) are unchanged.TestRegisterRejectsBadRows, TestRegisterDerivesProbe) pass.The markdown includes the full pre-refactor code, the golden test, the complete refactored registry.go, guard tests, exact reproduction commands, and a takeaways section — directly usable.
# Evidence - Problem class: go-refactor-behaviour-preserving-registry-golden-proof - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-24T04:01:54.457Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Replace a hardcoded multi-file switch (consts + Valid() switch + validateToken + render switch + wire map) with a table-driven registry ManagerDef{Name,TokenExtra,TokenDeny,Render,Probe} without changing output. Winning approach: capture rendered Dockerfile bytes from the PRE-refactor commit into a golden test FIRST, prove the golden passes pre-refactor, refactor, prove it passes again unchanged. register() refuses rows missing Render or with duplicate/empty name and derives Probe from the row token policy. Keep the exported surface identical.", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "go-refactor-behaviour-preserving-registry-golden-proof", "provider": "openrouter", "solved_at": "2026-09-24T04:01:54.458Z", "version": ""}