forked from longtao.wu/droboticflow
66 lines
3.9 KiB
Go
66 lines
3.9 KiB
Go
package worker
|
|
|
|
import (
|
|
"context"
|
|
"droboticflow/internal/domain"
|
|
"droboticflow/internal/store"
|
|
"testing"
|
|
)
|
|
|
|
func TestCaptureEvidencePreservesFrozenSamplingAfterPackaging(t *testing.T) {
|
|
for _, decision := range []domain.CaptureSamplingDecisionValue{domain.CaptureSamplingNotSelected, domain.CaptureSamplingSelected} {
|
|
t.Run(string(decision), func(t *testing.T) {
|
|
ctx := context.Background()
|
|
s := store.NewMemoryStore()
|
|
r := &Runtime{store: s}
|
|
b := domain.HumanBatchRecord{ID: "b", RunID: "parent", RequirePrePackageAcceptance: true}
|
|
s.UpsertRun(ctx, domain.RunRecord{ID: "child", ParentRunID: "parent", TaskID: "cap", WorkflowID: "wf", OrganizationID: "org", Trigger: domain.RunTriggerHumanRelease})
|
|
s.UpsertCaptureRecord(ctx, domain.CaptureRecord{ID: "cap", RunID: "child", WorkflowID: "wf", OrganizationID: "org", SamplingDecision: &domain.CaptureSamplingDecision{Decision: decision, Probability: 0.5, PolicyRevision: 7, RandomValue: 0.2, DecidedAt: "2026-09-07T00:00:00Z"}})
|
|
if decision == domain.CaptureSamplingSelected {
|
|
s.UpsertHumanBatch(ctx, domain.HumanBatchRecord{ID: "human-batch-fanyu-v5-prepackage-acceptance-b"})
|
|
s.UpsertHumanItem(ctx, domain.HumanItemRecord{ID: "human-item-fanyu-v5-prepackage-acceptance-b", Status: domain.HumanItemAccepted, AcceptedAt: "2026-09-07T01:00:00Z", AcceptedByUserID: "reviewer"})
|
|
}
|
|
got, err := fanyuV5PrePackageAcceptanceEvidence(ctx, r, &b)
|
|
if err != nil || got["samplingProbability"] != 0.5 || got["samplingPolicyRevision"] != 7 || got["samplingRandomValue"] != 0.2 || got["samplingDecidedAt"] != "2026-09-07T00:00:00Z" {
|
|
t.Fatalf("frozen evidence: %#v %v", got, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCompactWilorFrameCountRemainsVisible(t *testing.T) {
|
|
for _, count := range []int{14, 53} {
|
|
got := annotationPoseSummary([]domain.ExecutionArtifact{{ID: "wilor", Data: compactArtifactData(map[string]any{"schemaVersion": "droboticflow.wilor.hand_pose_result/v1", "frameCount": count, "frames": []any{}})}})
|
|
if got["handposeFrameCount"] != count || got["handPrelabelFrameCount"] != count {
|
|
t.Fatalf("summary: %#v", got)
|
|
}
|
|
}
|
|
for _, data := range []map[string]any{
|
|
{"schemaVersion": "droboticflow.wilor.hand_pose_result/v1", "result": map[string]any{"frameCount": 14}},
|
|
{"schemaVersion": "droboticflow.wilor.hand_pose_result/v1", "framesCount": 14},
|
|
} {
|
|
got := annotationPoseSummary([]domain.ExecutionArtifact{{ID: "wilor", Data: compactArtifactData(data)}})
|
|
if got["handposeFrameCount"] != 14 {
|
|
t.Fatalf("transport lost count: %#v", got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCaptureSamplingExemptionFinalizesWithoutInventingReviewer(t *testing.T) {
|
|
ctx := context.Background()
|
|
s := store.NewMemoryStore()
|
|
r := &Runtime{store: s}
|
|
b := domain.HumanBatchRecord{ID: "batch", OrganizationID: "org", WorkflowID: "wf", RunID: "parent", GateNodeID: "human", RequirePrePackageAcceptance: true}
|
|
s.UpsertRun(ctx, domain.RunRecord{ID: "parent", OrganizationID: "org", WorkflowID: "wf", TaskID: "cap"})
|
|
s.UpsertRun(ctx, domain.RunRecord{ID: "child", OrganizationID: "org", WorkflowID: "wf", TaskID: "cap", ParentRunID: "parent", Trigger: domain.RunTriggerHumanRelease, Status: domain.RunStatusCompleted, NodeExecutions: []domain.NodeExecutionRecord{{NodeID: "package", Artifacts: []domain.ExecutionArtifact{{ID: "manifest", RunID: "child", Name: "packages-manifest.json"}}}}})
|
|
s.UpsertCaptureRecord(ctx, domain.CaptureRecord{ID: "cap", OrganizationID: "org", WorkflowID: "wf", RunID: "child", SamplingDecision: &domain.CaptureSamplingDecision{Decision: domain.CaptureSamplingNotSelected, Probability: 0}})
|
|
partition := domain.ReleasePartitionRecord{ID: "partition", ChildRunID: "child"}
|
|
if err := r.syncDeliveryPackage(ctx, b, partition); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
packages, err := s.ListDeliveryPackages(ctx, "org", domain.DeliveryPackageQuery{})
|
|
if err != nil || len(packages) != 1 || packages[0].Status != domain.DeliveryPackageAccepted || len(packages[0].AcceptanceReviews) != 0 {
|
|
t.Fatalf("unexpected acceptance: %#v %v", packages, err)
|
|
}
|
|
}
|