66import { mkdtemp , rm } from 'node:fs/promises' ;
77import { tmpdir } from 'node:os' ;
88import { join } from 'node:path' ;
9- import { RepositoryIndexer } from '@lytics/dev-agent-core' ;
10- import { afterEach , beforeEach , describe , expect , it } from 'vitest' ;
9+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
1110import type { GitHubAgentConfig } from '../github/agent' ;
1211import { GitHubAgent } from '../github/agent' ;
1312import type { GitHubContextRequest , GitHubContextResult } from '../github/types' ;
1413import { SubagentCoordinator } from './coordinator' ;
1514
15+ // Mock GitHub utilities to avoid actual gh CLI calls
16+ vi . mock ( '../github/utils/index' , ( ) => ( {
17+ fetchAllDocuments : vi . fn ( ( ) => [
18+ {
19+ type : 'issue' ,
20+ number : 1 ,
21+ title : 'Test Issue' ,
22+ body : 'Test body' ,
23+ state : 'open' ,
24+ author : 'testuser' ,
25+ labels : [ ] ,
26+ createdAt : '2024-01-01T00:00:00Z' ,
27+ updatedAt : '2024-01-01T00:00:00Z' ,
28+ url : 'https://github.com/test/repo/issues/1' ,
29+ relatedIssues : [ ] ,
30+ relatedPRs : [ ] ,
31+ linkedFiles : [ ] ,
32+ mentions : [ ] ,
33+ } ,
34+ ] ) ,
35+ enrichDocument : vi . fn ( ( doc : any ) => doc ) ,
36+ getCurrentRepository : vi . fn ( ( ) => 'lytics/dev-agent' ) ,
37+ calculateRelevance : vi . fn ( ( ) => 0.8 ) ,
38+ matchesQuery : vi . fn ( ( ) => true ) ,
39+ } ) ) ;
40+
1641describe ( 'Coordinator → GitHub Integration' , ( ) => {
1742 let coordinator : SubagentCoordinator ;
1843 let github : GitHubAgent ;
1944 let tempDir : string ;
20- let codeIndexer : RepositoryIndexer ;
2145
2246 beforeEach ( async ( ) => {
2347 // Create temp directory
2448 tempDir = await mkdtemp ( join ( tmpdir ( ) , 'gh-coordinator-test-' ) ) ;
2549
26- // Initialize code indexer
27- codeIndexer = new RepositoryIndexer ( {
28- repositoryPath : process . cwd ( ) ,
29- vectorStorePath : join ( tempDir , '.vectors' ) ,
30- } ) ;
31- await codeIndexer . initialize ( ) ;
32-
3350 // Create coordinator
3451 coordinator = new SubagentCoordinator ( {
3552 logLevel : 'error' , // Reduce noise in tests
3653 } ) ;
3754
38- // Create GitHub agent
55+ // Create GitHub agent with vector storage config
3956 const config : GitHubAgentConfig = {
4057 repositoryPath : process . cwd ( ) ,
41- codeIndexer,
42- storagePath : join ( tempDir , '.github-index' ) ,
58+ vectorStorePath : join ( tempDir , '.github-vectors' ) ,
59+ statePath : join ( tempDir , 'github-state.json' ) ,
60+ autoUpdate : false , // Disable for tests
4361 } ;
4462 github = new GitHubAgent ( config ) ;
4563
@@ -49,7 +67,6 @@ describe('Coordinator → GitHub Integration', () => {
4967
5068 afterEach ( async ( ) => {
5169 await coordinator . stop ( ) ;
52- await codeIndexer . close ( ) ;
5370 await rm ( tempDir , { recursive : true , force : true } ) ;
5471 } ) ;
5572
@@ -67,7 +84,7 @@ describe('Coordinator → GitHub Integration', () => {
6784 it ( 'should prevent duplicate registration' , async ( ) => {
6885 const duplicate = new GitHubAgent ( {
6986 repositoryPath : process . cwd ( ) ,
70- codeIndexer ,
87+ vectorStorePath : join ( tempDir , '.github-vectors-dup' ) ,
7188 } ) ;
7289 await expect ( coordinator . registerAgent ( duplicate ) ) . rejects . toThrow ( 'already registered' ) ;
7390 } ) ;
@@ -101,6 +118,17 @@ describe('Coordinator → GitHub Integration', () => {
101118 } ) ;
102119
103120 it ( 'should route search request to GitHub agent' , async ( ) => {
121+ // Index first (required for search)
122+ await coordinator . sendMessage ( {
123+ type : 'request' ,
124+ sender : 'test' ,
125+ recipient : 'github' ,
126+ payload : {
127+ action : 'index' ,
128+ indexOptions : { } ,
129+ } as GitHubContextRequest ,
130+ } ) ;
131+
104132 const response = await coordinator . sendMessage ( {
105133 type : 'request' ,
106134 sender : 'test' ,
0 commit comments