























@@ -398,6 +398,45 @@ describe("startGatewayPostAttachRuntime", () => {
398398params.deps.cron = reloadedCron as never;
399399expect(getCron()).toBe(reloadedCron);
400400});
401+402+it("resolves gateway_start cron from the live runtime getter before deps fallback", async () => {
403+const runGatewayStart = vi.fn<
404+(event: PluginHookGatewayStartEvent, ctx: PluginHookGatewayContext) => Promise<void>
405+>(async () => undefined);
406+const hookRunner = {
407+hasHooks: vi.fn((hookName: string) => hookName === "gateway_start"),
408+ runGatewayStart,
409+};
410+const depsCron = { list: vi.fn(), add: vi.fn(), update: vi.fn(), remove: vi.fn() };
411+const liveCron = { list: vi.fn(), add: vi.fn(), update: vi.fn(), remove: vi.fn() };
412+const reloadedCron = { list: vi.fn(), add: vi.fn(), update: vi.fn(), remove: vi.fn() };
413+let currentLiveCron = liveCron;
414+const params = createPostAttachParams({
415+deps: { cron: depsCron } as never,
416+getCronService: () => currentLiveCron,
417+});
418+419+await startGatewayPostAttachRuntime(
420+params,
421+createPostAttachRuntimeDeps({
422+getGlobalHookRunner: vi.fn(async () => hookRunner as never),
423+}),
424+);
425+426+await vi.waitFor(() => {
427+expect(runGatewayStart).toHaveBeenCalledTimes(1);
428+});
429+430+const ctx = runGatewayStart.mock.calls[0]?.[1];
431+if (!ctx?.getCron) {
432+throw new Error("gateway_start context did not expose getCron");
433+}
434+expect(ctx.getCron()).toBe(liveCron);
435+436+params.deps.cron = depsCron as never;
437+currentLiveCron = reloadedCron;
438+expect(ctx.getCron()).toBe(reloadedCron);
439+});
401440});
402441403442function createPostAttachRuntimeDeps(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。