





















@@ -5,11 +5,13 @@ const hoisted = vi.hoisted(() => {
55stop: vi.fn(),
66updateConfig: vi.fn(),
77};
8+const stopModelPricingRefresh = vi.fn();
89return {
910 heartbeatRunner,
1011startHeartbeatRunner: vi.fn(() => heartbeatRunner),
1112startChannelHealthMonitor: vi.fn(() => ({ stop: vi.fn() })),
12-startGatewayModelPricingRefresh: vi.fn(() => vi.fn()),
13+ stopModelPricingRefresh,
14+startGatewayModelPricingRefresh: vi.fn(() => stopModelPricingRefresh),
1315loadModelPricingCacheModule: vi.fn(),
1416isVitestRuntimeEnv: vi.fn(() => false),
1517recoverPendingDeliveries: vi.fn(async () => undefined),
@@ -61,6 +63,7 @@ describe("server-runtime-services", () => {
6163hoisted.startHeartbeatRunner.mockClear();
6264hoisted.startChannelHealthMonitor.mockClear();
6365hoisted.startGatewayModelPricingRefresh.mockClear();
66+hoisted.stopModelPricingRefresh.mockClear();
6467hoisted.loadModelPricingCacheModule.mockClear();
6568hoisted.isVitestRuntimeEnv.mockReset().mockReturnValue(false);
6669hoisted.recoverPendingDeliveries.mockClear();
@@ -69,14 +72,13 @@ describe("server-runtime-services", () => {
6972});
70737174it("skips model pricing bootstrap import when pricing is disabled", async () => {
72-startGatewayRuntimeServices({
75+activateGatewayScheduledServices({
7376minimalTestGateway: false,
7477cfgAtStart: { models: { pricing: { enabled: false } } } as never,
75-channelManager: {
76-getRuntimeSnapshot: vi.fn(),
77-isHealthMonitorEnabled: vi.fn(),
78-isManuallyStopped: vi.fn(),
79-} as never,
78+deps: {} as never,
79+sessionDeliveryRecoveryMaxEnqueuedAt: 123,
80+cron: { start: vi.fn(async () => undefined) },
81+logCron: { error: vi.fn() },
8082log: createLog(),
8183});
8284@@ -86,7 +88,7 @@ describe("server-runtime-services", () => {
8688expect(hoisted.startGatewayModelPricingRefresh).not.toHaveBeenCalled();
8789});
889089-it("keeps scheduled services inert during initial runtime setup", async () => {
91+it("keeps scheduled services and pricing refresh inert during initial runtime setup", async () => {
9092const services = startGatewayRuntimeServices({
9193minimalTestGateway: false,
9294cfgAtStart: {} as never,
@@ -100,55 +102,62 @@ describe("server-runtime-services", () => {
100102101103expect(hoisted.startChannelHealthMonitor).toHaveBeenCalledTimes(1);
102104await vi.dynamicImportSettled();
103-expect(hoisted.startGatewayModelPricingRefresh).toHaveBeenCalledWith({ config: {} });
105+expect(hoisted.loadModelPricingCacheModule).not.toHaveBeenCalled();
106+expect(hoisted.startGatewayModelPricingRefresh).not.toHaveBeenCalled();
104107expect(hoisted.startHeartbeatRunner).not.toHaveBeenCalled();
105108expect(hoisted.recoverPendingDeliveries).not.toHaveBeenCalled();
106109107110services.heartbeatRunner.stop();
108111expect(hoisted.heartbeatRunner.stop).not.toHaveBeenCalled();
109112});
110113111-it("passes startup plugin lookup metadata to the initial pricing refresh", async () => {
114+it("starts model pricing refresh after scheduled services activate", async () => {
112115const pluginLookUpTable = {
113116index: { plugins: [] },
114117manifestRegistry: { plugins: [], diagnostics: [] },
115118};
119+const cron = { start: vi.fn(async () => undefined) };
120+const log = createLog();
116121117-startGatewayRuntimeServices({
122+const services = activateGatewayScheduledServices({
118123minimalTestGateway: false,
119124cfgAtStart: {} as never,
120-channelManager: {
121-getRuntimeSnapshot: vi.fn(),
122-isHealthMonitorEnabled: vi.fn(),
123-isManuallyStopped: vi.fn(),
124-} as never,
125-log: createLog(),
125+deps: {} as never,
126+sessionDeliveryRecoveryMaxEnqueuedAt: 123,
127+ cron,
128+logCron: { error: vi.fn() },
129+ log,
126130pluginLookUpTable: pluginLookUpTable as never,
127131});
128132133+expect(hoisted.startHeartbeatRunner).toHaveBeenCalledTimes(1);
134+expect(cron.start).toHaveBeenCalledTimes(1);
129135await vi.dynamicImportSettled();
130136expect(hoisted.startGatewayModelPricingRefresh).toHaveBeenCalledWith({
131137config: {},
132138 pluginLookUpTable,
133139});
140+services.stopModelPricingRefresh();
141+expect(hoisted.stopModelPricingRefresh).toHaveBeenCalledTimes(1);
134142});
135143136-it("does not start model pricing refresh after early stop", async () => {
137-const services = startGatewayRuntimeServices({
144+it("does not start model pricing refresh after scheduled services stop before import settles", async () => {
145+const cron = { start: vi.fn(async () => undefined) };
146+const services = activateGatewayScheduledServices({
138147minimalTestGateway: false,
139148cfgAtStart: {} as never,
140-channelManager: {
141-getRuntimeSnapshot: vi.fn(),
142-isHealthMonitorEnabled: vi.fn(),
143-isManuallyStopped: vi.fn(),
144-} as never,
149+deps: {} as never,
150+sessionDeliveryRecoveryMaxEnqueuedAt: 123,
151+ cron,
152+logCron: { error: vi.fn() },
145153log: createLog(),
146154});
147155148156services.stopModelPricingRefresh();
149157await vi.dynamicImportSettled();
150158151159expect(hoisted.startGatewayModelPricingRefresh).not.toHaveBeenCalled();
160+expect(hoisted.stopModelPricingRefresh).not.toHaveBeenCalled();
152161});
153162154163it("activates heartbeat, cron, and delivery recovery after sidecars are ready", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。