Repository navigation
Conversation
… runs In coverage mode pester.ps1 passes every test file to one Invoke-Pester call from its own scope, so a test that reads a variable it never assigned resolves it up the scope chain and finds the runner's. `$config = New-PesterConfiguration` was therefore visible to the tests as `$config`. Test-MtCaEmergencyAccessExists.Tests.ps1 has five cases that pass `$config` to the check while meaning "no configuration", so that it auto-detects. In coverage mode they received the PesterConfiguration object instead: three failed and two passed for the wrong reason. Coverage runs only on the Linux leg of build-validation, which is why the failures appeared there and nowhere else. The runner's locals become `$pesterConfig` and `$pesterRun`, and the five cases say `$null` instead of relying on a variable not existing.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Up to standards ✅🟢 Issues
|
|
@merill two test-infrastructure fixes that together take #2795 adds a missing byte order mark to #2797 is the other three. In coverage mode Measured on unmodified The fix in #2797 is a rename of two locals in |
|
Measured what this fixes, since "the runner's variables leak" is hard to size from the diff.
The remaining one is the byte order mark, which #2795 removes.
Two details that make the diagnosis legible:
One warning for anyone reading those logs: the 28 of the 40 open non-draft PRs show that leg red today, on changes that did not cause it. |
|
Measured evidence that this PR and #2795 are complementary and that together they take
The subtraction is clean: the baseline is four, #2795 removes exactly the one it is about, #2797 removes exactly the three it is about, and no other failure appears in any of the four runs. The BOM failure names the file in its own message — Two notes for whoever picks this up:
The totals differ per run (8743, 8756, 8760) because each branch adds its own tests; the failure counts are what matter. Every open PR against |
|
Still Every open PR that actually runs the suite on Ubuntu is red. Of the 45 open non-draft PRs:
The two green ones from today, #2808 and #2809, touch only From the job logs:
The point I had not made before: a check that is red on every PR has stopped being a signal. A real regression arriving tomorrow would land as red-on-already-red and be indistinguishable from the four standing failures — most of all for the 20 authors who have no reason to suspect the red is not theirs. This one is test-infrastructure only: it stops the runner's own variables leaking into the tests it runs. It does not touch product code and is independent of #2795; either can go first. Happy to rebase, split, or re-measure anything on request. |
build-validation (ubuntu-latest)has been failing three tests inTest-MtCaEmergencyAccessExists.Tests.ps1while macOS and Windows stay green. This is why, and it is not the tests being flaky.The mechanism
In coverage mode
pester.ps1passes every test file to oneInvoke-Pestercall, from its own scope:A test that reads a variable it never assigned resolves it up the scope chain, and in that single combined invocation the chain reaches the runner. So
$configinside a test is the runner'sPesterConfiguration.Test-MtCaEmergencyAccessExists.Tests.ps1has five cases that pass$configto the check while meaning "no configuration supplied", so that it auto-detects:$configis only assigned inside the otherItblocks, so in a per-file run it is genuinely$nullthere. Measured, with aWrite-Hostadded to one of those cases on a throwaway copy:The check receives a
PesterConfigurationinstead of$null, skips auto-detection, and returns$false. Three cases fail. Two more pass for the wrong reason — they expect$falseand aPesterConfigurationalso produces$false.Coverage is enabled only on the Linux leg (
PESTER_COVERAGE: "${{ runner.os == 'Linux' && 'true' || 'false' }}"), which is exactly where the failures appear.Reproduced, both large and small
On unmodified
mainat02a220b2:-TestGeneral:$false)PESTER_COVERAGE=truePESTER_COVERAGE=true, twiceThe four in the full coverage run are these three plus the byte-order-mark test, which is #2795. Together the two PRs take that leg to zero. CI's own Linux leg reported 4 of 8,760 on an unrelated PR of mine, which is the same four.
Note what the single-file reproduction rules out: it is not an interaction between test files, and it is not the coverage instrumentation. A direct
Invoke-Pesterwith the sameCodeCoverageconfiguration — profiler or breakpoints, module pre-imported or not — passes 20 of 20. Only going throughpester.ps1fails, because only then is the runner's$configin the scope chain.The fix
pester.ps1: the two locals a test could capture become$pesterConfigand$pesterRun. That is the fix: it protects every test, present and future, without anyone having to know this rule.$nullinstead of relying on a variable not existing, so the file states its premise.$resultis renamed as cheap insurance rather than a known bug: two files reference$resultwithout assigning it in the sameIt, and I checked that both pass in either mode today. Drop that half if you prefer the minimum change.Verified
The third line is the one that matters for review: with only
pester.ps1changed and the test file exactly as it is onmain, the three cases pass. The test-side change is clarity, not the repair.No test asserts this behaviour, and I have not added one. A test that a test file cannot see the runner's variables would have to run
pester.ps1inside Pester, which is more machinery than the one-line rename deserves — but if you want it, the shape is a case that runspester.ps1 -Coverageover a fixture file that fails when$pesterConfigis visible to it.Summary by CodeRabbit
Update — folded in the missing-BOM fix (supersedes #2795).
The
ubuntu-latestbuild-validationleg is red onmainfor two independent reasons, and only the Linux leg runs the combined coverage pass that surfaces them:$configleaking into the tests it runs (fixed here), andpowershell/tests/functions/Invoke-MtPackGitHubRequest.Tests.ps1, flagged by theFileEncodingtest and originally fixed in fix(tests): add the missing byte order mark to Invoke-MtPackGitHubRequest.Tests.ps1 #2795.Neither fix greens the leg on its own, so #2795 and this PR each stayed red by construction and could not pass the green-check merge gate separately. This PR now carries both, so a single
ubuntu-latestrun goes green and it can merge on its own. Closing #2795 as superseded. This clears the ubuntu red inherited by many of the open PRs.