11// OpenWebUI probe tests cover QA Lab OpenAI-compatible API evidence.
2- import { spawn } from "node:child_process" ;
32import { readFileSync } from "node:fs" ;
43import { createServer , type IncomingMessage , type Server as HttpServer } from "node:http" ;
54import { createServer as createTcpServer , type Server as TcpServer , type Socket } from "node:net" ;
65import path from "node:path" ;
76import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion" ;
87import { describe , expect , it } from "vitest" ;
9- import { createBoundedChildOutput } from "../../../helpers/bounded-child-output .js" ;
8+ import { runNodeScript } from "../../../helpers/run-node-script .js" ;
109
1110const probePath = path . resolve ( "scripts/e2e/openwebui-probe.mjs" ) ;
1211
13- interface ProbeResult {
14- error ?: Error ;
15- status : number | null ;
16- stderr : string ;
17- stdout : string ;
18- }
19-
2012async function listen ( server : HttpServer | TcpServer ) : Promise < string > {
2113 await new Promise < void > ( ( resolve , reject ) => {
2214 server . once ( "error" , reject ) ;
@@ -33,52 +25,23 @@ async function listen(server: HttpServer | TcpServer): Promise<string> {
3325}
3426
3527function runProbe ( baseUrl : string , env : Record < string , string > = { } , timeout = 3_000 ) {
36- return new Promise < ProbeResult > ( ( resolve ) => {
37- const child = spawn ( process . execPath , [ probePath ] , {
38- env : {
39- ...process . env ,
40- OPENWEBUI_ADMIN_EMAIL :
"[email protected] " , 41- OPENWEBUI_ADMIN_PASSWORD : "test-password" ,
42- OPENWEBUI_BASE_URL : baseUrl ,
43- OPENWEBUI_CONTROL_TIMEOUT_MS : "250" ,
44- OPENWEBUI_EXPECTED_NONCE : "nonce-123" ,
45- OPENWEBUI_MODEL_ATTEMPTS : "1" ,
46- OPENWEBUI_MODEL_RETRY_MS : "0" ,
47- OPENWEBUI_PROMPT : "reply with nonce-123" ,
48- OPENWEBUI_SMOKE_MODE : "models" ,
49- ...env ,
50- } ,
51- stdio : [ "ignore" , "pipe" , "pipe" ] ,
52- } ) ;
53- const stdout = createBoundedChildOutput ( ) ;
54- const stderr = createBoundedChildOutput ( ) ;
55- let timedOut = false ;
56- child . stdout . setEncoding ( "utf8" ) ;
57- child . stderr . setEncoding ( "utf8" ) ;
58- child . stdout . on ( "data" , ( chunk ) => {
59- stdout . append ( chunk ) ;
60- } ) ;
61- child . stderr . on ( "data" , ( chunk ) => {
62- stderr . append ( chunk ) ;
63- } ) ;
64- const timer = setTimeout ( ( ) => {
65- timedOut = true ;
66- child . kill ( "SIGKILL" ) ;
67- } , timeout ) ;
68- child . on ( "error" , ( error ) => {
69- clearTimeout ( timer ) ;
70- resolve ( { error, status : null , stderr : stderr . text ( ) , stdout : stdout . text ( ) } ) ;
71- } ) ;
72- child . on ( "exit" , ( status ) => {
73- clearTimeout ( timer ) ;
74- resolve ( {
75- error : timedOut ? new Error ( `probe timed out after ${ timeout } ms` ) : undefined ,
76- status,
77- stderr : stderr . text ( ) ,
78- stdout : stdout . text ( ) ,
79- } ) ;
80- } ) ;
81- } ) ;
28+ return runNodeScript (
29+ probePath ,
30+ {
31+ ...process . env ,
32+ OPENWEBUI_ADMIN_EMAIL :
"[email protected] " , 33+ OPENWEBUI_ADMIN_PASSWORD : "test-password" ,
34+ OPENWEBUI_BASE_URL : baseUrl ,
35+ OPENWEBUI_CONTROL_TIMEOUT_MS : "250" ,
36+ OPENWEBUI_EXPECTED_NONCE : "nonce-123" ,
37+ OPENWEBUI_MODEL_ATTEMPTS : "1" ,
38+ OPENWEBUI_MODEL_RETRY_MS : "0" ,
39+ OPENWEBUI_PROMPT : "reply with nonce-123" ,
40+ OPENWEBUI_SMOKE_MODE : "models" ,
41+ ...env ,
42+ } ,
43+ timeout ,
44+ ) ;
8245}
8346
8447async function readRequestBody ( request : IncomingMessage ) : Promise < string > {
0 commit comments