refactor(qa): share progress formatting helpers

This commit is contained in:
Vincent Koc
2026-06-20 08:12:44 +08:00
parent 87358d7a7c
commit 208bed06e1
3 changed files with 35 additions and 56 deletions
@@ -18,6 +18,10 @@ import {
} from "../../evidence-summary.js";
import { startQaGatewayChild } from "../../gateway-child.js";
import { isTruthyOptIn } from "../../mantis-options.runtime.js";
import {
parseQaProgressBooleanEnv as parseTelegramQaProgressBooleanEnv,
sanitizeQaProgressValue as sanitizeTelegramQaProgressValue,
} from "../../progress-format.js";
import { DEFAULT_QA_LIVE_PROVIDER_MODE } from "../../providers/index.js";
import {
defaultQaModelForMode,
@@ -574,20 +578,6 @@ function readConfigRecord(root: Record<string, unknown>, key: string): Record<st
return value;
}
function parseTelegramQaProgressBooleanEnv(value: string | undefined): boolean | undefined {
const normalized = value?.trim().toLowerCase();
if (!normalized) {
return undefined;
}
if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
return true;
}
if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
return false;
}
return undefined;
}
function shouldLogTelegramQaLiveProgress(env: NodeJS.ProcessEnv = process.env) {
const override = parseTelegramQaProgressBooleanEnv(env[QA_SUITE_PROGRESS_ENV]);
if (override !== undefined) {
@@ -680,20 +670,6 @@ function writeTelegramQaProgress(enabled: boolean, message: string) {
process.stderr.write(`${TELEGRAM_QA_PROGRESS_PREFIX} ${message}\n`);
}
function sanitizeTelegramQaProgressValue(value: string): string {
let normalized = "";
for (const char of value) {
const code = char.codePointAt(0);
if (code === undefined) {
continue;
}
const isControl = code <= 0x1f || (code >= 0x7f && code <= 0x9f);
normalized += isControl ? " " : char;
}
normalized = normalized.replace(/\s+/gu, " ").trim();
return normalized.length > 0 ? normalized : "<empty>";
}
function formatTelegramQaProgressDetails(details: string): string {
const sanitized = sanitizeTelegramQaProgressValue(details);
if (sanitized.length <= TELEGRAM_QA_PROGRESS_DETAIL_LIMIT) {
+27
View File
@@ -0,0 +1,27 @@
export function parseQaProgressBooleanEnv(value: string | undefined): boolean | undefined {
const normalized = value?.trim().toLowerCase();
if (!normalized) {
return undefined;
}
if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
return true;
}
if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
return false;
}
return undefined;
}
export function sanitizeQaProgressValue(value: string): string {
let normalized = "";
for (const char of value) {
const code = char.codePointAt(0);
if (code === undefined) {
continue;
}
const isControl = code <= 0x1f || (code >= 0x7f && code <= 0x9f);
normalized += isControl ? " " : char;
}
normalized = normalized.replace(/\s+/gu, " ").trim();
return normalized.length > 0 ? normalized : "<empty>";
}
+4 -28
View File
@@ -27,6 +27,10 @@ import {
normalizeQaProviderMode,
type QaProviderMode,
} from "./model-selection.js";
import {
parseQaProgressBooleanEnv as parseQaSuiteBooleanEnv,
sanitizeQaProgressValue as sanitizeQaSuiteProgressValue,
} from "./progress-format.js";
import { DEFAULT_QA_LIVE_PROVIDER_MODE } from "./providers/index.js";
import { startQaProviderServer } from "./providers/server-runtime.js";
import type { QaThinkingLevel } from "./qa-gateway-config.js";
@@ -124,20 +128,6 @@ export type QaSuiteRunParams = {
captureRuntimeParityCell?: boolean;
};
function parseQaSuiteBooleanEnv(value: string | undefined): boolean | undefined {
const normalized = value?.trim().toLowerCase();
if (!normalized) {
return undefined;
}
if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
return true;
}
if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
return false;
}
return undefined;
}
function shouldLogQaSuiteProgress(env: NodeJS.ProcessEnv = process.env) {
const override = parseQaSuiteBooleanEnv(env.OPENCLAW_QA_SUITE_PROGRESS);
if (override !== undefined) {
@@ -214,20 +204,6 @@ async function waitForQaLabReadyOrStopOwned(params: {
}
}
function sanitizeQaSuiteProgressValue(value: string): string {
let normalized = "";
for (const char of value) {
const code = char.codePointAt(0);
if (code === undefined) {
continue;
}
const isControl = code <= 0x1f || (code >= 0x7f && code <= 0x9f);
normalized += isControl ? " " : char;
}
normalized = normalized.replace(/\s+/gu, " ").trim();
return normalized.length > 0 ? normalized : "<empty>";
}
function requireQaSuiteStartLab(startLab: QaSuiteStartLabFn | undefined): QaSuiteStartLabFn {
if (startLab) {
return startLab;