🐛 Clear stale Capture lifecycle metadata
This commit is contained in:
parent
213c4b555c
commit
fa283c96f6
@ -92,6 +92,11 @@ func objectType(key string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func sourceFixtureObjectAllowed(relative string) bool {
|
||||
relative = strings.Trim(strings.TrimSpace(relative), "/")
|
||||
return relative != "" && !strings.HasPrefix(relative, "_droboticflow/")
|
||||
}
|
||||
|
||||
func parseFixture(value string) (string, string, error) {
|
||||
parts := strings.SplitN(value, "=", 2)
|
||||
if len(parts) != 2 || strings.TrimSpace(parts[0]) == "" || strings.TrimSpace(parts[1]) == "" {
|
||||
@ -153,6 +158,10 @@ func main() {
|
||||
result := fixtureResult{Name: name, Kind: kind, Prefix: targetPrefix}
|
||||
relativeFiles := make([]string, 0, len(keys))
|
||||
for _, sourceKey := range keys {
|
||||
relative := strings.TrimPrefix(sourceKey, *sourcePrefix+"/")
|
||||
if !sourceFixtureObjectAllowed(relative) {
|
||||
continue
|
||||
}
|
||||
if objectType(sourceKey) == "manifest" {
|
||||
if kind == "manifest" {
|
||||
result.Skipped = append(result.Skipped, sourceKey)
|
||||
@ -163,7 +172,6 @@ func main() {
|
||||
result.Skipped = append(result.Skipped, sourceKey)
|
||||
continue
|
||||
}
|
||||
relative := strings.TrimPrefix(sourceKey, *sourcePrefix+"/")
|
||||
targetKey := targetPrefix + "/" + relative
|
||||
if _, err := client.CopyObjectWithContext(ctx, bucket, targetKey, bucket, sourceKey, nil); err != nil {
|
||||
panic(fmt.Errorf("copy %s to %s: %w", sourceKey, targetKey, err))
|
||||
|
||||
@ -32,3 +32,12 @@ func TestParseFixtureRejectsUnknownAndNestedNames(t *testing.T) {
|
||||
t.Fatalf("valid fixture parse failed: %q %q %v", name, kind, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInternalPlatformObjectsStayOutOfSourceManifest(t *testing.T) {
|
||||
if sourceFixtureObjectAllowed("_droboticflow/manifests/run-internal.json") {
|
||||
t.Fatal("internal platform objects must not be copied into a source fixture")
|
||||
}
|
||||
if !sourceFixtureObjectAllowed("camera_left_part0001.mp4") {
|
||||
t.Fatal("business Capture objects must remain copyable")
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,7 +106,9 @@ func (server *server) captureAutomationPayload(ctx context.Context, ctxWorkflow
|
||||
if record.Attempt <= 0 {
|
||||
record.Attempt = 1
|
||||
}
|
||||
record.NextRetryAt = run.AvailableAt
|
||||
if run.Trigger == domain.RunTriggerRetry && run.Status == domain.RunStatusQueued {
|
||||
record.NextRetryAt = run.AvailableAt
|
||||
}
|
||||
record.ParentRunID = run.ParentRunID
|
||||
}
|
||||
return captureAutomationResponse{Config: config, Counts: captureAutomationCounts(records), Records: records}
|
||||
|
||||
@ -176,6 +176,9 @@ func TestCaptureRecordCancelStopsRunCancelsHumanWorkAndKeepsRetryMetadata(t *tes
|
||||
if getRecorder.Code != http.StatusOK || !strings.Contains(getRecorder.Body.String(), `"attempt":2`) || !strings.Contains(getRecorder.Body.String(), `"maxAttempts":3`) || !strings.Contains(getRecorder.Body.String(), `"parentRunId":"run-parent"`) {
|
||||
t.Fatalf("capture retry metadata missing: %d %s", getRecorder.Code, getRecorder.Body.String())
|
||||
}
|
||||
if strings.Contains(getRecorder.Body.String(), `"nextRetryAt"`) {
|
||||
t.Fatalf("a running non-retry Run must not expose nextRetryAt: %s", getRecorder.Body.String())
|
||||
}
|
||||
|
||||
duplicate := httptest.NewRequest(http.MethodPost, "/api/workflows/"+workflow.ID+"/capture-automation/records/"+record.ID+"/cancel", bytes.NewBufferString(`{"reason":"重复取消","mode":"graceful"}`))
|
||||
duplicate.Header.Set("Content-Type", "application/json")
|
||||
|
||||
@ -155,10 +155,35 @@ func (store *MongoStore) GetCaptureRecordByWorkflowPrefix(ctx context.Context, w
|
||||
}
|
||||
|
||||
func (store *MongoStore) UpsertCaptureRecord(ctx context.Context, item domain.CaptureRecord) error {
|
||||
_, err := store.captureRecords.UpdateOne(ctx, bson.M{"id": item.ID}, bson.M{"$set": item}, options.Update().SetUpsert(true))
|
||||
update := bson.M{"$set": item}
|
||||
if unset := captureRecordUnsetFields(item); len(unset) > 0 {
|
||||
update["$unset"] = unset
|
||||
}
|
||||
_, err := store.captureRecords.UpdateOne(ctx, bson.M{"id": item.ID}, update, options.Update().SetUpsert(true))
|
||||
return err
|
||||
}
|
||||
|
||||
func captureRecordUnsetFields(item domain.CaptureRecord) bson.M {
|
||||
unset := bson.M{}
|
||||
for key, empty := range map[string]bool{
|
||||
"manifestKey": strings.TrimSpace(item.ManifestKey) == "",
|
||||
"fingerprint": strings.TrimSpace(item.Fingerprint) == "",
|
||||
"missingTypes": len(item.MissingTypes) == 0,
|
||||
"stabilityObservedAt": strings.TrimSpace(item.StabilityObservedAt) == "",
|
||||
"runId": strings.TrimSpace(item.RunID) == "",
|
||||
"error": strings.TrimSpace(item.Error) == "",
|
||||
"statusBeforeDiscard": strings.TrimSpace(string(item.StatusBeforeDiscard)) == "",
|
||||
"readyAt": strings.TrimSpace(item.ReadyAt) == "",
|
||||
"startedAt": strings.TrimSpace(item.StartedAt) == "",
|
||||
"completedAt": strings.TrimSpace(item.CompletedAt) == "",
|
||||
} {
|
||||
if empty {
|
||||
unset[key] = ""
|
||||
}
|
||||
}
|
||||
return unset
|
||||
}
|
||||
|
||||
func (store *MongoStore) ClaimCaptureRecordForLaunch(ctx context.Context, id, fingerprint string) (bool, error) {
|
||||
result, err := store.captureRecords.UpdateOne(ctx,
|
||||
bson.M{"id": id, "status": domain.CaptureRecordReady, "fingerprint": fingerprint},
|
||||
|
||||
26
internal/store/capture_automation_unset_test.go
Normal file
26
internal/store/capture_automation_unset_test.go
Normal file
@ -0,0 +1,26 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
func TestCaptureRecordUnsetFieldsClearStaleOptionalState(t *testing.T) {
|
||||
unset := captureRecordUnsetFields(domain.CaptureRecord{ID: "capture-1", Status: domain.CaptureRecordQueued})
|
||||
for _, field := range []string{"missingTypes", "error", "statusBeforeDiscard", "stabilityObservedAt", "completedAt"} {
|
||||
if _, exists := unset[field]; !exists {
|
||||
t.Fatalf("expected stale field %s to be cleared: %#v", field, unset)
|
||||
}
|
||||
}
|
||||
|
||||
kept := captureRecordUnsetFields(domain.CaptureRecord{
|
||||
ID: "capture-2", Status: domain.CaptureRecordIncomplete, MissingTypes: []string{"左目视频"},
|
||||
Error: "source invalid", CompletedAt: "2026-08-31T00:00:00Z",
|
||||
})
|
||||
for _, field := range []string{"missingTypes", "error", "completedAt"} {
|
||||
if _, exists := kept[field]; exists {
|
||||
t.Fatalf("non-empty field %s must not be cleared: %#v", field, kept)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -44,13 +44,14 @@ def item_list(payload: Any) -> list[dict[str, Any]]:
|
||||
|
||||
|
||||
def upsert_hyperparam(node: dict[str, Any], key: str, value: Any) -> None:
|
||||
normalized = str(value)
|
||||
data = node.setdefault("data", {})
|
||||
params = data.setdefault("hyperparams", [])
|
||||
for param in params:
|
||||
if str(param.get("key", "")).strip() == key:
|
||||
param["value"] = value
|
||||
param["value"] = normalized
|
||||
return
|
||||
params.append({"key": key, "value": value, "type": "number"})
|
||||
params.append({"key": key, "value": normalized, "type": "number"})
|
||||
|
||||
|
||||
class Harness:
|
||||
@ -276,6 +277,10 @@ class Harness:
|
||||
"/api/users",
|
||||
{"name": f"Fanyu acceptance probe {self.args.acceptance_id}", "email": probe_email, "role": "member", "password": self.probe_password},
|
||||
)
|
||||
else:
|
||||
probe = self.admin.request_json(
|
||||
"PUT", f"/api/users/{probe['id']}", {"role": "member", "status": "active", "password": self.probe_password}
|
||||
)
|
||||
manager = by_email.get(manager_email)
|
||||
if manager is None:
|
||||
manager = self.admin.request_json(
|
||||
@ -289,6 +294,12 @@ class Harness:
|
||||
"password": self.manager_password,
|
||||
},
|
||||
)
|
||||
else:
|
||||
manager = self.admin.request_json(
|
||||
"PUT",
|
||||
f"/api/users/{manager['id']}",
|
||||
{"role": "supplier_manager", "status": "active", "password": self.manager_password},
|
||||
)
|
||||
self.state.update(
|
||||
{
|
||||
"probeUserId": probe["id"],
|
||||
@ -639,12 +650,13 @@ class Harness:
|
||||
self.check(f"escalation_{action}", decided["status"] == expected, item=decided)
|
||||
|
||||
def finalize(self) -> None:
|
||||
for key in ("probeUserId", "managerUserId"):
|
||||
user_id = self.state.get(key)
|
||||
if user_id:
|
||||
self.admin.request_json("PUT", f"/api/users/{user_id}", {"status": "disabled"})
|
||||
self.state.pop("probePassword", None)
|
||||
self.state.pop("managerPassword", None)
|
||||
if self.args.finalize_users:
|
||||
for key in ("probeUserId", "managerUserId"):
|
||||
user_id = self.state.get(key)
|
||||
if user_id:
|
||||
self.admin.request_json("PUT", f"/api/users/{user_id}", {"status": "disabled"})
|
||||
self.state.pop("probePassword", None)
|
||||
self.state.pop("managerPassword", None)
|
||||
self.report["status"] = "passed"
|
||||
self.report["finishedAt"] = datetime.now(timezone.utc).isoformat()
|
||||
self.save_report()
|
||||
@ -676,6 +688,7 @@ def parse_args() -> argparse.Namespace:
|
||||
parser.add_argument("--phase", action="append", choices=["all", "setup", "capture", "human"])
|
||||
parser.add_argument("--capture-timeout", type=int, default=3600)
|
||||
parser.add_argument("--human-timeout", type=int, default=7200)
|
||||
parser.add_argument("--finalize-users", action="store_true")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
|
||||
@ -32,4 +32,4 @@ def test_workflow_rework_override_is_added_without_duplicates() -> None:
|
||||
node = {"data": {"hyperparams": [{"key": "MAX_REWORK_ROUNDS", "value": 5}]}}
|
||||
module.upsert_hyperparam(node, "MAX_REWORK_ROUNDS", 1)
|
||||
values = [item for item in node["data"]["hyperparams"] if item["key"] == "MAX_REWORK_ROUNDS"]
|
||||
assert values == [{"key": "MAX_REWORK_ROUNDS", "value": 1}]
|
||||
assert values == [{"key": "MAX_REWORK_ROUNDS", "value": "1"}]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user