@@ -806,4 +806,61 @@ void testMultipleHooksAndIdOverwrite() {
806806 assertEquals (1 , count2 [0 ], "hook2 should be called" );
807807 assertEquals (1 , count3 [0 ], "New hook1 should be called" );
808808 }
809+
810+ @ Test
811+ void testChangeHookReceivesNonNullPlanOnFinishPlan () {
812+ Plan [] capturedPlan = {null };
813+ notebook .addChangeHook ("finishHook" , (nb , plan ) -> capturedPlan [0 ] = plan );
814+
815+ List <SubTask > subtasks = List .of (new SubTask ("Task1" , "Desc1" , "Outcome1" ));
816+ notebook .createPlanWithSubTasks ("Plan" , "Desc" , "Outcome" , subtasks ).block ();
817+
818+ notebook .finishPlan ("done" , "All done" ).block ();
819+
820+ assertNotNull (capturedPlan [0 ], "Hook should receive the finished plan, not null" );
821+ assertEquals ("Plan" , capturedPlan [0 ].getName ());
822+ assertEquals (PlanState .DONE , capturedPlan [0 ].getState ());
823+ }
824+
825+ @ Test
826+ void testChangeHookReceivesNonNullPlanOnFinishPlanAbandoned () {
827+ Plan [] capturedPlan = {null };
828+ notebook .addChangeHook ("abandonHook" , (nb , plan ) -> capturedPlan [0 ] = plan );
829+
830+ List <SubTask > subtasks = List .of (new SubTask ("Task1" , "Desc1" , "Outcome1" ));
831+ notebook .createPlanWithSubTasks ("Plan" , "Desc" , "Outcome" , subtasks ).block ();
832+
833+ notebook .finishPlan ("abandoned" , "Not needed" ).block ();
834+
835+ assertNotNull (capturedPlan [0 ], "Hook should receive the abandoned plan, not null" );
836+ assertEquals (PlanState .ABANDONED , capturedPlan [0 ].getState ());
837+ }
838+
839+ @ Test
840+ void testGetCurrentPlanVisibleDuringFinishPlanHook () {
841+ Plan [] capturedViaGetter = {null };
842+ notebook .addChangeHook (
843+ "getterHook" , (nb , plan ) -> capturedViaGetter [0 ] = nb .getCurrentPlan ());
844+
845+ List <SubTask > subtasks = List .of (new SubTask ("Task1" , "Desc1" , "Outcome1" ));
846+ notebook .createPlanWithSubTasks ("Plan" , "Desc" , "Outcome" , subtasks ).block ();
847+
848+ notebook .finishPlan ("done" , "Done" ).block ();
849+
850+ assertNotNull (
851+ capturedViaGetter [0 ],
852+ "getCurrentPlan() should return the plan during hook execution" );
853+ assertEquals ("Plan" , capturedViaGetter [0 ].getName ());
854+ }
855+
856+ @ Test
857+ void testCurrentPlanIsNullAfterFinishPlanCompletes () {
858+ List <SubTask > subtasks = List .of (new SubTask ("Task1" , "Desc1" , "Outcome1" ));
859+ notebook .createPlanWithSubTasks ("Plan" , "Desc" , "Outcome" , subtasks ).block ();
860+
861+ notebook .finishPlan ("done" , "Done" ).block ();
862+
863+ assertNull (
864+ notebook .getCurrentPlan (), "currentPlan should be null after finishPlan completes" );
865+ }
809866}
0 commit comments