@@ -4,6 +4,16 @@ import path from 'path';
44import os from 'os' ;
55import { InitCommand } from '../../src/core/init.js' ;
66
7+ // Mock @inquirer /prompts for language selection
8+ const mockSelect = vi . fn ( ) ;
9+ vi . mock ( '@inquirer/prompts' , async ( ) => {
10+ const actual = await vi . importActual ( '@inquirer/prompts' ) ;
11+ return {
12+ ...actual ,
13+ select : mockSelect ,
14+ } ;
15+ } ) ;
16+
717const DONE = '__done__' ;
818
919type SelectionQueue = string [ ] [ ] ;
@@ -43,6 +53,7 @@ describe('InitCommand', () => {
4353 await fs . mkdir ( testDir , { recursive : true } ) ;
4454 selectionQueue = [ ] ;
4555 mockPrompt . mockReset ( ) ;
56+ mockSelect . mockReset ( ) ;
4657 initCommand = new InitCommand ( { prompt : mockPrompt } ) ;
4758
4859 // Route Codex global directory into the test sandbox
@@ -51,6 +62,11 @@ describe('InitCommand', () => {
5162
5263 // Mock console.log to suppress output during tests
5364 vi . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
65+
66+ // Default language selection mock - return default language unless overridden
67+ mockSelect . mockImplementation ( async ( options : any ) => {
68+ return options . default || 'en-US' ;
69+ } ) ;
5470 } ) ;
5571
5672 afterEach ( async ( ) => {
@@ -1296,22 +1312,61 @@ describe('InitCommand', () => {
12961312 expect ( projectContent ) . toContain ( 'Project Context' ) ;
12971313 } ) ;
12981314
1299- it ( 'should read existing language config in extend mode' , async ( ) => {
1315+ it ( 'should read existing language config in extend mode and allow changing ' , async ( ) => {
13001316 // First init with Chinese
13011317 const firstCommand = new InitCommand ( { tools : 'none' , language : 'zh-CN' } ) ;
13021318 await firstCommand . execute ( testDir ) ;
13031319
1304- // Second init in extend mode should use existing language
1320+ // Second init in extend mode - should prompt with Chinese as default, but allow changing
1321+ // Mock language selection to return French (fr-FR)
1322+ mockSelect . mockResolvedValueOnce ( 'fr-FR' ) ;
13051323 queueSelections ( DONE ) ;
13061324 await initCommand . execute ( testDir ) ;
13071325
1326+ // Verify language was changed to French
1327+ const configPath = path . join ( testDir , 'openspec' , 'config.json' ) ;
1328+ const configContent = await fs . readFile ( configPath , 'utf-8' ) ;
1329+ const config = JSON . parse ( configContent ) ;
1330+ expect ( config . language ) . toBe ( 'fr-FR' ) ;
1331+
1332+ // Verify French templates were used
13081333 const projectPath = path . join ( testDir , 'openspec' , 'project.md' ) ;
13091334 const projectContent = await fs . readFile ( projectPath , 'utf-8' ) ;
1310- // Should still be Chinese (though file might not be regenerated in extend mode)
1335+ expect ( projectContent ) . toContain ( 'Contexte' ) ;
1336+
1337+ // Verify language prompt was called with Chinese as default
1338+ expect ( mockSelect ) . toHaveBeenCalledWith (
1339+ expect . objectContaining ( {
1340+ message : 'Select your preferred language:' ,
1341+ default : 'zh-CN' ,
1342+ } )
1343+ ) ;
1344+ } ) ;
1345+
1346+ it ( 'should use existing language as default in extend mode when user confirms' , async ( ) => {
1347+ // First init with Japanese
1348+ const firstCommand = new InitCommand ( { tools : 'none' , language : 'ja-JP' } ) ;
1349+ await firstCommand . execute ( testDir ) ;
1350+
1351+ // Second init in extend mode - user confirms default (Japanese)
1352+ // Mock language selection to return Japanese (default)
1353+ mockSelect . mockResolvedValueOnce ( 'ja-JP' ) ;
1354+ queueSelections ( DONE ) ;
1355+ await initCommand . execute ( testDir ) ;
1356+
1357+ // Verify language remains Japanese
13111358 const configPath = path . join ( testDir , 'openspec' , 'config.json' ) ;
13121359 const configContent = await fs . readFile ( configPath , 'utf-8' ) ;
13131360 const config = JSON . parse ( configContent ) ;
1314- expect ( config . language ) . toBe ( 'zh-CN' ) ;
1361+ expect ( config . language ) . toBe ( 'ja-JP' ) ;
1362+
1363+ // Verify language prompt was called with Japanese as default
1364+ expect ( mockSelect ) . toHaveBeenCalledWith (
1365+ expect . objectContaining ( {
1366+ message : 'Select your preferred language:' ,
1367+ default : 'ja-JP' ,
1368+ } )
1369+ ) ;
13151370 } ) ;
13161371
13171372 it ( 'should use French templates when language is fr-FR' , async ( ) => {
0 commit comments