























@@ -33,14 +33,26 @@ function expectQueuedRunAck(result: unknown) {
3333expect(typeof ack.runId).toBe("string");
3434}
353536+function requireMockCall(
37+mock: { mock: { calls: unknown[][] } },
38+callIndex: number,
39+label: string,
40+): unknown[] {
41+const call = mock.mock.calls.at(callIndex);
42+if (!call) {
43+throw new Error(`expected ${label} call ${callIndex}`);
44+}
45+return call;
46+}
47+3648function expectIsolatedRunJobId(
3749runIsolatedAgentJob: ReturnType<typeof vi.fn>,
3850callIndex: number,
3951jobId: string,
4052) {
41-const params = runIsolatedAgentJob.mock.calls[callIndex]?.[0] as
42-| { job?: { id?: string } }
43- | undefined;
53+const [params] = requireMockCall(runIsolatedAgentJob, callIndex, "runIsolatedAgentJob") as [
54+{ job?: { id?: string } }?,
55+];
4456expect(params?.job?.id).toBe(jobId);
4557}
4658@@ -326,9 +338,10 @@ describe("cron service ops regressions", () => {
326338const result = await run(state, "stale-running", "force");
327339expect(result).toEqual({ ok: true, ran: true });
328340expect(enqueueSystemEvent).toHaveBeenCalledTimes(1);
329-const enqueueCall = enqueueSystemEvent.mock.calls[0];
330-expect(enqueueCall).toBeDefined();
331-const [text, options] = enqueueCall as [string, { agentId?: unknown }?];
341+const [text, options] = requireMockCall(enqueueSystemEvent, 0, "enqueueSystemEvent") as [
342+string,
343+{ agentId?: unknown }?,
344+];
332345expect(text).toBe("stale-running");
333346expect(options?.agentId).toBeUndefined();
334347});
@@ -447,7 +460,7 @@ describe("cron service ops regressions", () => {
447460448461await errorLogged.promise;
449462expect(log.error).toHaveBeenCalledTimes(1);
450-expect(log.error.mock.calls[0]?.[1]).toBe(
463+expect(requireMockCall(log.error, 0, "logger error")[1]).toBe(
451464"cron: queued manual run background execution failed",
452465);
453466此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。