Bundle: redb-tsak / scripts (scripts.txt), 5 files Snapshot: 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-tsak Index: https://redbase.app/src/dev-2026-12-06/redb-tsak/_index.txt ==== Path: redb-tsak/scripts/README.md Snapshot: redb-tsak, 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-tsak Page: https://redbase.app/src/dev-2026-12-06/redb-tsak/scripts/README.md ---- # scripts/ Tooling for the **shared runtime layer** — `Libs/shared/`, the directory the Worker loads the redb.* framework and the Route connectors from at startup. Since 3.4.0 that layer holds **both**: - the **framework** — `redb.Core(.Pro)`, the storage providers, `redb.Route.Core/Http/Quartz`; - the **connectors** — RabbitMQ, Kafka, Elasticsearch, LDAP, Llm, … with their native payloads (`runtimes//native`, e.g. librdkafka, e_sqlite3). Only `redb.Tsak.*` and `redb.Licensing` remain in the application bin; every redb.* framework DLL is pruned from it at build time. **A Worker started without a populated `Libs/shared/` fails fast** with a message naming the missing assembly — that is by design, not a bug to work around. The payoff: a binary-compatible patch of any library, or a new beta connector, ships by swapping a DLL in `Libs/shared/` — no rebuild of the Worker, no re-cut archives. ## `shared-manifest.psd1` The single source of truth for what belongs in the layer — two lists, `Framework` and `Connectors`. Both scripts read it. Adding a connector means adding one line here, nowhere else. ## `build-shared.ps1` — populate the layer ```powershell # dev: connectors + framework into src/redb.Tsak.Worker/Libs/shared (Debug, net10.0) ./scripts/build-shared.ps1 -IncludeFramework # rebuild just two of them ./scripts/build-shared.ps1 -IncludeFramework -Clean -Only IbmMq,RabbitMQ # publish mode: one directory per TFM under , Release ./scripts/build-shared.ps1 -Configuration Release -Tfms net8.0,net9.0,net10.0 -OutRoot publish/staging -IncludeFramework ``` `-IncludeFramework` is what makes the Worker actually start; without it you get connectors only and the fail-fast on the first framework type. **Building from the standalone repository.** The Route sources are a separate repository, so point the script at a checkout of : ```powershell git clone https://github.com/redbase-app/redb-route ../redb-route ./scripts/build-shared.ps1 -IncludeFramework -RouteSrc ../redb-route ``` `-RouteSrc` accepts either the repository root or its `src/` directly. In the monorepo the parameter is omitted and the layout is resolved automatically. ## `refresh-shared.ps1` — patch one library in place ```powershell # into the dev tree ./scripts/refresh-shared.ps1 -Lib redb.Route.Http # into an unpacked distribution archive ./scripts/refresh-shared.ps1 -Lib redb.SQLite.Pro -SharedDir D:\dist\redb-tsak-3.4.0-win-x64\worker\Libs\shared ``` Rebuilds a single library and drops its DLL into the target layer. Takes the same `-RouteSrc`. ⚠️ The host compares the **minor** version of the shared layer against its own on startup: a patch difference is fine — that is the whole point — but a minor mismatch, or a mix of minors inside `Libs/shared/`, aborts the process. So a given Worker build accepts patches of its own minor only; a new ecosystem minor means a full release. ## `smoke-template.ps1` — the template pack is verified before it is published Packs `redb.Tsak.Templates`, generates the host in each mode the template offers, builds it and — where no server is needed — starts it and reads back what the host says about itself: the provider, the tier and the save strategy the runtime applied. | case | database | tier | starts | |------|----------|------|--------| | `default` | SQLite | Pro | yes | | `inmemory` | SQLite | Pro | yes | | `free` | SQLite | Free (`DeleteInsert`) | yes | | `postgres` | Postgres | Pro | build only — needs a server | | `mssql` | SQL Server | Pro | build only — needs a server | ```powershell ./scripts/smoke-template.ps1 ./scripts/smoke-template.ps1 -PackagePath ..\nupkg\redb.Tsak.Templates.4.2.1.nupkg ``` ## `smoke-module-in-host.ps1` — the module chain, end to end Walks what the two template packs promise together: generates a `RedbWorker` module from the **redb.Templates** pack, packs it with its own `deploy/pack-tpkg.ps1`, generates the host, refreshes the shared layer, drops the package into `Libs/` and waits for the module to return a receipt: ```powershell ./scripts/smoke-module-in-host.ps1 ``` Outside the monorepo — that is, in a checkout of this repository — there is no `redb.Templates` next to it, so the module templates are installed from nuget.org; `-TemplatesPackage ` tests a local build of that pack instead, and `-SkipSharedRefresh` keeps the layer the host already has. ## Do not put modules here `Libs/shared/` is process-global: everything in it is loaded into the default `AssemblyLoadContext` and shared by every module. Module packages belong in the worker's `modules/` directory, where they are loaded in isolation and can be hot-reloaded. Path: redb-tsak/scripts/build-shared.ps1 Snapshot: redb-tsak, 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-tsak Page: https://redbase.app/src/dev-2026-12-06/redb-tsak/scripts/build-shared.ps1 ---- #!/usr/bin/env pwsh <# .SYNOPSIS Builds Route connector (and optionally framework) projects and copies their DLLs into the shared assembly layer that SharedAssemblyLoader reads at runtime. Single source of truth for the connector/framework list: scripts/shared-manifest.psd1. This one script covers BOTH modes (the old build-shared-multitfm.ps1 is gone): * DEV mode (default, no -OutRoot): - output: src/redb.Tsak.Worker/Libs/shared - single TFM (net10.0), Configuration=Debug - filters out DLLs already present in Worker bin AND in the .NET shared frameworks - hard-fails (exit 1) if any connector fails to build - then MIRRORS the layer into bin///Libs/shared, which is where the worker reads it from (AppContext.BaseDirectory). The csproj's PreserveNewest copy cannot do it: it keeps files the layer dropped and skips sources with an older timestamp. So after this script the worker starts on the new layer without a rebuild. * PUBLISH mode (-OutRoot given): - output: /shared- (e.g. shared-net100) per TFM - one dir per -Tfms entry, Configuration=Release (pass -Configuration Release) - filters out DLLs already present in the .NET shared frameworks only (no single Worker bin exists at multi-TFM publish time) - tolerates per-TFM build failures (tracked as "incompatible"), never hard-fails Both modes filter against the two shared frameworks the worker runs on, Microsoft.NETCore.App and Microsoft.AspNetCore.App, and place one version of each file: a file two projects publish in different versions fails the run (see -TakeHighest). .PARAMETER Configuration Build configuration. Default: Debug (dev). Publish pipeline passes Release. .PARAMETER Tfms Target framework monikers. Default: net10.0, the framework of the worker; the release builds net10.0 only. .PARAMETER OutRoot When set, switches to PUBLISH mode and writes shared- dirs under this root (e.g. publish/staging). When empty, DEV mode writes to Worker/Libs/shared. .PARAMETER IncludeFramework Also build the Framework section from the manifest (redb.Core/Route.Core/providers). Dormant for stage A (composition unchanged) — used from stage B onward when framework moves out of bin into shared. .PARAMETER Only Build only the specified project(s). Matched case-insensitively against the full id or its tail (e.g. "IbmMq" matches "redb.Route.IbmMq"). .PARAMETER Clean Clean the output directory/directories before copying. .PARAMETER TakeHighest When two projects publish the same file in different versions, keep the newest and warn instead of failing the run. The failure is the default on purpose: the fix is to pin the package to one version in the projects listed, as the layer loads exactly one copy. .PARAMETER SelfTest Prove the version policy on two builds of one assembly from the local NuGet cache and exit. Publishes nothing; run it after touching Add-LayerFile or Compare-LayerVersion. .EXAMPLE ./scripts/build-shared.ps1 ./scripts/build-shared.ps1 -Clean -Only IbmMq,RabbitMQ ./scripts/build-shared.ps1 -Configuration Release -Tfms net10.0 -OutRoot publish/staging ./scripts/build-shared.ps1 -SelfTest #> param( [string]$Configuration = "Debug", [string[]]$Tfms = @('net10.0'), [string]$OutRoot = "", [switch]$IncludeFramework, [switch]$Clean, [switch]$TakeHighest, [switch]$SelfTest, [string[]]$Only = @(), # Where the redb.Route / redb core sources live. Empty = monorepo layout (../../redb.Route/src). # The public redb-tsak repository is standalone, so there this points at a separate clone of # https://github.com/redbase-app/redb-route — e.g. -RouteSrc ..\redb-route # This parameter is why there is no second, "public" copy of this script: a copy drifted for # three weeks and shipped a version that could not stage the framework at all. [string]$RouteSrc = "" ) $ErrorActionPreference = "Stop" # pwsh -File passes "-Tfms a,b" / "-Only a,b" as a single element — normalize. $Tfms = @($Tfms | ForEach-Object { $_ -split ',' } | Where-Object { $_ }) $Only = @($Only | ForEach-Object { $_ -split ',' } | Where-Object { $_ }) # ---- One version of each file in the layer ---- # Every project publishes its own copy of a shared dependency. Copying them over each other made # the last project in the manifest win regardless of version (caught 2026-09-16: Microsoft.IdentityModel # 8.0.0 from redb.Licensing overwrote 8.16.0 from redb.MSSql in the publish layer, and the worker # loaded the 8.0.0 next to a host on 8.16.0). A duplicate is compared by version instead: an equal # version is skipped, a different one is a conflict — the run fails with the list, or -TakeHighest # keeps the newest and warns. function Get-LayerFileVersion([string]$path) { # The assembly version is what binds at load time; the file version tells package builds apart # that share an assembly version. Native files (the SNI runtime) carry a file version only; # a file with neither is compared by its bytes. $asm = $null try { $asm = [System.Reflection.AssemblyName]::GetAssemblyName($path).Version } catch [System.BadImageFormatException] { $asm = $null # not a managed assembly } $file = $null $fvi = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path) if ($fvi.FileVersion) { [version]$parsed = $null if ([version]::TryParse((($fvi.FileVersion -split '[ +-]')[0]), [ref]$parsed)) { $file = $parsed } } # Without a file version two copies of one assembly version can only be told apart by their bytes # (System.Diagnostics.EventLog.Messages.dll ships that way: an assembly version, no file version). $hash = $null if (-not $file) { $hash = (Get-FileHash -Path $path -Algorithm SHA256).Hash } $display = if ($asm) { "assembly $asm" } else { "native" } if ($file) { $display += ", file $file" } if ($hash) { $display += ", sha256 $($hash.Substring(0, 12))" } return @{ Assembly = $asm; File = $file; Hash = $hash; Display = $display } } function Compare-LayerVersion($a, $b) { # Positive when $a is newer, negative when older, 0 when equal, $null when the two cannot be ordered. if ($a.Assembly -and $b.Assembly -and $a.Assembly -ne $b.Assembly) { return $a.Assembly.CompareTo($b.Assembly) } if ($a.File -and $b.File) { return $a.File.CompareTo($b.File) } if ($a.Hash -and $b.Hash) { if ($a.Hash -eq $b.Hash) { return 0 } else { return $null } } return $null } # Places one file into the layer under $relative. Returns $true when the file was copied, $false when # an equal copy is already there or a conflict was recorded. $placed and $mismatches are per layer. function Add-LayerFile([hashtable]$placed, [System.Collections.ArrayList]$mismatches, [string]$source, [string]$sharedDir, [string]$relative, [string]$project) { $key = $relative.ToLowerInvariant() $version = Get-LayerFileVersion $source $dest = Join-Path $sharedDir $relative if (-not $placed.ContainsKey($key)) { $destDir = Split-Path -Parent $dest if (-not (Test-Path $destDir)) { New-Item -ItemType Directory -Path $destDir -Force | Out-Null } Copy-Item $source -Destination $dest -Force $placed[$key] = @{ Version = $version; Project = $project } return $true } $first = $placed[$key] $cmp = Compare-LayerVersion $version $first.Version if ($null -ne $cmp -and $cmp -eq 0) { return $false } # same version from another project: the first copy stays $entry = @{ File = $relative; Orderable = ($null -ne $cmp) } if ($TakeHighest -and $null -ne $cmp -and $cmp -gt 0) { Copy-Item $source -Destination $dest -Force $entry.Kept = "$($version.Display) from $project" $entry.Dropped = "$($first.Version.Display) from $($first.Project)" $placed[$key] = @{ Version = $version; Project = $project } } else { $entry.Kept = "$($first.Version.Display) from $($first.Project)" $entry.Dropped = "$($version.Display) from $project" } [void]$mismatches.Add($entry) return $false } # Prints the conflicts of one layer; throws unless -TakeHighest resolved every one of them. function Assert-LayerConsistent([string]$tfm, [System.Collections.ArrayList]$mismatches) { if ($mismatches.Count -eq 0) { return } $color = if ($TakeHighest) { 'Yellow' } else { 'Red' } Write-Host "Version conflicts in the $tfm layer:" -ForegroundColor $color foreach ($m in $mismatches) { $note = if ($m.Orderable) { '' } else { ' (versions cannot be ordered)' } Write-Host " $($m.File): kept $($m.Kept); dropped $($m.Dropped)$note" -ForegroundColor $color } if (-not $TakeHighest) { throw "Shared layer for $tfm carries $($mismatches.Count) file(s) in different versions across projects. " + "Pin the package to one version in the projects listed, or pass -TakeHighest to keep the newest." } $unordered = @($mismatches | Where-Object { -not $_.Orderable }) if ($unordered.Count -gt 0) { throw "Shared layer for ${tfm}: $($unordered.Count) file(s) differ between projects and carry no comparable " + "version, so -TakeHighest cannot choose. Fix the projects listed." } } if ($SelfTest) { # Two builds of one assembly from the NuGet cache stand in for two projects. Nothing is published. $cache = Join-Path $HOME ".nuget/packages/microsoft.identitymodel.tokens" $builds = @(Get-ChildItem $cache -Directory -ErrorAction SilentlyContinue | ForEach-Object { [version]$v = $null $dll = Get-ChildItem (Join-Path $_.FullName "lib") -Recurse -Filter "Microsoft.IdentityModel.Tokens.dll" -ErrorAction SilentlyContinue | Select-Object -First 1 if ($dll -and [version]::TryParse($_.Name, [ref]$v)) { @{ Version = $v; Dll = $dll } } } | Sort-Object { $_.Version }) if ($builds.Count -lt 2) { throw "Self-test needs two builds of Microsoft.IdentityModel.Tokens in $cache; found $($builds.Count)." } $low = $builds[0]; $high = $builds[-1] $tmp = Join-Path ([IO.Path]::GetTempPath()) ("tsak_shared_selftest_" + [guid]::NewGuid().ToString('N')) $layer = Join-Path $tmp "layer" New-Item -ItemType Directory -Path $layer -Force | Out-Null try { $name = $high.Dll.Name $placedVersion = { (Get-LayerFileVersion (Join-Path $layer $name)).Display } # 1. Default policy: a second, different version is a conflict and the first copy stays. $placed = @{}; $mismatches = [System.Collections.ArrayList]::new() [void](Add-LayerFile $placed $mismatches $high.Dll.FullName $layer $name "proj-high") [void](Add-LayerFile $placed $mismatches $low.Dll.FullName $layer $name "proj-low") if ($mismatches.Count -ne 1) { throw "Self-test: expected one conflict, got $($mismatches.Count)." } if ((& $placedVersion) -ne (Get-LayerFileVersion $high.Dll.FullName).Display) { throw "Self-test: the default policy must keep the first copy." } $failed = $false try { Assert-LayerConsistent "selftest" $mismatches } catch { $failed = $true } if (-not $failed) { throw "Self-test: a conflict must fail the run without -TakeHighest." } # 2. The same version from two projects is not a conflict. $placed = @{}; $mismatches = [System.Collections.ArrayList]::new() [void](Add-LayerFile $placed $mismatches $high.Dll.FullName $layer $name "proj-a") [void](Add-LayerFile $placed $mismatches $high.Dll.FullName $layer $name "proj-b") if ($mismatches.Count -ne 0) { throw "Self-test: equal versions must not conflict." } # 3. -TakeHighest keeps the newest whichever project comes first, and does not fail. $TakeHighest = $true $placed = @{}; $mismatches = [System.Collections.ArrayList]::new() [void](Add-LayerFile $placed $mismatches $low.Dll.FullName $layer $name "proj-low") [void](Add-LayerFile $placed $mismatches $high.Dll.FullName $layer $name "proj-high") if ($mismatches.Count -ne 1) { throw "Self-test: -TakeHighest must still record the conflict." } if ((& $placedVersion) -ne (Get-LayerFileVersion $high.Dll.FullName).Display) { throw "Self-test: -TakeHighest must keep the newest." } Assert-LayerConsistent "selftest" $mismatches $TakeHighest = $false # 4. An assembly without a file version (the EventLog messages resource assembly) placed twice with # the same bytes is not a conflict — caught on the first real run, where redb.MSSql and # redb.MSSql.Pro both publish it under runtimes/ and the bytes were never compared. $messages = Get-ChildItem (Join-Path $HOME ".nuget/packages/system.diagnostics.eventlog") -Recurse -Filter "System.Diagnostics.EventLog.Messages.dll" -ErrorAction SilentlyContinue | Select-Object -First 1 if (-not $messages) { throw "Self-test needs System.Diagnostics.EventLog.Messages.dll in the NuGet cache." } $messagesVersion = Get-LayerFileVersion $messages.FullName if ($messagesVersion.File -or -not $messagesVersion.Hash) { throw "Self-test: $($messages.Name) was expected to carry no file version and a hash, got '$($messagesVersion.Display)'." } $placed = @{}; $mismatches = [System.Collections.ArrayList]::new() [void](Add-LayerFile $placed $mismatches $messages.FullName $layer $messages.Name "proj-a") [void](Add-LayerFile $placed $mismatches $messages.FullName $layer $messages.Name "proj-b") if ($mismatches.Count -ne 0) { throw "Self-test: equal bytes without a file version must not conflict." } Write-Host "Self-test OK: $name $($low.Version) vs $($high.Version) — conflict fails by default, equal versions pass, -TakeHighest keeps $($high.Version); $($messages.Name) without a file version compares by bytes." -ForegroundColor Green } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } exit 0 } $scriptDir = $PSScriptRoot # redb.Tsak/scripts $tsakRoot = Split-Path -Parent $scriptDir # redb.Tsak $repoRoot = Split-Path -Parent $tsakRoot # csharp/redb # Route sources: monorepo layout by default; -RouteSrc for a standalone checkout. Accept either # the repo root of redb-route or its src/ directly — telling a user which one to pass is a support # question nobody should have to ask. if ([string]::IsNullOrWhiteSpace($RouteSrc)) { $routeRoot = Join-Path (Join-Path $repoRoot "redb.Route") "src" # The framework and provider projects live under redb.DB/src in the monorepo; the layout is written down # once, in scripts/lib/RedbLayout.ps1. That file is not part of the public redb-tsak repository, which is # why it is loaded in the monorepo layout only. . (Join-Path $repoRoot 'scripts/lib/RedbLayout.ps1') } else { $routeRoot = (Resolve-Path $RouteSrc).Path if (-not (Test-Path (Join-Path $routeRoot "redb.Route"))) { $nested = Join-Path $routeRoot "src" if (Test-Path (Join-Path $nested "redb.Route")) { $routeRoot = $nested } } } $monorepo = [string]::IsNullOrWhiteSpace($RouteSrc) if (-not (Test-Path $routeRoot)) { throw "Route sources not found: $routeRoot. Pass -RouteSrc ." } $publishMode = -not [string]::IsNullOrWhiteSpace($OutRoot) # ---- Load the manifest (single source of truth) ---- $manifestPath = Join-Path $scriptDir "shared-manifest.psd1" if (-not (Test-Path $manifestPath)) { throw "Manifest not found: $manifestPath" } $manifest = Import-PowerShellDataFile -Path $manifestPath $projects = @($manifest.Connectors) if ($IncludeFramework) { # Additive, de-duplicated (a name can appear only once even if both sections list it). $projects = @($projects + $manifest.Framework) | Select-Object -Unique } # ---- Apply -Only filter ---- if ($Only.Count -gt 0) { $filtered = @() foreach ($pat in $Only) { $m = $projects | Where-Object { $_ -ieq $pat -or $_ -ieq "redb.Route.$pat" -or $_ -like "*$pat*" } if (-not $m) { Write-Host "WARNING: -Only '$pat' did not match any project" -ForegroundColor Yellow } else { $filtered += $m } } $projects = @($filtered | Select-Object -Unique) if ($projects.Count -eq 0) { Write-Host "Nothing matched -Only; done." -ForegroundColor Yellow; exit 0 } } $dotnetRoot = Split-Path (Get-Command dotnet).Source # The worker runs on two shared frameworks (redb.Tsak.Worker.runtimeconfig.json lists both). Filtering # against Microsoft.NETCore.App alone let ASP.NET framework assemblies (System.Security.Cryptography.Pkcs # among them) into the layer, in whichever version each project happened to publish; at runtime the # framework copy wins over them, so they were dead weight that made the layer differ from run to run. $sharedFrameworks = @('Microsoft.NETCore.App', 'Microsoft.AspNetCore.App') function Get-RuntimeDirs([string]$tfm) { $tfmVersion = $tfm -replace '^net', '' # net10.0 -> 10.0 $dirs = @() foreach ($framework in $sharedFrameworks) { $dir = Get-ChildItem (Join-Path (Join-Path $dotnetRoot "shared") $framework) -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -match "^$([regex]::Escape($tfmVersion))\." } | Sort-Object Name -Descending | Select-Object -First 1 -ExpandProperty FullName if ($dir) { $dirs += $dir } else { Write-Host "WARNING: no $framework $tfmVersion runtime dir, its framework filter is disabled for $tfm" -ForegroundColor Yellow } } return $dirs } function Test-InFramework([string[]]$runtimeDirs, [string]$name) { foreach ($dir in $runtimeDirs) { if (Test-Path (Join-Path $dir $name)) { return $true } } return $false } # In DEV mode, also filter against the Worker bin (framework/host deps already there). $workerBin = $null if (-not $publishMode) { $workerBin = Join-Path (Join-Path (Join-Path (Join-Path (Join-Path $tsakRoot "src") "redb.Tsak.Worker") "bin") $Configuration) $Tfms[0] } Write-Host "=== build-shared.ps1 ===" -ForegroundColor Cyan Write-Host "Mode: $(if ($publishMode) { 'PUBLISH' } else { 'DEV' })" Write-Host "Configuration: $Configuration" Write-Host "Tfms: $($Tfms -join ', ')" Write-Host "Route root: $routeRoot" Write-Host "IncludeFramework: $IncludeFramework" Write-Host "" if (-not (Test-Path $routeRoot)) { throw "redb.Route source not found at $routeRoot" } # ---- Every publish starts empty ---- # Each project used to publish into %TEMP%\tsak_shared_\, kept from run to run. dotnet publish # does not overwrite a file whose copy in the output folder is NEWER than the source, so a package rolled back # to a version with an older file date never replaced its predecessor: 4.4.0-beta.1 shipped JsonPath.Net 3.0.2 # and Json.More 3.0.1 in the layer while every deps.json and the host said 2.2.0, and the worker logged two # "Failed to load shared assembly". Now each run publishes into a folder of its own, removed when the run ends. $runTemp = Join-Path ([IO.Path]::GetTempPath()) ("tsak_shared_run_" + [guid]::NewGuid().ToString('N')) # What a project's publish put on disk must be what its deps.json resolved: an assembly whose version differs # from the deps.json entry is a leftover, not this build's output. Checked for lib and runtimes/ entries. function Assert-PublishMatchesDeps([string]$proj, [string]$pubDir) { $depsFile = Join-Path $pubDir "$proj.deps.json" if (-not (Test-Path $depsFile)) { return } $deps = Get-Content $depsFile -Raw | ConvertFrom-Json $target = $deps.targets.PSObject.Properties | Select-Object -First 1 $wrong = @() foreach ($lib in $target.Value.PSObject.Properties) { $entries = @() if ($lib.Value.runtime) { $entries += $lib.Value.runtime.PSObject.Properties | ForEach-Object { @{ Rel = (Split-Path $_.Name -Leaf); Want = $_.Value.assemblyVersion } } } if ($lib.Value.runtimeTargets) { $entries += $lib.Value.runtimeTargets.PSObject.Properties | ForEach-Object { @{ Rel = $_.Name; Want = $_.Value.assemblyVersion } } } foreach ($e in $entries) { if (-not $e.Want) { continue } $file = Join-Path $pubDir ($e.Rel -replace '/', [IO.Path]::DirectorySeparatorChar) if (-not (Test-Path $file)) { continue } try { $have = [System.Reflection.AssemblyName]::GetAssemblyName($file).Version } catch { continue } if ($have.ToString() -ne $e.Want) { $wrong += "$proj : $($e.Rel) is assembly $have on disk, deps.json resolved $($e.Want) ($($lib.Name))" } } } if ($wrong.Count -gt 0) { $wrong | ForEach-Object { Write-Host " STALE FILE: $_" -ForegroundColor Red } throw "Publish of $proj left $($wrong.Count) assembly(ies) that do not match its deps.json - a leftover in $pubDir, not this build's output." } } # Builds one TFM into $sharedDir. Returns @{ Copied=; Incompatible=@(...); Conflicts= }. function Build-Tfm([string]$tfm, [string]$sharedDir, [string[]]$runtimeDirs) { if ($Clean -and (Test-Path $sharedDir)) { Write-Host "Cleaning $sharedDir..." -ForegroundColor Yellow Remove-Item -Recurse -Force $sharedDir } if (-not (Test-Path $sharedDir)) { New-Item -ItemType Directory -Path $sharedDir -Force | Out-Null } $copied = 0 $incompatible = @() $placed = @{} # relative path -> version and project of the copy in the layer $mismatches = [System.Collections.ArrayList]::new() foreach ($proj in $projects) { # Connectors live under redb.Route/src/. The framework and providers (redb.Core[.Pro], # redb.Postgres[.Pro], redb.MSSql[.Pro], redb.SQLite[.Pro]) live under redb.DB/src in the # monorepo: Get-RedbProjectFile resolves them and stops the run when one is missing. $projPath = Join-Path (Join-Path $routeRoot $proj) "$proj.csproj" if (-not (Test-Path $projPath)) { $projPath = if ($monorepo) { Get-RedbProjectFile -RepoRoot $repoRoot -Name $proj } else { Join-Path (Join-Path $repoRoot $proj) "$proj.csproj" } } if (-not (Test-Path $projPath)) { Write-Host " SKIP $proj (project not found)" -ForegroundColor Yellow continue } $tmpPub = Join-Path (Join-Path $runTemp $tfm) $proj Write-Host " $proj ($tfm)..." -NoNewline $logFile = Join-Path ([IO.Path]::GetTempPath()) "tsak_shared_$tfm`_$proj.log" & dotnet publish $projPath -c $Configuration -f $tfm --nologo -v q -o $tmpPub 2>&1 | Out-File -FilePath $logFile -Encoding UTF8 if ($LASTEXITCODE -ne 0) { if ($publishMode) { Write-Host " INCOMPATIBLE" -ForegroundColor Yellow $incompatible += $proj continue } else { Write-Host " FAILED (log: $logFile)" -ForegroundColor Red throw "Build failed for $proj" } } Write-Host " OK" -ForegroundColor Green Assert-PublishMatchesDeps $proj $tmpPub if (Test-Path $tmpPub) { $dlls = Get-ChildItem -Path $tmpPub -Filter "*.dll" | Where-Object { # The shared layer OWNS every redb.* except the two the Worker keeps in its bin on # purpose (redb.Tsak.*, redb.Licensing - see PruneRedbFromBuild in the Worker csproj). # Without this exemption the bin filter below drops the whole framework out of the # layer whenever a Worker build left redb.* in bin, and SharedRuntimeBootstrap then # refuses to start the worker: its fail-fast requires those assemblies IN the layer. # The filter stays in force for third-party deps, which is what it was meant for. $ownedByShared = $_.Name -like "redb.*" -and $_.Name -notlike "redb.Tsak.*" -and $_.Name -notlike "redb.Licensing.*" (-not (Test-InFramework $runtimeDirs $_.Name)) -and ($publishMode -or $ownedByShared -or -not (Test-Path (Join-Path $workerBin $_.Name))) } foreach ($dll in $dlls) { if (Add-LayerFile $placed $mismatches $dll.FullName $sharedDir $dll.Name $proj) { $copied++ } } # RID-specific builds (runtimes//lib//*.dll, native SNI) follow the same rule. $runtimes = Join-Path $tmpPub "runtimes" if (Test-Path $runtimes) { foreach ($file in Get-ChildItem -Path $runtimes -Recurse -File) { $relative = $file.FullName.Substring($tmpPub.Length).TrimStart('\', '/') [void](Add-LayerFile $placed $mismatches $file.FullName $sharedDir $relative $proj) } } } } Assert-LayerConsistent $tfm $mismatches # Every project in the manifest must have produced its own DLL in the layer. Without this the # script can report success on a layer that cannot start a worker at all: SharedRuntimeBootstrap # byte-preloads the framework set from here and fail-fasts when one is missing. Caught on # 2026-09-09, when the Worker-bin filter silently removed all 14 framework assemblies and the # run still ended with "Done" and exit 0. $missing = @($projects | Where-Object { ($_ -notin $incompatible) -and -not (Test-Path (Join-Path $sharedDir "$_.dll")) }) if ($missing.Count -gt 0) { Write-Host "MISSING from ${sharedDir}: $($missing -join ', ')" -ForegroundColor Red throw "Shared layer incomplete for $tfm - $($missing.Count) assembly(ies) did not land in the layer." } return @{ Copied = $copied; Incompatible = $incompatible; Conflicts = $mismatches.Count } } $summary = @{} try { foreach ($tfm in $Tfms) { if ($publishMode) { Write-Host "===== TFM: $tfm =====" -ForegroundColor Magenta $sharedDir = Join-Path $OutRoot "shared-$($tfm -replace '\.', '')" } else { # Shared DLLs go into the source tree — MSBuild copies them to output via CopyToOutputDirectory. $sharedDir = Join-Path (Join-Path (Join-Path (Join-Path $tsakRoot "src") "redb.Tsak.Worker") "Libs") "shared" } $runtimeDirs = Get-RuntimeDirs $tfm Write-Host "Shared dir: $sharedDir" Write-Host "Runtime dirs: $($runtimeDirs -join '; ')" $summary[$tfm] = Build-Tfm $tfm $sharedDir $runtimeDirs Write-Host " -> $($summary[$tfm].Copied) DLLs in $sharedDir" -ForegroundColor Cyan if (-not $publishMode) { # Deliver the layer where the worker actually reads it. SharedAssemblyLoader resolves # Libs/shared against AppContext.BaseDirectory - bin// - not the project folder # this script writes, and the csproj brings it there with CopyToOutputDirectory="PreserveNewest". # That copy never deletes what has left the layer, and it skips a file whose source is OLDER: # this script keeps the NuGet file dates, so a newer package can carry an older timestamp and # never replace its predecessor. On 2026-09-17 the bin copy was therefore holding redb.* of two # older commits plus 22 ASP.NET framework assemblies the layer had stopped shipping, and the # worker was running on that. Mirroring here ends the "wipe bin, rebuild the worker" ritual: # after this script the worker can simply be started. $binShared = Join-Path (Join-Path $workerBin "Libs") "shared" if (Test-Path $workerBin) { if (Test-Path $binShared) { try { Remove-Item $binShared -Recurse -Force -ErrorAction Stop } catch { throw "Cannot refresh ${binShared}: $($_.Exception.Message). A running worker holds these files - stop it and rerun." } } New-Item -ItemType Directory -Path $binShared -Force | Out-Null Copy-Item (Join-Path $sharedDir '*') $binShared -Recurse -Force Write-Host " -> mirrored into $binShared" -ForegroundColor Cyan } else { Write-Host " worker bin not built yet ($workerBin) - the first Worker build copies the layer itself." -ForegroundColor DarkGray } } Write-Host "" } } finally { if (Test-Path $runTemp) { Remove-Item $runTemp -Recurse -Force -ErrorAction SilentlyContinue } } Write-Host "=== Summary ===" -ForegroundColor Cyan $anyIncompatible = $false foreach ($tfm in $Tfms) { $inc = $summary[$tfm].Incompatible if ($inc.Count -gt 0) { $anyIncompatible = $true Write-Host "$tfm incompatible: $($inc -join ', ')" -ForegroundColor Yellow } elseif ($summary[$tfm].Conflicts -gt 0) { Write-Host "$tfm OK ($($summary[$tfm].Copied) DLLs, $($summary[$tfm].Conflicts) version conflict(s) resolved by -TakeHighest — see above)" -ForegroundColor Yellow } else { Write-Host "$tfm OK ($($summary[$tfm].Copied) DLLs)" -ForegroundColor Green } } # In DEV mode a failing build already threw. In PUBLISH mode incompatibility is tolerated # (matches the old build-shared-multitfm.ps1 behavior) — exit 0 so the pipeline continues. Write-Host "Done." -ForegroundColor Green Path: redb-tsak/scripts/refresh-shared.ps1 Snapshot: redb-tsak, 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-tsak Page: https://redbase.app/src/dev-2026-12-06/redb-tsak/scripts/refresh-shared.ps1 ---- #!/usr/bin/env pwsh <# .SYNOPSIS Refresh ONE redb.* library in an existing shared layer — WITHOUT rebuilding Tsak/Identity. .DESCRIPTION This is the payoff of the shared-layer move (docs/SHARED_RUNTIME_PLAN.md): a binary-compatible patch of a leaf/provider/connector (e.g. redb.Route.Http 3.4.0 -> 3.4.1, or a beta connector) ships by swapping its DLL in Libs/shared. The framework is byte-loaded from there at startup, so no host rebuild, no giant archive re-spin. The script: 1. resolves the project (redb.Route/src/, or redb.DB/src/ for the framework and providers), 2. `dotnet publish`es it to a temp dir, 3. copies .dll (+ its runtimes/ native, if any) into the target shared directory, 4. warns about any NEW transitive dependency the publish produced that is missing from the target — a hint that this is more than a compatible patch (may need a fuller rebuild). It does NOT re-zip or re-sign an archive — that is packaging-specific. After running against an archive's Libs/shared, re-zip and re-cosign the archive as usual (see publish/HOW_TO_PUBLISH.md). COMPAT NOTE: the running host enforces a compat-gate (redb minor must match Tsak's). Only swap in a DLL of the SAME minor as the archive's Tsak — patches (3rd number) are fine, a new minor is not. .PARAMETER Lib Assembly/project simple name, e.g. redb.Route.Http, redb.SQLite.Pro, redb.Route.Kafka. .PARAMETER SharedDir Target shared directory to update. Default: the dev Worker Libs/shared. For an archive, pass its /worker/Libs/shared. .PARAMETER Configuration Build configuration. Default: Release. .PARAMETER Tfm Target framework. Default: net10.0. .EXAMPLE ./scripts/refresh-shared.ps1 -Lib redb.Route.Http ./scripts/refresh-shared.ps1 -Lib redb.SQLite.Pro -SharedDir D:\dist\redb-tsak-3.3.3-win-x64\worker\Libs\shared #> param( [Parameter(Mandatory)][string]$Lib, [string]$SharedDir = "", [string]$Configuration = "Release", [string]$Tfm = "net10.0", # Same as in build-shared.ps1: empty = monorepo layout, otherwise a standalone redb-route checkout. [string]$RouteSrc = "" ) $ErrorActionPreference = "Stop" $scriptDir = $PSScriptRoot # redb.Tsak/scripts $tsakRoot = Split-Path -Parent $scriptDir # redb.Tsak $repoRoot = Split-Path -Parent $tsakRoot # csharp/redb if ([string]::IsNullOrWhiteSpace($RouteSrc)) { $routeRoot = Join-Path (Join-Path $repoRoot "redb.Route") "src" # As in build-shared.ps1: the framework and providers live under redb.DB/src (scripts/lib/RedbLayout.ps1, # which the public redb-tsak repository does not carry). . (Join-Path $repoRoot 'scripts\lib\RedbLayout.ps1') } else { $routeRoot = (Resolve-Path $RouteSrc).Path if (-not (Test-Path (Join-Path $routeRoot "redb.Route"))) { $nested = Join-Path $routeRoot "src" if (Test-Path (Join-Path $nested "redb.Route")) { $routeRoot = $nested } } } if ([string]::IsNullOrWhiteSpace($SharedDir)) { $SharedDir = Join-Path (Join-Path (Join-Path (Join-Path $tsakRoot "src") "redb.Tsak.Worker") "Libs") "shared" } # Resolve project path: connectors under redb.Route/src; framework/providers under redb.DB/src in the # monorepo (Get-RedbProjectFile throws when the project is missing), at the repo root otherwise. $projPath = Join-Path (Join-Path $routeRoot $Lib) "$Lib.csproj" if (-not (Test-Path $projPath)) { if ([string]::IsNullOrWhiteSpace($RouteSrc)) { $projPath = Get-RedbProjectFile -RepoRoot $repoRoot -Name $Lib } else { $projPath = Join-Path (Join-Path $repoRoot $Lib) "$Lib.csproj" if (-not (Test-Path $projPath)) { throw "Project for '$Lib' not found under $routeRoot or $repoRoot." } } } if (-not (Test-Path $SharedDir)) { throw "Target shared dir not found: $SharedDir" } Write-Host "=== refresh-shared.ps1 ===" -ForegroundColor Cyan Write-Host "Lib: $Lib" Write-Host "Project: $projPath" Write-Host "SharedDir: $SharedDir" Write-Host "Config/Tfm: $Configuration / $Tfm" Write-Host "" $pubDir = Join-Path (Join-Path $env:TEMP "tsak_refresh_shared") $Lib if (Test-Path $pubDir) { Remove-Item -Recurse -Force $pubDir } Write-Host "Publishing $Lib..." -NoNewline $log = Join-Path $env:TEMP "tsak_refresh_$Lib.log" & dotnet publish $projPath -c $Configuration -f $Tfm --nologo -v q -o $pubDir 2>&1 | Out-File -FilePath $log -Encoding UTF8 if ($LASTEXITCODE -ne 0) { Write-Host " FAILED (log: $log)" -ForegroundColor Red; throw "publish failed for $Lib" } Write-Host " OK" -ForegroundColor Green $srcDll = Join-Path $pubDir "$Lib.dll" if (-not (Test-Path $srcDll)) { throw "Published output missing $Lib.dll" } $oldVer = if (Test-Path (Join-Path $SharedDir "$Lib.dll")) { [Reflection.AssemblyName]::GetAssemblyName((Join-Path $SharedDir "$Lib.dll")).Version.ToString() } else { "(absent)" } $newVer = [Reflection.AssemblyName]::GetAssemblyName($srcDll).Version.ToString() # 1. The library DLL itself. Copy-Item $srcDll -Destination $SharedDir -Force Write-Host " updated $Lib.dll : $oldVer -> $newVer" -ForegroundColor Green # 2. Native runtimes it may carry (e.g. Kafka librdkafka, SQLite e_sqlite3). $srcRuntimes = Join-Path $pubDir "runtimes" if (Test-Path $srcRuntimes) { Copy-Item -Path $srcRuntimes -Destination $SharedDir -Recurse -Force Write-Host " + runtimes/ refreshed" -ForegroundColor DarkGray } # 3. Warn about NEW managed deps the publish produced that are absent from the target — a sign this # is more than a drop-in patch (a new/updated transitive dependency). Host-provided BCL/extension # assemblies (Microsoft.*, System.*) are normally served from the app bin, not the shared layer, # so they are expected-absent here and would only be noise — skip them. $newDeps = @() foreach ($dll in Get-ChildItem -Path $pubDir -Filter "*.dll") { if ($dll.Name -ieq "$Lib.dll") { continue } if ($dll.Name -like "Microsoft.*" -or $dll.Name -like "System.*") { continue } if (-not (Test-Path (Join-Path $SharedDir $dll.Name))) { $newDeps += $dll.Name } } if ($newDeps.Count -gt 0) { Write-Host "" Write-Host " NOTE: publish produced deps not present in the shared layer (host bin may still" -ForegroundColor Yellow Write-Host " provide them). Review before shipping — if any is genuinely new, add it to shared:" -ForegroundColor Yellow $newDeps | ForEach-Object { Write-Host " - $_" -ForegroundColor Yellow } } Write-Host "" Write-Host "Done. For an archive: re-zip and re-cosign it (see publish/HOW_TO_PUBLISH.md)." -ForegroundColor Cyan Write-Host "The host compat-gate requires the SAME redb minor as its Tsak build (patches ok)." -ForegroundColor DarkGray Path: redb-tsak/scripts/smoke-module-in-host.ps1 Snapshot: redb-tsak, 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-tsak Page: https://redbase.app/src/dev-2026-12-06/redb-tsak/scripts/smoke-module-in-host.ps1 ---- <# .SYNOPSIS End-to-end check of the module chain: a module from redb-worker runs inside a tsak-worker host. .DESCRIPTION The two template packs are separate packages, and a module only works when the host can resolve its dependencies. This script proves the chain instead of assuming it: 1. packs both template packs (unless -TemplatesPackage / -TsakTemplatesPackage are given; outside the monorepo — in a checkout of the public redb-tsak repository — the module templates are installed from nuget.org instead), 2. generates a RedbWorker module, packs it with its own deploy/pack-tpkg.ps1, 3. generates the tsak-worker host (defaults: SQLite, Pro) and builds it, 4. puts the assemblies the worker does not ship into the host's Libs/shared with the existing scripts/refresh-shared.ps1 (the whole layer, if you need it, is build-shared.ps1 -Clean), 5. drops the module package into the host's Libs/, 6. starts the host, feeds the module's sample order file and waits for the receipt. A receipt with Accepted means: the host started, the module was discovered, initialized and its file route ran a transacted write through RedBase. .EXAMPLE ./scripts/smoke-module-in-host.ps1 ./scripts/smoke-module-in-host.ps1 -TemplatesPackage ../nupkg/redb.Templates.4.2.1.nupkg #> param( [string] $TemplatesPackage = '', [string] $TsakTemplatesPackage = '', [string] $WorkDir = (Join-Path ([IO.Path]::GetTempPath()) 'redb-tsak-module-in-host'), # Skip filling Libs/shared: use it when the host already has the layer you want to test. [switch] $SkipSharedRefresh ) $ErrorActionPreference = 'Stop' # Build nodes keep output files locked between runs, which breaks the cleanup of the work directory. $env:MSBUILDDISABLENODEREUSE = '1' $scriptDir = $PSScriptRoot # redb.Tsak/scripts $tsakRoot = Split-Path -Parent $scriptDir # redb.Tsak $repoRoot = Split-Path -Parent $tsakRoot # csharp/redb function Pack-Template([string] $Project, [string] $Filter, [string] $Given) { if ($Given) { return (Resolve-Path $Given).Path } # Not a monorepo checkout (the public redb-tsak repository has no redb.Templates next to it): the # published pack is used instead, see below. if (-not (Test-Path $Project)) { return '' } dotnet pack $Project -c Release -o $packOutput -v quiet if ($LASTEXITCODE -ne 0) { throw "dotnet pack of $Project failed" } $packed = Get-ChildItem $packOutput -Filter $Filter | Sort-Object LastWriteTime -Descending | Select-Object -First 1 if (-not $packed) { throw "no $Filter in $packOutput" } return $packed.FullName } function Stop-Hosts { # The apphost is TsakHost.exe; started as `dotnet TsakHost.dll` the process is dotnet instead. Get-Process -Name 'TsakHost' -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue Get-CimInstance Win32_Process -Filter "Name='dotnet.exe'" -ErrorAction SilentlyContinue | Where-Object { $_.CommandLine -like '*TsakHost.dll*' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue } Start-Sleep -Milliseconds 500 } function Wait-Api([int] $TimeoutSeconds = 60) { $deadline = (Get-Date).AddSeconds($TimeoutSeconds) while ((Get-Date) -lt $deadline) { try { return Invoke-WebRequest 'http://127.0.0.1:9090/api/contexts' -UseBasicParsing -TimeoutSec 3 } catch { } Start-Sleep -Milliseconds 500 } throw 'the management API did not answer on http://127.0.0.1:9090' } function Wait-Receipt([string] $Outbox, [int] $TimeoutSeconds = 90) { $deadline = (Get-Date).AddSeconds($TimeoutSeconds) while ((Get-Date) -lt $deadline) { $receipt = Get-ChildItem $Outbox -Filter '*.receipt.xml' -ErrorAction SilentlyContinue | Select-Object -First 1 if ($receipt) { return $receipt } Start-Sleep -Milliseconds 500 } throw "no receipt in $Outbox" } Stop-Hosts # A leftover host or build node can still hold files in the previous work directory: retry, and give up # with a clear message rather than deleting something half-way. Remove-Item -Recurse -Force $WorkDir -ErrorAction SilentlyContinue for ($attempt = 0; $attempt -lt 3 -and (Test-Path $WorkDir); $attempt++) { Stop-Hosts Start-Sleep -Seconds 1 Remove-Item -Recurse -Force $WorkDir -ErrorAction SilentlyContinue } if (Test-Path $WorkDir) { throw "the previous work directory is locked: $WorkDir (stop the hosts and run again)" } New-Item -ItemType Directory -Force $WorkDir | Out-Null $packOutput = Join-Path $WorkDir 'pkg' New-Item -ItemType Directory -Force $packOutput | Out-Null # The module templates live next to redb.Tsak in the monorepo; a standalone checkout (the public # redb-tsak repository) has no redb.Templates project, so the published pack is installed instead. $templatesPack = Pack-Template (Join-Path $repoRoot 'redb.Templates/redb.Templates.csproj') 'redb.Templates.*.nupkg' $TemplatesPackage $tsakPack = Pack-Template (Join-Path $tsakRoot 'templates/redb.Tsak.Templates.csproj') 'redb.Tsak.Templates.*.nupkg' $TsakTemplatesPackage if (-not $tsakPack) { throw 'the host template pack was not produced' } Write-Host "module templates: $(if ($templatesPack) { $templatesPack } else { 'the published redb.Templates from nuget.org' })" -ForegroundColor DarkGray Write-Host "host template: $tsakPack" -ForegroundColor DarkGray # Installing over an already installed pack of the same id registers a second copy, and `dotnet new` # then fails with "Sequence contains more than one matching element". foreach ($id in @('redb.Templates', 'redb.Tsak.Templates')) { dotnet new uninstall $id 2>&1 | Out-Null } if ($templatesPack) { dotnet new install $templatesPack 2>&1 | Out-Null } else { dotnet new install redb.Templates 2>&1 | Out-Null } dotnet new install $tsakPack 2>&1 | Out-Null if ($LASTEXITCODE -ne 0) { throw 'dotnet new install failed' } $failed = @() try { # ---------- 1. the module ---------- $moduleDir = Join-Path $WorkDir 'module' Write-Host '=== module: dotnet new redb-worker + deploy/pack-tpkg.ps1 ===' -ForegroundColor Cyan dotnet new redb-worker -n SmokeModule -o $moduleDir if ($LASTEXITCODE -ne 0) { throw 'dotnet new redb-worker failed' } $templates = Join-Path $moduleDir 'deploy\pack-tpkg.ps1' & $templates if ($LASTEXITCODE -ne 0) { throw 'pack-tpkg.ps1 failed' } $package = Join-Path $moduleDir 'deploy\output\SmokeModule.tpkg' if (-not (Test-Path $package)) { throw 'the module package was not produced' } Write-Host (" package: {0} bytes" -f (Get-Item $package).Length) -ForegroundColor DarkGray # ---------- 2. the host ---------- $hostDir = Join-Path $WorkDir 'host' Write-Host '=== host: dotnet new tsak-worker + build ===' -ForegroundColor Cyan dotnet new tsak-worker -n TsakHost -o $hostDir if ($LASTEXITCODE -ne 0) { throw 'dotnet new tsak-worker failed' } dotnet build $hostDir -c Release -v quiet if ($LASTEXITCODE -ne 0) { throw 'the host did not build' } # Two folders, two resolution rules (both checked against the runtime): # Libs/*.tpkg - the module scan resolves Tsak:Modules:AssemblyPaths against the WORKING DIRECTORY # Libs/shared/*.dll - the shared layer is resolved against the APPLICATION directory (AppContext.BaseDirectory) # The template copies Libs/** to the output at build, so filling the project folder and mirroring it into # the output is exactly what a user does. $appDir = Join-Path $hostDir 'bin\Release\net10.0' $appLibs = Join-Path $appDir 'Libs' $libs = Join-Path $hostDir 'Libs' $shared = Join-Path $libs 'shared' New-Item -ItemType Directory -Force $shared, $appLibs | Out-Null Copy-Item $package $libs -Force # ---------- 3. the shared layer ---------- if (-not $SkipSharedRefresh) { Write-Host '=== Libs/shared: scripts/refresh-shared.ps1 ===' -ForegroundColor Cyan # The worker image ships these in /app/Libs/shared; a host built here has to be given them. # (The whole connector layer at once: scripts/build-shared.ps1 -Clean.) foreach ($lib in @('redb.Route.File', 'redb.Route.GenericFile')) { & (Join-Path $scriptDir 'refresh-shared.ps1') -Lib $lib -SharedDir $shared -Configuration Release -Tfm net10.0 if ($LASTEXITCODE -ne 0) { throw "refresh-shared.ps1 failed for $lib" } } Write-Host (" shared: {0} assemblies" -f @(Get-ChildItem $shared -Filter *.dll).Count) -ForegroundColor DarkGray } # What the build's Libs/** copy does: the same files next to the application. Copy-Item (Join-Path $libs '*') $appLibs -Recurse -Force # ---------- 4. run the module in the host ---------- Write-Host '=== host run: module discovers, initializes, processes a file ===' -ForegroundColor Cyan $stdout = Join-Path $WorkDir 'host.out.log' $stderr = Join-Path $WorkDir 'host.err.log' $process = Start-Process (Join-Path $appDir 'TsakHost.exe') -WorkingDirectory $hostDir -PassThru ` -RedirectStandardOutput $stdout -RedirectStandardError $stderr try { $answer = Wait-Api if ($answer.Content -notmatch 'Running') { throw 'no running context in the management API' } $inbox = Join-Path $hostDir 'data\inbox' New-Item -ItemType Directory -Force $inbox | Out-Null Copy-Item (Join-Path $moduleDir 'samples\order-1001.xml') (Join-Path $inbox 'order-1001.xml') -Force $outbox = Join-Path $hostDir 'data\outbox' $receipt = Wait-Receipt $outbox $text = Get-Content $receipt.FullName -Raw if ($text -notmatch 'Accepted') { throw "the receipt says: $($text.Trim())" } Write-Host " receipt: $($receipt.Name) -> Accepted" -ForegroundColor DarkGray $log = (Get-Content $stderr -Raw -ErrorAction SilentlyContinue) + (Get-Content $stdout -Raw -ErrorAction SilentlyContinue) if ($log -notmatch 'Initialized module') { throw 'the module was not initialized' } Write-Host 'OK module-in-host' -ForegroundColor Green } catch { Write-Host "FAIL module-in-host : $($_.Exception.Message)" -ForegroundColor Red $failed += 'module-in-host' Write-Host '--- host stdout tail ---' -ForegroundColor DarkGray Get-Content $stdout -Tail 25 -ErrorAction SilentlyContinue | Out-String | Write-Host Write-Host '--- host stderr tail ---' -ForegroundColor DarkGray Get-Content $stderr -Tail 25 -ErrorAction SilentlyContinue | Out-String | Write-Host } finally { Stop-Hosts } } finally { Stop-Hosts } if ($failed.Count -gt 0) { throw "Failed: $($failed -join ', ')" } Path: redb-tsak/scripts/smoke-template.ps1 Snapshot: redb-tsak, 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-tsak Page: https://redbase.app/src/dev-2026-12-06/redb-tsak/scripts/smoke-template.ps1 ---- <# .SYNOPSIS Generates a host from the tsak-worker template, one case per option that changes the configuration, builds it and starts it. .DESCRIPTION Packs the template pack (or takes -PackagePath), installs it, runs `dotnet new tsak-worker` for every case, builds the host and, for the cases that run without a server, starts it against SQLite and checks what the host says about itself: the provider and tier from the log, the save strategy the runtime applied, and that the database file appeared. The postgres/mssql cases are built only: their providers need a server. Why these checks: the template's defaults once disagreed with the runtime's (Free tier with batch ChangeTracking, Postgres with nothing installed) and every release shipped that. .EXAMPLE ./scripts/smoke-template.ps1 ./scripts/smoke-template.ps1 -PackagePath templates/bin/Release/redb.Tsak.Templates.4.2.1.nupkg #> param( [string] $PackagePath = '', [string] $WorkDir = (Join-Path ([IO.Path]::GetTempPath()) 'redb-tsak-template-smoke') ) $ErrorActionPreference = 'Stop' # Build nodes keep output files locked between runs, which breaks the cleanup of the work directory. $env:MSBUILDDISABLENODEREUSE = '1' $repo = Resolve-Path (Join-Path $PSScriptRoot '..') if (-not $PackagePath) { dotnet pack (Join-Path $repo 'templates/redb.Tsak.Templates.csproj') -c Release -v quiet if ($LASTEXITCODE -ne 0) { throw 'dotnet pack failed' } $PackagePath = (Get-ChildItem (Join-Path $repo 'templates/bin/Release') -Filter 'redb.Tsak.Templates.*.nupkg' | Sort-Object LastWriteTime -Descending | Select-Object -First 1).FullName if (-not $PackagePath) { throw 'dotnet pack produced no nupkg' } } $PackagePath = (Resolve-Path $PackagePath).Path # Run = $true: the host starts on SQLite and must report the provider, tier and strategy below. $cases = @( @{ Id = 'default'; Args = @(); Run = $true; Provider = 'sqlite'; Tier = 'Pro'; Strategy = 'ChangeTracking' } @{ Id = 'inmemory'; Args = @('-s', 'inmemory'); Run = $true; Provider = 'sqlite'; Tier = 'Pro'; Strategy = 'ChangeTracking' } @{ Id = 'free'; Args = @('--pro', 'false'); Run = $true; Provider = 'sqlite'; Tier = 'Free'; Strategy = 'DeleteInsert' } @{ Id = 'postgres'; Args = @('-db', 'postgres') } @{ Id = 'mssql'; Args = @('-db', 'mssql') } ) function Stop-Hosts { # `dotnet run` starts the apphost, not dotnet itself, so kill that name too. Get-Process -Name 'TsakHost' -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue Start-Sleep -Milliseconds 500 } function Wait-Api([int] $TimeoutSeconds = 60) { $deadline = (Get-Date).AddSeconds($TimeoutSeconds) while ((Get-Date) -lt $deadline) { try { return Invoke-WebRequest 'http://127.0.0.1:9090/api/contexts' -UseBasicParsing -TimeoutSec 3 } catch { } Start-Sleep -Milliseconds 500 } throw 'the management API did not answer on http://127.0.0.1:9090' } Stop-Hosts # A leftover host or build node can hold files in the previous work directory: retry, then say so. Remove-Item -Recurse -Force $WorkDir -ErrorAction SilentlyContinue for ($attempt = 0; $attempt -lt 3 -and (Test-Path $WorkDir); $attempt++) { Stop-Hosts Start-Sleep -Seconds 1 Remove-Item -Recurse -Force $WorkDir -ErrorAction SilentlyContinue } if (Test-Path $WorkDir) { throw "the previous work directory is locked: $WorkDir (stop the hosts and run again)" } New-Item -ItemType Directory -Force $WorkDir | Out-Null # Installing over an already installed pack of the same id registers a second copy, and `dotnet new` # then fails with "Sequence contains more than one matching element". Stop-Hosts dotnet new uninstall redb.Tsak.Templates 2>&1 | Out-Null dotnet new install $PackagePath 2>&1 | Out-Null if ($LASTEXITCODE -ne 0) { throw 'dotnet new install failed' } $failed = @() foreach ($case in $cases) { $id = $case.Id $out = Join-Path $WorkDir $id Write-Host "=== $id ===" -ForegroundColor Cyan try { $newArgs = @('tsak-worker', '-n', 'TsakHost', '-o', $out) + $case.Args dotnet new @newArgs if ($LASTEXITCODE -ne 0) { throw 'dotnet new tsak-worker failed' } dotnet build $out -c Release -v quiet if ($LASTEXITCODE -ne 0) { throw 'the host did not build' } $settings = Get-Content (Join-Path $out 'appsettings.json') -Raw $expected = if ($case.Provider) { $case.Provider } else { $id } $found = ([regex]::Match($settings, '"Provider":\s*"([a-z]+)"')).Groups[1].Value if ($found -ne $expected) { throw "appsettings.json has provider '$found', expected '$expected'" } if (-not $case.Run) { Write-Host " provider: $found (built only: the provider needs a server to run)" -ForegroundColor DarkGray } else { $stdout = Join-Path $out 'smoke.out.log' $stderr = Join-Path $out 'smoke.err.log' # -NoNewWindow: without it Windows gives the host 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. $process = Start-Process dotnet -ArgumentList @('run', '-c', 'Release', '--no-build', '--project', $out) -PassThru ` -NoNewWindow -RedirectStandardOutput $stdout -RedirectStandardError $stderr try { $answer = Wait-Api if ($answer.StatusCode -ne 200 -or $answer.Content -notmatch '_system') { throw 'the system context is not running' } $log = (Get-Content $stderr -Raw -ErrorAction SilentlyContinue) + (Get-Content $stdout -Raw -ErrorAction SilentlyContinue) if ($log -notmatch "provider=$($case.Provider), tier=$($case.Tier)") { throw "the log does not say 'provider=$($case.Provider), tier=$($case.Tier)'" } if ($log -notmatch "applied PropsSaveStrategy=$($case.Strategy)") { throw "the runtime did not apply 'PropsSaveStrategy=$($case.Strategy)'" } if (-not (Test-Path (Join-Path $out 'tsak.db'))) { throw 'tsak.db was not created' } Write-Host " provider=$($case.Provider), tier=$($case.Tier), strategy=$($case.Strategy)" -ForegroundColor DarkGray } finally { Stop-Hosts } } Write-Host "OK $id" -ForegroundColor Green } catch { Stop-Hosts Write-Host "FAIL $id : $($_.Exception.Message)" -ForegroundColor Red $failed += $id } } if ($failed.Count -gt 0) { throw "Failed cases: $($failed -join ', ')" } Write-Host 'All cases passed.' -ForegroundColor Green