Skip to content

fix(operation): report actual file total_lines instead of content slice line count#2771

Merged
tusharmath merged 3 commits intomainfrom
fix-total-lines
Apr 1, 2026
Merged

fix(operation): report actual file total_lines instead of content slice line count#2771
tusharmath merged 3 commits intomainfrom
fix-total-lines

Conversation

@tusharmath
Copy link
Copy Markdown
Collaborator

@tusharmath tusharmath commented Apr 1, 2026

Summary

Fix total_lines attribute in file read output to report the actual total line count of the file rather than the number of lines in the returned content slice.

Context

When reading a file with an explicit line range or when truncation is applied, the total_lines XML attribute was computed as content.lines().count() — i.e., the number of lines in the returned content rather than the total number of lines in the full file. This caused the attribute to be misleading: an agent reading lines 2–3 of a 5-line file would see total_lines="3" instead of total_lines="5", and a truncated read of a 200-line file would report total_lines="1".

The FileInfo struct already carries the correct total_lines value populated during the read operation, so the fix is straightforward.

Changes

  • Replaced content.lines().count() with output.info.total_lines when emitting the total_lines XML attribute in operation.rs
  • Updated two insta snapshots to reflect the corrected values:
    • fs_read_with_explicit_range: total_lines now correctly shows 5 (full file) instead of 3 (lines in the range)
    • fs_read_with_truncation_path: total_lines now correctly shows 200 (full file) instead of 1 (lines in the truncated output)

Testing

cargo insta test --accept -p forge_app

Both snapshot tests now assert the correct total_lines value that reflects the actual file size.

@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Apr 1, 2026
@tusharmath tusharmath changed the title fix total lines fix(operation): correct total_lines attribute and fix ZSH plugin lazy-loading compatibility Apr 1, 2026
@tusharmath tusharmath changed the title fix(operation): correct total_lines attribute and fix ZSH plugin lazy-loading compatibility fix(operation): correct total_lines attribute in file read Apr 1, 2026
@tusharmath tusharmath changed the title fix(operation): correct total_lines attribute in file read fix(operation): report actual file total_lines instead of content slice line count Apr 1, 2026
@tusharmath tusharmath enabled auto-merge (squash) April 1, 2026 18:19
@tusharmath tusharmath merged commit 9aa2a80 into main Apr 1, 2026
9 checks passed
@tusharmath tusharmath deleted the fix-total-lines branch April 1, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant