|
1 | 1 | package tui |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strings" |
4 | 5 | "testing" |
5 | 6 |
|
6 | 7 | agentruntime "neo-code/internal/runtime" |
@@ -161,3 +162,92 @@ func TestShouldHandleRuntimeEventFiltersBySessionAndRun(t *testing.T) { |
161 | 162 | t.Fatalf("expected matched event to be handled") |
162 | 163 | } |
163 | 164 | } |
| 165 | + |
| 166 | +func TestRuntimeEventMultimodalHandlers(t *testing.T) { |
| 167 | + t.Parallel() |
| 168 | + |
| 169 | + app, _ := newTestApp(t) |
| 170 | + |
| 171 | + if handled := runtimeEventInputNormalizedHandler(&app, agentruntime.RuntimeEvent{Payload: "bad"}); handled { |
| 172 | + t.Fatalf("expected invalid normalized payload to return false") |
| 173 | + } |
| 174 | + runtimeEventInputNormalizedHandler(&app, agentruntime.RuntimeEvent{ |
| 175 | + RunID: "run-1", |
| 176 | + Payload: agentruntime.InputNormalizedPayload{ |
| 177 | + TextLength: 12, |
| 178 | + ImageCount: 2, |
| 179 | + }, |
| 180 | + }) |
| 181 | + if app.state.ActiveRunID != "run-1" { |
| 182 | + t.Fatalf("expected active run id to be updated, got %q", app.state.ActiveRunID) |
| 183 | + } |
| 184 | + if len(app.activities) == 0 { |
| 185 | + t.Fatalf("expected input normalized activity to be appended") |
| 186 | + } |
| 187 | + last := app.activities[len(app.activities)-1] |
| 188 | + if last.Title != "Input normalized" || !strings.Contains(last.Detail, "images=2") { |
| 189 | + t.Fatalf("unexpected normalized activity: %+v", last) |
| 190 | + } |
| 191 | + |
| 192 | + before := len(app.activities) |
| 193 | + runtimeEventAssetSavedHandler(&app, agentruntime.RuntimeEvent{ |
| 194 | + Payload: agentruntime.AssetSavedPayload{ |
| 195 | + AssetID: "asset-1", |
| 196 | + Path: "/tmp/chart.png", |
| 197 | + }, |
| 198 | + }) |
| 199 | + if len(app.activities) != before+1 { |
| 200 | + t.Fatalf("expected saved attachment activity appended") |
| 201 | + } |
| 202 | + last = app.activities[len(app.activities)-1] |
| 203 | + if last.Title != "Saved attachment" || !strings.Contains(last.Detail, "chart.png") { |
| 204 | + t.Fatalf("unexpected asset saved activity: %+v", last) |
| 205 | + } |
| 206 | + if handled := runtimeEventAssetSavedHandler(&app, agentruntime.RuntimeEvent{Payload: 123}); handled { |
| 207 | + t.Fatalf("expected invalid asset_saved payload to return false") |
| 208 | + } |
| 209 | + |
| 210 | + runtimeEventAssetSaveFailedHandler(&app, agentruntime.RuntimeEvent{ |
| 211 | + Payload: agentruntime.AssetSaveFailedPayload{Message: " failed "}, |
| 212 | + }) |
| 213 | + if app.state.ExecutionError != "failed" || app.state.StatusText != "failed" { |
| 214 | + t.Fatalf("expected failed status to be surfaced, got status=%q err=%q", app.state.StatusText, app.state.ExecutionError) |
| 215 | + } |
| 216 | + last = app.activities[len(app.activities)-1] |
| 217 | + if !last.IsError || last.Title != "Failed to save attachment" { |
| 218 | + t.Fatalf("unexpected asset save failed activity: %+v", last) |
| 219 | + } |
| 220 | + runtimeEventAssetSaveFailedHandler(&app, agentruntime.RuntimeEvent{ |
| 221 | + Payload: agentruntime.AssetSaveFailedPayload{}, |
| 222 | + }) |
| 223 | + if app.state.ExecutionError != "failed to save attachment" || app.state.StatusText != "failed to save attachment" { |
| 224 | + t.Fatalf("expected default failed message, got status=%q err=%q", app.state.StatusText, app.state.ExecutionError) |
| 225 | + } |
| 226 | + if handled := runtimeEventAssetSaveFailedHandler(&app, agentruntime.RuntimeEvent{Payload: true}); handled { |
| 227 | + t.Fatalf("expected invalid asset_save_failed payload to return false") |
| 228 | + } |
| 229 | +} |
| 230 | + |
| 231 | +func TestHandleRuntimeEventSetsSessionAndRoutesByRegistry(t *testing.T) { |
| 232 | + t.Parallel() |
| 233 | + |
| 234 | + app, _ := newTestApp(t) |
| 235 | + handled := app.handleRuntimeEvent(agentruntime.RuntimeEvent{ |
| 236 | + Type: agentruntime.EventAssetSaved, |
| 237 | + SessionID: "session-1", |
| 238 | + Payload: agentruntime.AssetSavedPayload{AssetID: "asset-1"}, |
| 239 | + }) |
| 240 | + if handled { |
| 241 | + t.Fatalf("expected asset_saved handler to return false") |
| 242 | + } |
| 243 | + if app.state.ActiveSessionID != "session-1" { |
| 244 | + t.Fatalf("expected active session to be set from event, got %q", app.state.ActiveSessionID) |
| 245 | + } |
| 246 | + if len(app.activities) == 0 || app.activities[len(app.activities)-1].Title != "Saved attachment" { |
| 247 | + t.Fatalf("expected saved attachment activity") |
| 248 | + } |
| 249 | + |
| 250 | + if app.handleRuntimeEvent(agentruntime.RuntimeEvent{Type: "unknown_event", SessionID: "session-1"}) { |
| 251 | + t.Fatalf("expected unknown event handler result to be false") |
| 252 | + } |
| 253 | +} |
0 commit comments