Skip to content

refactor: split review_test.go into focused test files#379

Merged
wesm merged 5 commits intomainfrom
refactor-review-test
Feb 26, 2026
Merged

refactor: split review_test.go into focused test files#379
wesm merged 5 commits intomainfrom
refactor-review-test

Conversation

@wesm
Copy link
Collaborator

@wesm wesm commented Feb 26, 2026

Summary

  • Split the 3,067-line review_test.go into 9 focused test files by feature area, matching the existing pattern used for filter and queue tests
  • Extract shared test helpers (initTestModel, option functions, assertion helpers) into review_test_helpers_test.go
  • Convert fix panel tests to use shared helpers and table-driven patterns

New files: review_fetch_test.go, review_navigation_test.go, review_branch_test.go, review_addressed_test.go, review_views_test.go, review_clipboard_test.go, review_log_test.go, review_fix_panel_test.go, review_render_test.go

Test plan

  • go test ./cmd/roborev/tui/... -count=1 passes
  • go vet ./cmd/roborev/tui/... clean
  • go fmt ./cmd/roborev/tui/... clean
  • CI passes

🤖 Generated with Claude Code

wesm and others added 3 commits February 26, 2026 10:11
Extract mockEnqueue and mockWaitableReview helpers to eliminate
duplicated mock setup across 8+ tests. Replace unnecessary channel-based
captures with direct variable reads (executeReviewCmd is synchronous).
Consolidate 5 flag-validation subtests into a single table-driven
TestReviewFlagValidation. Remove unused "time" import.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add review_test_helpers_test.go with reusable testModelOption functions
(withReview, withFixPanel, withFixPrompt, etc.), semantic assertion
helpers (assertFixPanelOpen/Closed, assertFixPanelState), and a
mockReviewHandler factory. Rewrite fix panel tests to use initTestModel
with option functions and pressKey/pressSpecial instead of raw
handleKeyMsg calls. Replace withModelBranch with withBranchName and
update setupRenderModel to accept testModelOption.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Split the 3,067-line review_test.go into files by feature area,
matching the existing pattern (filter_test.go, queue_test.go, etc.):

- review_fetch_test.go: fetch review + SHA fallback (4 tests)
- review_navigation_test.go: review nav + selection sync (7 tests)
- review_branch_test.go: branch name set/clear/filter (5 tests)
- review_addressed_test.go: addressed toggle + rollback (7 tests)
- review_views_test.go: escape/commit msg/help views (8 tests)
- review_clipboard_test.go: yank/copy + formatClipboardContent (13 tests)
- review_log_test.go: log paging/loading/nav (10 tests)
- review_fix_panel_test.go: fix panel open/close/submit (17 tests)
- review_render_test.go: render views + visible lines (3 tests)

Pure file-move refactor — no test logic changed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@roborev-ci
Copy link

roborev-ci bot commented Feb 26, 2026

roborev: Combined Review (615dff0)

Verdict: All agents agree the code is clean and no issues were found.

The reviewed commits consist entirely of test-only refactors, including splitting large test files and extracting shared helpers, with no modifications to production logic or security boundaries.


Synthesized from 4 reviews (agents: codex, gemini | types: default, security)

mockEnqueue wrote to a shared capturedEnqueue struct in the HTTP
handler goroutine and returned a pointer for tests to read without
synchronization, tripping -race. The json.Decode error was also
silently discarded.

Replace the shared pointer with a buffered channel: the handler
decodes (checking the error), sends the value, then responds. Tests
receive from the channel after executeReviewCmd returns, giving a
clean happens-before edge.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@roborev-ci
Copy link

roborev-ci bot commented Feb 26, 2026

roborev: Combined Review (1a5f4a6)

Verdict: The PR is a secure, test-only
refactoring with one medium-severity risk regarding test stability.

🟡 Medium

Potential indefinite test hangs due to unbounded channel receives

  • File: cmd/roborev/review_test.go (lines 120, 142, 159, 41 1, 474, 496, 513)
  • Description: The refactor switched from shared variables / timed select statements to direct req := <-reqCh reads with no timeout. If the /api/enqueue endpoint is not hit or if JSON decoding
    fails, these tests can block forever and stall CI pipelines instead of failing fast.
  • Suggested Fix: Add a helper function like mustRecvEnqueue(t, ch) using a timeout: select { case req := <-ch: ...; case <-time.After(...): t.Fatal(...) } and
    utilize it in all of these test cases.

Synthesized from 4 reviews (agents: codex, gemini | types: default, security)

Use a non-blocking channel send so a second enqueue call fails the
test immediately instead of blocking forever.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@roborev-ci
Copy link

roborev-ci bot commented Feb 26, 2026

roborev: Combined Review (94c3e0f)

Verdict: The PR consists of safe test refactoring but introduces a medium-severity risk of test hangs due to unbounded channel receives.

Medium

Potential test hang due unbounded channel receive

  • Files: [review_test.go:57](/home/
    roborev/repos/roborev/cmd/roborev/review_test.go:57), review_test.go:123,
    review_test.go:145, [review_test.go:162](/home/roborev/repos/roborev/cmd/
    roborev/review_test.go:162), review_test.go:414, [review_test.go:477](/
    home/roborev/repos/roborev/cmd/roborev/review_test.go:477), [review_test.go:499](/home/roborev/repos/roborev/cmd/roborev/review_test.go:4
    99), review_test.go:516
  • Description: mockEnqueue only sends to reqCh on successful decode and non-
    duplicate request. On decode/duplicate paths it returns without sending, while many tests now do blocking <-reqCh with no timeout. That can hang until global test timeout instead of failing fast.
  • Suggested fix: Use a timeout receive helper (select { case req := <-ch ... case <-time.After (...) ... }) or guarantee mockEnqueue always signals completion (including error cases).

Synthesized from 4 reviews (agents: codex, gemini | types: default, security)

@wesm
Copy link
Collaborator Author

wesm commented Feb 26, 2026

Not valid. Merging

@wesm wesm merged commit 566dbb6 into main Feb 26, 2026
8 checks passed
@wesm wesm deleted the refactor-review-test branch February 26, 2026 19:09
wesm added a commit that referenced this pull request Feb 27, 2026
Split the 2,487-line sync_test.go (36 tests) into 7 focused files:
- sync_test_helpers_test.go: shared helpers, legacy DDL, syncTestHelper
- sync_state_test.go: sync state and worker lifecycle (6 tests)
- sync_backfill_test.go: machine ID and repo identity backfill (6 tests)
- sync_identity_test.go: repo identity CRUD and schema migrations (8 tests)
- sync_queries_test.go: sync query functions and timestamps (5 tests)
- sync_ordering_test.go: sync ordering and dependency enforcement (8 tests)
- sync_remap_test.go: patch ID round-trip and job remapping (4 tests)

No test logic changes. Follows the pattern set by review_test.go split (#379).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
wesm added a commit that referenced this pull request Feb 27, 2026
## Summary
- Split `internal/storage/sync_test.go` (2,487 lines, 36 tests) into 7
focused files following the pattern set by the `review_test.go` split
(#379)
- One shared helpers file (`sync_test_helpers_test.go`) plus 6
feature-area test files: state, backfill, identity, queries, ordering,
remap
- No test logic changes — purely mechanical refactor

## Test plan
- [x] `go build ./internal/storage/...` passes
- [x] `go vet ./internal/storage/...` passes
- [x] `go fmt ./internal/storage/...` clean
- [x] `go test ./internal/storage/... -count=1` — all tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant