@@ -34,6 +34,30 @@ function applyWithApnChannelConfig(extra?: {
3434 } ) ;
3535}
3636
37+ function materializeEnvCatalogCandidates (
38+ stateDir : string ,
39+ candidates : Parameters < typeof materializePluginAutoEnableCandidates > [ 0 ] [ "candidates" ] = [
40+ { pluginId : "env-primary" , kind : "channel-configured" , channelId : "env-primary" } ,
41+ { pluginId : "env-secondary" , kind : "channel-configured" , channelId : "env-secondary" } ,
42+ ] ,
43+ ) {
44+ return materializePluginAutoEnableCandidates ( {
45+ config : {
46+ channels : {
47+ "env-primary" : { token : "primary" } ,
48+ "env-secondary" : { token : "secondary" } ,
49+ } ,
50+ } ,
51+ candidates,
52+ env : {
53+ ...makeIsolatedEnv ( ) ,
54+ OPENCLAW_STATE_DIR : stateDir ,
55+ OPENCLAW_BUNDLED_PLUGINS_DIR : "/nonexistent/bundled/plugins" ,
56+ } ,
57+ manifestRegistry : makeRegistry ( [ ] ) ,
58+ } ) ;
59+ }
60+
3761beforeEach ( ( ) => {
3862 resetPluginAutoEnableTestState ( ) ;
3963} ) ;
@@ -73,32 +97,7 @@ describe("applyPluginAutoEnable channels", () => {
7397 "utf-8" ,
7498 ) ;
7599
76- const result = materializePluginAutoEnableCandidates ( {
77- config : {
78- channels : {
79- "env-primary" : { token : "primary" } ,
80- "env-secondary" : { token : "secondary" } ,
81- } ,
82- } ,
83- candidates : [
84- {
85- pluginId : "env-primary" ,
86- kind : "channel-configured" ,
87- channelId : "env-primary" ,
88- } ,
89- {
90- pluginId : "env-secondary" ,
91- kind : "channel-configured" ,
92- channelId : "env-secondary" ,
93- } ,
94- ] ,
95- env : {
96- ...makeIsolatedEnv ( ) ,
97- OPENCLAW_STATE_DIR : stateDir ,
98- OPENCLAW_BUNDLED_PLUGINS_DIR : "/nonexistent/bundled/plugins" ,
99- } ,
100- manifestRegistry : makeRegistry ( [ ] ) ,
101- } ) ;
100+ const result = materializeEnvCatalogCandidates ( stateDir ) ;
102101
103102 expect ( result . config . plugins ?. entries ?. [ "env-secondary" ] ?. enabled ) . toBe ( true ) ;
104103 expect ( result . config . plugins ?. entries ?. [ "env-primary" ] ) . toBeUndefined ( ) ;
@@ -151,25 +150,14 @@ describe("applyPluginAutoEnable channels", () => {
151150 const realpathSpy = vi . spyOn ( fs , "realpathSync" ) ;
152151
153152 try {
154- materializePluginAutoEnableCandidates ( {
155- config : {
156- channels : {
157- "env-primary" : { token : "primary" } ,
158- "env-secondary" : { token : "secondary" } ,
159- } ,
160- } ,
161- candidates : Array . from ( { length : 20 } , ( _ , index ) => ( {
153+ materializeEnvCatalogCandidates (
154+ stateDir ,
155+ Array . from ( { length : 20 } , ( _ , index ) => ( {
162156 pluginId : index % 2 === 0 ? "env-primary" : "env-secondary" ,
163157 kind : "channel-configured" as const ,
164158 channelId : index % 2 === 0 ? "env-primary" : "env-secondary" ,
165159 } ) ) ,
166- env : {
167- ...makeIsolatedEnv ( ) ,
168- OPENCLAW_STATE_DIR : stateDir ,
169- OPENCLAW_BUNDLED_PLUGINS_DIR : "/nonexistent/bundled/plugins" ,
170- } ,
171- manifestRegistry : makeRegistry ( [ ] ) ,
172- } ) ;
160+ ) ;
173161
174162 expect (
175163 realpathSpy . mock . calls . filter ( ( [ filePath ] ) =>
@@ -211,32 +199,7 @@ describe("applyPluginAutoEnable channels", () => {
211199 const catalogPath = path . join ( pluginsDir , "catalog.json" ) ;
212200 fs . symlinkSync ( realPath , catalogPath ) ;
213201
214- const result = materializePluginAutoEnableCandidates ( {
215- config : {
216- channels : {
217- "env-primary" : { token : "primary" } ,
218- "env-secondary" : { token : "secondary" } ,
219- } ,
220- } ,
221- candidates : [
222- {
223- pluginId : "env-primary" ,
224- kind : "channel-configured" as const ,
225- channelId : "env-primary" ,
226- } ,
227- {
228- pluginId : "env-secondary" ,
229- kind : "channel-configured" as const ,
230- channelId : "env-secondary" ,
231- } ,
232- ] ,
233- env : {
234- ...makeIsolatedEnv ( ) ,
235- OPENCLAW_STATE_DIR : stateDir ,
236- OPENCLAW_BUNDLED_PLUGINS_DIR : "/nonexistent/bundled/plugins" ,
237- } ,
238- manifestRegistry : makeRegistry ( [ ] ) ,
239- } ) ;
202+ const result = materializeEnvCatalogCandidates ( stateDir ) ;
240203
241204 expect ( result . config . plugins ?. entries ?. [ "env-secondary" ] ?. enabled ) . toBe ( true ) ;
242205 expect ( result . config . plugins ?. entries ?. [ "env-primary" ] ) . toBeUndefined ( ) ;
@@ -257,32 +220,7 @@ describe("applyPluginAutoEnable channels", () => {
257220 fs . closeSync ( fd ) ;
258221 }
259222
260- const result = materializePluginAutoEnableCandidates ( {
261- config : {
262- channels : {
263- "env-primary" : { token : "primary" } ,
264- "env-secondary" : { token : "secondary" } ,
265- } ,
266- } ,
267- candidates : [
268- {
269- pluginId : "env-primary" ,
270- kind : "channel-configured" as const ,
271- channelId : "env-primary" ,
272- } ,
273- {
274- pluginId : "env-secondary" ,
275- kind : "channel-configured" as const ,
276- channelId : "env-secondary" ,
277- } ,
278- ] ,
279- env : {
280- ...makeIsolatedEnv ( ) ,
281- OPENCLAW_STATE_DIR : stateDir ,
282- OPENCLAW_BUNDLED_PLUGINS_DIR : "/nonexistent/bundled/plugins" ,
283- } ,
284- manifestRegistry : makeRegistry ( [ ] ) ,
285- } ) ;
223+ const result = materializeEnvCatalogCandidates ( stateDir ) ;
286224
287225 // Selection continues: env-secondary is still auto-enabled.
288226 expect ( result . config . plugins ?. entries ?. [ "env-secondary" ] ?. enabled ) . toBe ( true ) ;
0 commit comments