droboticflow/internal/api/robodata_100_item_test.go
2026-08-19 03:08:37 +08:00

58 lines
2.3 KiB
Go

package api
import (
"context"
"fmt"
"testing"
"time"
"droboticflow/internal/domain"
"droboticflow/internal/store"
)
func TestRobodataHundredItemsReleaseAcceptedDataWithoutRejectBlocking(t *testing.T) {
ctx := context.Background()
dataStore := store.NewMemoryStore()
server := &server{store: dataStore}
batch := domain.HumanBatchRecord{ID: "batch-100", OrganizationID: "org-a", PluginID: "annotation-qa", ProjectID: "project-a", WorkflowID: "workflow-a", RunID: "run-a", GateNodeID: "gate", ReleasePolicy: domain.HumanReleaseAcceptedPartition, PartitionMaxItems: 32, PartitionMaxWaitSeconds: 60, MaxReworkRounds: 5}
if err := dataStore.UpsertHumanBatch(ctx, batch); err != nil {
t.Fatal(err)
}
acceptedAt := time.Now().Add(-2 * time.Minute).UTC().Format(time.RFC3339Nano)
for index := 0; index < 100; index++ {
status := domain.HumanItemAccepted
if index == 17 {
status = domain.HumanItemRejected
}
item := domain.HumanItemRecord{ID: fmt.Sprintf("item-%03d", index), OrganizationID: "org-a", PluginID: "annotation-qa", BatchID: batch.ID, ProjectID: batch.ProjectID, WorkflowID: batch.WorkflowID, RunID: batch.RunID, GateNodeID: batch.GateNodeID, Subject: domain.HumanSubjectRef{ItemKey: fmt.Sprintf("clip-%03d", index)}, CurrentStageID: "quality_review", Status: status, Version: 1, AcceptedAt: acceptedAt}
if err := dataStore.UpsertHumanItem(ctx, item); err != nil {
t.Fatal(err)
}
}
storedBatch, _ := dataStore.GetHumanBatch(ctx, batch.ID)
if err := server.flushHumanReleasePartitions(ctx, storedBatch, true); err != nil {
t.Fatal(err)
}
partitions, err := dataStore.ListReleasePartitions(ctx, "org-a", batch.ID)
if err != nil {
t.Fatal(err)
}
if len(partitions) != 4 {
t.Fatalf("expected 4 partitions for 99 accepted items, got %d", len(partitions))
}
released := 0
for _, partition := range partitions {
released += len(partition.ItemIDs)
if partition.ManifestDigest == "" || partition.UniqueKey == "" {
t.Fatalf("invalid partition=%#v", partition)
}
}
if released != 99 {
t.Fatalf("released=%d want=99", released)
}
rejected, _ := dataStore.GetHumanItem(ctx, "item-017")
if rejected == nil || rejected.ReleasePartitionID != "" || rejected.Status != domain.HumanItemRejected {
t.Fatalf("rejected item was incorrectly released: %#v", rejected)
}
}