fix(tests): stabilize cron and blocked-flow assertions

This commit is contained in:
Vincent Koc 2026-03-31 17:58:41 +09:00
parent cd8d0881ed
commit f288ff3f9f
2 changed files with 21 additions and 1 deletions

View File

@ -1,8 +1,16 @@
import { describe, expect, it } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { CronJob } from "../../cron/types.js";
import type { RuntimeEnv } from "../../runtime.js";
import { getCronChannelOptions, printCronList } from "./shared.js";
const hoisted = vi.hoisted(() => ({
listChannelPluginsMock: vi.fn(),
}));
vi.mock("../../channels/plugins/index.js", () => ({
listChannelPlugins: hoisted.listChannelPluginsMock,
}));
function createRuntimeLogCapture(): { logs: string[]; runtime: RuntimeEnv } {
const logs: string[] = [];
const runtime = {
@ -31,6 +39,11 @@ function createBaseJob(overrides: Partial<CronJob>): CronJob {
}
describe("printCronList", () => {
beforeEach(() => {
hoisted.listChannelPluginsMock.mockReset();
hoisted.listChannelPluginsMock.mockReturnValue([]);
});
it("handles job with undefined sessionTarget (#9649)", () => {
const { logs, runtime } = createRuntimeLogCapture();
@ -170,6 +183,12 @@ describe("printCronList", () => {
describe("getCronChannelOptions", () => {
it("falls back to a generic channel placeholder when no plugins are loaded", () => {
hoisted.listChannelPluginsMock.mockReturnValue([]);
expect(getCronChannelOptions()).toBe("last|<channel-id>");
});
it("lists discovered channel plugin ids when plugins are available", () => {
hoisted.listChannelPluginsMock.mockReturnValue([{ id: "telegram" }, { id: "signal" }]);
expect(getCronChannelOptions()).toBe("last|telegram|signal");
});
});

View File

@ -224,6 +224,7 @@ describe("task-executor", () => {
task: "Patch file",
startedAt: 10,
deliveryStatus: "pending",
notifyPolicy: "silent",
});
completeTaskRunByRunId({