@@ -66,7 +66,9 @@ type Options = {
6666 idleTimeout : string ;
6767 keepBox : boolean ;
6868 leaseId ?: string ;
69+ linkPreview ?: boolean ;
6970 mcpAppFixture : boolean ;
71+ mockResponseChunkDelayMs ?: number ;
7072 mockResponseText : string ;
7173 mockPort : number ;
7274 outputDir : string ;
@@ -92,6 +94,8 @@ type Options = {
9294 timeoutMs : number ;
9395 ttl : string ;
9496 userDriverScript : string ;
97+ nodeBin : string ;
98+ pnpmBin ?: string ;
9599} ;
96100
97101type FunnelBridge = {
@@ -208,7 +212,9 @@ function usageText() {
208212 " --desktop-chat-title <name> Telegram Desktop chat to select before recording." ,
209213 " --id <cbx_id> Reuse an existing Crabbox desktop lease." ,
210214 " --keep-box Leave the Crabbox lease running for VNC debugging." ,
215+ " --link-preview <true|false> Set channels.telegram.linkPreview before Gateway startup." ,
211216 " --mock-response-file <path> Text returned by the mock model." ,
217+ " --mock-response-chunk-delay-ms <ms> Split the mock reply across two delayed deltas." ,
212218 " --mcp-app-fixture Configure the pinned MCP App fixture through a Crabbox Funnel." ,
213219 " --output-dir <path> Artifact directory under the repo." ,
214220 " --message-id <id> Telegram message id for proof-view deep link." ,
@@ -283,6 +289,16 @@ function parseTcpPort(value: string, label: string) {
283289 return parsed ;
284290}
285291
292+ function parseBoolean ( value : string , label : string ) {
293+ if ( value === "true" ) {
294+ return true ;
295+ }
296+ if ( value === "false" ) {
297+ return false ;
298+ }
299+ throw new Error ( `${ label } must be true or false.` ) ;
300+ }
301+
286302function createTelegramProofRunId ( ) {
287303 return `${ new Date ( ) . toISOString ( ) . replace ( / [: .] / gu, "-" ) } -${ randomUUID ( ) . slice ( 0 , 8 ) } ` ;
288304}
@@ -332,6 +348,8 @@ export function parseArgs(argvInput: string[]): Options {
332348 ttl : "120m" ,
333349 userDriverScript :
334350 trimToValue ( process . env . OPENCLAW_TELEGRAM_USER_DRIVER_SCRIPT ) ?? DEFAULT_USER_DRIVER ,
351+ nodeBin : trimToValue ( process . env . MANTIS_NODE_BIN ) ?? process . execPath ,
352+ pnpmBin : trimToValue ( process . env . MANTIS_PNPM_BIN ) ,
335353 } ;
336354 const commandSeparator = argv . indexOf ( "--" ) ;
337355 if ( command === "run" && commandSeparator >= 0 ) {
@@ -383,10 +401,17 @@ export function parseArgs(argvInput: string[]): Options {
383401 opts . idleTimeout = readValue ( ) ;
384402 } else if ( arg === "--keep-box" ) {
385403 opts . keepBox = true ;
404+ } else if ( arg === "--link-preview" ) {
405+ opts . linkPreview = parseBoolean ( readValue ( ) , "--link-preview" ) ;
386406 } else if ( arg === "--mock-port" ) {
387407 opts . mockPort = parseTcpPort ( readValue ( ) , "--mock-port" ) ;
388408 } else if ( arg === "--mock-response-file" ) {
389409 opts . mockResponseText = fs . readFileSync ( resolveRepoPath ( process . cwd ( ) , readValue ( ) ) , "utf8" ) ;
410+ } else if ( arg === "--mock-response-chunk-delay-ms" ) {
411+ opts . mockResponseChunkDelayMs = parsePositiveTimerMs (
412+ readValue ( ) ,
413+ "--mock-response-chunk-delay-ms" ,
414+ ) ;
390415 } else if ( arg === "--mcp-app-fixture" ) {
391416 opts . mcpAppFixture = true ;
392417 } else if ( arg === "--message-id" ) {
@@ -541,12 +566,20 @@ function childProcessBaseEnv() {
541566 return env ;
542567}
543568
544- function mockServerEnv ( params : { mockPort : number ; mockResponseText : string ; requestLog : string } ) {
569+ function mockServerEnv ( params : {
570+ mockPort : number ;
571+ mockResponseChunkDelayMs ?: number ;
572+ mockResponseText : string ;
573+ requestLog : string ;
574+ } ) {
545575 return {
546576 ...childProcessBaseEnv ( ) ,
547577 MOCK_PORT : String ( params . mockPort ) ,
548578 MOCK_REQUEST_LOG : params . requestLog ,
549579 SUCCESS_MARKER : params . mockResponseText ,
580+ ...( params . mockResponseChunkDelayMs === undefined
581+ ? { }
582+ : { MOCK_RESPONSE_CHUNK_DELAY_MS : String ( params . mockResponseChunkDelayMs ) } ) ,
550583 } ;
551584}
552585
@@ -577,8 +610,16 @@ export function createOpenClawGatewaySpawnSpec(params: {
577610 comSpec ?: string ;
578611 nodeExecPath ?: string ;
579612 npmExecPath ?: string ;
613+ pnpmExecPath ?: string ;
580614 platform ?: NodeJS . Platform ;
581615} ) : GatewaySpawnSpec {
616+ if ( params . pnpmExecPath ) {
617+ return {
618+ args : [ "openclaw" , "gateway" , "--port" , String ( params . gatewayPort ) ] ,
619+ command : params . pnpmExecPath ,
620+ options : { cwd : params . repoRoot , env : params . env , shell : false } ,
621+ } ;
622+ }
582623 const spec = createPnpmRunnerSpawnSpec ( {
583624 comSpec : params . comSpec ,
584625 cwd : params . repoRoot ,
@@ -1137,6 +1178,7 @@ function telegramResultObject(value: unknown, label: string): JsonObject {
11371178export function writeSutConfig ( params : {
11381179 gatewayPort : number ;
11391180 groupId : string ;
1181+ linkPreview ?: boolean ;
11401182 mcpAppFixture ?: boolean ;
11411183 mockPort : number ;
11421184 outputDir : string ;
@@ -1185,6 +1227,7 @@ export function writeSutConfig(params: {
11851227 requireMention : false ,
11861228 } ,
11871229 } ,
1230+ ...( params . linkPreview === undefined ? { } : { linkPreview : params . linkPreview } ) ,
11881231 replyToMode : "first" ,
11891232 } ,
11901233 } ,
@@ -1264,10 +1307,14 @@ export async function startLocalSut(
12641307 groupId : string ;
12651308 mockResponseText : string ;
12661309 mockPort : number ;
1310+ linkPreview ?: boolean ;
1311+ mockResponseChunkDelayMs ?: number ;
12671312 outputDir : string ;
12681313 sutToken : string ;
12691314 testerId : string ;
12701315 repoRoot : string ;
1316+ nodeBin ?: string ;
1317+ pnpmBin ?: string ;
12711318 } ,
12721319 deps : StartLocalSutDeps = { } ,
12731320) {
@@ -1282,10 +1329,14 @@ export async function startLocalSut(
12821329 const drained = await drainUpdates ( params . sutToken ) ;
12831330 const config = writeConfig ( params ) ;
12841331 const requestLog = path . join ( params . outputDir , "mock-openai-requests.ndjson" ) ;
1285- mock = spawnLoggedCommand ( "node" , [ "scripts/e2e/mock-openai-server.mjs" ] , {
1286- cwd : params . repoRoot ,
1287- env : mockServerEnv ( { ...params , requestLog } ) ,
1288- } ) ;
1332+ mock = spawnLoggedCommand (
1333+ params . nodeBin ?? process . execPath ,
1334+ [ "scripts/e2e/mock-openai-server.mjs" ] ,
1335+ {
1336+ cwd : params . repoRoot ,
1337+ env : mockServerEnv ( { ...params , requestLog } ) ,
1338+ } ,
1339+ ) ;
12891340 const runningMock = mock ;
12901341 await waitForOutputReady (
12911342 runningMock . child ,
@@ -1297,6 +1348,7 @@ export async function startLocalSut(
12971348 const gatewaySpec = createGatewaySpawnSpec ( {
12981349 env : gatewayEnv ( { ...config , sutToken : params . sutToken } ) ,
12991350 gatewayPort : params . gatewayPort ,
1351+ pnpmExecPath : params . pnpmBin ,
13001352 repoRoot : params . repoRoot ,
13011353 } ) ;
13021354 gateway = spawnLoggedCommand ( gatewaySpec . command , gatewaySpec . args , gatewaySpec . options ) ;
@@ -1376,11 +1428,15 @@ async function startLocalSutDaemon(params: {
13761428 groupId : string ;
13771429 mockResponseText : string ;
13781430 mockPort : number ;
1431+ linkPreview ?: boolean ;
13791432 mcpAppFixture ?: boolean ;
1433+ mockResponseChunkDelayMs ?: number ;
13801434 outputDir : string ;
13811435 sutToken : string ;
13821436 testerId : string ;
13831437 repoRoot : string ;
1438+ nodeBin ?: string ;
1439+ pnpmBin ?: string ;
13841440} ) {
13851441 const drained = await drainSutUpdates ( params . sutToken ) ;
13861442 const config = writeSutConfig ( params ) ;
@@ -1392,7 +1448,7 @@ async function startLocalSutDaemon(params: {
13921448 let gatewayPid : number | undefined ;
13931449 try {
13941450 mockPid = spawnDaemon ( {
1395- command : "node" ,
1451+ command : params . nodeBin ?? process . execPath ,
13961452 args : [ "scripts/e2e/mock-openai-server.mjs" ] ,
13971453 cwd : params . repoRoot ,
13981454 env : mockServerEnv ( { ...params , requestLog } ) ,
@@ -1414,6 +1470,7 @@ async function startLocalSutDaemon(params: {
14141470 const gatewaySpec = createOpenClawGatewaySpawnSpec ( {
14151471 env : gatewayEnvVars ,
14161472 gatewayPort : params . gatewayPort ,
1473+ pnpmExecPath : params . pnpmBin ,
14171474 repoRoot : params . repoRoot ,
14181475 } ) ;
14191476 gatewayPid = spawnDaemon ( {
@@ -2414,10 +2471,14 @@ async function startSession(root: string, opts: Options, outputDir: string) {
24142471 funnelBridge,
24152472 gatewayPort : opts . gatewayPort ,
24162473 groupId : credential . groupId ,
2474+ linkPreview : opts . linkPreview ,
24172475 mockResponseText : opts . mockResponseText ,
2476+ mockResponseChunkDelayMs : opts . mockResponseChunkDelayMs ,
24182477 mockPort : opts . mockPort ,
24192478 mcpAppFixture : opts . mcpAppFixture ,
24202479 outputDir,
2480+ nodeBin : opts . nodeBin ,
2481+ pnpmBin : opts . pnpmBin ,
24212482 repoRoot : root ,
24222483 sutToken : credential . sutToken ,
24232484 testerId : credential . testerUserId ,
@@ -2978,9 +3039,13 @@ async function main() {
29783039 const sutRuntime = await startLocalSut ( {
29793040 gatewayPort : opts . gatewayPort ,
29803041 groupId : credential . groupId ,
3042+ linkPreview : opts . linkPreview ,
29813043 mockResponseText : opts . mockResponseText ,
3044+ mockResponseChunkDelayMs : opts . mockResponseChunkDelayMs ,
29823045 mockPort : opts . mockPort ,
29833046 outputDir,
3047+ nodeBin : opts . nodeBin ,
3048+ pnpmBin : opts . pnpmBin ,
29843049 repoRoot : root ,
29853050 sutToken : credential . sutToken ,
29863051 testerId : credential . testerUserId ,
0 commit comments