Skip to content
31 changes: 27 additions & 4 deletions test/e2e/live/channels-add-remove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,16 @@ async function expectProvider(
}
}

async function openClawHasTelegram(sandbox: SandboxClient, artifactName: string): Promise<boolean> {
/** Report whether the OpenClaw Telegram entries match the requested probe. */
async function openClawTelegramMatches(
sandbox: SandboxClient,
artifactName: string,
probe: "active" | "present",
): Promise<boolean> {
const predicate =
probe === "active"
? "channel.get('enabled') is True and plugin.get('enabled') is True"
: "'telegram' in channels or 'telegram' in plugins";
const result = await sandbox.exec(
SANDBOX_NAME,
[
Expand All @@ -291,7 +300,11 @@ async function openClawHasTelegram(sandbox: SandboxClient, artifactName: string)
[
"import json",
"data=json.load(open('/sandbox/.openclaw/openclaw.json'))",
"print('yes' if 'telegram' in data.get('channels', {}) else 'no')",
"channels=data.get('channels', {})",
"plugins=data.get('plugins', {}).get('entries', {})",
"channel=channels.get('telegram', {})",
"plugin=plugins.get('telegram', {})",
`print('yes' if ${predicate} else 'no')`,
].join("; "),
],
{
Expand All @@ -308,14 +321,24 @@ async function openClawHasTelegram(sandbox: SandboxClient, artifactName: string)
return verdict === "yes";
}

/** Assert the active Telegram state recorded inside the OpenClaw sandbox. */
async function expectOpenClawTelegram(
sandbox: SandboxClient,
expected: boolean,
artifactName: string,
): Promise<void> {
await expect(openClawHasTelegram(sandbox, artifactName)).resolves.toBe(expected);
await expect(openClawTelegramMatches(sandbox, artifactName, "active")).resolves.toBe(expected);
}

/** Assert that neither OpenClaw Telegram configuration entry remains. */
async function expectOpenClawTelegramRemoved(
sandbox: SandboxClient,
artifactName: string,
): Promise<void> {
await expect(openClawTelegramMatches(sandbox, artifactName, "present")).resolves.toBe(false);
}

/** Detect an active policy preset in the human-readable policy listing. */
function policyListHasActivePreset(output: string, preset: string): boolean {
const activePreset = new RegExp(`^\\s*\\u25cf\\s+${escapeRegex(preset)}\\b`, "im");
return activePreset.test(stripAnsi(output));
Expand Down Expand Up @@ -551,7 +574,7 @@ test(
});

progress.phase("validate Telegram removal");
await expectOpenClawTelegram(sandbox, false, "phase-6-openclaw-json-after-remove");
await expectOpenClawTelegramRemoved(sandbox, "phase-6-openclaw-json-after-remove");
await expectProvider(host, "absent", "phase-6-provider-get-after-remove");
await expectPolicyPreset(host, "telegram", "not-applied", "phase-6-policy-list-after-remove");
expectHostTelegramPlan("removed", "after remove+rebuild");
Expand Down
Loading