Skip to content

Split CLI file-output modes (#362) - #406

Merged
leynos merged 8 commits into
mainfrom
issue-362-refactor-cli-replace-handle-file-s-option-string-with-an-explicit-output-type
Jul 26, 2026
Merged

Split CLI file-output modes (#362)#406
leynos merged 8 commits into
mainfrom
issue-362-refactor-cli-replace-handle-file-s-option-string-with-an-explicit-output-type

Conversation

@lodyai

@lodyai lodyai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

This branch replaces handle_file's Boolean-controlled Option<String>
contract with purpose-specific file-output functions.

Closes #362.

format_to_string now returns newline-terminated formatted text, and
rewrite_in_place writes that same text. The CLI's parallel paths collect their
natural result types directly, without discarding an encoded mode sentinel.

Review walkthrough

Validation

  • make check-fmt: passed
  • make lint: passed
  • make test: passed
  • make markdownlint: passed
  • make nixie: passed
  • mbake validate Makefile: passed
  • make: passed
  • coderabbit review --agent: no findings

Notes

Model checking is not applicable: this API-shape refactor concerns unbounded
file content, while the property test directly compares the pure formatting
result with the bytes written in place across generated inputs.

References

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry @LodyAI[bot], you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Summary

  • Split CLI file output into purpose-specific format_to_string and rewrite_in_place functions, eliminating the ambiguous Option<String> contract.
  • Added capability-scoped filesystem handling with cap-std and camino, plus developer and architecture documentation.
  • Updated parallel CLI processing to preserve natural result types for stdout and in-place modes.
  • Added property tests, independent-oracle CLI tests, snapshots, and parity coverage verifying stdout and in-place output.
  • Added the unformatted parity fixture and documented the filesystem boundary and mode contracts.

Walkthrough

The CLI now uses capability-scoped filesystem helpers: format_to_string emits formatted text, while rewrite_in_place writes formatted content back. Parallel dispatch, documentation, dependency declarations, property tests, snapshots, and fixtures are updated.

Changes

CLI output refactor

Layer / File(s) Summary
Dedicated output helpers
Cargo.toml, src/main.rs, docs/developers-guide.md
Add camino and cap-std, introduce capability-scoped file helpers, and document their output contracts.
CLI processing wiring
src/main.rs, docs/architecture.md
Route stdout and --in-place modes through separate helpers and document their parallel execution flows.
Output parity validation
src/main.rs, tests/cli.rs, tests/data/cli-output-parity.expected.md
Add property, snapshot, parity, and idempotence coverage using capability-scoped temporary directories.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant Rayon
  participant OutputHelpers
  participant StdoutStderr
  CLI->>Rayon: process input paths in parallel
  alt stdout mode
    Rayon->>OutputHelpers: format_to_string for each file
    OutputHelpers-->>Rayon: Result<String>
    Rayon->>StdoutStderr: print results and errors in input order
  else in-place mode
    Rayon->>OutputHelpers: rewrite_in_place for each file
    OutputHelpers-->>Rayon: Result<()>
    Rayon->>StdoutStderr: print errors in input order
  end
Loading

Suggested labels: Issue

Suggested reviewers: leynos

Poem

Files find their parent, safely bound,
Strings emerge with newlines round.
Rewriters polish, then write anew,
Parallel paths keep order true.
Tables and snapshots ring the bell—
A tidy CLI now serves well.

🚥 Pre-merge checks | ✅ 19 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
User-Facing Documentation ⚠️ Warning The CLI now constrains file handling to UTF-8 capability paths, but docs/users-guide.md still lacks coverage of the affected stdout/--in-place modes and path limits. Add a users-guide section for the CLI file-output modes and any filename/UTF-8 constraints, or remove the user-facing restriction if it is unintended.
✅ Passed checks (19 passed)
Check name Status Explanation
Title check ✅ Passed Match the title to the refactor and include the linked issue reference (#362).
Description check ✅ Passed Keep the description on-topic; it clearly describes the file-output split and related testing work.
Linked Issues check ✅ Passed Satisfy #362 by splitting the file-output paths, updating docs, adding parity/property tests, and covering both CLI modes.
Out of Scope Changes check ✅ Passed Avoid marking any changes as out of scope; the dependency, docs, and test updates all support the linked refactor.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Testing (Overall) ✅ Passed PASS: The new parity snapshot test uses a real oracle, checks stdout immutability and in-place rewrites, and the proptest plus parallel CLI tests exercise the changed paths end-to-end.
Developer Documentation ✅ Passed Confirm the guide documents open_file_parent/format_to_string/rewrite_in_place, the architecture doc reflects the new parallel flow, and the roadmap checklist is fully checked off.
Module-Level Documentation ✅ Passed PASS: The changed Rust modules all begin with //! docs that explain their purpose and role, including src/main.rs and tests/cli.rs.
Testing (Unit And Behavioural) ✅ Passed Keep the CLI snapshot tests: they drive the binary via assert_cmd, verify stdout/in-place parity and unchanged input, while the property test asserts the write/format invariant.
Testing (Property / Proof) ✅ Passed Approve: src/main.rs adds proptest equivalence over generated inputs, and tests/cli.rs snapshots both stdout and in-place modes.
Testing (Compile-Time / Ui) ✅ Passed UI output is covered by focused snapshots plus semantic assertions, and the PR adds no compile-time behaviour that would make trybuild applicable.
Unit Architecture ✅ Passed PASS: open_file_parent isolates ambient FS access, format_to_string/rewrite_in_place expose fallible read vs write paths, and tests exercise the seams via capability-scoped Dir.
Domain Architecture ✅ Passed PASS: The refactor keeps Markdown processing pure and confines all filesystem/path handling to CLI adapter helpers; no domain module now depends on infrastructure concerns.
Observability ✅ Passed Keep the existing anyhow::Context and stderr error reporting; this refactor adds no new telemetry surface or operational state to instrument.
Security And Privacy ✅ Passed No secrets, auth bypasses, or over-broad scopes were added; file I/O stays capability-scoped and fixtures/snapshots contain only generic sample content.
Performance And Resource Use ✅ Passed No new hot-path regression: each file still does one read/process/write, and the parallel paths buffer only per-input results to preserve order.
Concurrency And State ✅ Passed PASS: docs state rayon parallelism and ordered buffering; tests cover multi-file stdout ordering plus partial-failure paths, and file I/O is per-file capability-scoped.
Architectural Complexity And Maintainability ✅ Passed Split file-output helpers replace the boolean/Option contract with explicit, documented boundaries that simplify call sites and tests without adding speculative layers.
Rust Compiler Lint Integrity ✅ Passed PASS: Changed Rust files add no dead_code/unused suppressions or lint-appeasement anchors; only a narrow clippy::struct_excessive_bools expect and ordinary ownership transfers appear.
📋 Issue Planner

Built with CodeRabbit's Coding Plans for faster development and fewer bugs.

View plan used: #362

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-362-refactor-cli-replace-handle-file-s-option-string-with-an-explicit-output-type

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

@leynos
leynos marked this pull request as ready for review July 23, 2026 12:54

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 090f872d2d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/developers-guide.md Outdated
@coderabbitai coderabbitai Bot added the Issue label Jul 23, 2026
@buzzybee-df12

Copy link
Copy Markdown

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@docs/architecture.md`:
- Around line 599-623: Add an italicized “Figure N: …” caption immediately after
the closing fence of the Mermaid diagram, describing the CLI’s parallel file
processing and ordered output behavior.

In `@tests/cli.rs`:
- Around line 107-111: Extend the --in-place assertions in the relevant CLI test
to verify in_place.stdout is empty after confirming in_place.status.success().
Keep the existing stderr failure diagnostic and rewritten-content validation
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a59eafea-bdee-4a79-906f-ce32111f32b2

📥 Commits

Reviewing files that changed from the base of the PR and between 9bf67eb and 14e4dd2.

⛔ Files ignored due to path filters (2)
  • tests/snapshots/cli__format_to_string_table_prose.snap is excluded by !**/*.snap
  • tests/snapshots/cli__rewrite_in_place_table_prose.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • docs/architecture.md
  • docs/developers-guide.md
  • src/main.rs
  • tests/cli.rs
  • tests/data/cli-output-parity.md

Comment thread docs/architecture.md
Comment thread tests/cli.rs
@lodyai
lodyai Bot force-pushed the issue-362-refactor-cli-replace-handle-file-s-option-string-with-an-explicit-output-type branch from 40ab249 to 58cf151 Compare July 24, 2026 00:52
@pandalump

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/main.rs`:
- Around line 108-125: Update format_to_string and rewrite_in_place to use
cap_std/camino capability-scoped directory or file handles instead of direct
std::fs operations, preserving their current read, format, newline, and write
behavior. Refactor the file-output tests to use the same capability-scoped I/O
boundary and path types, removing direct filesystem access throughout these
paths.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9f180a3e-417b-4924-b7e0-dab6a761d852

📥 Commits

Reviewing files that changed from the base of the PR and between 14e4dd2 and 58cf151.

⛔ Files ignored due to path filters (2)
  • tests/snapshots/cli__format_to_string_table_prose.snap is excluded by !**/*.snap
  • tests/snapshots/cli__rewrite_in_place_table_prose.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • docs/architecture.md
  • docs/developers-guide.md
  • src/main.rs
  • tests/cli.rs
  • tests/data/cli-output-parity.md

Comment thread src/main.rs Outdated
@leynos

leynos commented Jul 24, 2026

Copy link
Copy Markdown
Owner

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

@leynos

leynos commented Jul 24, 2026

Copy link
Copy Markdown
Owner

@coderabbitai Have the following failed checks now been resolved?

If further work is required, please provide an AI agent prompt for the remaining work to be done to address these failures.

Do not treat warnings as optional or aspirational. Where a change is out of scope for this PR, propose a GitHub issue unless one exists already. (Treat documentation and validation coverage as in scope).

❌ Failed checks (2 errors)

Check name Status Explanation Resolution
Testing (Overall) ❌ Error The new tests only compare the two helper paths and snapshot an already-formatted fixture, so a no-op or shared-bug implementation could still pass. Use an unformatted fixture with an independent expected output, assert stdout and in-place results against that oracle, and verify format_to_string leaves the file untouched.
Unit Architecture ❌ Error format_to_string/rewrite_in_place still hard-code std::fs reads/writes, so the filesystem dependency is not injectable at the boundary. Move file access behind a narrow capability-scoped abstraction (for example cap_std/camino or an injected trait) and route the helpers/tests through that seam.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== Current PR diff/stat =='
git diff --stat "$(git merge-base HEAD origin/main)" HEAD 2>/dev/null || git diff --stat HEAD~1 HEAD

echo '== Relevant file discovery =='
fd -t f -a '^(main\.rs|cli\.rs|Cargo\.toml|cli-output-parity\.md)$' . | sort

echo '== src/main.rs outline =='
ast-grep outline src/main.rs --items all --view expanded 2>/dev/null || true

echo '== File helper and filesystem call sites =='
rg -n -C 5 -P '\b(format_to_string|rewrite_in_place|handle_file)\s*\(|\b(std::)?fs::(read_to_string|write)\s*\(' src/main.rs tests/cli.rs

echo '== Test assertions related to output modes =='
rg -n -C 8 -P '\b(format_to_string|rewrite_in_place|assert_snapshot!?|stdout|read_to_string|write|cli_output_modes_snapshot_table_prose)\b' src/main.rs tests/cli.rs

echo '== Fixture contents =='
fixture="$(fd -t f -a '^cli-output-parity\.md$' tests | head -n1 || true)"
if [ -n "$fixture" ]; then
  cat -n "$fixture"
fi

echo '== Snapshot files related to output modes =='
fd -t f -a . tests | rg 'format_to_string|rewrite_in_place|output.*parity|snap$' || true

echo '== Dependencies relevant to filesystem abstraction =='
if [ -f Cargo.toml ]; then
  rg -n -C 2 -i 'cap-std|camino|tempfile|fs|dependency' Cargo.toml
fi

echo '== Issues matching filesystem injection / output mode architecture =='
gh issue list --repo leynos/mdtablefix --state all --limit 100 \
  --search 'filesystem inject OR file I/O abstraction OR output mode OR handle_file' \
  --json number,title,state,url --jq '.[] | "#\(.number) [\(.state)] \(.title) \(.url)"' || true

Length of output: 40329


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== Input fixture: tests/data/cli-output-parity.dat =='
cat -n tests/data/cli-output-parity.dat

echo '== Independent expected oracle: tests/data/cli-output-parity.expected.md =='
cat -n tests/data/cli-output-parity.expected.md

echo '== Output-mode snapshots =='
for f in \
  tests/snapshots/cli__format_to_string_table_prose.snap \
  tests/snapshots/cli__rewrite_in_place_table_prose.snap
do
  echo "-- $f"
  cat -n "$f"
done

echo '== Helper contract documentation =='
rg -n -C 6 -P '\b(format_to_string|rewrite_in_place|capability|capability-scoped|Dir|filesystem)\b' \
  docs/developers-guide.md docs/architecture.md src/main.rs

echo '== Exact diff for relevant production and integration-test code =='
git diff "$(git merge-base HEAD origin/main)" HEAD -- \
  src/main.rs tests/cli.rs Cargo.toml docs/developers-guide.md docs/architecture.md \
  tests/data/cli-output-parity.dat tests/data/cli-output-parity.expected.md

Length of output: 36169


@leynos Both failed checks are now resolved.

  • Testing (Overall): resolved. tests/data/cli-output-parity.dat is deliberately unformatted, and tests/data/cli-output-parity.expected.md provides a distinct expected-output oracle. cli_output_modes_snapshot_table_prose asserts:

    • stdout exactly matches that oracle;
    • stdout mode leaves the source file unchanged;
    • --in-place produces no stdout;
    • rewritten file contents exactly match the same oracle.

    This prevents a no-op implementation, or a shared formatting defect that merely makes both paths agree, from passing the new CLI coverage.

  • Unit Architecture: resolved. format_to_string and rewrite_in_place now receive &cap_std::fs_utf8::Dir and a relative &camino::Utf8Path. They perform I/O through the injected, capability-scoped directory rather than hard-coding std::fs reads or writes. open_file_parent contains the sole ambient filesystem boundary, and unit/property tests instantiate and pass the scoped Dir explicitly.

  • Documentation: resolved. docs/developers-guide.md documents the ambient boundary, helper contracts, capability-scoped I/O, and the requirement for future file-output call sites to receive the directory capability and relative path.

No further implementation work or follow-up GitHub issue is required for these two failures. Issue #362 remains the appropriate tracking issue for the completed output-mode refactor.

Runtime validation was not executable in this inspection sandbox; rely on the PR’s reported full validation gate for execution confirmation.

@pandalump

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@tests/data/cli-output-parity.expected.md`:
- Around line 5-7: Add a descriptive caption immediately before the fixture
table in the expected output, and update the corresponding paired input fixture
and snapshots so they produce the same captioned table consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 59cf39b1-4151-4b2c-bd11-ebff4ec48620

📥 Commits

Reviewing files that changed from the base of the PR and between 14e4dd2 and e1cc849.

⛔ Files ignored due to path filters (4)
  • Cargo.lock is excluded by !**/*.lock
  • tests/data/cli-output-parity.dat is excluded by !**/*.dat
  • tests/snapshots/cli__format_to_string_table_prose.snap is excluded by !**/*.snap
  • tests/snapshots/cli__rewrite_in_place_table_prose.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • Cargo.toml
  • docs/architecture.md
  • docs/developers-guide.md
  • src/main.rs
  • tests/cli.rs
  • tests/data/cli-output-parity.expected.md

Comment thread tests/data/cli-output-parity.expected.md
@lodyai
lodyai Bot force-pushed the issue-362-refactor-cli-replace-handle-file-s-option-string-with-an-explicit-output-type branch from e1cc849 to 0d0cee3 Compare July 26, 2026 02:28
leynos added 8 commits July 26, 2026 04:29
Replace the Boolean-controlled `Option<String>` contract with dedicated
formatting and in-place rewrite functions. Keep both modes byte-identical,
and cover the contract with property and CLI snapshot tests.
Update the concurrency diagram so both parallel CLI modes reference the
current handlers and their concrete result contracts.
Caption the concurrency diagram and ensure the in-place CLI contract rejects
unexpected stdout while retaining its rewrite snapshot coverage.
Keep the upstream before-and-after example intact after the concurrency
diagram replay altered its surrounding Markdown.
Open each input file's parent directory once at the CLI boundary, then
perform formatting and rewrites through `cap_std` UTF-8 directory
capabilities. Keep the property and CLI file-output tests on the same
boundary, and document the ownership rule for future callers.
Use an unformatted raw fixture and a separate expected-output oracle so
stdout and in-place results each prove the formatting contract. Keep the
raw fixture outside Markdown formatting to preserve this regression guard.
Keep the raw fixture, expected output, and both output-mode snapshots in
sync with a descriptive caption immediately before the representative table.
Keep the labelled numbered-list input and converted footnote output
separate so the architecture document remains valid Markdown and explains
the transformation accurately.
@lodyai
lodyai Bot force-pushed the issue-362-refactor-cli-replace-handle-file-s-option-string-with-an-explicit-output-type branch from a41b05d to 580363a Compare July 26, 2026 02:30
@leynos
leynos merged commit 3271f68 into main Jul 26, 2026
4 checks passed
@leynos
leynos deleted the issue-362-refactor-cli-replace-handle-file-s-option-string-with-an-explicit-output-type branch July 26, 2026 21:31
@pandalump

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@docs/architecture.md`:
- Around line 619-645: The architecture diagram’s file-processing calls are
shown sequentially despite stating parallel execution. Update the Stdout and
In-place branches to model each file operation as explicit Mermaid parallel
branches (or a single Rayon batch submission), while preserving ordered result
handling and the existing error/exit behavior; include the required “Triage:”
paragraph for this documentation style change.

In `@src/main.rs`:
- Around line 105-107: Update open_file_parent to retain the original
std::path::Path and use the cap_std::fs/Path APIs instead of converting through
Utf8Path, allowing valid non-UTF-8 Unix paths to reach file I/O. Add a Unix-only
regression test that exercises opening a path containing non-UTF-8 bytes and
verifies it succeeds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a87f3bc8-6473-4747-babf-9e2065e61815

📥 Commits

Reviewing files that changed from the base of the PR and between e1cc849 and 580363a.

⛔ Files ignored due to path filters (4)
  • Cargo.lock is excluded by !**/*.lock
  • tests/data/cli-output-parity.dat is excluded by !**/*.dat
  • tests/snapshots/cli__format_to_string_table_prose.snap is excluded by !**/*.snap
  • tests/snapshots/cli__rewrite_in_place_table_prose.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • Cargo.toml
  • docs/architecture.md
  • docs/developers-guide.md
  • src/main.rs
  • tests/cli.rs
  • tests/data/cli-output-parity.expected.md

Comment thread docs/architecture.md
Comment on lines +619 to 645
participant Formatter as format_to_string
participant Rewriter as rewrite_in_place
participant Stdout as Stdout
participant Stderr as Stderr

User->>CLI: Run CLI with multiple files (not in-place)
CLI->>FileHandler: handle_file(file1)
CLI->>FileHandler: handle_file(file2)
CLI->>FileHandler: handle_file(file3)
Note over CLI,FileHandler: Files processed in parallel
FileHandler-->>CLI: Result (Ok(Some(output)) or Err(error))
loop For each file in input order
CLI->>Stdout: Print output (if Ok)
CLI->>Stderr: Print error (if Err)
User->>CLI: Run CLI with multiple files
alt Stdout mode
CLI->>Formatter: format_to_string(file1)
CLI->>Formatter: format_to_string(file2)
CLI->>Formatter: format_to_string(file3)
Note over CLI,Formatter: Files processed in parallel
Formatter-->>CLI: Result<String> or Err(error)
loop For each file in input order
CLI->>Stdout: Print text (if Ok)
CLI->>Stderr: Print error (if Err)
end
else In-place mode
CLI->>Rewriter: rewrite_in_place(file1)
CLI->>Rewriter: rewrite_in_place(file2)
CLI->>Rewriter: rewrite_in_place(file3)
Note over CLI,Rewriter: Files processed in parallel
Rewriter-->>CLI: Result<()> or Err(error)
loop For each file in input order
CLI->>Stderr: Print error (if Err)
end
end
CLI-->>User: Exit (with error if any file errored)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Model the worker calls as parallel branches.

Represent each file operation with a Mermaid par branch and its own result, or
show one batch submission to Rayon. The current sequential arrows contradict
the stated parallel execution model.

Triage: [type:docstyle]

As per coding guidelines, “Make concurrency models explicit for shared state,
async execution, ordering, cancellation, locks, transactions, task lifetimes,
and parallelism.” As per path instructions, “Include a ‘Triage:’ paragraph”
for style comments.

🤖 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 `@docs/architecture.md` around lines 619 - 645, The architecture diagram’s
file-processing calls are shown sequentially despite stating parallel execution.
Update the Stdout and In-place branches to model each file operation as explicit
Mermaid parallel branches (or a single Rayon batch submission), while preserving
ordered result handling and the existing error/exit behavior; include the
required “Triage:” paragraph for this documentation style change.

Sources: Coding guidelines, Path instructions

Comment thread src/main.rs
Comment on lines +105 to +107
fn open_file_parent(path: &Path) -> anyhow::Result<(Dir, Utf8PathBuf)> {
let path = Utf8Path::from_path(path)
.with_context(|| format!("converting {} to a UTF-8 path", path.display()))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== Files ==\n'
git ls-files | rg '^(src/main\.rs|Cargo\.toml|docs/|src/.*\.rs)$'

printf '\n== main.rs outline ==\n'
ast-grep outline src/main.rs --view expanded

printf '\n== Relevant lines in src/main.rs ==\n'
sed -n '1,220p' src/main.rs

printf '\n== Search for open_file_parent and cap_std usage ==\n'
rg -n 'open_file_parent|cap_std::fs_utf8|Utf8Path|Utf8PathBuf|PathBuf|Dir' src/main.rs src/**/*.rs

Repository: leynos/mdtablefix

Length of output: 11962


🌐 Web query:

cap-std 4.0.2 cap_std::fs::Dir Path read write std::path::Path non-UTF-8

💡 Result:

In cap-std 4.0.2, the handling of non-UTF-8 paths depends on which filesystem module you use [1][2]. The primary module, cap_std::fs, is designed to support non-UTF-8 paths by using standard Rust types like std::path::Path and std::ffi::OsString, similar to the standard library's std::fs [3][1]. You should use this module if your application requires support for filenames that are not valid UTF-8 [1][2]. If you specifically require UTF-8-only path handling, cap-std provides an optional fs_utf8 module (enabled via the fs_utf8 Cargo feature) [1][4]. This module uses the camino crate's Utf8Path and Utf8PathBuf types [4]. If you attempt to use this module, it will enforce that all paths are valid UTF-8 [1][2]. Key points regarding path handling in cap-std: 1. Capability-based security: cap-std operates using Dir handles [4]. Methods on Dir (such as read, write, and open) accept paths that are relative to that directory, ensuring sandboxing [5][3]. 2. Path Types: When using cap_std::fs, you interact with standard std::path::Path types, which natively handle non-UTF-8 sequences found on various operating systems [3]. 3. DirEntry: In cap_std::fs, the DirEntry::file_name method returns an OsString, which correctly preserves non-UTF-8 data [6]. 4. Avoiding Restricted Modules: If your application must handle arbitrary non-UTF-8 filesystem paths, avoid the cap_std::fs_utf8 module, as it is explicitly intended to restrict operations to valid UTF-8 paths [1][2].

Citations:


Preserve non-UTF-8 CLI paths.
Stop converting PathBuf into Utf8Path here; cap_std::fs_utf8::Dir rejects valid non-UTF-8 Unix filenames before any file I/O. Use the cap_std::fs/Path boundary instead and add a Unix-only regression test.

🤖 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 `@src/main.rs` around lines 105 - 107, Update open_file_parent to retain the
original std::path::Path and use the cap_std::fs/Path APIs instead of converting
through Utf8Path, allowing valid non-UTF-8 Unix paths to reach file I/O. Add a
Unix-only regression test that exercises opening a path containing non-UTF-8
bytes and verifies it succeeds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(cli): replace handle_file's Option<String> with an explicit Output type

3 participants