Skip to content

use-trusted-publishing: read every argument of PowerShell commands - #2431

Closed
LucaCappelletti94 wants to merge 1 commit into
zizmorcore:mainfrom
LucaCappelletti94:upstream/trusted-publishing-dry-run-pwsh
Closed

LucaCappelletti94 wants to merge 1 commit into
zizmorcore:mainfrom
LucaCappelletti94:upstream/trusted-publishing-dry-run-pwsh

Conversation

@LucaCappelletti94

Copy link
Copy Markdown

Pre-submission checks

Please check these boxes:

  • Mandatory: This PR corresponds to an issue (if not, please create
    one first).

  • Having read the AI policy, I hereby disclose the use of an LLM or other
    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.

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_parameter nodes, so is_publish_command never saw publish and --dry-run together. It now captures the whole command_elements node and reads both plain arguments and parameters from it, which also catches dotnet nuget push and similar commands under pwsh.

cargo publish --features=foo --dry-run stays reported because of #2389.

Test Plan

PowerShell cases added to the cargo-publish.yml and nuget-push.yml inputs.

.map(|cap| {
cap.node
.utf8_text(run.as_bytes())
.flat_map(|cap| {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 airbus-cert/tree-sitter-powershell#46

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I hope that tool will come handy

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.

[BUG]: use-trusted-publishing misreads PowerShell command arguments

2 participants