Skip to content

Commit 4e449d0

Browse files
authored
Delete the dead TUI, and add a check that could have seen it (#653)
internal/tui/spinner.go and internal/tui/paginated_picker.go have no callers — 602 lines of exported API nothing in the repo or the binary reaches, each holding a tea.NewProgram. Verified symbol by symbol before removing; the surviving `Spinner` matches are bubbles/spinner's own field. Neither had a test file. Removing internal Go symbols does not touch .surface, which tracks the CLI command surface, so no .surface-breaking entry is needed. The reason this survived is worth fixing too. `unused` (staticcheck U1000) is the repo's only dead-code check, it runs per-package, and it treats every exported identifier in a non-main package as used by definition. It is structurally incapable of reporting any of this, and no configuration changes that. So add `make deadcode`, which starts from a main and follows the call graph. Rooted at ./cmd/basecamp, and again with -tags=dev, because those answer different questions. Not `./...`: only main packages are roots, so loading every package makes deadcode report everything no main reaches — 1100+ of 1250 lines here, nearly all the dev-tagged workspace tree, which the untagged build genuinely cannot reach. True, and useless. The tool version is pinned and invoked with `go run`, so the output does not depend on what happens to be installed. Deliberately NOT wired into `make check`. It is a report to read, not a gate: some zero-caller exported symbols are a deliberate API surface, and the dev tree is legitimately incomplete. Land the target, look at real output, decide separately. Adding a noisy gate is how a control nobody sized gets built. Scoped to the two TUI files. The other candidates the plan listed — internal/models, internal/sdk, sdk/errors, resolve/comment_thread.go — are a separate backlog; internal/sdk in particular is documented in AGENTS.md as the SDK wrapper and touching it means editing the SDK-sync workflow in the same breath.
1 parent 5f15ad6 commit 4e449d0

6 files changed

Lines changed: 71 additions & 680 deletions

File tree

‎AGENTS.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ make lint # Linter
8686
make check # All checks (what bin/ci runs)
8787
```
8888

89+
**Dead code**: `make deadcode` reports unreachable functions whole-program, rooted
90+
at the shipped binary and again with `-tags dev`. It is a report, not a gate, and
91+
is deliberately outside `make check`. The linter's `unused` cannot do this job —
92+
it runs per-package and counts every exported identifier in a non-main package as
93+
used, which is how 600 lines of exported, zero-caller `internal/tui` API survived
94+
it. Root it at the binary, not `./...`: only main packages are roots, so `./...`
95+
reports everything no main reaches — mostly the `dev`-tagged workspace tree — as
96+
unreachable.
97+
98+
It also analyzes one GOOS/GOARCH at a time, while we release five. A host run says
99+
nothing about the others: code behind another platform's build tag is never loaded,
100+
and a function whose only caller sits behind one looks unreachable. Before deleting
101+
anything platform-adjacent, check the other targets — install the tool for the host
102+
and set GOOS for the analysis (`GOOS=windows deadcode ./cmd/basecamp`), since
103+
`GOOS=windows go run` cross-compiles the tool itself and fails.
104+
105+
Read the output before acting on it: a zero-caller exported symbol is a candidate,
106+
not a verdict, and the `dev`-tagged tree is legitimately partial.
107+
89108
Requirements: Go 1.26+, [bats-core](https://github.com/bats-core/bats-core) for e2e tests.
90109

91110
## OAuth Development

‎Makefile‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,56 @@ bench-compare:
190190
@command -v benchstat >/dev/null 2>&1 || go install golang.org/x/perf/cmd/benchstat@latest
191191
benchstat benchmarks-baseline.txt benchmarks-current.txt
192192

193+
# Report unreachable code, whole-program, from the production binary's main.
194+
#
195+
# NOT a gate, and not wired into `make check`. golangci's `unused` (staticcheck
196+
# U1000) runs per-package and treats every exported identifier in a non-main
197+
# package as used by definition, which is why 602 lines of exported, zero-caller
198+
# internal/tui API survived it — no configuration fixes that, the analysis
199+
# cannot see across package boundaries. deadcode can, because it starts from a
200+
# main and follows the call graph.
201+
#
202+
# Which main matters. Only main packages are roots, so `deadcode ./...` loads
203+
# every package and then reports everything no main reaches as unreachable —
204+
# 1100+ of its 1250 lines here are the dev-tagged workspace tree, which the
205+
# untagged build genuinely cannot reach. True, and useless. Naming the binary
206+
# gives two answers worth reading instead:
207+
#
208+
# deadcode ./cmd/basecamp what a released basecamp can never run
209+
# deadcode -tags=dev ./cmd/basecamp the same, with the dev `basecamp tui` tree
210+
#
211+
# `go run` the pinned version rather than trusting whatever `deadcode` happens
212+
# to be on PATH; an unpinned tool makes the output depend on the machine.
213+
#
214+
# ONE PLATFORM AT A TIME. deadcode analyzes the current GOOS/GOARCH, and this
215+
# repo releases darwin, linux, windows, freebsd and openbsd. So a host run is
216+
# evidence about the host and nothing else, in both directions: code behind
217+
# another platform's build tag is never loaded, and a function whose only caller
218+
# sits behind one looks unreachable here. Measured on this tree: 78 findings for
219+
# linux and darwin, 77 for windows, with harden_unix.go's ownedByUID present
220+
# only in the unix reports.
221+
#
222+
# To check another target, install the tool for the host and set GOOS for the
223+
# analysis — `GOOS=windows go run ...` cross-compiles the tool itself and dies
224+
# with an exec format error:
225+
#
226+
# go install golang.org/x/tools/cmd/deadcode@v0.40.0
227+
# GOOS=windows deadcode ./cmd/basecamp
228+
#
229+
# Read the output before acting on it. A zero-caller exported symbol is a
230+
# candidate, not a verdict — some are a deliberate API surface, the -tags dev
231+
# tree is legitimately partial, and a cross-platform deletion needs a run per
232+
# target. Wiring a noisy check into CI is how a control nobody sized gets built.
233+
DEADCODE := golang.org/x/tools/cmd/deadcode@v0.40.0
234+
235+
.PHONY: deadcode
236+
deadcode: check-toolchain
237+
@echo "== shipped binary =="
238+
$(GOCMD) run $(DEADCODE) ./cmd/basecamp
239+
@echo
240+
@echo "== with -tags dev =="
241+
$(GOCMD) run $(DEADCODE) -tags=dev ./cmd/basecamp
242+
193243
# Guard against Go toolchain mismatch (mise environment)
194244
.PHONY: check-toolchain
195245
check-toolchain:
@@ -558,6 +608,7 @@ help:
558608
@echo " fmt-check Check code formatting"
559609
@echo " lint Run golangci-lint"
560610
@echo " lint-actions Lint GitHub Actions workflows (actionlint + zizmor)"
611+
@echo " deadcode Report unreachable code from the binary (report, not a gate)"
561612
@echo " tidy-check Verify go.mod/go.sum are tidy"
562613
@echo " check Run all checks (local CI gate)"
563614
@echo " check-surface Verify committed .surface matches the command tree (TestSurfaceSnapshot)"

‎internal/tui/forms_test.go‎

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package tui
22

33
import (
4-
"context"
54
"errors"
65
"go/ast"
76
"go/parser"
@@ -202,65 +201,6 @@ func TestPickerFloorRefusesNonInteractiveStdio(t *testing.T) {
202201
assert.Zero(t, loaderCalls, "a refused picker must not fetch items it cannot show")
203202
}
204203

205-
// TestDeadLaunchersStillRefuse covers Spinner and PaginatedPicker. Both are
206-
// exported, both have zero callers today, and both are slated for deletion —
207-
// but "nobody calls it" is not a gate. Adding a caller would not add a
208-
// tea.NewProgram, so the structural backstop would still pass while the hang
209-
// came straight back. They hold the floor until they are gone.
210-
func TestDeadLaunchersStillRefuse(t *testing.T) {
211-
for _, kind := range stdinKinds {
212-
t.Run("spinner/"+kind, func(t *testing.T) {
213-
terminalStdout(t)
214-
nonInteractiveStdin(t, kind)
215-
216-
var ran bool
217-
done := make(chan error, 1)
218-
go func() {
219-
_, err := NewSpinner("working").Run(func() (string, error) {
220-
ran = true
221-
return "", nil
222-
})
223-
done <- err
224-
}()
225-
226-
select {
227-
case err := <-done:
228-
assert.True(t, errors.Is(err, ErrNotInteractive),
229-
"spinner should return ErrNotInteractive on %s stdin, got %v", kind, err)
230-
assert.False(t, ran, "a refused spinner must not run the work it was wrapping")
231-
case <-time.After(5 * time.Second):
232-
t.Fatalf("spinner blocked on %s stdin instead of refusing", kind)
233-
}
234-
})
235-
236-
t.Run("paginated_picker/"+kind, func(t *testing.T) {
237-
terminalStdout(t)
238-
nonInteractiveStdin(t, kind)
239-
240-
var fetched bool
241-
fetcher := func(context.Context, string) (*PageResult, error) {
242-
fetched = true
243-
return &PageResult{}, nil
244-
}
245-
246-
done := make(chan error, 1)
247-
go func() {
248-
_, err := NewPaginatedPicker(context.Background(), fetcher).Run()
249-
done <- err
250-
}()
251-
252-
select {
253-
case err := <-done:
254-
assert.True(t, errors.Is(err, ErrNotInteractive),
255-
"paginated picker should return ErrNotInteractive on %s stdin, got %v", kind, err)
256-
assert.False(t, fetched, "a refused picker must not fetch a page it cannot show")
257-
case <-time.After(5 * time.Second):
258-
t.Fatalf("paginated picker blocked on %s stdin instead of refusing", kind)
259-
}
260-
})
261-
}
262-
}
263-
264204
// TestAutoSelectSingleWorksWithoutATerminal pins the one path through
265205
// Picker.Run that is deliberately outside the floor. With WithAutoSelectSingle
266206
// and exactly one static item, Run resolves without constructing a bubbletea

‎internal/tui/launchers_test.go‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,7 @@ var (
3636
// bubbleteaLaunchers maps a file that may call tea.NewProgram to the sole
3737
// function within it that may do so.
3838
bubbleteaLaunchers = map[string]string{
39-
"internal/tui/picker.go": "runPicker",
40-
41-
// Zero callers today and slated for deletion, but "dead" is not a gate:
42-
// adding a caller would not add a NewProgram, so the check would still
43-
// pass while the hang came back. Both launch from their own Run, and
44-
// both apply the floor there.
45-
"internal/tui/spinner.go": "Run",
46-
"internal/tui/paginated_picker.go": "Run",
47-
39+
"internal/tui/picker.go": "runPicker",
4840
"internal/commands/tui.go": "", // dev build tag; not in a shipped binary
4941
}
5042

0 commit comments

Comments
 (0)