🐛 Preserve annotation drafts and recover source video playback
This commit is contained in:
parent
2876a14d4a
commit
3221ac65e4
@ -30,6 +30,14 @@
|
||||
|
||||
新的 JSON-only 源索引交付是 **v2 协议**,含固定完整源的逻辑键、哈希、双目帧区间。它只能交给有权读取完整源、承诺按区间解析的下游。完整源含舍弃区间,因此不能把它视为“物理交付视频不含舍弃区间”的等价替代。该变化尚未得到交付协议批准,必须同时显式设置 `PART_INDEX_DELIVERY=true` 和 `SOURCE_INDEX_DELIVERY=true`;仅有旧开关时拒绝新源索引 JSON 交付。目录交付无需放宽旧契约。上线启用前必须确认实际工作流使用哪种交付方式。
|
||||
|
||||
## 2026-10-21:MP4 呈现终点量化兼容与旧任务恢复
|
||||
|
||||
逐帧时间戳和解码帧数检查保持原要求。总时长检查还需考虑 MP4 编辑列表使用的 movie timescale,而非只看视频 track time base:新的终点容差为原容差与 `min(movie tick + track tick + 浮点余量, 半个帧周期)` 的较大值。无法读取有效 movie clock 时维持原容差,不扩大放行范围。
|
||||
|
||||
B06/part0002、B14/part0001、B18/part0003 的本地样本均为连续 30fps,packet 时长全部是 512 track tick;编辑列表导致呈现总时长少 5 个 track tick,约 0.326ms。不得将此误认为丢帧,也不得直接删除时长检查或统一放宽一帧。兼容处理不改源文件、硬件 PTS、统一边界或已有证书,不以忽略编辑列表重新定义播放起点。整帧截短、帧数差异和逐帧断档仍拒绝。
|
||||
|
||||
没有 `sliceWorkflow` 的旧任务仍按已有正式生成证据识别。只有草稿而没有有效生成证据的任务不能凭前端推断进入标注;允许操作者显式按服务器保存的完整快照恢复生成,复用持久作业、租约和版本竞争机制,并保留动作、描述及分类。已确认工作区之外还存在较新的本人自动保存草稿时,恢复采用该草稿,与页面恢复内容一致;归属、版本、时间或数据格式无法核对时停止,不能猜选或清空。恢复模式需跨失败重试保留,避免再次退回旧工作区。恢复不是清空后重新切片。
|
||||
|
||||
## 成本、兼容性与回退
|
||||
|
||||
- 固定源每 Run/源版本复制一次,不是跨 Run 去重;首用仍消耗解码 CPU、读取带宽与一份源大小的存储,之后修订为 JSON。
|
||||
|
||||
@ -7,9 +7,9 @@ for this project's selection, so other projects sharing an entry are unaffected.
|
||||
|
||||
In the annotator's slice phase, **从切片字典选择** searches active names enabled
|
||||
for the current project and fills the selected slice's existing `name` field.
|
||||
The name remains editable. Selection does not seek video, change boundaries or
|
||||
The name is selected from the project dictionary. Selection does not seek video, change boundaries or
|
||||
submit work; **确认全部切片** retains the existing save/materialization flow.
|
||||
No dictionary means manual naming still works. Editing/removing dictionary
|
||||
An absent or unavailable dictionary blocks a new slice confirmation. Editing/removing dictionary
|
||||
entries never rewrites already saved slice names or historical delivery data.
|
||||
|
||||
## Compatibility and API
|
||||
@ -26,7 +26,22 @@ entries never rewrites already saved slice names or historical delivery data.
|
||||
- Project selections store `sliceLabelIds` independently from existing `labelIds`.
|
||||
Memory/Mongo updates change only the relevant dictionary selection.
|
||||
- Task/project switches abort stale reads; reopening the picker refreshes names.
|
||||
Load failures do not disable manual name entry.
|
||||
Load failures retain saved names and expose retry rather than manual name entry.
|
||||
|
||||
## Post-confirmation naming and submission
|
||||
|
||||
The annotation view has a visible **选择切片名称 / 修改切片名称** button. It opens
|
||||
the existing atomic slice-edit panel; choosing a name preserves action content,
|
||||
boundaries and history. E remains a keyboard entry. Renaming never requires
|
||||
the destructive initial **重新切片** operation.
|
||||
|
||||
Unnamed kept slices may be saved as drafts while editing. Formal submission
|
||||
requires a nonempty classification name, including after a split/merge was
|
||||
saved: an unchanged empty workspace name is not a historical-name exemption.
|
||||
Unchanged nonempty historical names retain their existing compatibility rule;
|
||||
new/changed names still require the enabled project dictionary. This rule does
|
||||
not prohibit unnamed or pending actions, which remain distinct from invalid or
|
||||
discarded data. Existing deliveries and customer records are not rewritten.
|
||||
|
||||
Tests cover legacy action compatibility, purpose and project isolation, permissions,
|
||||
independent updates, removal without history mutation, and the existing name callback.
|
||||
|
||||
112
docs/verification/annotation-failures-20261021.md
Normal file
112
docs/verification/annotation-failures-20261021.md
Normal file
@ -0,0 +1,112 @@
|
||||
# Annotation generation, naming and media recovery
|
||||
|
||||
Scope: October 21 platform-tuning reports B06, B14, B18, B11 and B20. Production
|
||||
inspection is read-only. Tests use local synthetic media and isolated stores.
|
||||
|
||||
## Evidence
|
||||
|
||||
- B06/B14/B18 downloaded left videos have 6343/7957/11239 continuous 30fps
|
||||
frames. Their stream duration is approximately 0.326ms short. All packet
|
||||
durations are 512 ticks; the difference comes from MP4 edit-list presentation
|
||||
duration. Unedited duration and decoded cadence agree. This does not establish
|
||||
the state of every right-camera source in production.
|
||||
- The user confirmed the 15:26 report is B11/part0001. Its task has no
|
||||
`sliceWorkflow` or completed materialization evidence, no annotation revision,
|
||||
and only an old slice revision 0. Its saved workspace contains seven slices
|
||||
and six actions; its draft contains seven slices and ten actions. Frontend
|
||||
draft inference can show annotation while the write gate rejects it. Merely
|
||||
seeing numbered slices does not prove successful generation.
|
||||
- B20/part0001 recording shows repeated HEAD 405 responses on the authenticated
|
||||
`subject-content` URL during recovery. Both referenced BOS camera objects
|
||||
exist; metadata and 1KiB range reads succeed (226335649/217067600 bytes).
|
||||
This verifies the recovery blocker, without claiming the recording proves
|
||||
what first interrupted native playback. Its later generation job completed.
|
||||
- A local HTTP flow reproduced named parent → two unnamed children → saved
|
||||
workspace → formal submission 201. Unchanged blank names bypassed the old
|
||||
historical-name exception.
|
||||
|
||||
Redacted source metadata and recording are under the main repository's
|
||||
untracked `local-data/diagnostics/annotation-failures-20261021/`.
|
||||
|
||||
## Behavior and compatibility
|
||||
|
||||
- Keep strict decoded frame/PTS checks; bound presentation endpoint rounding
|
||||
by the actual MP4 movie clock and preserve rejection of whole-frame loss.
|
||||
- Detail GET ships `editorState.phase`, `canConfirmDescriptions` and
|
||||
`canRecoverGeneration`. The existing description gate remains authoritative.
|
||||
Status-only polling does not perform the additional legacy evidence lookup.
|
||||
- Explicit `recoverExisting` on slice confirmation is restricted to legacy
|
||||
full-source tasks missing generation evidence. The server owns its retained
|
||||
snapshot; client-supplied replacement snapshots are ignored. If a newer,
|
||||
owned autosaved draft exists alongside the confirmed workspace, recovery uses
|
||||
that draft, matching the editor's restored view. Ambiguous ownership, version,
|
||||
timestamps or malformed content stop recovery without mutation. Queueing,
|
||||
interruption/reclaim, failure/retry and completion preserve the selected work.
|
||||
Ordinary failed-generation retries retain their existing confirmation policy.
|
||||
- A visible post-confirmation name button uses the atomic edit application.
|
||||
Blank kept names block formal submission; nonempty historical compatibility,
|
||||
pending actions and discard evidence remain intact.
|
||||
- Subject and scoped evidence media routes accept HEAD with the same access
|
||||
checks as GET. The existing storage handler returns metadata without reading
|
||||
the video body. Hidden cameras remain unloaded.
|
||||
- The movi wrapper clears its exposed error for each new load instead of
|
||||
retaining the vendor's previous failure. Transport sets the custom element's
|
||||
source once, avoiding a second concurrent decoder load. Vendor assets and
|
||||
media sources are unchanged.
|
||||
- The recovery mode remains marked in `sliceWorkflow` until completion, so a
|
||||
failure followed by another retry cannot silently select the older workspace.
|
||||
API and annotation processing components need compatible versions for this
|
||||
recovery path. Source-validation processes also need the clock fix before
|
||||
retrying the affected source checks. Do not roll active recovery jobs back to
|
||||
an API that lacks these retention rules.
|
||||
|
||||
## Verification
|
||||
|
||||
- Focused HTTP/API tests pass for server-owned editor readiness, blank-name
|
||||
submission rejection, name correction, authenticated HEAD and denied access.
|
||||
- Real MP4 regressions pass for 6343/7957/11239 frames with movie-clock endpoint
|
||||
rounding. Mismatched frame counts and a whole-frame endpoint truncation remain
|
||||
rejected. Invalid movie metadata retains strict tolerance.
|
||||
- `TestLegacyGenerationRecoveryPreservesAnnotationsAcrossRestart` passes:
|
||||
a newer autosaved draft survives queue interruption/reclaim, a real processor
|
||||
rejection, retry and successful generation. Duplicate recovery and replacement
|
||||
snapshot attempts cannot overwrite it. Ambiguous drafts reject without writes.
|
||||
- The full local page → HTTP handler → isolated store browser flow passes:
|
||||
the recovery button preserves the newer draft and waits for generation before
|
||||
entering annotation; post-confirmation naming, first-pass/rework drag edits,
|
||||
archived discard-side actions, failed saves, lost responses, reload and
|
||||
persisted undo/redo also pass.
|
||||
- Real `<movi-player>` software fallback passes injected media failure → reload
|
||||
for annotator, quality and acceptance views. HEAD succeeds, the hidden camera
|
||||
stays unloaded, editing position and unsaved description survive, and playback
|
||||
advances after recovery. Review views do not expose the new naming control.
|
||||
- The frontend and Go repository gates report no new failures against
|
||||
`tests/known-failures.json` (13 frontend failures in the 14-case baseline,
|
||||
70 Go failures in the 70-case baseline). The baseline is unchanged.
|
||||
- A subsequent Go run also exposed
|
||||
`TestDispatchTwoWorkersAndRestartDoNotDuplicateClaims`: it intermittently
|
||||
records six distinct claims where the test expects three. The exact failure
|
||||
reproduces 15 times in 3000 repetitions on pristine commit `2876a14d`, before
|
||||
this change. Worker, store and domain files are unchanged. This independent
|
||||
concurrency issue remains unresolved and is not added to the known-failure
|
||||
baseline; its failed run is retained alongside the successful gate evidence.
|
||||
- The pristine full gate also exposes the preceding commit's stale route
|
||||
snapshot (the admin-pool route was already present). This change regenerates
|
||||
the snapshot from the actual router, including that route and the new HEAD
|
||||
routes; it does not change admin-pool access behavior.
|
||||
- Type checking, formatting, Go build, web build and the production-dist browser
|
||||
boot check pass. The boot check uses loopback API stubs, with no page errors or
|
||||
unexpected writes.
|
||||
|
||||
Local browser regression commands:
|
||||
|
||||
```sh
|
||||
REWORK_BOUNDARY_BROWSER_TEST=1 go test ./internal/api -run '^TestReworkBoundaryBrowserReplica$' -count=1 -v
|
||||
REWORK_BOUNDARY_BROWSER_TEST=1 ANNOTATION_FEEDBACK_BROWSER_SCRIPT=tests/browser/annotation-media-recovery-replica.mjs go test ./internal/api -run '^TestReworkBoundaryBrowserReplica$' -count=1 -v
|
||||
```
|
||||
|
||||
The browser runs use local Edge/Chromium and synthetic media; they do not prove
|
||||
every customer's decoder or network. The original cause of B20's initial native
|
||||
playback interruption remains unverified. Production B11 generation recovery
|
||||
has not been executed. No rollout, customer-record repair, index migration or
|
||||
object-storage write is part of this change.
|
||||
@ -7,6 +7,57 @@ import (
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
type annotationEditorState struct {
|
||||
Phase string `json:"phase"`
|
||||
CanConfirmDescriptions bool `json:"canConfirmDescriptions"`
|
||||
CanRecoverGeneration bool `json:"canRecoverGeneration"`
|
||||
}
|
||||
|
||||
// Use the same persisted evidence as the write gate, including legacy tasks
|
||||
// without sliceWorkflow. Restored draft actions do not prove generation ready.
|
||||
func (server *server) annotationEditorStateForTask(ctx context.Context, task domain.AnnotationTaskRecord, item *domain.HumanItemRecord) (annotationEditorState, error) {
|
||||
ready, err := server.legacyAnnotationConfirmationReady(ctx, task, item)
|
||||
state := annotationEditorState{Phase: "slice", CanConfirmDescriptions: ready}
|
||||
if err != nil {
|
||||
return state, err
|
||||
}
|
||||
if ready {
|
||||
state.Phase = "annotate"
|
||||
return state, nil
|
||||
}
|
||||
if item != nil {
|
||||
state.CanRecoverGeneration = legacyGenerationRecoveryCandidate(task, item)
|
||||
workflow := mapValue(item.Subject.Payload["sliceWorkflow"])
|
||||
status := stringValue(workflow["status"])
|
||||
jobStatus := ""
|
||||
if item.ProcessingJob != nil {
|
||||
jobStatus = item.ProcessingJob.Status
|
||||
}
|
||||
if status == "failed" || jobStatus == "failed" {
|
||||
return state, nil
|
||||
}
|
||||
if status == "processing" || status == "queued" || status == "running" || status == "materializing" || jobStatus == "queued" || jobStatus == "running" || jobStatus == "processing" || item.PendingCombinedSubmissionID != "" {
|
||||
state.Phase = "materializing"
|
||||
}
|
||||
}
|
||||
return state, nil
|
||||
}
|
||||
|
||||
func legacyGenerationRecoveryCandidate(task domain.AnnotationTaskRecord, item *domain.HumanItemRecord) bool {
|
||||
if item == nil || !task.SourceIsFullVideo || item.PendingCombinedSubmissionID != "" || item.Subject.Payload["sliceWorkflow"] != nil {
|
||||
return false
|
||||
}
|
||||
if item.ProcessingJob != nil && item.ProcessingJob.Status != "completed" {
|
||||
return false
|
||||
}
|
||||
for _, workspace := range []map[string]any{annotationWorkspacePayload(item), mapValue(item.Subject.Payload["annotationDraft"])} {
|
||||
if len(decodeMaterializationValue[domain.SliceSegment](workspace["sliceSegments"])) > 0 && len(decodeMaterializationValue[domain.AnnotationSegment](workspace["segments"])) > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// legacyAnnotationConfirmationReady recognizes persisted pre-workflow evidence
|
||||
// for tasks whose old records do not have sliceWorkflow. It never mutates the
|
||||
// item; the caller remains responsible for checking the submitted version.
|
||||
|
||||
52
internal/api/annotation_editor_state_test.go
Normal file
52
internal/api/annotation_editor_state_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
func TestAnnotationDetailSharesDescriptionConfirmationReadiness(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, status, phase, expected string
|
||||
ready bool
|
||||
}{
|
||||
{"completed", "completed", "annotate", "annotate", true},
|
||||
{"failed-with-old-phase", "failed", "annotate", "slice", false},
|
||||
{"failed-with-draft", "failed", "", "slice", false},
|
||||
{"inconsistent-completed", "completed", "slice", "slice", false},
|
||||
{"processing", "processing", "slice", "materializing", false},
|
||||
{"legacy-confirmed", "", "", "annotate", true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
f := continuousFixture(t)
|
||||
item := f.item
|
||||
item.Subject.Payload["annotationWorkspace"] = map[string]any{"sliceSegments": []domain.SliceSegment{{ID: "s", Name: "测试切片", Start: 0, End: 10}}, "segments": []domain.AnnotationSegment{{ID: "a", Start: 0, End: 10, Status: "pending"}}}
|
||||
if tc.status != "" {
|
||||
item.Subject.Payload["sliceWorkflow"] = map[string]any{"status": tc.status, "phase": tc.phase, "leaseExpiresAt": time.Now().Add(time.Hour).UTC().Format(time.RFC3339Nano)}
|
||||
}
|
||||
if err := f.store.UpsertHumanItem(f.ctx, item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := f.request("GET", "/api/plugins/annotation-qa/tasks/"+f.task.ID, f.annotator, nil)
|
||||
if r.Code != 200 {
|
||||
t.Fatalf("detail: %d %s", r.Code, r.Body.String())
|
||||
}
|
||||
var body struct {
|
||||
EditorState annotationEditorState `json:"editorState"`
|
||||
}
|
||||
if err := json.Unmarshal(r.Body.Bytes(), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if body.EditorState.Phase != tc.expected || body.EditorState.CanConfirmDescriptions != tc.ready {
|
||||
t.Fatalf("state=%+v", body.EditorState)
|
||||
}
|
||||
ready, err := (&server{store: f.store}).legacyAnnotationConfirmationReady(f.ctx, f.task, &item)
|
||||
if err != nil || ready != body.EditorState.CanConfirmDescriptions {
|
||||
t.Fatalf("gate differs: %v %v", ready, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
55
internal/api/annotation_feedback_names_test.go
Normal file
55
internal/api/annotation_feedback_names_test.go
Normal file
@ -0,0 +1,55 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
func TestNewUnnamedSplitCannotBecomeHistoricalNameAtSubmission(t *testing.T) {
|
||||
f := continuousFixture(t)
|
||||
seedCompletedMaterialization(t, f, 1)
|
||||
item, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
||||
item.Subject.Payload["sliceWorkflow"] = map[string]any{"status": "completed", "phase": "annotate"}
|
||||
item.Subject.Payload["annotationWorkspace"] = map[string]any{
|
||||
"sliceSegments": []domain.SliceSegment{{ID: "parent", Name: "测试切片", Start: 0, End: 10}},
|
||||
"segments": []domain.AnnotationSegment{{ID: "a", Start: 0, End: 10, Status: "pending"}},
|
||||
}
|
||||
if err := f.store.UpsertHumanItem(f.ctx, *item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := "/api/plugins/annotation-qa/tasks/" + f.task.ID
|
||||
split := []domain.SliceSegment{{ID: "child-a", SourceIDs: []string{"parent"}, Start: 0, End: 5}, {ID: "child-b", SourceIDs: []string{"parent"}, Start: 5, End: 10}}
|
||||
actions := []domain.AnnotationSegment{{ID: "a1", Start: 0, End: 5, Status: "pending"}, {ID: "a2", Start: 5, End: 10, Status: "pending"}}
|
||||
r := f.request("POST", path+"/slice-edit-applications", f.annotator, sliceEditApplicationInput{ApplicationID: "unnamed-split", combinedAnnotationDraftInput: combinedAnnotationDraftInput{Version: item.Version, SliceSegments: split, Segments: actions}})
|
||||
if r.Code != 200 {
|
||||
t.Fatalf("save split: %d %s", r.Code, r.Body.String())
|
||||
}
|
||||
var got struct {
|
||||
Workspace combinedAnnotationDraftInput `json:"workspace"`
|
||||
}
|
||||
if err := json.Unmarshal(r.Body.Bytes(), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
item, _ = f.store.GetHumanItem(f.ctx, item.ID)
|
||||
got.Workspace.Version = item.Version
|
||||
r = f.request("POST", path+"/combined-submissions", f.annotator, got.Workspace)
|
||||
if r.Code != 400 || !strings.Contains(r.Body.String(), "slice_dictionary_name_required") {
|
||||
t.Fatalf("unnamed new slices submitted: %d %s", r.Code, r.Body.String())
|
||||
}
|
||||
unchanged, _ := f.store.GetHumanItem(f.ctx, item.ID)
|
||||
if unchanged.Version != item.Version || unchanged.CurrentStageID != item.CurrentStageID {
|
||||
t.Fatal("rejection changed the task")
|
||||
}
|
||||
// Naming the slices must preserve the anonymous pending actions, which are
|
||||
// valid classification results and must never be silently marked invalid.
|
||||
for i := range got.Workspace.SliceSegments {
|
||||
got.Workspace.SliceSegments[i].Name = "测试切片"
|
||||
}
|
||||
r = f.request("POST", path+"/combined-submissions", f.annotator, got.Workspace)
|
||||
if r.Code != 201 {
|
||||
t.Fatalf("named split: %d %s", r.Code, r.Body.String())
|
||||
}
|
||||
}
|
||||
@ -1090,7 +1090,12 @@ func (server *server) handleAnnotationTaskGet(writer http.ResponseWriter, reques
|
||||
}
|
||||
linkedHumanItem.CanClaim = &claimable
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"task": item, "sliceRevisions": sliceRevisions, "revisions": revisions, "reviews": reviews, "humanItem": linkedHumanItem})
|
||||
editorState, readinessErr := server.annotationEditorStateForTask(request.Context(), *item, linkedHumanItem)
|
||||
if readinessErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, readinessErr)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"task": item, "sliceRevisions": sliceRevisions, "revisions": revisions, "reviews": reviews, "humanItem": linkedHumanItem, "editorState": editorState})
|
||||
}
|
||||
|
||||
func annotationFrameTimelinePayload(camera string, rows []hardwarePTSRow) (map[string]any, error) {
|
||||
@ -1415,6 +1420,7 @@ type combinedAnnotationDraftInput struct {
|
||||
}
|
||||
|
||||
type sliceConfirmationInput struct {
|
||||
RecoverExisting bool `json:"recoverExisting,omitempty"`
|
||||
RetryFailed bool `json:"retryFailed,omitempty"`
|
||||
RetryWorkspace map[string]any `json:"retryWorkspace,omitempty"`
|
||||
Version int `json:"version"`
|
||||
@ -2135,7 +2141,25 @@ func (server *server) handleSliceConfirmationCreate(writer http.ResponseWriter,
|
||||
}
|
||||
payload.RetryWorkspace = nil // Private durable snapshot is always server-owned.
|
||||
var retained combinedAnnotationDraftInput
|
||||
if payload.RetryFailed {
|
||||
if payload.RecoverExisting {
|
||||
ready, err := server.legacyAnnotationConfirmationReady(request.Context(), *task, item)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if ready || !legacyGenerationRecoveryCandidate(*task, item) {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "当前任务不需要恢复历史切片生成,已有内容仍保留", "code": "slice_recovery_unavailable"})
|
||||
return
|
||||
}
|
||||
var recoveryErr error
|
||||
payload, retained, recoveryErr = retainedSliceRecoveryInput(item, payload.Version)
|
||||
if recoveryErr != nil {
|
||||
renderJSON(writer, http.StatusUnprocessableEntity, map[string]string{"error": recoveryErr.Error(), "code": "slice_retry_workspace_invalid"})
|
||||
return
|
||||
}
|
||||
payload.RecoverExisting = true
|
||||
payload.ChangeReason = "恢复历史切片生成并保留已有标注"
|
||||
} else if payload.RetryFailed {
|
||||
workflow := mapValue(item.Subject.Payload["sliceWorkflow"])
|
||||
job := item.ProcessingJob
|
||||
if stringValue(workflow["status"]) != "failed" || (job != nil && (job.Status == "queued" || job.Status == "running" || job.Kind != "slice")) {
|
||||
@ -2143,7 +2167,13 @@ func (server *server) handleSliceConfirmationCreate(writer http.ResponseWriter,
|
||||
return
|
||||
}
|
||||
var retryErr error
|
||||
payload, retained, retryErr = retainedSliceRetryInput(item, payload.Version)
|
||||
recoverExisting := boolValue(workflow["recoverExisting"])
|
||||
if recoverExisting {
|
||||
payload, retained, retryErr = retainedSliceRecoveryInput(item, payload.Version)
|
||||
payload.RecoverExisting = true
|
||||
} else {
|
||||
payload, retained, retryErr = retainedSliceRetryInput(item, payload.Version)
|
||||
}
|
||||
if retryErr != nil {
|
||||
renderJSON(writer, http.StatusUnprocessableEntity, map[string]string{"error": retryErr.Error(), "code": "slice_retry_workspace_invalid"})
|
||||
return
|
||||
@ -2232,6 +2262,9 @@ func (server *server) handleSliceConfirmationCreate(writer http.ResponseWriter,
|
||||
// mutations remain blocked by the existing processing guard.
|
||||
workflow := mapValue(item.Subject.Payload["sliceWorkflow"])
|
||||
workflow["retryOf"] = retryOf
|
||||
if payload.RecoverExisting {
|
||||
workflow["recoverExisting"] = true
|
||||
}
|
||||
item.Subject.Payload["sliceWorkflow"] = workflow
|
||||
} else {
|
||||
delete(item.Subject.Payload, "annotationDraft")
|
||||
|
||||
@ -242,9 +242,10 @@ func validateSourceMediaClock(ctx context.Context, path string, count int, durat
|
||||
period := 1 / rate
|
||||
// r_frame_rate is only a candidate cadence: verify every decoded frame
|
||||
// against it below, rather than trusting the metadata or deriving a cadence
|
||||
// from rounded total duration. The final frame timestamp and packet duration
|
||||
// can each round, so allow one time-base tick at the end of the stream.
|
||||
if math.IsInf(period, 0) || math.Abs(duration-float64(count)*period) > math.Max(0.0001, tick+1e-9) {
|
||||
// from rounded total duration. MP4 edit lists additionally round the
|
||||
// presentation endpoint in the movie clock (often 1ms, even for a video
|
||||
// track at 1/15360). This never relaxes the decoded frame checks below.
|
||||
if math.IsInf(period, 0) || math.Abs(duration-float64(count)*period) > sourceClockEndTolerance(path, tick, period) {
|
||||
return fmt.Errorf("source video duration does not match its fixed frame cadence")
|
||||
}
|
||||
// Integer timestamps preserve half-tick boundaries; ffprobe's *_time
|
||||
|
||||
85
internal/api/annotation_source_movie_clock.go
Normal file
85
internal/api/annotation_source_movie_clock.go
Normal file
@ -0,0 +1,85 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
)
|
||||
|
||||
// MP4 edit-list durations use the movie clock, not the video's track clock.
|
||||
// Read only atom headers and mvhd: a large mdat is skipped without loading it.
|
||||
func sourceMovieClockTick(path string) (float64, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer f.Close()
|
||||
info, err := f.Stat()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var scan func(int64, int64, bool) (float64, error)
|
||||
scan = func(start, end int64, inMovie bool) (float64, error) {
|
||||
for offset, boxes := start, 0; offset+8 <= end && boxes < 4096; boxes++ {
|
||||
var header [16]byte
|
||||
if _, err := f.ReadAt(header[:8], offset); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
size, headerSize := uint64(binary.BigEndian.Uint32(header[:4])), int64(8)
|
||||
if size == 1 {
|
||||
if _, err := f.ReadAt(header[8:], offset+8); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
size, headerSize = binary.BigEndian.Uint64(header[8:]), 16
|
||||
} else if size == 0 {
|
||||
size = uint64(end - offset)
|
||||
}
|
||||
if size < uint64(headerSize) || size > uint64(end-offset) {
|
||||
return 0, fmt.Errorf("invalid MP4 atom size")
|
||||
}
|
||||
kind := string(header[4:8])
|
||||
if kind == "moov" && !inMovie {
|
||||
return scan(offset+headerSize, offset+int64(size), true)
|
||||
}
|
||||
if kind == "mvhd" && inMovie {
|
||||
var version [1]byte
|
||||
if _, err := f.ReadAt(version[:], offset+headerSize); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
clockOffset := int64(12)
|
||||
if version[0] == 1 {
|
||||
clockOffset = 20
|
||||
} else if version[0] != 0 {
|
||||
return 0, fmt.Errorf("unsupported MP4 movie clock")
|
||||
}
|
||||
if headerSize+clockOffset+4 > int64(size) {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
var clock [4]byte
|
||||
if _, err := f.ReadAt(clock[:], offset+headerSize+clockOffset); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
timescale := binary.BigEndian.Uint32(clock[:])
|
||||
if timescale == 0 {
|
||||
return 0, fmt.Errorf("invalid MP4 movie timescale")
|
||||
}
|
||||
return 1 / float64(timescale), nil
|
||||
}
|
||||
offset += int64(size)
|
||||
}
|
||||
return 0, fmt.Errorf("MP4 movie clock unavailable")
|
||||
}
|
||||
return scan(0, info.Size(), false)
|
||||
}
|
||||
|
||||
func sourceClockEndTolerance(path string, trackTick, period float64) float64 {
|
||||
tolerance := math.Max(0.0001, trackTick+1e-9)
|
||||
if movieTick, err := sourceMovieClockTick(path); err == nil {
|
||||
// Both conversions can round. Never turn the container exception into
|
||||
// permission to lose a whole final frame; decoded cadence stays strict.
|
||||
tolerance = math.Max(tolerance, math.Min(movieTick+trackTick+1e-9, period/2))
|
||||
}
|
||||
return tolerance
|
||||
}
|
||||
78
internal/api/annotation_source_movie_clock_test.go
Normal file
78
internal/api/annotation_source_movie_clock_test.go
Normal file
@ -0,0 +1,78 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSourceClockAcceptsEditListTailRoundingWithoutRelaxingFrames(t *testing.T) {
|
||||
if _, err := exec.LookPath("ffmpeg"); err != nil {
|
||||
t.Skip("ffmpeg unavailable")
|
||||
}
|
||||
for _, count := range []int{6343, 7957, 11239} {
|
||||
t.Run(fmt.Sprint(count), func(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "edit-list.mp4")
|
||||
args := []string{"-v", "error", "-y", "-f", "lavfi", "-i", "color=c=navy:s=32x32:r=30", "-frames:v", fmt.Sprint(count), "-c:v", "libx264", "-preset", "ultrafast", "-bf", "3", "-video_track_timescale", "15360", "-movie_timescale", "1000", "-use_editlist", "1", path}
|
||||
if out, err := exec.CommandContext(t.Context(), "ffmpeg", args...).CombinedOutput(); err != nil {
|
||||
t.Fatalf("encode: %v %s", err, out)
|
||||
}
|
||||
body, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
at := bytes.Index(body, []byte("elst"))
|
||||
if at < 4 || at+24 > len(body) || body[at+4] != 0 || binary.BigEndian.Uint32(body[at+8:]) != 1 {
|
||||
t.Fatal("fixture needs one version-0 edit")
|
||||
}
|
||||
writeEndpoint := func(milliseconds uint32) {
|
||||
binary.BigEndian.PutUint32(body[at+12:], milliseconds)
|
||||
if err := os.WriteFile(path, body, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
writeEndpoint(uint32(count * 1000 / 30))
|
||||
duration, err := ffprobeDurationSeconds(t.Context(), path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if delta := float64(count)/30 - duration; delta < .0003 || delta > .0004 {
|
||||
t.Fatalf("fixture does not reproduce endpoint rounding: %.9f", delta)
|
||||
}
|
||||
if err := validateSourceMediaClock(t.Context(), path, count, duration); err != nil {
|
||||
t.Fatalf("complete CFR source rejected: %v", err)
|
||||
}
|
||||
if err := validateSourceMediaClock(t.Context(), path, count-1, duration); err == nil {
|
||||
t.Fatal("frame/PTS mismatch admitted")
|
||||
}
|
||||
writeEndpoint(uint32((count - 1) * 1000 / 30))
|
||||
duration, err = ffprobeDurationSeconds(t.Context(), path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := validateSourceMediaClock(t.Context(), path, count, duration); err == nil {
|
||||
t.Fatal("whole-frame endpoint truncation admitted")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceMovieClockMalformedInputKeepsStrictTolerance(t *testing.T) {
|
||||
for _, data := range [][]byte{nil, []byte("not MP4"), {0xff, 0xff, 0xff, 0xff, 'm', 'o', 'o', 'v'}, {0, 0, 0, 1, 'm', 'o', 'o', 'v'}} {
|
||||
path := filepath.Join(t.TempDir(), "bad.mp4")
|
||||
if err := os.WriteFile(path, data, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := sourceMovieClockTick(path); err == nil {
|
||||
t.Fatal("malformed movie clock accepted")
|
||||
}
|
||||
if got := sourceClockEndTolerance(path, 1.0/15360, 1.0/30); math.Abs(got-.0001) > 1e-12 {
|
||||
t.Fatal(got)
|
||||
}
|
||||
}
|
||||
}
|
||||
48
internal/api/human_media_head_test.go
Normal file
48
internal/api/human_media_head_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
func TestHumanSubjectMediaHeadSupportsBothCamerasAndRetry(t *testing.T) {
|
||||
f := continuousFixture(t)
|
||||
root := t.TempDir()
|
||||
artifacts := []domain.ExecutionArtifact{}
|
||||
for _, side := range []string{"left", "right"} {
|
||||
path := filepath.Join(root, side+".mp4")
|
||||
if err := os.WriteFile(path, []byte("synthetic-media"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
artifacts = append(artifacts, domain.ExecutionArtifact{ID: side, Name: side + ".mp4", Path: path, Type: domain.PortTypeVideo})
|
||||
}
|
||||
if err := f.store.UpsertRun(f.ctx, domain.RunRecord{ID: f.task.RunID, OrganizationID: f.task.OrganizationID, ProjectID: f.task.ProjectID, Artifacts: artifacts}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
item := f.item
|
||||
item.Subject.ArtifactID = "left"
|
||||
item.Subject.Payload["rightArtifactId"] = "right"
|
||||
if err := f.store.UpsertHumanItem(f.ctx, item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, side := range []string{"left", "right"} {
|
||||
url := "/api/human-items/" + item.ID + "/subject-content?side=" + side + "&_mediaRetry=synthetic"
|
||||
get := f.request(http.MethodGet, url, f.annotator, nil)
|
||||
if get.Code != 200 {
|
||||
t.Fatalf("GET %s: %d %s", side, get.Code, get.Body.String())
|
||||
}
|
||||
head := f.request(http.MethodHead, url, f.annotator, nil)
|
||||
if head.Code != 200 || head.Body.Len() != 0 || head.Header().Get("Content-Length") != get.Header().Get("Content-Length") {
|
||||
t.Fatalf("HEAD %s: status=%d body=%q headers=%v", side, head.Code, head.Body.String(), head.Header())
|
||||
}
|
||||
foreign := f.annotator
|
||||
foreign.ID = "unassigned-media-reader"
|
||||
if r := f.request(http.MethodHead, url, foreign, nil); r.Code == 200 {
|
||||
t.Fatal("HEAD bypassed subject access control")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -24,6 +24,18 @@ func TestReworkBoundaryBrowserReplica(t *testing.T) {
|
||||
}
|
||||
f := continuousFixture(t)
|
||||
reason := dispositionFixturePayload(t, f)
|
||||
selection, err := f.store.GetProjectAnnotationLabels(f.ctx, f.task.ProjectID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
label := domain.AnnotationLabelRecord{ID: "browser-extra-slice-name", OrganizationID: f.task.OrganizationID, Kind: "slice", Code: "browser-extra", Name: "补充切片名称", Status: domain.AnnotationLabelActive}
|
||||
if err := f.store.UpsertAnnotationLabel(f.ctx, label); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
selection.SliceLabelIDs = append(selection.SliceLabelIDs, label.ID)
|
||||
if err := f.store.UpsertProjectSliceLabels(f.ctx, *selection); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := f.store.UpsertOrganizationPlugin(f.ctx, domain.OrganizationPluginRecord{OrganizationID: domain.DefaultOrganizationID, PluginID: "annotation-qa", Enabled: true, Config: defaultAnnotationPluginConfig()}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -31,6 +43,9 @@ func TestReworkBoundaryBrowserReplica(t *testing.T) {
|
||||
var before []domain.SliceSegment
|
||||
d := domain.SliceSegment{ID: "d", Start: 0, End: 5, DeliveryDisposition: "discard", DiscardReason: "相机被遮挡", DiscardReasonLabelID: reason.ReasonLabelID, DiscardReasonVersion: reason.ReasonVersion}
|
||||
k := domain.SliceSegment{ID: "k", Name: "测试切片", Start: 5, End: 10}
|
||||
if side == "unnamed" {
|
||||
k.Name = ""
|
||||
}
|
||||
if side == "right" {
|
||||
k.Start, k.End = 0, 5
|
||||
d.Start, d.End = 5, 10
|
||||
@ -47,9 +62,19 @@ func TestReworkBoundaryBrowserReplica(t *testing.T) {
|
||||
a.Description = "合成有效动作"
|
||||
}
|
||||
item := f.item
|
||||
item.Subject.ArtifactID = "left-video"
|
||||
item.ReviewRound = round
|
||||
actions := []domain.AnnotationSegment{a}
|
||||
item.Subject.Payload = map[string]any{"sliceWorkflow": map[string]any{"status": "completed", "phase": "annotate"}, "annotationWorkspace": map[string]any{"userId": f.annotator.ID, "savedAt": nowISO(), "sliceSegments": before, "segments": actions, "statuses": map[string]string{"k": "pending", "d": "discarded"}}}
|
||||
item.Subject.Payload = map[string]any{"rightArtifactId": "right-video", "sliceWorkflow": map[string]any{"status": "completed", "phase": "annotate"}, "annotationWorkspace": map[string]any{"userId": f.annotator.ID, "savedAt": nowISO(), "sliceSegments": before, "segments": actions, "statuses": map[string]string{"k": "pending", "d": "discarded"}}}
|
||||
if side == "legacy" {
|
||||
delete(item.Subject.Payload, "sliceWorkflow")
|
||||
draft := mapValue(item.Subject.Payload["annotationWorkspace"])
|
||||
draft["segments"] = []domain.AnnotationSegment{{ID: "newer-described", Start: 5, End: 7, Status: "described", Description: "最新草稿描述"}, {ID: "newer-pending", Start: 7, End: 10, Status: "pending"}}
|
||||
draft["statuses"] = map[string]string{"k": "pending", "d": "pending"}
|
||||
draft["savedAt"] = nowISO()
|
||||
draft["savedVersion"] = item.Version
|
||||
item.Subject.Payload["annotationDraft"] = draft
|
||||
}
|
||||
return f.store.UpsertHumanItem(f.ctx, item)
|
||||
}
|
||||
root := t.TempDir()
|
||||
@ -66,12 +91,14 @@ func TestReworkBoundaryBrowserReplica(t *testing.T) {
|
||||
pts += fmt.Sprintf("%d\n", 1000000+i*100000)
|
||||
}
|
||||
bindings := []domain.NodeInputBinding{}
|
||||
mediaArtifacts := []domain.ExecutionArtifact{}
|
||||
for _, side := range []string{"left", "right"} {
|
||||
video := filepath.Join(root, side+".mp4")
|
||||
if out, err := exec.Command("ffmpeg", "-v", "error", "-y", "-f", "lavfi", "-i", "color=c=navy:s=160x90:r=10:d=10", "-c:v", "libx264", "-pix_fmt", "yuv420p", video).CombinedOutput(); err != nil {
|
||||
t.Fatalf("video: %v: %s", err, out)
|
||||
}
|
||||
timestamps := filepath.Join(root, side+"_pts.csv")
|
||||
mediaArtifacts = append(mediaArtifacts, domain.ExecutionArtifact{ID: side + "-video", Name: side + ".mp4", Path: video, Type: domain.PortTypeVideo})
|
||||
if err := os.WriteFile(timestamps, []byte(pts), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -91,7 +118,7 @@ func TestReworkBoundaryBrowserReplica(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bindings = append(bindings, domain.NodeInputBinding{TargetPortID: "imu", Artifacts: []domain.ExecutionArtifact{{ID: "imu", Name: "imu.csv", Path: imuPath, Data: map[string]any{"collectionId": "capture"}}}})
|
||||
if err := f.store.UpsertRun(f.ctx, domain.RunRecord{ID: f.task.RunID, OrganizationID: f.task.OrganizationID, ProjectID: f.task.ProjectID, WorkflowID: f.task.WorkflowID, NodeExecutions: []domain.NodeExecutionRecord{{NodeID: f.task.NodeID, InputBindings: bindings}}}); err != nil {
|
||||
if err := f.store.UpsertRun(f.ctx, domain.RunRecord{ID: f.task.RunID, OrganizationID: f.task.OrganizationID, ProjectID: f.task.ProjectID, WorkflowID: f.task.WorkflowID, Artifacts: mediaArtifacts, NodeExecutions: []domain.NodeExecutionRecord{{NodeID: f.task.NodeID, InputBindings: bindings}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := f.store.UpsertAnnotationTask(f.ctx, f.task); err != nil {
|
||||
@ -123,7 +150,7 @@ func TestReworkBoundaryBrowserReplica(t *testing.T) {
|
||||
renderJSON(w, 200, item)
|
||||
return
|
||||
}
|
||||
if r.Method != "GET" && r.Method != "HEAD" && !strings.HasSuffix(r.URL.Path, "/slice-edit-applications") && !strings.HasSuffix(r.URL.Path, "/slice-edit-restorations") && !strings.HasSuffix(r.URL.Path, "/drafts") {
|
||||
if r.Method != "GET" && r.Method != "HEAD" && !strings.HasSuffix(r.URL.Path, "/slice-edit-applications") && !strings.HasSuffix(r.URL.Path, "/slice-edit-restorations") && !strings.HasSuffix(r.URL.Path, "/slice-confirmations") && !strings.HasSuffix(r.URL.Path, "/drafts") {
|
||||
renderJSON(w, 403, map[string]string{"error": "fixture write not permitted"})
|
||||
return
|
||||
}
|
||||
@ -135,7 +162,11 @@ func TestReworkBoundaryBrowserReplica(t *testing.T) {
|
||||
defer server.Close()
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 4*time.Minute)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, "node", "tests/browser/rework-boundary-replica.mjs")
|
||||
script := os.Getenv("ANNOTATION_FEEDBACK_BROWSER_SCRIPT")
|
||||
if script == "" {
|
||||
script = "tests/browser/rework-boundary-replica.mjs"
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "node", script)
|
||||
cmd.Dir = "../.."
|
||||
cmd.Env = append(os.Environ(), "REWORK_BOUNDARY_API="+server.URL)
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
||||
@ -15,9 +15,12 @@ func (server *server) mountHumanLoopRoutes(router chi.Router) {
|
||||
router.Get("/api/human-items/{id}/review-draft", server.handleReviewDraft)
|
||||
router.Get("/api/human-items/{id}/review-operations/{operationId}", server.handleReviewOperation)
|
||||
router.Get("/api/human-items/{id}/subject-content", server.handleHumanItemSubjectContent)
|
||||
router.Head("/api/human-items/{id}/subject-content", server.handleHumanItemSubjectContent)
|
||||
router.Get("/api/human-items/{id}/evidence/{artifactId}/content", server.handleHumanItemEvidenceContent)
|
||||
router.Head("/api/human-items/{id}/evidence/{artifactId}/content", server.handleHumanItemEvidenceContent)
|
||||
router.Get("/api/human-items/{id}/evidence/{artifactId}/members", server.handleHumanItemEvidenceMembers)
|
||||
router.Get("/api/human-items/{id}/evidence/{artifactId}/members/{memberId}/content", server.handleHumanItemEvidenceMemberContent)
|
||||
router.Head("/api/human-items/{id}/evidence/{artifactId}/members/{memberId}/content", server.handleHumanItemEvidenceMemberContent)
|
||||
router.Get("/api/human-items/{id}/events", server.handleHumanItemEvents)
|
||||
router.Get("/api/human-rejects", server.handleHumanRejectsList)
|
||||
router.Get("/api/human-rejects/{id}", server.handleHumanRejectGet)
|
||||
|
||||
@ -39,7 +39,7 @@ func (s *server) validateProjectSliceNames(ctx context.Context, item *domain.Hum
|
||||
if c.IsDiscarded() {
|
||||
continue
|
||||
}
|
||||
if mode != "confirm" {
|
||||
if mode != "confirm" && strings.TrimSpace(c.Name) != "" {
|
||||
if name, ok := old[c.ID]; ok && name == c.Name {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
@ -10,7 +11,36 @@ import (
|
||||
// A retry reads the retained server workspace. Client-supplied slices must never
|
||||
// replace it, and malformed historic containers must not become empty content.
|
||||
func retainedSliceRetryInput(item *domain.HumanItemRecord, version int) (sliceConfirmationInput, combinedAnnotationDraftInput, error) {
|
||||
return retainedSliceInput(annotationWorkspacePayload(item), version)
|
||||
}
|
||||
|
||||
// Legacy recovery must retain the same newer, owned autosave restored by the
|
||||
// editor. Failed-job retries keep their separately frozen confirmation snapshot.
|
||||
func retainedSliceRecoveryInput(item *domain.HumanItemRecord, version int) (sliceConfirmationInput, combinedAnnotationDraftInput, error) {
|
||||
workspace := annotationWorkspacePayload(item)
|
||||
baseline := mapValue(item.Subject.Payload["annotationWorkspace"])
|
||||
if raw := item.Subject.Payload["annotationDraft"]; raw != nil && len(baseline) > 0 {
|
||||
draft := mapValue(raw)
|
||||
if len(draft) == 0 || item.AssignedUserID == "" || stringValue(draft["userId"]) != item.AssignedUserID || intValue(draft["savedVersion"]) > item.Version {
|
||||
return sliceConfirmationInput{}, combinedAnnotationDraftInput{}, fmt.Errorf("自动保存草稿的归属或版本无法核对,请先保存当前进度;原内容仍保留")
|
||||
}
|
||||
baselineTime := stringValue(baseline["confirmedAt"])
|
||||
if baselineTime == "" {
|
||||
baselineTime = stringValue(baseline["savedAt"])
|
||||
}
|
||||
confirmedAt, confirmedErr := time.Parse(time.RFC3339Nano, baselineTime)
|
||||
savedAt, savedErr := time.Parse(time.RFC3339Nano, stringValue(draft["savedAt"]))
|
||||
if confirmedErr != nil || savedErr != nil {
|
||||
return sliceConfirmationInput{}, combinedAnnotationDraftInput{}, fmt.Errorf("无法核对自动保存草稿与已确认内容的先后,请先核对保存记录;原内容仍保留")
|
||||
}
|
||||
if !savedAt.Before(confirmedAt) {
|
||||
workspace = draft
|
||||
}
|
||||
}
|
||||
return retainedSliceInput(workspace, version)
|
||||
}
|
||||
|
||||
func retainedSliceInput(workspace map[string]any, version int) (sliceConfirmationInput, combinedAnnotationDraftInput, error) {
|
||||
var saved combinedAnnotationDraftInput
|
||||
encoded, err := json.Marshal(workspace)
|
||||
if err == nil {
|
||||
|
||||
@ -83,6 +83,154 @@ func TestFailedSliceRetryUsesRetainedWorkspaceAndDurableRecovery(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegacyGenerationRecoveryPreservesAnnotationsAcrossRestart(t *testing.T) {
|
||||
t.Setenv("ANNOTATION_PROCESSOR_MODE", "external")
|
||||
f, root := annotationProcessorFixture(t)
|
||||
h := seedFailedSliceRetry(t, f)
|
||||
delete(h.Subject.Payload, "sliceWorkflow")
|
||||
delete(h.Subject.Payload, "materialization")
|
||||
workspace := annotationWorkspacePayload(&h)
|
||||
h.Subject.Payload["annotationWorkspace"] = workspace
|
||||
draft := map[string]any{}
|
||||
for key, value := range workspace {
|
||||
draft[key] = value
|
||||
}
|
||||
draft["segments"] = []domain.AnnotationSegment{{ID: "retained-action", Start: 0, End: 2, Status: "pending"}, {ID: "human-description", Start: 2, End: 4, Status: "described", Description: "人工确认的分类内容"}}
|
||||
draft["savedAt"] = nowISO()
|
||||
draft["savedVersion"] = h.Version
|
||||
h.Subject.Payload["annotationDraft"] = draft
|
||||
if err := f.store.UpsertHumanItem(f.ctx, h); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
saved, err := f.store.GetHumanItem(f.ctx, h.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h = *saved
|
||||
workspace = annotationWorkspacePayload(&h)
|
||||
draft = mapValue(h.Subject.Payload["annotationDraft"])
|
||||
s := &server{store: f.store, workspaceMountPath: root, externalAnnotationProcessor: true}
|
||||
state, err := s.annotationEditorStateForTask(f.ctx, f.task, &h)
|
||||
if err != nil || state.Phase != "slice" || !state.CanRecoverGeneration || state.CanConfirmDescriptions {
|
||||
t.Fatalf("state=%+v err=%v", state, err)
|
||||
}
|
||||
r := f.request("POST", "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/slice-confirmations", f.annotator, map[string]any{"version": h.Version, "recoverExisting": true, "retryWorkspace": map[string]any{"segments": []any{}}})
|
||||
if r.Code != http.StatusAccepted {
|
||||
t.Fatalf("recover: %d %s", r.Code, r.Body.String())
|
||||
}
|
||||
queued, _ := f.store.GetHumanItem(f.ctx, h.ID)
|
||||
if !reflect.DeepEqual(annotationWorkspacePayload(queued), workspace) {
|
||||
t.Fatal("queueing recovery erased annotations")
|
||||
}
|
||||
if !reflect.DeepEqual(mapValue(queued.Subject.Payload["annotationDraft"]), draft) {
|
||||
t.Fatal("queueing recovery erased the newer autosaved draft")
|
||||
}
|
||||
if duplicate := f.request("POST", "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/slice-confirmations", f.annotator, map[string]any{"version": queued.Version, "recoverExisting": true}); duplicate.Code != 409 {
|
||||
t.Fatal("duplicate recovery accepted")
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
old, _ := f.store.ClaimAnnotationProcessing(f.ctx, "recovery-old", now.Format(time.RFC3339Nano), now.Add(-time.Second).Format(time.RFC3339Nano))
|
||||
claimed, _ := f.store.ClaimAnnotationProcessing(f.ctx, "recovery-new", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
if old == nil || claimed == nil || claimed.ProcessingJob.Attempt != 2 {
|
||||
t.Fatal("recovery did not survive worker restart")
|
||||
}
|
||||
// Exercise a real processor rejection before retrying: both snapshots must
|
||||
// survive failure, and retry must not switch back to the older baseline.
|
||||
claimed.ProcessingJob.SourceFingerprint = "synthetic-source-changed"
|
||||
s.executeAnnotationJob(context.Background(), *claimed)
|
||||
failed, _ := f.store.GetHumanItem(f.ctx, h.ID)
|
||||
if failed.ProcessingJob.Status != "failed" || !reflect.DeepEqual(annotationWorkspacePayload(failed), workspace) || !reflect.DeepEqual(mapValue(failed.Subject.Payload["annotationDraft"]), draft) {
|
||||
t.Fatal("failed recovery changed retained snapshots")
|
||||
}
|
||||
r = f.request("POST", "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/slice-confirmations", f.annotator, map[string]any{"version": failed.Version, "retryFailed": true})
|
||||
if r.Code != http.StatusAccepted {
|
||||
t.Fatalf("retry recovery: %d %s", r.Code, r.Body.String())
|
||||
}
|
||||
claimed, _ = f.store.ClaimAnnotationProcessing(f.ctx, "recovery-retry", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
if claimed == nil {
|
||||
t.Fatal("recovery retry was not queued")
|
||||
}
|
||||
s.executeAnnotationJob(context.Background(), *claimed)
|
||||
completed, _ := f.store.GetHumanItem(f.ctx, h.ID)
|
||||
if completed.ProcessingJob.Status != "completed" {
|
||||
t.Fatalf("recovery failed: %+v", completed.ProcessingJob)
|
||||
}
|
||||
if !reflect.DeepEqual(decodeMaterializationValue[domain.AnnotationSegment](annotationWorkspacePayload(completed)["segments"]), decodeMaterializationValue[domain.AnnotationSegment](draft["segments"])) {
|
||||
t.Fatal("generation lost human descriptions or pending actions")
|
||||
}
|
||||
state, err = s.annotationEditorStateForTask(f.ctx, f.task, completed)
|
||||
if err != nil || state.Phase != "annotate" || !state.CanConfirmDescriptions || state.CanRecoverGeneration {
|
||||
t.Fatalf("completed state=%+v err=%v", state, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegacyGenerationRecoveryRecognizesDraftBeyondEmptyBaseline(t *testing.T) {
|
||||
t.Setenv("ANNOTATION_PROCESSOR_MODE", "external")
|
||||
f, _ := annotationProcessorFixture(t)
|
||||
h := seedFailedSliceRetry(t, f)
|
||||
delete(h.Subject.Payload, "sliceWorkflow")
|
||||
workspace := annotationWorkspacePayload(&h)
|
||||
draft := mapValue(workspace)
|
||||
draft["savedAt"] = nowISO()
|
||||
workspace["segments"] = []domain.AnnotationSegment{}
|
||||
h.Subject.Payload["annotationWorkspace"] = workspace
|
||||
h.Subject.Payload["annotationDraft"] = draft
|
||||
if err := f.store.UpsertHumanItem(f.ctx, h); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state, err := (&server{store: f.store}).annotationEditorStateForTask(f.ctx, f.task, &h)
|
||||
if err != nil || !state.CanRecoverGeneration || state.CanConfirmDescriptions {
|
||||
t.Fatalf("draft-only work was not recoverable: %+v %v", state, err)
|
||||
}
|
||||
r := f.request("POST", "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/slice-confirmations", f.annotator, map[string]any{"version": h.Version, "recoverExisting": true})
|
||||
if r.Code != http.StatusAccepted {
|
||||
t.Fatalf("recover draft-only work: %d %s", r.Code, r.Body.String())
|
||||
}
|
||||
queued, _ := f.store.GetHumanItem(f.ctx, h.ID)
|
||||
if len(decodeMaterializationValue[domain.AnnotationSegment](mapValue(queued.ProcessingJob.Input["retryWorkspace"])["segments"])) != 1 {
|
||||
t.Fatal("empty baseline replaced the newer draft in the durable job")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegacyGenerationRecoveryRejectsAmbiguousDraftWithoutMutation(t *testing.T) {
|
||||
t.Setenv("ANNOTATION_PROCESSOR_MODE", "external")
|
||||
for _, name := range []string{"wrong-owner", "future-version", "missing-time", "malformed-actions"} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
f, _ := annotationProcessorFixture(t)
|
||||
h := seedFailedSliceRetry(t, f)
|
||||
delete(h.Subject.Payload, "sliceWorkflow")
|
||||
draft := map[string]any{}
|
||||
for key, value := range annotationWorkspacePayload(&h) {
|
||||
draft[key] = value
|
||||
}
|
||||
draft["savedAt"] = nowISO()
|
||||
switch name {
|
||||
case "wrong-owner":
|
||||
draft["userId"] = f.reviewer.ID
|
||||
case "future-version":
|
||||
draft["savedVersion"] = h.Version + 1
|
||||
case "missing-time":
|
||||
delete(draft, "savedAt")
|
||||
case "malformed-actions":
|
||||
draft["segments"] = "not-a-list"
|
||||
}
|
||||
h.Subject.Payload["annotationDraft"] = draft
|
||||
if err := f.store.UpsertHumanItem(f.ctx, h); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, _ := f.store.GetHumanItem(f.ctx, h.ID)
|
||||
r := f.request("POST", "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/slice-confirmations", f.annotator, map[string]any{"version": h.Version, "recoverExisting": true})
|
||||
if r.Code != http.StatusUnprocessableEntity {
|
||||
t.Fatalf("ambiguous draft accepted: %d %s", r.Code, r.Body.String())
|
||||
}
|
||||
after, _ := f.store.GetHumanItem(f.ctx, h.ID)
|
||||
if !reflect.DeepEqual(before, after) {
|
||||
t.Fatal("rejected recovery changed saved snapshots")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailedSliceRetryRejectsUnsafeSnapshotsWithoutMutation(t *testing.T) {
|
||||
t.Setenv("ANNOTATION_PROCESSOR_MODE", "external")
|
||||
f, _ := annotationProcessorFixture(t)
|
||||
|
||||
6
internal/api/testdata/routes.golden
vendored
6
internal/api/testdata/routes.golden
vendored
@ -1,7 +1,7 @@
|
||||
# Generated by TestRouteSnapshot; see routes_snapshot_test.go.
|
||||
# access: reach = endpoint reached; otherwise the status the middleware chain returned.
|
||||
global=[diagnosticTrace,middleware.(*Compressor).Handler-fm,(*server).invalidateDashboardCachesOnWrite-fm,(*server).apiTokenAuth-fm,(*server).sessionAuth-fm,(*server).csrfProtection-fm,(*server).projectDeletionWriteGuard-fm,(*server).supplierDeletionWriteGuard-fm,(*server).acceptanceAccessCache-fm,annotationReadCache]
|
||||
routes=369
|
||||
routes=373
|
||||
DELETE /api/admin/organizations/{id} | mw=[(*server).requireSuperAdmin-fm] | (*server).handleAdminOrganizationsDelete-fm | anon=401 token=401 super=reach admin=403 supplier=403 annotator=403 quality=403 acceptance=403
|
||||
DELETE /api/admin/users/{id} | mw=[(*server).requireSuperAdmin-fm] | (*server).handleAdminUserDelete-fm | anon=401 token=401 super=reach admin=403 supplier=403 annotator=403 quality=403 acceptance=403
|
||||
DELETE /api/database/collections/{name} | mw=[(*server).requireBusinessRole.1] | (*server).handleDatabaseCollectionDelete-fm | anon=401 token=401 super=403 admin=reach supplier=403 annotator=403 quality=403 acceptance=403
|
||||
@ -111,6 +111,7 @@ GET /api/packages | mw=[] | (*server).handlePackagesList-fm | anon=401 token=401
|
||||
GET /api/packages/{runId}/{packageName} | mw=[] | (*server).handlePackageDetail-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
GET /api/packages/{runId}/{packageName}/content | mw=[] | (*server).handlePackageContent-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
GET /api/plugins | mw=[] | (*server).handlePluginsList-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
GET /api/plugins/annotation-qa/admin-pool | mw=[] | (*server).handleAdminAnnotationPool-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
GET /api/plugins/annotation-qa/claim-count | mw=[] | (*server).handleAnnotationClaimCount-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
GET /api/plugins/annotation-qa/claim-projects | mw=[] | (*server).handleAnnotationClaimProjects-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
GET /api/plugins/annotation-qa/sidebar | mw=[] | (*server).handleAnnotationSidebar-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
@ -186,6 +187,9 @@ GET /worker-api/metrics | mw=[(*server).requireWorkerAPIRole.1] | (*server).hand
|
||||
GET /worker-api/ready | mw=[] | (*server).handleWorkerAPIReady-fm | anon=reach token=reach super=reach admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
GET /worker-api/stats | mw=[(*server).requireWorkerAPIRole.1] | (*server).handleWorkerAPIStats-fm | anon=401 token=401 super=403 admin=reach supplier=403 annotator=403 quality=403 acceptance=403
|
||||
HEAD /api/delivery-packages/{id}/artifacts/{artifactId}/content | mw=[] | (*server).handleDeliveryPackageArtifactContent-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
HEAD /api/human-items/{id}/evidence/{artifactId}/content | mw=[] | (*server).handleHumanItemEvidenceContent-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
HEAD /api/human-items/{id}/evidence/{artifactId}/members/{memberId}/content | mw=[] | (*server).handleHumanItemEvidenceMemberContent-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
HEAD /api/human-items/{id}/subject-content | mw=[] | (*server).handleHumanItemSubjectContent-fm | anon=401 token=401 super=403 admin=reach supplier=reach annotator=reach quality=reach acceptance=reach
|
||||
HEAD /api/object-storage/content | mw=[(*server).requireBusinessRole.1] | (*server).handleObjectStorageContent-fm | anon=401 token=401 super=403 admin=reach supplier=403 annotator=403 quality=403 acceptance=403
|
||||
HEAD /api/object-sync/client-releases/{id}/artifacts/{platform} | mw=[(*server).requireObjectSyncFeature-fm,(*server).requireBusinessRole.1] | (*server).handleObjectSyncClientReleaseDownload-fm | anon=401 token=401 super=403 admin=reach supplier=403 annotator=reach quality=403 acceptance=403
|
||||
HEAD /api/runs/{id}/artifacts/{artifactId}/content | mw=[(*server).requireAdminMonitoringAccess-fm] | (*server).handleRunsArtifactContent-fm | anon=401 token=reach super=403 admin=reach supplier=403 annotator=403 quality=403 acceptance=403
|
||||
|
||||
19
public/vendor/movi-player-0.4.1/README.md
vendored
19
public/vendor/movi-player-0.4.1/README.md
vendored
@ -40,9 +40,8 @@ SHA-256 (this directory, element.slim.js includes the patch above):
|
||||
|
||||
## Host-element quirks (found in production, 2026-10-12)
|
||||
|
||||
Three hotfix rounds traced back to how this custom element behaves from the
|
||||
outside. None of these are visible in the upstream README; all three re-break
|
||||
silently on an upgrade unless the bridges below are re-checked:
|
||||
Several production fixes traced back to how this custom element behaves from
|
||||
the outside. These need explicit upgrade checks:
|
||||
|
||||
1. **Host events are incomplete.** The element forwards `play`/`pause`/`ended`
|
||||
to the host, but NOT `timeupdate`, `seeking`, `seeked`, or `waiting`. The
|
||||
@ -57,10 +56,22 @@ silently on an upgrade unless the bridges below are re-checked:
|
||||
has a real host size. Bridge: review caption overlay measurement.
|
||||
3. **The playback-rate cap is hard-coded** (`getMaxAllowedRate`), patched
|
||||
locally to 4 — see the patch section above.
|
||||
4. **Host `error` retains an earlier failure after a successful reload.**
|
||||
`MoviVideo.tsx` exposes a per-load error through the host instance, captures
|
||||
error events, and clears it on a new load or media readiness. It does not
|
||||
modify vendor private fields. Without this adapter, transport recovery can
|
||||
reject a successfully loaded replacement source.
|
||||
5. **Setting host `src` already loads the player.** The transport must not also
|
||||
call `load()` for this element: two asynchronous decoder loads race. Native
|
||||
`<video>` keeps its explicit `load()` call. Software fallback also probes
|
||||
extensionless media URLs with HEAD; those routes need the same authorized
|
||||
metadata access as GET.
|
||||
|
||||
**Upgrade checklist**: re-apply the rate patch; verify the event bridge still
|
||||
covers all four events; verify overlay measurement still reads the shadow
|
||||
video. Verify with `<movi-player>` actually mounted (dev default can fall back
|
||||
video; verify failed-load recovery clears host error, restores position and
|
||||
resumes playback in software fallback without a duplicate load. Verify with
|
||||
`<movi-player>` actually mounted (dev default can fall back
|
||||
to a native `<video>` and mask every quirk above — see HANDOFF §4).
|
||||
|
||||
**Loader discipline** (`src/lib/movi-player.ts`): `/vendor` assets must never
|
||||
|
||||
@ -274,6 +274,7 @@ type Props = ReviewViewingProps & {
|
||||
sliceEditAppliedRevision?: number;
|
||||
onConfirmSlices?: () => void;
|
||||
canConfirmSlices?: boolean;
|
||||
confirmSlicesLabel?: string;
|
||||
onConfirmAnnotations?: (
|
||||
segments: AnnotationSegment[],
|
||||
sliceId: string,
|
||||
@ -418,6 +419,7 @@ export function CaptureAnnotationWorkbench({
|
||||
onSliceEditSessionChange,
|
||||
onConfirmSlices,
|
||||
canConfirmSlices = false,
|
||||
confirmSlicesLabel = "确认全部切片",
|
||||
onConfirmAnnotations,
|
||||
problemSliceIds = [],
|
||||
onProblemSliceIdsChange,
|
||||
@ -5207,6 +5209,16 @@ export function CaptureAnnotationWorkbench({
|
||||
<h3 className="text-sm font-semibold text-slate-800 dark:text-gray-100">
|
||||
当前切片标注 · {selectedSlice.name || `切片 ${selectedSliceIndex + 1}`}
|
||||
</h3>
|
||||
{!readOnly && !isQualityReview && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving}
|
||||
onClick={() => openSliceEditPanel()}
|
||||
className="rounded border border-orange-400 px-2 py-1 text-xs font-medium text-orange-700 disabled:opacity-50 dark:text-orange-300"
|
||||
>
|
||||
{selectedSlice.name?.trim() ? "修改切片名称" : "选择切片名称"}
|
||||
</button>
|
||||
)}
|
||||
<span className="font-mono text-xs text-slate-500">
|
||||
({formatTime(selectedSlice.start)} ~ {formatTime(selectedSlice.end)} · 时长{" "}
|
||||
{formatTime(selectedSlice.end - selectedSlice.start)})
|
||||
@ -6385,7 +6397,7 @@ export function CaptureAnnotationWorkbench({
|
||||
onClick={() => requestStageConfirmation()}
|
||||
className="rounded bg-orange-500 px-4 py-2 text-sm font-semibold text-white disabled:opacity-50"
|
||||
>
|
||||
确认全部切片
|
||||
{confirmSlicesLabel}
|
||||
</button>
|
||||
{sliceNameIssue ? (
|
||||
<span role="status" className="text-xs text-amber-700">
|
||||
|
||||
@ -180,18 +180,35 @@ export const MoviVideo = React.forwardRef<HTMLVideoElement, MoviVideoProps>(func
|
||||
if (!element) return;
|
||||
const handlers: Array<[string, EventListener]> = [];
|
||||
let innerCleanup: (() => void) | null = null;
|
||||
// 0.4.1 remembers its last error forever, including after a new source
|
||||
// successfully loads. Expose HTMLMediaElement's per-load error contract
|
||||
// without modifying the vendor's private state or remounting the editor.
|
||||
const originalOwnError = Object.getOwnPropertyDescriptor(element, "error");
|
||||
const mediaPrototype = Object.getPrototypeOf(element);
|
||||
let currentMediaError: unknown = null;
|
||||
if (mode === "movi") {
|
||||
Object.defineProperty(element, "error", { configurable: true, get: () => currentMediaError });
|
||||
}
|
||||
const add = (name: string, listener: EventListener) => {
|
||||
element.addEventListener(name, listener);
|
||||
handlers.push([name, listener]);
|
||||
};
|
||||
for (const [prop, eventName] of EVENT_BRIDGE) {
|
||||
add(eventName, (event) => {
|
||||
if (mode === "movi") {
|
||||
if (eventName === "error")
|
||||
currentMediaError = Reflect.get(mediaPrototype, "error", element) || { code: 3, message: "视频读取失败" };
|
||||
else if (["loadedmetadata", "loadeddata", "canplay"].includes(eventName)) currentMediaError = null;
|
||||
}
|
||||
const handler = handlersRef.current[prop];
|
||||
if (handler) handler(event as unknown as { currentTarget: HTMLVideoElement });
|
||||
});
|
||||
}
|
||||
|
||||
if (mode === "movi") {
|
||||
add("loadstart", () => {
|
||||
currentMediaError = null;
|
||||
});
|
||||
// Media fragment `#t=start,end`: movi does not parse fragments for
|
||||
// progressive files, so the wrapper enforces the end bound itself.
|
||||
if (endAt !== null) {
|
||||
@ -302,6 +319,10 @@ export const MoviVideo = React.forwardRef<HTMLVideoElement, MoviVideoProps>(func
|
||||
return () => {
|
||||
innerCleanup?.();
|
||||
for (const [name, listener] of handlers) element.removeEventListener(name, listener);
|
||||
if (mode === "movi") {
|
||||
if (originalOwnError) Object.defineProperty(element, "error", originalOwnError);
|
||||
else Reflect.deleteProperty(element, "error");
|
||||
}
|
||||
};
|
||||
}, [mode, plainSrc, endAt]);
|
||||
|
||||
|
||||
@ -83,7 +83,9 @@ export function useCaptureVideoTransport(options: Options) {
|
||||
url.searchParams.set("_mediaRetry", `${Date.now()}-${++reloadSequence.current}`);
|
||||
}
|
||||
video.src = url.href;
|
||||
video.load();
|
||||
// The movi src setter already disposes/loads the player. Calling load()
|
||||
// again races two asynchronous decoders; native media keeps its own reset.
|
||||
if (video.tagName !== "MOVI-PLAYER") video.load();
|
||||
}
|
||||
|
||||
function visibleTracks() {
|
||||
|
||||
@ -37,3 +37,22 @@ export function normalizeAnnotationTaskDetail(detail) {
|
||||
reviews: list(detail.reviews, "审核记录"),
|
||||
};
|
||||
}
|
||||
|
||||
/** Server-owned generation readiness takes priority over restored draft content. */
|
||||
export function annotationEditorPhase(detail) {
|
||||
if (["slice", "materializing", "annotate"].includes(detail.editorState?.phase)) return detail.editorState.phase;
|
||||
// Compatibility with an older API during a rolling release. A known workflow
|
||||
// always wins over drafts; legacy responses keep their existing history path.
|
||||
const item = detail.humanItem;
|
||||
const workflow = item?.subject?.payload?.sliceWorkflow;
|
||||
const job = item?.processingJob?.status;
|
||||
if (workflow?.status === "failed" || job === "failed") return "slice";
|
||||
if (
|
||||
["processing", "queued", "running", "materializing"].includes(workflow?.status) ||
|
||||
["processing", "queued", "running"].includes(job)
|
||||
)
|
||||
return "materializing";
|
||||
if (workflow) return workflow.status === "completed" && workflow.phase === "annotate" ? "annotate" : "slice";
|
||||
const confirmed = (revision) => revision.revision > 0 && revision.segments?.length > 0;
|
||||
return detail.revisions?.some(confirmed) || detail.sliceRevisions?.some(confirmed) ? "annotate" : "slice";
|
||||
}
|
||||
|
||||
@ -112,6 +112,7 @@ import type {
|
||||
import { useUser } from "../context/UserContext";
|
||||
import { useTimeZone } from "../context/TimeZoneContext";
|
||||
import { annotationOperationsApi, type AnnotationWorkBuffer } from "../services/api/annotation-operations";
|
||||
import { annotationEditorPhase } from "../lib/annotation-workspace.js";
|
||||
import { humanLoopApi } from "../services/api/human-loop";
|
||||
import { deliveryPackagesApi } from "../services/api/delivery-packages";
|
||||
import { projectsApi } from "../services/api/projects";
|
||||
@ -1768,20 +1769,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
const sliceWorkflow = next.humanItem?.subject?.payload?.sliceWorkflow as
|
||||
| { status?: string; phase?: string; error?: string }
|
||||
| undefined;
|
||||
const nextPhase: CombinedEditorPhase =
|
||||
sliceWorkflow?.status === "processing"
|
||||
? "materializing"
|
||||
: sliceWorkflow?.status === "completed" || sliceWorkflow?.phase === "annotate"
|
||||
? "annotate"
|
||||
: sliceWorkflow?.status === "editing" || sliceWorkflow?.phase === "slice"
|
||||
? "slice"
|
||||
: requestedSliceId ||
|
||||
nextAnnotations.some(
|
||||
(segment) => segment.source !== "qwen" && segment.source !== "workflow-prelabel",
|
||||
) ||
|
||||
Object.values(nextStatuses).some((status) => status !== "pending")
|
||||
? "annotate"
|
||||
: "slice";
|
||||
const nextPhase: CombinedEditorPhase = annotationEditorPhase(next);
|
||||
if (
|
||||
next.task.continuousActions &&
|
||||
nextPhase === "annotate" &&
|
||||
@ -3108,6 +3096,12 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
if (combinedSubmissionProcessing) {
|
||||
return { canSubmit: false, reason: "正在提交中..." };
|
||||
}
|
||||
if (detail?.editorState?.canConfirmDescriptions === false) {
|
||||
return { canSubmit: false, reason: "切片生成尚未完成,请先完成或恢复切片生成" };
|
||||
}
|
||||
if (sliceSegments.some((slice) => slice.deliveryDisposition !== "discard" && !slice.name?.trim())) {
|
||||
return { canSubmit: false, reason: "还有切片未选择名称,请补充后提交" };
|
||||
}
|
||||
if (!sliceCoverage.complete) {
|
||||
return { canSubmit: false, reason: "视频片段尚未完全由切片覆盖" };
|
||||
}
|
||||
@ -3157,6 +3151,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
exactFrameEditing,
|
||||
frameBoundaries,
|
||||
detail?.task.continuousActions,
|
||||
detail?.editorState?.canConfirmDescriptions,
|
||||
]);
|
||||
const canCurrentUserClaimItem = useCallback((item: HumanItem | undefined) => item?.canClaim === true, []);
|
||||
const sliceEditorReadOnly = annotationSliceEditorReadOnly({
|
||||
@ -3251,6 +3246,10 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
) => {
|
||||
if (!annotationAuthoringRef.current) return false;
|
||||
if (!detail?.humanItem || !selectedClaimedByMe || combinedSubmissionLocked) return false;
|
||||
if (detail.editorState?.canConfirmDescriptions === false) {
|
||||
setError("切片生成尚未完成,描述仍保留在编辑器中,请先完成或恢复切片生成。");
|
||||
return false;
|
||||
}
|
||||
const taskId = detail.task.id;
|
||||
let submittedVersion = detailRef.current?.humanItem?.version ?? detail.humanItem.version;
|
||||
const previousWorkspace = confirmedAnnotationWorkspace();
|
||||
@ -4269,13 +4268,15 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
}
|
||||
};
|
||||
|
||||
const retryFailedSlices = async () => {
|
||||
const retryFailedSlices = async (recoverExisting = false) => {
|
||||
if (!detail?.humanItem || !selectedClaimedByMe || annotationDirty || combinedSubmissionLocked || saving) return;
|
||||
const taskId = detail.task.id;
|
||||
const token = await beginAnnotationMutation(taskId);
|
||||
if (!token) return;
|
||||
try {
|
||||
const response = await annotationOperationsApi.retryFailedSlices(taskId, token.version);
|
||||
const response = recoverExisting
|
||||
? await annotationOperationsApi.recoverExistingSlices(taskId, token.version)
|
||||
: await annotationOperationsApi.retryFailedSlices(taskId, token.version);
|
||||
if (!annotationMutationScopeRef.current.owns(token, currentAnnotationMutationContext())) return;
|
||||
setDetail((current) => (current?.task.id === taskId ? { ...current, humanItem: response.item } : current));
|
||||
clearEditHistory();
|
||||
@ -4298,6 +4299,11 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
|
||||
const confirmSlicesAndMaterialize = async () => {
|
||||
if (!annotationAuthoringRef.current) return;
|
||||
if (detail?.editorState?.canRecoverGeneration) {
|
||||
if (annotationDirty) setError("请先保存当前进度,再恢复切片生成;已有标注将保留。");
|
||||
else await retryFailedSlices(true);
|
||||
return;
|
||||
}
|
||||
if ((detail?.humanItem?.subject.payload?.sliceWorkflow as { status?: string } | undefined)?.status === "failed") {
|
||||
if (annotationDirty) setError("请先保存当前编辑,再按已保存内容重试切片。");
|
||||
else await retryFailedSlices();
|
||||
@ -7853,6 +7859,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
}}
|
||||
onDeleteSlice={deleteSlice}
|
||||
onConfirmSlices={() => void confirmSlicesAndMaterialize()}
|
||||
confirmSlicesLabel={detail.editorState?.canRecoverGeneration ? "恢复生成并保留标注" : undefined}
|
||||
canConfirmSlices={
|
||||
!sliceAlignmentIssue &&
|
||||
sliceCoverage.complete &&
|
||||
|
||||
@ -344,6 +344,12 @@ export const annotationOperationsApi = {
|
||||
{ method: "POST" },
|
||||
{ version, retryFailed: true },
|
||||
),
|
||||
recoverExistingSlices: (taskId: string, version: number) =>
|
||||
apiRequest<{ item: HumanItem; sliceWorkflow: Record<string, unknown> }>(
|
||||
`/api/plugins/annotation-qa/tasks/${taskId}/slice-confirmations`,
|
||||
{ method: "POST" },
|
||||
{ version, recoverExisting: true },
|
||||
),
|
||||
confirmSlices: (
|
||||
taskId: string,
|
||||
payload: {
|
||||
|
||||
@ -2139,6 +2139,11 @@ export interface AnnotationReview {
|
||||
|
||||
export interface AnnotationTaskDetail {
|
||||
task: AnnotationTaskRecord;
|
||||
editorState?: {
|
||||
phase: "slice" | "materializing" | "annotate";
|
||||
canConfirmDescriptions: boolean;
|
||||
canRecoverGeneration?: boolean;
|
||||
};
|
||||
sliceRevisions: SliceRevision[];
|
||||
revisions: AnnotationRevision[];
|
||||
reviews: AnnotationReview[];
|
||||
|
||||
169
tests/browser/annotation-media-recovery-replica.mjs
Normal file
169
tests/browser/annotation-media-recovery-replica.mjs
Normal file
@ -0,0 +1,169 @@
|
||||
// Real movi + real authenticated media handlers. Synthetic local videos only.
|
||||
import assert from "node:assert/strict";
|
||||
import { createServer } from "vite";
|
||||
import { chromium } from "playwright";
|
||||
const api = process.env.REWORK_BOUNDARY_API;
|
||||
assert.match(api, /^http:\/\/127\.0\.0\.1:\d+$/);
|
||||
const vite = await createServer({
|
||||
server: { host: "127.0.0.1", port: 5205, strictPort: true, proxy: { "/api": { target: api } } },
|
||||
});
|
||||
let browser;
|
||||
try {
|
||||
await vite.listen();
|
||||
browser = await chromium.launch({
|
||||
executablePath: "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
||||
headless: true,
|
||||
args: ["--no-proxy-server"],
|
||||
});
|
||||
for (const role of ["annotation", "quality", "acceptance"]) {
|
||||
const page = await browser.newPage({ viewport: { width: 1500, height: 1000 } });
|
||||
page.setDefaultTimeout(15000);
|
||||
let fail = false;
|
||||
const requests = [],
|
||||
errors = [];
|
||||
page.on("pageerror", (e) => {
|
||||
errors.push(e.message);
|
||||
console.error("fixture page error", e.message);
|
||||
});
|
||||
await page.route("**/*", (route) => {
|
||||
const request = route.request(),
|
||||
u = new URL(request.url());
|
||||
if (u.hostname !== "127.0.0.1") return route.abort();
|
||||
if (u.pathname.endsWith("/subject-content")) {
|
||||
requests.push({
|
||||
method: request.method(),
|
||||
side: u.searchParams.get("side"),
|
||||
retry: u.searchParams.has("_mediaRetry"),
|
||||
});
|
||||
if (fail) return route.abort("failed");
|
||||
} else if (u.pathname.includes("/api/") && !["GET", "HEAD"].includes(request.method())) {
|
||||
assert.ok(u.pathname.endsWith("/movi-stats"), "media recovery must not write annotation data");
|
||||
return route.fulfill({ status: 202, json: {} });
|
||||
}
|
||||
return route.continue();
|
||||
});
|
||||
await page.route("**/__media_feedback", (route) =>
|
||||
route.fulfill({
|
||||
contentType: "text/html",
|
||||
body: `<html><body><div id="root"></div><script type="module">
|
||||
import RefreshRuntime from '/@react-refresh';RefreshRuntime.injectIntoGlobalHook(window);window.$RefreshReg$=()=>{};window.$RefreshSig$=()=>type=>type;window.__vite_plugin_react_preamble_installed__=true;
|
||||
const React=await import('/node_modules/.vite/deps/react.js').then(m=>m.default||m);const D=await import('/node_modules/.vite/deps/react-dom_client.js');await import('/src/index.css');
|
||||
const {CaptureAnnotationWorkbench}=await import('/src/components/CaptureAnnotationWorkbench.tsx');
|
||||
const role=${JSON.stringify(role)};
|
||||
const props={taskId:'draft-task',videoSource:'/api/human-items/draft-item/subject-content',rightVideoSource:'/api/human-items/draft-item/subject-content?side=right',sourceIsFullVideo:true,focusedLayout:true,clipStart:0,clipEnd:10,slices:[{id:'s',name:'测试切片',start:0,end:10}],segments:[{id:'a',start:0,end:10,description:'Original',status:'described',source:'manual',confidence:1}],sliceDictionary:[{id:'label',name:'测试切片'}],labels:[],statuses:{},phase:'annotate',continuousActions:true,frameBoundaries:Array.from({length:101},(_,i)=>i/10),isQualityReview:role!=='annotation',reviewMode:role==='acceptance'?'acceptance':'quality',onChange:()=>{throw Error('Unexpected annotation write')}};
|
||||
(D.createRoot||D.default.createRoot)(document.getElementById('root')).render(React.createElement('div',{className:'annotation-operations-page'},React.createElement(CaptureAnnotationWorkbench,props)));
|
||||
</script></body></html>`,
|
||||
}),
|
||||
);
|
||||
await page.goto("http://127.0.0.1:5205/__media_feedback", { waitUntil: "domcontentloaded" });
|
||||
const bench = page.getByTestId("capture-annotation-workbench"),
|
||||
left = page.locator('movi-player[data-camera="left"]');
|
||||
await left.waitFor().catch(async (error) => {
|
||||
console.error(
|
||||
JSON.stringify(
|
||||
await page.evaluate(() => ({
|
||||
text: document.body.innerText.slice(0, 500),
|
||||
players: [...document.querySelectorAll("movi-player,video")].map((v) => ({
|
||||
tag: v.tagName,
|
||||
camera: v.getAttribute("data-camera"),
|
||||
})),
|
||||
registered: Boolean(customElements.get("movi-player")),
|
||||
})),
|
||||
),
|
||||
);
|
||||
throw error;
|
||||
});
|
||||
const settled = () =>
|
||||
page.waitForFunction(() => {
|
||||
const v = document.querySelector('movi-player[data-camera="left"]');
|
||||
return v && v.readyState >= 2 && !v.seeking && !v.error;
|
||||
});
|
||||
await settled();
|
||||
// The native engine can start without a probe; the software fallback used
|
||||
// after a decode failure probes the same authenticated, extensionless URL.
|
||||
await left.evaluate((v) => {
|
||||
v.setAttribute("engine", "wasm");
|
||||
const u = new URL(v.getAttribute("src"), location.href);
|
||||
u.searchParams.set("fallback", "1");
|
||||
v.src = u.href;
|
||||
});
|
||||
await settled();
|
||||
assert.ok(
|
||||
requests.some((r) => r.method === "HEAD"),
|
||||
"software fallback probes the extensionless subject URL",
|
||||
);
|
||||
assert.ok(!requests.some((r) => r.side === "right"), "hidden camera does not load");
|
||||
await bench.getByRole("button", { name: "播放", exact: true }).click();
|
||||
await page.waitForFunction(() => document.querySelector('movi-player[data-camera="left"]').currentTime > 1);
|
||||
await bench.getByRole("button", { name: "暂停", exact: true }).click();
|
||||
let input;
|
||||
if (role === "annotation") {
|
||||
await bench.getByTestId("annotation-description-block").first().click();
|
||||
input = bench.getByRole("textbox", { name: "动作描述", exact: true });
|
||||
await input.fill("Draft survives a failed media load");
|
||||
} else {
|
||||
assert.equal(await bench.getByRole("button", { name: "修改切片名称", exact: true }).count(), 0);
|
||||
}
|
||||
const held = await left.evaluate((v) => v.currentTime);
|
||||
fail = true;
|
||||
await left.evaluate((v) => {
|
||||
const u = new URL(v.getAttribute("src"), location.href);
|
||||
u.searchParams.set("simulatedFailure", "1");
|
||||
v.src = u.href;
|
||||
});
|
||||
await page.waitForTimeout(4500);
|
||||
assert.ok(
|
||||
await bench.getByRole("button", { name: "重新加载视频", exact: true }).count(),
|
||||
"failed media keeps a recovery action visible",
|
||||
);
|
||||
fail = false;
|
||||
await bench.getByRole("button", { name: "重新加载视频", exact: true }).click();
|
||||
await settled().catch(async (error) => {
|
||||
console.error(
|
||||
JSON.stringify({
|
||||
recentRequests: requests.slice(-12),
|
||||
media: await left.evaluate((v) => ({
|
||||
source: v.getAttribute("src"),
|
||||
readyState: v.readyState,
|
||||
currentTime: v.currentTime,
|
||||
duration: v.duration,
|
||||
seeking: v.seeking,
|
||||
error: v.error && { code: v.error.code, message: v.error.message },
|
||||
inner: [...(v.shadowRoot?.querySelectorAll("video") || [])].map((x) => ({
|
||||
readyState: x.readyState,
|
||||
error: x.error?.code,
|
||||
})),
|
||||
})),
|
||||
}),
|
||||
);
|
||||
throw error;
|
||||
});
|
||||
await page.waitForFunction(
|
||||
(time) => Math.abs(document.querySelector('movi-player[data-camera="left"]').currentTime - time) < 0.15,
|
||||
held,
|
||||
);
|
||||
assert.ok(
|
||||
requests.some((r) => r.retry),
|
||||
"recovery uses the original authenticated URL",
|
||||
);
|
||||
assert.ok(
|
||||
Math.abs((await left.evaluate((v) => v.currentTime)) - held) < 0.15,
|
||||
"media retry preserves the editing position",
|
||||
);
|
||||
if (input) assert.equal(await input.inputValue(), "Draft survives a failed media load");
|
||||
await bench.getByRole("button", { name: "播放", exact: true }).click();
|
||||
await page.waitForFunction(
|
||||
(time) => document.querySelector('movi-player[data-camera="left"]').currentTime > time + 0.3,
|
||||
held,
|
||||
);
|
||||
await bench.getByRole("button", { name: "暂停", exact: true }).click();
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(
|
||||
JSON.stringify({ role, passed: true, headRequests: requests.filter((r) => r.method === "HEAD").length }),
|
||||
);
|
||||
await page.close();
|
||||
}
|
||||
} finally {
|
||||
await browser?.close();
|
||||
await vite.close();
|
||||
}
|
||||
@ -36,6 +36,10 @@ try {
|
||||
page = await ctx.newPage();
|
||||
page.setDefaultTimeout(12000);
|
||||
page.on("pageerror", (e) => report.pageErrors.push(e.message));
|
||||
page.on("response", async (response) => {
|
||||
if (response.url().endsWith("/slice-confirmations") && response.status() >= 400)
|
||||
console.error("local generation response", response.status(), await response.text());
|
||||
});
|
||||
page.on("request", (r) => {
|
||||
if (!["GET", "HEAD"].includes(r.method()))
|
||||
report.writes.push({ method: r.method(), path: new URL(r.url()).pathname });
|
||||
@ -113,6 +117,34 @@ try {
|
||||
assert.equal(w.segments[0].end, 4);
|
||||
}
|
||||
};
|
||||
await reset("legacy", "described", 0);
|
||||
await page.getByRole("button", { name: "恢复生成并保留标注", exact: true }).click();
|
||||
await page.getByRole("button", { name: "确认生成", exact: true }).click();
|
||||
await waitFor(async () => (await read()).segments.length === 2);
|
||||
const recovered = await read();
|
||||
assert.equal(recovered.segments.find((a) => a.id === "newer-described").description, "最新草稿描述");
|
||||
assert.equal(recovered.segments.find((a) => a.id === "newer-pending").status, "pending");
|
||||
await page.locator('[data-testid="capture-annotation-workbench"][data-stage="annotate"]').waitFor();
|
||||
await page.getByTestId("capture-slice-timeline").locator('[data-slice-id="k"]').click();
|
||||
await page.getByRole("button", { name: "修改切片名称", exact: true }).waitFor();
|
||||
report.cases.push("legacy recovery preserves newer autosave and enters annotation only after generation");
|
||||
await reset("unnamed", "pending", 0);
|
||||
await page.getByTestId("capture-slice-timeline").locator('[data-slice-id="k"]').click();
|
||||
await page.getByRole("button", { name: "选择切片名称", exact: true }).click();
|
||||
const namingPanel = page.getByTestId("slice-edit-panel");
|
||||
await namingPanel.getByRole("button", { name: "从切片字典选择", exact: true }).click();
|
||||
await namingPanel.getByRole("button", { name: "补充切片名称", exact: true }).click();
|
||||
await namingPanel.getByTestId("slice-edit-panel-apply").click();
|
||||
await namingPanel.waitFor({ state: "hidden" });
|
||||
const renamed = await read();
|
||||
assert.equal(renamed.sliceSegments.find((s) => s.id === "k").name, "补充切片名称");
|
||||
assert.equal(renamed.segments.length, 1);
|
||||
assert.equal(renamed.segments[0].status, "pending");
|
||||
assert.equal(renamed.segments[0].start, 5);
|
||||
assert.equal(renamed.segments[0].end, 10);
|
||||
await load();
|
||||
assert.equal((await read()).sliceSegments.find((s) => s.id === "k").name, "补充切片名称");
|
||||
report.cases.push("visible post-confirmation naming preserves actions, boundaries and reload");
|
||||
for (const side of ["left", "right"])
|
||||
for (const status of ["pending", "described"]) {
|
||||
await reset(side, status, status === "pending" ? 0 : 1);
|
||||
|
||||
45
tests/frontend/annotation-editor-state.test.mjs
Normal file
45
tests/frontend/annotation-editor-state.test.mjs
Normal file
@ -0,0 +1,45 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { annotationEditorPhase } from "../../src/lib/annotation-workspace.js";
|
||||
|
||||
const draft = (workflow, processingJob) => ({
|
||||
humanItem: {
|
||||
processingJob,
|
||||
subject: { payload: { sliceWorkflow: workflow, annotationDraft: { segments: [{ id: "a", source: "human" }] } } },
|
||||
},
|
||||
revisions: [{ revision: 1, segments: [{ id: "a", source: "human" }] }],
|
||||
});
|
||||
test("server readiness overrides restored annotations and requested editor state", () => {
|
||||
for (const phase of ["slice", "materializing", "annotate"]) {
|
||||
assert.equal(
|
||||
annotationEditorPhase({ ...draft({ status: "completed", phase: "annotate" }), editorState: { phase } }),
|
||||
phase,
|
||||
);
|
||||
}
|
||||
});
|
||||
test("known unfinished or failed workflows never infer annotation readiness from drafts", () => {
|
||||
for (const workflow of [
|
||||
{ status: "failed" },
|
||||
{ status: "failed", phase: "annotate" },
|
||||
{ status: "editing", phase: "annotate" },
|
||||
{ status: "completed", phase: "slice" },
|
||||
]) {
|
||||
assert.equal(annotationEditorPhase(draft(workflow)), "slice");
|
||||
}
|
||||
assert.equal(annotationEditorPhase(draft({ status: "completed", phase: "annotate" }, { status: "failed" })), "slice");
|
||||
assert.equal(
|
||||
annotationEditorPhase(draft({ status: "completed", phase: "annotate" }, { status: "queued" })),
|
||||
"materializing",
|
||||
);
|
||||
});
|
||||
test("legacy API responses retain confirmed history but not draft-only readiness", () => {
|
||||
assert.equal(annotationEditorPhase(draft(undefined)), "annotate");
|
||||
assert.equal(annotationEditorPhase({ humanItem: draft(undefined).humanItem }), "slice");
|
||||
assert.equal(
|
||||
annotationEditorPhase({
|
||||
humanItem: draft(undefined).humanItem,
|
||||
sliceRevisions: [{ revision: 0, segments: [{ id: "s" }] }],
|
||||
}),
|
||||
"slice",
|
||||
);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user