Skip to content

loopguard: read a wrapper's own options before a shell edit - #237

Open
KVR Vishnu (VISHNU0906) wants to merge 1 commit into
microsoft:mainfrom
VISHNU0906:fix/wrapper-options-shell-edits
Open

KVR Vishnu (VISHNU0906) wants to merge 1 commit into
microsoft:mainfrom
VISHNU0906:fix/wrapper-options-shell-edits

Conversation

@VISHNU0906

Copy link
Copy Markdown
Contributor

Hi Saksham Uboweja (@SakshamUboweja), a follow-up to #212 and #213, this time in _bare in loopguard/shell_edits.py.

_bare drops the wrapper in front of a command before the parser looks at it, but it only dropped the wrapper's name. If the wrapper had options of its own, the first option became the "command" and the edit was lost:

  • env -u CURSOR_AGENT sed -i 's/a/b/' pkg/mod.py and sudo -u bob sed -i ... were not counted as edits
  • timeout and nice were not in the list at all, so timeout 60 sed -i ... and nice -n 10 sed -i ... were missed too (the verification side already knows these from _PREFIX_RE in turn.py)
  • the same went for git apply, tee and a git checkout -- revert run through any of them

Now _bare goes past each wrapper's options, including the ones that take a value (sudo -u/-g/-C/..., env -u/-C, timeout -s/-k, nice -n, time -o/-f), short clusters like sudo -Eu bob, attached values like nice -n5, --, and timeout's duration. VAR=1 words between wrappers are still skipped. Plain sudo sed -i ... and the rest behave as before, and reads like env -u X sed -n '1,20p' f.py still count as nothing.

Tests: new cases in test_edits_made_through_the_shell_are_recognised, plus one through TurnGuard.fold that checks two wrapped edits and a sudo -u bob git checkout -- revert all count. With shell_edits.py from main, 11 of them fail. python -m pytest tests experiments/tests passes on Python 3.10 and 3.13 (1407 passed, 20 skipped), and scripts/dead_code.py output is the same as on main.

`_bare` dropped only the name of sudo, env, time, nohup and command, so
`env -u VAR sed -i ...` or `sudo -u bob sed -i ...` left the option as
the command and the edit was not counted. timeout and nice were not
dropped at all, so `timeout 60 sed -i ...` was missed too, and so was a
`git checkout --` revert run through any of them.

Skip each wrapper's options, with the ones that take a value
(`sudo -u`, `env -u/-C`, `timeout -s/-k`, `nice -n`, `time -o/-f`),
and timeout's duration.

Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.com>
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