fix: update stale interactive-loop snippets in implementation.md (#1167)#1168
Open
fix: update stale interactive-loop snippets in implementation.md (#1167)#1168
Conversation
Update _read_line_nonblocking snippet to include EOFError raise on closed stdin. Add 'except EOFError: break' clause to the fallback reader snippet. Update surrounding prose to document the EOFError early-exit path. Add test_read_line_nonblocking_doc_snippet_matches_implementation to tests/test_docs.py to prevent future drift between docs and code. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates the interactive-loop documentation to match the current copilot_usage.cli EOF handling behavior, and adds regression tests to prevent future doc/implementation drift.
Changes:
- Refreshes
implementation.mdsnippets/prose to include_read_line_nonblockingraisingEOFError("stdin closed")and_interactive_loopbreaking onEOFError. - Adds a new docs regression test that checks the implementation and documentation mention EOFError handling.
- Imports
inspectto enable source-based assertions in the new test.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
tests/test_docs.py |
Adds a regression test using inspect.getsource to ensure EOFError handling remains reflected in both code and docs. |
src/copilot_usage/docs/implementation.md |
Updates interactive-loop snippets and prose to accurately document EOFError behavior and fallback reader control flow. |
Comment on lines
+317
to
+320
| # _read_line_nonblocking must mention EOFError (source or docstring) | ||
| read_src = inspect.getsource(cli_mod._read_line_nonblocking) | ||
| assert "EOFError" in read_src, ( | ||
| "_read_line_nonblocking source must reference EOFError — " |
Comment on lines
+324
to
+329
| # _interactive_loop must have 'except EOFError' near the | ||
| # ValueError/OSError fallback logic | ||
| loop_src = inspect.getsource(cli_mod._interactive_loop) | ||
| assert "except EOFError" in loop_src, ( | ||
| "_interactive_loop source must contain 'except EOFError' — " | ||
| "the loop breaks immediately when stdin is closed" |
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.
Closes #1167
Changes
Documentation (
src/copilot_usage/docs/implementation.md)_read_line_nonblockingsnippet — Updated to match the actual implementation that checks for emptyreadline()and raisesEOFError("stdin closed")to prevent infinite polling.Fallback reader snippet — Added the
except EOFError: breakclause beforeexcept (ValueError, OSError):to reflect the actual control flow in_interactive_loop.Prose updates — Updated the "Non-blocking input with
select()" subsection to mention that_read_line_nonblockingraisesEOFErrorwhen stdin is closed, and updated the fallback section to explain thatEOFErrorcauses an immediate loop break rather than starting the fallback reader.Tests (
tests/test_docs.py)Added
test_read_line_nonblocking_doc_snippet_matches_implementationwhich:EOFErrorappears in_read_line_nonblocking's source viainspect.getsourceexcept EOFErrorappears in_interactive_loop's sourceEOFErrorappears inimplementation.mdThis prevents the docs from silently diverging from the implementation again.
Warning
The following domains were blocked by the firewall during workflow execution:
astral.shpypi.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.