Repository navigation
Conversation
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
NanaseInori
left a comment
There was a problem hiding this comment.
Reviewed d4dc107. Returning an initialized empty slice makes the missing-directory case consistent with an existing empty directory. runSessionList passes that slice directly to the JSON encoder, and the added tests cover both the non-nil slice and the command's [] output. No blocking issue found.
Code review only; tests were not run in this review.
kittimzhe
left a comment
There was a problem hiding this comment.
Verified locally on the PR branch — this is the right fix, and it's safe beyond the JSON path.
Local run: go test ./internal/session/ ./cmd/opencodereview/ -run 'TestListSessions|TestRunSessionList' — both packages pass, including the new TestRunSessionList_JSON_MissingSessionsDirReturnsEmptyArray and the renamed empty-repo test.
Caller audit: all four production call sites handle the empty case with len()/range (session_cmd.go:183 completions, :241 empty check, :275 limit, viewer/handler.go:40), so none of them can tell nil from empty — no behavioral risk outside the JSON encoder, where nil marshals as null and breaks jq-style consumers (.[0] on null errors).
One semantic worth a sentence in the description: the viewer's separate ListSessions (internal/viewer/store.go:115, same name, different package) intentionally returns an error for a missing repo dir rather than an empty list — it needs repo identity to render the page. So the two functions now deliberately differ on missing-input semantics (CLI: empty list; viewer: error), which is correct but easy to trip over in future refactoring.
Fixes #1696
Summary
When a repository has no prior review sessions,
internal/session.ListSessionspreviously returnednil, nilon theos.IsNotExist(err)path. When serialized byocr session list --json, this produced JSONnullinstead of an empty array[], making CLI consumers handle two different shapes for an empty list of sessions.Changes
ListSessionsto return an empty initialized slice[]Summary{}when the sessions directory does not exist.TestListSessions_EmptyRepoReturnsEmptySliceininternal/sessionto verify non-nil empty slice.TestRunSessionList_JSON_MissingSessionsDirReturnsEmptyArrayincmd/opencodereviewto ensure the JSON command consistently outputs[].