chore(scripts): detect a SMOKE_BROWSER assignment in any shell dialect (#2146)

Copilot, sixth review: the run-script rule matched POSIX `NAME=value` only.
PowerShell is the DEFAULT shell on a Windows runner, so
`$env:SMOKE_BROWSER = "firefox"; npm run smoke` redirected the suite with the
guard silent — on exactly the workflow least likely to be read closely.

Three patterns now, one per dialect: POSIX (which also covers cmd's
`set NAME=…` and the GitHub-native `>> $GITHUB_ENV` append, since both carry
the same substring), PowerShell's `$env:NAME =` and `${env:NAME} =`, and the
.NET SetEnvironmentVariable call reachable from PowerShell. Regression cases
for all five spellings, plus a negative for a PowerShell assignment of
chromium.

Signed-off-by: Cliff Hall <cliff@futurescale.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-27 01:40:27 -04:00
commit 74aa94fb1f

View file

@ -175,6 +175,52 @@ describe("findWorkflowViolations", () => {
text: workflow(" - run: SMOKE_BROWSER= npm run smoke"),
rules: [VIOLATION.BROWSER_ENV],
},
{
// Copilot, sixth review: PowerShell is the DEFAULT shell on a Windows
// runner, so a POSIX-only pattern is silent on exactly the workflow least
// likely to be read closely.
name: "flags a PowerShell assignment",
text: workflow(
' - run: |\n $env:SMOKE_BROWSER = "firefox"\n npm run smoke',
),
rules: [VIOLATION.BROWSER_ENV],
},
{
name: "flags the PowerShell ${env:NAME} spelling too",
text: workflow(
' - run: ${env:SMOKE_BROWSER}="webkit"; npm run smoke',
),
rules: [VIOLATION.BROWSER_ENV],
},
{
name: "flags a .NET SetEnvironmentVariable call",
text: workflow(
' - run: |\n [Environment]::SetEnvironmentVariable("SMOKE_BROWSER", "firefox")\n npm run smoke',
),
rules: [VIOLATION.BROWSER_ENV],
},
{
// cmd's `set NAME=value` and the GitHub-native `>> $GITHUB_ENV` append
// both carry the POSIX `NAME=value` substring, so one pattern covers all
// three — worth pinning, since that is not obvious from reading it.
name: "flags a cmd-style set",
text: workflow(" - run: set SMOKE_BROWSER=firefox && npm run smoke"),
rules: [VIOLATION.BROWSER_ENV],
},
{
name: "flags an append to $GITHUB_ENV",
text: workflow(
' - run: echo "SMOKE_BROWSER=firefox" >> $GITHUB_ENV',
),
rules: [VIOLATION.BROWSER_ENV],
},
{
name: "allows a PowerShell assignment of chromium",
text: workflow(
' - run: |\n $env:SMOKE_BROWSER = "chromium"\n npm run smoke',
),
rules: [],
},
{
name: "flags a workflow-level env override",
text: [