|
| 1 | +package integration_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "net/http" |
| 6 | + "net/http/httptest" |
| 7 | + "path/filepath" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/LAA-Software-Engineering/agentic-control-plane/internal/inspect" |
| 11 | + "github.com/LAA-Software-Engineering/agentic-control-plane/internal/state/sqlite" |
| 12 | +) |
| 13 | + |
| 14 | +// TestIntegration_inspectWeb_API_afterRun seeds state via CLI run, then hits inspector HTTP API. |
| 15 | +func TestIntegration_inspectWeb_API_afterRun(t *testing.T) { |
| 16 | + parent := t.TempDir() |
| 17 | + projName := "inspectweb" |
| 18 | + projDir := filepath.Join(parent, projName) |
| 19 | + db := filepath.Join(t.TempDir(), "inspect-web.db") |
| 20 | + |
| 21 | + out, err := runCLI(t, "init", projName, "--parent-dir", parent) |
| 22 | + if err != nil { |
| 23 | + t.Fatalf("init: %v\n%s", err, out) |
| 24 | + } |
| 25 | + out, err = runCLI(t, "apply", "--project", projDir, "--state", db, "--auto-approve") |
| 26 | + if err != nil { |
| 27 | + t.Fatalf("apply: %v\n%s", err, out) |
| 28 | + } |
| 29 | + out, err = runCLI(t, "run", "workflow/hello", "--project", projDir, "--state", db, "--input", "topic=web-int") |
| 30 | + if err != nil { |
| 31 | + t.Fatalf("run: %v\n%s", err, out) |
| 32 | + } |
| 33 | + runID := extractRunID(out) |
| 34 | + if runID == "" { |
| 35 | + t.Fatalf("no run id in:\n%s", out) |
| 36 | + } |
| 37 | + |
| 38 | + st, err := sqlite.OpenReadOnly(t.Context(), db) |
| 39 | + if err != nil { |
| 40 | + t.Fatal(err) |
| 41 | + } |
| 42 | + t.Cleanup(func() { _ = st.Close() }) |
| 43 | + |
| 44 | + srv, err := inspect.NewServer(st, inspect.Config{StatePath: db, Env: "local"}) |
| 45 | + if err != nil { |
| 46 | + t.Fatal(err) |
| 47 | + } |
| 48 | + ts := httptest.NewServer(srv.Handler()) |
| 49 | + t.Cleanup(ts.Close) |
| 50 | + |
| 51 | + res, err := http.Get(ts.URL + "/api/runs/" + runID) |
| 52 | + if err != nil { |
| 53 | + t.Fatal(err) |
| 54 | + } |
| 55 | + defer res.Body.Close() |
| 56 | + if res.StatusCode != http.StatusOK { |
| 57 | + t.Fatalf("status=%d", res.StatusCode) |
| 58 | + } |
| 59 | + if res.Header.Get("X-Content-Type-Options") != "nosniff" { |
| 60 | + t.Fatalf("missing security headers: %v", res.Header) |
| 61 | + } |
| 62 | + var body inspect.RunDetailResponse |
| 63 | + if err := json.NewDecoder(res.Body).Decode(&body); err != nil { |
| 64 | + t.Fatal(err) |
| 65 | + } |
| 66 | + if body.Run.RunID != runID { |
| 67 | + t.Fatalf("run=%+v", body.Run) |
| 68 | + } |
| 69 | + if len(body.Events) == 0 { |
| 70 | + t.Fatal("expected trace events") |
| 71 | + } |
| 72 | +} |
0 commit comments