@@ -394,6 +394,7 @@ test('init fails without overwriting malformed existing agent-card.json', () =>
394394 assert . match ( result . stderr , / I n v a l i d a g e n t - c a r d \. j s o n / ) ;
395395 assert . equal ( readFileSync ( cardPath , 'utf8' ) , '{bad json' ) ;
396396 assert . equal ( existsSync ( join ( cwd , '.nit' ) ) , false ) ;
397+ assert . equal ( existsSync ( join ( cwd , '.gitignore' ) ) , false ) ;
397398} ) ;
398399
399400test ( 'init fails before creating .nit when existing card lacks required fields' , ( ) => {
@@ -405,6 +406,7 @@ test('init fails before creating .nit when existing card lacks required fields',
405406 assert . notEqual ( result . status , 0 ) ;
406407 assert . match ( result . stderr , / m i s s i n g " n a m e " / ) ;
407408 assert . equal ( existsSync ( join ( cwd , '.nit' ) ) , false ) ;
409+ assert . equal ( existsSync ( join ( cwd , '.gitignore' ) ) , false ) ;
408410} ) ;
409411
410412test ( 'init rejects malformed skill entries before creating .nit' , ( ) => {
@@ -420,6 +422,37 @@ test('init rejects malformed skill entries before creating .nit', () => {
420422 assert . notEqual ( result . status , 0 ) ;
421423 assert . match ( result . stderr , / s k i l l s \[ 0 \] m u s t b e a J S O N o b j e c t / ) ;
422424 assert . equal ( existsSync ( join ( cwd , '.nit' ) ) , false ) ;
425+ assert . equal ( existsSync ( join ( cwd , '.gitignore' ) ) , false ) ;
426+ } ) ;
427+
428+ test ( 'init creates .gitignore entry for private nit state' , ( ) => {
429+ const cwd = workspace ( 'nit-init-gitignore-' ) ;
430+ initWorkspace ( cwd ) ;
431+
432+ const gitignore = readFileSync ( join ( cwd , '.gitignore' ) , 'utf8' ) ;
433+ assert . match ( gitignore , / ^ \. n i t \/ $ / m) ;
434+ } ) ;
435+
436+ test ( 'init appends .nit to existing .gitignore exactly once' , ( ) => {
437+ const cwd = workspace ( 'nit-init-gitignore-existing-' ) ;
438+ writeFileSync ( join ( cwd , '.gitignore' ) , 'node_modules/\n.DS_Store' , 'utf8' ) ;
439+
440+ initWorkspace ( cwd ) ;
441+
442+ const gitignore = readFileSync ( join ( cwd , '.gitignore' ) , 'utf8' ) ;
443+ assert . match ( gitignore , / ^ n o d e _ m o d u l e s \/ / ) ;
444+ assert . match ( gitignore , / \. D S _ S t o r e \n \. n i t \/ \n $ / ) ;
445+ assert . equal ( ( gitignore . match ( / ^ \. n i t \/ $ / gm) ?? [ ] ) . length , 1 ) ;
446+ } ) ;
447+
448+ test ( 'init respects existing .nit ignore variants without duplicating' , ( ) => {
449+ const cwd = workspace ( 'nit-init-gitignore-existing-nit-' ) ;
450+ writeFileSync ( join ( cwd , '.gitignore' ) , '# local\n/.nit/\n' , 'utf8' ) ;
451+
452+ initWorkspace ( cwd ) ;
453+
454+ const gitignore = readFileSync ( join ( cwd , '.gitignore' ) , 'utf8' ) ;
455+ assert . equal ( gitignore , '# local\n/.nit/\n' ) ;
423456} ) ;
424457
425458test ( 'checkout fails closed when working card is malformed' , ( ) => {
0 commit comments