(timeout = STEP9_SUCCESS_BADGE_TIMEOUT_MS)
| 453 | } |
| 454 | |
| 455 | async function waitForExactSuccessBadge(timeout = STEP9_SUCCESS_BADGE_TIMEOUT_MS) { |
| 456 | const start = Date.now(); |
| 457 | let lastDiagnosticsSignature = ''; |
| 458 | let lastHeartbeatLoggedAt = 0; |
| 459 | let lastSuccessLikeMismatchSignature = ''; |
| 460 | let lastSuccessFailureConflictSignature = ''; |
| 461 | |
| 462 | while (Date.now() - start < timeout) { |
| 463 | throwIfStopped(); |
| 464 | const diagnostics = getStatusBadgeDiagnostics(); |
| 465 | const elapsed = Date.now() - start; |
| 466 | |
| 467 | if (diagnostics.signature !== lastDiagnosticsSignature) { |
| 468 | lastDiagnosticsSignature = diagnostics.signature; |
| 469 | lastHeartbeatLoggedAt = elapsed; |
| 470 | log(`步骤 9:认证状态检测中,${diagnostics.summary}`); |
| 471 | console.log(LOG_PREFIX, '[Step 9] status badge diagnostics changed', diagnostics); |
| 472 | } else if (elapsed - lastHeartbeatLoggedAt >= 10000) { |
| 473 | lastHeartbeatLoggedAt = elapsed; |
| 474 | log(`步骤 9:仍在等待认证成功,${diagnostics.summary}`); |
| 475 | console.log(LOG_PREFIX, '[Step 9] still waiting for success badge', diagnostics); |
| 476 | } |
| 477 | |
| 478 | if (diagnostics.hasSuccessLikeVisibleBadge && !diagnostics.hasExactSuccessVisibleBadge) { |
| 479 | const mismatchSignature = JSON.stringify({ |
| 480 | selectedText: diagnostics.selectedText, |
| 481 | successLikeSummary: diagnostics.successLikeSummary, |
| 482 | visibleSummary: diagnostics.visibleSummary, |
| 483 | errorStyledSummary: diagnostics.errorStyledSummary, |
| 484 | }); |
| 485 | if (mismatchSignature !== lastSuccessLikeMismatchSignature) { |
| 486 | lastSuccessLikeMismatchSignature = mismatchSignature; |
| 487 | const errorStyledSuffix = diagnostics.hasErrorStyledVisibleBadge |
| 488 | ? `;错误样式徽标:${diagnostics.errorStyledSummary}` |
| 489 | : ''; |
| 490 | log( |
| 491 | `步骤 9:检测到“认证成功”相关徽标,但未命中精确成功条件。当前聚焦="${getInlineTextSnippet(diagnostics.selectedText || '(空)', 80)}";成功相关徽标:${diagnostics.successLikeSummary}${errorStyledSuffix}`, |
| 492 | 'warn' |
| 493 | ); |
| 494 | console.warn(LOG_PREFIX, '[Step 9] success-like badge detected without exact match', diagnostics); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | if (diagnostics.hasExactSuccessVisibleBadge && diagnostics.hasFailureVisibleBadge) { |
| 499 | const conflictSignature = JSON.stringify({ |
| 500 | exactSuccessSummary: diagnostics.exactSuccessSummary, |
| 501 | failureSummary: diagnostics.failureSummary, |
| 502 | pageErrorSummary: diagnostics.pageErrorSummary, |
| 503 | }); |
| 504 | if (conflictSignature !== lastSuccessFailureConflictSignature) { |
| 505 | lastSuccessFailureConflictSignature = conflictSignature; |
| 506 | const failureSummary = diagnostics.pageErrorSummary !== '无可见状态徽标' |
| 507 | ? diagnostics.pageErrorSummary |
| 508 | : diagnostics.failureSummary; |
| 509 | log( |
| 510 | `步骤 9:同时检测到成功徽标和失败提示,本轮不判定成功。成功徽标:${diagnostics.exactSuccessSummary};失败提示:${failureSummary}`, |
| 511 | 'warn' |
| 512 | ); |
no test coverage detected