forked from longtao.wu/droboticflow
68 lines
2.5 KiB
Go
68 lines
2.5 KiB
Go
package worker
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
)
|
|
|
|
func TestAnnotationSourceDurationReadsFaceAnonymizationV2Metrics(t *testing.T) {
|
|
artifact := domain.ExecutionArtifact{Data: map[string]any{
|
|
"schemaVersion": "droboticflow.video-face-anonymized/v2",
|
|
"privacyTransform": map[string]any{
|
|
"metrics": map[string]any{"duration": 25.07, "videoDurationSeconds": 25.070459},
|
|
},
|
|
}}
|
|
if got := annotationSourceDuration(artifact, nil); got != 25.07 {
|
|
t.Fatalf("duration=%v", got)
|
|
}
|
|
}
|
|
|
|
func TestRoughCutWindowItemsReadsInlineTimestampWindowContract(t *testing.T) {
|
|
artifact := domain.ExecutionArtifact{Data: map[string]any{
|
|
"schemaVersion": "droboticflow.rough-cut-windows/v1",
|
|
"windows": []any{map[string]any{
|
|
"id": "window-1", "startSecond": 1.0, "endSecond": 2.0,
|
|
}},
|
|
}}
|
|
items := roughCutWindowItems([]domain.ExecutionArtifact{artifact})
|
|
if len(items) != 1 || items[0]["id"] != "window-1" {
|
|
t.Fatalf("items=%#v", items)
|
|
}
|
|
}
|
|
|
|
func TestFullCoverageSliceSuggestionsPartitionTheEntireSourceWithoutGaps(t *testing.T) {
|
|
slices := fullCoverageSliceSuggestions(10, []map[string]any{
|
|
{"id": "action-a", "startSecond": 2.0, "endSecond": 4.0},
|
|
{"id": "action-b", "startSecond": 6.0, "endSecond": 8.0},
|
|
})
|
|
expected := [][2]float64{{0, 2}, {2, 4}, {4, 6}, {6, 8}, {8, 10}}
|
|
if len(slices) != len(expected) {
|
|
t.Fatalf("slices=%#v", slices)
|
|
}
|
|
for index, item := range slices {
|
|
if item.Start != expected[index][0] || item.End != expected[index][1] {
|
|
t.Fatalf("slice %d=%#v expected=%#v", index, item, expected[index])
|
|
}
|
|
if index > 0 && slices[index-1].End != item.Start {
|
|
t.Fatalf("coverage gap between %#v and %#v", slices[index-1], item)
|
|
}
|
|
}
|
|
if len(slices[1].SourceIDs) != 1 || slices[1].SourceIDs[0] != "action-a" || len(slices[3].SourceIDs) != 1 || slices[3].SourceIDs[0] != "action-b" {
|
|
t.Fatalf("Qwen provenance was not retained: %#v", slices)
|
|
}
|
|
}
|
|
|
|
func TestFullCoverageSliceSuggestionsMergeOverlappingSuggestions(t *testing.T) {
|
|
slices := fullCoverageSliceSuggestions(5, []map[string]any{
|
|
{"id": "a", "startSecond": 1.0, "endSecond": 3.0},
|
|
{"id": "b", "startSecond": 2.0, "endSecond": 4.0},
|
|
})
|
|
if len(slices) != 3 || slices[0].Start != 0 || slices[0].End != 1 || slices[1].Start != 1 || slices[1].End != 4 || slices[2].Start != 4 || slices[2].End != 5 {
|
|
t.Fatalf("overlapping suggestions must form a gap-free partition: %#v", slices)
|
|
}
|
|
if len(slices[1].SourceIDs) != 2 {
|
|
t.Fatalf("merged suggestion provenance=%#v", slices[1].SourceIDs)
|
|
}
|
|
}
|