Tests: move cron direct-text delivery to dispatch seam

This commit is contained in:
Peter Steinberger
2026-04-07 09:21:33 +08:00
parent 64c18bc77b
commit d8dbacb900
3 changed files with 29 additions and 51 deletions

View File

@@ -1,10 +1,10 @@
import type { ChannelDoctorLegacyConfigRule } from "openclaw/plugin-sdk/channel-contract";
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
import {
ELEVENLABS_TALK_PROVIDER_ID,
isRecord,
migrateElevenLabsLegacyTalkConfig,
} from "./config-compat.js";
import { ELEVENLABS_TALK_PROVIDER_ID, migrateElevenLabsLegacyTalkConfig } from "./config-compat.js";
function isRecord(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
}
export function hasLegacyTalkFields(value: unknown): boolean {
const talk = isRecord(value) ? value : null;

View File

@@ -243,58 +243,12 @@ async function runSignalDeliveryResult(bestEffort: boolean) {
return outcome;
}
async function assertExplicitTelegramTargetDelivery(params: {
home: string;
storePath: string;
deps: CliDeps;
payloads: Array<Record<string, unknown>>;
expectedTexts: string[];
}): Promise<void> {
mockAgentPayloads(params.payloads);
const res = await runExplicitTelegramAnnounceTurn({
home: params.home,
storePath: params.storePath,
deps: params.deps,
});
expectDeliveredOk(res);
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
if (params.expectedTexts.length === 1) {
expectDirectTelegramDelivery(params.deps, {
chatId: "123",
text: params.expectedTexts[0] ?? "",
});
return;
}
expect(params.deps.sendMessageTelegram).toHaveBeenCalledTimes(params.expectedTexts.length);
for (const [index, text] of params.expectedTexts.entries()) {
expect(params.deps.sendMessageTelegram).toHaveBeenNthCalledWith(
index + 1,
"123",
text,
expect.objectContaining({ cfg: expect.any(Object) }),
);
}
}
describe("runCronIsolatedAgentTurn", () => {
beforeEach(() => {
vi.spyOn(modelSelection, "resolveThinkingDefault").mockReturnValue("off");
setupIsolatedAgentTurnMocks({ fast: true });
});
it("delivers explicit targets with direct text", async () => {
await withTelegramAnnounceFixture(async ({ home, storePath, deps }) => {
await assertExplicitTelegramTargetDelivery({
home,
storePath,
deps,
payloads: [{ text: "hello from cron" }],
expectedTexts: ["hello from cron"],
});
});
});
it("delivers explicit targets directly with per-channel-peer session scoping", async () => {
await withTelegramAnnounceFixture(async ({ home, storePath, deps }) => {
mockAgentPayloads([{ text: "hello from cron" }]);

View File

@@ -666,6 +666,30 @@ describe("dispatchCronDelivery — double-announce guard", () => {
).toBe(false);
});
it("delivers explicit targets with direct text through the outbound adapter", async () => {
vi.mocked(countActiveDescendantRuns).mockReturnValue(0);
vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);
const params = makeBaseParams({ synthesizedText: "hello from cron" });
const state = await dispatchCronDelivery(params);
expect(state.result).toBeUndefined();
expect(state.delivered).toBe(true);
expect(state.deliveryAttempted).toBe(true);
expect(deliverOutboundPayloads).toHaveBeenCalledTimes(1);
expect(deliverOutboundPayloads).toHaveBeenCalledWith(
expect.objectContaining({
channel: "telegram",
to: "123456",
accountId: undefined,
threadId: undefined,
bestEffort: false,
skipQueue: true,
payloads: [{ text: "hello from cron" }],
}),
);
});
it("suppresses NO_REPLY payload with surrounding whitespace", async () => {
vi.mocked(countActiveDescendantRuns).mockReturnValue(0);
vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);