Path: redb/redb.Templates/scripts/smoke-templates.ps1 Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Templates/scripts/smoke-templates.ps1 ---- <# .SYNOPSIS Generates a project from every template of the redb.Templates pack, with each option that changes the code, and builds it. .DESCRIPTION Installs the given template pack, runs `dotnet new` for each case of $Cases into a temporary folder, then `dotnet build` and, per case, one behavioural check: a console app is started and its output is read, a web site is started and a page is checked, the worker's module is packed and the package is inspected, the chat is started without an API key and must refuse to run without leaving a database behind. Before a release is on nuget.org, pass -LocalFeed with the folder that holds the freshly built redb.* packages: a nuget.config pointing at it is written next to the generated projects, and the restored packages go to /packages instead of the global NuGet cache. .EXAMPLE ./smoke-templates.ps1 -PackagePath ../../nupkg/redb.Templates.4.2.1.nupkg -LocalFeed ../../nupkg ./smoke-templates.ps1 -PackagePath ../../nupkg/redb.Templates.4.2.1.nupkg -Only redb-chat #> param( [Parameter(Mandatory = $true)] [string] $PackagePath, [string] $LocalFeed, # Short names to run; empty runs every case. [string[]] $Only = @(), [string] $WorkDir = (Join-Path ([System.IO.Path]::GetTempPath()) "redb-templates-smoke") ) $ErrorActionPreference = 'Stop' # pwsh -File passes "-Only a,b" as ONE element; split it like the other release scripts do. Without this a list # matched no template, no case ran, and the run still ended with "All cases passed". $Only = @($Only | ForEach-Object { $_ -split ',' } | ForEach-Object { $_.Trim() } | Where-Object { $_ }) # Build nodes keep output files locked between runs, which breaks the cleanup of the work directory. $env:MSBUILDDISABLENODEREUSE = '1' # Every template, and every option that puts different code into the project. # RunDll / ExpectOut - start the built app (relative to the project folder) and check its output # ExpectFail - the app must stop with an error instead of starting # Web / WebProject - start the site, wait for the url and check the answer with Assert # Pack / PackHas - run deploy/pack-tpkg.ps1 and check what the package holds, PackHas: files it must carry # ModuleMaxTfm - the highest framework the packed module may target (net10.0, the runtime of the Tsak # worker), read from the module assembly inside the package of Pack or RoutePack $Cases = @( @{ Id = 'redb'; Template = 'redb'; Args = @(); RunDll = 'bin/Release/net10.0/SmokeApp.dll'; ExpectOut = 'Cleaned up. Done!' } @{ Id = 'redb-free'; Template = 'redb'; Args = @('--pro', 'false'); RunDll = 'bin/Release/net10.0/SmokeApp.dll'; ExpectOut = 'Cleaned up. Done!' } @{ Id = 'redb-postgres'; Template = 'redb'; Args = @('--db', 'postgres') } @{ Id = 'redb-mssql'; Template = 'redb'; Args = @('--db', 'mssql') } @{ Id = 'redb-razor'; Template = 'redb-razor'; Args = @(); Web = 'http://localhost:5080/'; WebProject = '.' Assert = { param($page) # The decimal price is parsed and printed with the invariant culture: a site on a machine # with a comma locale must answer the same as everywhere else (see the README, "Culture"). if ($page.Content -notmatch '1299\.00') { throw 'the price list does not use the invariant culture' } } } @{ Id = 'redb-blazor'; Template = 'redb-blazor'; Args = @(); Web = 'http://localhost:5081/'; WebProject = '.' Assert = { param($page) if ($page.Content -notmatch '5 product\(s\)') { throw 'the product list did not render' } if ($page.Content -notmatch 'prerenderId') { throw 'the page was not prerendered' } } } @{ Id = 'redb-worker'; Template = 'redb-worker'; Args = @(); Pack = $true } @{ Id = 'redb-chat'; Template = 'redb-chat'; Args = @(); ExpectFail = $true; RunDll = 'SmokeApp.Host/bin/Release/net10.0/SmokeApp.Host.dll' ExpectOut = 'The LLM API key is not set'; NoFiles = '*.db' } @{ Id = 'redb-chat-shell'; Template = 'redb-chat'; Args = @('--tools', 'shell'); ExpectFail = $true; RunDll = 'SmokeApp.Host/bin/Release/net10.0/SmokeApp.Host.dll' ExpectOut = 'The LLM API key is not set'; NoFiles = '*.db' } @{ Id = 'redb-chat-mcp-audit'; Template = 'redb-chat'; Args = @('--tools', 'mcp', '--audit', 'true'); ExpectFail = $true; RunDll = 'SmokeApp.Host/bin/Release/net10.0/SmokeApp.Host.dll' ExpectOut = 'The LLM API key is not set'; NoFiles = '*.db' } @{ Id = 'redb-app'; Template = 'redb-app'; Args = @(); Web = 'http://localhost:5082/'; WebProject = 'SmokeApp.Web' Assert = { param($page) # .NET 10 serves the client with an import map and fingerprinted names (see the template). if ($page.Content -notmatch 'type="importmap"') { throw 'the client index.html has no import map' } if ($page.Content -notmatch 'blazor\.webassembly\.[0-9a-z]+\.js') { throw 'the client loader is not fingerprinted' } } } @{ Id = 'redb-bff'; Template = 'redb-bff'; Args = @(); Web = 'http://localhost:5083/login'; WebProject = 'SmokeApp.Web' Assert = { param($page) if ($page.Content -notmatch ' "@ | Set-Content -Path (Join-Path $WorkDir 'nuget.config') -Encoding utf8 # The packages restored from the local feed must not land in the global cache: there they would stand in # for the published packages of the same version on every later restore of this machine. They go to a # folder of the work directory, which the next run removes with it. Restored paths run to ~190 # characters below this folder, so a long -WorkDir hits MAX_PATH and the build loses its references. $env:NUGET_PACKAGES = Join-Path $WorkDir 'packages' } # `dotnet new install --force` over an installed pack of the same id adds a second entry instead of replacing # it, and every `dotnet new` of its templates then fails with "Sequence contains more than one matching # element" (exit 70). Every entry of the id goes first; it is redb.Templates, whichever source it came from. for ($i = 0; $i -lt 5; $i++) { dotnet new uninstall redb.Templates *> $null; if ($LASTEXITCODE -ne 0) { break } } Invoke-Checked "dotnet new install" { dotnet new install $PackagePath } function Wait-ForUrl([string] $url, [int] $TimeoutSeconds = 90) { $deadline = (Get-Date).AddSeconds($TimeoutSeconds) while ((Get-Date) -lt $deadline) { try { $answer = Invoke-WebRequest $url -UseBasicParsing -TimeoutSec 5 -SkipHttpErrorCheck if ($answer.StatusCode -lt 500) { return $answer } } catch { } Start-Sleep -Milliseconds 500 } throw "no answer from $url within $TimeoutSeconds s" } # `dotnet run` leaves the app it started behind, so the whole tree goes. Process.Kill(true) does that on Windows and # Linux alike (the CIM query it replaces existed on Windows only, and the smoke could not run in the SDK container). function Stop-ProcessTree([int] $ProcessId) { try { [Diagnostics.Process]::GetProcessById($ProcessId).Kill($true) } catch { } } # The pack script must put the module and its own dependencies in the package and nothing the worker # already ships, which is what deploy/shipped-module-deps.txt lists. # A Route-XML module packed by its build: pkg/-0.0.1.tpkg, and the context name the template was asked for # in pkg/-0.0.1/.config.json. function Invoke-RoutePackCheck([string] $ProjectDir, [string] $Name, [hashtable] $Expect) { $package = Join-Path $ProjectDir "pkg/$Name-0.0.1.tpkg" if (-not (Test-Path $package)) { throw "the build produced no pkg/$Name-0.0.1.tpkg" } # Every redb-route-* carries an AGENTS.md assembled at pack time (route-xml/_agents + the scenario part of the # template). Its placeholders must be replaced by the template engine like everywhere else in the project. $agents = Join-Path $ProjectDir 'AGENTS.md' if (-not (Test-Path $agents)) { throw 'the project has no AGENTS.md' } $agentsText = Get-Content $agents -Raw $left = @('modulectx', 'routemodule', 'RouteModule' | Where-Object { $agentsText -cmatch "\b$_\b" }) if ($left.Count -gt 0) { throw "AGENTS.md still carries the template placeholder(s): $($left -join ', ')" } if ($Expect.ContextName) { $config = Join-Path $ProjectDir "pkg/$Name-0.0.1/$Name.config.json" if (-not (Test-Path $config)) { throw "no pkg/$Name-0.0.1/$Name.config.json" } $context = (Get-Content $config -Raw | ConvertFrom-Json).ContextName if ($context -ne $Expect.ContextName) { throw "ContextName is '$context', expected '$($Expect.ContextName)'" } } if ($Expect.RequiredConfigKey -or $Expect.RequiredConfigKeys -or $Expect.NoRequiredConfigKeys) { $manifest = Join-Path $ProjectDir "pkg/$Name-0.0.1/manifest.json" if (-not (Test-Path $manifest)) { throw "no pkg/$Name-0.0.1/manifest.json" } $keys = @((Get-Content $manifest -Raw | ConvertFrom-Json).RequiredConfigKeys | Where-Object { $_ }) # RequiredConfigKeys: the exact set, in any order; a key short or one too many both fail. if ($Expect.RequiredConfigKeys) { $diff = @(Compare-Object @($Expect.RequiredConfigKeys) $keys) if ($diff.Count -gt 0) { throw "RequiredConfigKeys is [$($keys -join ', ')], expected [$($Expect.RequiredConfigKeys -join ', ')]" } } if ($Expect.RequiredConfigKey -and $keys -notcontains $Expect.RequiredConfigKey) { throw "RequiredConfigKeys has no $($Expect.RequiredConfigKey) (has: $($keys -join ', '))" } # A module that needs no key must not ask for one: the worker would refuse to start it. if ($Expect.NoRequiredConfigKeys -and $keys.Count -gt 0) { throw "RequiredConfigKeys should be empty, has: $($keys -join ', ')" } } if ($Expect.Entries) { # Resources the routes read at run time travel inside the package, not next to it. Add-Type -AssemblyName System.IO.Compression.FileSystem $zip = [IO.Compression.ZipFile]::OpenRead($package) try { $inside = @($zip.Entries | ForEach-Object { $_.FullName -replace '\\', '/' }) } finally { $zip.Dispose() } $missing = @($Expect.Entries | Where-Object { $inside -notcontains $_ }) if ($missing.Count -gt 0) { throw "the package has no $($missing -join ', ')" } } if ($Expect.PackageRef) { $csproj = Join-Path $ProjectDir 'SmokeApp.csproj' if ((Get-Content $csproj -Raw) -notmatch ('[^"]+)"') | ForEach-Object { $_.Groups['v'].Value } | Sort-Object -Unique) if ($providers.Count -eq 0) { throw 'context.sample.json names no Provider' } if (@($providers | Where-Object { $_ -ne $Expect.SampleProvider }).Count -gt 0) { throw "context.sample.json Provider is $($providers -join ', '), expected $($Expect.SampleProvider)" } } if ($Expect.Provider) { $contextXml = Join-Path $ProjectDir "pkg/$Name-0.0.1/context.xml" if (-not (Test-Path $contextXml)) { throw "no pkg/$Name-0.0.1/context.xml" } $text = Get-Content $contextXml -Raw if ($text -match '#if\b') { throw 'context.xml still carries #if: the template conditions were not resolved' } # of the redb.Route XML, or an attribute ProviderName="...". $declared = @([regex]::Matches($text, 'key\s*=\s*"ProviderName"\s+value\s*=\s*"(?[^"]+)"|\bProviderName\s*=\s*"(?[^"]+)"') | ForEach-Object { $_.Groups['v'].Value } | Sort-Object -Unique) if ($declared.Count -eq 0) { throw 'context.xml declares no ProviderName' } if (@($declared | Where-Object { $_ -ne $Expect.Provider }).Count -gt 0) { throw "ProviderName is $($declared -join ', '), expected $($Expect.Provider)" } } Write-Host (" package: pkg/{0}-0.0.1.tpkg, {1:N0} KB" -f $Name, ((Get-Item $package).Length / 1KB)) -ForegroundColor DarkGray } function Invoke-PackageCheck([string] $ProjectDir, [string] $PackageName, [string] $ModuleDll, [string[]] $MustHave = @()) { Push-Location $ProjectDir try { & (Join-Path $ProjectDir 'deploy/pack-tpkg.ps1') | Out-Null $package = Join-Path $ProjectDir ('deploy/output/' + $PackageName) if (-not (Test-Path $package)) { throw "the pack script produced no $PackageName" } Add-Type -AssemblyName System.IO.Compression.FileSystem $zip = [IO.Compression.ZipFile]::OpenRead($package) try { $names = @($zip.Entries | ForEach-Object { $_.Name }) $shipped = @(Get-Content (Join-Path $ProjectDir 'deploy/shipped-module-deps.txt') | ForEach-Object { $_.Trim() } | Where-Object { $_ -and -not $_.StartsWith('#') }) $repeated = @($names | Where-Object { $shipped -contains $_ }) if ($repeated.Count -gt 0) { throw "the package repeats what the worker ships: $($repeated -join ', ')" } if ($names -notcontains $ModuleDll) { throw "$ModuleDll is not in the package" } if ($names -notcontains 'manifest.json') { throw 'manifest.json is not in the package' } $absent = @($MustHave | Where-Object { $names -notcontains $_ }) if ($absent.Count -gt 0) { throw "the package has no $($absent -join ', ')" } if (-not (Test-Path ($package + '.contents.txt'))) { throw 'the package contents list was not written' } Write-Host " package: $($names.Count) entries" -ForegroundColor DarkGray } finally { $zip.Dispose() } } finally { Pop-Location } } # A module loads into the Tsak worker, so it must not target a framework above the worker's runtime: the package # builds and packs either way, and only the worker would refuse it. The framework is the TargetFrameworkAttribute # of the module assembly as it sits in the package (".NETCoreApp,Version=v10.0"). function Assert-ModuleFramework([string] $Package, [string] $ModuleDll, [string] $MaxTfm) { if ($MaxTfm -notmatch '^net(\d+)\.(\d+)$') { throw "ModuleMaxTfm '$MaxTfm' is not a netX.Y framework" } $max = [version]"$($Matches[1]).$($Matches[2])" Add-Type -AssemblyName System.IO.Compression.FileSystem $zip = [IO.Compression.ZipFile]::OpenRead($Package) try { $entry = @($zip.Entries | Where-Object { $_.Name -eq $ModuleDll }) | Select-Object -First 1 if (-not $entry) { throw "$ModuleDll is not in the package" } $bytes = [IO.MemoryStream]::new() $stream = $entry.Open() try { $stream.CopyTo($bytes) } finally { $stream.Dispose() } } finally { $zip.Dispose() } $bytes.Position = 0 $pe = [Reflection.PortableExecutable.PEReader]::new($bytes) try { $md = [Reflection.Metadata.PEReaderExtensions]::GetMetadataReader($pe) $framework = $null foreach ($handle in $md.GetAssemblyDefinition().GetCustomAttributes()) { $attribute = $md.GetCustomAttribute($handle) if ($attribute.Constructor.Kind -ne [Reflection.Metadata.HandleKind]::MemberReference) { continue } $parent = $md.GetMemberReference([Reflection.Metadata.MemberReferenceHandle]$attribute.Constructor).Parent if ($parent.Kind -ne [Reflection.Metadata.HandleKind]::TypeReference) { continue } if ($md.GetString($md.GetTypeReference([Reflection.Metadata.TypeReferenceHandle]$parent).Name) -ne 'TargetFrameworkAttribute') { continue } # Blob: prolog 01 00, then the string with a one-byte length (a framework name is shorter than 128). $blob = $md.GetBlobBytes($attribute.Value) $framework = [Text.Encoding]::UTF8.GetString($blob, 3, $blob[2]) break } } finally { $pe.Dispose() } if (-not $framework) { throw "$ModuleDll carries no TargetFrameworkAttribute" } if ($framework -notmatch '^\.NETCoreApp,Version=v(\d+\.\d+)$') { throw "$ModuleDll targets '$framework', not .NETCoreApp" } if ([version]$Matches[1] -gt $max) { throw "$ModuleDll targets $framework, above ${MaxTfm}: the worker cannot load it" } Write-Host " module framework: $framework (at most $MaxTfm)" -ForegroundColor DarkGray } $failed = @() $ran = 0 foreach ($case in $Cases) { if ($Only.Count -gt 0 -and $Only -notcontains $case.Template) { continue } $ran++ $id = $case.Id $out = Join-Path $WorkDir $id Write-Host "=== $id ===" -ForegroundColor Cyan try { $newArgs = @($case.Template, '-n', 'SmokeApp', '-o', $out) + $case.Args Invoke-Checked "dotnet new $id" { dotnet new @newArgs } $buildArgs = @($out, '-c', 'Release') if ($case.RoutePack) { $buildArgs += '-p:PackRouteOnBuild=true', '-p:Version=0.0.1' } Invoke-Checked "dotnet build $id" { dotnet build @buildArgs } if ($case.RoutePack) { Invoke-RoutePackCheck $out 'smokeapp' $case.RoutePack } if ($case.Web) { $projectDir = if ($case.WebProject -eq '.') { $out } else { Join-Path $out $case.WebProject } $env:ASPNETCORE_ENVIRONMENT = 'Development' # -NoNewWindow: without it Windows gives the site a console window of its own, which pops up on the # desktop of whoever runs the smoke. The output goes to the two logs either way. $site = Start-Process dotnet -ArgumentList @('run', '-c', 'Release', '--no-build', '--project', $projectDir) -PassThru ` -NoNewWindow -RedirectStandardOutput (Join-Path $out 'smoke.out.log') -RedirectStandardError (Join-Path $out 'smoke.err.log') try { $answer = Wait-ForUrl $case.Web & $case.Assert $answer } finally { Stop-ProcessTree $site.Id } } if ($case.RunDll -or $case.ExpectFail) { Push-Location $out try { $output = (& dotnet $case.RunDll 2>&1 | Out-String) Write-Host $output -ForegroundColor DarkGray if ($case.ExpectFail -and $LASTEXITCODE -eq 0) { throw 'the app was expected to stop with an error, it started instead' } if ($case.RunDll -and -not $case.ExpectFail -and $LASTEXITCODE -ne 0) { throw "the app exited with $LASTEXITCODE" } if ($case.ExpectOut -and $output -notmatch $case.ExpectOut) { throw "the output has no '$($case.ExpectOut)'" } if ($case.NoFiles) { $left = @(Get-ChildItem -Path $out -Filter $case.NoFiles -ErrorAction SilentlyContinue) if ($left.Count -gt 0) { throw "the app created $($left[0].Name) before it stopped" } } } finally { Pop-Location } } if ($case.Pack) { Invoke-PackageCheck $out 'SmokeApp.tpkg' 'SmokeApp.Module.dll' @($case.PackHas | Where-Object { $_ }) } if ($case.ModuleMaxTfm) { if ($case.Pack) { Assert-ModuleFramework (Join-Path $out 'deploy/output/SmokeApp.tpkg') 'SmokeApp.Module.dll' $case.ModuleMaxTfm } elseif ($case.RoutePack) { Assert-ModuleFramework (Join-Path $out 'pkg/smokeapp-0.0.1.tpkg') 'SmokeApp.dll' $case.ModuleMaxTfm } else { throw 'ModuleMaxTfm needs Pack or RoutePack: there is no package to read the module from' } } Write-Host "OK $id" -ForegroundColor Green } catch { Write-Host "FAIL $id : $($_.Exception.Message)" -ForegroundColor Red $failed += $id } } if ($ran -eq 0) { throw "No case ran: -Only $($Only -join ', ') matches no template of the cases list." } if ($failed.Count -gt 0) { throw "Failed cases: $($failed -join ', ')" } Write-Host "All $ran case(s) passed." -ForegroundColor Green