|
3 | 3 | const fs = require('fs'); |
4 | 4 | const path = require('path'); |
5 | 5 | const yaml = require('js-yaml'); |
| 6 | +const codeIntel = require('../../.aiox-core/core/code-intel'); |
6 | 7 | const { RegistrySyncer, inferRole, ROLE_MAP } = require('../../.aiox-core/core/code-intel/registry-syncer'); |
7 | 8 |
|
8 | 9 | // Mock fs module for controlled testing |
@@ -87,6 +88,8 @@ function createSyncer(options = {}) { |
87 | 88 | describe('RegistrySyncer', () => { |
88 | 89 | beforeEach(() => { |
89 | 90 | jest.clearAllMocks(); |
| 91 | + codeIntel.getClient.mockReset(); |
| 92 | + codeIntel.isCodeIntelAvailable.mockReset().mockReturnValue(false); |
90 | 93 | // Default fs mocks |
91 | 94 | fs.existsSync.mockReturnValue(true); |
92 | 95 | fs.writeFileSync.mockImplementation(() => {}); |
@@ -304,6 +307,30 @@ describe('RegistrySyncer', () => { |
304 | 307 |
|
305 | 308 | // T5: Fallback sem provider (AC5) |
306 | 309 | describe('Fallback without provider (T5 — AC5)', () => { |
| 310 | + it('should bootstrap default client before checking module-level provider availability', async () => { |
| 311 | + const logger = jest.fn(); |
| 312 | + const mockClient = createMockClient(); |
| 313 | + |
| 314 | + codeIntel.getClient.mockReturnValue(mockClient); |
| 315 | + codeIntel.isCodeIntelAvailable.mockImplementation( |
| 316 | + () => codeIntel.getClient.mock.calls.length > 0, |
| 317 | + ); |
| 318 | + |
| 319 | + const syncer = new RegistrySyncer({ |
| 320 | + registryPath: '/mock/entity-registry.yaml', |
| 321 | + repoRoot: '/mock/repo', |
| 322 | + client: null, |
| 323 | + logger, |
| 324 | + }); |
| 325 | + |
| 326 | + const stats = await syncer.sync({ full: true }); |
| 327 | + |
| 328 | + expect(codeIntel.getClient).toHaveBeenCalled(); |
| 329 | + expect(stats.aborted).toBeUndefined(); |
| 330 | + expect(stats.processed).toBe(3); |
| 331 | + expect(fs.writeFileSync).toHaveBeenCalled(); |
| 332 | + }); |
| 333 | + |
307 | 334 | it('should skip enrichment and log message when no provider available', async () => { |
308 | 335 | const logger = jest.fn(); |
309 | 336 | const syncer = new RegistrySyncer({ |
|
0 commit comments