Skip to content

[AI:zf-builder] refactor(server): dedupe create-claim error-mapping tail in create_static_hub.go and create_hub_by_id.go (Ponytail Rung 2) - #170

Merged
ntsd merged 2 commits into
mainfrom
task/zf-z-ca978960
Nov 20, 2026
Merged

ntsd merged 2 commits into
mainfrom
task/zf-z-ca978960

Conversation

@ntsd

@ntsd ntsd commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

[AI:zf-builder] Task: zf-z-ca978960

Automated PR for task zf-z-ca978960

Completed by: @zf-builder

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying zerohub with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7f5e19f
Status: ✅  Deploy successful!
Preview URL: https://c3238ff0.zerohub.pages.dev
Branch Preview URL: https://task-zf-z-ca978960.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.

Verified the Ponytail Rung 2 dedup (create-claim error-mapping tail shared by create_static_hub.go and create_hub_by_id.go).

Correctness & behavior preservation

  • claimHubForCreate (server/pkg/handler/claim_hub_for_create.go) preserves the exact log lines (hub with id %s already exists / raw err) and the pinned response contract: rejected -> 409 written by claimUserChosenHubId (stop), ErrHubAlreadyExists -> 409 "hub id already exists", other -> 500 "create hub error".
  • hubMetadata is now read just before the claim instead of inside the create closure — equivalent: query args are immutable per request and the callback runs synchronously under hubIdCrossModeMu.
  • Auth ordering in CreateStaticHub unchanged: CheckAdminAuth -> migration-HTTP response -> validateHubCreateParams -> claim; the migration response path is untouched.
  • return h.Response(...) vs. return nil after h.Response(...): observationally identical — Response returns nil for a static map[string]string body (marshal cannot fail), so the dispatcher's 503-rewrite in handler.go never fires in either version.
  • Dedup is complete: the helper is now the only production caller of claimUserChosenHubId; CreateHubRandom delegates to CreateHubByID, and claimGetOrCreateHub (join-or-create) has a different response contract, correctly left out of scope.

Ponytail ladder

  • Rung 7 (diff scope): exactly 4 files, all in scope; no drive-by churn, no reformatting, no debug leftovers; go.mod/go.sum untouched.
  • Rungs 3 & 5 (dependency veto): no new dependencies.
  • Rungs 1 & 6 (simplicity): one flat method replaces ~12 duplicated lines x 2; isPermanent is a genuine per-caller difference, not a speculative flag. No premature abstraction.

Test coverage

  • 4 new unit tests pin every branch of the helper:
    • TestClaimHubForCreateSuccess — created hub returned with ok=true, no response written (caller owns it), hubMetadata passthrough verbatim, isPermanent=true forwarded.
    • TestClaimHubForCreateSiblingCollision — (nil,false), 409 "hub id collides with another hub type", CreateHubIfAbsent never called.
    • TestClaimHubForCreateAlreadyExists — 409 "hub id already exists".
    • TestClaimHubForCreateGenericErrorMapsTo500 — 500 "create hub error", internal error not leaked to the client, isPermanent=false path exercised.
  • All existing pinned spec/behavior tests pass: TestCreateStaticHub* (auth precedence, migration-HTTP, concurrent, already-exists, cross-mode collision), TestCreateHubByID* (400/413 metadata), cross-mode concurrent + probe-collision tests.

Verification (executed in the task worktree)

  • cd server && go build ./... && go vet ./... — clean
  • go test ./... -count=1 — all packages pass (config, handler, hub, peer, storage, zerohub)
  • gh pr view — mergeable against main

Approved for human review.

@ntsd
ntsd merged commit fde3d62 into main Nov 20, 2026
3 checks passed
@ntsd
ntsd deleted the task/zf-z-ca978960 branch November 20, 2026 01:40
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