fix: improve hwlab probe diagnostics

This commit is contained in:
Codex
2026-06-20 03:59:48 +00:00
parent 7696fddccf
commit 6a88f38ca9
6 changed files with 317 additions and 5 deletions
+85 -1
View File
@@ -12,10 +12,12 @@ function nullableRecord(value: unknown): Record<string, unknown> | null {
export function compactWebProbeScriptResult(report: Record<string, unknown> | null): Record<string, unknown> | null {
if (report === null) return null;
const summary = compactIssueSummary(record(report.summary));
const issueEvidence = compactIssueEvidence(report.issueEvidence ?? summary.issueEvidence ?? fallbackIssueEvidence(report, summary));
return {
ok: report.ok === true,
status: typeof report.status === "string" ? report.status : null,
summary,
issueEvidence,
baseUrl: typeof report.baseUrl === "string" ? report.baseUrl : null,
finalUrl: typeof report.finalUrl === "string" ? report.finalUrl : null,
lastUrl: typeof report.lastUrl === "string" ? report.lastUrl : null,
@@ -41,7 +43,7 @@ function compactWebProbeScriptBlock(value: unknown): Record<string, unknown> {
const script = record(value);
return {
ok: script.ok === true,
result: compactJsonForIssue(script.result),
result: compactJsonForEvidence(script.result),
stepCount: Array.isArray(script.steps) ? script.steps.length : null,
};
}
@@ -80,6 +82,7 @@ function compactIssueSummary(value: Record<string, unknown>): Record<string, unk
apiMatrix: compactApiMatrixSummary(value.apiMatrix),
stepCount: typeof value.stepCount === "number" ? value.stepCount : null,
lastStep: compactStepForIssue(value.lastStep),
issueEvidence: compactIssueEvidence(value.issueEvidence),
valuesRedacted: value.valuesRedacted === true,
};
}
@@ -100,6 +103,87 @@ function compactJsonForIssue(value: unknown, depth = 0): unknown {
return String(value).slice(0, 240);
}
function fallbackIssueEvidence(report: Record<string, unknown>, summary: Record<string, unknown>): Record<string, unknown> {
const script = record(report.script);
return {
ok: report.ok === true,
status: typeof report.status === "string" ? report.status : summary.status ?? null,
degradedReason: summary.degradedReason ?? null,
failureKind: summary.failureKind ?? (typeof report.failureKind === "string" ? report.failureKind : null),
failedCondition: summary.failedCondition ?? (typeof report.errorMessage === "string" ? report.errorMessage : null),
nextAction: summary.nextAction ?? null,
baseUrl: typeof report.baseUrl === "string" ? report.baseUrl : null,
finalUrl: typeof report.finalUrl === "string" ? report.finalUrl : summary.finalUrl ?? null,
lastUrl: typeof report.lastUrl === "string" ? report.lastUrl : summary.lastUrl ?? null,
scriptSha256: typeof report.scriptSha256 === "string" ? report.scriptSha256 : summary.scriptSha256 ?? null,
runDir: typeof report.runDir === "string" ? report.runDir : summary.runDir ?? null,
reportPath: typeof report.reportPath === "string" ? report.reportPath : summary.reportPath ?? null,
reportSha256: typeof report.reportSha256 === "string" ? report.reportSha256 : summary.reportSha256 ?? null,
result: script.result,
apiMatrix: summary.apiMatrix ?? null,
lastStep: summary.lastStep ?? null,
steps: Array.isArray(report.steps) ? report.steps.slice(-3) : [],
lastScreenshot: report.lastScreenshot ?? summary.lastScreenshot ?? null,
screenshots: summary.screenshots ?? [],
valuesRedacted: true,
};
}
function compactIssueEvidence(value: unknown): Record<string, unknown> | null {
const evidence = nullableRecord(value);
if (evidence === null) return null;
return {
ok: evidence.ok === true,
status: typeof evidence.status === "string" ? evidence.status : null,
degradedReason: typeof evidence.degradedReason === "string" ? evidence.degradedReason : null,
failureKind: typeof evidence.failureKind === "string" ? evidence.failureKind : null,
failedCondition: typeof evidence.failedCondition === "string" ? evidence.failedCondition : null,
nextAction: typeof evidence.nextAction === "string" ? evidence.nextAction : null,
baseUrl: typeof evidence.baseUrl === "string" ? evidence.baseUrl : null,
finalUrl: typeof evidence.finalUrl === "string" ? evidence.finalUrl : null,
lastUrl: typeof evidence.lastUrl === "string" ? evidence.lastUrl : null,
scriptSha256: typeof evidence.scriptSha256 === "string" ? evidence.scriptSha256 : null,
runDir: typeof evidence.runDir === "string" ? evidence.runDir : null,
reportPath: typeof evidence.reportPath === "string" ? evidence.reportPath : null,
reportSha256: typeof evidence.reportSha256 === "string" ? evidence.reportSha256 : null,
result: compactJsonForEvidence(evidence.result),
apiMatrix: compactApiMatrixSummary(evidence.apiMatrix),
lastStep: compactStepForEvidence(evidence.lastStep),
steps: Array.isArray(evidence.steps) ? evidence.steps.slice(-3).map(compactStepForEvidence).filter((item): item is Record<string, unknown> => item !== null) : [],
lastScreenshot: nullableRecord(evidence.lastScreenshot),
screenshots: Array.isArray(evidence.screenshots) ? evidence.screenshots.slice(-5).map(nullableRecord).filter((item): item is Record<string, unknown> => item !== null) : [],
valuesRedacted: evidence.valuesRedacted === true,
};
}
function compactStepForEvidence(value: unknown): Record<string, unknown> | null {
const step = nullableRecord(value);
if (step === null) return null;
return {
index: typeof step.index === "number" ? step.index : null,
name: typeof step.name === "string" ? step.name : null,
ok: typeof step.ok === "boolean" ? step.ok : null,
atMs: typeof step.atMs === "number" ? step.atMs : null,
data: compactJsonForEvidence(step.data),
};
}
function compactJsonForEvidence(value: unknown, depth = 0): unknown {
if (value === null || value === undefined) return value ?? null;
if (typeof value === "string") return value.replace(/\s+/gu, " ").trim().slice(0, 600);
if (typeof value === "number" || typeof value === "boolean") return value;
if (depth >= 8) return "[max-depth]";
if (Array.isArray(value)) return value.slice(0, 16).map((item) => compactJsonForEvidence(item, depth + 1));
if (typeof value === "object") {
const out: Record<string, unknown> = {};
for (const [key, nested] of Object.entries(value as Record<string, unknown>).slice(0, 32)) {
out[key] = compactJsonForEvidence(nested, depth + 1);
}
return out;
}
return String(value).slice(0, 600);
}
function compactStepForIssue(value: unknown): Record<string, unknown> | null {
const step = nullableRecord(value);
if (step === null) return null;