From e84a45e28ecf44dec085b94589c3fcc5c17c12cb Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 16 Aug 2026 22:56:01 -0700 Subject: [PATCH] test(plugins): reset the whole plugin metadata lifecycle between tests (#125037) * test(plugins): reset the whole plugin metadata lifecycle between tests Tests that touch process-global plugin metadata were calling clearCurrentPluginMetadataSnapshot, which drops the published snapshot but leaves every memo registered through registerPluginMetadataProcessMemoLifecycleClear populated. Those memos are not content-addressed: setup-registry keys its cached registries on resolveCurrentSetupSnapshotCacheId, which returns the literal "nosnap" whenever no snapshot is published. A registry cached by one file is therefore served to any later file that also runs without a snapshot. The affected lanes run isolate: false, so that is a live cross-file leak. It matches the observed failure shape, e.g. setup-registry descriptor lookup failing with "Cannot read properties of undefined (reading 'flatMap')" only inside a shared worker and never in isolation. Switch these files to clearPluginMetadataLifecycleCaches, which clears the snapshot and every registered memo as one lifecycle unit. Two files kept both calls; the narrow one is now redundant and removed. current-plugin-metadata-snapshot.test.ts keeps the narrow primitive: it is the unit test for that function. No production change. * test(plugins): drop the duplicate lifecycle reset in provider-runtime hooks The blanket clearCurrentPluginMetadataSnapshot -> clearPluginMetadataLifecycleCaches substitution collided with the lifecycle call this suite already made, so each test boundary ran every registered metadata-cache clear twice. Keep one call per hook. Addresses the ClawSweeper P3 finding on #125037. --- src/agents/agent-model-discovery.test.ts | 4 ++-- src/agents/model-ref-shared.test.ts | 6 +++--- src/agents/models-config.write-serialization.test.ts | 8 ++++---- src/agents/openclaw-tools.media-factory-plan.test.ts | 6 +++--- src/agents/provider-auth-aliases.test.ts | 3 +-- .../subagents/announce/subagent-announce.live.test.ts | 10 +++++----- src/agents/tools/video-generate-tool.test.ts | 4 ++-- ...missing-configured-plugin-install.load-path.test.ts | 4 ++-- src/commands/models/list.status.test.ts | 5 ++--- src/gateway/server-startup-minimal-boot.test.ts | 4 ++-- src/infra/dotenv-workspace-blocklist.test.ts | 4 ++-- src/plugin-sdk/facade-runtime.test.ts | 3 +-- src/plugins/activation-context.test.ts | 4 ++-- src/plugins/capability-provider-runtime.test.ts | 5 +---- ...gin-registry-contributions.current-snapshot.test.ts | 6 +++--- src/plugins/plugin-registry-snapshot.test.ts | 4 ++-- .../providers.runtime.consult-current-snapshot.test.ts | 3 --- src/plugins/setup-registry.runtime.test.ts | 4 ++-- src/plugins/status-effective-plugin-discovery.test.ts | 10 +++++----- src/plugins/tools.optional.test.ts | 8 ++++---- src/skills/loading/workspace-skill-loader.test.ts | 4 ++-- 21 files changed, 50 insertions(+), 59 deletions(-) diff --git a/src/agents/agent-model-discovery.test.ts b/src/agents/agent-model-discovery.test.ts index 797c32aad279..240dfb22769c 100644 --- a/src/agents/agent-model-discovery.test.ts +++ b/src/agents/agent-model-discovery.test.ts @@ -4,7 +4,7 @@ import os from "node:os"; import path from "node:path"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/types.openclaw.js"; -import { clearCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-state.js"; +import { clearPluginMetadataLifecycleCaches } from "../plugins/plugin-metadata-lifecycle.js"; import { discoverAuthStorage, discoverModels, @@ -17,7 +17,7 @@ import { // The ambient plugin metadata snapshot is cleared for the same reason. beforeEach(() => { vi.stubEnv("OPENCLAW_DISABLE_BUNDLED_PLUGINS", "1"); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); }); afterEach(() => vi.unstubAllEnvs()); diff --git a/src/agents/model-ref-shared.test.ts b/src/agents/model-ref-shared.test.ts index 2b491afcbed0..97a6850fd660 100644 --- a/src/agents/model-ref-shared.test.ts +++ b/src/agents/model-ref-shared.test.ts @@ -1,18 +1,18 @@ // Documents provider/model id normalization from built-ins and plugin manifests. import { afterEach, beforeEach, describe, expect, it } from "vitest"; import { setCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-state.js"; +import { clearPluginMetadataLifecycleCaches } from "../plugins/plugin-metadata-lifecycle.js"; import { normalizeConfiguredProviderCatalogModelId, normalizeStaticProviderModelId, } from "./model-ref-shared.js"; beforeEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); }); afterEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); }); describe("normalizeStaticProviderModelId", () => { diff --git a/src/agents/models-config.write-serialization.test.ts b/src/agents/models-config.write-serialization.test.ts index 27b107459627..ed4b02cf302a 100644 --- a/src/agents/models-config.write-serialization.test.ts +++ b/src/agents/models-config.write-serialization.test.ts @@ -58,7 +58,7 @@ installModelsConfigTestHooks(); let ensureOpenClawModelsJson: typeof import("./models-config.js").ensureOpenClawModelsJson; let planOpenClawModelsJsonSource: typeof import("./models-config.js").planOpenClawModelsJsonSource; -let clearCurrentPluginMetadataSnapshot: typeof import("../plugins/current-plugin-metadata-state.js").clearCurrentPluginMetadataSnapshot; +let clearPluginMetadataLifecycleCaches: typeof import("../plugins/plugin-metadata-lifecycle.js").clearPluginMetadataLifecycleCaches; let setCurrentPluginMetadataSnapshot: typeof import("../plugins/current-plugin-metadata-snapshot.js").setCurrentPluginMetadataSnapshot; function createPluginMetadataSnapshot(workspaceDir: string): PluginMetadataSnapshot { @@ -161,14 +161,14 @@ beforeAll(async () => { }; }); ({ ensureOpenClawModelsJson, planOpenClawModelsJsonSource } = await import("./models-config.js")); - ({ clearCurrentPluginMetadataSnapshot } = - await import("../plugins/current-plugin-metadata-state.js")); + ({ clearPluginMetadataLifecycleCaches } = + await import("../plugins/plugin-metadata-lifecycle.js")); ({ setCurrentPluginMetadataSnapshot } = await import("../plugins/current-plugin-metadata-snapshot.js")); }); beforeEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); writePrivateStoreTextWriteMock .mockReset() .mockImplementation( diff --git a/src/agents/openclaw-tools.media-factory-plan.test.ts b/src/agents/openclaw-tools.media-factory-plan.test.ts index 7fd3177022ea..6b443ba25926 100644 --- a/src/agents/openclaw-tools.media-factory-plan.test.ts +++ b/src/agents/openclaw-tools.media-factory-plan.test.ts @@ -6,10 +6,10 @@ import { getCurrentPluginMetadataSnapshot, setCurrentPluginMetadataSnapshot, } from "../plugins/current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-state.js"; import { resolveInstalledPluginIndexPolicyHash } from "../plugins/installed-plugin-index-policy.js"; import type { InstalledPluginIndexRecord } from "../plugins/installed-plugin-index.js"; import type { PluginManifestRecord } from "../plugins/manifest-registry.js"; +import { clearPluginMetadataLifecycleCaches } from "../plugins/plugin-metadata-lifecycle.js"; import type { PluginMetadataSnapshot } from "../plugins/plugin-metadata-snapshot.types.js"; import { resetPluginRuntimeStateForTest } from "../plugins/runtime.js"; import { clearSecretsRuntimeSnapshot } from "../secrets/runtime.js"; @@ -245,7 +245,7 @@ describe("optional media tool factory planning", () => { pluginToolAllowlist: ["image_generate", "video_generate", "music_generate"], }) ).map((tool) => tool.name); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); resetPluginRuntimeStateForTest(); clearSecretsRuntimeSnapshot(); vi.unstubAllEnvs(); @@ -257,7 +257,7 @@ describe("optional media tool factory planning", () => { }); afterEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); resetPluginRuntimeStateForTest(); clearSecretsRuntimeSnapshot(); vi.unstubAllEnvs(); diff --git a/src/agents/provider-auth-aliases.test.ts b/src/agents/provider-auth-aliases.test.ts index 1d597e7cd44c..bde5cb1e5e2b 100644 --- a/src/agents/provider-auth-aliases.test.ts +++ b/src/agents/provider-auth-aliases.test.ts @@ -50,7 +50,6 @@ vi.mock("../plugins/provider-runtime.js", () => ({ })); import { setCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-state.js"; import { resolveInstalledPluginIndexPolicyHash } from "../plugins/installed-plugin-index-policy.js"; import type { InstalledPluginIndexRecord } from "../plugins/installed-plugin-index.js"; import type { PluginManifestRecord } from "../plugins/manifest-registry.js"; @@ -143,7 +142,7 @@ function createPluginMetadataSnapshot(params: { describe("provider auth aliases", () => { beforeEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); resetProviderAuthAliasMapCacheForTest(); pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex.mockReset(); pluginRegistryMocks.loadPluginManifestRegistryForPluginRegistry.mockReset(); diff --git a/src/agents/subagents/announce/subagent-announce.live.test.ts b/src/agents/subagents/announce/subagent-announce.live.test.ts index 273e90e08e76..ad03f843bed2 100644 --- a/src/agents/subagents/announce/subagent-announce.live.test.ts +++ b/src/agents/subagents/announce/subagent-announce.live.test.ts @@ -13,7 +13,7 @@ import { startGatewayServer, type GatewayServer } from "../../../gateway/server. import { extractPayloadText } from "../../../gateway/test-helpers.agent-results.js"; import { onAgentEvent, type AgentEventPayload } from "../../../infra/agent-events.js"; import { isTruthyEnvValue } from "../../../infra/env.js"; -import { clearCurrentPluginMetadataSnapshot } from "../../../plugins/current-plugin-metadata-state.js"; +import { clearPluginMetadataLifecycleCaches } from "../../../plugins/plugin-metadata-lifecycle.js"; import { createOpenClawTestState, type OpenClawTestState, @@ -260,7 +260,7 @@ describeLive("subagent announce live", () => { await server?.close({ reason: "subagent announce live test done" }).catch(() => undefined); await state?.cleanup().catch(() => undefined); clearRuntimeConfigSnapshot(); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); client = undefined; server = undefined; state = undefined; @@ -309,7 +309,7 @@ describeLive("subagent announce live", () => { }), ); clearRuntimeConfigSnapshot(); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); server = await startGatewayServer(port, { bind: "loopback", @@ -501,7 +501,7 @@ describeLive("subagent announce live", () => { }), ); clearRuntimeConfigSnapshot(); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); server = await startGatewayServer(port, { bind: "loopback", @@ -717,7 +717,7 @@ describeLive("subagent announce live", () => { }), ); clearRuntimeConfigSnapshot(); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); server = await startGatewayServer(port, { bind: "loopback", diff --git a/src/agents/tools/video-generate-tool.test.ts b/src/agents/tools/video-generate-tool.test.ts index 783a20dbfb70..ced924b1c081 100644 --- a/src/agents/tools/video-generate-tool.test.ts +++ b/src/agents/tools/video-generate-tool.test.ts @@ -10,9 +10,9 @@ import { getCurrentPluginMetadataSnapshot, setCurrentPluginMetadataSnapshot, } from "../../plugins/current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "../../plugins/current-plugin-metadata-state.js"; import { resolveInstalledPluginIndexPolicyHash } from "../../plugins/installed-plugin-index-policy.js"; import type { PluginManifestRecord } from "../../plugins/manifest-registry.js"; +import { clearPluginMetadataLifecycleCaches } from "../../plugins/plugin-metadata-lifecycle.js"; import type { PluginMetadataSnapshot } from "../../plugins/plugin-metadata-snapshot.types.js"; import * as videoGenerationRuntime from "../../video-generation/runtime.js"; import type { AuthProfileStore } from "../auth-profiles/types.js"; @@ -363,7 +363,7 @@ describe("createVideoGenerateTool", () => { }); afterEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); vi.unstubAllEnvs(); }); diff --git a/src/commands/doctor/shared/missing-configured-plugin-install.load-path.test.ts b/src/commands/doctor/shared/missing-configured-plugin-install.load-path.test.ts index 14ce035ce3e0..573d60fd4aca 100644 --- a/src/commands/doctor/shared/missing-configured-plugin-install.load-path.test.ts +++ b/src/commands/doctor/shared/missing-configured-plugin-install.load-path.test.ts @@ -2,8 +2,8 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; -import { clearCurrentPluginMetadataSnapshot } from "../../../plugins/current-plugin-metadata-state.js"; import { loadManifestMetadataSnapshot } from "../../../plugins/manifest-contract-eligibility.js"; +import { clearPluginMetadataLifecycleCaches } from "../../../plugins/plugin-metadata-lifecycle.js"; import { detectConfiguredPluginInstallHealthIssues, repairMissingConfiguredPluginInstalls, @@ -12,7 +12,7 @@ import { const tempDirs: string[] = []; afterEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); for (const dir of tempDirs.splice(0)) { fs.rmSync(dir, { recursive: true, force: true }); } diff --git a/src/commands/models/list.status.test.ts b/src/commands/models/list.status.test.ts index 8817c74532b7..4d0a624f1cd1 100644 --- a/src/commands/models/list.status.test.ts +++ b/src/commands/models/list.status.test.ts @@ -6,7 +6,6 @@ import { getCurrentPluginMetadataSnapshot, setCurrentPluginMetadataSnapshot, } from "../../plugins/current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "../../plugins/current-plugin-metadata-state.js"; import { clearPluginMetadataLifecycleCaches } from "../../plugins/plugin-metadata-lifecycle.js"; import { withEnvAsync } from "../../test-utils/env.js"; @@ -637,7 +636,7 @@ describe("modelsStatusCommand auth overview", () => { const catalogStarted = createDeferred(); const releaseCatalog = createDeferred(); let replacement: ReturnType = undefined; - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); mocks.loadModelCatalog.mockImplementationOnce(async () => { replacement = getCurrentPluginMetadataSnapshot({ config, @@ -672,7 +671,7 @@ describe("modelsStatusCommand auth overview", () => { } finally { releaseCatalog.resolve(); await commandPromise.catch(() => {}); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); if (originalLoadModelCatalog) { mocks.loadModelCatalog.mockImplementation(originalLoadModelCatalog); } else { diff --git a/src/gateway/server-startup-minimal-boot.test.ts b/src/gateway/server-startup-minimal-boot.test.ts index a88b8f45c5ad..1d03bf933a4e 100644 --- a/src/gateway/server-startup-minimal-boot.test.ts +++ b/src/gateway/server-startup-minimal-boot.test.ts @@ -6,7 +6,7 @@ import { afterEach, describe, expect, it } from "vitest"; import { resetConfigRuntimeState } from "../config/runtime-snapshot.js"; import { createSubsystemLogger } from "../logging/subsystem.js"; -import { clearCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-state.js"; +import { clearPluginMetadataLifecycleCaches } from "../plugins/plugin-metadata-lifecycle.js"; import { createOpenClawTestState } from "../test-utils/openclaw-test-state.js"; import { getFreePort } from "../test-utils/ports.js"; @@ -17,7 +17,7 @@ const BOOT_BUDGET_MS = 90_000; afterEach(() => { resetConfigRuntimeState(); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); }); describe("gateway minimal boot smoke", () => { diff --git a/src/infra/dotenv-workspace-blocklist.test.ts b/src/infra/dotenv-workspace-blocklist.test.ts index 19442b87c2bb..8a41234fa1e9 100644 --- a/src/infra/dotenv-workspace-blocklist.test.ts +++ b/src/infra/dotenv-workspace-blocklist.test.ts @@ -4,9 +4,9 @@ import os from "node:os"; import path from "node:path"; import { describe, expect, it, vi } from "vitest"; import { setCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-state.js"; import { resolveInstalledPluginIndexPolicyHash } from "../plugins/installed-plugin-index-policy.js"; import type { PluginManifestRecord } from "../plugins/manifest-registry.js"; +import { clearPluginMetadataLifecycleCaches } from "../plugins/plugin-metadata-lifecycle.js"; import type { PluginMetadataSnapshot } from "../plugins/plugin-metadata-snapshot.types.js"; import { listKnownProviderAuthEnvVarNames } from "../secrets/provider-env-vars.js"; import { captureFullEnv, deleteTestEnvValue, setTestEnvValue } from "../test-utils/env.js"; @@ -137,7 +137,7 @@ describe("workspace .env blocklist completeness", () => { expect(process.env.RUNTIME_CLOUD_API_KEY).toBe("global-plugin-key"); } finally { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); } }); }); diff --git a/src/plugin-sdk/facade-runtime.test.ts b/src/plugin-sdk/facade-runtime.test.ts index 1b2774b2d71a..e9099842f493 100644 --- a/src/plugin-sdk/facade-runtime.test.ts +++ b/src/plugin-sdk/facade-runtime.test.ts @@ -6,7 +6,6 @@ import { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } from "../config/ import type { OpenClawConfig } from "../config/types.openclaw.js"; import { createPluginActivationSource, normalizePluginsConfig } from "../plugins/config-state.js"; import { setCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-state.js"; import { resolveInstalledPluginIndexPolicyHash } from "../plugins/installed-plugin-index-policy.js"; import { clearPluginMetadataLifecycleCaches } from "../plugins/plugin-metadata-lifecycle.js"; import type { PluginMetadataSnapshot } from "../plugins/plugin-metadata-snapshot.types.js"; @@ -97,7 +96,7 @@ afterEach(() => { fs.rmSync(dir, { recursive: true, force: true }); } clearRuntimeConfigSnapshot(); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); resetFacadeRuntimeStateForTest(); vi.doUnmock("../plugins/manifest-registry.js"); if (originalBundledPluginsDir === undefined) { diff --git a/src/plugins/activation-context.test.ts b/src/plugins/activation-context.test.ts index e67902719658..f348ec58d5fe 100644 --- a/src/plugins/activation-context.test.ts +++ b/src/plugins/activation-context.test.ts @@ -6,8 +6,8 @@ import { } from "../config/plugin-auto-enable.test-helpers.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import { setCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-state.js"; import type { PluginDiscoveryResult } from "./discovery.js"; +import { clearPluginMetadataLifecycleCaches } from "./plugin-metadata-lifecycle.js"; const applyPluginAutoEnableMock = vi.hoisted(() => vi.fn((params: { config?: OpenClawConfig }) => ({ @@ -34,7 +34,7 @@ import { } from "./activation-context.js"; afterEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); applyPluginAutoEnableMock.mockClear(); withBundledPluginEnablementCompatMock.mockClear(); }); diff --git a/src/plugins/capability-provider-runtime.test.ts b/src/plugins/capability-provider-runtime.test.ts index b3debb92a0b4..518af92d7e7a 100644 --- a/src/plugins/capability-provider-runtime.test.ts +++ b/src/plugins/capability-provider-runtime.test.ts @@ -128,7 +128,6 @@ vi.mock("./bundled-compat.js", () => ({ let resolvePluginCapabilityProviders: typeof import("./capability-provider-runtime.js").resolvePluginCapabilityProviders; let resolvePluginCapabilityProvider: typeof import("./capability-provider-runtime.js").resolvePluginCapabilityProvider; let prepareMediaCapabilityProviders: typeof import("./capability-provider-runtime.js").prepareMediaCapabilityProviders; -let clearCurrentPluginMetadataSnapshot: typeof import("./current-plugin-metadata-state.js").clearCurrentPluginMetadataSnapshot; let setCurrentPluginMetadataSnapshot: typeof import("./current-plugin-metadata-snapshot.js").setCurrentPluginMetadataSnapshot; let clearPluginMetadataLifecycleCaches: typeof import("./plugin-metadata-lifecycle.js").clearPluginMetadataLifecycleCaches; @@ -359,13 +358,11 @@ describe("resolvePluginCapabilityProviders", () => { resolvePluginCapabilityProvider, resolvePluginCapabilityProviders, } = await import("./capability-provider-runtime.js")); - ({ clearCurrentPluginMetadataSnapshot } = await import("./current-plugin-metadata-state.js")); ({ setCurrentPluginMetadataSnapshot } = await import("./current-plugin-metadata-snapshot.js")); ({ clearPluginMetadataLifecycleCaches } = await import("./plugin-metadata-lifecycle.js")); }); beforeEach(() => { - clearCurrentPluginMetadataSnapshot(); clearPluginMetadataLifecycleCaches(); mocks.resolveRuntimePluginRegistry.mockReset(); mocks.resolveRuntimePluginRegistry.mockReturnValue(undefined); @@ -386,7 +383,7 @@ describe("resolvePluginCapabilityProviders", () => { }); afterEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); }); it("resolves bundled capability plugins from the current metadata snapshot", () => { diff --git a/src/plugins/plugin-registry-contributions.current-snapshot.test.ts b/src/plugins/plugin-registry-contributions.current-snapshot.test.ts index 7ce26f6695c4..ff0651416b43 100644 --- a/src/plugins/plugin-registry-contributions.current-snapshot.test.ts +++ b/src/plugins/plugin-registry-contributions.current-snapshot.test.ts @@ -3,16 +3,16 @@ import fs from "node:fs"; import { afterEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import { setCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-state.js"; import { resolveInstalledPluginIndexPolicyHash } from "./installed-plugin-index-policy.js"; import type { InstalledPluginIndex } from "./installed-plugin-index.js"; import type { PluginManifestRecord } from "./manifest-registry.js"; +import { clearPluginMetadataLifecycleCaches } from "./plugin-metadata-lifecycle.js"; import type { PluginMetadataSnapshot } from "./plugin-metadata-snapshot.types.js"; import { loadPluginManifestRegistryForPluginRegistry } from "./plugin-registry-contributions.js"; import { loadPluginRegistrySnapshotWithMetadata } from "./plugin-registry-snapshot.js"; afterEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); }); function createPluginRecord(id: string, enabled: boolean): InstalledPluginIndex["plugins"][number] { @@ -176,7 +176,7 @@ describe("loadPluginManifestRegistryForPluginRegistry current snapshot", () => { }).plugins, ).toEqual([]); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); setCurrentPluginMetadataSnapshot( createSnapshot({ config, diff --git a/src/plugins/plugin-registry-snapshot.test.ts b/src/plugins/plugin-registry-snapshot.test.ts index ee11d73d95be..0af91b394451 100644 --- a/src/plugins/plugin-registry-snapshot.test.ts +++ b/src/plugins/plugin-registry-snapshot.test.ts @@ -5,7 +5,6 @@ import path from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import { setCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-state.js"; import type { PluginCandidate } from "./discovery.js"; import { loadInstalledPluginIndexInstallRecordsSync } from "./installed-plugin-index-records.js"; import { writePersistedInstalledPluginIndexSync } from "./installed-plugin-index-store.js"; @@ -16,6 +15,7 @@ import { } from "./installed-plugin-index.js"; import { markRetainedManagedNpmInstall } from "./managed-npm-retention.js"; import { loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed.js"; +import { clearPluginMetadataLifecycleCaches } from "./plugin-metadata-lifecycle.js"; import { loadPluginMetadataSnapshot } from "./plugin-metadata-snapshot.js"; import type { PluginMetadataSnapshot } from "./plugin-metadata-snapshot.types.js"; import { loadPluginRegistrySnapshotWithMetadata } from "./plugin-registry-snapshot.js"; @@ -26,7 +26,7 @@ const tempDirs: string[] = []; afterEach(() => { vi.restoreAllMocks(); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); cleanupTrackedTempDirs(tempDirs); }); diff --git a/src/plugins/providers.runtime.consult-current-snapshot.test.ts b/src/plugins/providers.runtime.consult-current-snapshot.test.ts index 575095e10414..d0cb131cb282 100644 --- a/src/plugins/providers.runtime.consult-current-snapshot.test.ts +++ b/src/plugins/providers.runtime.consult-current-snapshot.test.ts @@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import { setCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-state.js"; import { resolveInstalledPluginIndexPolicyHash } from "./installed-plugin-index-policy.js"; import type { InstalledPluginIndex } from "./installed-plugin-index.js"; import type { PluginManifestRecord, PluginManifestRegistry } from "./manifest-registry.js"; @@ -118,14 +117,12 @@ describe("provider runtime consults the current plugin metadata snapshot", () => beforeEach(() => { resetPluginRuntimeStateForTest(); clearPluginMetadataLifecycleCaches(); - clearCurrentPluginMetadataSnapshot(); loadPluginRegistrySnapshotWithMetadata.mockReset(); loadPluginManifestRegistryForInstalledIndex.mockReset(); loadPluginManifestRegistryForInstalledIndex.mockReturnValue(makeManifestRegistry()); }); afterEach(() => { - clearCurrentPluginMetadataSnapshot(); clearPluginMetadataLifecycleCaches(); resetPluginRuntimeStateForTest(); }); diff --git a/src/plugins/setup-registry.runtime.test.ts b/src/plugins/setup-registry.runtime.test.ts index c996411b8101..01dbbfaa9b1f 100644 --- a/src/plugins/setup-registry.runtime.test.ts +++ b/src/plugins/setup-registry.runtime.test.ts @@ -1,9 +1,9 @@ // Verifies metadata-backed setup registry descriptor lookup. import { afterEach, describe, expect, it, vi } from "vitest"; import { setCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-state.js"; import { resolveInstalledPluginIndexPolicyHash } from "./installed-plugin-index-policy.js"; import type { InstalledPluginIndex } from "./installed-plugin-index.js"; +import { clearPluginMetadataLifecycleCaches } from "./plugin-metadata-lifecycle.js"; import type { PluginMetadataSnapshot } from "./plugin-metadata-snapshot.js"; import { createEmptyPluginRegistry } from "./registry-empty.js"; import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "./runtime.js"; @@ -39,7 +39,7 @@ vi.mock("./plugin-metadata-snapshot.js", async () => { }); afterEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); resetPluginRuntimeStateForTest(); loadPluginRegistrySnapshotMock.mockReset(); loadPluginManifestRegistryForInstalledIndexMock.mockReset(); diff --git a/src/plugins/status-effective-plugin-discovery.test.ts b/src/plugins/status-effective-plugin-discovery.test.ts index 018188e21f28..1f7be467dbaa 100644 --- a/src/plugins/status-effective-plugin-discovery.test.ts +++ b/src/plugins/status-effective-plugin-discovery.test.ts @@ -5,7 +5,7 @@ import os from "node:os"; import path from "node:path"; import { afterAll, afterEach, beforeEach, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/types.openclaw.js"; -import { clearCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-state.js"; +import { clearPluginMetadataLifecycleCaches } from "./plugin-metadata-lifecycle.js"; import type { PluginMetadataSnapshot } from "./plugin-metadata-snapshot.types.js"; import { createColdPluginFixture } from "./test-helpers/cold-plugin-fixtures.js"; @@ -90,14 +90,14 @@ function countResolve(metadataSnapshot: PluginMetadataSnapshot): { } beforeEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); vi.stubEnv("OPENCLAW_DISABLE_BUNDLED_PLUGINS", "1"); vi.stubEnv("OPENCLAW_HOME", path.join(tempRoot, "home")); vi.stubEnv("OPENCLAW_STATE_DIR", path.join(tempRoot, "state")); }); afterEach(() => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); }); afterAll(() => { @@ -123,7 +123,7 @@ it("only reuses a snapshot that answers for the whole config", () => { const env = process.env; const withoutSnapshot = resolveEffectivePluginIds({ config, env }); const full = countResolve(loadPluginMetadataSnapshot({ config, env })); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); // `recordPluginInstallSource` asks for one plugin's effective state, which scopes the // snapshot to that plugin and truncates its manifest set to that plugin alone. const scopedSnapshot = loadPluginMetadataSnapshot({ @@ -131,7 +131,7 @@ it("only reuses a snapshot that answers for the whole config", () => { env, pluginIds: ["other-plugin"], }); - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); const scoped = countResolve(scopedSnapshot); expect({ full: full.ids, scoped: scoped.ids }).toEqual({ diff --git a/src/plugins/tools.optional.test.ts b/src/plugins/tools.optional.test.ts index a6611bd1acee..91543cc026db 100644 --- a/src/plugins/tools.optional.test.ts +++ b/src/plugins/tools.optional.test.ts @@ -60,7 +60,7 @@ let resetPluginToolDescriptorCacheForTest: typeof import("./tools.test-fixtures. let getActivePluginRegistry: typeof import("./runtime.js").getActivePluginRegistry; let resetPluginRuntimeStateForTest: typeof import("./runtime.js").resetPluginRuntimeStateForTest; let setActivePluginRegistry: typeof import("./runtime.js").setActivePluginRegistry; -let clearCurrentPluginMetadataSnapshot: typeof import("./current-plugin-metadata-state.js").clearCurrentPluginMetadataSnapshot; +let clearPluginMetadataLifecycleCaches: typeof import("./plugin-metadata-lifecycle.js").clearPluginMetadataLifecycleCaches; let setCurrentPluginMetadataSnapshot: typeof import("./current-plugin-metadata-snapshot.js").setCurrentPluginMetadataSnapshot; let getPluginRuntimeGatewayRequestScope: typeof import("./runtime/gateway-request-scope.js").getPluginRuntimeGatewayRequestScope; let withPluginRuntimeGatewayRequestScope: typeof import("./runtime/gateway-request-scope.js").withPluginRuntimeGatewayRequestScope; @@ -550,7 +550,7 @@ describe("resolvePluginTools optional tools", () => { await import("./runtime.js")); ({ getPluginRuntimeGatewayRequestScope, withPluginRuntimeGatewayRequestScope } = await import("./runtime/gateway-request-scope.js")); - ({ clearCurrentPluginMetadataSnapshot } = await import("./current-plugin-metadata-state.js")); + ({ clearPluginMetadataLifecycleCaches } = await import("./plugin-metadata-lifecycle.js")); ({ setCurrentPluginMetadataSnapshot } = await import("./current-plugin-metadata-snapshot.js")); ({ resetPluginToolDescriptorCacheForTest } = await import("./tools.test-fixtures.js")); }); @@ -574,13 +574,13 @@ describe("resolvePluginTools optional tools", () => { return loadContextMocks.actualResolve(...(args as [never])); }); resetPluginRuntimeStateForTest?.(); - clearCurrentPluginMetadataSnapshot?.(); + clearPluginMetadataLifecycleCaches?.(); resetPluginToolDescriptorCacheForTest?.(); }); afterEach(() => { resetPluginRuntimeStateForTest?.(); - clearCurrentPluginMetadataSnapshot?.(); + clearPluginMetadataLifecycleCaches?.(); resetPluginToolDescriptorCacheForTest?.(); setLoggerOverride(null); loggingState.rawConsole = null; diff --git a/src/skills/loading/workspace-skill-loader.test.ts b/src/skills/loading/workspace-skill-loader.test.ts index 87646b1b7554..cd8f96e59521 100644 --- a/src/skills/loading/workspace-skill-loader.test.ts +++ b/src/skills/loading/workspace-skill-loader.test.ts @@ -8,12 +8,12 @@ import type { OpenClawConfig } from "../../config/types.openclaw.js"; import { resetLogger, setLoggerOverride } from "../../logging/logger.js"; import { loggingState } from "../../logging/state.js"; import { setCurrentPluginMetadataSnapshot } from "../../plugins/current-plugin-metadata-snapshot.js"; -import { clearCurrentPluginMetadataSnapshot } from "../../plugins/current-plugin-metadata-state.js"; import { resolveInstalledPluginIndexPolicyHash } from "../../plugins/installed-plugin-index-policy.js"; import type { PluginManifestRecord, PluginManifestRegistry, } from "../../plugins/manifest-registry.js"; +import { clearPluginMetadataLifecycleCaches } from "../../plugins/plugin-metadata-lifecycle.js"; import type { PluginMetadataSnapshot } from "../../plugins/plugin-metadata-snapshot.js"; import { writeSkill, writeWorkspaceSkills } from "../test-support/e2e-test-helpers.js"; import { @@ -209,7 +209,7 @@ beforeAll(async () => { }); afterEach(async () => { - clearCurrentPluginMetadataSnapshot(); + clearPluginMetadataLifecycleCaches(); setLoggerOverride(null); loggingState.rawConsole = null; resetLogger();