Files
agents/control-plane/internal/handlers/workflow_execution_events_test.go
zeekay 114b9701db refactor: /v1/ canonical paths (sweep)
Per global rule: /v1/ only, never /api/. Internal API calls + handler
comments + route registrations updated.

- Control plane: agentAPI mount moves from /api/v1 -> /v1; uiAPI from
  /api/ui/v1 -> /v1/ui; uiAPIV2 from /api/ui/v2 -> /v2/ui. Auth middleware
  /api/v1/health -> /v1/health. All UI handler comments updated.
- Go SDK (sdk/go/agent, sdk/go/client): control_plane_memory_backend,
  discovery, agent, note, client now use /v1/* and /v1/ui/* canonically.
- LegacyExecutionEndpoints catalog in pkg/types/execution.go normalized
  to /v1/* and /v1/ui/* (UIWorkflowRunList stays /v2/ui as it's the v2 surface).
- All test fixtures updated to match the new contract.

Build note: pre-existing rot in internal/utils/paths.go and
internal/handlers/ui/env.go (hanzo-agentsHome is not a valid Go identifier;
hyphens not allowed) prevents `go build ./...` from succeeding — this
predates the sweep and is not introduced here.
2026-05-18 22:34:48 -07:00

92 lines
2.6 KiB
Go

package handlers
import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/hanzoai/agents/control-plane/pkg/types"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWorkflowExecutionEventHandler_CreateAndUpdate(t *testing.T) {
gin.SetMode(gin.TestMode)
storage := newTestExecutionStorage(&types.AgentNode{ID: "deep_research"})
handler := WorkflowExecutionEventHandler(storage)
startPayload := WorkflowExecutionEventRequest{
ExecutionID: "exec_child",
RunID: "run_123",
ReasonerID: "understand_query_deeply",
AgentNodeID: "deep_research",
Status: "running",
InputData: map[string]interface{}{
"arg": "value",
},
}
body, err := json.Marshal(startPayload)
require.NoError(t, err)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
req := httptest.NewRequest(http.MethodPost, "/v1/workflow/executions/events", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
c.Request = req
handler(c)
require.Equal(t, http.StatusOK, w.Code)
exec, err := storage.GetExecutionRecord(context.Background(), "exec_child")
require.NoError(t, err)
require.NotNil(t, exec)
assert.Equal(t, "run_123", exec.RunID)
assert.Equal(t, string(types.ExecutionStatusRunning), exec.Status)
assert.Nil(t, exec.CompletedAt)
assert.WithinDuration(t, time.Now(), exec.StartedAt, time.Second)
resultPayload := map[string]string{"result": "ok"}
duration := int64(1500)
completePayload := WorkflowExecutionEventRequest{
ExecutionID: "exec_child",
RunID: "run_123",
ReasonerID: "understand_query_deeply",
AgentNodeID: "deep_research",
Status: "succeeded",
Result: resultPayload,
DurationMS: &duration,
}
body, err = json.Marshal(completePayload)
require.NoError(t, err)
w = httptest.NewRecorder()
c, _ = gin.CreateTestContext(w)
req = httptest.NewRequest(http.MethodPost, "/v1/workflow/executions/events", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
c.Request = req
handler(c)
require.Equal(t, http.StatusOK, w.Code)
exec, err = storage.GetExecutionRecord(context.Background(), "exec_child")
require.NoError(t, err)
require.NotNil(t, exec)
assert.Equal(t, string(types.ExecutionStatusSucceeded), exec.Status)
require.NotNil(t, exec.CompletedAt)
assert.True(t, exec.CompletedAt.After(exec.StartedAt))
require.NotNil(t, exec.ResultPayload)
assert.Contains(t, string(exec.ResultPayload), "result")
require.NotNil(t, exec.DurationMS)
assert.Equal(t, duration, *exec.DurationMS)
}