Repository navigation
loopguard: a here-string is not a heredoc - #176
Merged
Aaron Li (aaron-jx-li) merged 1 commit intoNov 10, 2026
Merged
Aaron Li (aaron-jx-li) merged 1 commit into
Aaron Li (aaron-jx-li) merged 1 commit into
Conversation
`<<<` feeds one word to a command, but the heredoc pattern also matched its last two characters. A command such as `grep -q ok <<< ok` then read every later line as a heredoc body, so a `sed -i` after it was not counted as an edit and a test run after it was not seen by exit_status_covers. microskills' segments() had the same pattern and could elide the commands between a here-string and a later line that starts with its word. Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.com>
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.
Hi Aaron Li (@aaron-jx-li), I ran into this while reading how loopguard tells edits and test runs apart in a shell command.
_HEREDOC_STARTinloopguard/shell_edits.pyalso matches the last two characters of a here-string (<<<). So after something likegrep -q ok <<< "ok", every later line is treated as a heredoc body that never ends. Two effects:sed -i 's/a/b/' pkg/mod.pyon the next line is not counted as an edit, soTurnGuard.foldmisses it.exit_status_covers("python repro.py <<< \"y\"\npython -m pytest -q | tail -3")returns True, because the piped pytest line is hidden inside the "heredoc".microskills/observe.pyhad the same pattern in_HEREDOC_RE, soclassify_commandcould drop the commands between a here-string and a later line starting with its word.The fix is a lookbehind and lookahead so
<<only matches when it is not part of<<<. Real heredocs,<<-and quoted delimiters behave as before.Tests cover the shell-edit detection (including one through
TurnGuard.fold),exit_status_coversandclassify_command. With the fix reverted, 5 of them fail.python -m pytest testspasses on Python 3.10 and 3.13 (855 passed, 16 skipped), andexperiments/testspasses too.#174 also touches heredoc handling, but in
turn.py'sstatus_of_tests, so the two don't overlap.