-
Notifications
You must be signed in to change notification settings - Fork 167
fix(consume): consume_direct.sh
files contained invalid commands because value after --filter
flag was not enclosed in parenthesis (issue reported by flcl42)
#1987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…_direct.sh would be invalid because the value after the --filter flag was not wrapped in parenthesis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion on a change to the approach, thanks!
src/ethereum_clis/clis/nethermind.py
Outdated
@@ -55,13 +55,26 @@ def _consume_debug_dump( | |||
result: subprocess.CompletedProcess, | |||
debug_output_path: Path, | |||
): | |||
consume_direct_call = " ".join(command) | |||
# ensure that the --filter flag value is wrapped in parentheses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# ensure that the --filter flag value is wrapped in parentheses | |
# ensure that the --filter flag value is wrapped in double-quotes |
# ensure that the --filter flag value is wrapped in parentheses | ||
consume_direct_call = "" | ||
prev_command_was_filter_flag = False | ||
for s in command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afaik, all parameters that contain spaces need to be enclosed in double-quotes, not only the ones after filter, and not only for the nethermind commands.
Should we look into pre-processing the command
parameter before it's passed to this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick gpt-query yields that we should use shlex.quote
on every parameter to handle this automatically:
import shlex
args = ["my command", "--option", "value with spaces", "file$(rm -rf /)"]
command = " ".join(shlex.quote(arg) for arg in args)
print(command)
Output:
'my command' --option 'value with spaces' 'file$(rm -rf /)'
And shlex
is included in the default libraries so no new package dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not heard of shlex before, so I think it will be harder to read the code if someone sees shlex.quote()
because chances are the reader is not familar with that function. But the current solution is just a few lines of trivial code. I also saw in shlex docs that that function seems to be incompatible with windows, I know that windows support itsn't a prio but why make potential future support harder for no reason.
We could add pre-processing to command
but we need separate logic for fixing the sh command produced by geth's evm anyway, so its simpler to have separate fixes for nethtest and geth and then decide to not add support for more execution clients. For geth's evm specifically we create faulty .sh files for blockchain tests, I will add another commit to fix it too. All problems are just results from our decision to allow weird chars like :
, [
and ]
in filenames which makes escaping of names ugly and error-prone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on this takes me longer than expected because I can't get logging to work for some reason. Edit: found temporary workaround
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from our decision to allow weird chars like
:
,[
and]
in filenames
Just for clarification, they are part of the test names, not file names, this is a pytest intrinsic issue.
I also saw in shlex docs that that function seems to be incompatible with windows
This will end up in a .sh
file anyway, which needs bash to run. If required it we could build a windows script in the future but I feel like that's out of scope for this PR.
I think it will be harder to read the code if someone sees shlex.quote() because chances are the reader is not familar with that function.
That's true, I haven't heard of it before but (a) this is deep into the weeds of the code anyway, I would be more concerned if this was part of a test, and (b) it's really easy to look it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point with the .sh
lol.. I would not be against shlex if I didn't already build a solution. Can re-do this PR and start from scratch (and use shlex) if you want
I have now figured out what we must change to also fix geth's evm command in the sh files. There actually are 2 issues with blockchain tests:
So e.g. currently in the .sh file you would see sth like:
when actually the command should be
|
Can be merged as is, I tested both |
Is making use of shlex a requirement to get this merged? The current solution works well and has been tested, I don't think this is a part of the codebase we will touch often |
🗒️ Description
Title says it all, simple fix. Context: #1843 , more specifically this comment by flcl
What is fixed?
Before this PR, if you run sth like
uv run consume direct --bin=nethtest --input=stable@latest --traces --dump-dir=evm-tmp -n 8 -k push0
and then try to run a
consume_direct.sh
file like./push0_contracts/tests-shanghai-eip3855_push0-test_push0.py::test_push0_contracts[fork_Shanghai-blockchain_test_from_state_test-gas_cost]/consume_direct.sh
you will see sth like:
This PR fixes this, after applying it the command works as expected (e.g.):
Both Nethtest and geth's evm were leading to faulty sh files and this PR fixes both.
🔗 Related Issues or PRs
N/A.
✅ Checklist
tox
checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:uvx --with=tox-uv tox -e lint,typecheck,spellcheck,markdownlint
type(scope):
.mkdocs serve
locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.@ported_from
marker.