@@ -3,6 +3,9 @@ import { createQueryResult, mockPostgresDialect } from '../test/mocks/database';
33import { Codebase } from '../types' ;
44
55const mockQuery = mock ( ( ) => Promise . resolve ( createQueryResult ( [ ] ) ) ) ;
6+ const mockLoadConfig = mock ( ( ) =>
7+ Promise . resolve ( { assistant : 'claude' } as { assistant : string } )
8+ ) ;
69
710// Mock the connection module before importing the module under test
811mock . module ( './connection' , ( ) => ( {
@@ -12,6 +15,10 @@ mock.module('./connection', () => ({
1215 getDialect : ( ) => mockPostgresDialect ,
1316} ) ) ;
1417
18+ mock . module ( '../config/config-loader' , ( ) => ( {
19+ loadConfig : mockLoadConfig ,
20+ } ) ) ;
21+
1522import {
1623 createCodebase ,
1724 getCodebase ,
@@ -28,6 +35,8 @@ import {
2835describe ( 'codebases' , ( ) => {
2936 beforeEach ( ( ) => {
3037 mockQuery . mockClear ( ) ;
38+ mockLoadConfig . mockClear ( ) ;
39+ mockLoadConfig . mockResolvedValue ( { assistant : 'claude' } as { assistant : string } ) ;
3140 } ) ;
3241
3342 const mockCodebase : Codebase = {
@@ -78,7 +87,23 @@ describe('codebases', () => {
7887 ) ;
7988 } ) ;
8089
81- test ( 'defaults ai_assistant_type to claude' , async ( ) => {
90+ test ( 'reads defaultAssistant from config when ai_assistant_type omitted' , async ( ) => {
91+ mockLoadConfig . mockResolvedValueOnce ( { assistant : 'codex' } as { assistant : string } ) ;
92+ mockQuery . mockResolvedValueOnce (
93+ createQueryResult ( [ { ...mockCodebase , ai_assistant_type : 'codex' } ] )
94+ ) ;
95+
96+ await createCodebase ( {
97+ name : 'test-project' ,
98+ default_cwd : '/workspace/test-project' ,
99+ } ) ;
100+
101+ expect ( mockLoadConfig ) . toHaveBeenCalled ( ) ;
102+ expect ( mockQuery ) . toHaveBeenCalledWith ( expect . any ( String ) , expect . arrayContaining ( [ 'codex' ] ) ) ;
103+ } ) ;
104+
105+ test ( 'falls back to claude when config loading fails' , async ( ) => {
106+ mockLoadConfig . mockRejectedValueOnce ( new Error ( 'config not found' ) ) ;
82107 mockQuery . mockResolvedValueOnce ( createQueryResult ( [ mockCodebase ] ) ) ;
83108
84109 await createCodebase ( {
@@ -91,6 +116,21 @@ describe('codebases', () => {
91116 expect . arrayContaining ( [ 'claude' ] )
92117 ) ;
93118 } ) ;
119+
120+ test ( 'uses explicit ai_assistant_type over config default' , async ( ) => {
121+ mockQuery . mockResolvedValueOnce (
122+ createQueryResult ( [ { ...mockCodebase , ai_assistant_type : 'pi' } ] )
123+ ) ;
124+
125+ await createCodebase ( {
126+ name : 'test-project' ,
127+ default_cwd : '/workspace/test-project' ,
128+ ai_assistant_type : 'pi' ,
129+ } ) ;
130+
131+ expect ( mockLoadConfig ) . not . toHaveBeenCalled ( ) ;
132+ expect ( mockQuery ) . toHaveBeenCalledWith ( expect . any ( String ) , expect . arrayContaining ( [ 'pi' ] ) ) ;
133+ } ) ;
94134 } ) ;
95135
96136 describe ( 'getCodebase' , ( ) => {
0 commit comments