Skip to content

fix(tests): Golden.Tests.ps1 imports the module it reaches into - #2816

Open
earbona23 wants to merge 1 commit into
maester365:mainfrom
earbona23:fix/golden-tests-solo-execution
Open

earbona23 wants to merge 1 commit into
maester365:mainfrom
earbona23:fix/golden-tests-solo-execution

Conversation

@earbona23

@earbona23 earbona23 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Golden.Tests.ps1 reaches into the module with InModuleScope Maester but never imports it, so it passes only when another test file in the same run imported it first. Run on its own, it fails:

No modules named 'Maester' are currently loaded.

Measured on main at 2d659e8, the file on its own through Pester 5.7.1:

Result
main, as it is 12 passed, 1 failed
with this one line 13 passed, 0 failed

CI never sees it, because it runs every file in one invocation where something else has already imported the module. The cost falls on a contributor doing what AGENTS.md says to do — add a built-in test, run build/golden/Export-MtGoldenFixture.ps1, then run this file to check the fixtures — and meeting a failure that has nothing to do with their change. I ran into it while checking whether something of mine had broken the fixtures; it had not.

One line, in the form the other 98 test files use. It does not disturb a combined run: this file together with AttributeReview, NativeTestAttributes and Test-MtCaEmergencyAccessExists in a single Invoke-Pester gives 93 of 93.

The red build-validation (ubuntu-latest) this will show is main's, not this change: four tests fail there today, and #2795 and #2797 between them account for all four.

Summary by CodeRabbit

  • Tests
    • Made golden fixture tests load the module before running, so they no longer depend on test-file execution order.

Golden.Tests.ps1 reaches into the module with InModuleScope Maester but never
imports it, so it passes only when another test file in the same run imported it
first. Run on its own it fails with "No modules named 'Maester' are currently
loaded".

Measured on main at 2d659e8:

    Golden.Tests.ps1 alone, as it is:    12 passed, 1 failed
                                         -> No modules named 'Maester' are currently loaded.
    Golden.Tests.ps1 alone, with this:   13 passed, 0 failed

CI never saw it, because it runs every file in one invocation where something
else has already imported the module. The cost falls on a contributor who
follows AGENTS.md - add a built-in test, run the exporter, then run this file to
check the fixtures - and meets a failure that has nothing to do with the change
being made.

One line, in the form the other 98 test files use. It does not disturb a
combined run: this file together with AttributeReview, NativeTestAttributes and
Test-MtCaEmergencyAccessExists in a single Invoke-Pester gives 93 of 93.
@earbona23
earbona23 requested a review from a team as a code owner November 15, 2026 18:40
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The golden fixture test setup now imports Maester.psd1 with -Force in BeforeAll, before tests enter InModuleScope.

Changes: Golden fixture tests

Layer / File(s) Summary
Import module before module-scoped tests
powershell/tests/functions/golden/Golden.Tests.ps1
BeforeAll imports Maester.psd1 with -Force before tests enter InModuleScope.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Other

Suggested reviewers: merill

Merge Risk: Minimal · up to 2f69b

This is a test-only change that lets the golden fixture tests run on their own without depending on another test file to load the module. It has no production impact and is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: Golden.Tests.ps1 now imports the module it uses via InModuleScope. The raw summary confirms a Maester import was added in BeforeAll to that file. The title is specific and …
Description check Passed The description follows the template's main content. It explains the problem (the file uses InModuleScope Maester without importing it), gives reproduction evidence (12 passed, 1 failed on main versus…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: Golden.Tests.ps1 now imports the module it uses via InModuleScope. The raw summary confirms a Maester import was added in BeforeAll to that file. The title is specific and matches the single-file change. It follows the conventional fix(tests) form and is 63 characters, so it is concise.

Full details: Description check

Explanation

The description follows the template's main content. It explains the problem (the file uses InModuleScope Maester without importing it), gives reproduction evidence (12 passed, 1 failed on main versus 13 passed with the fix), and notes the combined-run check (93 of 93). It also explains why CI missed the failure and notes the unrelated build-validation failures. It does not fill in the template's Closes issue line, and the Checks boxes are unticked. The template's description and checklist sections are still missing a linked issue and a checklist confirmation, but the substance is complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2d659e8 and 2f69bf6.

Files selected for processing: 1

  • powershell/tests/functions/golden/Golden.Tests.ps1

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

This branch has not been deployed

No deployments
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.

1 participant