@@ -2,7 +2,6 @@ import { mkdtemp, rm } from "node:fs/promises";
22import http from "node:http" ;
33import os from "node:os" ;
44import path from "node:path" ;
5- import { performance } from "node:perf_hooks" ;
65import { afterEach , describe , expect , it , vi } from "vitest" ;
76import type { OpenClawConfig } from "../config/types.openclaw.js" ;
87import type { ProviderPlugin } from "../plugins/types.js" ;
@@ -41,8 +40,8 @@ vi.mock("../plugins/provider-discovery.js", async (importOriginal) => {
4140 pluginId : "openai" ,
4241 label : "OpenAI" ,
4342 auth : [ ] ,
44- catalog : { order : "simple" , run : async ( ) => null } ,
45- staticCatalog : { order : "simple" , run : async ( ) => null } ,
43+ catalog : { order : "simple" , run : providerMocks . liveCatalog } ,
44+ staticCatalog : { order : "simple" , run : providerMocks . staticCatalog } ,
4645 } ;
4746 return {
4847 ...actual ,
@@ -56,6 +55,11 @@ const { resetPreparedModelRuntimeSnapshotsForTest } =
5655 await import ( "../agents/prepared-model-runtime.test-support.js" ) ;
5756const { writePersistedAuthProfileStoreRaw } = await import ( "../agents/auth-profiles/sqlite.js" ) ;
5857const { resolveAgentDir } = await import ( "../agents/agent-scope.js" ) ;
58+ const { createPluginMetadataSnapshot, makeRegistry } =
59+ await import ( "../config/plugin-auto-enable.test-helpers.js" ) ;
60+ const { setCurrentPluginMetadataSnapshot } =
61+ await import ( "../plugins/current-plugin-metadata-snapshot.js" ) ;
62+ const pluginDiscovery = await import ( "../plugins/discovery.js" ) ;
5963const { startGatewaySidecars } = await import ( "./server-startup-post-attach.js" ) ;
6064
6165async function listenHealthz (
@@ -108,9 +112,55 @@ describe("Gateway prepared model runtime startup", () => {
108112 } ,
109113 } ,
110114 gateway : { mode : "local" , bind : "loopback" , auth : { mode : "none" } } ,
111- plugins : { enabled : false } ,
112115 } satisfies OpenClawConfig ;
113116 const env = { ...process . env , OPENCLAW_STATE_DIR : stateDir } ;
117+ const manifestRegistry = makeRegistry ( [
118+ { id : "openai" , channels : [ ] , providers : [ "openai" ] , origin : "bundled" } ,
119+ ] ) ;
120+ const providerManifest = manifestRegistry . plugins [ 0 ] ;
121+ if ( ! providerManifest ) {
122+ throw new Error ( "expected bundled OpenAI provider manifest" ) ;
123+ }
124+ providerManifest . enabledByDefault = true ;
125+ providerManifest . modelCatalog = { ...providerConfig , discovery : { openai : "runtime" } } ;
126+ const metadataSnapshot = createPluginMetadataSnapshot ( {
127+ config : cfg ,
128+ manifestRegistry,
129+ workspaceDir,
130+ } ) ;
131+ const startupMetadataSnapshot = {
132+ ...metadataSnapshot ,
133+ index : {
134+ ...metadataSnapshot . index ,
135+ plugins : [
136+ {
137+ pluginId : providerManifest . id ,
138+ manifestPath : providerManifest . manifestPath ,
139+ manifestHash : "openai-test-manifest" ,
140+ rootDir : providerManifest . rootDir ,
141+ origin : providerManifest . origin ,
142+ enabled : true ,
143+ enabledByDefault : true ,
144+ startup : {
145+ sidecar : false ,
146+ memory : false ,
147+ deferConfiguredChannelFullLoadUntilAfterListen : false ,
148+ agentHarnesses : [ ] ,
149+ } ,
150+ compat : [ ] ,
151+ } ,
152+ ] ,
153+ } ,
154+ owners : {
155+ ...metadataSnapshot . owners ,
156+ providers : new Map ( [ [ "openai" , [ "openai" ] ] ] ) ,
157+ modelCatalogProviders : new Map ( [ [ "openai" , [ "openai" ] ] ] ) ,
158+ } ,
159+ metrics : { ...metadataSnapshot . metrics , indexPluginCount : 1 } ,
160+ startup : { channelPluginIds : [ ] , configuredDeferredChannelPluginIds : [ ] , pluginIds : [ ] } ,
161+ } ;
162+ setCurrentPluginMetadataSnapshot ( startupMetadataSnapshot , { config : cfg , env, workspaceDir } ) ;
163+ const discoverPlugins = vi . spyOn ( pluginDiscovery , "discoverOpenClawPlugins" ) ;
114164 const agentDir = resolveAgentDir ( cfg , "main" , env ) ;
115165 writePersistedAuthProfileStoreRaw (
116166 {
@@ -126,15 +176,6 @@ describe("Gateway prepared model runtime startup", () => {
126176 } ,
127177 agentDir ,
128178 ) ;
129- const blockEventLoop = async ( ) => {
130- const stopAt = performance . now ( ) + 1_500 ;
131- while ( performance . now ( ) < stopAt ) {
132- // Deliberately model synchronous provider/plugin catalog work that starves timers.
133- }
134- return providerConfig ;
135- } ;
136- providerMocks . staticCatalog . mockImplementation ( blockEventLoop ) ;
137- providerMocks . liveCatalog . mockImplementation ( blockEventLoop ) ;
138179 const startupEvents : string [ ] = [ ] ;
139180 const healthServer = await listenHealthz ( ( ) => {
140181 startupEvents . push ( "health-served" ) ;
@@ -198,6 +239,7 @@ describe("Gateway prepared model runtime startup", () => {
198239 "startup-complete" ,
199240 ] ) ;
200241 console . info ( `[gateway-startup-proof] ${ startupEvents . join ( " -> " ) } ` ) ;
242+ expect ( discoverPlugins ) . not . toHaveBeenCalled ( ) ;
201243 expect ( providerMocks . staticCatalog ) . not . toHaveBeenCalled ( ) ;
202244 expect ( providerMocks . liveCatalog ) . not . toHaveBeenCalled ( ) ;
203245 } ,
0 commit comments