MCPcopy Create free account
hub / github.com/compozy/agh / TestSessionEventsFollowIntegration

Function TestSessionEventsFollowIntegration

internal/cli/cli_integration_test.go:1323–1402  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1321}
1322
1323func TestSessionEventsFollowIntegration(t *testing.T) {
1324 t.Parallel()
1325
1326 h := newIntegrationHarness(t)
1327 mustExecuteRoot(t, h.deps, "daemon", "start", "-o", "json")
1328 defer func() {
1329 _, _, _ = executeRootCommand(t, h.deps, "daemon", "stop", "-o", "json")
1330 _ = h.runner.waitForExit()
1331 }()
1332
1333 sessionOut, _, err := executeRootCommand(
1334 t,
1335 h.deps,
1336 "session",
1337 "new",
1338 "--agent",
1339 "coder",
1340 "--name",
1341 "demo",
1342 "--cwd",
1343 h.workspace,
1344 "-o",
1345 "json",
1346 )
1347 if err != nil {
1348 t.Fatalf("session new error = %v", err)
1349 }
1350 var created SessionRecord
1351 if err := json.Unmarshal([]byte(sessionOut), &created); err != nil {
1352 t.Fatalf("json.Unmarshal(session new) error = %v", err)
1353 }
1354
1355 if _, _, err := executeRootCommand(t, h.deps, "session", "prompt", created.ID, "hello", "-o", "json"); err != nil {
1356 t.Fatalf("session prompt error = %v", err)
1357 }
1358
1359 cmd := newRootCommand(h.deps)
1360 var stderr bytes.Buffer
1361 stdout := &lockedBuffer{}
1362 cmd.SetOut(stdout)
1363 cmd.SetErr(&stderr)
1364 cmd.SetArgs([]string{"session", "events", created.ID, "--follow", "-o", "json"})
1365
1366 done := make(chan error, 1)
1367 go func() {
1368 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
1369 defer cancel()
1370 done <- cmd.ExecuteContext(ctx)
1371 }()
1372
1373 waitForCondition(t, 3*time.Second, func() bool {
1374 return strings.Contains(stdout.String(), `"type":"agent_message"`)
1375 })
1376
1377 if _, _, err := executeRootCommand(t, h.deps, "daemon", "stop", "-o", "json"); err != nil {
1378 t.Fatalf("daemon stop error = %v", err)
1379 }
1380

Callers

nothing calls this directly

Calls 8

StringMethod · 0.95
newIntegrationHarnessFunction · 0.85
mustExecuteRootFunction · 0.85
executeRootCommandFunction · 0.85
newRootCommandFunction · 0.85
ContainsMethod · 0.80
waitForConditionFunction · 0.70
waitForExitMethod · 0.45

Tested by

no test coverage detected