-
Notifications
You must be signed in to change notification settings - Fork 687
test(ci): bind the Windows shard assertion to an executable command (#1185) #1301
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,15 @@ function count(text: string, fragment: string): number { | |
| return text.split(fragment).length - 1; | ||
| } | ||
|
|
||
| /** Match an executable shell line, not a fragment that could appear in echo or a comment. */ | ||
| function hasExactShellCommand(run: string | undefined, expected: string): boolean { | ||
| return (run ?? "") | ||
| .split(/\r?\n/) | ||
| .map(line => line.trim()) | ||
| .filter(line => line.length > 0 && !line.startsWith("#")) | ||
| .includes(expected); | ||
| } | ||
|
|
||
|
Comment on lines
+42
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Reject exact command text that is not executable.
run: |
<#
bun test --isolate tests --shard=${{ matrix.shard }}/4
#>The step has no Proposed fix- const windowsTestSteps = winSteps.filter(step => hasExactShellCommand(step.run, windowsTestCommand));
+ const windowsTestSteps = winSteps.filter(
+ step => step.run?.trim() === windowsTestCommand,
+ );Also applies to: 176-184 🤖 Prompt for AI Agents |
||
| function expectSecureLinuxKeyringBootstrap(workflow: string): void { | ||
| const smokeStep = workflow | ||
| .split("- name: OS keyring create/read/delete smoke")[1] | ||
|
|
@@ -164,7 +173,15 @@ describe("GitHub Actions hardening", () => { | |
| // the runner's disk and the suite passes against a tree that no longer | ||
| // exists in git. | ||
| const winSteps = (ci.jobs?.["platform-windows"] as { steps?: { if?: string; run?: string }[] })?.steps ?? []; | ||
| expect(winSteps.some(step => step.run?.includes(`--shard=\${{ matrix.shard }}/${windowsShards.length}`))).toBe(true); | ||
| const windowsTestCommand = `bun test --isolate tests --shard=\${{ matrix.shard }}/${windowsShards.length}`; | ||
| expect(hasExactShellCommand(`echo ${windowsTestCommand}`, windowsTestCommand)).toBe(false); | ||
| // Binding the assertion to an executable line is only half the guarantee: a | ||
| // step carrying the exact command still runs nothing under `if: false`, and | ||
| // the suite would stay green against a Windows leg that never tests. Require | ||
| // the matching step to be unconditional. | ||
| const windowsTestSteps = winSteps.filter(step => hasExactShellCommand(step.run, windowsTestCommand)); | ||
| expect(windowsTestSteps.length).toBeGreaterThan(0); | ||
| expect(windowsTestSteps.every(step => step.if === undefined)).toBe(true); | ||
| expect(winSteps.some(step => step.if === "runner.environment == 'self-hosted'" | ||
| && step.run?.includes("git clean -xffd"))).toBe(true); | ||
|
|
||
|
|
||
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.
When the Windows Test step wraps the command in a PowerShell block comment such as
<#\nbun test ...\n#>, this filter retains the command line andhasExactShellCommandreturns true, even though the step executes no tests; the step has no explicit shell, so Windows uses PowerShell. This leaves the same silent no-test regression the new assertion is intended to prevent. Compare the trimmedrunvalue directly with the expected single-line command, or otherwise account for PowerShell block comments rather than filtering only lines beginning with#.Useful? React with 👍 / 👎.