Skip to content

Commit 1d0c982

Browse files
committed
fix(db): read defaultAssistant from config in createCodebase (fixes #1703)
createCodebase() hardcoded 'claude' as the fallback when ai_assistant_type was not provided, ignoring the user's configured defaultAssistant in ~/.archon/config.yaml. Now reads the configured default via loadConfig(). Falls back to 'claude' only if config loading fails.
1 parent aa71520 commit 1d0c982

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

packages/core/src/db/codebases.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { createQueryResult, mockPostgresDialect } from '../test/mocks/database';
33
import { Codebase } from '../types';
44

55
const 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
811
mock.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+
1522
import {
1623
createCodebase,
1724
getCodebase,
@@ -28,6 +35,8 @@ import {
2835
describe('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', () => {

packages/core/src/db/codebases.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { pool, getDialect } from './connection';
55
import type { Codebase } from '../types';
66
import { createLogger } from '@archon/paths';
7+
import { loadConfig } from '../config/config-loader';
78

89
/** Lazy-initialized logger (deferred so test mocks can intercept createLogger) */
910
let cachedLog: ReturnType<typeof createLogger> | undefined;
@@ -18,7 +19,15 @@ export async function createCodebase(data: {
1819
default_cwd: string;
1920
ai_assistant_type?: string;
2021
}): Promise<Codebase> {
21-
const assistantType = data.ai_assistant_type ?? 'claude';
22+
let assistantType = data.ai_assistant_type;
23+
if (!assistantType) {
24+
try {
25+
const config = await loadConfig();
26+
assistantType = config.assistant;
27+
} catch {
28+
assistantType = 'claude';
29+
}
30+
}
2231
const result = await pool.query<Codebase>(
2332
'INSERT INTO remote_agent_codebases (name, repository_url, default_cwd, ai_assistant_type) VALUES ($1, $2, $3, $4) RETURNING *',
2433
[data.name, data.repository_url ?? null, data.default_cwd, assistantType]

0 commit comments

Comments
 (0)