Files
jiapuapp/tests/a04-registration-contract.ps1
T
2026-07-27 06:50:23 +08:00

135 lines
6.8 KiB
PowerShell

$ErrorActionPreference = 'Stop'
function ConvertFrom-Utf8Base64 {
param([string]$Value)
return [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($Value))
}
function Assert-Contains {
param([string]$Content, [string]$Expected, [string]$Message)
if ($Content -notmatch [regex]::Escape($Expected)) { throw $Message }
}
function Assert-NotContains {
param([string]$Content, [string]$Unexpected, [string]$Message)
if ($Content -match [regex]::Escape($Unexpected)) { throw $Message }
}
$root = Split-Path -Parent $PSScriptRoot
$registerPath = Join-Path $root 'pages/auth/a04-register.vue'
$pages = Get-Content -LiteralPath (Join-Path $root 'pages.json') -Raw -Encoding utf8 | ConvertFrom-Json
$register = Get-Content -LiteralPath $registerPath -Raw -Encoding utf8
$globalStyles = Get-Content -LiteralPath (Join-Path $root 'styles/global.scss') -Raw -Encoding utf8
$registerCopy = ConvertFrom-Utf8Base64 '5rOo5YaM6LSm5Y+3'
$loginCopy = ConvertFrom-Utf8Base64 '55m75b2V'
if (-not ($pages.pages.path -contains 'pages/auth/a04-register')) { throw 'A-04 route must remain declared in pages.json' }
Assert-NotContains -Content $register -Unexpected 'ModulePage' -Message 'A-04 must not remain a ModulePage shell'
foreach ($required in @(
'<AuthPageShell',
'import AuthPageShell from "@/components/AuthPageShell.vue";',
'a01-vnext-divider-v1.png',
'a01-scroll-primary-v3.png',
'import AppToast from "@/components/AppToast.vue";',
'a02-agreement-unchecked.png',
'a02-agreement-checked.png',
'v-model.trim="phone"',
'v-model.trim="nickName"',
'for="a04-nickname"',
'class="required-mark"',
'v-model.trim="verificationCode"',
'v-model="password"',
'v-model="confirmPassword"',
'const agreed = ref(false)',
'const agreementError = ref(false)',
'const fieldErrors = ref({',
'const toggleAgreement = () =>',
'const submitRegister = async () =>',
'<AppToast :visible="feedbackVisible" :message="feedbackMessage" />',
'<TacVerification',
'AUTH_VERIFICATION_OPERATION.REGISTER',
'appApi.registerWithPassword',
'if (!/^\d{4}$/.test(verificationCode.value))',
'if (!isAuthPhone(phone.value))',
'validatePassword(password.value)',
'PASSWORD_POLICY_MESSAGE',
'if (!confirmPassword.value)',
'if (password.value !== confirmPassword.value)'
)) {
Assert-Contains -Content $register -Expected $required -Message "Missing A-04 registration contract: $required"
}
Assert-Contains -Content $register -Expected $registerCopy -Message 'A-04 must visibly identify registration'
Assert-Contains -Content $register -Expected $loginCopy -Message 'A-04 must provide a login return path'
Assert-NotContains -Content $register -Unexpected 'register-intro' -Message 'A-04 must not retain the redundant registration intro copy'
foreach ($forbidden in @('class="page-canvas"', 'class="page-backdrop"', 'mode="scaleToFill"', '1665rpx', 'a01-red-hall-ink-backdrop-v1.png')) {
Assert-NotContains -Content $register -Unexpected $forbidden -Message "A04 retains rejected page coordinates: $forbidden"
}
Assert-Contains -Content $globalStyles -Expected 'font-family: "STKaiti", "KaiTi", serif' -Message 'Global styles must own the A04 font contract.'
Assert-NotContains -Content $register -Unexpected 'font-family:' -Message 'A04 must inherit the global font contract instead of overriding it locally.'
foreach ($obsoleteVisual in @(
'a01-primary-button.png',
'a01-secondary-button.png',
'a02-login-panel.png',
'verificationVisible',
'verification-layer',
'feedback-toast__skin'
)) {
Assert-NotContains -Content $register -Unexpected $obsoleteVisual -Message "A04 must not retain obsolete visual or placeholder state: $obsoleteVisual"
}
foreach ($nativeUi in @('uni.showToast', 'uni.showModal', 'uni.showLoading', 'uni.showActionSheet')) {
Assert-NotContains -Content $register -Unexpected $nativeUi -Message "A-04 must not use native UniApp feedback: $nativeUi"
}
Assert-NotContains -Content $register -Unexpected '/pages/auth/a02-login' -Message 'A-04 must not return to the retired A02 route.'
foreach ($required in @(
'register-divider',
'mode="aspectFit"',
'role="alert"',
'aria-describedby'
)) {
Assert-Contains -Content $register -Expected $required -Message "Missing A-04 visual balance contract: $required"
}
$contentRule = [regex]::Match($register, '(?ms)^\.register-content\s*\{(?<Body>.*?)^\}')
if (-not $contentRule.Success) { throw 'A04 register content rule is missing.' }
foreach ($required in @('display: flex;', 'flex: 1;', 'flex-direction: column;', 'justify-content: flex-start;', 'max-width: 480px;', 'margin: 0 auto;')) {
Assert-Contains -Content $contentRule.Groups['Body'].Value -Expected $required -Message "A04 register content must use document flow: $required"
}
$headingRule = [regex]::Match($register, '(?ms)^\.page-heading\s*\{(?<Body>.*?)^\}')
if (-not $headingRule.Success) { throw 'A04 page heading rule is missing.' }
Assert-Contains -Content $headingRule.Groups['Body'].Value -Expected 'grid-template-columns: minmax(0, 1fr);' -Message 'A04 heading must center against the full content width.'
foreach ($selector in @('page-title', 'page-subtitle', 'register-divider')) {
$rule = [regex]::Match($register, "(?ms)^\.$selector\s*\{(?<Body>.*?)^\}")
if (-not $rule.Success) { throw "A04 heading child rule is missing: $selector" }
Assert-Contains -Content $rule.Groups['Body'].Value -Expected 'grid-column: 1;' -Message "A04 heading child must remain in the full-width grid column: $selector"
}
foreach ($ruleContract in @(
@{ Selector = 'register-submit__content'; Expected = 'font-size: 36rpx;' },
@{ Selector = 'agreement-row'; Expected = 'font-size: 24rpx;' },
@{ Selector = 'agreement-row'; Expected = 'color: #493323;' },
@{ Selector = 'input-label'; Expected = 'font-size: 30rpx;' },
@{ Selector = 'auth-input'; Expected = 'font-size: 30rpx;' },
@{ Selector = 'auth-input'; Expected = 'color: #493323;' },
@{ Selector = 'placeholder'; Expected = 'color: #9f968d;' },
@{ Selector = 'login-entry'; Expected = 'font-size: 28rpx;' },
@{ Selector = 'login-entry'; Expected = 'color: #493323;' },
@{ Selector = 'login-entry'; Expected = 'margin-top: auto;' }
)) {
$rule = [regex]::Match($register, "(?ms)^\.$($ruleContract.Selector)\s*\{(?<Body>.*?)^\}")
if (-not $rule.Success) { throw "A04 style rule is missing: $($ruleContract.Selector)" }
Assert-Contains -Content $rule.Groups['Body'].Value -Expected $ruleContract.Expected -Message "A04 typography must match A01: $($ruleContract.Selector) $($ruleContract.Expected)"
}
foreach ($forbidden in @(
'(?s)\.register-panel\s*\{[^}]*\bborder\s*:',
'(?s)\.register-panel\s*\{[^}]*\bbackground\s*:',
'(?s)\.register-submit\s*\{[^}]*\bborder\s*:',
'(?s)\.register-submit\s*\{[^}]*\bbackground\s*:',
'\.agreement-icon::(?:before|after)'
)) {
if ($register -match $forbidden) { throw "A-04 retains forbidden CSS visual construction: $forbidden" }
}
Write-Output 'A04-REGISTRATION-CONTRACT PASS'