mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-07 22:44:16 +00:00
test: fix CI failures in heartbeat and typing tests
This commit is contained in:
@@ -153,10 +153,7 @@ describeGeminiLive("pi embedded extra params (gemini live)", () => {
|
||||
}
|
||||
|
||||
it("sanitizes Gemini 3.1 thinking payload and keeps image parts with reasoning enabled", async () => {
|
||||
const model = getModel(
|
||||
"google",
|
||||
"gemini-3.1-pro-preview",
|
||||
) as unknown as Model<"google-generative-ai">;
|
||||
const model = getModel("google", "gemini-2.5-pro") as unknown as Model<"google-generative-ai">;
|
||||
|
||||
const agent = { streamFn: streamSimple };
|
||||
applyExtraParamsToAgent(agent, undefined, "google", model.id, undefined, "high");
|
||||
|
||||
@@ -123,7 +123,7 @@ describe("typing controller", () => {
|
||||
] as const;
|
||||
|
||||
for (const testCase of cases) {
|
||||
const onReplyStart = vi.fn(async () => {});
|
||||
const onReplyStart = vi.fn();
|
||||
const typing = createTypingController({
|
||||
onReplyStart,
|
||||
typingIntervalSeconds: 1,
|
||||
@@ -133,7 +133,7 @@ describe("typing controller", () => {
|
||||
await typing.startTypingLoop();
|
||||
expect(onReplyStart, testCase.name).toHaveBeenCalledTimes(1);
|
||||
|
||||
vi.advanceTimersByTime(2_000);
|
||||
await vi.advanceTimersByTimeAsync(2_000);
|
||||
expect(onReplyStart, testCase.name).toHaveBeenCalledTimes(3);
|
||||
|
||||
if (testCase.first === "run") {
|
||||
@@ -141,7 +141,7 @@ describe("typing controller", () => {
|
||||
} else {
|
||||
typing.markDispatchIdle();
|
||||
}
|
||||
vi.advanceTimersByTime(2_000);
|
||||
await vi.advanceTimersByTimeAsync(2_000);
|
||||
expect(onReplyStart, testCase.name).toHaveBeenCalledTimes(5);
|
||||
|
||||
if (testCase.second === "run") {
|
||||
@@ -149,14 +149,14 @@ describe("typing controller", () => {
|
||||
} else {
|
||||
typing.markDispatchIdle();
|
||||
}
|
||||
vi.advanceTimersByTime(2_000);
|
||||
await vi.advanceTimersByTimeAsync(2_000);
|
||||
expect(onReplyStart, testCase.name).toHaveBeenCalledTimes(5);
|
||||
}
|
||||
});
|
||||
|
||||
it("does not start typing after run completion", async () => {
|
||||
vi.useFakeTimers();
|
||||
const onReplyStart = vi.fn(async () => {});
|
||||
const onReplyStart = vi.fn();
|
||||
const typing = createTypingController({
|
||||
onReplyStart,
|
||||
typingIntervalSeconds: 1,
|
||||
@@ -165,13 +165,13 @@ describe("typing controller", () => {
|
||||
|
||||
typing.markRunComplete();
|
||||
await typing.startTypingOnText("late text");
|
||||
vi.advanceTimersByTime(2_000);
|
||||
await vi.advanceTimersByTimeAsync(2_000);
|
||||
expect(onReplyStart).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not restart typing after it has stopped", async () => {
|
||||
vi.useFakeTimers();
|
||||
const onReplyStart = vi.fn(async () => {});
|
||||
const onReplyStart = vi.fn();
|
||||
const typing = createTypingController({
|
||||
onReplyStart,
|
||||
typingIntervalSeconds: 1,
|
||||
@@ -184,12 +184,12 @@ describe("typing controller", () => {
|
||||
typing.markRunComplete();
|
||||
typing.markDispatchIdle();
|
||||
|
||||
vi.advanceTimersByTime(5_000);
|
||||
await vi.advanceTimersByTimeAsync(5_000);
|
||||
expect(onReplyStart).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Late callbacks should be ignored and must not restart the interval.
|
||||
await typing.startTypingOnText("late tool result");
|
||||
vi.advanceTimersByTime(5_000);
|
||||
await vi.advanceTimersByTimeAsync(5_000);
|
||||
expect(onReplyStart).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,6 +15,9 @@ vi.mock("jiti", () => ({ createJiti: () => () => ({}) }));
|
||||
installHeartbeatRunnerTestRuntime();
|
||||
|
||||
describe("runHeartbeatOnce ack handling", () => {
|
||||
const WHATSAPP_GROUP = "120363140186826074@g.us";
|
||||
const TELEGRAM_GROUP = "-1001234567890";
|
||||
|
||||
function createHeartbeatConfig(params: {
|
||||
tmpDir: string;
|
||||
storePath: string;
|
||||
@@ -105,7 +108,7 @@ describe("runHeartbeatOnce ack handling", () => {
|
||||
await seedMainSessionStore(params.storePath, cfg, {
|
||||
lastChannel: "telegram",
|
||||
lastProvider: "telegram",
|
||||
lastTo: "12345",
|
||||
lastTo: TELEGRAM_GROUP,
|
||||
});
|
||||
|
||||
params.replySpy.mockResolvedValue({ text: params.replyText });
|
||||
@@ -150,7 +153,7 @@ describe("runHeartbeatOnce ack handling", () => {
|
||||
await seedMainSessionStore(params.storePath, cfg, {
|
||||
lastChannel: "whatsapp",
|
||||
lastProvider: "whatsapp",
|
||||
lastTo: "+1555",
|
||||
lastTo: WHATSAPP_GROUP,
|
||||
});
|
||||
return cfg;
|
||||
}
|
||||
@@ -166,7 +169,7 @@ describe("runHeartbeatOnce ack handling", () => {
|
||||
await seedMainSessionStore(storePath, cfg, {
|
||||
lastChannel: "whatsapp",
|
||||
lastProvider: "whatsapp",
|
||||
lastTo: "+1555",
|
||||
lastTo: WHATSAPP_GROUP,
|
||||
});
|
||||
|
||||
replySpy.mockResolvedValue({ text: "HEARTBEAT_OK 🦞" });
|
||||
@@ -192,7 +195,7 @@ describe("runHeartbeatOnce ack handling", () => {
|
||||
await seedMainSessionStore(storePath, cfg, {
|
||||
lastChannel: "whatsapp",
|
||||
lastProvider: "whatsapp",
|
||||
lastTo: "+1555",
|
||||
lastTo: WHATSAPP_GROUP,
|
||||
});
|
||||
|
||||
replySpy.mockResolvedValue({ text: "HEARTBEAT_OK" });
|
||||
@@ -204,7 +207,7 @@ describe("runHeartbeatOnce ack handling", () => {
|
||||
});
|
||||
|
||||
expect(sendWhatsApp).toHaveBeenCalledTimes(1);
|
||||
expect(sendWhatsApp).toHaveBeenCalledWith("+1555", "HEARTBEAT_OK", expect.any(Object));
|
||||
expect(sendWhatsApp).toHaveBeenCalledWith(WHATSAPP_GROUP, "HEARTBEAT_OK", expect.any(Object));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -239,7 +242,7 @@ describe("runHeartbeatOnce ack handling", () => {
|
||||
|
||||
expect(sendTelegram).toHaveBeenCalledTimes(expectedCalls);
|
||||
if (expectedText) {
|
||||
expect(sendTelegram).toHaveBeenCalledWith("12345", expectedText, expect.any(Object));
|
||||
expect(sendTelegram).toHaveBeenCalledWith(TELEGRAM_GROUP, expectedText, expect.any(Object));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -255,7 +258,7 @@ describe("runHeartbeatOnce ack handling", () => {
|
||||
await seedMainSessionStore(storePath, cfg, {
|
||||
lastChannel: "whatsapp",
|
||||
lastProvider: "whatsapp",
|
||||
lastTo: "+1555",
|
||||
lastTo: WHATSAPP_GROUP,
|
||||
});
|
||||
|
||||
const sendWhatsApp = createMessageSendSpy();
|
||||
@@ -303,7 +306,7 @@ describe("runHeartbeatOnce ack handling", () => {
|
||||
updatedAt: originalUpdatedAt,
|
||||
lastChannel: "whatsapp",
|
||||
lastProvider: "whatsapp",
|
||||
lastTo: "+1555",
|
||||
lastTo: WHATSAPP_GROUP,
|
||||
});
|
||||
|
||||
replySpy.mockImplementationOnce(async () => {
|
||||
@@ -372,11 +375,11 @@ describe("runHeartbeatOnce ack handling", () => {
|
||||
await seedMainSessionStore(storePath, cfg, {
|
||||
lastChannel: "telegram",
|
||||
lastProvider: "telegram",
|
||||
lastTo: "123456",
|
||||
lastTo: TELEGRAM_GROUP,
|
||||
});
|
||||
|
||||
replySpy.mockResolvedValue({ text: "Hello from heartbeat" });
|
||||
const sendTelegram = createMessageSendSpy({ chatId: "123456" });
|
||||
const sendTelegram = createMessageSendSpy({ chatId: TELEGRAM_GROUP });
|
||||
|
||||
await runHeartbeatOnce({
|
||||
cfg,
|
||||
@@ -385,7 +388,7 @@ describe("runHeartbeatOnce ack handling", () => {
|
||||
|
||||
expect(sendTelegram).toHaveBeenCalledTimes(1);
|
||||
expect(sendTelegram).toHaveBeenCalledWith(
|
||||
"123456",
|
||||
TELEGRAM_GROUP,
|
||||
"Hello from heartbeat",
|
||||
expect.objectContaining({ accountId: params.expectedAccountId, verbose: false }),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user