use-trusted-publishing: read every argument of PowerShell commands #2431
I'm not sure this approach is what we want: it effectively pierces the abstraction across different tree-sitter grammars, which also means it'll break in hard to predict ways if any other grammar happens to add node kinds that match these PowerShell names. Is there a way to fix the query itself so that it captures what we're expecting here?
The answer might be "no" without a fix to https://github.com/airbus-cert/tree-sitter-powershell/issues/46
Requested changes.
I will extend the test suite with a few adversarial cases and see what is the cleanest general solution I can come up with. I will also spend a second looking at upstream, in case by any chance that could be the first domino to push down. Given the issue is only a few months old and not one of the pre-covid era, I hope it may be still there only because of it being not too important and not because it is cursed.
Ok so I spend a bit more time rabbit-holing upstream than I care to admit, set up a differential fuzzer against the original windows C# lexer and it is a bit of a disaster, it found a vast amount of errors. I believe that this problem I reported here yesterday and patched in an arguably not sufficiently general way is only one of several possible corner cases that the parser upstream does not handle correctly.
I am unsure regarding how to proceed, as clearly the tree-sitter-powershell needs extensive improvement and I absolutely do not have the bandwidth to fix it.
Yeah, that was unfortunately the conclusion I came to as well when I saw the --foo=bar issue -- the grammar does not appear to follow Microsoft's own documented grammar closely, and has lots of gaps.
I think long term I'm going to replace tree-sitter-powershell with zizmor-tree-sitter-powershell, which will almost certainly just be written by an LLM and reviewed by me with a bunch of known-answer tests and fuzz/differential testing.
(But thank you for looking into it! I greatly appreciate the effort you've put in, especially setting up a differential test harness for the upstream.)
Yeah I hope that tool will come handy
woodruffw
LucaCappelletti94
Pre-submission checks
Please check these boxes:
one first).
AI coding assistant in the creation of this PR. PRs will not be rejected
for using AI tools, but will be rejected for undisclosed use or
use that violates the policy.
[AI policy]: https://github.com/zizmorcore/.github/blob/main/AI_POLICY.md
If a checkbox is not applicable, you can leave it unchecked.
Summary
Fixes #2430.
The PowerShell query from #1357 yielded one match per argument and skipped
command_parameternodes, sois_publish_commandnever sawpublishand--dry-runtogether. It now captures the wholecommand_elementsnode and reads both plain arguments and parameters from it, which also catchesdotnet nuget pushand similar commands underpwsh.cargo publish --features=foo --dry-runstays reported because of #2389.Test Plan
PowerShell cases added to the
cargo-publish.ymlandnuget-push.ymlinputs.<!-- IMPORTANT: Do not delete the following lines. -->
<!-- @@NUDNIK NEUTRALIZER@@ -->