package api import ( "context" "droboticflow/internal/domain" "droboticflow/internal/store" "encoding/json" "net/http" "testing" ) // Exercise the real receipt decision path: a recovery marker that exists only // on the in-memory plan disappears on restart and strands deleted-author work. func TestReviewRejectionPersistsDeletedAuthorRoutingIntent(t *testing.T) { t.Setenv("DELETED_ANNOTATOR_HANDOFF", "true") f := decisionFixture(t) f.item.LatestAuthorUserID = f.annotator.ID f.item.SupplierID = f.annotator.SupplierID f.item.MaxReworkRounds = 5 if err := f.store.UpsertHumanItem(f.ctx, f.item); err != nil { t.Fatal(err) } version, headers := openReviewDraftSession(t, f) input := map[string]any{"stage": "quality", "decision": "rejected", "reasonCodes": []string{"manual_review_reject"}, "comment": "请修正", "problemSliceIds": []string{"left"}, "operationId": "closure-routing", "draftVersion": 0, "resultVersion": version} r := reviewSessionRequest(f, http.MethodPost, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/reviews", f.reviewer, input, headers) if r.Code != 201 { t.Fatal(r.Code, r.Body.String()) } item, err := f.store.GetHumanItem(f.ctx, f.item.ID) if err != nil { t.Fatal(err) } if item.CurrentStageID != domain.FanyuV58StageAnnotationCombined || !item.ReworkRoutingPending { t.Fatal("formal rejection lost durable routing intent", item.CurrentStageID, item.ReworkRoutingPending) } } type filteredCountClosureStore struct { store.Store filteredVisits int filteredLists int } func (s *filteredCountClosureStore) VisitHumanPoolCountCandidates(ctx context.Context, org string, q domain.HumanItemQuery, visit func([]domain.HumanItemRecord) error) error { if q.Search != "" || q.Capture != "" || q.Category != "" && q.Category != "all" { s.filteredVisits++ } return s.Store.VisitHumanPoolCountCandidates(ctx, org, q, visit) } func (s *filteredCountClosureStore) ListHumanItems(ctx context.Context, org string, q domain.HumanItemQuery) ([]domain.HumanItemRecord, error) { if q.Search != "" || q.Capture != "" || q.Category != "" && q.Category != "all" { s.filteredLists++ } return s.Store.ListHumanItems(ctx, org, q) } func TestFilteredPoolCountsUseOneExhaustiveVisitorPerPool(t *testing.T) { f := newCombinedDraftFixture(t) probe := &filteredCountClosureStore{Store: f.store} f.handler = NewHandler(probe, nil) r := f.request(http.MethodGet, "/api/human-item-counts?pluginId=annotation-qa&search=capture-custom", f.admin, nil) if r.Code != 200 { t.Fatal(r.Code, r.Body.String()) } var body struct { Counts map[string]int `json:"counts"` } if err := json.Unmarshal(r.Body.Bytes(), &body); err != nil || body.Counts["all"] != 1 { t.Fatal("wrong filtered count", body, err) } if probe.filteredVisits != 4 || probe.filteredLists != 0 { t.Fatalf("filtered counts repeated paged list reads: visitors=%d lists=%d", probe.filteredVisits, probe.filteredLists) } }