|
| 1 | +import fs from "node:fs"; |
| 2 | +import { afterEach, expect, it, vi } from "vitest"; |
| 3 | +import { clearPluginMetadataLifecycleCaches } from "../plugins/plugin-metadata-lifecycle.js"; |
| 4 | +import { createColdPluginFixture } from "../plugins/test-helpers/cold-plugin-fixtures.js"; |
| 5 | +import { withOpenClawTestState } from "../test-utils/openclaw-test-state.js"; |
| 6 | + |
| 7 | +const registryLoads = vi.hoisted(() => ({ count: 0 })); |
| 8 | + |
| 9 | +vi.mock("../plugins/plugin-registry-snapshot.js", async (importOriginal) => { |
| 10 | + const actual = await importOriginal<typeof import("../plugins/plugin-registry-snapshot.js")>(); |
| 11 | + return { |
| 12 | + ...actual, |
| 13 | + loadPluginRegistrySnapshotWithMetadata: ( |
| 14 | + ...args: Parameters<typeof actual.loadPluginRegistrySnapshotWithMetadata> |
| 15 | + ) => { |
| 16 | + registryLoads.count += 1; |
| 17 | + return actual.loadPluginRegistrySnapshotWithMetadata(...args); |
| 18 | + }, |
| 19 | + }; |
| 20 | +}); |
| 21 | + |
| 22 | +vi.mock("./status.scan.bootstrap-shared.js", () => ({ |
| 23 | + createStatusScanCoreBootstrap: async () => ({ |
| 24 | + tailscaleMode: "off", |
| 25 | + tailscaleDnsPromise: Promise.resolve(null), |
| 26 | + updatePromise: Promise.resolve({ installKind: "unknown" }), |
| 27 | + agentStatusPromise: Promise.resolve({ |
| 28 | + defaultId: "main", |
| 29 | + agents: [], |
| 30 | + totalSessions: 0, |
| 31 | + bootstrapPendingCount: 0, |
| 32 | + }), |
| 33 | + gatewayProbePromise: Promise.resolve({ gatewayReachable: false }), |
| 34 | + resolveTailscaleHttpsUrl: async () => null, |
| 35 | + skipColdStartNetworkChecks: false, |
| 36 | + }), |
| 37 | +})); |
| 38 | + |
| 39 | +vi.mock("../gateway/call.js", () => ({ |
| 40 | + callGateway: vi.fn(async () => { |
| 41 | + throw new Error("gateway unavailable in status snapshot test"); |
| 42 | + }), |
| 43 | +})); |
| 44 | + |
| 45 | +const { collectStatusScanOverview } = await import("./status.scan-overview.js"); |
| 46 | + |
| 47 | +afterEach(() => { |
| 48 | + clearPluginMetadataLifecycleCaches(); |
| 49 | +}); |
| 50 | + |
| 51 | +it("builds plugin metadata once for a status scan", async () => { |
| 52 | + await withOpenClawTestState( |
| 53 | + { |
| 54 | + prefix: "openclaw-status-plugin-metadata-", |
| 55 | + layout: "split", |
| 56 | + env: { OPENCLAW_DISABLE_BUNDLED_PLUGINS: "1" }, |
| 57 | + }, |
| 58 | + async (state) => { |
| 59 | + const pluginDir = state.path("cold-plugin"); |
| 60 | + fs.mkdirSync(pluginDir, { recursive: true }); |
| 61 | + createColdPluginFixture({ rootDir: pluginDir, pluginId: "cold-plugin" }); |
| 62 | + await state.writeConfig({ |
| 63 | + memory: { |
| 64 | + search: { |
| 65 | + remote: { apiKey: "${OPENCLAW_STATUS_PLUGIN_METADATA_KEY}" }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + plugins: { |
| 69 | + load: { paths: [pluginDir] }, |
| 70 | + entries: { "cold-plugin": { enabled: true } }, |
| 71 | + }, |
| 72 | + }); |
| 73 | + clearPluginMetadataLifecycleCaches(); |
| 74 | + registryLoads.count = 0; |
| 75 | + |
| 76 | + const overview = await collectStatusScanOverview({ |
| 77 | + commandName: "status --json", |
| 78 | + opts: {}, |
| 79 | + showSecrets: false, |
| 80 | + includeChannelsData: false, |
| 81 | + skipUpdateCheck: true, |
| 82 | + resolveHasConfiguredChannels: () => false, |
| 83 | + }); |
| 84 | + |
| 85 | + expect(overview.cfg.plugins?.entries?.["cold-plugin"]?.enabled).toBe(true); |
| 86 | + expect(registryLoads.count).toBe(1); |
| 87 | + }, |
| 88 | + ); |
| 89 | +}); |
0 commit comments