@@ -89,6 +89,26 @@ suite('InstallPackagesTool Unit Tests', () => {
8989 assert . isTrue ( hasExecuted , 'Should return true for notebook with executed cells' ) ;
9090 } ) ;
9191
92+ test ( 'Should not detect cells with execution order 0' , ( ) => {
93+ // Setup notebook with cell that has execution order 0 (not executed)
94+ const mockNonExecutedCell = {
95+ kind : vscode . NotebookCellKind . Code ,
96+ executionSummary : { executionOrder : 0 }
97+ } as vscode . NotebookCell ;
98+
99+ mockCells . push ( mockNonExecutedCell ) ;
100+
101+ installPackagesTool = new InstallPackagesTool (
102+ instance ( kernelProvider ) ,
103+ instance ( controllerRegistration ) ,
104+ instance ( installationManager )
105+ ) ;
106+
107+ // hasExecutedCells should return false for cell with execution order 0
108+ const hasExecuted = ( installPackagesTool as any ) . hasExecutedCells ( mockNotebook ) ;
109+ assert . isFalse ( hasExecuted , 'Should return false for cell with execution order 0' ) ;
110+ } ) ;
111+
92112 test ( 'Should track cell execution via event listener' , ( ) => {
93113 let onDidChangeCallback : ( e : vscode . NotebookDocumentChangeEvent ) => void ;
94114
@@ -170,6 +190,29 @@ suite('InstallPackagesTool Unit Tests', () => {
170190 assert . isFalse ( ( installPackagesTool as any ) . hasExecutedCells ( mockNotebook ) ) ;
171191 } ) ;
172192
193+ test ( 'Should handle errors gracefully during initialization' , ( ) => {
194+ // Setup notebook that throws error when getCells is called
195+ const mockErrorNotebook = {
196+ uri : vscode . Uri . file ( '/test/error-notebook.ipynb' ) ,
197+ getCells : sinon . stub ( ) . throws ( new Error ( 'Test error' ) )
198+ } as any ;
199+
200+ mockWorkspace . notebookDocuments = [ mockErrorNotebook ] ;
201+
202+ // Should not throw error during initialization
203+ assert . doesNotThrow ( ( ) => {
204+ installPackagesTool = new InstallPackagesTool (
205+ instance ( kernelProvider ) ,
206+ instance ( controllerRegistration ) ,
207+ instance ( installationManager )
208+ ) ;
209+ } , 'Should handle initialization errors gracefully' ) ;
210+
211+ // Should return false for error case
212+ const hasExecuted = ( installPackagesTool as any ) . hasExecutedCells ( mockErrorNotebook ) ;
213+ assert . isFalse ( hasExecuted , 'Should return false when error occurs' ) ;
214+ } ) ;
215+
173216 test ( 'Should dispose of event listeners properly' , ( ) => {
174217 const disposeSpy = sinon . spy ( ) ;
175218 ( mockWorkspace . onDidChangeNotebookDocument as sinon . SinonStub ) . returns ( { dispose : disposeSpy } ) ;
0 commit comments