<# .SYNOPSIS OA Pattern B 端到端 - Windows Terminal 兼容版 .DESCRIPTION v0.27.0 auth login OA 失败 (form 识别失败) → 走 fallback 路径 流程: 1. 验证 vault 'oa' 存在 2. 重启 daemon (--args --no-sandbox) 3. Read-Host 收 username + password (Windows Terminal 调用) 4. fill + click submit 5. 等待跳转到非 /login 页 6. state save 7. 清理敏感变量 .NOTES Author: Duckula Date : 2026-07-29 (v3) Run in: Windows Terminal (NOT in agent-browser PowerShell tool) #> $ErrorActionPreference = 'Continue' Write-Host "============================================" -ForegroundColor Cyan Write-Host " OA Pattern B 端到端 - fallback manual" -ForegroundColor Cyan Write-Host "============================================" -ForegroundColor Cyan # 1. Vault 验证 Write-Host "" Write-Host "Step 1: vault list" -ForegroundColor Yellow agent-browser auth list 2>&1 | Out-Null # 2. 清理 daemon + 启动 Write-Host "" Write-Host "Step 2: restart daemon (--args --no-sandbox)" -ForegroundColor Yellow agent-browser close --all 2>&1 | Out-Null for ($i = 1; $i -le 5; $i++) { $procs = Get-Process | Where-Object { $_.Name -match '^(chrome|agent-browser-win32-x64)$' } if ($procs.Count -eq 0) { break } foreach ($p in $procs) { try { & taskkill /F /PID $p.Id /T 2>&1 | Out-Null } catch {} } Start-Sleep 2 } $sw = [System.Diagnostics.Stopwatch]::StartNew() agent-browser --args --no-sandbox open "https://oa.servyou-it.com/" 2>&1 | Out-Null $sw.Stop() Write-Host " [open] $($sw.ElapsedMilliseconds) ms" -ForegroundColor Gray Start-Sleep 5 # 3. Read-Host 收凭据 Write-Host "" Write-Host "Step 3: receiver credentials (in your Windows Terminal)" -ForegroundColor Yellow Write-Host "" $username = Read-Host " OA Username (工号)" Write-Host "" $securePwd = Read-Host " OA Password" -AsSecureString if ($null -eq $securePwd) { Write-Host " ❌ Password empty" -ForegroundColor Red exit 1 } $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePwd) $password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR) if ([string]::IsNullOrWhiteSpace($username) -or [string]::IsNullOrWhiteSpace($password)) { Write-Host " ❌ Empty credentials" -ForegroundColor Red exit 1 } Write-Host " ✅ Got credentials" -ForegroundColor Green Write-Host " Username: $username" -ForegroundColor Gray Write-Host " Password: *** (length=$(($password.Length)))" -ForegroundColor Gray # 4. Fill + Submit Write-Host "" Write-Host "Step 4: fill + submit" -ForegroundColor Yellow agent-browser --args --no-sandbox fill "input#loginid" $username 2>&1 | Out-Null agent-browser --args --no-sandbox fill "input#userpassword" $password 2>&1 | Out-Null agent-browser --args --no-sandbox click "button#submit" 2>&1 | Out-Null Write-Host " ✅ submitted" -ForegroundColor Green # 5. 等待跳转 Write-Host "" Write-Host "Step 5: wait 30s (URL not on /login)" -ForegroundColor Yellow $ok = $false for ($i = 1; $i -le 10; $i++) { Start-Sleep 3 $url = (agent-browser --args --no-sandbox get url 2>&1 | Out-String).Trim() $iTag = "{0:D2}" -f $i Write-Host " [$iTag] URL: $url" -ForegroundColor Gray if ($url -notlike "*/login*" -and $url -notlike "*logintype=1*" -and $url -notlike "*Loginx.aspx*") { $ok = $true break } } if (-not $ok) { Write-Host " ⚠️ URL still on login page" -ForegroundColor Yellow Write-Host " (credentials might be wrong, or extra verification needed)" -ForegroundColor Yellow } # 6. state save Write-Host "" Write-Host "Step 6: state save" -ForegroundColor Yellow $stateFile = "D:\资料\03-项目开发\wecom_it_smart_desk\.workbuddy\outputs\oa-auth-state.json" agent-browser --args --no-sandbox state save $stateFile 2>&1 | Out-Null if (Test-Path $stateFile) { $len = (Get-Item $stateFile).Length Write-Host " ✅ saved $stateFile ($len bytes)" -ForegroundColor Green } else { Write-Host " ⚠️ state save failed" -ForegroundColor Yellow } # 7. Screenshot Write-Host "" Write-Host "Step 7: screenshot" -ForegroundColor Yellow $screenshotPath = "D:\资料\03-项目开发\wecom_it_smart_desk\.workbuddy\outputs\oa-after-login.png" agent-browser --args --no-sandbox screenshot $screenshotPath 2>&1 | Out-Null if (Test-Path $screenshotPath) { Write-Host " ✅ $screenshotPath" -ForegroundColor Green } # 8. 清理敏感变量 $username = $null $password = $null [System.GC]::Collect() Write-Host "" Write-Host "============================================" -ForegroundColor Green Write-Host " ✅ Pattern B fallback 完成" -ForegroundColor Green Write-Host "============================================" -ForegroundColor Green Write-Host "" Write-Host "后续验证:" -ForegroundColor Cyan Write-Host " state file: $stateFile" -ForegroundColor Gray Write-Host " screenshot: $screenshotPath" -ForegroundColor Gray Write-Host ""