From be9b6dce23f52128119f6aa8071aa224207ec2ab Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Wed, 24 Jun 2026 04:23:53 +0800 Subject: [PATCH] fix(web-probe): expose observe analyze tail samples (#778) Co-authored-by: Codex --- scripts/src/hwlab-node-impl.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/src/hwlab-node-impl.ts b/scripts/src/hwlab-node-impl.ts index fed82a1c..55f54d7c 100644 --- a/scripts/src/hwlab-node-impl.ts +++ b/scripts/src/hwlab-node-impl.ts @@ -85,6 +85,7 @@ interface NodeWebProbeObserveOptions { collectFinding: string | null; collectGrep: string | null; analyzeArchivePrefix: string | null; + analyzeTailSamples: number | null; full: boolean; stateDir: string | null; jobId: string | null; @@ -7273,6 +7274,7 @@ function parseNodeWebProbeObserveOptions( "--finding", "--grep", "--archive-prefix", + "--tail-samples", "--state-dir", "--job-id", "--type", @@ -7296,6 +7298,11 @@ function parseNodeWebProbeObserveOptions( if (collectGrep !== null && (collectGrep.includes("\0") || collectGrep.length > 200)) throw new Error("unsafe web-probe observe --grep: expected 1-200 non-NUL chars"); const analyzeArchivePrefix = optionValue(args, "--archive-prefix") ?? null; if (analyzeArchivePrefix !== null && !isSafeWebObserveArchivePrefix(analyzeArchivePrefix)) throw new Error(`unsafe web-probe observe --archive-prefix: ${analyzeArchivePrefix}`); + const analyzeTailSamplesRaw = optionValue(args, "--tail-samples") ?? null; + const analyzeTailSamples = analyzeTailSamplesRaw === null ? null : Number(analyzeTailSamplesRaw); + if (analyzeTailSamples !== null && (!Number.isInteger(analyzeTailSamples) || analyzeTailSamples < 0)) { + throw new Error("unsafe web-probe observe --tail-samples: expected a non-negative integer; use 0 for all samples"); + } if (observeActionRaw !== "start" && stateDir === null && jobId === null) { throw new Error("web-probe observe status|command|stop|collect|analyze requires --state-dir or --job-id"); } @@ -7330,6 +7337,7 @@ function parseNodeWebProbeObserveOptions( collectFinding, collectGrep, analyzeArchivePrefix, + analyzeTailSamples, full: args.includes("--full"), stateDir, jobId, @@ -8506,8 +8514,9 @@ function runNodeWebProbeObserveAnalyze(options: NodeWebProbeObserveOptions, spec "analysis_stderr=\"$state_dir/analysis/analyzer-stderr.log\"", "set +e", `UNIDESK_WEB_OBSERVE_ANALYZE_ARCHIVE_PREFIX=${shellQuote(options.analyzeArchivePrefix ?? "")}`, + `UNIDESK_WEB_OBSERVE_ANALYZE_TAIL_SAMPLES=${shellQuote(options.analyzeTailSamples === null ? "" : String(options.analyzeTailSamples))}`, `UNIDESK_WEB_OBSERVE_ALERT_THRESHOLDS_JSON=${shellQuote(JSON.stringify(alertThresholds))}`, - "UNIDESK_WEB_OBSERVE_STATE_DIR=\"$state_dir\" UNIDESK_WEB_OBSERVE_ANALYZE_ARCHIVE_PREFIX=\"$UNIDESK_WEB_OBSERVE_ANALYZE_ARCHIVE_PREFIX\" UNIDESK_WEB_OBSERVE_ALERT_THRESHOLDS_JSON=\"$UNIDESK_WEB_OBSERVE_ALERT_THRESHOLDS_JSON\" node \"$analyzer\" >\"$analysis_stdout\" 2>\"$analysis_stderr\"", + "UNIDESK_WEB_OBSERVE_STATE_DIR=\"$state_dir\" UNIDESK_WEB_OBSERVE_ANALYZE_ARCHIVE_PREFIX=\"$UNIDESK_WEB_OBSERVE_ANALYZE_ARCHIVE_PREFIX\" UNIDESK_WEB_OBSERVE_ANALYZE_TAIL_SAMPLES=\"$UNIDESK_WEB_OBSERVE_ANALYZE_TAIL_SAMPLES\" UNIDESK_WEB_OBSERVE_ALERT_THRESHOLDS_JSON=\"$UNIDESK_WEB_OBSERVE_ALERT_THRESHOLDS_JSON\" node \"$analyzer\" >\"$analysis_stdout\" 2>\"$analysis_stderr\"", "analyzer_exit=$?", "set -e", "report_json=\"$state_dir/analysis/report.json\"",