Skip to content

Fix Glancer to return correct FileWindow reflecting actual content read#20

Merged
rbharvs merged 1 commit intomainfrom
brett/fix-returned-window
Jun 21, 2025
Merged

Fix Glancer to return correct FileWindow reflecting actual content read#20
rbharvs merged 1 commit intomainfrom
brett/fix-returned-window

Conversation

@rbharvs
Copy link
Owner

@rbharvs rbharvs commented Jun 21, 2025

Summary

  • Fixes Glancer.glance() to return the actual FileWindow that was read from the file
  • Previously returned the requested window instead of what was actually read
  • For example, requesting 100 lines from an empty file now returns window with line_count=0 instead of line_count=100

Changes Made

  • Added actual_window field to FileReadResult to track what was actually read
  • Updated StreamingFileReader.read_window() to return actual window information
  • Modified Glancer.glance() to use actual_window instead of requested window
  • Updated FileWindow validation to allow line_count=0 for reporting empty reads
  • Added comprehensive test suite (test_glancer_window_behavior.py) with 5 test cases covering edge cases

Test Plan

  • All existing tests continue to pass (150/150)
  • New tests verify correct behavior for empty files, partial reads, and offset beyond file end
  • Manual verification with the original issue example works correctly
  • All linting and type checking passes

Breaking Changes

  • FileReadResult now requires an actual_window field
  • FileWindow.line_count validation changed from ge=1 to ge=0

These are internal API changes that shouldn't affect most users of the public API.

The Glancer.glance() method was returning the requested FileWindow
instead of the actual window that was read from the file. For example,
requesting 100 lines from an empty file would return window with
line_count=100 instead of line_count=0.

Changes:
- Add actual_window field to FileReadResult to track what was actually read
- Update StreamingFileReader to return actual window information
- Modify Glancer.glance() to use actual_window instead of requested window
- Allow FileWindow.line_count=0 for reporting empty reads
- Add comprehensive tests covering various edge cases
@rbharvs rbharvs merged commit c057c11 into main Jun 21, 2025
1 check passed
@rbharvs rbharvs deleted the brett/fix-returned-window branch June 21, 2025 01:51
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