From 5a498169330e7284674ce3982b33f8c25fa80853 Mon Sep 17 00:00:00 2001 From: Stiwi Gabriel Courage Date: Tue, 28 Apr 2026 09:56:49 +0200 Subject: [PATCH 1/3] feat(#100): add architecture guardrails tests for NovaModuleTools - Implement tests to ensure public commands do not use raw infrastructure primitives - Centralize environment-variable access in the shared helper - Centralize direct git execution in the shared git adapter - Ensure raw upload requests are handled by the package request adapter --- tests/ArchitectureGuardrails.Tests.ps1 | 74 ++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/ArchitectureGuardrails.Tests.ps1 diff --git a/tests/ArchitectureGuardrails.Tests.ps1 b/tests/ArchitectureGuardrails.Tests.ps1 new file mode 100644 index 00000000..561ef085 --- /dev/null +++ b/tests/ArchitectureGuardrails.Tests.ps1 @@ -0,0 +1,74 @@ +BeforeAll { + $script:repoRoot = Split-Path -Parent $PSScriptRoot + $script:srcRoot = Join-Path $script:repoRoot 'src' + $script:findMatches = { + param( + [Parameter(Mandatory)][string]$Pattern, + [Parameter(Mandatory)][string]$RootPath + ) + + $matches = foreach ($file in (Get-ChildItem -LiteralPath $RootPath -Filter '*.ps1' -Recurse -File)) { + foreach ($match in (Select-String -Path $file.FullName -Pattern $Pattern)) { + [pscustomobject]@{ + Path = ([System.IO.Path]::GetRelativePath($script:repoRoot, $file.FullName)).Replace('\', '/') + Line = $match.LineNumber + Text = $match.Line.Trim() + } + } + } + + return @($matches) + } + $script:getMatchedPaths = { + param([AllowNull()][object[]]$MatchList) + + if ($null -eq $MatchList) { + return @() + } + + return @($MatchList | ForEach-Object Path | Sort-Object -Unique) + } + $script:formatMatches = { + param([AllowNull()][object[]]$MatchList) + + if ($null -eq $MatchList) { + return 'No matches.' + } + + return ($MatchList | ForEach-Object { + "$( $_.Path ):$( $_.Line ) -> $( $_.Text )" + }) -join [Environment]::NewLine + } +} + +Describe 'Architecture guardrails' { + It 'public commands stay free of raw infrastructure primitives' { + $matches = & $script:findMatches -RootPath (Join-Path $script:srcRoot 'public') -Pattern 'ConvertFrom-Json|ConvertTo-Json|Invoke-WebRequest|Invoke-RestMethod|Update-Module|&\s*git\b|\$env:|GetEnvironmentVariable\(' + + $matches | Should -BeNullOrEmpty -Because (& $script:formatMatches -MatchList $matches) + } + + It 'direct environment-variable access stays centralized in the shared helper' { + $matches = & $script:findMatches -RootPath $script:srcRoot -Pattern '\$env:|GetEnvironmentVariable\(' + $actual = & $script:getMatchedPaths -MatchList $matches + $expected = @('src/private/shared/GetNovaEnvironmentVariableValue.ps1') + + (Compare-Object -ReferenceObject $expected -DifferenceObject $actual) | Should -BeNullOrEmpty -Because (($actual -join ', '), (& $script:formatMatches -MatchList $matches) -join [Environment]::NewLine) + } + + It 'direct git execution stays centralized in the shared git adapter' { + $matches = & $script:findMatches -RootPath $script:srcRoot -Pattern '&\s*git\b' + $actual = & $script:getMatchedPaths -MatchList $matches + $expected = @('src/private/shared/InvokeNovaGitCommand.ps1') + + (Compare-Object -ReferenceObject $expected -DifferenceObject $actual) | Should -BeNullOrEmpty -Because (($actual -join ', '), (& $script:formatMatches -MatchList $matches) -join [Environment]::NewLine) + } + + It 'raw upload requests stay behind the package request adapter' { + $matches = & $script:findMatches -RootPath $script:srcRoot -Pattern '\bInvoke-WebRequest\b' + $actual = & $script:getMatchedPaths -MatchList $matches + $expected = @('src/private/package/InvokeNovaPackageUploadRequest.ps1') + + (Compare-Object -ReferenceObject $expected -DifferenceObject $actual) | Should -BeNullOrEmpty -Because (($actual -join ', '), (& $script:formatMatches -MatchList $matches) -join [Environment]::NewLine) + } +} From 497b224afad838475eab8266a9f7ee9c3e9c911f Mon Sep 17 00:00:00 2001 From: Stiwi Gabriel Courage Date: Tue, 28 Apr 2026 10:00:34 +0200 Subject: [PATCH 2/3] feat(#100): add architecture guardrails tests for NovaModuleTools - implement tests for self-update execution order - verify public orchestration entrypoints delegate to context and workflow helpers - ensure project.json persistence is limited to expected callers --- tests/ArchitectureGuardrails.Tests.ps1 | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/ArchitectureGuardrails.Tests.ps1 b/tests/ArchitectureGuardrails.Tests.ps1 index 561ef085..fd789154 100644 --- a/tests/ArchitectureGuardrails.Tests.ps1 +++ b/tests/ArchitectureGuardrails.Tests.ps1 @@ -71,4 +71,49 @@ Describe 'Architecture guardrails' { (Compare-Object -ReferenceObject $expected -DifferenceObject $actual) | Should -BeNullOrEmpty -Because (($actual -join ', '), (& $script:formatMatches -MatchList $matches) -join [Environment]::NewLine) } + + It 'self-update execution stays behind the update command adapter' { + $matches = & $script:findMatches -RootPath $script:srcRoot -Pattern '^\s*(?:return\s+)?Update-Module\b' + $actual = & $script:getMatchedPaths -MatchList $matches + $expected = @('src/private/update/InvokeNovaModuleUpdateCommand.ps1') + + (Compare-Object -ReferenceObject $expected -DifferenceObject $actual) | Should -BeNullOrEmpty -Because (($actual -join ', '), (& $script:formatMatches -MatchList $matches) -join [Environment]::NewLine) + } + + It 'public orchestration entrypoints keep delegating to their context and workflow helpers' { + $testCases = @( + [pscustomobject]@{Path = 'src/public/DeployNovaPackage.ps1'; ContextPattern = '\bGet-NovaPackageUploadWorkflowContext\b'; ActionPattern = '\bInvoke-NovaPackageUploadWorkflow\b'} + [pscustomobject]@{Path = 'src/public/InitializeNovaModule.ps1'; ContextPattern = '\bGet-NovaModuleInitializationWorkflowContext\b'; ActionPattern = '\bInvoke-NovaModuleInitializationWorkflow\b'} + [pscustomobject]@{Path = 'src/public/InstallNovaCli.ps1'; ContextPattern = '\bGet-NovaCliInstallWorkflowContext\b'; ActionPattern = '\bInvoke-NovaCliInstallWorkflow\b'} + [pscustomobject]@{Path = 'src/public/InvokeNovaBuild.ps1'; ContextPattern = '\bGet-NovaBuildWorkflowContext\b'; ActionPattern = '\bInvoke-NovaBuildWorkflow\b'} + [pscustomobject]@{Path = 'src/public/InvokeNovaCli.ps1'; ContextPattern = '\bGet-NovaCliInvocationContext\b'; ActionPattern = '\bInvoke-NovaCliCommandRoute\b'} + [pscustomobject]@{Path = 'src/public/InvokeNovaRelease.ps1'; ContextPattern = '\bGet-NovaPublishWorkflowContext\b'; ActionPattern = '\bInvoke-NovaReleaseWorkflow\b'} + [pscustomobject]@{Path = 'src/public/NewNovaModulePackage.ps1'; ContextPattern = '\bGet-NovaPackageWorkflowContext\b'; ActionPattern = '\bInvoke-NovaPackageWorkflow\b'} + [pscustomobject]@{Path = 'src/public/PublishNovaModule.ps1'; ContextPattern = '\bGet-NovaPublishWorkflowContext\b'; ActionPattern = '\bInvoke-NovaPublishWorkflow\b'} + [pscustomobject]@{Path = 'src/public/SetNovaUpdateNotificationPreference.ps1'; ContextPattern = '\bGet-NovaUpdateNotificationPreferenceChangeContext\b'; ActionPattern = '\bInvoke-NovaUpdateNotificationPreferenceChange\b'} + [pscustomobject]@{Path = 'src/public/TestNovaBuild.ps1'; ContextPattern = '\bGet-NovaTestWorkflowContext\b'; ActionPattern = '\bInvoke-NovaTestWorkflow\b'} + [pscustomobject]@{Path = 'src/public/UpdateNovaModuleTools.ps1'; ContextPattern = '\bGet-NovaModuleSelfUpdateWorkflowContext\b'; ActionPattern = '\bInvoke-NovaModuleSelfUpdateWorkflow\b'} + [pscustomobject]@{Path = 'src/public/UpdateNovaModuleVersion.ps1'; ContextPattern = '\bGet-NovaVersionUpdateWorkflowContext\b'; ActionPattern = '\bInvoke-NovaVersionUpdateWorkflow\b'} + ) + + foreach ($testCase in $testCases) { + $filePath = Join-Path $script:repoRoot $testCase.Path + $content = Get-Content -LiteralPath $filePath -Raw + + $content | Should -Match $testCase.ContextPattern -Because "$( $testCase.Path ) should build or resolve its workflow/context state before orchestration" + $content | Should -Match $testCase.ActionPattern -Because "$( $testCase.Path ) should delegate execution to its workflow or routing helper" + } + } + + It 'project.json persistence stays limited to the shared writer and its expected callers' { + $matches = & $script:findMatches -RootPath $script:srcRoot -Pattern '\bWrite-ProjectJsonData\b' + $actual = & $script:getMatchedPaths -MatchList $matches + $expected = @( + 'src/private/release/SetNovaModuleVersion.ps1' + 'src/private/scaffold/WriteNovaModuleProjectJson.ps1' + 'src/private/shared/Write-ProjectJsonData.ps1' + ) + + (Compare-Object -ReferenceObject $expected -DifferenceObject $actual) | Should -BeNullOrEmpty -Because (($actual -join ', '), (& $script:formatMatches -MatchList $matches) -join [Environment]::NewLine) + } } From 39a0606ae6bca55a9e2880a8c6212ff79d25f062 Mon Sep 17 00:00:00 2001 From: Stiwi Gabriel Courage Date: Tue, 28 Apr 2026 10:24:13 +0200 Subject: [PATCH 3/3] feat(#100): update architecture guardrails tests for NovaModuleTools - rename test cases to reflect approved helper surface - enhance validation of public command files against expected helpers --- tests/ArchitectureGuardrails.Tests.ps1 | 51 +++++++++++++++++--------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/tests/ArchitectureGuardrails.Tests.ps1 b/tests/ArchitectureGuardrails.Tests.ps1 index fd789154..778b3171 100644 --- a/tests/ArchitectureGuardrails.Tests.ps1 +++ b/tests/ArchitectureGuardrails.Tests.ps1 @@ -80,28 +80,45 @@ Describe 'Architecture guardrails' { (Compare-Object -ReferenceObject $expected -DifferenceObject $actual) | Should -BeNullOrEmpty -Because (($actual -join ', '), (& $script:formatMatches -MatchList $matches) -join [Environment]::NewLine) } - It 'public orchestration entrypoints keep delegating to their context and workflow helpers' { + It 'public command files use only their approved Nova helper surface' { $testCases = @( - [pscustomobject]@{Path = 'src/public/DeployNovaPackage.ps1'; ContextPattern = '\bGet-NovaPackageUploadWorkflowContext\b'; ActionPattern = '\bInvoke-NovaPackageUploadWorkflow\b'} - [pscustomobject]@{Path = 'src/public/InitializeNovaModule.ps1'; ContextPattern = '\bGet-NovaModuleInitializationWorkflowContext\b'; ActionPattern = '\bInvoke-NovaModuleInitializationWorkflow\b'} - [pscustomobject]@{Path = 'src/public/InstallNovaCli.ps1'; ContextPattern = '\bGet-NovaCliInstallWorkflowContext\b'; ActionPattern = '\bInvoke-NovaCliInstallWorkflow\b'} - [pscustomobject]@{Path = 'src/public/InvokeNovaBuild.ps1'; ContextPattern = '\bGet-NovaBuildWorkflowContext\b'; ActionPattern = '\bInvoke-NovaBuildWorkflow\b'} - [pscustomobject]@{Path = 'src/public/InvokeNovaCli.ps1'; ContextPattern = '\bGet-NovaCliInvocationContext\b'; ActionPattern = '\bInvoke-NovaCliCommandRoute\b'} - [pscustomobject]@{Path = 'src/public/InvokeNovaRelease.ps1'; ContextPattern = '\bGet-NovaPublishWorkflowContext\b'; ActionPattern = '\bInvoke-NovaReleaseWorkflow\b'} - [pscustomobject]@{Path = 'src/public/NewNovaModulePackage.ps1'; ContextPattern = '\bGet-NovaPackageWorkflowContext\b'; ActionPattern = '\bInvoke-NovaPackageWorkflow\b'} - [pscustomobject]@{Path = 'src/public/PublishNovaModule.ps1'; ContextPattern = '\bGet-NovaPublishWorkflowContext\b'; ActionPattern = '\bInvoke-NovaPublishWorkflow\b'} - [pscustomobject]@{Path = 'src/public/SetNovaUpdateNotificationPreference.ps1'; ContextPattern = '\bGet-NovaUpdateNotificationPreferenceChangeContext\b'; ActionPattern = '\bInvoke-NovaUpdateNotificationPreferenceChange\b'} - [pscustomobject]@{Path = 'src/public/TestNovaBuild.ps1'; ContextPattern = '\bGet-NovaTestWorkflowContext\b'; ActionPattern = '\bInvoke-NovaTestWorkflow\b'} - [pscustomobject]@{Path = 'src/public/UpdateNovaModuleTools.ps1'; ContextPattern = '\bGet-NovaModuleSelfUpdateWorkflowContext\b'; ActionPattern = '\bInvoke-NovaModuleSelfUpdateWorkflow\b'} - [pscustomobject]@{Path = 'src/public/UpdateNovaModuleVersion.ps1'; ContextPattern = '\bGet-NovaVersionUpdateWorkflowContext\b'; ActionPattern = '\bInvoke-NovaVersionUpdateWorkflow\b'} + [pscustomobject]@{Path = 'src/public/DeployNovaPackage.ps1'; ExpectedHelpers = @('Get-NovaPackageUploadWorkflowContext', 'Get-NovaProjectInfo', 'Invoke-NovaPackageUploadWorkflow', 'New-NovaPackageUploadDynamicParameterDictionary', 'New-NovaPackageUploadOption')} + [pscustomobject]@{Path = 'src/public/GetNovaProjectInfo.ps1'; ExpectedHelpers = @('Get-NovaProjectInfoContext', 'Get-NovaProjectInfoResult')} + [pscustomobject]@{Path = 'src/public/GetNovaUpdateNotificationPreference.ps1'; ExpectedHelpers = @('Get-NovaUpdateNotificationPreferenceStatus')} + [pscustomobject]@{Path = 'src/public/InitializeNovaModule.ps1'; ExpectedHelpers = @('Get-NovaModuleInitializationWorkflowContext', 'Invoke-NovaModuleInitializationWorkflow')} + [pscustomobject]@{Path = 'src/public/InstallNovaCli.ps1'; ExpectedHelpers = @('Get-NovaCliInstallWorkflowContext', 'Invoke-NovaCliInstallWorkflow', 'Write-NovaModuleReleaseNotesLink')} + [pscustomobject]@{Path = 'src/public/InvokeNovaBuild.ps1'; ExpectedHelpers = @('Get-NovaBuildWorkflowContext', 'Invoke-NovaBuildWorkflow')} + [pscustomobject]@{Path = 'src/public/InvokeNovaCli.ps1'; ExpectedHelpers = @('Get-NovaCliInvocationContext', 'Invoke-NovaCliCommandRoute')} + [pscustomobject]@{Path = 'src/public/InvokeNovaRelease.ps1'; ExpectedHelpers = @('Get-NovaProjectInfo', 'Get-NovaPublishWorkflowContext', 'Get-NovaShouldProcessForwardingParameter', 'Invoke-NovaReleaseWorkflow', 'Write-NovaPublishWorkflowContext')} + [pscustomobject]@{Path = 'src/public/NewNovaModulePackage.ps1'; ExpectedHelpers = @('Get-NovaPackageWorkflowContext', 'Get-NovaShouldProcessForwardingParameter', 'Invoke-NovaPackageWorkflow')} + [pscustomobject]@{Path = 'src/public/PublishNovaModule.ps1'; ExpectedHelpers = @('Get-NovaDynamicDeliveryParameterDictionary', 'Get-NovaProjectInfo', 'Get-NovaPublishWorkflowContext', 'Get-NovaShouldProcessForwardingParameter', 'Invoke-NovaPublishWorkflow', 'Write-NovaPublishWorkflowContext')} + [pscustomobject]@{Path = 'src/public/SetNovaUpdateNotificationPreference.ps1'; ExpectedHelpers = @('Get-NovaUpdateNotificationPreferenceChangeContext', 'Invoke-NovaUpdateNotificationPreferenceChange')} + [pscustomobject]@{Path = 'src/public/TestNovaBuild.ps1'; ExpectedHelpers = @('Get-NovaTestWorkflowContext', 'Invoke-NovaTestWorkflow', 'New-NovaTestDynamicParameterDictionary')} + [pscustomobject]@{Path = 'src/public/UpdateNovaModuleTools.ps1'; ExpectedHelpers = @('Complete-NovaModuleSelfUpdateResult', 'Confirm-NovaPrereleaseModuleUpdate', 'Get-NovaModuleSelfUpdateWorkflowContext', 'Invoke-NovaModuleSelfUpdateWorkflow', 'Write-NovaModuleReleaseNotesLink')} + [pscustomobject]@{Path = 'src/public/UpdateNovaModuleVersion.ps1'; ExpectedHelpers = @('Get-NovaVersionUpdateCiActivatedCommand', 'Get-NovaVersionUpdateWorkflowContext', 'Invoke-NovaVersionUpdateWorkflow')} ) + $expectedPaths = @($testCases | ForEach-Object Path | Sort-Object) + $actualPaths = @( + Get-ChildItem -LiteralPath (Join-Path $script:srcRoot 'public') -Filter '*.ps1' -File | + ForEach-Object {([System.IO.Path]::GetRelativePath($script:repoRoot, $_.FullName)).Replace('\', '/')} | + Sort-Object + ) + + (Compare-Object -ReferenceObject $expectedPaths -DifferenceObject $actualPaths) | Should -BeNullOrEmpty -Because "Public command allowlist should stay in sync with src/public. Expected: $( $expectedPaths -join ', ' ) | Actual: $( $actualPaths -join ', ' )" foreach ($testCase in $testCases) { $filePath = Join-Path $script:repoRoot $testCase.Path - $content = Get-Content -LiteralPath $filePath -Raw - - $content | Should -Match $testCase.ContextPattern -Because "$( $testCase.Path ) should build or resolve its workflow/context state before orchestration" - $content | Should -Match $testCase.ActionPattern -Because "$( $testCase.Path ) should delegate execution to its workflow or routing helper" + $null = $tokens = $parseErrors = $null + $ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$tokens, [ref]$parseErrors) + $actualHelpers = @( + $ast.FindAll({param($node) $node -is [System.Management.Automation.Language.CommandAst]}, $true) | + ForEach-Object {$_.GetCommandName()} | + Where-Object {$_ -like '*Nova*'} | + Sort-Object -Unique + ) + $expectedHelpers = @($testCase.ExpectedHelpers | Sort-Object -Unique) + + (Compare-Object -ReferenceObject $expectedHelpers -DifferenceObject $actualHelpers) | Should -BeNullOrEmpty -Because "$( $testCase.Path ) should only use its approved Nova helper surface. Expected: $( $expectedHelpers -join ', ' ) | Actual: $( $actualHelpers -join ', ' )" } }