Repository navigation
[AI:zf-builder] refactor(server): dedup CreateHubIfAbsent and GetOrCreateHub shared skeleton - #167
Merged
Merged
Conversation
…keleton Task: zf-z-49f43665 refactor(server): dedup CreateHubIfAbsent and GetOrCreateHub shared skeleton (Ponytail Rung 2)
Deploying zerohub with
|
| Latest commit: |
d66b43d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3b480def.zerohub.pages.dev |
| Branch Preview URL: | https://task-zf-z-49f43665.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.
Correctness
server/pkg/zerohub/zerohub.go: the shared skeleton is now a single privategetOrCreateHubLockedcore; both public methods holdz.mubefore calling it, and the core's doc comment states the "under the caller's held z.mu" contract explicitly.- Behavior is byte-for-byte preserved:
CreateHubIfAbsent: existing hub ->(nil, ErrHubAlreadyExists); build error -> propagated error, nothing stored; success ->(newHub, nil).GetOrCreateHub: existing ->(existing, false, nil); build error ->(nil, false, err); success ->(newHub, true, nil).
- The atomicity invariants documented on both methods now live in one place, eliminating the mirror-fix risk the task called out.
Test coverage (verified green)
cd server && go build ./... && go vet ./...— clean;gofmt -l pkg/zerohub/— clean.go test -count=1 ./...— all packages pass (config, handler, hub, peer, storage, zerohub).- Existing concurrency regression tests (memory + gache backends, 200 goroutines, pointer-identity check) pass unchanged.
ErrHubAlreadyExistssemantics still covered: zerohub tests (sequential + concurrent) and the handler 409-mapping test (create_static_hub_test.go).- New
TestSharedCoreBuildHubFailureguards the error branch that moved into the core: asserts error surfaced, hub nil,created=false, and nothing left in storage — through BOTH public entry points. Correct addition for a dedup refactor: the deduplicated branch gained its own direct test.
Ponytail 7-Rung check
- Rung 7 (diff scope): exactly the 2 task files, +50/-9. No drive-by reformatting, no unrelated churn, no leftover debug code.
- Rungs 3 & 5 (dependencies): no new packages; test reuses existing imports.
- Rungs 1 & 6 (simplicity): the extraction is justified — 2 real callers sharing a documented invariant, not a single-caller wrapper. Naming (
getOrCreateHubLocked) conveys the locking precondition. No added indirection beyond one level. No YAGNI violations.
Mergeability
- PR is MERGEABLE / CLEAN against main (branch includes a merge of origin/main).
CONVENTION: For server-only Go refactor tasks, the full verification gate is cd server && go build ./... && go vet ./... && go test -count=1 ./... plus gofmt -l on touched packages — the npm install client/+test/ harness gotchas do not apply (those are only for test/ Playwright specs).
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-49f43665
refactor(server): dedup CreateHubIfAbsent and GetOrCreateHub shared skeleton (Ponytail Rung 2)
Automated PR for task zf-z-49f43665
Completed by: @zf-builder