Skip to content

fix: preserve CLI argument order for files#474

Merged
tomasz-tomczyk merged 3 commits intomainfrom
fix/preserve-cli-file-order
May 6, 2026
Merged

fix: preserve CLI argument order for files#474
tomasz-tomczyk merged 3 commits intomainfrom
fix/preserve-cli-file-order

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Summary

  • crit a.md b.md was always sorting files alphabetically in the frontend, ignoring CLI argument order. Backend already preserved order in NewSessionFromFiles; only the frontend's fileSortComparator was clobbering it.
  • Skip the frontend sort when session.mode === 'files' (top-level file list + tree sibling sort), so user-provided order flows through.
  • Update walkDirectory to yield "directories first at each depth, then alphabetical files" — the order the frontend used to impose for directory args like crit . — so backend is now the single source of truth for display order.

Review

  • Code review: passed
  • Parity audit: N/A (crit-only — crit-web receives shared file lists, not CLI args)

Test plan

  • go test -race ./... passes
  • golangci-lint run ./... clean
  • Playwright multi-file-mode suite passes (19 tests, including new regression test asserting CLI order)
  • Manual: crit beta.md alpha.md displays beta first

🤖 Generated with Claude Code

tomasz-tomczyk and others added 2 commits May 6, 2026 09:43
`crit a.md b.md` was always sorting files alphabetically in the frontend,
ignoring the order the user passed on the command line. Backend already
preserves the order in NewSessionFromFiles; only the frontend's
fileSortComparator was clobbering it. Skip sort when session.mode === 'files'
(both top-level file list and tree sibling sort) so user-provided order
flows through.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pairs with the previous commit. Now that the frontend trusts backend file
order in files mode, walkDirectory must produce the order users expect for
directory args like `crit .`: at each depth, recurse into subdirectories
(alphabetical) before listing files (alphabetical). This recovers the
"directories before files at each depth" grouping the frontend used to
impose via fileSortComparator.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 80.64516% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.24%. Comparing base (1b48658) to head (7ba2286).

Files with missing lines Patch % Lines
session.go 80.64% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #474      +/-   ##
==========================================
+ Coverage   69.17%   69.24%   +0.07%     
==========================================
  Files          36       36              
  Lines       10744    10754      +10     
==========================================
+ Hits         7432     7447      +15     
+ Misses       2747     2744       -3     
+ Partials      565      563       -2     
Flag Coverage Δ
e2e 32.40% <48.38%> (+<0.01%) ⬆️
unit 66.77% <80.64%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The two `e edits` / `d deletes` tests assumed alphabetical sort placed
handler.js first, so pressing `j` from cleared focus landed on it. With
CLI argument order preserved, plan.md (first arg in the fixture) is now
the first focusable file. Update the tests to seed and target plan.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tomasz-tomczyk tomasz-tomczyk merged commit bc7509f into main May 6, 2026
8 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the fix/preserve-cli-file-order branch May 6, 2026 09:55
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