Merge pull request #536 from pikasTech/fix/1770-web-probe-script-bounded-report

fix(web-probe): bound script report summaries
This commit is contained in:
Lyon
2026-06-21 07:51:44 +08:00
committed by GitHub
2 changed files with 56 additions and 6 deletions
+51 -1
View File
@@ -7064,7 +7064,57 @@ function readNodeWebProbeScriptReport(
): { source: string; report: Record<string, unknown> | null; result: CommandResult | null; degradedReason: string | null; path: string | null } | null {
if (!reportPath) return null;
if (!isSafeWebProbeScriptReportPath(reportPath)) return { source: "unsafe-path", report: null, result: null, degradedReason: "web-probe-report-path-invalid", path: reportPath };
const result = runTransWorkspaceStdinScript(options.node, spec.workspace, `test -f ${shellQuote(reportPath)} && cat ${shellQuote(reportPath)}`, 55);
const script = [
"set -eu",
`test -f ${shellQuote(reportPath)}`,
`node - ${shellQuote(reportPath)} <<'NODE'`,
"const fs = require('fs');",
"const reportPath = process.argv[2];",
"const report = JSON.parse(fs.readFileSync(reportPath, 'utf8'));",
"function rec(value) { return value && typeof value === 'object' && !Array.isArray(value) ? value : {}; }",
"function compact(value, depth = 0) {",
" if (value === null || value === undefined) return value ?? null;",
" if (typeof value === 'string') return value.replace(/\\s+/gu, ' ').trim().slice(0, 240);",
" if (typeof value === 'number' || typeof value === 'boolean') return value;",
" if (depth >= 4) return '[max-depth]';",
" if (Array.isArray(value)) return value.slice(0, 6).map((item) => compact(item, depth + 1));",
" if (typeof value === 'object') {",
" const out = {};",
" for (const [key, nested] of Object.entries(value).slice(0, 12)) out[key] = compact(nested, depth + 1);",
" return out;",
" }",
" return String(value).slice(0, 240);",
"}",
"const scriptBlock = rec(report.script);",
"const compactReport = {",
" ok: report.ok === true,",
" status: typeof report.status === 'string' ? report.status : null,",
" summary: compact(report.summary),",
" issueEvidence: compact(report.issueEvidence ?? rec(report.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,",
" scriptSha256: typeof report.scriptSha256 === 'string' ? report.scriptSha256 : null,",
" runDir: typeof report.runDir === 'string' ? report.runDir : null,",
" reportPath: typeof report.reportPath === 'string' ? report.reportPath : reportPath,",
" reportSha256: typeof report.reportSha256 === 'string' ? report.reportSha256 : null,",
" auth: compact(report.auth),",
" script: { ok: scriptBlock.ok === true, result: compact(scriptBlock.result), stepCount: Array.isArray(scriptBlock.steps) ? scriptBlock.steps.length : null },",
" steps: Array.isArray(report.steps) ? report.steps.slice(-5).map((item) => compact(item)) : [],",
" failureKind: typeof report.failureKind === 'string' ? report.failureKind : null,",
" guidance: typeof report.guidance === 'string' ? report.guidance : null,",
" lastScreenshot: compact(report.lastScreenshot),",
" readiness: compact(report.readiness),",
" artifacts: compact(report.artifacts),",
" error: typeof report.error === 'string' ? report.error : null,",
" errorMessage: typeof report.errorMessage === 'string' ? report.errorMessage : null,",
" safety: compact(report.safety),",
" valuesRedacted: true,",
"};",
"console.log(JSON.stringify(compactReport));",
"NODE",
].join("\n");
const result = runTransWorkspaceStdinScript(options.node, spec.workspace, script, 55);
if (result.exitCode !== 0 || result.timedOut) {
return { source: "report-file", report: null, result, degradedReason: result.timedOut ? "web-probe-command-timeout" : "web-probe-report-read-failed", path: reportPath };
}
@@ -2095,20 +2095,20 @@ function compactStepForEvidence(step) {
function compactJsonForEvidence(value, depth = 0) {
if (value === null || value === undefined) return value ?? null;
if (typeof value === "string") return compactText(value, 600);
if (typeof value === "string") return compactText(value, 240);
if (typeof value === "number" || typeof value === "boolean") return value;
if (typeof value === "bigint") return String(value);
if (typeof value === "function" || typeof value === "symbol") return "[" + typeof value + "]";
if (depth >= 8) return "[max-depth]";
if (Array.isArray(value)) return value.slice(0, 16).map((item) => compactJsonForEvidence(item, depth + 1));
if (depth >= 4) return "[max-depth]";
if (Array.isArray(value)) return value.slice(0, 6).map((item) => compactJsonForEvidence(item, depth + 1));
if (typeof value === "object") {
const out = {};
for (const [key, nested] of Object.entries(value).slice(0, 32)) {
for (const [key, nested] of Object.entries(value).slice(0, 12)) {
out[key] = compactJsonForEvidence(nested, depth + 1);
}
return out;
}
return compactText(String(value), 600);
return compactText(String(value), 240);
}
function compactText(value, maxChars) {