Administrator counters were derived from the stage-filtered first human-item page, while annotators used an aggregate. Add authorized whole-pool counters with a five-second bounded cache, page human items before joining task summaries, and search older metadata on the server. Cancel stale reads and preserve existing non-admin scope behavior. Cover permissions, mixed stages, real Mongo parity, old-page search, categories, pagination, stale responses and claim invalidation.
71 lines
2.9 KiB
Go
71 lines
2.9 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"droboticflow/internal/domain"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"os/exec"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAdminAnnotationPoolBrowserReplica(t *testing.T) {
|
|
if os.Getenv("ADMIN_POOL_BROWSER_TEST") != "1" {
|
|
t.Skip("local browser opt-in")
|
|
}
|
|
f := randomClaimFixture(t, 610)
|
|
admin := domain.UserRecord{ID: "pool-admin", OrganizationID: domain.DefaultOrganizationID, Role: domain.UserRoleAdmin, Status: domain.UserStatusActive}
|
|
_ = f.store.UpsertUser(f.ctx, admin)
|
|
_ = f.store.UpsertOrganizationPlugin(f.ctx, domain.OrganizationPluginRecord{OrganizationID: domain.DefaultOrganizationID, PluginID: "annotation-qa", Enabled: true, Config: defaultAnnotationPluginConfig()})
|
|
for n := 0; n < 610; n++ {
|
|
item, _ := f.store.GetHumanItem(f.ctx, fmt.Sprintf("random-item-%d", n))
|
|
task, _ := f.store.GetAnnotationTask(f.ctx, item.LegacyTaskID)
|
|
stamp := fmt.Sprintf("2026-10-21T00:%02d:%02dZ", n/60, n%60)
|
|
item.CreatedAt = stamp
|
|
task.CreatedAt = stamp
|
|
item.Subject.ItemKey = fmt.Sprintf("CAPTURE_%04d_camera_left_part0001.mp4", n)
|
|
task.ArtifactID = item.Subject.ItemKey
|
|
task.SourceVideo = item.Subject.ItemKey
|
|
item.Subject.Payload = map[string]any{"sliceWorkflow": map[string]any{"status": "editing", "phase": "slice"}}
|
|
if n >= 606 {
|
|
item.CurrentStageID = "quality_review"
|
|
task.Status = domain.AnnotationTaskStatusPendingQuality
|
|
}
|
|
_ = f.store.UpsertHumanItem(f.ctx, *item)
|
|
_ = f.store.UpsertAnnotationTask(f.ctx, *task)
|
|
}
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path == "/api/auth/me" {
|
|
renderJSON(w, 200, map[string]any{"user": sanitizeUser(&admin), "organization": domain.OrganizationRecord{ID: domain.DefaultOrganizationID, Status: domain.OrganizationStatusActive}})
|
|
return
|
|
}
|
|
if r.URL.Path == "/__fixture/claim" {
|
|
result := f.request(http.MethodPost, "/api/plugins/annotation-qa/random-claims", f.annotator, map[string]any{"projectId": f.task.ProjectID, "requestId": "admin-pool-fixture-claim-01"})
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(result.Code)
|
|
_, _ = w.Write(result.Body.Bytes())
|
|
return
|
|
}
|
|
if r.Method != "GET" && r.Method != "HEAD" {
|
|
renderJSON(w, 403, map[string]string{"error": "fixture read-only"})
|
|
return
|
|
}
|
|
r = r.WithContext(context.WithValue(r.Context(), authContextKey{}, &authenticatedPrincipal{User: admin, Organization: domain.OrganizationRecord{ID: domain.DefaultOrganizationID, Status: domain.OrganizationStatusActive}}))
|
|
f.handler.ServeHTTP(w, r)
|
|
}))
|
|
defer server.Close()
|
|
ctx, cancel := context.WithTimeout(t.Context(), 3*time.Minute)
|
|
defer cancel()
|
|
cmd := exec.CommandContext(ctx, "node", "tests/browser/admin-annotation-pool-replica.mjs")
|
|
cmd.Dir = "../.."
|
|
cmd.Env = append(os.Environ(), "ADMIN_POOL_API="+server.URL)
|
|
out, err := cmd.CombinedOutput()
|
|
t.Log(string(out))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|