# One-command quality gate for ek-ui.
# Runs: cargo fmt --check / cargo test / cargo clippy -D warnings / cargo doc
# / scripts/check-package.ps1
# Usage: powershell -ExecutionPolicy Bypass -File scripts/gate.ps1 [-AllowDirty]
# NOTE: ASCII-only on purpose (Windows PowerShell 5.1 decodes BOM-less .ps1 as ANSI).
[CmdletBinding()]
param(
[switch]$AllowDirty
)
$ErrorActionPreference = 'Continue'
$root = Split-Path -Parent $PSScriptRoot
Push-Location $root
try {
Write-Host "toolchain:" -ForegroundColor Cyan
& rustfmt --version
& rustc --version
& cargo --version
$results = New-Object System.Collections.ArrayList
function Invoke-Gate {
param([string]$Name, [scriptblock]$Body)
Write-Host ""
Write-Host ("=== " + $Name + " ===") -ForegroundColor Cyan
& $Body
$code = $LASTEXITCODE
if ($null -eq $code) { $code = 0 }
if ($code -eq 0) {
Write-Host ("PASS " + $Name) -ForegroundColor Green
[void]$results.Add([pscustomobject]@{ Name = $Name; Ok = $true })
} else {
Write-Host ("FAIL " + $Name + " (exit " + $code + ")") -ForegroundColor Red
[void]$results.Add([pscustomobject]@{ Name = $Name; Ok = $false })
}
}
Invoke-Gate 'cargo fmt --check' { cargo fmt --check }
Invoke-Gate 'cargo test' { cargo test }
Invoke-Gate 'cargo clippy --all-targets -- -D warnings' { cargo clippy --all-targets -- -D warnings }
# native 档**只编译**不跑:CTP 实连测试全带 `#[ignore]`,平时跑不了,
# 但它们必须在闸里**编得过** —— 否则 `SecretString` 迁移那类断裂会静默躺平
# (2026-11-01 实测:5 个测试文件从未编译,实连面等于空的)。
Invoke-Gate 'cargo check --tests --features ctp-native' { cargo check --tests --features ctp-native }
Invoke-Gate 'cargo doc --no-deps' { cargo doc --no-deps }
$guard = Join-Path $PSScriptRoot 'check-package.ps1'
if ($AllowDirty) {
Invoke-Gate 'scripts/check-package.ps1 -AllowDirty' { & $guard -AllowDirty }
} else {
Invoke-Gate 'scripts/check-package.ps1 (strict)' { & $guard }
}
Write-Host ""
Write-Host "===== gate summary =====" -ForegroundColor Cyan
$failed = 0
foreach ($r in $results) {
if ($r.Ok) {
Write-Host (" PASS " + $r.Name) -ForegroundColor Green
} else {
Write-Host (" FAIL " + $r.Name) -ForegroundColor Red
$failed++
}
}
if ($failed -eq 0) {
Write-Host "ALL GATES PASSED" -ForegroundColor Green
exit 0
} else {
Write-Host ("GATES FAILED: " + $failed) -ForegroundColor Red
exit 1
}
} finally {
Pop-Location
}
# ── 数据契约禁止 `..*Data::default()` 兜底(2026-11-01)─────────────────
# 老写法让 `ek-data` 新增字段时静默变默认值、编译器一声不响
# (`traded_price` 就这么躺了好几轮才被审计发现)。
# 只查 src/:**examples 与 tests 里构造最小测试对象是正常写法**,不算违规。
$fallbacks = Get-ChildItem -Recurse -Filter *.rs -Path src | Select-String -Pattern '^\s*\.\.\w*Data::default\(\)'
if ($fallbacks) {
Write-Host "[gate] FAIL 数据契约出现兜底构造:" -ForegroundColor Red
$fallbacks | ForEach-Object { Write-Host (" {0}:{1} {2}" -f (Split-Path $_.Path -Leaf), $_.LineNumber, $_.Line.Trim()) }
throw "数据契约禁止 ..*Data::default();请显式写全字段"
}
Write-Host "[gate] OK 数据契约无兜底构造" -ForegroundColor Green