- 前端: React+Vite 首页/AI专区, 算法库(MARD色板/量化/背景去除), API对接 - 后端: Express+SQLite, 兑换码/订单/支付/chibi生成, 风控+云端同步 - CI/CD: GitHub Actions + Docker + nginx 配置 - 文档: PRD/DESIGN/LAUNCH/ROADMAP/E2E/竞品对照等 15 份 - 工程: 任务看板(taskboard) + 健康巡检(agent-health) + Git流程(gitflow)
88 lines
4.9 KiB
PowerShell
88 lines
4.9 KiB
PowerShell
# Final E2E run for PERLER LAB — uses curl.exe -o to capture raw UTF-8 bytes,
|
|
# then reads files with UTF-8 encoding (avoids PS pipeline codepage mangling).
|
|
$ErrorActionPreference = "Stop"
|
|
$base = "http://localhost:8788"
|
|
$tmp = "D:\拼豆\perler-lab-server\data\e2e"
|
|
New-Item -ItemType Directory -Path $tmp -Force | Out-Null
|
|
Remove-Item "$tmp\*" -ErrorAction SilentlyContinue
|
|
|
|
# ---------- request bodies (UTF-8 no BOM) ----------
|
|
$ordersBody = '{"packageName":"体验包","paymentMethod":"wechat"}'
|
|
$genBody = '{"code":"CODEHERE","image":"data:image/png;base64,iVBORw0KGgo=","category":"pet","subtype":"cat","gridSize":64,"colorCount":24,"composition":"主体特写","detailTags":["眼睛更有神"]}'
|
|
[System.IO.File]::WriteAllText("$tmp\orders.json", $ordersBody, (New-Object System.Text.UTF8Encoding($false)))
|
|
[System.IO.File]::WriteAllText("$tmp\gen.template.json", $genBody, (New-Object System.Text.UTF8Encoding($false)))
|
|
|
|
function CurlJson($name, $method, $url, $dataFile, $extraHeaders) {
|
|
$out = "$tmp\$name.json"
|
|
$code = "$tmp\$name.code"
|
|
$args = @("-s","-o",$out,"-w","%{http_code}", "-X",$method, $url, "-H","Content-Type: application/json; charset=utf-8")
|
|
if ($dataFile) { $args += @("--data-binary", "@$dataFile") }
|
|
if ($extraHeaders) { $args += $extraHeaders }
|
|
curl.exe @args | Out-File $code -Encoding ascii -NoNewline
|
|
$http = (Get-Content $code -Raw).Trim()
|
|
$json = Get-Content $out -Raw -Encoding UTF8
|
|
return @{ http = [int]$http; json = $json }
|
|
}
|
|
|
|
$results = [ordered]@{}
|
|
|
|
# S1 health
|
|
$h = curl.exe -s -o "$tmp\health.json" -w "%{http_code}" "$base/health"
|
|
$results["S1_health"] = "GET /health -> HTTP $h `n $([System.IO.File]::ReadAllText("$tmp\health.json"))"
|
|
|
|
# S2 CORS preflight
|
|
$p = curl.exe -s -o NUL -w "%{http_code}" -X OPTIONS "$base/api/codes/redeem" -H "Origin: http://localhost:5173" -H "Access-Control-Request-Method: POST" -H "Access-Control-Request-Headers: Content-Type"
|
|
$hdrs = curl.exe -s -D - -o NUL "$base/health" -H "Origin: http://localhost:5173"
|
|
$corsLine = ($hdrs | Select-String "Access-Control-Allow-Origin|Vary|Access-Control-Allow-Methods|Access-Control-Allow-Headers") -join "; "
|
|
$results["S2_cors"] = "OPTIONS preflight -> HTTP $p (expect 204); real GET headers -> $corsLine"
|
|
|
|
# S3 create order
|
|
$r = CurlJson "s3_orders" "POST" "$base/api/orders" "$tmp\orders.json"
|
|
$o = $r.json | ConvertFrom-Json
|
|
$orderNo = $o.order.orderNo
|
|
$results["S3_orders"] = "POST /api/orders -> HTTP $($r.http) `n $($r.json) `n orderNo=$orderNo"
|
|
|
|
# S4 pay-callback
|
|
$r = CurlJson "s4_cb" "POST" "$base/api/orders/$orderNo/pay-callback" "$tmp\orders.json"
|
|
$o = $r.json | ConvertFrom-Json
|
|
$accessCode = $o.accessCode
|
|
$results["S4_callback"] = "POST pay-callback -> HTTP $($r.http) `n $($r.json) `n accessCode=$accessCode"
|
|
|
|
# S5 redeem
|
|
$redeemBody = "{`"code`":`"$accessCode`"}"
|
|
[System.IO.File]::WriteAllText("$tmp\redeem.json", $redeemBody, (New-Object System.Text.UTF8Encoding($false)))
|
|
$r = CurlJson "s5_redeem" "POST" "$base/api/codes/redeem" "$tmp\redeem.json"
|
|
$results["S5_redeem"] = "POST /api/codes/redeem -> HTTP $($r.http) `n $($r.json)"
|
|
|
|
# S6 consume
|
|
$consumeBody = "{`"code`":`"$accessCode`",`"fileName`":`"test.png`"}"
|
|
[System.IO.File]::WriteAllText("$tmp\consume.json", $consumeBody, (New-Object System.Text.UTF8Encoding($false)))
|
|
$r = CurlJson "s6_consume" "POST" "$base/api/codes/consume" "$tmp\consume.json"
|
|
$results["S6_consume"] = "POST /api/codes/consume -> HTTP $($r.http) `n $($r.json)"
|
|
|
|
# S7 generate
|
|
$gBody = $genBody.Replace("CODEHERE", $accessCode)
|
|
[System.IO.File]::WriteAllText("$tmp\gen.json", $gBody, (New-Object System.Text.UTF8Encoding($false)))
|
|
$r = CurlJson "s7_gen" "POST" "$base/api/chibi/generate" "$tmp\gen.json"
|
|
$g = $r.json | ConvertFrom-Json
|
|
$results["S7_generate"] = "POST /api/chibi/generate -> HTTP $($r.http) `n image_prefix=$($g.image.Substring(0,22))... len=$($g.image.Length) `n downloadGrant=$($g.downloadGrant) `n access=$($g.access | ConvertTo-Json -Compress)"
|
|
|
|
# S8 redeem invalid code -> 404
|
|
$invBody = '{"code":"ZZZZZZZZZZZZZZZZ"}'
|
|
[System.IO.File]::WriteAllText("$tmp\inv.json", $invBody, (New-Object System.Text.UTF8Encoding($false)))
|
|
$r = CurlJson "s8_inv" "POST" "$base/api/codes/redeem" "$tmp\inv.json"
|
|
$results["S8_redeem_invalid"] = "POST redeem invalid code -> HTTP $($r.http) (expect 404) `n $($r.json)"
|
|
|
|
# S9 exhaust + generate -> 402
|
|
$r = CurlJson "s9_consume2" "POST" "$base/api/codes/consume" "$tmp\consume.json"
|
|
$results["S9a_exhaust"] = "POST consume (3rd use) -> HTTP $($r.http) `n $($r.json)"
|
|
$r = CurlJson "s9_gen_exhausted" "POST" "$base/api/chibi/generate" "$tmp\gen.json"
|
|
$results["S9b_generate_exhausted"] = "POST generate exhausted -> HTTP $($r.http) (expect 402) `n $($r.json)"
|
|
|
|
# ---------- output ----------
|
|
$out = ""
|
|
foreach ($k in $results.Keys) { $out += "=== $k ===`n$($results[$k])`n`n" }
|
|
[System.IO.File]::WriteAllText("$tmp\summary.txt", $out, (New-Object System.Text.UTF8Encoding($false)))
|
|
Write-Output "SUMMARY_WRITTEN: $tmp\summary.txt"
|
|
Write-Output "accessCode=$accessCode orderNo=$orderNo"
|