153 lines
5.8 KiB
Go
153 lines
5.8 KiB
Go
package worker
|
|
|
|
import (
|
|
"droboticflow/internal/domain"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const layoutCapture = "FYLX_B10_AZEC86400GP_19700101_035516"
|
|
|
|
func partObjects(part string) []captureObject {
|
|
items := []captureObject{}
|
|
for _, suffix := range []string{"camera_left_" + part + "_silent_480p_wm.mp4", "camera_right_" + part + "_silent_480p_wm.mp4", "camera_left_" + part + "_pts.csv", "camera_right_" + part + "_pts.csv", "imu_" + part + ".csv"} {
|
|
items = append(items, captureObject{Key: "incoming/" + layoutCapture + "/" + part + "/" + layoutCapture + "_" + suffix, Size: 10, ETag: "original"})
|
|
}
|
|
return items
|
|
}
|
|
|
|
func calibrationObjects() []captureObject {
|
|
return []captureObject{{Key: "incoming/" + layoutCapture + "/" + layoutCapture + "_calibration_camera.yaml", Size: 2}, {Key: "incoming/" + layoutCapture + "/" + layoutCapture + "_calibration_imu.yaml", Size: 2}}
|
|
}
|
|
|
|
func discoverLayout(t *testing.T, objects []captureObject) []captureGroup {
|
|
t.Helper()
|
|
groups, err := discoverCaptureGroups(objects, normalizedCaptureAutomation(&domain.CaptureAutomationConfig{Prefix: "incoming"}))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return groups
|
|
}
|
|
|
|
func TestPartCaptureIndependentGroupsAndFingerprint(t *testing.T) {
|
|
objects := append(calibrationObjects(), partObjects("part0001")...)
|
|
objects = append(objects, partObjects("part0002")...)
|
|
groups := discoverLayout(t, objects)
|
|
if len(groups) != 2 {
|
|
t.Fatal(groups)
|
|
}
|
|
for i, g := range groups {
|
|
part := []string{"part0001", "part0002"}[i]
|
|
if len(g.Missing) != 0 || len(g.SourceKeys) != 7 || g.CaptureID != layoutCapture+"/"+part || g.SourcePrefix != "incoming/"+layoutCapture {
|
|
t.Fatalf("bad unit: %+v", g)
|
|
}
|
|
for _, key := range g.SourceKeys {
|
|
if strings.Contains(key, "part") && !strings.Contains(key, part) {
|
|
t.Fatal("cross-part reference", key)
|
|
}
|
|
}
|
|
}
|
|
objects[len(objects)-1].ETag = "changed"
|
|
next := discoverLayout(t, objects)
|
|
if groups[0].Fingerprint != next[0].Fingerprint || groups[1].Fingerprint == next[1].Fingerprint {
|
|
t.Fatal("fingerprint not isolated")
|
|
}
|
|
objects[0].ETag = "new calibration"
|
|
if discoverLayout(t, objects)[0].Fingerprint == next[0].Fingerprint {
|
|
t.Fatal("shared calibration excluded from fingerprint")
|
|
}
|
|
if captureRecordID("workflow", groups[0].Prefix) == captureRecordID("workflow", groups[1].Prefix) {
|
|
t.Fatal("part identities collide")
|
|
}
|
|
}
|
|
|
|
func TestPartCaptureMissingEmptyConflictAndWrongIdentity(t *testing.T) {
|
|
for _, kind := range []string{"missing", "empty", "wrong-part", "wrong-capture", "duplicate", "missing-calibration"} {
|
|
t.Run(kind, func(t *testing.T) {
|
|
objects := append(calibrationObjects(), partObjects("part0001")...)
|
|
switch kind {
|
|
case "missing":
|
|
objects = objects[:len(objects)-1]
|
|
case "empty":
|
|
objects[len(objects)-1].Size = 0
|
|
case "wrong-part":
|
|
objects[len(objects)-1].Key = strings.Replace(objects[len(objects)-1].Key, "_imu_part0001", "_imu_part0002", 1)
|
|
case "wrong-capture":
|
|
objects[len(objects)-1].Key = "incoming/" + layoutCapture + "/part0001/other_imu_part0001.csv"
|
|
case "duplicate":
|
|
objects = append(objects, captureObject{Key: "incoming/" + layoutCapture + "/part0001/" + layoutCapture + "_camera_left_part0001.mp4", Size: 10})
|
|
case "missing-calibration":
|
|
objects = objects[1:]
|
|
}
|
|
objects = append(objects, partObjects("part0002")...)
|
|
groups := discoverLayout(t, objects)
|
|
if len(groups) != 2 || len(groups[0].Missing) == 0 {
|
|
t.Fatal("invalid part admitted", groups)
|
|
}
|
|
if kind != "missing-calibration" && len(groups[1].Missing) != 0 {
|
|
t.Fatal("other part blocked", groups[1])
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPartCaptureMixedAndLegacyLayouts(t *testing.T) {
|
|
legacy := completeCaptureObjects("incoming", "Orbbec_Ego_legacy")
|
|
groups := discoverLayout(t, legacy)
|
|
if len(groups) != 1 || len(groups[0].Missing) != 0 || groups[0].Prefix != "incoming/Orbbec_Ego_legacy" {
|
|
t.Fatal(groups)
|
|
}
|
|
mixed := append(completeCaptureObjects("incoming", layoutCapture), partObjects("part0001")...)
|
|
groups = discoverLayout(t, mixed)
|
|
if len(groups) != 1 || !strings.Contains(strings.Join(groups[0].Missing, ""), "结构冲突") {
|
|
t.Fatal(groups)
|
|
}
|
|
}
|
|
|
|
func TestPartCaptureHistoricalParentGuard(t *testing.T) {
|
|
for _, record := range []*domain.CaptureRecord{{RunID: "old", Status: domain.CaptureRecordFailed}, {RunID: "old", Status: domain.CaptureRecordCompleted}, {Status: domain.CaptureRecordDiscarded}, {Status: domain.CaptureRecordLaunching}} {
|
|
if !preserveCaptureParent(record) {
|
|
t.Fatal("historical parent may relaunch", record)
|
|
}
|
|
}
|
|
if preserveCaptureParent(nil) || preserveCaptureParent(&domain.CaptureRecord{Status: domain.CaptureRecordIncomplete}) {
|
|
t.Fatal("unadmitted parent cannot upgrade")
|
|
}
|
|
}
|
|
|
|
func TestPartCapturePrefersVideoSpecificPTS(t *testing.T) {
|
|
objects := append(calibrationObjects(), partObjects("part0001")...)
|
|
key := "incoming/" + layoutCapture + "/part0001/" + layoutCapture + "_camera_left_part0001_silent_480p_wm_pts.csv"
|
|
objects = append(objects, captureObject{Key: key, Size: 10})
|
|
groups := discoverLayout(t, objects)
|
|
if len(groups) != 1 || len(groups[0].Missing) != 0 {
|
|
t.Fatal(groups)
|
|
}
|
|
found := false
|
|
for _, selected := range groups[0].SourceKeys {
|
|
if selected == key {
|
|
found = true
|
|
}
|
|
if strings.HasSuffix(selected, "_camera_left_part0001_pts.csv") {
|
|
t.Fatal("raw PTS selected despite video-specific PTS")
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatal("video-specific PTS missing")
|
|
}
|
|
}
|
|
|
|
func TestPartCaptureDeliveryAcceptsIndependentMultipleParts(t *testing.T) {
|
|
objects := append(calibrationObjects(), partObjects("part0001")...)
|
|
objects = append(objects, partObjects("part0002")...)
|
|
groups, e := discoverCaptureGroups(objects, normalizedCaptureAutomation(&domain.CaptureAutomationConfig{Prefix: "incoming", DeliveryPrefix: "deliveries"}))
|
|
if e != nil || len(groups) != 2 {
|
|
t.Fatal(groups, e)
|
|
}
|
|
for _, group := range groups {
|
|
if len(group.Missing) != 0 {
|
|
t.Fatal(group)
|
|
}
|
|
}
|
|
}
|