Skip to content

Fix csv-view path and row display behavior#57

Open
BeauDevCode wants to merge 5 commits into
TruFoundation:mainfrom
BeauDevCode:fix/csv-view-display-43
Open

Fix csv-view path and row display behavior#57
BeauDevCode wants to merge 5 commits into
TruFoundation:mainfrom
BeauDevCode:fix/csv-view-display-43

Conversation

@BeauDevCode

@BeauDevCode BeauDevCode commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary:

  • Preserves unquoted Windows file paths when csv-view parses its file argument.
  • Allows csv-view to reach and display the existing limited-row table output instead of reporting valid Windows paths as missing.
  • Adds focused regression coverage for unquoted paths with spaces, Windows paths with spaces, and truncated row captions.
  • Preserves upstream tests/test_data.py coverage, including the short-row padding regression test, after resolving the merge conflict.

Validation:

  • python -m pytest tests/test_data.py -q
  • Result: 3 passed, 4 skipped on Windows after merging upstream main.
  • Prior full-suite Windows run reported unrelated existing failures in tests/test_cli_argv.py, tests/test_help_docs.py, and tests/test_nav.py; the focused data target passes.

Related issue:

Risk:

  • Low, only csv-view display behavior and tests changed.

@AkshajSinghal

Copy link
Copy Markdown
Collaborator

Before I take this out of draft:

  1. Resolve the conflict in test_data.py.
  2. Let’s get that CI check green, skip the pre-existing Windows failures if they’re unrelated so we can see if your change actually broke anything.
  3. Add a quick test for paths with spaces (e.g., C:\Program Files\) to ensure we don’t regress on that common case.

Fix those, and it’s good to go!

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Modified run_csv_view to normalize raw arguments and try multiple unquoted path candidates (including a Windows-style parse) when the initially resolved path does not exist. Added three pytest regression tests covering unquoted paths with spaces and Windows backslashes, asserting headers, row inclusion/exclusion, and truncation messaging.

Changes

CSV path handling with fallback resolution

Layer / File(s) Summary
Path resolution fallback in run_csv_view
trushell/commands/data.py
run_csv_view normalizes raw args, extracts a raw path candidate, shlex-splits arguments, and when the initial file path doesn't exist constructs alternative candidate paths (including a shlex.split(..., posix=False) branch for backslashes). The first existing candidate is used for CSV reading.
Regression tests for unquoted path handling
tests/test_data.py
Three pytest regressions: a non-Windows test for temp dirs with spaces, a Windows-only test checking row truncation messaging for unquoted backslash paths, and a Windows-only test for paths with spaces. Each writes users.csv, calls run_csv_view with an unquoted path, strips ANSI, and asserts expected headers/rows/truncation text.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Paths and slashes in a race,

I hop through spaces, find the place.
Windows backslashes, I tame with care,
Tests now show the rows that were there.
A tiny hop, a passing cheer — code cleared!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main changes: fixing CSV path handling and row display behavior in the csv-view command.
Linked Issues check ✅ Passed The PR directly addresses issue #43 by fixing the csv.reader exhaustion problem that prevented truncation captions from appearing, and adds regression tests for path handling.
Out of Scope Changes check ✅ Passed All changes are scoped to CSV path resolution and row display fixes. Tests added are focused regression coverage for paths with spaces and Windows path handling.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@BeauDevCode

Copy link
Copy Markdown
Contributor Author

Follow-up verification:

  • Resolved the tests/test_data.py merge conflict by merging upstream main and preserving both upstream short-row padding coverage and this PR's path parsing regressions.
  • python -m pytest tests/test_data.py -q passes locally on Windows: 2 passed, 4 skipped by existing platform guards.
  • GitHub now reports the PR as mergeable; CodeRabbit is passing.

@BeauDevCode BeauDevCode marked this pull request as ready for review June 9, 2026 04:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/test_data.py (1)

89-102: ⚡ Quick win

Consider adding a test for Windows paths with spaces.

The current test validates Windows path handling and truncation, but the path used (tmp_path / "users.csv") may not contain spaces. Real-world Windows paths commonly include spaces (e.g., C:\Program Files\..., C:\Users\John Doe\...).

Adding a test that creates a directory with spaces on Windows would validate the interaction of both fallback mechanisms (backslash handling + space handling).

Example test structure
`@pytest.mark.skipif`(sys.platform != "win32", reason="Windows path with spaces regression")
def test_run_csv_view_handles_windows_paths_with_spaces(tmp_path: Path) -> None:
    from trushell.commands.data import run_csv_view
    
    directory = tmp_path / "Program Files"
    directory.mkdir()
    file_path = directory / "users.csv"
    file_path.write_text("ID,Name\n1,Ada\n", encoding="utf-8")
    
    output = _strip_ansi(run_csv_view(str(file_path)))
    
    assert "ID" in output
    assert "Name" in output
    assert "Ada" in output
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_data.py` around lines 89 - 102, Add a new Windows-only test to
cover paths that include spaces: create a directory with a space in its name
inside tmp_path, write a small CSV file there, call run_csv_view with
str(file_path) (wrapped with _strip_ansi as in
test_run_csv_view_handles_unquoted_windows_paths) and assert the expected
headers and row values appear; name the test function
test_run_csv_view_handles_windows_paths_with_spaces and use the same
pytest.mark.skipif(sys.platform != "win32", ...) guard so it only runs on
Windows.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/test_data.py`:
- Around line 89-102: Add a new Windows-only test to cover paths that include
spaces: create a directory with a space in its name inside tmp_path, write a
small CSV file there, call run_csv_view with str(file_path) (wrapped with
_strip_ansi as in test_run_csv_view_handles_unquoted_windows_paths) and assert
the expected headers and row values appear; name the test function
test_run_csv_view_handles_windows_paths_with_spaces and use the same
pytest.mark.skipif(sys.platform != "win32", ...) guard so it only runs on
Windows.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4bd1f94d-06f4-4568-80f1-78d62b1efcbe

📥 Commits

Reviewing files that changed from the base of the PR and between 8425b0b and 2900b8b.

📒 Files selected for processing (2)
  • tests/test_data.py
  • trushell/commands/data.py

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.

run_csv_view reads beyond exhausted file handle

2 participants