
























@@ -47,6 +47,7 @@ const hoisted = vi.hoisted(() => {
4747inCatalog: true,
4848}));
4949const ensureOpenClawModelsJson = vi.fn(async () => {});
50+const ensureRuntimePluginsLoaded = vi.fn();
5051const clearCurrentProviderAuthState = vi.fn();
5152const warmCurrentProviderAuthStateOffMainThread = vi.fn(
5253async (_cfg?: unknown, _options?: unknown) => {},
@@ -82,6 +83,7 @@ const hoisted = vi.hoisted(() => {
8283 loadModelCatalog,
8384 getModelRefStatus,
8485 ensureOpenClawModelsJson,
86+ ensureRuntimePluginsLoaded,
8587 clearCurrentProviderAuthState,
8688 warmCurrentProviderAuthStateOffMainThread,
8789 setAuthProfileFailureHook,
@@ -179,6 +181,10 @@ vi.mock("../agents/models-config.js", () => ({
179181ensureOpenClawModelsJson: hoisted.ensureOpenClawModelsJson,
180182}));
181183184+vi.mock("../agents/runtime-plugins.js", () => ({
185+ensureRuntimePluginsLoaded: hoisted.ensureRuntimePluginsLoaded,
186+}));
187+182188vi.mock("../agents/model-provider-auth.js", () => ({
183189clearCurrentProviderAuthState: hoisted.clearCurrentProviderAuthState,
184190warmCurrentProviderAuthStateOffMainThread: hoisted.warmCurrentProviderAuthStateOffMainThread,
@@ -294,6 +300,7 @@ describe("startGatewayPostAttachRuntime", () => {
294300});
295301hoisted.ensureOpenClawModelsJson.mockReset();
296302hoisted.ensureOpenClawModelsJson.mockResolvedValue(undefined);
303+hoisted.ensureRuntimePluginsLoaded.mockReset();
297304hoisted.clearCurrentProviderAuthState.mockClear();
298305hoisted.warmCurrentProviderAuthStateOffMainThread.mockReset();
299306hoisted.warmCurrentProviderAuthStateOffMainThread.mockResolvedValue(undefined);
@@ -926,7 +933,7 @@ describe("startGatewayPostAttachRuntime", () => {
926933await vi.advanceTimersToNextTimerAsync();
927934expect(postReadyRequestTurn).toHaveBeenCalledTimes(1);
928935expect(onPostReadySidecars.mock.calls[0]?.[0]).toHaveLength(0);
929-expect(onGatewayLifetimeSidecars.mock.calls[0]?.[0]).toHaveLength(1);
936+expect(onGatewayLifetimeSidecars.mock.calls[0]?.[0]).toHaveLength(2);
930937await vi.dynamicImportSettled();
931938await vi.waitFor(() => {
932939expect(hoisted.setAuthProfileFailureHook).toHaveBeenCalledTimes(1);
@@ -942,6 +949,34 @@ describe("startGatewayPostAttachRuntime", () => {
942949}
943950});
944951952+it("uses current config when agent runtime plugin prewarm runs", async () => {
953+const startupConfig = { marker: "startup" } as never;
954+const currentConfig = { marker: "current" } as never;
955+956+await startGatewayPostAttachRuntime({
957+ ...createPostAttachParams({
958+gatewayPluginConfigAtStart: startupConfig,
959+}),
960+providerAuthPrewarm: { enabled: false },
961+agentRuntimePluginPrewarm: {
962+enabled: true,
963+delayMs: 0,
964+getConfig: () => currentConfig,
965+},
966+});
967+968+await vi.waitFor(() => {
969+expect(hoisted.ensureRuntimePluginsLoaded).toHaveBeenCalledWith({
970+config: currentConfig,
971+workspaceDir: "/tmp/openclaw-workspace",
972+allowGatewaySubagentBinding: true,
973+});
974+});
975+expect(hoisted.ensureRuntimePluginsLoaded).not.toHaveBeenCalledWith(
976+expect.objectContaining({ config: startupConfig }),
977+);
978+});
979+945980it("keeps provider auth prewarm alive when Gmail post-ready sidecars stop", async () => {
946981vi.useFakeTimers();
947982const onPostReadySidecars = vi.fn();
@@ -985,7 +1020,7 @@ describe("startGatewayPostAttachRuntime", () => {
9851020| { stop: () => void }[]
9861021| undefined;
9871022expect(gmailSidecars).toHaveLength(1);
988-expect(lifetimeSidecars).toHaveLength(1);
1023+expect(lifetimeSidecars).toHaveLength(2);
98910249901025for (const sidecar of gmailSidecars ?? []) {
9911026sidecar.stop();
@@ -1045,7 +1080,7 @@ describe("startGatewayPostAttachRuntime", () => {
10451080| Array<{ stop: () => Promise<void> | void }>
10461081| undefined;
10471082expect(gmailSidecars).toHaveLength(1);
1048-expect(lifetimeSidecars).toHaveLength(1);
1083+expect(lifetimeSidecars).toHaveLength(2);
1049108410501085await vi.waitFor(() => {
10511086expect(hoisted.transcriptsAutoStartService.start).toHaveBeenCalledTimes(1);
@@ -1056,7 +1091,9 @@ describe("startGatewayPostAttachRuntime", () => {
10561091}
10571092expect(hoisted.transcriptsAutoStartService.stop).not.toHaveBeenCalled();
105810931059-await lifetimeSidecars?.[0]?.stop();
1094+for (const sidecar of lifetimeSidecars ?? []) {
1095+await sidecar.stop();
1096+}
10601097expect(hoisted.transcriptsAutoStartService.stop).toHaveBeenCalledTimes(1);
10611098});
10621099@@ -1440,7 +1477,7 @@ describe("startGatewayPostAttachRuntime", () => {
14401477name: "sidecars.ready",
14411478metrics: [
14421479["loadedPluginCount", 2],
1443-["postReadySidecarCount", 0],
1480+["postReadySidecarCount", 1],
14441481],
14451482});
14461483});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。