@@ -686,3 +686,64 @@ func TestMain(m *testing.M) {
686
686
687
687
os .Exit (code )
688
688
}
689
+
690
+ func TestReportTaskNilPointerDeref (t * testing.T ) {
691
+ t .Parallel ()
692
+
693
+ // Create deps without a task reporter (simulating MCP server scenario)
694
+ client ,_ := coderdtest .NewWithDatabase (t ,nil )// Use a proper test client
695
+ deps ,err := toolsdk .NewDeps (client )
696
+ require .NoError (t ,err )
697
+
698
+ // Prepare test arguments
699
+ args := toolsdk.ReportTaskArgs {
700
+ Summary :"Test task" ,
701
+ Link :"https://example.com" ,
702
+ State :string (codersdk .WorkspaceAppStatusStateWorking ),
703
+ }
704
+
705
+ // This should panic with nil pointer dereference if the bug is present
706
+ ctx := t .Context ()
707
+
708
+ // Attempt to call the handler - this should cause the panic described in the issue
709
+ _ ,err = toolsdk .ReportTask .Handler (ctx ,deps ,args )
710
+
711
+ // We expect an error, not a panic
712
+ require .Error (t ,err )
713
+ require .Contains (t ,err .Error (),"task reporting not available" )
714
+ }
715
+
716
+ func TestReportTaskWithReporter (t * testing.T ) {
717
+ t .Parallel ()
718
+
719
+ // Create deps with a task reporter
720
+ client ,_ := coderdtest .NewWithDatabase (t ,nil )// Use a proper test client
721
+
722
+ called := false
723
+ reporter := func (args toolsdk.ReportTaskArgs )error {
724
+ called = true
725
+ require .Equal (t ,"Test task" ,args .Summary )
726
+ require .Equal (t ,"https://example.com" ,args .Link )
727
+ require .Equal (t ,string (codersdk .WorkspaceAppStatusStateWorking ),args .State )
728
+ return nil
729
+ }
730
+
731
+ deps ,err := toolsdk .NewDeps (client ,toolsdk .WithTaskReporter (reporter ))
732
+ require .NoError (t ,err )
733
+
734
+ // Prepare test arguments
735
+ args := toolsdk.ReportTaskArgs {
736
+ Summary :"Test task" ,
737
+ Link :"https://example.com" ,
738
+ State :string (codersdk .WorkspaceAppStatusStateWorking ),
739
+ }
740
+
741
+ // This should work correctly
742
+ ctx := t .Context ()
743
+ result ,err := toolsdk .ReportTask .Handler (ctx ,deps ,args )
744
+ require .NoError (t ,err )
745
+ require .True (t ,called )
746
+
747
+ // Verify response
748
+ require .Equal (t ,"Thanks for reporting!" ,result .Message )
749
+ }