Skip to content

Commit cc6181c

Browse files
committed
merge: refresh PR #9401 from main
Signed-off-by: Senthil Ravichandran <senthilr@nvidia.com>
2 parents c68e474 + c4c987d commit cc6181c

1 file changed

Lines changed: 48 additions & 18 deletions

File tree

test/e2e/live/channels-add-remove.test.ts

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,11 @@ async function expectProvider(
282282
}
283283
}
284284

285-
async function openClawHasTelegram(sandbox: SandboxClient, artifactName: string): Promise<boolean> {
285+
/** Read non-secret Telegram activation state from the rendered OpenClaw config. */
286+
async function readOpenClawTelegramState(
287+
sandbox: SandboxClient,
288+
artifactName: string,
289+
): Promise<JsonRecord> {
286290
const result = await sandbox.exec(
287291
SANDBOX_NAME,
288292
[
@@ -291,7 +295,13 @@ async function openClawHasTelegram(sandbox: SandboxClient, artifactName: string)
291295
[
292296
"import json",
293297
"data=json.load(open('/sandbox/.openclaw/openclaw.json'))",
294-
"print('yes' if 'telegram' in data.get('channels', {}) else 'no')",
298+
"channels=data.get('channels', {})",
299+
"plugins=data.get('plugins', {}).get('entries', {})",
300+
"channel=channels.get('telegram', {})",
301+
"plugin=plugins.get('telegram', {})",
302+
"accounts=channel.get('accounts', {})",
303+
"state={'channelPresent': 'telegram' in channels, 'pluginPresent': 'telegram' in plugins, 'channelEnabled': channel.get('enabled') is True, 'pluginEnabled': plugin.get('enabled') is True, 'accountEnabled': any(isinstance(account, dict) and account.get('enabled') is True for account in accounts.values())}",
304+
"print(json.dumps(state))",
295305
].join("; "),
296306
],
297307
{
@@ -301,21 +311,11 @@ async function openClawHasTelegram(sandbox: SandboxClient, artifactName: string)
301311
},
302312
);
303313
assertExitZero(result, "read /sandbox/.openclaw/openclaw.json");
304-
const verdict = stripAnsi(result.stdout).trim().split(/\r?\n/).at(-1);
305-
expect(["yes", "no"], `unexpected openclaw.json verdict:\n${resultText(result)}`).toContain(
306-
verdict,
307-
);
308-
return verdict === "yes";
309-
}
310-
311-
async function expectOpenClawTelegram(
312-
sandbox: SandboxClient,
313-
expected: boolean,
314-
artifactName: string,
315-
): Promise<void> {
316-
await expect(openClawHasTelegram(sandbox, artifactName)).resolves.toBe(expected);
314+
const output = stripAnsi(result.stdout).trim().split(/\r?\n/).at(-1) ?? "";
315+
return JSON.parse(output) as JsonRecord;
317316
}
318317

318+
/** Detect an active policy preset in the human-readable policy listing. */
319319
function policyListHasActivePreset(output: string, preset: string): boolean {
320320
const activePreset = new RegExp(`^\\s*\\u25cf\\s+${escapeRegex(preset)}\\b`, "im");
321321
return activePreset.test(stripAnsi(output));
@@ -465,7 +465,17 @@ test(
465465

466466
progress.phase("verify baseline channel absence");
467467
await expectProvider(host, "absent", "phase-2-provider-get-baseline");
468-
await expectOpenClawTelegram(sandbox, false, "phase-2-openclaw-json-baseline");
468+
const baselineTelegram = await readOpenClawTelegramState(
469+
sandbox,
470+
"phase-2-openclaw-json-baseline",
471+
);
472+
expect(baselineTelegram).toEqual({
473+
accountEnabled: false,
474+
channelEnabled: false,
475+
channelPresent: true,
476+
pluginEnabled: false,
477+
pluginPresent: false,
478+
});
469479
await expectPolicyPreset(host, "telegram", "not-applied", "phase-2-policy-list-baseline");
470480

471481
progress.phase("add Telegram and rebuild sandbox");
@@ -507,7 +517,17 @@ test(
507517

508518
progress.phase("validate active Telegram integration");
509519
await expectPolicyPreset(host, "telegram", "applied", "phase-4-policy-list-after-add");
510-
await expectOpenClawTelegram(sandbox, true, "phase-4-openclaw-json-after-add");
520+
const activeTelegram = await readOpenClawTelegramState(
521+
sandbox,
522+
"phase-4-openclaw-json-after-add",
523+
);
524+
expect(activeTelegram).toEqual({
525+
accountEnabled: true,
526+
channelEnabled: true,
527+
channelPresent: true,
528+
pluginEnabled: true,
529+
pluginPresent: true,
530+
});
511531
await expectProvider(host, "present", "phase-4-provider-get-after-add");
512532
expectHostTelegramConfig("after add+rebuild");
513533
expectHostTelegramPlan("active", "after add+rebuild");
@@ -551,7 +571,17 @@ test(
551571
});
552572

553573
progress.phase("validate Telegram removal");
554-
await expectOpenClawTelegram(sandbox, false, "phase-6-openclaw-json-after-remove");
574+
const removedTelegram = await readOpenClawTelegramState(
575+
sandbox,
576+
"phase-6-openclaw-json-after-remove",
577+
);
578+
expect(removedTelegram).toEqual({
579+
accountEnabled: false,
580+
channelEnabled: false,
581+
channelPresent: false,
582+
pluginEnabled: false,
583+
pluginPresent: false,
584+
});
555585
await expectProvider(host, "absent", "phase-6-provider-get-after-remove");
556586
await expectPolicyPreset(host, "telegram", "not-applied", "phase-6-policy-list-after-remove");
557587
expectHostTelegramPlan("removed", "after remove+rebuild");

0 commit comments

Comments
 (0)