Tests: stabilize provider reload boundaries

This commit is contained in:
Peter Steinberger
2026-04-07 22:16:12 +08:00
parent bcaa195c52
commit cd92c6289c
2 changed files with 74 additions and 24 deletions

View File

@@ -38,6 +38,10 @@ const hoisted = vi.hoisted(() => {
stop: heartbeatStop,
updateConfig: heartbeatUpdateConfig,
}));
const activeEmbeddedRunCount = { value: 0 };
const totalPendingReplies = { value: 0 };
const totalQueueSize = { value: 0 };
const activeTaskCount = { value: 0 };
const startGmailWatcher = vi.fn(async () => ({ started: true }));
const stopGmailWatcher = vi.fn(async () => {});
@@ -135,6 +139,10 @@ const hoisted = vi.hoisted(() => {
heartbeatStop,
heartbeatUpdateConfig,
startHeartbeatRunner,
activeEmbeddedRunCount,
totalPendingReplies,
totalQueueSize,
activeTaskCount,
startGmailWatcher,
stopGmailWatcher,
providerManager,
@@ -159,6 +167,51 @@ vi.mock("../hooks/gmail-watcher.js", () => ({
stopGmailWatcher: hoisted.stopGmailWatcher,
}));
vi.mock("../agents/pi-embedded-runner/runs.js", async () => {
const actual = await vi.importActual<typeof import("../agents/pi-embedded-runner/runs.js")>(
"../agents/pi-embedded-runner/runs.js",
);
return {
...actual,
getActiveEmbeddedRunCount: () => hoisted.activeEmbeddedRunCount.value,
};
});
vi.mock("../auto-reply/reply/dispatcher-registry.js", async () => {
const actual = await vi.importActual<typeof import("../auto-reply/reply/dispatcher-registry.js")>(
"../auto-reply/reply/dispatcher-registry.js",
);
return {
...actual,
getTotalPendingReplies: () => hoisted.totalPendingReplies.value,
};
});
vi.mock("../process/command-queue.js", async () => {
const actual = await vi.importActual<typeof import("../process/command-queue.js")>(
"../process/command-queue.js",
);
return {
...actual,
getTotalQueueSize: () => hoisted.totalQueueSize.value,
};
});
vi.mock("../tasks/task-registry.maintenance.js", async () => {
const actual = await vi.importActual<typeof import("../tasks/task-registry.maintenance.js")>(
"../tasks/task-registry.maintenance.js",
);
return {
...actual,
getInspectableTaskRegistrySummary: () => ({
active: hoisted.activeTaskCount.value,
queued: 0,
completed: 0,
failed: 0,
}),
};
});
vi.mock("./server-channels.js", () => ({
createChannelManager: hoisted.createChannelManager,
}));
@@ -185,6 +238,10 @@ describe("gateway hot reload", () => {
process.env.OPENCLAW_SKIP_CHANNELS = "0";
delete process.env.OPENCLAW_SKIP_GMAIL_WATCHER;
delete process.env.OPENCLAW_SKIP_PROVIDERS;
hoisted.activeEmbeddedRunCount.value = 0;
hoisted.totalPendingReplies.value = 0;
hoisted.totalQueueSize.value = 0;
hoisted.activeTaskCount.value = 0;
});
afterEach(() => {

View File

@@ -21,22 +21,15 @@ const getOAuthProvidersMock = vi.hoisted(() =>
]),
);
const providerRuntimeContractModules = vi.hoisted(() => ({
anthropicIndexModuleUrl: new URL("../../../extensions/anthropic/index.ts", import.meta.url).href,
githubCopilotIndexModuleUrl: new URL(
"../../../extensions/github-copilot/index.ts",
import.meta.url,
).href,
googleIndexModuleUrl: new URL("../../../extensions/google/index.ts", import.meta.url).href,
openAIIndexModuleUrl: new URL("../../../extensions/openai/index.ts", import.meta.url).href,
openAICodexProviderRuntimeModuleId: new URL(
"../../../extensions/openai/openai-codex-provider.runtime.js",
import.meta.url,
).pathname,
openRouterIndexModuleUrl: new URL("../../../extensions/openrouter/index.ts", import.meta.url)
.href,
veniceIndexModuleUrl: new URL("../../../extensions/venice/index.ts", import.meta.url).href,
xAIIndexModuleUrl: new URL("../../../extensions/xai/index.ts", import.meta.url).href,
zaiIndexModuleUrl: new URL("../../../extensions/zai/index.ts", import.meta.url).href,
anthropicIndexModuleId: "../../../extensions/anthropic/index.ts",
githubCopilotIndexModuleId: "../../../extensions/github-copilot/index.ts",
googleIndexModuleId: "../../../extensions/google/index.ts",
openAIIndexModuleId: "../../../extensions/openai/index.ts",
openAICodexProviderRuntimeModuleId: "../../../extensions/openai/openai-codex-provider.runtime.js",
openRouterIndexModuleId: "../../../extensions/openrouter/index.ts",
veniceIndexModuleId: "../../../extensions/venice/index.ts",
xAIIndexModuleId: "../../../extensions/xai/index.ts",
zaiIndexModuleId: "../../../extensions/zai/index.ts",
}));
vi.mock("@mariozechner/pi-ai/oauth", async () => {
@@ -88,7 +81,7 @@ const PROVIDER_RUNTIME_CONTRACT_FIXTURES: readonly ProviderRuntimeContractFixtur
load: async () =>
await importBundledProviderPlugin<{
default: Parameters<typeof registerProviderPlugin>[0]["plugin"];
}>(providerRuntimeContractModules.anthropicIndexModuleUrl),
}>(providerRuntimeContractModules.anthropicIndexModuleId),
},
{
providerIds: ["github-copilot"],
@@ -97,7 +90,7 @@ const PROVIDER_RUNTIME_CONTRACT_FIXTURES: readonly ProviderRuntimeContractFixtur
load: async () =>
await importBundledProviderPlugin<{
default: Parameters<typeof registerProviderPlugin>[0]["plugin"];
}>(providerRuntimeContractModules.githubCopilotIndexModuleUrl),
}>(providerRuntimeContractModules.githubCopilotIndexModuleId),
},
{
providerIds: ["google", "google-gemini-cli"],
@@ -106,7 +99,7 @@ const PROVIDER_RUNTIME_CONTRACT_FIXTURES: readonly ProviderRuntimeContractFixtur
load: async () =>
await importBundledProviderPlugin<{
default: Parameters<typeof registerProviderPlugin>[0]["plugin"];
}>(providerRuntimeContractModules.googleIndexModuleUrl),
}>(providerRuntimeContractModules.googleIndexModuleId),
},
{
providerIds: ["openai", "openai-codex"],
@@ -115,7 +108,7 @@ const PROVIDER_RUNTIME_CONTRACT_FIXTURES: readonly ProviderRuntimeContractFixtur
load: async () =>
await importBundledProviderPlugin<{
default: Parameters<typeof registerProviderPlugin>[0]["plugin"];
}>(providerRuntimeContractModules.openAIIndexModuleUrl),
}>(providerRuntimeContractModules.openAIIndexModuleId),
},
{
providerIds: ["openrouter"],
@@ -124,7 +117,7 @@ const PROVIDER_RUNTIME_CONTRACT_FIXTURES: readonly ProviderRuntimeContractFixtur
load: async () =>
await importBundledProviderPlugin<{
default: Parameters<typeof registerProviderPlugin>[0]["plugin"];
}>(providerRuntimeContractModules.openRouterIndexModuleUrl),
}>(providerRuntimeContractModules.openRouterIndexModuleId),
},
{
providerIds: ["venice"],
@@ -133,7 +126,7 @@ const PROVIDER_RUNTIME_CONTRACT_FIXTURES: readonly ProviderRuntimeContractFixtur
load: async () =>
await importBundledProviderPlugin<{
default: Parameters<typeof registerProviderPlugin>[0]["plugin"];
}>(providerRuntimeContractModules.veniceIndexModuleUrl),
}>(providerRuntimeContractModules.veniceIndexModuleId),
},
{
providerIds: ["xai"],
@@ -142,7 +135,7 @@ const PROVIDER_RUNTIME_CONTRACT_FIXTURES: readonly ProviderRuntimeContractFixtur
load: async () =>
await importBundledProviderPlugin<{
default: Parameters<typeof registerProviderPlugin>[0]["plugin"];
}>(providerRuntimeContractModules.xAIIndexModuleUrl),
}>(providerRuntimeContractModules.xAIIndexModuleId),
},
{
providerIds: ["zai"],
@@ -151,7 +144,7 @@ const PROVIDER_RUNTIME_CONTRACT_FIXTURES: readonly ProviderRuntimeContractFixtur
load: async () =>
await importBundledProviderPlugin<{
default: Parameters<typeof registerProviderPlugin>[0]["plugin"];
}>(providerRuntimeContractModules.zaiIndexModuleUrl),
}>(providerRuntimeContractModules.zaiIndexModuleId),
},
] as const;