fix: 固化 Workbench Trace 可读性探针

This commit is contained in:
Codex
2026-07-10 18:00:24 +02:00
parent 92686ff213
commit b6f5e5efd4
21 changed files with 1378 additions and 16 deletions
+92 -9
View File
@@ -38,9 +38,9 @@ function renderWebObserveStatusTable(value: Record<string, unknown>): string {
const diagnostics = record(observer?.diagnostics) ?? record(value.diagnostics);
const commands = record(observer?.commands);
const exactCommand = record(observer?.exactCommand);
const exactResult = record(exactCommand?.result);
const exactResult = nullableRecord(exactCommand?.result);
const exactError = record(exactCommand?.error);
const exactErrorDetails = record(exactError?.details);
const exactErrorDetails = nullableRecord(exactError?.details);
const exactReplayEvidence = exactResult ?? exactErrorDetails;
const tails = record(observer?.tails);
const result = record(value.result);
@@ -170,9 +170,9 @@ function renderWebObserveStatusTable(value: Record<string, unknown>): string {
exactCommand.type,
exactCommand.phase,
exactCommand.ok,
exactResult.status,
webObserveShort(webObserveText(exactResult.reportSha256 ?? exactErrorDetails.reportSha256), 32),
webObserveShort(webObserveText(exactError.message ?? exactResult.reportPath ?? exactErrorDetails.reportPath), 96),
exactResult?.status,
webObserveShort(webObserveText(exactResult?.reportSha256 ?? exactErrorDetails?.reportSha256), 32),
webObserveShort(webObserveText(exactError.message ?? exactResult?.reportPath ?? exactErrorDetails?.reportPath), 96),
]]),
"",
] : []),
@@ -180,7 +180,15 @@ function renderWebObserveStatusTable(value: Record<string, unknown>): string {
...renderWorkbenchKafkaDebugReplayEvidence(
exactReplayEvidence,
exactResult?.reportSha256 ?? exactErrorDetails?.reportSha256,
record(exactResult?.screenshot)?.sha256,
record(exactResult?.screenshot ?? exactErrorDetails?.screenshot)?.sha256,
),
"",
] : []),
...(exactCommand.type === "validateWorkbenchTraceReadability" && exactReplayEvidence !== null ? [
...renderWorkbenchTraceReadabilityEvidence(
exactReplayEvidence,
exactResult?.reportSha256 ?? exactErrorDetails?.reportSha256,
record(exactResult?.screenshot ?? exactErrorDetails?.screenshot)?.sha256,
),
"",
] : []),
@@ -239,6 +247,8 @@ function renderWorkbenchKafkaDebugReplayEvidence(
const trace = record(evidence.traceTimeline);
const raw = record(evidence.rawHwlabEventWindow);
const rawCounts = record(raw?.counts);
const layerDom = record(evidence.layerDom);
const layerStable = record(evidence.layerDomStabilization);
return [
"Workbench Kafka debug replay:",
webObserveTable(["TRACE", "TOPIC", "GROUP", "PHASE", "CODE", "RECEIVED", "APPLIED", "TERMINAL", "REPORT_SHA", "SCREENSHOT_SHA"], [[
@@ -262,6 +272,18 @@ function renderWorkbenchKafkaDebugReplayEvidence(
client?.decoded,
client?.applied,
]]),
"分层 DOM 诊断:",
webObserveTable(["MATCH", "VISIBLE", "CONNECTED", "TEXT_BYTES", "TEXT_HASH", "STABLE", "TIMED_OUT", "SAMPLES", "ELAPSED_MS"], [[
layerDom?.matchCount,
layerDom?.visibleCount,
layerDom?.connectedCount,
layerDom?.textBytes,
webObserveShort(webObserveText(layerDom?.textHash), 32),
layerStable?.stable,
layerStable?.timedOut,
layerStable?.sampleCount,
layerStable?.elapsedMs,
]]),
"Trace and raw HWLAB Event:",
webObserveTable(["AUTHORITY", "SOURCE_ROWS", "READABLE_ROWS", "RAW_AVAILABLE", "SAME_PAGE", "UNFILTERED", "RAW_RECEIVED", "RAW_RETAINED", "RAW_REJECTED", "RAW_EVICTED", "RAW_BYTES", "EXTRA_PRODUCT_SSE"], [[
trace?.contract,
@@ -280,16 +302,69 @@ function renderWorkbenchKafkaDebugReplayEvidence(
];
}
function renderWorkbenchTraceReadabilityEvidence(
evidence: Record<string, unknown>,
reportSha: unknown,
screenshotSha: unknown,
): string[] {
const scope = record(evidence.scope);
const disclosure = record(evidence.disclosure);
const running = record(evidence.running);
const runningSnapshot = record(running?.snapshot);
const terminal = record(evidence.terminal);
const terminalSnapshot = record(terminal?.snapshot);
const retention = record(evidence.runningRetention);
const failures = Array.isArray(evidence.failures)
? evidence.failures.map(record).filter((item): item is Record<string, unknown> => item !== null)
: [];
return [
"Workbench 产品 Trace 可读性:",
webObserveTable(["TRACE", "STARTED_RUNNING", "RUNNING_OBSERVED", "AUTO_READABLE", "OPEN_BEFORE", "FORCED", "OPEN_TERMINAL", "RETENTION_MODE", "RETENTION_OK", "RETAINED", "REPORT_SHA", "SCREENSHOT_SHA"], [[
webObserveShort(webObserveText(evidence.traceId), 28),
evidence.startedDuringRunning,
running?.observed,
disclosure?.autoReadable,
disclosure?.openBefore,
evidence.forcedExpansion,
disclosure?.openAfterTerminal,
retention?.mode,
retention?.passed,
evidence.retainedRunningRowCount,
webObserveShort(webObserveText(reportSha), 32),
webObserveShort(webObserveText(screenshotSha), 32),
]]),
"产品 Trace DOM",
webObserveTable(["CONVERSATION", "PRODUCT_CARDS", "DEBUG_IN_SCOPE", "RUN_STATUS", "RUN_ROWS", "RUN_SOURCE", "TERM_STATUS", "TERM_ROWS", "TERM_SOURCE", "TERM_PROJECTED", "TERM_STABLE"], [[
scope?.conversationCount,
scope?.productCardCount,
scope?.debugPanelCountInsideConversation,
runningSnapshot?.status,
runningSnapshot?.rowCount,
runningSnapshot?.sourceAuthorityRowCount,
terminalSnapshot?.status,
terminalSnapshot?.rowCount,
terminalSnapshot?.sourceAuthorityRowCount,
terminalSnapshot?.projectedAuthorityRowCount,
terminal?.stable,
]]),
"失败项:",
failures.length > 0
? failures.map((failure) => webObserveText(failure.code)).join(",")
: "-",
];
}
function renderWebObserveCommandTable(value: Record<string, unknown>): string {
const observerCommand = record(value.observerCommand);
const observer = record(value.observer);
const control = record(value.control);
const asyncTurn = record(value.asyncTurn);
const result = record(observer?.result);
const result = nullableRecord(observer?.result);
const resultScreenshot = record(result?.screenshot);
const error = record(observer?.error);
const details = record(error?.details);
const details = nullableRecord(error?.details);
const replayEvidence = result ?? details;
const replayScreenshot = record(result?.screenshot ?? details?.screenshot);
const rawReadiness = record(error?.navigationReadiness) ?? record(details?.readiness) ?? record(details?.readinessAfterWait) ?? record(details?.readinessBeforeClick);
const readiness = record(rawReadiness?.snapshot) ?? rawReadiness;
const id = webObserveText(value.id);
@@ -313,7 +388,15 @@ function renderWebObserveCommandTable(value: Record<string, unknown>): string {
...renderWorkbenchKafkaDebugReplayEvidence(
replayEvidence,
result?.reportSha256 ?? details?.reportSha256,
resultScreenshot?.sha256,
replayScreenshot?.sha256 ?? resultScreenshot?.sha256,
),
] : []),
...(observerCommand?.type === "validateWorkbenchTraceReadability" && replayEvidence !== null ? [
"",
...renderWorkbenchTraceReadabilityEvidence(
replayEvidence,
result?.reportSha256 ?? details?.reportSha256,
replayScreenshot?.sha256 ?? resultScreenshot?.sha256,
),
] : []),
...(readiness !== null ? [