Files
jiapuapp/tests/help-center-openapi-contract.ps1
T
2026-07-24 07:56:33 +08:00

52 lines
2.5 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
$snapshotPath = Join-Path $root 'APP.openapi.json'
$pagePath = Join-Path $root 'pages/profile/m06-help-center.vue'
$issues = New-Object System.Collections.Generic.List[string]
if (-not (Test-Path -LiteralPath $snapshotPath -PathType Leaf)) {
$issues.Add('missing protected OpenAPI snapshot')
} else {
$snapshot = Get-Content -Raw -Encoding UTF8 -LiteralPath $snapshotPath | ConvertFrom-Json
$path = '/genealogy/app/help-articles'
$pathProperty = $snapshot.paths.PSObject.Properties[$path]
$operation = if ($pathProperty) { $pathProperty.Value.PSObject.Properties['get'] } else { $null }
if (-not $operation) {
$issues.Add("protected snapshot does not declare GET $path")
} else {
$response = $operation.Value.responses.PSObject.Properties['200']
$responseValue = if ($response) { $response.Value } else { $null }
if ($responseValue -and $responseValue.'$ref') {
$responseName = ([string]$responseValue.'$ref').Split('/')[-1]
$responseValue = $snapshot.components.responses.PSObject.Properties[$responseName].Value
}
$media = if ($responseValue -and $responseValue.content) { $responseValue.content.PSObject.Properties['application/json'] } else { $null }
$responseRef = if ($media) { [string]$media.Value.schema.'$ref' } else { '' }
if ($responseRef -eq '#/components/schemas/RListHelpArticleVo') {
$issues.Add('protected snapshot asserts RListHelpArticleVo, while current Apifox only declares a generic ListResult item projection')
}
}
}
if (-not (Test-Path -LiteralPath $pagePath -PathType Leaf)) {
$issues.Add('missing M06 page')
} else {
$page = Get-Content -Raw -Encoding UTF8 -LiteralPath $pagePath
foreach ($required in @('help-source-note', 'openPage("M07", {}, "M06")')) {
if (-not $page.Contains($required)) { $issues.Add("M06 page missing local/help fallback: $required") }
}
foreach ($forbidden in @('appApi.getHelp', '/help-articles/', 'helpId')) {
if ($page.Contains($forbidden)) { $issues.Add("M06 page must not invent an independent detail owner: $forbidden") }
}
}
if ($issues.Count -gt 0) {
Write-Output 'HELP-CENTER-OPENAPI-CONTRACT BLOCKED'
foreach ($issue in $issues) { Write-Output "- $issue" }
Write-Output '- The list is the only declared remote candidate. Do not add a detail endpoint or consume the protected snapshot schema until Apifox and a real authenticated response agree.'
exit 1
}
Write-Output 'HELP-CENTER-OPENAPI-CONTRACT PASS'