|
1 | | -import fs from "node:fs"; |
2 | | -import fsp from "node:fs/promises"; |
3 | 1 | import { createServer } from "node:net"; |
4 | | -import path from "node:path"; |
5 | 2 | // QA runtime helpers register and execute plugin QA scenarios from local files. |
6 | | -import { toErrorObject } from "@openclaw/normalization-core/error-coercion"; |
7 | | -import { formatErrorMessage } from "./error-runtime.js"; |
8 | 3 | import { loadBundledPluginPublicSurfaceModuleSync } from "./facade-runtime.js"; |
9 | 4 | import { resolvePrivateQaBundledPluginsEnv } from "./private-qa-bundled-env.js"; |
10 | 5 | import { runExec } from "./process-runtime.js"; |
@@ -110,35 +105,6 @@ export type QaDockerFetchLike = ( |
110 | 105 | const DEFAULT_QA_DOCKER_COMMAND_TIMEOUT_MS = 120_000; |
111 | 106 | const DEFAULT_QA_DOCKER_HEALTH_REQUEST_TIMEOUT_MS = 2_000; |
112 | 107 |
|
113 | | -/** Append a formatted live-lane issue while preserving the caller-owned issue list. */ |
114 | | -export function appendQaLiveLaneIssue(issues: string[], label: string, error: unknown) { |
115 | | - issues.push(`${label}: ${formatErrorMessage(error)}`); |
116 | | -} |
117 | | - |
118 | | -/** Format a live-lane failure message that includes artifact labels and paths. */ |
119 | | -export function buildQaLiveLaneArtifactsError(params: { |
120 | | - heading: string; |
121 | | - artifacts: Record<string, string>; |
122 | | - details?: string[]; |
123 | | -}) { |
124 | | - return [ |
125 | | - params.heading, |
126 | | - ...(params.details ?? []), |
127 | | - "Artifacts:", |
128 | | - ...Object.entries(params.artifacts).map(([label, filePath]) => `- ${label}: ${filePath}`), |
129 | | - ].join("\n"); |
130 | | -} |
131 | | - |
132 | | -/** Print live-transport QA artifact paths with a lane label for CI log parsers. */ |
133 | | -export function printLiveTransportQaArtifacts( |
134 | | - laneLabel: string, |
135 | | - artifacts: Record<string, string>, |
136 | | -) { |
137 | | - for (const [label, filePath] of Object.entries(artifacts)) { |
138 | | - process.stdout.write(`${laneLabel} ${label}: ${filePath}\n`); |
139 | | - } |
140 | | -} |
141 | | - |
142 | 108 | function describeQaDockerError(error: unknown) { |
143 | 109 | if (error instanceof Error) { |
144 | 110 | return error.message; |
@@ -461,66 +427,3 @@ export function createQaDockerRuntime(params: { |
461 | 427 | waitForHealth, |
462 | 428 | }; |
463 | 429 | } |
464 | | - |
465 | | -type ProcessWriteCallback = (err?: Error | null) => void; |
466 | | - |
467 | | -/** Tee stdout and stderr into a private artifact file until the returned stop hook runs. */ |
468 | | -export async function startLiveTransportQaOutputTee(params: { |
469 | | - fileName: string; |
470 | | - outputDir: string; |
471 | | -}) { |
472 | | - await fsp.mkdir(params.outputDir, { recursive: true }); |
473 | | - const outputPath = path.join(params.outputDir, params.fileName); |
474 | | - const output = fs.createWriteStream(outputPath, { |
475 | | - encoding: "utf8", |
476 | | - flags: "a", |
477 | | - mode: 0o600, |
478 | | - }); |
479 | | - let outputError: Error | null = null; |
480 | | - output.on("error", (error) => { |
481 | | - outputError ??= error; |
482 | | - }); |
483 | | - const originalStdoutWrite = Reflect.get(process.stdout, "write"); |
484 | | - const originalStderrWrite = Reflect.get(process.stderr, "write"); |
485 | | - const boundStdoutWrite = originalStdoutWrite.bind(process.stdout); |
486 | | - const boundStderrWrite = originalStderrWrite.bind(process.stderr); |
487 | | - let stopped = false; |
488 | | - |
489 | | - const tee = (originalWrite: typeof process.stdout.write) => |
490 | | - function writeWithTee( |
491 | | - this: NodeJS.WriteStream, |
492 | | - chunk: string | Uint8Array, |
493 | | - encodingOrCallback?: BufferEncoding | ProcessWriteCallback, |
494 | | - callback?: ProcessWriteCallback, |
495 | | - ) { |
496 | | - if (!stopped && !outputError) { |
497 | | - output.write(chunk); |
498 | | - } |
499 | | - return Reflect.apply(originalWrite, this, [chunk, encodingOrCallback, callback]) as boolean; |
500 | | - }; |
501 | | - |
502 | | - process.stdout.write = tee(boundStdoutWrite) as typeof process.stdout.write; |
503 | | - process.stderr.write = tee(boundStderrWrite) as typeof process.stderr.write; |
504 | | - |
505 | | - return { |
506 | | - outputPath, |
507 | | - async stop() { |
508 | | - if (stopped) { |
509 | | - return; |
510 | | - } |
511 | | - stopped = true; |
512 | | - process.stdout.write = originalStdoutWrite; |
513 | | - process.stderr.write = originalStderrWrite; |
514 | | - if (outputError) { |
515 | | - throw outputError; |
516 | | - } |
517 | | - await new Promise<void>((resolve, reject) => { |
518 | | - output.once("error", reject); |
519 | | - output.end(resolve); |
520 | | - }); |
521 | | - if (outputError) { |
522 | | - throw toErrorObject(outputError, "Non-Error thrown"); |
523 | | - } |
524 | | - }, |
525 | | - }; |
526 | | -} |
0 commit comments