Repository navigation
[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
Conversation
…atic_hub.go and create_hub_by_id.go (Ponytail Rung 2) Task: zf-z-ca978960
Deploying zerohub with
|
| Latest commit: |
7f5e19f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c3238ff0.zerohub.pages.dev |
| Branch Preview URL: | https://task-zf-z-ca978960.zerohub.pages.dev |
ntsd
commented
Nov 20, 2026
ntsd
left a comment
Contributor
Author
There was a problem hiding this comment.
[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 byclaimUserChosenHubId(stop),ErrHubAlreadyExists-> 409 "hub id already exists", other -> 500 "create hub error".hubMetadatais now read just before the claim instead of inside the create closure — equivalent: query args are immutable per request and the callback runs synchronously underhubIdCrossModeMu.- Auth ordering in
CreateStaticHubunchanged: CheckAdminAuth -> migration-HTTP response ->validateHubCreateParams-> claim; the migration response path is untouched. return h.Response(...)vs.return nilafterh.Response(...): observationally identical —Responsereturns nil for a staticmap[string]stringbody (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;CreateHubRandomdelegates toCreateHubByID, andclaimGetOrCreateHub(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;
isPermanentis 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),hubMetadatapassthrough verbatim,isPermanent=trueforwarded.TestClaimHubForCreateSiblingCollision— (nil,false), 409 "hub id collides with another hub type",CreateHubIfAbsentnever called.TestClaimHubForCreateAlreadyExists— 409 "hub id already exists".TestClaimHubForCreateGenericErrorMapsTo500— 500 "create hub error", internal error not leaked to the client,isPermanent=falsepath 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 ./...— cleango test ./... -count=1— all packages pass (config, handler, hub, peer, storage, zerohub)gh pr view— mergeable againstmain
Approved for human review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[AI:zf-builder] Task: zf-z-ca978960
Automated PR for task zf-z-ca978960
Completed by: @zf-builder