Repository navigation
Conversation
Add-MtTestResultDetail's -Severity 'High' on the failure path never took effect: Invoke-MtNativePlan.ps1 resolves a native test's severity from its [MaesterTest] attribute (Medium) before it ever looks at the helper call, so every failed run already reported Medium. Remove the override so the code no longer implies a severity the check never actually reports (maester365#2692).
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Up to standards ✅🟢 Issues
|
earbona23
left a comment
There was a problem hiding this comment.
The premise checks out, and the engine says so in its own words. powershell/internal/engine/Invoke-MtNativePlan.ps1:467-472:
# Severity: config row (instance, then parent), the instance's, the attribute's, then the helper's.
$severity = if ($setting -and ... ) { ... }
elseif ($isInstance -and (Get-MtInstanceValue -Instance $Instance -Name 'Severity')) { ... }
elseif ($test.Severity) { [string]$test.Severity } # the attribute
elseif ($detail -and $detail.Severity) { [string]$detail.Severity } # the helperThe helper is the last fallback, so for any native test that declares Severity in [MaesterTest] the argument can never win. MT.1208 declares Medium, so High never reached a report. Removing it is right.
It is a class, not an instance
I swept every call to Add-MtTestResultDetail that passes -Severity in tests/ and powershell/internal/checks/. 50 call sites in 47 files, and all 50 are dead: every one of those files declares Severity in its attribute, so :471 always answers first. The 50 split into two groups that need opposite treatment.
Seven pass a literal that contradicts the attribute. These are the ones that actively mislead a reader of the code:
| test | the code asks for | the report shows |
|---|---|---|
MT.1208 |
High | Medium |
MT.1077 |
High | Medium |
MT.1118 |
High | Medium |
CISA.MS.SHAREPOINT.1.1 |
High | Medium |
CISA.MS.SHAREPOINT.1.2 |
High | Medium |
CISA.MS.SHAREPOINT.2.2 |
Low | Medium |
CISA.MS.SHAREPOINT.3.1 |
High | Medium |
So this PR fixes one of seven. Test.CISA.MS.SHAREPOINT.3.1.ps1 is the same shape line for line — Severity = 'Medium' at line 24, -Severity 'High' at line 56.
Fifteen pass a computed value, which is a different problem: deleting the argument there would throw away an intent rather than dead weight.
| test | passes | attribute |
|---|---|---|
MT.1024 |
$priority |
Medium |
MT.1059 |
$Instance.Severity |
Medium |
MT.1182 |
$maxSeverity |
Medium |
MT.1078–MT.1081, MT.1085–MT.1089, MT.1111, MT.1112, MT.1213 |
$Severity |
Low / Medium / High |
MT.1059 is the telling one: it passes $Instance.Severity, and the engine does support exactly that — one line above, at :470, through Get-MtInstanceValue. The intent is supported; it is the route that is wrong. Those fifteen want the instance severity or a config row, not a deletion.
One question on this PR
Removing the argument settles a disagreement silently. The code said High, the report said Medium, and after this the answer is Medium with nothing recording that anyone chose it. You are right that Medium is what shipped, but was Medium the intended severity for a dead-tenant-admin finding, or was High the author's later judgement that never took effect? #2692 is the right place for that if it is open; a line in the PR body either way would stop the next reader reopening it.
Worth a gate
The parameter is not useless in general: Add-MtTestResultDetail.ps1:206 still fills it from the Pester tag for non-native tests, so it cannot just be removed from the signature. But a general test in the shape of TestParameterNames.Tests.ps1 — fail when a native test passes -Severity to the helper — would close the class instead of these seven being found one at a time. I am happy to write that, and the other six literals, as a follow-up PR if you would rather keep this one at a single line.
earbona23
left a comment
There was a problem hiding this comment.
Approving. I re-verified the premise against today's main rather than relying on my earlier reading, because Invoke-MtNativePlan.ps1 changed in between.
The severity resolution order is unchanged (powershell/internal/engine/Invoke-MtNativePlan.ps1:469-473):
$severity = if ($setting -and ...) { ... } # config row
elseif ($isInstance -and (Get-MtInstanceValue ... 'Severity')) { ... } # the instance
elseif ($test.Severity) { [string]$test.Severity } # the attribute <-- answers first
elseif ($detail -and $detail.Severity) { ... } # the helper <-- never reachedMT.1208 declares Severity = 'Medium' at line 27 and passed -Severity 'High' at line 173, so the argument could never reach a report. Removing it is correct, and the net diff is still exactly that one line.
The wider point from my earlier comment stands as a repo-wide observation rather than anything owed by this PR: six other checks pass a literal that contradicts their attribute, Test.CISA.MS.SHAREPOINT.3.1.ps1 being the same shape line for line. Those are separate changes, and fifteen more pass a computed value where deleting the argument would discard an intent instead of dead weight — so a blanket sweep would be wrong.
Summary
-Severity 'High'toAdd-MtTestResultDetail, but native tests resolve severity from the[MaesterTest]attribute before that call ever runs, so the override had no effect, every failed run already reportedMedium. Removed it so the code doesn't claim a severity the check never reports.Test plan
./powershell/tests/pester.ps1(8323 tests) - one unrelated, pre-existingMtConsoleRenderer.Tests.ps1timing flake; everything else passesRefs #2692.
Summary by CodeRabbit