Repository navigation
fix(session): return an empty slice, not nil, when the sessions dir is missing - #1809
OUAO-FRANK wants to merge 1 commit into
Conversation
…s missing
ListSessions is documented to return an empty slice when the sessions
directory does not exist, but it returned nil, which json.Marshal renders as
null. `ocr session list --json` therefore printed null for a repo that never
ran a review, but [] for a repo whose (now empty) session directory still
exists. Return []Summary{} so the JSON shape is consistent.
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
NanaseInori
left a comment
There was a problem hiding this comment.
Reviewed both changed files, #1696 and the existing discussion. Returning an initialized empty slice on the missing-directory path is a correct, focused fix for the null-versus-array output difference. The strengthened non-nil assertion detects the old behavior; no implementation defect found in this two-file patch.
The issue-number search also found the earlier open #1742. I compared its actual diff: it already makes the identical return []Summary{}, nil production change, asserts both non-nil and JSON [] in the session test, and adds a CLI regression checking the raw session list --json output. The merged #1792 concerns session show and does not replace either list fix.
There is no distinct remaining production change here relative to #1742. I recommend retaining one implementation, preferably preserving the CLI wire-output regression, rather than merging two copies of the same fix. This is an overlap comment, not a request for the earlier PR to coordinate with this later submission, and it does not close either PR.
Validation: complete patch/test inspection and comparison of the two implementations; no independent repository test execution.
This review was conducted by NanaseInori's review bot, using the model GPT-6 Astra Pro. If you need a human review, please manually @NanaseInori.
|
Thanks for the contribution! #1742 has now been merged and fixes the same issue: |
Summary
ListSessionsis documented to "return an empty slice with no error" when the sessions directory is missing, but it returnednil. Sincejson.Marshal(nil)renders asnull,ocr session list --jsonprinted:nullfor a repository that never ran a review (directory absent), and[]for a repository whose session directory exists but is empty.Now
ListSessionsreturns[]Summary{}in the missing-directory branch, so the JSON shape is always[].Testing
Renamed
TestListSessions_EmptyRepoReturnsNiltoTestListSessions_EmptyRepoReturnsEmptySliceand added a non-nil assertion. It fails on the previous code (expected a non-nil empty slice, got nil) and passes now.gofmt -lon the changed files is clean.Fixes #1696.