test(plugins): refresh fixture contracts (#122986)

This commit is contained in:
Vincent Koc
2026-08-13 12:30:34 +08:00
committed by GitHub
parent 095f3e1a44
commit 01b3ece441
4 changed files with 52 additions and 10 deletions
+9
View File
@@ -32,6 +32,15 @@ vi.mock("../channels/config-presence.js", () => ({
env: NodeJS.ProcessEnv,
options?: { includePersistedAuthState?: boolean },
) => listPotentialConfiguredChannelIds(config, env, options),
listPotentialConfiguredChannelPresenceSignals: (
config: OpenClawConfig,
env: NodeJS.ProcessEnv,
options?: { includePersistedAuthState?: boolean },
) =>
listPotentialConfiguredChannelIds(config, env, options).map((channelId: string) => ({
channelId,
source: "env" as const,
})),
listExplicitlyDisabledChannelIdsForConfig: (config: OpenClawConfig) =>
listExplicitlyDisabledChannelIdsForConfig(config),
}));
@@ -24,7 +24,11 @@ vi.mock("../loader.js", () => ({
}));
vi.mock("../../agents/agent-scope.js", () => ({
listAgentEntries: vi.fn<typeof import("../../agents/agent-scope.js").listAgentEntries>(() => []),
resolveAgentWorkspaceDir: () => "/resolved-workspace",
tryResolveConfiguredAgentWorkspaceDir: vi.fn<
typeof import("../../agents/agent-scope.js").tryResolveConfiguredAgentWorkspaceDir
>(() => "/resolved-workspace"),
resolveDefaultAgentId: () => "default",
}));
@@ -19,9 +19,16 @@ const mocks = vi.hoisted(() => ({
vi.fn<typeof import("../plugin-metadata-snapshot.js").resolvePluginMetadataSnapshot>(),
isPluginMetadataSnapshotCompatible:
vi.fn<typeof import("../plugin-metadata-snapshot.js").isPluginMetadataSnapshotCompatible>(),
rebasePluginMetadataSnapshotManifestRegistry: vi.fn<
typeof import("../plugin-metadata-snapshot.js").rebasePluginMetadataSnapshotManifestRegistry
>((snapshot) => snapshot),
listAgentEntries: vi.fn<typeof import("../../agents/agent-scope.js").listAgentEntries>(() => []),
resolveAgentWorkspaceDir: vi.fn<
typeof import("../../agents/agent-scope.js").resolveAgentWorkspaceDir
>(() => "/resolved-workspace"),
tryResolveConfiguredAgentWorkspaceDir: vi.fn<
typeof import("../../agents/agent-scope.js").tryResolveConfiguredAgentWorkspaceDir
>(() => "/resolved-workspace"),
resolveDefaultAgentId: vi.fn<typeof import("../../agents/agent-scope.js").resolveDefaultAgentId>(
() => "default",
),
@@ -63,11 +70,19 @@ vi.mock("../plugin-metadata-snapshot.js", () => ({
isPluginMetadataSnapshotCompatible: (
...args: Parameters<typeof mocks.isPluginMetadataSnapshotCompatible>
) => mocks.isPluginMetadataSnapshotCompatible(...args),
rebasePluginMetadataSnapshotManifestRegistry: (
...args: Parameters<typeof mocks.rebasePluginMetadataSnapshotManifestRegistry>
) => mocks.rebasePluginMetadataSnapshotManifestRegistry(...args),
}));
vi.mock("../../agents/agent-scope.js", () => ({
listAgentEntries: (...args: Parameters<typeof mocks.listAgentEntries>) =>
mocks.listAgentEntries(...args),
resolveAgentWorkspaceDir: (...args: Parameters<typeof mocks.resolveAgentWorkspaceDir>) =>
mocks.resolveAgentWorkspaceDir(...args),
tryResolveConfiguredAgentWorkspaceDir: (
...args: Parameters<typeof mocks.tryResolveConfiguredAgentWorkspaceDir>
) => mocks.tryResolveConfiguredAgentWorkspaceDir(...args),
resolveDefaultAgentId: (...args: Parameters<typeof mocks.resolveDefaultAgentId>) =>
mocks.resolveDefaultAgentId(...args),
}));
@@ -107,7 +122,10 @@ function requireLoadOptions(): Record<string, unknown> {
describe("ensurePluginRegistryLoaded", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.resolvePluginMetadataSnapshot.mockReset();
mocks.resolvePluginMetadataSnapshot.mockReset().mockReturnValue({
index: { installRecords: {}, plugins: [{ pluginId: "openai" }] },
manifestRegistry: { plugins: [], diagnostics: [] },
} as never);
mocks.isPluginMetadataSnapshotCompatible.mockReturnValue(true);
mocks.applyPluginAutoEnable.mockImplementation((params) => ({
config: params.config ?? {},
@@ -3,22 +3,23 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterAll, beforeEach, expect, it, vi } from "vitest";
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 type { PluginMetadataSnapshot } from "./plugin-metadata-snapshot.types.js";
import { createColdPluginFixture } from "./test-helpers/cold-plugin-fixtures.js";
const counters = vi.hoisted(() => ({ manifestRegistryRebuilds: 0, discoveryScans: 0 }));
vi.mock("./plugin-registry-contributions.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("./plugin-registry-contributions.js")>();
vi.mock("../config/io.plugin-metadata.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../config/io.plugin-metadata.js")>();
return {
...actual,
loadPluginManifestRegistryForPluginRegistry: (
...args: Parameters<typeof actual.loadPluginManifestRegistryForPluginRegistry>
resolveConfigWidePluginManifestRegistry: (
...args: Parameters<typeof actual.resolveConfigWidePluginManifestRegistry>
) => {
counters.manifestRegistryRebuilds += 1;
return actual.loadPluginManifestRegistryForPluginRegistry(...args);
return actual.resolveConfigWidePluginManifestRegistry(...args);
},
};
});
@@ -89,11 +90,16 @@ function countResolve(metadataSnapshot: PluginMetadataSnapshot): {
}
beforeEach(() => {
clearCurrentPluginMetadataSnapshot();
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();
});
afterAll(() => {
fs.rmSync(tempRoot, { recursive: true, force: true });
vi.unstubAllEnvs();
@@ -117,11 +123,16 @@ 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();
// `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 scoped = countResolve(
loadPluginMetadataSnapshot({ config, env, pluginIds: ["other-plugin"] }),
);
const scopedSnapshot = loadPluginMetadataSnapshot({
config,
env,
pluginIds: ["other-plugin"],
});
clearCurrentPluginMetadataSnapshot();
const scoped = countResolve(scopedSnapshot);
expect({ full: full.ids, scoped: scoped.ids }).toEqual({
full: withoutSnapshot,