@@ -828,6 +828,40 @@ func TestSession(t *testing.T) {
828828 t .Error ("Expected error when resuming deleted session" )
829829 }
830830 })
831+ t .Run ("should get last session id" , func (t * testing.T ) {
832+ ctx .ConfigureForTest (t )
833+
834+ // Create a session and send a message to persist it
835+ session , err := client .CreateSession (t .Context (), & copilot.SessionConfig {OnPermissionRequest : copilot .PermissionHandler .ApproveAll })
836+ if err != nil {
837+ t .Fatalf ("Failed to create session: %v" , err )
838+ }
839+
840+ _ , err = session .SendAndWait (t .Context (), copilot.MessageOptions {Prompt : "Say hello" })
841+ if err != nil {
842+ t .Fatalf ("Failed to send message: %v" , err )
843+ }
844+
845+ // Small delay to ensure session data is flushed to disk
846+ time .Sleep (500 * time .Millisecond )
847+
848+ lastSessionID , err := client .GetLastSessionID (t .Context ())
849+ if err != nil {
850+ t .Fatalf ("Failed to get last session ID: %v" , err )
851+ }
852+
853+ if lastSessionID == nil {
854+ t .Fatal ("Expected last session ID to be non-nil" )
855+ }
856+
857+ if * lastSessionID != session .SessionID {
858+ t .Errorf ("Expected last session ID to be %s, got %s" , session .SessionID , * lastSessionID )
859+ }
860+
861+ if err := session .Destroy (); err != nil {
862+ t .Fatalf ("Failed to destroy session: %v" , err )
863+ }
864+ })
831865}
832866
833867func getSystemMessage (exchange testharness.ParsedHttpExchange ) string {
0 commit comments