|
1 |
| -/* eslint-disable no-console */ |
2 | 1 | import type { SetupContext, SetupPlugin } from '../src/setup'
|
3 | 2 | import { afterEach, beforeEach, describe, expect, it } from 'bun:test'
|
4 | 3 | import fs from 'node:fs'
|
@@ -150,51 +149,35 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
|
150 | 149 |
|
151 | 150 | describe('Plugin Discovery', () => {
|
152 | 151 | it('should discover no plugins when no integrations are configured', async () => {
|
153 |
| - const plugins = await pluginManager.discoverPlugins() |
154 |
| - |
155 |
| - // In CI environments, there might be unexpected environment variables |
156 |
| - // So instead of expecting specific counts, check that no built-in integration plugins exist |
157 |
| - const integrationPlugins = plugins.filter(p => |
158 |
| - p.name === 'slack-integration' |
159 |
| - || p.name === 'discord-integration' |
160 |
| - || p.name === 'jira-integration', |
161 |
| - ) |
162 |
| - |
163 |
| - // Debug info for CI troubleshooting |
164 |
| - if (integrationPlugins.length > 0) { |
165 |
| - console.log('🚨 Unexpected plugins found in clean environment:') |
166 |
| - console.log(`Total plugins discovered: ${plugins.length}`) |
167 |
| - console.log('All discovered plugins:') |
168 |
| - plugins.forEach((p, i) => { |
169 |
| - console.log(` ${i + 1}. ${p.name}: enabled=${p.enabled}, version=${p.version}`) |
170 |
| - }) |
171 |
| - console.log('Integration plugins (should be 0):') |
172 |
| - integrationPlugins.forEach((p) => { |
173 |
| - console.log(` - ${p.name}: enabled=${p.enabled}`) |
174 |
| - }) |
175 |
| - console.log('Environment check:') |
176 |
| - console.log(` - SLACK_WEBHOOK_URL: ${process.env.SLACK_WEBHOOK_URL ? 'SET' : 'UNSET'}`) |
177 |
| - console.log(` - DISCORD_WEBHOOK_URL: ${process.env.DISCORD_WEBHOOK_URL ? 'SET' : 'UNSET'}`) |
178 |
| - console.log(` - JIRA_API_TOKEN: ${process.env.JIRA_API_TOKEN ? 'SET' : 'UNSET'}`) |
179 |
| - console.log(` - JIRA_BASE_URL: ${process.env.JIRA_BASE_URL ? 'SET' : 'UNSET'}`) |
180 |
| - console.log(` - JIRA_PROJECT_KEY: ${process.env.JIRA_PROJECT_KEY ? 'SET' : 'UNSET'}`) |
181 |
| - console.log('File system check:') |
182 |
| - console.log(` - .buddy exists: ${fs.existsSync('.buddy')}`) |
183 |
| - console.log(` - .buddy/slack-webhook exists: ${fs.existsSync('.buddy/slack-webhook')}`) |
184 |
| - console.log(` - .buddy/jira-config.json exists: ${fs.existsSync('.buddy/jira-config.json')}`) |
185 |
| - console.log(` - .buddy/discord-webhook exists: ${fs.existsSync('.buddy/discord-webhook')}`) |
186 |
| - if (fs.existsSync('.buddy')) { |
187 |
| - try { |
188 |
| - const buddyFiles = fs.readdirSync('.buddy', { recursive: true }) |
189 |
| - console.log(' - .buddy contents:', buddyFiles) |
190 |
| - } |
191 |
| - catch { |
192 |
| - console.log(' - .buddy contents: error reading') |
193 |
| - } |
194 |
| - } |
| 152 | + // Mock the detection methods to ensure clean state in CI environment |
| 153 | + const mockPluginManager = pluginManager as any |
| 154 | + const originalHasSlack = mockPluginManager.hasSlackWebhook |
| 155 | + const originalHasJira = mockPluginManager.hasJiraIntegration |
| 156 | + const originalHasDiscord = mockPluginManager.hasDiscordWebhook |
| 157 | + |
| 158 | + // Override detection methods to return false |
| 159 | + mockPluginManager.hasSlackWebhook = async () => false |
| 160 | + mockPluginManager.hasJiraIntegration = async () => false |
| 161 | + mockPluginManager.hasDiscordWebhook = async () => false |
| 162 | + |
| 163 | + try { |
| 164 | + const plugins = await pluginManager.discoverPlugins() |
| 165 | + |
| 166 | + // Filter out only integration plugins to test |
| 167 | + const integrationPlugins = plugins.filter(p => |
| 168 | + p.name === 'slack-integration' |
| 169 | + || p.name === 'discord-integration' |
| 170 | + || p.name === 'jira-integration', |
| 171 | + ) |
| 172 | + |
| 173 | + expect(integrationPlugins).toHaveLength(0) |
| 174 | + } |
| 175 | + finally { |
| 176 | + // Restore original methods |
| 177 | + mockPluginManager.hasSlackWebhook = originalHasSlack |
| 178 | + mockPluginManager.hasJiraIntegration = originalHasJira |
| 179 | + mockPluginManager.hasDiscordWebhook = originalHasDiscord |
195 | 180 | }
|
196 |
| - |
197 |
| - expect(integrationPlugins).toHaveLength(0) |
198 | 181 | })
|
199 | 182 |
|
200 | 183 | // Group file-based tests together with their own setup to ensure isolation
|
@@ -356,28 +339,39 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
|
356 | 339 | })
|
357 | 340 |
|
358 | 341 | it('should handle malformed custom plugin files gracefully', async () => {
|
359 |
| - fs.mkdirSync('.buddy/plugins', { recursive: true }) |
360 |
| - fs.writeFileSync(path.join('.buddy/plugins', 'invalid.json'), 'invalid json{') |
361 |
| - |
362 |
| - // Should not throw, just log warning |
363 |
| - const plugins = await pluginManager.discoverPlugins() |
364 |
| - |
365 |
| - // Filter out any plugins that might exist in CI environment, only check for integration plugins |
366 |
| - const integrationPlugins = plugins.filter(p => |
367 |
| - p.name === 'slack-integration' |
368 |
| - || p.name === 'discord-integration' |
369 |
| - || p.name === 'jira-integration', |
370 |
| - ) |
371 |
| - |
372 |
| - // Debug info for CI troubleshooting |
373 |
| - if (integrationPlugins.length > 0) { |
374 |
| - console.log('🚨 Unexpected plugins found after malformed plugin test:') |
375 |
| - integrationPlugins.forEach((p) => { |
376 |
| - console.log(` - ${p.name}: enabled=${p.enabled}`) |
377 |
| - }) |
| 342 | + // Mock the detection methods to ensure clean state in CI environment |
| 343 | + const mockPluginManager = pluginManager as any |
| 344 | + const originalHasSlack = mockPluginManager.hasSlackWebhook |
| 345 | + const originalHasJira = mockPluginManager.hasJiraIntegration |
| 346 | + const originalHasDiscord = mockPluginManager.hasDiscordWebhook |
| 347 | + |
| 348 | + // Override detection methods to return false |
| 349 | + mockPluginManager.hasSlackWebhook = async () => false |
| 350 | + mockPluginManager.hasJiraIntegration = async () => false |
| 351 | + mockPluginManager.hasDiscordWebhook = async () => false |
| 352 | + |
| 353 | + try { |
| 354 | + fs.mkdirSync('.buddy/plugins', { recursive: true }) |
| 355 | + fs.writeFileSync(path.join('.buddy/plugins', 'invalid.json'), 'invalid json{') |
| 356 | + |
| 357 | + // Should not throw, just log warning |
| 358 | + const plugins = await pluginManager.discoverPlugins() |
| 359 | + |
| 360 | + // Filter out only integration plugins to test |
| 361 | + const integrationPlugins = plugins.filter(p => |
| 362 | + p.name === 'slack-integration' |
| 363 | + || p.name === 'discord-integration' |
| 364 | + || p.name === 'jira-integration', |
| 365 | + ) |
| 366 | + |
| 367 | + expect(integrationPlugins).toHaveLength(0) |
| 368 | + } |
| 369 | + finally { |
| 370 | + // Restore original methods |
| 371 | + mockPluginManager.hasSlackWebhook = originalHasSlack |
| 372 | + mockPluginManager.hasJiraIntegration = originalHasJira |
| 373 | + mockPluginManager.hasDiscordWebhook = originalHasDiscord |
378 | 374 | }
|
379 |
| - |
380 |
| - expect(integrationPlugins).toHaveLength(0) |
381 | 375 | })
|
382 | 376 | })
|
383 | 377 |
|
|
0 commit comments