Repository navigation
[AI:zf-builder] refactor(server): dedup triplicated upgrade-failure epilogue in 3 hub handlers - #157
Conversation
… handlers Task: zf-z-69f76171 refactor(server): dedup triplicated upgrade-failure epilogue in 3 hub handlers (Ponytail Rung 2)
Deploying zerohub with
|
| Latest commit: |
f6244a4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://aaf54509.zerohub.pages.dev |
| Branch Preview URL: | https://task-zf-z-69f76171.zerohub.pages.dev |
ntsd
left a comment
There was a problem hiding this comment.
[AI:zf-reviewer] [Reviewer Feedback] Round 1: Approved for human review.
Summary: Clean extraction of the triplicated post-Upgrade failure epilogue into a single finishUpgradeFailure helper in websocket.go. All three call sites delegate correctly with per-call-site rollback closures. Behavior is preserved exactly: rollback → log → responseWritten guard → 500 fallback.
Correctness ✅
- Helper preserves the exact ordering:
rollback()runs before logging, matching the original call-site code. - Builder correctly kept
fasthttp.StatusInternalServerError(500) rather than the task proposal'sStatusServiceUnavailable(503). join_hub.gopassesnilfor rollback (pre-existing hub, no cleanup) — correct.join_or_create_hub_by_id.gopasses a closure that checksif created— correct.create_hub_by_id.gopasses an unconditionalzh.RemoveHubById— correct.
Test coverage ✅ (auto-merge active, scrutinized)
- New test
TestFinishUpgradeFailureWrites500Fallbackpins the shared 500 fallback + body + no-rollback path — previously untested (the 500 was copy-pasted inline). - Pre-existing tests cover: orphan removal (join_or_create created=true), hub-preserved (created=false), IP-variant, 400-guard preservation for all three endpoints, and rollback-on-400 for create.
- Full matrix of rollback/no-rollback × err/responseWritten paths is covered.
- Pre-existing handler test files are unmodified (verified via
git diff).
Ponytail (Anti-Overengineering) ✅
- Rung 7 (Diff scope): 5 files, all directly in-scope. No drive-by reformatting, no debug leftovers, no unrelated churn.
- Rung 3 & 5 (Dependencies): Zero new dependencies.
- Rung 1 & 6 (Simplicity): A single method with a nil-able
func()callback. No interface, no class, no config struct. Minimal and flat.
Gates ✅
go build ./...— cleango vet ./...— cleango test ./...— all packages passgofmt -lon all 5 changed files — cleangh pr view→ mergeable: true
Line-count check: Handler files net −36 lines; helper +20; test +34. Production net ≈ −16 lines. Task estimated ~25; actual is close (the multi-line closures at call sites account for the difference). Dedup goal clearly met.
No issues found. Safe to merge.
[AI:zf-builder] Task: zf-z-69f76171
refactor(server): dedup triplicated upgrade-failure epilogue in 3 hub handlers (Ponytail Rung 2)
Automated PR for task zf-z-69f76171
Completed by: @zf-builder