# fix(control-plane): close resolver findings + drop redundant ireturn nolints

`08737c9`→[main](/content/gh/entireio/cli/commits/main/index.html)·

toothbrush·3w ago·2 files·+253 added/-17 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

93dc23440f69View transcript

[?\
Resolve Names Server-Side in Control PlaneClaude Code·Opus 4.8\[1m\]·1 step](/content/gh/entireio/cli/session/ae5aa6a1-3cb0-4726-830b-04f79e7f24ce#timeline-93dc23440f69/index.html)

## Changes

2

- cmd/entire/cli

- Mresolveref.go+23/-10

- Mresolveref_test.go+230/-7

```
64 unmodified lines

65
66
67
68
69
70
71
72
73
74
75
76
10 unmodified lines

87
88
89
84
85
90
91
92
93
94
95
96
8 unmodified lines

105
106
107
100
108
109
110
111
112
104
113
114
115
116
16 unmodified lines

133
134
135
127
136
137
138
139
140
141
131
142
143
144
145
11 unmodified lines

157
158
159
149
150
151
160
161
162
163
164
165
166
167
168
169
170
158
171
172
173
174

64 unmodified lines

if err != nil {
		return "", err
	}
	// ResolvedIdentity.AccountId is a plain string, so a handle that resolves to
	// an identity with no backing account would silently forward "" as the owner
	// ULID and fail later with an opaque server-side create error. Catch it here.
	if id.AccountId == "" {
		return "", fmt.Errorf("handle %q resolved to no account", ref)
	}
	return id.AccountId, nil
}

10 unmodified lines

// resolveProjectRef turns a project reference (ULID or name) into its ULID. A
// ULID is returned unchanged; a name is looked up via the server's exact-name
// filter (the same call `entire project list --name` uses).
// ULID is returned unchanged; a name is looked up via the server's name filter
// (the same call `entire project list --name` uses). Name matching is
// case-insensitive end to end: the server enforces lower(name) uniqueness and
// pickProject re-checks with EqualFold, so case-only differences resolve.
func resolveProjectRef(ctx context.Context, c *coreapi.Client, ref string) (string, error) {
	if looksLikeULID(ref) {
		return ref, nil

// pickOrg selects the single org named name. Org names are unique, so a name
// matches at most one org; zero matches is an error pointing at `org list`, and
// (defensively) multiple matches list the colliding ids so the user can fall
// back to a ULID.
// back to a ULID. Matching is case-insensitive (EqualFold): pickOrg filters the
// full ListOrgs result client-side, so a case-only typo should still resolve.
func pickOrg(orgs []coreapi.Org, name string) (string, error) {
	var matches []coreapi.Org
	for _, o := range orgs {
		if o.Name == name {
		if strings.EqualFold(o.Name, name) {
			matches = append(matches, o)
		}
	}

// filterProjectsByName narrows projects to exact name matches, returning all of
// them when name is empty. Used by `project list --org` to apply --name
// client-side, since the org-scoped list endpoint has no name parameter.
// filterProjectsByName narrows projects to name matches, returning all of them
// when name is empty. Used by `project list --org` to apply --name client-side,
// since the org-scoped list endpoint has no name parameter. Matching is
// case-insensitive (EqualFold), consistent with pickProject and the server's
// lower(name) uniqueness guarantee.
func filterProjectsByName(projects []coreapi.Project, name string) []coreapi.Project {
	if name == "" {
		return projects
	}
	var out []coreapi.Project
	for _, p := range projects {
		if p.Name == name {
		if strings.EqualFold(p.Name, name) {
			out = append(out, p)
		}
	}

Mcmd/entire/cli/resolveref.go+23/-10

```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
60 unmodified lines

295
296
297
75
76
298
299
300
301
302
2 unmodified lines

305
306
307
85
308
309
310
311
20 unmodified lines

332
333
334
112
113
335
336
337
338
339
17 unmodified lines

357
358
359
137
138
360
361
362
363
364

package cli

import (
	"context"
	"net/http"
	"net/http/httptest"
	"sync/atomic"
	"testing"

"github.com/entireio/cli/internal/coreapi"
)

// Valid ULID-shaped fixtures (26 Crockford base32 chars, no I/L/O/U) so the
// resolver tests exercise the ULID short-circuit instead of a name lookup.
const (
	ulidOrgAcme        = "0123456789ABCDEFGHJKMNPQR1"
	ulidOrgGlobex      = "0123456789ABCDEFGHJKMNPQR2"
	ulidProjectWidgets = "0123456789ABCDEFGHJKMNPQR3"
	ulidAccount        = "0123456789ABCDEFGHJKMNPQR4"
	ulidResolvedAcct   = "0123456789ABCDEFGHJKMNPQR9"
)

// resolveTestClient builds a coreapi client pointed at a test server whose
// handler is h, and returns the client plus a counter of HTTP requests seen.
// It lets the resolver tests assert the load-bearing invariant from
// resolveref.go's doc comment: a ULID ref makes zero network calls, a name ref
// makes exactly one.
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)
		}
	})

t.Run("name resolves via exactly one list call", func(t *testing.T) {
		t.Parallel()
		c, calls := resolveTestClient(t, func(w http.ResponseWriter, _ *http.Request) {
			if err := writeJSON(w, orgs); err != nil {
				t.Errorf("encode orgs: %v", err)
			}
		})
		got, err := resolveOrgRef(context.Background(), c, "globex")
		if err != nil {
			t.Fatalf("resolveOrgRef: %v", err)
		}
		if got != ulidOrgGlobex {
			t.Errorf("resolveOrgRef = %q, want globex id", got)
		}
		if n := calls.Load(); n != 1 {
			t.Errorf("name ref made %d HTTP calls, want 1", n)
		}
	})

t.Run("name match is case-insensitive", func(t *testing.T) {
		t.Parallel()
		c, _ := resolveTestClient(t, func(w http.ResponseWriter, _ *http.Request) {
			if err := writeJSON(w, orgs); err != nil {
				t.Errorf("encode orgs: %v", err)
			}
		})
		got, err := resolveOrgRef(context.Background(), c, "ACME")
		if err != nil {
			t.Fatalf("resolveOrgRef: %v", err)
		}
		if got != ulidOrgAcme {
			t.Errorf("resolveOrgRef(ACME) = %q, want acme id", got)
		}
	})
}

func TestResolveProjectRef(t *testing.T) {
	t.Parallel()
	projects := &coreapi.ListProjectsOutputBody{Projects: []coreapi.Project{
		{ID: ulidProjectWidgets, Name: "widgets", OwnerId: ulidOrgAcme, OwnerType: coreapi.ProjectOwnerTypeOrg},
	}}

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 := resolveProjectRef(context.Background(), c, ulidProjectWidgets)
		if err != nil {
			t.Fatalf("resolveProjectRef: %v", err)
		}
		if got != ulidProjectWidgets {
			t.Errorf("resolveProjectRef = %q, want the ULID unchanged", got)
		}
		if n := calls.Load(); n != 0 {
			t.Errorf("ULID ref made %d HTTP calls, want 0", n)
		}
	})

t.Run("name resolves via exactly one list call", func(t *testing.T) {
		t.Parallel()
		c, calls := resolveTestClient(t, func(w http.ResponseWriter, _ *http.Request) {
			if err := writeJSON(w, projects); err != nil {
				t.Errorf("encode projects: %v", err)
			}
		})
		got, err := resolveProjectRef(context.Background(), c, "widgets")
		if err != nil {
			t.Fatalf("resolveProjectRef: %v", err)
		}
		if got != ulidProjectWidgets {
			t.Errorf("resolveProjectRef = %q, want widgets id", got)
		}
		if n := calls.Load(); n != 1 {
			t.Errorf("name ref made %d HTTP calls, want 1", n)
		}
	})

t.Run("name match is case-insensitive", func(t *testing.T) {
		t.Parallel()
		c, _ := resolveTestClient(t, func(w http.ResponseWriter, _ *http.Request) {
			if err := writeJSON(w, projects); err != nil {
				t.Errorf("encode projects: %v", err)
			}
		})
		got, err := resolveProjectRef(context.Background(), c, "Widgets")
		if err != nil {
			t.Fatalf("resolveProjectRef: %v", err)
		}
		if got != ulidProjectWidgets {
			t.Errorf("resolveProjectRef(Widgets) = %q, want widgets id", got)
		}
	})
}

func TestResolveAccountRef(t *testing.T) {
	t.Parallel()

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 := resolveAccountRef(context.Background(), c, ulidAccount)
		if err != nil {
			t.Fatalf("resolveAccountRef: %v", err)
		}
		if got != ulidAccount {
			t.Errorf("resolveAccountRef = %q, want the ULID unchanged", got)
		}
		if n := calls.Load(); n != 0 {
			t.Errorf("ULID ref made %d HTTP calls, want 0", n)
		}
	})

t.Run("handle resolves via exactly one call", func(t *testing.T) {
		t.Parallel()
		c, calls := resolveTestClient(t, func(w http.ResponseWriter, _ *http.Request) {
			if err := writeJSON(w, &coreapi.ResolvedIdentity{AccountId: ulidResolvedAcct, Provider: "github", Handle: "alice"}); err != nil {
				t.Errorf("encode identity: %v", err)
			}
		})
		got, err := resolveAccountRef(context.Background(), c, "github:alice")
		if err != nil {
			t.Fatalf("resolveAccountRef: %v", err)
		}
		if got != ulidResolvedAcct {
			t.Errorf("resolveAccountRef = %q, want resolved account id", got)
		}
		if n := calls.Load(); n != 1 {
			t.Errorf("handle ref made %d HTTP calls, want 1", n)
		}
	})

t.Run("empty resolved account id is an error", func(t *testing.T) {
		t.Parallel()
		c, _ := resolveTestClient(t, func(w http.ResponseWriter, _ *http.Request) {
			if err := writeJSON(w, &coreapi.ResolvedIdentity{AccountId: "", Provider: "github", Handle: "alice"}); err != nil {
				t.Errorf("encode identity: %v", err)
			}
		})
		if _, err := resolveAccountRef(context.Background(), c, "github:alice"); err == nil {
			t.Error("resolveAccountRef expected error for empty account id")
		}
	})

t.Run("non-qualified handle fails before any network call", func(t *testing.T) {
		t.Parallel()
		c, calls := resolveTestClient(t, func(w http.ResponseWriter, _ *http.Request) {
			t.Error("unexpected HTTP call for an invalid handle")
			w.WriteHeader(http.StatusInternalServerError)
		})
		if _, err := resolveAccountRef(context.Background(), c, "alice"); err == nil {
			t.Error("resolveAccountRef expected error for non-qualified handle")
		}
		if n := calls.Load(); n != 0 {
			t.Errorf("invalid handle made %d HTTP calls, want 0", n)
		}
	})
}

func TestLooksLikeULID(t *testing.T) {
	t.Parallel()
	tests := []struct {
60 unmodified lines

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"},
	}

t.Run("unique match", func(t *testing.T) {
2 unmodified lines

if err != nil {
			t.Fatalf("pickOrg: %v", err)
		}
		if got != "01J0ORG0000000000000000002" {
			if got != ulidOrgGlobex {
				t.Errorf("pickOrg = %q, want globex id", got)
			}
	})

20 unmodified lines

func TestPickProject(t *testing.T) {
	t.Parallel()
	projects := []coreapi.Project{
		{ID: "01J0PRJ0000000000000000001", Name: "widgets", OwnerId: "01J0ORG0000000000000000001"},
		{ID: "01J0PRJ0000000000000000002", Name: "gadgets", OwnerId: "01J0ORG0000000000000000001"},
		{ID: ulidProjectWidgets, Name: "widgets", OwnerId: ulidOrgAcme, OwnerType: coreapi.ProjectOwnerTypeOrg},
		{ID: "01J0PRJ0000000000000000002", Name: "gadgets", OwnerId: ulidOrgAcme},
	}

t.Run("unique match", func(t *testing.T) {
17 unmodified lines

t.Run("ambiguous across owners", func(t *testing.T) {
		t.Parallel()
		dupes := []coreapi.Project{
			{ID: "01J0PRJ000000000000000000A", Name: "shared", OwnerId: "01J0ORG0000000000000000001"},
			{ID: "01J0PRJ000000000000000000B", Name: "shared", OwnerId: "01J0ORG0000000000000000002"},
			{ID: "01J0PRJ000000000000000000A", Name: "shared", OwnerId: ulidOrgAcme},
			{ID: "01J0PRJ000000000000000000B", Name: "shared", OwnerId: ulidOrgGlobex},
		}
		if _, err := pickProject(dupes, "shared"); err == nil {
			t.Error("pickProject expected error for ambiguous name")
		}
	})
}
