Artifact ea47926c64622ec4952a42bc9812b1ecbc29ac686ed26bd59cc46f062d116993:
- File
hub/users.go
— part of check-in
[5f025def67]
at
2026-05-04 20:51:09
on branch trunk
— feat(hub): add OpenRepo + *hub.Repo type for server-less operations (#134)
Adds hub.OpenRepo(path) (*Repo, error) — a server-less handle for one-off CLI invocations and short-lived helpers (bones #186 needs this for `bones hub user list`, `bones plan finalize`, and slot-user provisioning, all of which currently drop to direct libfossil.Open because hub.NewHub spins up a redundant NATS server every time).
The new *hub.Repo type holds the libfossil handle and carries every user / commit / read method that *hub.Hub used to define on itself. *hub.Hub now holds a *hub.Repo internally and one-line-delegates each method, so both code paths share method bodies — no duplication.
Adds Hub.Repo() *Repo accessor for sharing the live handle out of a running hub. Documented contract: don't call Close on a *Repo returned by Hub.Repo while the Hub is still serving — Hub.Stop is the right teardown for that case. Repo.Close is idempotent so accidental double- close from teardown ordering is safe.
Tests: - TestOpenRepo_RoundTrip — every *Repo method against a path bootstrapped by NewHub. Same observable state. - TestOpenRepo_RejectsEmptyPath, TestOpenRepo_RejectsMissingPath. - TestRepo_Close_IsIdempotent. - TestHub_Repo_AccessorReturnsLiveHandle — operations on the *Repo accessor are observable via the *Hub.
Closes #131 (user: [email protected], size: 844) [annotate] [blame] [check-ins using]
package hub // User describes a fossil user on the hub repo. type User struct { Login string Caps string } // AddUser creates a fossil user. Returns an error if Login is empty or the // user already exists. func (h *Hub) AddUser(u User) error { return h.repo.AddUser(u) } // GetUser returns the user with the given login. Returns an error if no // such user exists. func (h *Hub) GetUser(login string) (User, error) { return h.repo.GetUser(login) } // HasUser reports whether a user with the given login exists. func (h *Hub) HasUser(login string) bool { return h.repo.HasUser(login) } // ListUsers returns all users on the hub. func (h *Hub) ListUsers() ([]User, error) { return h.repo.ListUsers() } // RemoveUser deletes the user with the given login. func (h *Hub) RemoveUser(login string) error { return h.repo.RemoveUser(login) }