fix(control-plane): close resolver findings + drop redundant ireturn nolints · Entire
fix(control-plane): close resolver findings + drop redundant ireturn nolints
789678d·
toothbrush·3w ago·4 files·+256 added/-20 removed
Address trail #641 review findings on resolveref.go: - case-insensitive name matching (EqualFold) in pickOrg, pickProject, and filterProjectsByName, matching the server's lower(name) uniqueness, so a case-only typo resolves instead of erroring - guard empty resolved AccountId in resolveAccountRef with a clear local error instead of forwarding "" as the owner ULID - add resolver tests asserting ULID refs make 0 HTTP calls and name/handle refs make exactly 1, plus case-insensitive and empty-account cases
Also drop three //nolint:ireturn directives: main's ireturn allowlist now covers checkpoint.CommittedStore/TemporaryStore, so they are redundant and CI's nolintlint fails on them as unused.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
Changes
4
cmd/entire/cli
checkpoint
Mopen.go+1/-1
Mresolveref.go+23/-10
Mresolveref_test.go+230/-7
strategy
Mmanual_commit.go+2/-2
// Temporary returns the git-backed temporary shadow-branch store.
func (s *Stores) Temporary() TemporaryStore { return s.temporary } //nolint:ireturn // temporary store capability is the abstraction boundary
func (s *Stores) Temporary() TemporaryStore { return s.temporary }
// Refs returns the resolved committed-ref topology.
func (s *Stores) Refs() CommittedRefs { return s.refs }
package cli
import (
"context"
"net/http"
"net/http/httptest"
"sync/atomic"
"testing"
"github.com/entireio/cli/internal/coreapi"
)
const (
ulidOrgAcme = "0123456789ABCDEFGHJKMNPQR1"
ulidOrgGlobex = "0123456789ABCDEFGHJKMNPQR2"
ulidProjectWidgets = "0123456789ABCDEFGHJKMNPQR3"
ulidAccount = "0123456789ABCDEFGHJKMNPQR4"
ulidResolvedAcct = "0123456789ABCDEFGHJKMNPQR9"
)
func resolveTestClient(t *testing.T, h http.HandlerFunc) (*coreapi.Client, *atomic.Int64) {
t.Helper()
var calls atomic.Int64
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
calls.Add(1)
w.Header().Set("Content-Type", "application/json")
h(w, r)
}))
t.Cleanup(srv.Close)
c, err := coreapi.NewWithBearer(srv.URL, "tok")
if err != nil {
t.Fatalf("NewWithBearer: %v", err)
}
return c, &calls
}
func TestResolveOrgRef(t *testing.T) {
t.Parallel()
orgs := &coreapi.ListOrgsOutputBody{Orgs: []coreapi.Org{
{ID: ulidOrgAcme, Name: "acme"},
{ID: ulidOrgGlobex, Name: "globex"},
}}
t.Run("ULID passes through without a network call", func(t *testing.T) {
t.Parallel()
c, calls := resolveTestClient(t, func(w http.ResponseWriter, _ *http.Request) {
t.Error("unexpected HTTP call for a ULID ref")
w.WriteHeader(http.StatusInternalServerError)
})
got, err := resolveOrgRef(context.Background(), c, ulidOrgGlobex)
if err != nil {
t.Fatalf("resolveOrgRef: %v", err)
}
if got != ulidOrgGlobex {
t.Errorf("resolveOrgRef = %q, want the ULID unchanged", got)
}
if n := calls.Load(); n != 0 {
t.Errorf("ULID ref made %d HTTP calls, want 0", n)
}
})
... // More tests for resolveProjectRef and resolveAccountRef
}
func TestPickOrg(t *testing.T) {
t.Parallel()
orgs := []coreapi.Org{
{ID: "01J0ORG0000000000000000001", Name: "acme"},
{ID: "01J0ORG0000000000000000002", Name: "globex"},
{ID: ulidOrgAcme, Name: "acme"},
{ID: ulidOrgGlobex, Name: "globex"},
}
... // More tests for picking projects and other functionalities
}