Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a20b198
fix(messaging): surface telegram config inputs in channels status
laitingsheng Jun 24, 2026
53a053c
fix(doctor): surface telegram visible config in messaging section
laitingsheng Jun 24, 2026
581ad20
chore: biome format
laitingsheng Jun 24, 2026
371c38d
fix(messaging): render telegram mention-mode behavior text in diagnos…
laitingsheng Jun 24, 2026
120a479
fix(messaging): filter agent-scoped diagnostics and bound invalid values
laitingsheng Jun 24, 2026
bf35a86
fix(messaging): reject present-empty plan values and exercise compile…
laitingsheng Jun 24, 2026
ed906b3
chore(test): rewrite env-override helper without branching
laitingsheng Jun 24, 2026
c9206f9
test(messaging): exercise compiled telegram plan through status + doc…
laitingsheng Jun 24, 2026
b0258ec
Merge remote-tracking branch 'origin/main' into fix/channels-status-t…
laitingsheng Jun 28, 2026
343037f
refactor(doctor): extract visible-config helpers to bound complexity
laitingsheng Jun 28, 2026
2d14eca
fix(messaging): bound diagnostic disclosure to allowlisted inputs
laitingsheng Jun 28, 2026
144e0dc
test(messaging): rewrite tamper plan helper without conditional
laitingsheng Jun 28, 2026
a664a51
fix(messaging): require validValues on visible config display contract
laitingsheng Jun 28, 2026
cd7c19b
style: biome format channel-status visibility tests
laitingsheng Jun 28, 2026
b059070
test(messaging): share Telegram plan compile helper across diagnostic…
laitingsheng Jun 28, 2026
9b5419c
Merge remote-tracking branch 'origin/main' into fix/channels-status-t…
laitingsheng Jun 28, 2026
f2b0282
chore(checks): exempt validation-exit spawn fixture from no-test-dist…
laitingsheng Jun 28, 2026
1693804
style: drop residual blank line after helper extraction
laitingsheng Jun 28, 2026
6f8dd3e
chore(checks): move spawn-only validation fixture to no-test-dist-imp…
laitingsheng Jun 28, 2026
f5c9db4
test(messaging): cover serialize/parse round-trip for telegram visibl…
laitingsheng Jun 28, 2026
cd4290f
docs: sync hermes variant for channels status visible-config note
laitingsheng Jun 28, 2026
536efa8
test(onboard): keep validation test on source boundary
cv Jun 28, 2026
bf985fd
test(messaging): cover non-interactive compact-registry path through …
laitingsheng Jun 28, 2026
1001763
Merge remote-tracking branch 'origin/main' into fix/channels-status-t…
laitingsheng Jun 28, 2026
97c9d5a
style: apply biome format to telegram test helpers
laitingsheng Jun 28, 2026
c20ee5d
Merge remote-tracking branch 'origin/main' into fix/channels-status-t…
laitingsheng Jun 28, 2026
6436d36
fix(messaging): tighten telegram diagnostics contract and extract tes…
laitingsheng Jun 28, 2026
6fc2425
refactor(messaging): centralize compact-registry test helpers and ali…
laitingsheng Jun 28, 2026
f6979df
Merge remote-tracking branch 'origin/main' into fix/channels-status-t…
laitingsheng Jun 28, 2026
373fd97
style: apply biome format to compact-registry test helpers
laitingsheng Jun 28, 2026
a928426
test(checks): distinguish dynamic-require path construction from bare…
laitingsheng Jun 28, 2026
fd42b72
test(checks): build dist patterns from templates to keep them past th…
laitingsheng Jun 28, 2026
88dc960
Merge remote-tracking branch 'origin/main' into fix/channels-status-t…
laitingsheng Jun 29, 2026
331f342
refactor(messaging): harden visible config boundary and split monolit…
laitingsheng Jun 29, 2026
5ef3e73
Merge remote-tracking branch 'origin/main' into fix/channels-status-t…
laitingsheng Jun 29, 2026
1dbc44b
test(messaging): assert Telegram visible config in live messaging-pro…
laitingsheng Jun 29, 2026
d67a997
test(messaging): drop early-return ifs to keep test bodies linear
laitingsheng Jun 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 107 additions & 1 deletion src/lib/actions/sandbox/channel-status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ vi.mock("./process-recovery", () => ({
}));

import type { AgentDefinition } from "../../agent/defs";
import type {
MessagingSerializableValue,
SandboxMessagingPlan,
} from "../../messaging/manifest";
import type { SandboxEntry } from "../../state/registry";
import { showSandboxChannelStatus } from "./channel-status";

Expand Down Expand Up @@ -160,18 +164,24 @@ function makeDeps(opts: {
gatewayPresets?: string[] | null;
agentName?: "openclaw" | "hermes";
sandbox?: SandboxEntry | undefined;
channelInputs?: Record<
string,
ReadonlyArray<{ inputId: string; value?: MessagingSerializableValue }>
>;
out?: (line: string) => void;
}) {
const calls: string[] = [];
const out = opts.out ?? ((line: string) => calls.push(line));
const sandbox = opts.sandbox ?? entry();
return {
out,
deps: {
loadAgent: () => fakeAgent(opts.agentName),
getSandbox: () => opts.sandbox ?? entry(),
getSandbox: () => sandbox,
getAppliedPresets: () => opts.appliedPresets ?? ["whatsapp"],
getGatewayPresets: () =>
opts.gatewayPresets === undefined ? ["whatsapp"] : opts.gatewayPresets,
getMessagingPlan: () => fakePlanFromInputs(sandbox, opts.channelInputs),
execSandbox: vi.fn(opts.exec),
now: () => PROBED_AT,
out,
Expand All @@ -180,6 +190,43 @@ function makeDeps(opts: {
};
}

function fakePlanFromInputs(
sandbox: SandboxEntry | undefined,
channelInputs:
| Record<string, ReadonlyArray<{ inputId: string; value?: MessagingSerializableValue }>>
| undefined,
): SandboxMessagingPlan | null {
const base = sandbox?.messaging?.plan ?? null;
return base && channelInputs ? mergePlanInputs(base, channelInputs) : base;
}

function mergePlanInputs(
base: SandboxMessagingPlan,
channelInputs: Record<
string,
ReadonlyArray<{ inputId: string; value?: MessagingSerializableValue }>
>,
): SandboxMessagingPlan {
return {
...base,
channels: base.channels.map((channel) => {
const overrides = channelInputs[channel.channelId];
return overrides
? {
...channel,
inputs: overrides.map((entry) => ({
channelId: channel.channelId,
inputId: entry.inputId,
kind: "config" as const,
required: false,
...(entry.value !== undefined ? { value: entry.value } : {}),
})),
}
: channel;
}),
};
}

describe("showSandboxChannelStatus (whatsapp)", () => {
it("returns idle verdict and exit code 1 when paired but no inbound observed", async () => {
const heartbeat = JSON.stringify({
Expand Down Expand Up @@ -506,3 +553,62 @@ describe("showSandboxChannelStatus (whatsapp)", () => {
expect(dump).toMatch(/preset applied/);
});
});

describe("showSandboxChannelStatus (telegram config visibility)", () => {
for (const policy of ["open", "allowlist", "disabled"] as const) {
it(`surfaces the resolved Telegram group policy: ${policy}`, async () => {
const { deps, out_lines } = makeDeps({
exec: () => ({ status: 0, stdout: "", stderr: "" }),
sandbox: entry(["telegram"]),
appliedPresets: ["telegram"],
channelInputs: {
telegram: [{ inputId: "groupPolicy", value: policy }],
},
});
await showSandboxChannelStatus("alpha", { deps, channel: "telegram" });
const dump = out_lines.join("\n");
expect(dump).toMatch(new RegExp(`Telegram group policy:\\s+${policy}\\b`));
expect(dump).not.toMatch(new RegExp(`Telegram group policy:\\s+${policy}\\s+\\(default\\)`));
});
}

it("falls back to the manifest default when no group policy value is persisted", async () => {
const { deps, out_lines } = makeDeps({
exec: () => ({ status: 0, stdout: "", stderr: "" }),
sandbox: entry(["telegram"]),
appliedPresets: ["telegram"],
});
await showSandboxChannelStatus("alpha", { deps, channel: "telegram" });
const dump = out_lines.join("\n");
expect(dump).toMatch(/Telegram group policy:\s+open\s+\(default\)/);
});

it("surfaces the resolved Telegram mention mode alongside the group policy", async () => {
const { deps, out_lines } = makeDeps({
exec: () => ({ status: 0, stdout: "", stderr: "" }),
sandbox: entry(["telegram"]),
appliedPresets: ["telegram"],
channelInputs: {
telegram: [
{ inputId: "requireMention", value: "0" },
{ inputId: "groupPolicy", value: "allowlist" },
],
},
});
await showSandboxChannelStatus("alpha", { deps, channel: "telegram" });
const dump = out_lines.join("\n");
expect(dump).toMatch(/Telegram group mention mode:\s+0\b/);
expect(dump).toMatch(/Telegram group policy:\s+allowlist\b/);
});

it("skips visible config inputs that have neither a persisted value nor a default", async () => {
const { deps, out_lines } = makeDeps({
exec: () => ({ status: 0, stdout: "", stderr: "" }),
sandbox: entry(["telegram"]),
appliedPresets: ["telegram"],
});
await showSandboxChannelStatus("alpha", { deps, channel: "telegram" });
const dump = out_lines.join("\n");
expect(dump).not.toMatch(/Telegram User ID/);
});
});
65 changes: 63 additions & 2 deletions src/lib/actions/sandbox/channel-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import {
collectBuiltInMessagingChannelDiagnostics,
type MessagingChannelDiagnosticSpec,
} from "../../messaging/diagnostics";
import type {
SandboxMessagingChannelPlan,
SandboxMessagingInputReference,
SandboxMessagingPlan,
} from "../../messaging/manifest";
import * as policies from "../../policy";
import {
type DiagnosticSeverity,
Expand Down Expand Up @@ -64,6 +69,7 @@ type StatusDeps = {
getSandbox?: typeof registry.getSandbox;
getAppliedPresets?: (sandboxName: string) => string[];
getGatewayPresets?: (sandboxName: string) => string[] | null;
getMessagingPlan?: (entry: ReturnType<typeof registry.getSandbox>) => SandboxMessagingPlan | null;
execSandbox?: ExecRunner;
now?: () => Date;
out?: (line: string) => void;
Expand Down Expand Up @@ -131,6 +137,7 @@ function defaultDeps(deps: StatusDeps | undefined): Required<StatusDeps> {
getSandbox: deps?.getSandbox ?? registry.getSandbox,
getAppliedPresets: deps?.getAppliedPresets ?? policies.getAppliedPresets,
getGatewayPresets: deps?.getGatewayPresets ?? policies.getGatewayPresets,
getMessagingPlan: deps?.getMessagingPlan ?? registry.getMessagingPlanFromEntry,
execSandbox: deps?.execSandbox ?? defaultExec,
now: deps?.now ?? (() => new Date()),
out: deps?.out ?? ((line: string) => console.log(line)),
Expand Down Expand Up @@ -500,13 +507,14 @@ function buildBasicChannelReport(
? undefined
: `run \`${CLI_NAME} ${sandboxName} policy-add ${policyPresets[0]}\``,
});
for (const signal of buildConfigVisibilitySignals(channelName, diagnostic, deps, entry)) {
signals.push(signal);
}
signals.push({
label: "Deep diagnostics",
severity: "info",
detail: `not implemented for ${channelName}; see \`${CLI_NAME} ${sandboxName} doctor\` and \`${CLI_NAME} ${sandboxName} logs --follow\``,
});
// Reference the agent in a hint so the deep-diagnostic section is
// discoverable per agent without needing extra plumbing.
if (!agent.messagingPlatforms.includes(channelName)) {
signals.unshift({
label: "Agent support",
Expand All @@ -523,6 +531,59 @@ function buildBasicChannelReport(
};
}

function buildConfigVisibilitySignals(
channelName: string,
diagnostic: MessagingChannelDiagnosticSpec,
deps: Required<StatusDeps>,
entry: ReturnType<typeof registry.getSandbox>,
): DiagnosticSignal[] {
const visible = diagnostic.visibleConfigInputs;
if (!visible || visible.length === 0) return [];
const plan = deps.getMessagingPlan(entry);
const channelPlan = plan?.channels.find((channel) => channel.channelId === channelName) ?? null;
return visible.flatMap<DiagnosticSignal>((input) => {
const planInput = findChannelInput(channelPlan, input.inputId);
const rawValue = planInput?.value;
if (rawValue !== undefined && rawValue !== null && rawValue !== "") {
return [
{
label: input.label,
severity: "ok",
detail: formatVisibleConfigValue(rawValue),
},
];
}
if (input.defaultValue !== undefined) {
return [
{
label: input.label,
severity: "info",
detail: `${input.defaultValue} (default)`,
},
];
}
return [];
});
}

function findChannelInput(
channelPlan: SandboxMessagingChannelPlan | null,
inputId: string,
): SandboxMessagingInputReference | null {
if (!channelPlan) return null;
return channelPlan.inputs.find((input) => input.inputId === inputId) ?? null;
}

function formatVisibleConfigValue(value: unknown): string {
if (typeof value === "string") return value;
if (typeof value === "boolean") return value ? "true" : "false";
if (typeof value === "number") return String(value);
if (Array.isArray(value)) {
return value.map((entry) => formatVisibleConfigValue(entry)).join(", ");
}
return JSON.stringify(value);
}

/**
* Run the WhatsApp diagnostic or a thin per-channel summary for the named
* sandbox. The function never throws: any unexpected condition is rendered
Expand Down
66 changes: 66 additions & 0 deletions src/lib/actions/sandbox/doctor-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,72 @@ describe("runSandboxDoctor flow", () => {
expect(harness.logSpy).not.toHaveBeenCalled();
});

it("surfaces Telegram visible config inputs in the Messaging doctor section", async () => {
const harness = createDoctorHarness();
const registry = requireDist("../../../../dist/lib/state/registry.js");
vi.spyOn(registry, "getConfiguredMessagingChannelsFromEntry").mockReturnValue(["telegram"]);
vi.spyOn(registry, "getDisabledMessagingChannelsFromEntry").mockReturnValue([]);
vi.spyOn(registry, "getMessagingPlanFromEntry").mockReturnValue({
schemaVersion: 1,
sandboxName: "alpha",
agent: "openclaw",
workflow: "onboard",
channels: [
{
channelId: "telegram",
displayName: "telegram",
authMode: "token-paste",
active: true,
selected: true,
configured: true,
disabled: false,
inputs: [
{
channelId: "telegram",
inputId: "requireMention",
kind: "config",
required: false,
value: "0",
},
],
hooks: [],
},
],
disabledChannels: [],
credentialBindings: [],
networkPolicy: { presets: [], entries: [] },
agentRender: [],
buildSteps: [],
stateUpdates: [],
healthChecks: [],
});

const report = await harness.runSandboxDoctor("alpha", ["--json"], { quietJson: true });

expect(report?.checks).toEqual(
expect.arrayContaining([
expect.objectContaining({
group: "Messaging",
label: "Telegram group mention mode",
status: "ok",
detail: "0",
}),
expect.objectContaining({
group: "Messaging",
label: "Telegram group policy",
status: "info",
detail: "open (default)",
}),
]),
);
const messagingChecks = (report?.checks ?? []).filter(
(check) => check.group === "Messaging",
);
expect(
messagingChecks.some((check) => /[Bb]ot [Tt]oken|secret/i.test(check.label)),
).toBe(false);
});

it("rejects mutating --fix when JSON output was requested", async () => {
const harness = createDoctorHarness();

Expand Down
57 changes: 57 additions & 0 deletions src/lib/actions/sandbox/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { GATEWAY_PORT, OLLAMA_PORT } from "../../core/ports";
import { recoverNamedGatewayRuntime } from "../../gateway-runtime-action";
import { parseGatewayInference } from "../../inference/config";
import { type ProviderHealthStatus, probeProviderHealth } from "../../inference/health";
import type { MessagingSerializableValue } from "../../messaging/manifest";
import {
collectBuiltInMessagingChannelDiagnostics,
type MessagingChannelDiagnosticSpec,
Expand Down Expand Up @@ -516,6 +517,59 @@ function getChannelStatusDiagnostic(channelName: string): MessagingChannelDiagno
);
}

function messagingChannelConfigDoctorChecks(
sandboxName: string,
sb: SandboxEntry,
): DoctorCheck[] {
const registeredChannels = registry.getConfiguredMessagingChannelsFromEntry(sb);
const disabledChannels = new Set(registry.getDisabledMessagingChannelsFromEntry(sb));
const activeChannels = registeredChannels.filter(
(channel: string) => !disabledChannels.has(channel),
);
if (activeChannels.length === 0) return [];
const plan = registry.getMessagingPlanFromEntry(sb);
const checks: DoctorCheck[] = [];
for (const channelName of activeChannels) {
const diagnostic = getChannelStatusDiagnostic(channelName);
const visible = diagnostic?.visibleConfigInputs ?? [];
if (visible.length === 0) continue;
const channelPlan =
plan?.channels.find((channel) => channel.channelId === channelName) ?? null;
for (const input of visible) {
const planInput = channelPlan?.inputs.find((entry) => entry.inputId === input.inputId);
const rawValue = planInput?.value;
const persisted = rawValue !== undefined && rawValue !== null && rawValue !== "";
if (persisted) {
checks.push({
group: "Messaging",
label: input.label,
status: "ok",
detail: formatVisibleConfigValue(rawValue),
});
continue;
}
if (input.defaultValue !== undefined) {
checks.push({
group: "Messaging",
label: input.label,
status: "info",
detail: `${input.defaultValue} (default)`,
hint: `run \`${CLI_NAME} ${sandboxName} channels status --channel ${channelName}\` to confirm the resolved value`,
});
}
}
}
return checks;
}

function formatVisibleConfigValue(value: MessagingSerializableValue): string {
if (typeof value === "string") return value;
if (typeof value === "boolean") return value ? "true" : "false";
if (typeof value === "number") return String(value);
if (Array.isArray(value)) return value.map(formatVisibleConfigValue).join(", ");
return JSON.stringify(value);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

function formatMessagingOverlapDoctorDetail(overlap: {
readonly channel: string;
readonly sandboxes: readonly [string, string];
Expand Down Expand Up @@ -836,6 +890,9 @@ export async function runSandboxDoctor(
if (permsCheck) checks.push(permsCheck);

checks.push(messagingDoctorCheck(sandboxName, sb));
for (const check of messagingChannelConfigDoctorChecks(sandboxName, sb)) {
checks.push(check);
}
// #4156: bridge the gap between "configured" and "runtime-visible" — the
// existing messaging check above probes provider attachment, not whether
// OpenClaw's runtime config actually surfaces each enabled channel.
Expand Down
Loading
Loading