1d6ba6dc2e
- The attention lane was derived from page 1 of the queue (limit 50, newest by updated_at), so failures ranked past 50 silently disappeared from "needs attention" as the completed backlog grew. - Fetch attention items with a dedicated request: the API now accepts a comma-separated processing_state list (failed,stalled) and the view prefers that result set over the paged queue. - Batch retry/cancel targets are computed from the same failure set instead of the visible page, so actions reach every failing item. - 全部任务 shows 已显示 N / 共 M plus 加载更多 so rows past 50 are reachable. - Fix pre-existing ui_settings integration test: strict JSON decoding rejects the legacy updated_by field (actor comes from the session). - Tests: view regression (attention item outside the page, load-more affordance) + handler multi-state filter + isolated-DB set filter.
79 lines
2.9 KiB
Go
79 lines
2.9 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"knowledge-governance/internal/governance"
|
|
postgresstore "knowledge-governance/internal/platform/postgres"
|
|
)
|
|
|
|
func TestUISettingsWriteReadBackIntegration(t *testing.T) {
|
|
databaseURL := os.Getenv("TEST_DATABASE_URL")
|
|
if databaseURL == "" {
|
|
t.Skip("TEST_DATABASE_URL is not set")
|
|
}
|
|
ctx := context.Background()
|
|
pool, err := pgxpool.New(ctx, databaseURL)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer pool.Close()
|
|
if err := postgresstore.ApplyMigrations(ctx, pool); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
now := time.Date(2026, 9, 10, 9, 0, 0, 0, time.UTC)
|
|
handler, err := NewHandler(Config{Store: postgresstore.NewStore(pool), Now: func() time.Time { return now }})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
create := httptest.NewRecorder()
|
|
createRequest := httptest.NewRequest(http.MethodPost, "/api/v1/ui-settings/candidates", bytes.NewBufferString(`{"document_refresh_seconds":30,"resource_refresh_seconds":60,"stalled_after_seconds":3600,"finalizing_after_seconds":14400}`))
|
|
createRequest.Header.Set("X-Governance-Action", "ui-settings")
|
|
createRequest.Header.Set("Idempotency-Key", "op-e2e-uis-create")
|
|
handler.ServeHTTP(create, createRequest)
|
|
if create.Code != http.StatusCreated {
|
|
t.Fatalf("create status=%d body=%s", create.Code, create.Body.String())
|
|
}
|
|
var candidate struct {
|
|
Data governance.UISettings `json:"data"`
|
|
}
|
|
if err := json.NewDecoder(create.Body).Decode(&candidate); err != nil || candidate.Data.State != "validated" {
|
|
t.Fatalf("candidate=%#v error=%v", candidate, err)
|
|
}
|
|
|
|
activate := httptest.NewRecorder()
|
|
activateRequest := httptest.NewRequest(http.MethodPost, "/api/v1/ui-settings/"+candidate.Data.ID+"/activate", bytes.NewBufferString(`{}`))
|
|
activateRequest.Header.Set("X-Governance-Action", "ui-settings")
|
|
activateRequest.Header.Set("Idempotency-Key", "op-e2e-uis-activate")
|
|
handler.ServeHTTP(activate, activateRequest)
|
|
if activate.Code != http.StatusOK {
|
|
t.Fatalf("activate status=%d body=%s", activate.Code, activate.Body.String())
|
|
}
|
|
|
|
get := httptest.NewRecorder()
|
|
handler.ServeHTTP(get, httptest.NewRequest(http.MethodGet, "/api/v1/ui-settings", nil))
|
|
if get.Code != http.StatusOK {
|
|
t.Fatalf("get status=%d body=%s", get.Code, get.Body.String())
|
|
}
|
|
var active struct {
|
|
Data governance.UISettings `json:"data"`
|
|
}
|
|
if err := json.NewDecoder(get.Body).Decode(&active); err != nil || active.Data.ID != candidate.Data.ID || active.Data.State != "active" || active.Data.DocumentRefreshSeconds != 30 {
|
|
t.Fatalf("active=%#v error=%v", active, err)
|
|
}
|
|
var activeCount, retiredCount int
|
|
if err := pool.QueryRow(ctx, `SELECT COUNT(*) FILTER(WHERE state='active'),COUNT(*) FILTER(WHERE state='retired') FROM ui_setting_revisions`).Scan(&activeCount, &retiredCount); err != nil || activeCount != 1 || retiredCount != 1 {
|
|
t.Fatalf("active=%d retired=%d error=%v", activeCount, retiredCount, err)
|
|
}
|
|
}
|