$ErrorActionPreference = "Stop"
$ProjectRoot = Split-Path -Parent $PSScriptRoot
Push-Location (Join-Path $ProjectRoot "backend")
try {
    uv sync --locked
    if ($LASTEXITCODE -ne 0) { throw "依赖同步失败。" }
    uv run pytest
    if ($LASTEXITCODE -ne 0) { throw "测试失败。" }
    uv run ruff check .
    if ($LASTEXITCODE -ne 0) { throw "Ruff 检查失败。" }
    uv run mypy app
    if ($LASTEXITCODE -ne 0) { throw "mypy 检查失败。" }
}
finally {
    Pop-Location
}

Push-Location (Join-Path $ProjectRoot "frontend")
try {
    pnpm install --frozen-lockfile
    if ($LASTEXITCODE -ne 0) { throw "前端依赖同步失败。" }
    pnpm typecheck
    if ($LASTEXITCODE -ne 0) { throw "前端类型检查失败。" }
    pnpm build
    if ($LASTEXITCODE -ne 0) { throw "前端构建失败。" }
}
finally {
    Pop-Location
}
