forked from cflmy/deepseek-harness
Offline runtime pack bootstrap, real check/call smoke and cold-install evidence for the 2026-12-03 Windows experimental build; also fix the package script variable shadowing found during packaging.
254 lines
14 KiB
PowerShell
254 lines
14 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Build one experimental Windows (x86_64) Marqdo Harness release archive.
|
|
|
|
.DESCRIPTION
|
|
Stages the built tree without VCS data, installs a production-only flat
|
|
`node_modules` so the archive has no package-manager link farm, bundles the
|
|
Node 24 runtime, adds the `mqdh.cmd` portable launcher and `install.ps1`,
|
|
then verifies the archive from a cold extract (user-level install, version,
|
|
doctor, dump-config).
|
|
|
|
This is the Windows packaging entry point for the experimental distribution;
|
|
it does not replace the Linux `package.sh` pipeline or fabricate CI evidence.
|
|
CI/CD remains Woodpecker-only; a native Windows runner is still required
|
|
before the platform can be declared supported.
|
|
|
|
Environment:
|
|
MQDH_NODE24_DIR directory containing node.exe and pnpm.cmd (Node >= 24.22.3)
|
|
MQDH_PACKAGE_WORK working directory for staging/cold install (default: temp)
|
|
|
|
.EXAMPLE
|
|
powershell -ExecutionPolicy Bypass -File .\scripts\package-windows.ps1
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$OutDir = (Join-Path $PSScriptRoot '..\.ci'),
|
|
[string]$RuntimeDeps = ''
|
|
)
|
|
|
|
$ErrorActionPreference = 'Continue'
|
|
Set-StrictMode -Version Latest
|
|
$root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
|
Set-Location $root
|
|
$nodeDir = $env:MQDH_NODE24_DIR
|
|
if ([string]::IsNullOrWhiteSpace($nodeDir)) { throw 'MQDH_NODE24_DIR is required (Node >= 24.22.3 with pnpm)' }
|
|
$nodeExe = Join-Path $nodeDir 'node.exe'
|
|
$pnpmCmd = Join-Path $nodeDir 'pnpm.cmd'
|
|
foreach ($required in @($nodeExe, $pnpmCmd)) {
|
|
if (-not (Test-Path -LiteralPath $required)) { throw "missing build tool: $required" }
|
|
}
|
|
$nodeVersion = (& $nodeExe --version).Trim()
|
|
if ($nodeVersion -notmatch '^v(\d+)\.' -or [int]$Matches[1] -lt 24) {
|
|
throw "Node >= 24.22.3 is required, got $nodeVersion"
|
|
}
|
|
foreach ($required in @('apps\cli\lib\bin.js', 'apps\web\dist\index.html', 'scripts\mqdh.mjs')) {
|
|
if (-not (Test-Path -LiteralPath (Join-Path $root $required))) {
|
|
throw "build artifacts missing ($required); run pnpm run build first"
|
|
}
|
|
}
|
|
$version = (Get-Content -LiteralPath (Join-Path $root 'packages\marqdo\harness\package.json') -Raw | ConvertFrom-Json).version
|
|
$sha = (& git -C $root rev-parse HEAD).Trim()
|
|
if ($sha -notmatch '^[0-9a-f]{40}$') { throw "invalid source SHA: $sha" }
|
|
$status = & git -C $root status --porcelain
|
|
if ($status) { throw 'package-windows: the worktree must be clean before packaging' }
|
|
|
|
$target = 'x86_64-pc-windows-msvc'
|
|
$name = "marqdo-harness-$version-$target"
|
|
$workRoot = if ($env:MQDH_PACKAGE_WORK) { $env:MQDH_PACKAGE_WORK } else { $env:TEMP }
|
|
$stage = Join-Path $workRoot ("mqdh-win-stage-" + [guid]::NewGuid().ToString('N').Substring(0, 8))
|
|
$cold = Join-Path $workRoot ("mqdh-win-cold-" + [guid]::NewGuid().ToString('N').Substring(0, 8))
|
|
$app = Join-Path $stage $name
|
|
New-Item -ItemType Directory -Force -Path $app, $cold, $OutDir | Out-Null
|
|
try {
|
|
# Stage the tracked/built source tree without VCS data or any workspace
|
|
# node_modules. A tar copy is used instead of robocopy because pnpm creates
|
|
# per-workspace symbolic-link node_modules; robocopy follows those links and
|
|
# builds path-limit-breaking recursive copies.
|
|
$sourceTar = Join-Path $workRoot ("mqdh-win-src-" + [guid]::NewGuid().ToString('N').Substring(0, 8) + '.tar')
|
|
$excludes = @(
|
|
'--exclude=.git', '--exclude=node_modules', '--exclude=.ci', '--exclude=.build',
|
|
'--exclude=.issue-work', '--exclude=.app-verify', '--exclude=.integration-work',
|
|
'--exclude=.migration-work', '--exclude=.dsh-build', '--exclude=__pycache__',
|
|
'--exclude=.pytest_cache', '--exclude=coverage', '--exclude=.turbo', '--exclude=.vite',
|
|
'--exclude=*.log', '--exclude=*.tsbuildinfo', '--exclude=.DS_Store'
|
|
)
|
|
& tar.exe -cf $sourceTar @excludes -C $root .
|
|
if ($LASTEXITCODE -ne 0) { throw "source staging tar failed with exit code $LASTEXITCODE" }
|
|
& tar.exe -xf $sourceTar -C $app
|
|
if ($LASTEXITCODE -ne 0) { throw "source staging extraction failed with exit code $LASTEXITCODE" }
|
|
Remove-Item -LiteralPath $sourceTar -Force -ErrorAction SilentlyContinue
|
|
|
|
# Production-only flat dependency tree: no pnpm symlink/junction farm, so the
|
|
# archive extracts without Windows symlink privileges. Lifecycle scripts are
|
|
# skipped: the staged tree has no git checkout for the hook installer, and the
|
|
# build artifacts are already produced in the source worktree.
|
|
$env:PATH = "$nodeDir;$env:PATH"
|
|
Push-Location $app
|
|
try {
|
|
$pnpmLog = & $pnpmCmd install --frozen-lockfile --prod --node-linker=hoisted --ignore-scripts 2>&1
|
|
if ($LASTEXITCODE -ne 0) { throw ("production dependency install failed: " + ($pnpmLog -join "`n")) }
|
|
} finally {
|
|
Pop-Location
|
|
}
|
|
|
|
# pnpm also creates node_modules in each workspace package for its local
|
|
# links. Those link farms require symlink privileges after extraction and
|
|
# are unnecessary: the hoisted root node_modules resolves every dependency.
|
|
# cmd's rmdir removes junctions/links without following them.
|
|
$nested = @()
|
|
$nested += Get-ChildItem -LiteralPath (Join-Path $app 'apps') -Directory -ErrorAction SilentlyContinue | ForEach-Object { Join-Path $_.FullName 'node_modules' }
|
|
$nested += Get-ChildItem -LiteralPath (Join-Path $app 'packages') -Directory -ErrorAction SilentlyContinue | ForEach-Object {
|
|
Get-ChildItem -LiteralPath $_.FullName -Directory -ErrorAction SilentlyContinue | ForEach-Object { Join-Path $_.FullName 'node_modules' }
|
|
}
|
|
$nested += Get-ChildItem -LiteralPath (Join-Path $app 'vendor') -Directory -ErrorAction SilentlyContinue | ForEach-Object { Join-Path $_.FullName 'node_modules' }
|
|
$nested += Join-Path $app 'native\system\node_modules'
|
|
$nested += Get-ChildItem -LiteralPath (Join-Path $app 'native\system\packages') -Directory -ErrorAction SilentlyContinue | ForEach-Object { Join-Path $_.FullName 'node_modules' }
|
|
foreach ($nestedPath in $nested) {
|
|
if (Test-Path -LiteralPath $nestedPath) {
|
|
& cmd.exe /c "rmdir /s /q `"$nestedPath`"" | Out-Null
|
|
}
|
|
}
|
|
# Hoisted install still links workspace packages into node_modules. Replace
|
|
# each link with a copy so extraction on a clean Windows host needs no
|
|
# symbolic-link privilege; nested dependency links are unnecessary because
|
|
# the hoisted root node_modules holds the shared dependency tree.
|
|
for ($pass = 0; $pass -lt 3; $pass++) {
|
|
$links = @(Get-ChildItem -LiteralPath (Join-Path $app 'node_modules') -Recurse -Force -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.Attributes -band [System.IO.FileAttributes]::ReparsePoint })
|
|
if ($links.Count -eq 0) { break }
|
|
foreach ($link in $links) {
|
|
$linkTarget = $link.Target
|
|
if ($linkTarget -is [array]) { $linkTarget = $linkTarget[0] }
|
|
if (-not [System.IO.Path]::IsPathRooted($linkTarget)) { $linkTarget = Join-Path $link.DirectoryName $linkTarget }
|
|
$linkTarget = [System.IO.Path]::GetFullPath($linkTarget)
|
|
if ((Test-Path -LiteralPath $linkTarget) -and (Get-Item -LiteralPath $linkTarget).PSIsContainer) {
|
|
$copy = "$($link.FullName).workspace-copy"
|
|
Remove-Item -LiteralPath $copy -Recurse -Force -ErrorAction SilentlyContinue
|
|
# Do not copy the target's own node_modules: the hoisted root
|
|
# dependency tree is the only resolver, and copy sources can
|
|
# contain directory symlinks that robocopy would follow into
|
|
# path-limit-breaking recursive copies.
|
|
& robocopy $linkTarget $copy /E /XJ /XD (Join-Path $linkTarget 'node_modules') /R:1 /W:1 /NFL /NDL /NJH /NJS /NP | Out-Null
|
|
if ($LASTEXITCODE -ge 8) { throw "workspace link copy failed: $($link.FullName)" }
|
|
[System.IO.Directory]::Delete($link.FullName)
|
|
Move-Item -LiteralPath $copy -Destination $link.FullName
|
|
} else {
|
|
$bytes = [System.IO.File]::ReadAllBytes($linkTarget)
|
|
[System.IO.File]::Delete($link.FullName)
|
|
[System.IO.File]::WriteAllBytes($link.FullName, $bytes)
|
|
}
|
|
}
|
|
}
|
|
$links = @(Get-ChildItem -LiteralPath (Join-Path $app 'node_modules') -Recurse -Force -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.Attributes -band [System.IO.FileAttributes]::ReparsePoint })
|
|
if ($links.Count -gt 0) {
|
|
throw "flat node_modules still contains $($links.Count) reparse points; the archive would not be portable"
|
|
}
|
|
|
|
# Documentation, benchmarks, repository automation and Python/website
|
|
# sources are not part of the product runtime; dropping them keeps the
|
|
# experimental Windows download within the same order of magnitude as the
|
|
# Linux archive.
|
|
foreach ($prune in @('docs', 'website', 'benchmarks', '.agents', '.claude', '.github', '.woodpecker', 'python', 'snapshots')) {
|
|
Remove-Item -LiteralPath (Join-Path $app $prune) -Recurse -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
New-Item -ItemType Directory -Force -Path (Join-Path $app 'runtime') | Out-Null
|
|
Copy-Item -LiteralPath $nodeExe -Destination (Join-Path $app 'runtime\node.exe')
|
|
Set-Content -LiteralPath (Join-Path $app 'runtime\VERSION') -Value $nodeVersion -Encoding ASCII
|
|
Set-Content -LiteralPath (Join-Path $app 'SOURCE_SHA') -Value $sha -Encoding ASCII
|
|
Copy-Item -LiteralPath (Join-Path $root 'scripts\install.ps1') -Destination (Join-Path $app 'install.ps1') -Force
|
|
Copy-Item -LiteralPath (Join-Path $root 'scripts\mqdh.cmd') -Destination (Join-Path $app 'mqdh.cmd') -Force
|
|
|
|
# Optional bundled offline runtime pack: the launcher points bootstrap at it,
|
|
# so a fresh Windows install can install CLI/Worker/Bundle without network.
|
|
$bundledRuntime = @()
|
|
if ($RuntimeDeps -ne '') {
|
|
$deps = (Resolve-Path -LiteralPath $RuntimeDeps).Path
|
|
if (-not (Test-Path -LiteralPath $deps)) { throw "runtime deps directory is missing: $RuntimeDeps" }
|
|
$targetDeps = Join-Path $app 'runtime-deps'
|
|
New-Item -ItemType Directory -Force -Path $targetDeps | Out-Null
|
|
foreach ($file in Get-ChildItem -LiteralPath $deps -File) {
|
|
Copy-Item -LiteralPath $file.FullName -Destination (Join-Path $targetDeps $file.Name)
|
|
if ($file.Name -like '*.tar.gz') {
|
|
$sidecar = Join-Path $deps ($file.Name + '.sha256')
|
|
if (-not (Test-Path -LiteralPath $sidecar)) { throw "runtime deps archive has no .sha256 sidecar: $($file.Name)" }
|
|
$digest = (Get-FileHash -LiteralPath $file.FullName -Algorithm SHA256).Hash.ToLower()
|
|
$declared = (Get-Content -LiteralPath $sidecar -Raw).Trim().Split(' ')[0].ToLower()
|
|
if ($digest -ne $declared) { throw "runtime deps digest mismatch: $($file.Name)" }
|
|
$bundledRuntime += [ordered]@{ name = $file.Name; size = $file.Length; sha256 = $digest }
|
|
}
|
|
}
|
|
if ($bundledRuntime.Count -eq 0) { throw 'runtime deps directory has no component archive' }
|
|
}
|
|
|
|
$archive = Join-Path $OutDir "$name.tar.gz"
|
|
Remove-Item -LiteralPath $archive -Force -ErrorAction SilentlyContinue
|
|
& tar.exe -czf $archive -C $stage $name
|
|
if ($LASTEXITCODE -ne 0) { throw "archive creation failed with exit code $LASTEXITCODE" }
|
|
$sha256 = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash.ToLower()
|
|
Set-Content -LiteralPath "$archive.sha256" -Value "$sha256 $name.tar.gz" -Encoding ASCII
|
|
Write-Host "archive: $archive ($((Get-Item -LiteralPath $archive).Length) bytes, sha256 $sha256)"
|
|
|
|
$manifestArgs = @('scripts/release-manifest.ts', '--archive', $archive, '--target', $target, '--out', $OutDir)
|
|
$manifestLog = & $nodeExe @manifestArgs 2>&1
|
|
if ($LASTEXITCODE -ne 0) { throw ("release manifest generation failed: " + ($manifestLog -join "`n")) }
|
|
$manifestLog | Out-Host
|
|
|
|
& tar.exe -xzf $archive -C $cold
|
|
if ($LASTEXITCODE -ne 0) { throw "cold extract failed with exit code $LASTEXITCODE" }
|
|
$coldTree = Join-Path $cold $name
|
|
$coldPrefix = Join-Path $cold 'prefix'
|
|
& powershell -NoProfile -ExecutionPolicy Bypass -File (Join-Path $coldTree 'install.ps1') -Prefix $coldPrefix -NoPath -NoShortcut | Out-Host
|
|
if ($LASTEXITCODE -ne 0) { throw "cold install failed with exit code $LASTEXITCODE" }
|
|
$installed = (& (Join-Path $coldPrefix 'bin\mqdh.cmd') --version).Trim()
|
|
if ($installed -notlike "*$version*") { throw "cold version mismatch: $installed" }
|
|
$coldHome = Join-Path $cold 'home'
|
|
$env:MQDH_HOME = $coldHome
|
|
$doctor = (& (Join-Path $coldPrefix 'bin\mqdh.cmd') doctor --json) -join "`n"
|
|
$doctorJson = $doctor | ConvertFrom-Json
|
|
if ($doctorJson.schema -ne 'marqdo.mqdh.doctor') { throw "unexpected doctor schema: $($doctorJson.schema)" }
|
|
if ($doctorJson.platform.target -ne $target) { throw "unexpected doctor target: $($doctorJson.platform.target)" }
|
|
$dump = (& (Join-Path $coldPrefix 'bin\mqdh.cmd') --dump-config) -join "`n"
|
|
if ($dump -notmatch 'mqdh-harness' -or $dump -notmatch 'mqdh-web') { throw 'dump-config missing mqdh profile entries' }
|
|
Remove-Item Env:MQDH_HOME
|
|
& $nodeExe --version | Out-Null
|
|
|
|
$evidence = [ordered]@{
|
|
schema = 'marqdo.mqdh.package-evidence'
|
|
schema_version = 1
|
|
status = 'PASS'
|
|
archive = "$name.tar.gz"
|
|
size = (Get-Item -LiteralPath $archive).Length
|
|
sha256 = $sha256
|
|
application_sha = $sha
|
|
platform = $target
|
|
node = (& $nodeExe --version).Trim()
|
|
bundled_node = [ordered]@{ version = (Get-Content -LiteralPath (Join-Path $app 'runtime\VERSION')).Trim(); sha256 = (Get-FileHash -LiteralPath (Join-Path $app 'runtime\node.exe') -Algorithm SHA256).Hash.ToLower() }
|
|
cold_install = [ordered]@{
|
|
version = $installed
|
|
doctor_schema = $doctorJson.schema
|
|
doctor_target = $doctorJson.platform.target
|
|
dump_config = 'PASS'
|
|
bundle_node = 'PASS'
|
|
}
|
|
manifest = 'mqdh-release.json'
|
|
signature = 'unsigned'
|
|
bundled_runtime = $bundledRuntime
|
|
contains_marqdo_cli_source = $false
|
|
unverified = @(
|
|
'native Windows CI runner',
|
|
'official signing key',
|
|
'real model E2E',
|
|
'second clean Windows host',
|
|
'in-app Windows update path'
|
|
)
|
|
}
|
|
$evidence | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath (Join-Path $OutDir 'package-evidence.json') -Encoding UTF8
|
|
Write-Host 'mqdh windows package: PASS'
|
|
} finally {
|
|
Remove-Item -LiteralPath $stage -Recurse -Force -ErrorAction SilentlyContinue
|
|
Remove-Item -LiteralPath $cold -Recurse -Force -ErrorAction SilentlyContinue
|
|
}
|