yeg
2026-09-18 db704fbed062d5700a37b7858231bf7d0958e38d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# MerchantCapabilityProbe 的运行脚本(只读排查探针)。
#
# 机制与 docs/audits/2026-09-10/run-probe.ps1 一致:先用 Maven 拿到 target/classes 与依赖 classpath,
# 再单独 javac 这个探针(它不在 src/main/java 下,所以不进 Maven 编译),最后 java 跑它。
#
# 所有参数都从命令行传,脚本里没有默认值:探针的 --db-url 指向哪个库,排查的就是哪个库。
# 端口 8134 上放的是 2026-09-16 合并进服务器库之前的本机旧副本,不是开发库(见 docs/agents/testing.md)。
#
# 用法示例:
#   .\run-MerchantCapabilityProbe.ps1 -ApplicationId 128 -DbUrl $env:PROBE_DB_URL -DbUser root -DbPassword 123456 -Config .\huifu-probe.properties
param(
    [string] $ApplicationId,
    [string] $HuifuId,
    [string] $MerchantId,
    [string] $StoreId,
    [Parameter(Mandatory = $true)][string] $DbUrl,
    [Parameter(Mandatory = $true)][string] $DbUser,
    [Parameter(Mandatory = $true)][string] $DbPassword,
    [string] $Config,
    [ValidateSet('test', 'prod')][string] $HuifuEnvironment,
    [switch] $SkipBuild
)
 
$ErrorActionPreference = 'Stop'
 
$given = @($ApplicationId, $HuifuId, $MerchantId) | Where-Object { $_ }
if ($given.Count -eq 0) { throw '必须给一个定位方式:-ApplicationId、-HuifuId 或 -MerchantId。' }
 
$probeArgs = @("--db-url=$DbUrl", "--db-user=$DbUser", "--db-password=$DbPassword")
if ($ApplicationId) { $probeArgs += "--application-id=$ApplicationId" }
if ($HuifuId) { $probeArgs += "--huifu-id=$HuifuId" }
if ($MerchantId) { $probeArgs += "--merchant-id=$MerchantId" }
if ($StoreId) { $probeArgs += "--store-id=$StoreId" }
if ($Config) { $probeArgs += "--config=$Config" }
if ($HuifuEnvironment) { $probeArgs += "--huifu-environment=$HuifuEnvironment" }
 
$serverRoot = (Resolve-Path (Join-Path $PSScriptRoot '../..')).Path
Push-Location $serverRoot
try {
    $classpathFile = 'target/probes/classpath.txt'
    # -SkipBuild 是给「同一 checkout 一次只跑一个 Maven 构建」这条硬约束准备的:已经构建过就别再起一个。
    if ($SkipBuild -and (Test-Path $classpathFile)) {
        Write-Host "跳过 Maven,复用 $classpathFile" -ForegroundColor Cyan
    } else {
        $maven = (Get-Command mvn -ErrorAction SilentlyContinue).Source
        if (-not $maven) { $maven = Join-Path $serverRoot 'mvnw.cmd' }
        & $maven -q -DskipTests compile dependency:build-classpath "-Dmdep.outputFile=$classpathFile" '-Dmdep.includeScope=test'
        if ($LASTEXITCODE -ne 0) { throw 'Maven preparation failed' }
    }
    $probeCp = (Get-Content $classpathFile -Raw).Trim()
    & javac -encoding UTF-8 -cp "target/classes;$probeCp" -d target/probes (Join-Path $PSScriptRoot 'MerchantCapabilityProbe.java')
    if ($LASTEXITCODE -ne 0) { throw 'Probe compilation failed' }
    & java -cp "target/probes;target/classes;$probeCp" MerchantCapabilityProbe @probeArgs
    if ($LASTEXITCODE -ne 0) { throw "Probe exited with $LASTEXITCODE" }
} finally {
    Pop-Location
}