78 lines
2.7 KiB
Go
78 lines
2.7 KiB
Go
package api
|
|
|
|
import (
|
|
"droboticflow/internal/domain"
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAdminSourceFailureRemainsDiscoverableButUnavailable(t *testing.T) {
|
|
f := randomClaimFixture(t, 1)
|
|
task, _ := f.store.GetAnnotationTask(f.ctx, "random-task-0")
|
|
task.SourceIsFullVideo, task.TemplateVersion, task.ArtifactID = true, 5, "original-left"
|
|
if err := f.store.UpsertAnnotationTask(f.ctx, *task); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
item, _ := f.store.GetHumanItem(f.ctx, "random-item-0")
|
|
item.Subject.Payload = map[string]any{"draft": "keep annotation"}
|
|
if err := f.store.UpsertHumanItem(f.ctx, *item); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
now := time.Now().UTC()
|
|
job, err := f.store.ClaimAnnotationIndex(f.ctx, "invalid-source", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
|
if err != nil || job == nil {
|
|
t.Fatal(err)
|
|
}
|
|
job.Status, job.Error = "failed", "IMU invalid type gyr at row 418451"
|
|
if ok, err := f.store.FinishAnnotationIndex(f.ctx, *job); err != nil || !ok {
|
|
t.Fatal(err)
|
|
}
|
|
base := "/api/plugins/annotation-qa/admin-pool?projectId=" + task.ProjectID
|
|
read := func(suffix string) struct {
|
|
Items []struct {
|
|
ID string `json:"id"`
|
|
SourceValidationStatus string `json:"sourceValidationStatus"`
|
|
} `json:"items"`
|
|
Counts struct {
|
|
Available int `json:"available"`
|
|
All int `json:"all"`
|
|
} `json:"counts"`
|
|
} {
|
|
t.Helper()
|
|
var out struct {
|
|
Items []struct {
|
|
ID string `json:"id"`
|
|
SourceValidationStatus string `json:"sourceValidationStatus"`
|
|
} `json:"items"`
|
|
Counts struct {
|
|
Available int `json:"available"`
|
|
All int `json:"all"`
|
|
} `json:"counts"`
|
|
}
|
|
r := f.request(http.MethodGet, base+suffix, f.admin, nil)
|
|
if r.Code != 200 || json.Unmarshal(r.Body.Bytes(), &out) != nil {
|
|
t.Fatalf("%d %s", r.Code, r.Body)
|
|
}
|
|
return out
|
|
}
|
|
available := read("&pool=available")
|
|
if len(available.Items) != 0 || available.Counts.Available != 0 || available.Counts.All != 2 {
|
|
t.Fatalf("failed task still available or disappeared: %+v", available)
|
|
}
|
|
failed := read("&pool=all&category=source_failed")
|
|
if len(failed.Items) != 1 || failed.Items[0].ID != item.ID || failed.Items[0].SourceValidationStatus != "failed" {
|
|
t.Fatalf("exception not discoverable: %+v", failed)
|
|
}
|
|
for _, user := range []domain.UserRecord{f.annotator, f.reviewer} {
|
|
if r := f.request(http.MethodGet, base+"&pool=all&category=source_failed", user, nil); r.Code != 403 {
|
|
t.Fatalf("nonadmin exception access: %d", r.Code)
|
|
}
|
|
}
|
|
after, _ := f.store.GetHumanItem(f.ctx, item.ID)
|
|
if after.Version != item.Version || after.AssignedUserID != item.AssignedUserID || after.Subject.Payload["draft"] != "keep annotation" {
|
|
t.Fatal("diagnostic read altered task")
|
|
}
|
|
}
|