Skip to content

[AI:zf-builder] refactor(server): dedup triplicated upgrade-failure epilogue in 3 hub handlers - #157

Merged
ntsd merged 1 commit into
mainfrom
task/zf-z-69f76171
Nov 19, 2026
Merged

ntsd merged 1 commit into
mainfrom
task/zf-z-69f76171

Conversation

@ntsd

@ntsd ntsd commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

[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

… handlers

Task: zf-z-69f76171

refactor(server): dedup triplicated upgrade-failure epilogue in 3 hub handlers (Ponytail Rung 2)
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying zerohub with  Cloudflare Pages  Cloudflare Pages

Latest commit: f6244a4
Status: ✅  Deploy successful!
Preview URL: https://aaf54509.zerohub.pages.dev
Branch Preview URL: https://task-zf-z-69f76171.zerohub.pages.dev

View logs

@ntsd ntsd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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's StatusServiceUnavailable (503).
  • join_hub.go passes nil for rollback (pre-existing hub, no cleanup) — correct.
  • join_or_create_hub_by_id.go passes a closure that checks if created — correct.
  • create_hub_by_id.go passes an unconditional zh.RemoveHubById — correct.

Test coverage ✅ (auto-merge active, scrutinized)

  • New test TestFinishUpgradeFailureWrites500Fallback pins 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 ./... — clean
  • go vet ./... — clean
  • go test ./... — all packages pass
  • gofmt -l on all 5 changed files — clean
  • gh 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.

@ntsd
ntsd merged commit 4c83938 into main Nov 19, 2026
3 checks passed
@ntsd
ntsd deleted the task/zf-z-69f76171 branch November 19, 2026 19:30
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