Skip to content

Commit 45bad50

Browse files
authored
fix(qa): harden Mantis Telegram proof harness (#114429)
* fix(qa): harden Mantis Telegram proof harness * fix(qa): require explicit Mantis dispatch
1 parent 4aa2ab2 commit 45bad50

8 files changed

Lines changed: 374 additions & 200 deletions

File tree

‎.agents/skills/telegram-crabbox-e2e-proof/SKILL.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ proof_cmd="${OPENCLAW_TELEGRAM_USER_PROOF_CMD:-openclaw-telegram-user-crabbox-pr
4747
--output-dir .artifacts/qa-e2e/telegram-user-crabbox/pr-review
4848
```
4949

50+
When the scenario needs Telegram link previews explicitly enabled or disabled,
51+
set the SUT config before Gateway startup:
52+
53+
```bash
54+
"$proof_cmd" start \
55+
--tdlib-url http://artifacts.openclaw.ai/tdlib-v1.8.0-linux-x64.tgz \
56+
--link-preview false \
57+
--mock-response-chunk-delay-ms 1200 \
58+
--mock-response-file .artifacts/qa-e2e/telegram-user-crabbox/reply.txt \
59+
--output-dir .artifacts/qa-e2e/telegram-user-crabbox/pr-review
60+
```
61+
62+
Do not edit the generated config or restart the held-session Gateway to apply
63+
this setting; that bypasses the runner's lifecycle and cleanup ownership.
64+
The chunk delay splits the configured response into two streaming deltas so a
65+
recording can show the initial preview and a later in-place edit.
66+
5067
The runner defaults to `--class standard`, `--record-fps 24`,
5168
`--preview-fps 24`, and `--preview-width 1920`. Keep those defaults unless the
5269
proof needs something else.

‎.github/codex/prompts/mantis-telegram-desktop-proof.md‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,16 @@ than Telegram-visible behavior`. Use this manifest shape and do not create
111111
Reopen that same Telegram button after its ticket expires and capture the
112112
expired state. Do not substitute Control UI, transcript, curl, or a newly
113113
minted button for any part of that path.
114-
5. Create detached worktrees under
114+
5. Use the workflow-prepared detached worktrees under
115115
`.artifacts/qa-e2e/mantis/telegram-desktop-proof-worktrees/baseline` and
116-
`.artifacts/qa-e2e/mantis/telegram-desktop-proof-worktrees/candidate`, then
117-
install and build each worktree with the repo's normal `pnpm` commands.
116+
`.artifacts/qa-e2e/mantis/telegram-desktop-proof-worktrees/candidate`.
117+
Verify their `HEAD`s match `BASELINE_SHA` and `CANDIDATE_SHA`; do not create,
118+
install, rebuild, or replace them. The workflow prepared both with a pinned
119+
Node/pnpm toolchain before agent secrets were available.
118120
If `MANTIS_CANDIDATE_TRUST` is `fork-pr-head`, treat the
119121
candidate worktree as untrusted fork code: do not pass GitHub, OpenAI,
120-
Crabbox, Convex, or other workflow secrets into candidate install, build, or
121-
runtime commands. The candidate SUT may receive only the proof runner's
122+
Crabbox, Convex, or other workflow secrets into candidate runtime commands.
123+
The candidate SUT may receive only the proof runner's
122124
short-lived Telegram bot token, generated local config/state paths, and mock
123125
model key needed for this isolated proof.
124126
6. In each worktree, run the real-user Telegram Crabbox proof flow from the
@@ -133,6 +135,14 @@ than Telegram-visible behavior`. Use this manifest shape and do not create
133135
own; do not kill it while Crabbox is still waiting for bootstrap. Use a long
134136
command timeout for `start`, `send`, `view`, and `finish`. You may iterate
135137
and rerun if the visual result is not convincing.
138+
When the requested scenario needs `channels.telegram.linkPreview: false`,
139+
pass `--link-preview false` to `start`. The runner injects that setting into
140+
the isolated SUT config before Gateway startup. Do not edit the generated
141+
config or restart the Gateway to apply it.
142+
When the proof must show an in-place streamed edit, also pass
143+
`--mock-response-chunk-delay-ms 1200` and use a mock response long enough
144+
for the first chunk to clear the preview debounce. Capture both the initial
145+
partial reply and the later edit before finishing.
136146
7. Open Telegram Desktop directly to the newest relevant message with the
137147
runner `view` command before finishing each recording. Keep the chat scrolled
138148
to the bottom so new proof messages appear in-frame.

‎.github/workflows/mantis-telegram-desktop-proof.yml‎

Lines changed: 103 additions & 157 deletions
Large diffs are not rendered by default.

‎scripts/e2e/mock-openai-server.mjs‎

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Mock OpenAI-compatible server for broader E2E scenarios.
22
import { createHash } from "node:crypto";
33
import http from "node:http";
4+
import { setTimeout as delay } from "node:timers/promises";
45
import { escapeRegExp } from "../lib/regexp.mjs";
5-
import { readTcpPortEnv } from "./lib/env-limits.mjs";
6+
import { readPositiveIntEnv, readTcpPortEnv } from "./lib/env-limits.mjs";
67
import {
78
boundedRequestLogBody,
89
isRequestBodyTooLargeError,
@@ -18,8 +19,21 @@ const port =
1819
: readTcpPortEnv("OPENCLAW_MOCK_OPENAI_PORT");
1920
const successMarker = process.env.SUCCESS_MARKER ?? "OPENCLAW_E2E_OK";
2021
const requestLog = process.env.MOCK_REQUEST_LOG;
22+
const responseChunkDelayMs = process.env.MOCK_RESPONSE_CHUNK_DELAY_MS
23+
? readPositiveIntEnv("MOCK_RESPONSE_CHUNK_DELAY_MS", undefined)
24+
: 0;
2125

22-
function responseEvents(text) {
26+
function splitResponseText(text) {
27+
if (text.length < 2) {
28+
return [text];
29+
}
30+
const midpoint = Math.floor(text.length / 2);
31+
const whitespace = text.lastIndexOf(" ", midpoint);
32+
const splitAt = whitespace > 0 ? whitespace : Math.max(1, midpoint);
33+
return [text.slice(0, splitAt), text.slice(splitAt)];
34+
}
35+
36+
function responseEvents(text, deltas = [text]) {
2337
const itemId = "msg_e2e_1";
2438
return [
2539
{
@@ -32,13 +46,13 @@ function responseEvents(text) {
3246
status: "in_progress",
3347
},
3448
},
35-
{
49+
...deltas.map((delta) => ({
3650
type: "response.output_text.delta",
3751
item_id: itemId,
3852
output_index: 0,
3953
content_index: 0,
40-
delta: text,
41-
},
54+
delta,
55+
})),
4256
{
4357
type: "response.output_text.done",
4458
item_id: itemId,
@@ -81,6 +95,31 @@ function responseEvents(text) {
8195
];
8296
}
8397

98+
async function writeDefaultResponseEvents(res, text) {
99+
if (responseChunkDelayMs === 0) {
100+
writeSse(res, responseEvents(text));
101+
return;
102+
}
103+
const events = responseEvents(text, splitResponseText(text));
104+
res.writeHead(200, {
105+
"content-type": "text/event-stream",
106+
"cache-control": "no-store",
107+
connection: "keep-alive",
108+
});
109+
let deltaCount = 0;
110+
for (const event of events) {
111+
if (event.type === "response.output_text.delta" && deltaCount > 0) {
112+
await delay(responseChunkDelayMs);
113+
}
114+
res.write(`data: ${JSON.stringify(event)}\n\n`);
115+
if (event.type === "response.output_text.delta") {
116+
deltaCount += 1;
117+
}
118+
}
119+
res.write("data: [DONE]\n\n");
120+
res.end();
121+
}
122+
84123
function buildMockFunctionCall(name, args) {
85124
const serialized = JSON.stringify(args);
86125
const suffix = createHash("sha256")
@@ -380,7 +419,7 @@ const server = http.createServer((req, res) => {
380419
});
381420
return;
382421
}
383-
writeSse(res, responseEvents(responseText));
422+
await writeDefaultResponseEvents(res, responseText);
384423
return;
385424
}
386425

‎scripts/e2e/telegram-user-crabbox-proof.ts‎

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

97101
type 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+
286302
function 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 {
11371178
export 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

Comments
 (0)