@@ -4,6 +4,7 @@ import * as path from 'node:path';
44import { Command } from 'commander' ;
55import { afterAll , beforeAll , describe , expect , it , vi } from 'vitest' ;
66import { cleanCommand } from './clean' ;
7+ import { indexCommand } from './index' ;
78import { initCommand } from './init' ;
89
910describe ( 'CLI Commands' , ( ) => {
@@ -72,4 +73,58 @@ describe('CLI Commands', () => {
7273 expect ( forceOption ?. short ) . toBe ( '-f' ) ;
7374 } ) ;
7475 } ) ;
76+
77+ describe ( 'index command' , ( ) => {
78+ it ( 'should have correct command name and description' , ( ) => {
79+ expect ( indexCommand . name ( ) ) . toBe ( 'index' ) ;
80+ expect ( indexCommand . description ( ) ) . toBe (
81+ 'Index a repository (code, git history, GitHub issues/PRs)'
82+ ) ;
83+ } ) ;
84+
85+ it ( 'should display storage size after indexing' , async ( ) => {
86+ const indexDir = path . join ( testDir , 'index-test' ) ;
87+ await fs . mkdir ( indexDir , { recursive : true } ) ;
88+
89+ // Create a simple TypeScript file to index
90+ await fs . writeFile (
91+ path . join ( indexDir , 'sample.ts' ) ,
92+ `export function greet(name: string): string {
93+ return \`Hello, \${name}!\`;
94+ }
95+
96+ export class Calculator {
97+ add(a: number, b: number): number {
98+ return a + b;
99+ }
100+ }`
101+ ) ;
102+
103+ // Capture logger output
104+ const loggedMessages : string [ ] = [ ] ;
105+ const loggerModule = await import ( '../utils/logger.js' ) ;
106+ const originalLog = loggerModule . logger . log ;
107+ vi . spyOn ( loggerModule . logger , 'log' ) . mockImplementation ( ( msg : string ) => {
108+ loggedMessages . push ( msg ) ;
109+ } ) ;
110+
111+ // Mock process.exit to prevent test termination
112+ const exitSpy = vi . spyOn ( process , 'exit' ) . mockImplementation ( ( ) => undefined as never ) ;
113+
114+ // Create a program and add the command
115+ const program = new Command ( ) ;
116+ program . addCommand ( indexCommand ) ;
117+
118+ // Run index command (skip git and github for faster test)
119+ await program . parseAsync ( [ 'node' , 'cli' , 'index' , indexDir , '--no-git' , '--no-github' ] ) ;
120+
121+ exitSpy . mockRestore ( ) ;
122+ loggerModule . logger . log = originalLog ;
123+
124+ // Verify storage size is in the output
125+ const storageSizeLog = loggedMessages . find ( ( msg ) => msg . includes ( 'Storage size:' ) ) ;
126+ expect ( storageSizeLog ) . toBeDefined ( ) ;
127+ expect ( storageSizeLog ) . toMatch ( / S t o r a g e s i z e : .* \d + ( \. \d + ) ? \s * ( B | K B | M B | G B ) / ) ;
128+ } , 30000 ) ; // 30s timeout for indexing
129+ } ) ;
75130} ) ;
0 commit comments