From 3b17f2af8d902b5df80735d9ea8a9be3a720cd01 Mon Sep 17 00:00:00 2001 From: jcfs Date: Sun, 11 Jan 2026 00:29:54 +0000 Subject: [PATCH] test: Add integration test to verify session_id is stored in task metadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Wire session_info ACP handler in test server (mirrors main.go) - Update TestOrchestratorSessionInfo to verify auggie_session_id is stored - Test confirms session ID flows from agent → event bus → task metadata --- .../internal/integration/orchestrator_test.go | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/apps/backend/internal/integration/orchestrator_test.go b/apps/backend/internal/integration/orchestrator_test.go index e659d0c1ed..42be91055e 100644 --- a/apps/backend/internal/integration/orchestrator_test.go +++ b/apps/backend/internal/integration/orchestrator_test.go @@ -478,6 +478,19 @@ func NewOrchestratorTestServer(t *testing.T) *OrchestratorTestServer { gateway.Hub.BroadcastToTask(taskID, notification) }) + // Wire ACP handler to extract session_id from session_info messages and store in task metadata + // This mirrors the handler in main.go + orchestratorSvc.RegisterACPHandler(func(taskID string, msg *protocol.Message) { + if msg.Type == protocol.MessageTypeSessionInfo && msg.Data != nil { + if sessionID, ok := msg.Data["session_id"].(string); ok && sessionID != "" { + metadata := map[string]interface{}{ + "auggie_session_id": sessionID, + } + taskSvc.UpdateTaskMetadata(context.Background(), taskID, metadata) + } + } + }) + // Start orchestrator require.NoError(t, orchestratorSvc.Start(ctx)) @@ -1325,6 +1338,9 @@ func TestOrchestratorSessionInfo(t *testing.T) { ts := NewOrchestratorTestServer(t) defer ts.Close() + // Use a known session ID for verification + expectedSessionID := "test-session-abc12345" + // Configure agent to send session_info message ts.AgentManager.SetACPMessageFn(func(taskID, instanceID string) []protocol.Message { return []protocol.Message{ @@ -1333,7 +1349,7 @@ func TestOrchestratorSessionInfo(t *testing.T) { TaskID: taskID, Timestamp: time.Now(), Data: map[string]interface{}{ - "session_id": "test-session-" + instanceID[:8], + "session_id": expectedSessionID, }, }, { @@ -1359,14 +1375,17 @@ func TestOrchestratorSessionInfo(t *testing.T) { }) require.NoError(t, err) - // Wait for execution + // Wait for execution and event processing time.Sleep(500 * time.Millisecond) - // The session_id should have been stored in task metadata - // (This would require the ACP handler that extracts session_id, which is wired in main.go) - // For now, just verify the task exists + // Verify the session_id was stored in task metadata task, err := ts.TaskRepo.GetTask(context.Background(), taskID) require.NoError(t, err) - assert.NotNil(t, task) + require.NotNil(t, task) + require.NotNil(t, task.Metadata, "task metadata should not be nil") + + storedSessionID, ok := task.Metadata["auggie_session_id"] + require.True(t, ok, "auggie_session_id should be present in task metadata") + assert.Equal(t, expectedSessionID, storedSessionID, "session ID should match what the agent sent") }