@@ -4189,22 +4189,46 @@ func TestRebuildActivityWithHeightAndPersistPathGuard(t *testing.T) {
41894189 app .persistLogEntriesForActiveSession ()
41904190}
41914191
4192+ func updateWithSkillCommandResult (t * testing.T , app App , result skillCommandResultMsg ) App {
4193+ t .Helper ()
4194+
4195+ model , _ := app .Update (result )
4196+ return model .(App )
4197+ }
4198+
4199+ func assertIgnoredStaleSkillResultActivity (t * testing.T , app App , beforeActivities int , wantError bool ) tuistate.ActivityEntry {
4200+ t .Helper ()
4201+
4202+ if len (app .activities ) != beforeActivities + 1 {
4203+ t .Fatalf ("expected stale skill result to be logged, got %d activities" , len (app .activities ))
4204+ }
4205+ last := app .activities [len (app .activities )- 1 ]
4206+ if last .Title != "Ignored stale skill command result" {
4207+ t .Fatalf ("expected stale result activity title, got %q" , last .Title )
4208+ }
4209+ if last .IsError != wantError {
4210+ t .Fatalf ("expected stale result error flag=%v, got %v" , wantError , last .IsError )
4211+ }
4212+ return last
4213+ }
4214+
41924215func TestUpdateIgnoresStaleSkillCommandResultBySession (t * testing.T ) {
41934216 t .Parallel ()
41944217
41954218 app , _ := newTestApp (t )
41964219 app .state .ActiveSessionID = "session-current"
41974220 app .state .StatusText = "before"
4221+ beforeActivities := len (app .activities )
41984222
4199- model , _ := app . Update ( skillCommandResultMsg {
4223+ app = updateWithSkillCommandResult ( t , app , skillCommandResultMsg {
42004224 Notice : "should be ignored" ,
42014225 RequestSessionID : "session-old" ,
42024226 })
4203- app = model .(App )
42044227
42054228 if app .state .StatusText != "before" {
42064229 t .Fatalf ("expected stale skill result to be ignored, got status %q" , app .state .StatusText )
42074230 }
4231+ assertIgnoredStaleSkillResultActivity (t , app , beforeActivities , false )
42084232}
42094233
42104234func TestUpdateAcceptsSkillCommandResultForCurrentSession (t * testing.T ) {
@@ -4213,13 +4237,34 @@ func TestUpdateAcceptsSkillCommandResultForCurrentSession(t *testing.T) {
42134237 app , _ := newTestApp (t )
42144238 app .state .ActiveSessionID = "session-current"
42154239
4216- model , _ := app . Update ( skillCommandResultMsg {
4240+ app = updateWithSkillCommandResult ( t , app , skillCommandResultMsg {
42174241 Notice : "Skill command completed." ,
42184242 RequestSessionID : "session-current" ,
42194243 })
4220- app = model .(App )
42214244
42224245 if app .state .StatusText != "Skill command completed." {
42234246 t .Fatalf ("expected status to be updated, got %q" , app .state .StatusText )
42244247 }
42254248}
4249+
4250+ func TestUpdateLogsStaleSkillCommandErrorBySession (t * testing.T ) {
4251+ t .Parallel ()
4252+
4253+ app , _ := newTestApp (t )
4254+ app .state .ActiveSessionID = "session-current"
4255+ app .state .StatusText = "before"
4256+ beforeActivities := len (app .activities )
4257+
4258+ app = updateWithSkillCommandResult (t , app , skillCommandResultMsg {
4259+ Err : errors .New ("activate failed" ),
4260+ RequestSessionID : "session-old" ,
4261+ })
4262+
4263+ if app .state .StatusText != "before" {
4264+ t .Fatalf ("expected stale skill error to keep current status, got %q" , app .state .StatusText )
4265+ }
4266+ last := assertIgnoredStaleSkillResultActivity (t , app , beforeActivities , true )
4267+ if ! strings .Contains (last .Detail , "activate failed" ) {
4268+ t .Fatalf ("expected stale error detail to include original error, got %q" , last .Detail )
4269+ }
4270+ }
0 commit comments