@@ -9,8 +9,16 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
9
9
let pluginManager : PluginManager
10
10
let mockContext : SetupContext
11
11
let originalEnv : Record < string , string | undefined >
12
+ let originalCwd : string
12
13
13
14
beforeEach ( ( ) => {
15
+ // Store original working directory
16
+ originalCwd = process . cwd ( )
17
+
18
+ // Change to a temporary directory to avoid interference with project files
19
+ const tempDir = fs . mkdtempSync ( path . join ( require ( 'node:os' ) . tmpdir ( ) , 'plugin-test-' ) )
20
+ process . chdir ( tempDir )
21
+
14
22
pluginManager = new PluginManager ( )
15
23
mockContext = {
16
24
step : 'setup_complete' ,
@@ -58,18 +66,43 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
58
66
delete process . env . JIRA_TOKEN
59
67
delete process . env . JIRA_URL
60
68
61
- // Clean up any .buddy files that might exist
69
+ // Clean up any .buddy files that might exist (critical for plugin detection)
62
70
if ( fs . existsSync ( '.buddy' ) ) {
63
71
fs . rmSync ( '.buddy' , { recursive : true , force : true } )
64
72
}
73
+
74
+ // Also clean up specific plugin trigger files that might exist in the working directory
75
+ const pluginFiles = [ '.buddy/slack-webhook' , '.buddy/jira-config.json' , '.buddy/discord-webhook' ]
76
+ pluginFiles . forEach ( ( file ) => {
77
+ if ( fs . existsSync ( file ) ) {
78
+ fs . rmSync ( file , { force : true } )
79
+ }
80
+ } )
65
81
} )
66
82
67
83
afterEach ( ( ) => {
68
- // Clean up test files
84
+ // Clean up test files in temp directory
69
85
if ( fs . existsSync ( '.buddy' ) ) {
70
86
fs . rmSync ( '.buddy' , { recursive : true , force : true } )
71
87
}
72
88
89
+ // Clean up specific plugin trigger files
90
+ const pluginFiles = [ '.buddy/slack-webhook' , '.buddy/jira-config.json' , '.buddy/discord-webhook' ]
91
+ pluginFiles . forEach ( ( file ) => {
92
+ if ( fs . existsSync ( file ) ) {
93
+ fs . rmSync ( file , { force : true } )
94
+ }
95
+ } )
96
+
97
+ // Restore original working directory and clean up temp directory
98
+ const tempDir = process . cwd ( )
99
+ process . chdir ( originalCwd )
100
+ try {
101
+ fs . rmSync ( tempDir , { recursive : true , force : true } )
102
+ } catch {
103
+ // Ignore cleanup errors
104
+ }
105
+
73
106
// Restore original environment variables
74
107
if ( originalEnv . SLACK_WEBHOOK_URL !== undefined ) {
75
108
process . env . SLACK_WEBHOOK_URL = originalEnv . SLACK_WEBHOOK_URL
@@ -135,6 +168,9 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
135
168
console . log ( ` - JIRA_PROJECT_KEY: ${ process . env . JIRA_PROJECT_KEY ? 'SET' : 'UNSET' } ` )
136
169
console . log ( 'File system check:' )
137
170
console . log ( ` - .buddy exists: ${ fs . existsSync ( '.buddy' ) } ` )
171
+ console . log ( ` - .buddy/slack-webhook exists: ${ fs . existsSync ( '.buddy/slack-webhook' ) } ` )
172
+ console . log ( ` - .buddy/jira-config.json exists: ${ fs . existsSync ( '.buddy/jira-config.json' ) } ` )
173
+ console . log ( ` - .buddy/discord-webhook exists: ${ fs . existsSync ( '.buddy/discord-webhook' ) } ` )
138
174
if ( fs . existsSync ( '.buddy' ) ) {
139
175
try {
140
176
const buddyFiles = fs . readdirSync ( '.buddy' , { recursive : true } )
@@ -211,7 +247,7 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
211
247
expect ( process . env . DISCORD_WEBHOOK_URL ) . toBeUndefined ( )
212
248
expect ( process . env . JIRA_API_TOKEN ) . toBeUndefined ( )
213
249
214
- // Create custom plugin configuration
250
+ // Create custom plugin configuration (without handler function since it can't be serialized)
215
251
fs . mkdirSync ( '.buddy/plugins' , { recursive : true } )
216
252
const customPlugin = {
217
253
name : 'custom-integration' ,
@@ -223,18 +259,20 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
223
259
name : 'custom-hook' ,
224
260
priority : 15 ,
225
261
async : false ,
226
- handler ( ) {
227
- console . log ( 'Custom hook executed' )
228
- } ,
262
+ // Note: handler function would be loaded dynamically in real usage
229
263
} ,
230
264
] ,
231
265
configuration : { custom_setting : 'value' } ,
232
266
}
233
267
234
- fs . writeFileSync (
235
- path . join ( '.buddy/plugins' , 'custom.json' ) ,
236
- JSON . stringify ( customPlugin ) ,
237
- )
268
+ const customPluginPath = path . join ( '.buddy/plugins' , 'custom.json' )
269
+ fs . writeFileSync ( customPluginPath , JSON . stringify ( customPlugin ) )
270
+
271
+ // Verify the file was written correctly
272
+ expect ( fs . existsSync ( customPluginPath ) ) . toBe ( true )
273
+ const writtenContent = fs . readFileSync ( customPluginPath , 'utf8' )
274
+ const parsedContent = JSON . parse ( writtenContent )
275
+ expect ( parsedContent ) . toEqual ( customPlugin )
238
276
239
277
// Create a fresh PluginManager instance to avoid state pollution
240
278
const freshPluginManager = new PluginManager ( )
@@ -254,13 +292,25 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
254
292
const files = fs . readdirSync ( '.buddy/plugins' )
255
293
files . forEach ( f => console . log ( ` - ${ f } ` ) )
256
294
257
- // Read the custom plugin file to verify its contents
258
- const content = fs . readFileSync ( '.buddy/plugins/custom-integration.json' , 'utf8' )
259
- console . log ( 'Custom plugin file content:' , content )
295
+ // Read the custom plugin file to verify its contents (use correct filename)
296
+ const content = fs . readFileSync ( '.buddy/plugins/custom.json' , 'utf8' )
297
+ console . log ( 'Custom plugin file content:' , content . substring ( 0 , 200 ) )
298
+ const parsed = JSON . parse ( content )
299
+ console . log ( 'Parsed plugin name:' , parsed . name )
260
300
}
261
301
catch ( err ) {
262
302
console . log ( 'Error reading .buddy/plugins:' , err )
263
303
}
304
+
305
+ // Test the loadCustomPlugins method directly
306
+ try {
307
+ const directPlugins = await ( freshPluginManager as any ) . loadCustomPlugins ( )
308
+ console . log ( 'Direct loadCustomPlugins result:' , directPlugins . length )
309
+ directPlugins . forEach ( ( p : any ) => console . log ( ` Direct: ${ p . name } ` ) )
310
+ }
311
+ catch ( err ) {
312
+ console . log ( 'Direct loadCustomPlugins error:' , err )
313
+ }
264
314
}
265
315
266
316
expect ( customPlugins ) . toHaveLength ( 1 )
0 commit comments