Files
md-preview/agent/tests/smoke.ps1
Richard Wu d2b1630a35 chore: switch to Low workspace and Nutstore-only publish
- build.ps1: dev build only; no copy to a fixed exe
- publish.ps1: user-run Medium publish to Nutstore
- docs: workspace stays D:\Scripts\md-preview, repo under AgentLowWorking
- .gitignore: local test/ scratch directory
2026-11-02 01:26:49 +08:00

90 lines
3.1 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#requires -Version 5.1
<#
MD Preview 冒烟测试
cargo test + 关联检查 + 可选隔离启动(不污染真实 %LOCALAPPDATA%)
默认测试 Nutstore 发布版;-Dev 测试 target\release 开发版
#>
[CmdletBinding()]
param(
[string]$Exe = 'C:\Users\wucl1\Nutstore\1\Scripts\MD-Preview-windows-x64.exe',
[switch]$Launch,
[switch]$Dev
)
$ErrorActionPreference = 'Stop'
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
Set-Location $repoRoot
$tmpRoot = Join-Path $repoRoot 'target\tmp'
New-Item -ItemType Directory -Force $tmpRoot | Out-Null
$env:TEMP = $tmpRoot
$env:TMP = $tmpRoot
$cargo = Join-Path $env:USERPROFILE '.cargo\bin\cargo.exe'
if (-not (Test-Path $cargo)) { $cargo = (Get-Command cargo -ErrorAction Stop).Source }
if ($Dev) {
$Exe = Join-Path $repoRoot 'target\release\md-preview.exe'
if (-not $env:MD_PREVIEW_CONFIG_DIR) {
$env:MD_PREVIEW_CONFIG_DIR = Join-Path $repoRoot 'target\smoke'
New-Item -ItemType Directory -Force $env:MD_PREVIEW_CONFIG_DIR | Out-Null
}
}
if (-not (Test-Path $Exe)) {
throw ('missing exe: ' + $Exe + '(先运行 agent/scripts/build.ps1,或先发布)')
}
Write-Host '==> cargo test' -ForegroundColor Cyan
$previous = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
& $cargo test
$code = $LASTEXITCODE
$ErrorActionPreference = $previous
if ($code -ne 0) { throw 'cargo test failed' }
Write-Host '==> --help' -ForegroundColor Cyan
$help = (& $Exe --help 2>&1 | Out-String)
if ($help -match 'MD Preview') {
Write-Host ' OK'
} else {
Write-Warning '--help 无输出(GUI 子系统在部分终端下不回显,可忽略)'
}
if ($Dev) {
Write-Host '==> registry association (skipped: Low build cannot write HKCU)' -ForegroundColor Cyan
} else {
Write-Host '==> registry association' -ForegroundColor Cyan
$reg = Get-ItemProperty 'HKCU:\Software\Classes\MDPreview.md\shell\open\command' -ErrorAction SilentlyContinue
$expected = '"' + $Exe + '" "%1"'
if ($null -eq $reg) {
Write-Warning 'ProgID 未注册(先运行一次 exe)'
} elseif ($reg.'(default)' -ne $expected) {
Write-Warning ('ProgID 指向不一致: ' + $reg.'(default)')
} else {
Write-Host ' OK'
}
}
if ($Launch) {
Write-Host '==> launch with isolated config' -ForegroundColor Cyan
$config = Join-Path $tmpRoot ('mdp-smoke-' + [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $config | Out-Null
$fixture = Join-Path $PSScriptRoot 'fixtures\long-headings.md'
$env:MD_PREVIEW_CONFIG_DIR = $config
try {
$proc = Start-Process -FilePath $Exe -ArgumentList @($fixture) -PassThru
Start-Sleep -Seconds 3
if ($proc.HasExited) { throw ('process exited early: ' + $proc.ExitCode) }
Write-Host ' running - OK'
$proc.CloseMainWindow() | Out-Null
if (-not $proc.WaitForExit(5000)) { $proc.Kill() }
Write-Host ' exit - OK'
} finally {
Remove-Item Env:\MD_PREVIEW_CONFIG_DIR -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force $config -ErrorAction SilentlyContinue
}
}
Write-Host 'SMOKE OK' -ForegroundColor Green