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.
This commit is contained in:
Peter Steinberger
2026-08-16 22:56:01 -07:00
committed by GitHub
parent f9b1ccc4fa
commit e84a45e28e
21 changed files with 50 additions and 59 deletions
+2 -2
View File
@@ -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());
+3 -3
View File
@@ -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", () => {
@@ -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(
@@ -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();
+1 -2
View File
@@ -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();
@@ -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",
+2 -2
View File
@@ -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();
});
@@ -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 });
}
+2 -3
View File
@@ -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<typeof getCurrentPluginMetadataSnapshot> = 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 {
@@ -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", () => {
+2 -2
View File
@@ -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();
}
});
});
+1 -2
View File
@@ -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) {
+2 -2
View File
@@ -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();
});
@@ -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", () => {
@@ -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,
+2 -2
View File
@@ -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);
});
@@ -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();
});
+2 -2
View File
@@ -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();
@@ -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({
+4 -4
View File
@@ -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;
@@ -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();