v0.7.2 Package Runners + CI Gate
Five package-level test runners validating extension API contracts: - notes-runner: CRUD, folders, tags, search, backlinks (12 tests) - chat-runner: conversations, messaging, search (9 tests) - schedules-runner: CRUD + run (5 tests) - workflow-runner: definitions, instances, stage progression (5 tests) - renderer-runner: registry contract, block matching (4 tests) Runner Result API (in-memory, 3 admin endpoints) stores results from browser runs for CI consumption. Test-runners surface v0.2.0 posts results after each run and fixes suite prefix matching. CI integration via Playwright: wait-for-healthy.sh, run-surface-tests.sh, surface-test-driver.js. New test-runners stage in Gitea CI pipeline. Verified: 169 passed, 0 failed, 9 warned, 8 skipped on fresh install. Go handler tests: 4/4 passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
83
server/handlers/test_runners.go
Normal file
83
server/handlers/test_runners.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// TestRunnerHandler serves the admin test-runners result API.
|
||||
// Results are stored in memory — they reset on server restart.
|
||||
type TestRunnerHandler struct {
|
||||
mu sync.RWMutex
|
||||
byID map[string]json.RawMessage // runner-id → last results
|
||||
lastAll json.RawMessage // last "run all" results
|
||||
updated time.Time
|
||||
}
|
||||
|
||||
func NewTestRunnerHandler() *TestRunnerHandler {
|
||||
return &TestRunnerHandler{
|
||||
byID: make(map[string]json.RawMessage),
|
||||
}
|
||||
}
|
||||
|
||||
// StoreResults accepts results JSON from the browser after a test run.
|
||||
// POST /api/v1/admin/test-runners/results
|
||||
func (h *TestRunnerHandler) StoreResults(c *gin.Context) {
|
||||
var body struct {
|
||||
RunnerID string `json:"runner_id"`
|
||||
Results json.RawMessage `json:"results"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid JSON body"})
|
||||
return
|
||||
}
|
||||
if len(body.Results) == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "results field required"})
|
||||
return
|
||||
}
|
||||
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
|
||||
h.updated = time.Now()
|
||||
if body.RunnerID == "" || body.RunnerID == "all" {
|
||||
h.lastAll = body.Results
|
||||
} else {
|
||||
h.byID[body.RunnerID] = body.Results
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"stored": true, "runner_id": body.RunnerID})
|
||||
}
|
||||
|
||||
// GetAllResults returns the last stored "run all" results.
|
||||
// GET /api/v1/admin/test-runners/results
|
||||
func (h *TestRunnerHandler) GetAllResults(c *gin.Context) {
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
|
||||
if h.lastAll == nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "no results available"})
|
||||
return
|
||||
}
|
||||
c.Data(http.StatusOK, "application/json", h.lastAll)
|
||||
}
|
||||
|
||||
// GetRunnerResults returns the last stored results for a specific runner.
|
||||
// GET /api/v1/admin/test-runners/results/:id
|
||||
func (h *TestRunnerHandler) GetRunnerResults(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
|
||||
data, ok := h.byID[id]
|
||||
if !ok {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "no results for runner: " + id})
|
||||
return
|
||||
}
|
||||
c.Data(http.StatusOK, "application/json", data)
|
||||
}
|
||||
125
server/handlers/test_runners_test.go
Normal file
125
server/handlers/test_runners_test.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func setupTestRunnerRouter() (*gin.Engine, *TestRunnerHandler) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
h := NewTestRunnerHandler()
|
||||
r := gin.New()
|
||||
r.POST("/api/v1/admin/test-runners/results", h.StoreResults)
|
||||
r.GET("/api/v1/admin/test-runners/results", h.GetAllResults)
|
||||
r.GET("/api/v1/admin/test-runners/results/:id", h.GetRunnerResults)
|
||||
return r, h
|
||||
}
|
||||
|
||||
func TestTestRunnerGetAllEmpty(t *testing.T) {
|
||||
r, _ := setupTestRunnerRouter()
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/api/v1/admin/test-runners/results", nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusNotFound {
|
||||
t.Fatalf("expected 404, got %d", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTestRunnerStoreAndRetrieveAll(t *testing.T) {
|
||||
r, _ := setupTestRunnerRouter()
|
||||
|
||||
results := `{"summary":{"total":5,"passed":5,"failed":0}}`
|
||||
body, _ := json.Marshal(map[string]interface{}{
|
||||
"runner_id": "all",
|
||||
"results": json.RawMessage(results),
|
||||
})
|
||||
|
||||
// Store
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("POST", "/api/v1/admin/test-runners/results", bytes.NewReader(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("store: expected 200, got %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
|
||||
// Retrieve
|
||||
w = httptest.NewRecorder()
|
||||
req, _ = http.NewRequest("GET", "/api/v1/admin/test-runners/results", nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("get all: expected 200, got %d", w.Code)
|
||||
}
|
||||
|
||||
var got map[string]interface{}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
||||
t.Fatalf("invalid JSON: %v", err)
|
||||
}
|
||||
summary, _ := got["summary"].(map[string]interface{})
|
||||
if summary == nil {
|
||||
t.Fatal("expected summary in results")
|
||||
}
|
||||
if int(summary["failed"].(float64)) != 0 {
|
||||
t.Fatalf("expected 0 failures, got %v", summary["failed"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestTestRunnerStoreAndRetrieveByID(t *testing.T) {
|
||||
r, _ := setupTestRunnerRouter()
|
||||
|
||||
results := `{"runner":"notes-runner","summary":{"total":3,"passed":3,"failed":0}}`
|
||||
body, _ := json.Marshal(map[string]interface{}{
|
||||
"runner_id": "notes-runner",
|
||||
"results": json.RawMessage(results),
|
||||
})
|
||||
|
||||
// Store
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("POST", "/api/v1/admin/test-runners/results", bytes.NewReader(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("store: expected 200, got %d", w.Code)
|
||||
}
|
||||
|
||||
// Retrieve by ID
|
||||
w = httptest.NewRecorder()
|
||||
req, _ = http.NewRequest("GET", "/api/v1/admin/test-runners/results/notes-runner", nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("get by id: expected 200, got %d", w.Code)
|
||||
}
|
||||
|
||||
// Unknown ID → 404
|
||||
w = httptest.NewRecorder()
|
||||
req, _ = http.NewRequest("GET", "/api/v1/admin/test-runners/results/unknown", nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusNotFound {
|
||||
t.Fatalf("unknown id: expected 404, got %d", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTestRunnerStoreBadBody(t *testing.T) {
|
||||
r, _ := setupTestRunnerRouter()
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("POST", "/api/v1/admin/test-runners/results", bytes.NewReader([]byte(`{}`)))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusBadRequest {
|
||||
t.Fatalf("expected 400 for empty results, got %d", w.Code)
|
||||
}
|
||||
}
|
||||
@@ -842,6 +842,12 @@ func main() {
|
||||
admin.GET("/cluster", clusterH.ListNodes)
|
||||
}
|
||||
|
||||
// ── Test Runners ────────────
|
||||
trH := handlers.NewTestRunnerHandler()
|
||||
admin.POST("/test-runners/results", trH.StoreResults)
|
||||
admin.GET("/test-runners/results", trH.GetAllResults)
|
||||
admin.GET("/test-runners/results/:id", trH.GetRunnerResults)
|
||||
|
||||
// ── Metrics ─────────────────
|
||||
metricsCollector := metrics.NewCollector(
|
||||
nodeID, database.DB, hub, bus, stores,
|
||||
|
||||
Reference in New Issue
Block a user