mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 16:06:16 +00:00
test: stabilize gateway background tests
This commit is contained in:
@@ -378,11 +378,16 @@ describe("gateway server agent", () => {
|
||||
const spy = vi.mocked(agentCommand);
|
||||
const calls = spy.mock.calls;
|
||||
const callsBefore = calls.length;
|
||||
const res = await rpcReq(ws, "agent", {
|
||||
message: "/new",
|
||||
sessionKey: "main",
|
||||
idempotencyKey: "idem-agent-new",
|
||||
});
|
||||
const res = await rpcReq(
|
||||
ws,
|
||||
"agent",
|
||||
{
|
||||
message: "/new",
|
||||
sessionKey: "main",
|
||||
idempotencyKey: "idem-agent-new",
|
||||
},
|
||||
20_000,
|
||||
);
|
||||
expect(res.ok).toBe(true);
|
||||
|
||||
await vi.waitFor(() => expect(calls.length).toBeGreaterThan(callsBefore));
|
||||
|
||||
@@ -25,6 +25,7 @@ const fetchWithSsrFGuardMock = vi.hoisted(() =>
|
||||
);
|
||||
|
||||
const sendFailureNotificationAnnounceMock = vi.hoisted(() => vi.fn(async () => undefined));
|
||||
const closeTrackedBrowserTabsForSessionsMock = vi.hoisted(() => vi.fn(async () => 0));
|
||||
|
||||
vi.mock("../infra/net/fetch-guard.js", () => ({
|
||||
fetchWithSsrFGuard: (...args: unknown[]) =>
|
||||
@@ -48,6 +49,10 @@ vi.mock("../cron/delivery.js", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../plugin-sdk/browser-maintenance.js", () => ({
|
||||
closeTrackedBrowserTabsForSessions: closeTrackedBrowserTabsForSessionsMock,
|
||||
}));
|
||||
|
||||
installGatewayTestHooks({ scope: "suite" });
|
||||
const CRON_WAIT_TIMEOUT_MS = 3_000;
|
||||
const EMPTY_CRON_STORE_CONTENT = JSON.stringify({ version: 1, jobs: [] });
|
||||
@@ -246,6 +251,7 @@ describe("gateway server cron", () => {
|
||||
// Keep polling helpers deterministic even if other tests left fake timers enabled.
|
||||
vi.useRealTimers();
|
||||
sendFailureNotificationAnnounceMock.mockClear();
|
||||
closeTrackedBrowserTabsForSessionsMock.mockClear();
|
||||
});
|
||||
|
||||
test("handles cron CRUD, normalization, and patch semantics", { timeout: 45_000 }, async () => {
|
||||
@@ -692,16 +698,16 @@ describe("gateway server cron", () => {
|
||||
ws,
|
||||
(payload) => payload?.jobId === jobId && payload?.action === "started",
|
||||
);
|
||||
const finishedRun = waitForCronEvent(
|
||||
ws,
|
||||
(payload) => payload?.jobId === jobId && payload?.action === "finished",
|
||||
);
|
||||
const runRes = await rpcReq(ws, "cron.run", { id: jobId, mode: "force" }, 1_000);
|
||||
expect(runRes.ok).toBe(true);
|
||||
expect(runRes.payload).toEqual({ ok: true, enqueued: true, runId: expect.any(String) });
|
||||
await startedRun;
|
||||
expect(cronIsolatedRun).toHaveBeenCalledTimes(1);
|
||||
|
||||
const finishedRun = waitForCronEvent(
|
||||
ws,
|
||||
(payload) => payload?.jobId === jobId && payload?.action === "finished",
|
||||
);
|
||||
resolveRun?.({ status: "ok", summary: "background finished" });
|
||||
const finishedPayload = await finishedRun;
|
||||
expect(finishedPayload).toMatchObject({
|
||||
|
||||
Reference in New Issue
Block a user