Skip to content

test: validate $psake.build_success in per-file BeforeDiscovery bootstrap #27

@tablackburn

Description

@tablackburn

Gap

The per-file BeforeDiscovery bootstrap in unit-test files calls Invoke-psake -TaskList 'Build' and proceeds straight to setting $Env:BHBuildOutput / Import-Module, without checking $psake.build_success.

If the Build task fails, the failure is swallowed and the next steps surface as a confusing path-not-found / import error rather than the actual build failure.

BeforeDiscovery {
    if ($null -eq $Env:BHBuildOutput) {
        $invokePsakeParameters = @{
            TaskList  = 'Build'
            BuildFile = $buildFilePath
        }
        Invoke-psake @invokePsakeParameters
        # <-- missing: if (-not $psake.build_success) { throw ... }
    }
    ...
}

Scope

Same gap in all 4 repos using this convention:

Fixing in the template propagates to derived repos on their next sync.

Fix sketch

In tests/Unit/Public/Get-{{Prefix}}Example.tests.ps1 and tests/Unit/Private/*.tests.ps1, after the Invoke-psake call:

Invoke-psake @invokePsakeParameters
if (-not $psake.build_success) {
    throw "Build task failed; cannot Import-Module the staged manifest. See psake output above."
}

Surfaced by

Copilot review on tablackburn/SrrDBAutomationToolkit PR #15 (responded as won't-fix in that PR — the right place is here so all derived repos inherit it).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions