Repository navigation
fix: make pager and config tests hermetic under a TTY - #1747
Merged
Merged
Conversation
cargo test failed on any macOS/TTY environment (Terminal, ghostty, tmux) on three tests, two distinct causes: - pager: create_pager() read process-global io::stdout() .is_terminal(); libtest captures the thread-local print handles, not fd 1, so under a real terminal the tests asserting the non-TTY branch failed — and create_pager actually SPAWNED `less` mid-test. The paging decision's inputs (is_tty, NO_PAGER, $PAGER) now live in a PagerEnv struct; create_pager() reads the process, tests construct it directly. This also makes the previously-untestable TTY side testable: new tests cover NO_PAGER-wins, empty command (config and $PAGER), unparsable command, and spawn-failure fallback — none of which consult or mutate the real environment (parallel tests race on set_var). - config: the None-override assertion in resolve_user_config_path_env_override_wins collided with the macOS XDG fallback (#1616), which probes the REAL filesystem for ~/.config/rledger/config.toml when the fake native sentinel doesn't exist — failing for any macOS user with an actual rledger config. Moved into the already-cfg(not(macos)) sibling test with a comment naming the trap. Verified: full lib suite green both normally AND under a PTY (script -qec), where the pre-fix pager tests reproduce the reported failures (2 failed); clippy clean on 1.96 and 1.97. Co-Authored-By: Claude Fable 5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-07-10)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
Makes pager- and config-path unit tests hermetic so cargo test behaves consistently under real TTY/PTY environments and on machines with real user config files, without changing production behavior.
Changes:
- Refactors pager decision inputs into a
PagerEnvstruct and routescreate_pager()through an internalcreate_pager_in()to allow fully hermetic unit tests. - Expands pager unit tests to cover additional TTY decision branches without consulting/mutating real process env vars or spawning a real pager.
- Adjusts config-path unit tests to avoid macOS-specific filesystem probing behavior that depends on the developer’s real
~/.config/...state.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rustledger/src/pager.rs | Introduces PagerEnv + create_pager_in() and updates/extends tests to be TTY-safe and hermetic. |
| crates/rustledger/src/config.rs | Moves a “no override uses native” assertion into a non-macOS-gated test to avoid macOS real-filesystem interference. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…iew) Co-Authored-By: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes the three tests from #1729 hermetic, so
cargo testpasses in TTY environments (macOS Terminal, ghostty, tmux) and with real user config files on disk. Two distinct causes, per the triage on the issue:Pager (the TTY half).
create_pager()read process-globalio::stdout().is_terminal(); libtest captures the thread-local print handles, not fd 1, so under a real terminal the tests asserting the non-TTY branch failed — andcreate_pageractually spawnedlessmid-test-run on the developer's machine. The paging decision's inputs (is_tty,NO_PAGER,$PAGER) now live in a smallPagerEnvstruct: the publiccreate_pager()fills it from the process, tests construct it directly.Bonus: the previously-untestable TTY side is now covered —
NO_PAGER-wins, empty pager command (via config and via$PAGER), unparsable command, and spawn-failure fallback. None of the tests consult or mutate the real environment (parallel tests race onset_var), and none can spawn a process (spawn-success on a TTY is deliberately untested — it would launch a real pager from the suite; the comment says so).Config (the filesystem half — not TTY). The
None-override assertion inresolve_user_config_path_env_override_winscollided with the macOS XDG fallback (#1616), which probes the real filesystem for~/.config/rledger/config.tomlwhen the fake/native/...sentinel doesn't exist — so it failed for any macOS user with an actual rledger config, terminal or not. The assertion moved into the already-cfg(not(target_os = "macos"))sibling test, with a comment naming the trap so it isn't reintroduced.No production behavior changes —
create_pager's public signature and decision logic are unchanged; the config resolver is untouched.Verification
rustledgerlib suite (370 tests) green both normally and under a PTY (script -qec "cargo test …"), the reporter's environment shape.--all-features --all-targets -D warningsclean on both 1.96 (nix) and 1.97 (CI's stable); fmt clean.Closes #1729
🤖 Generated with Claude Code