🛡️ Require complete source validation before annotation claims
This commit is contained in:
parent
08bbd632e7
commit
b3322680d9
@ -17,7 +17,7 @@
|
||||
3. 校验后将两路视频、两份 PTS、一份 IMU 固定到 `system/runs/<run>/annotation-sources/<fingerprint>/`。BOS 使用条件复制,不能覆盖已有固定对象;本地使用完整临时文件及原子发布。源版本变化必须重新验证,旧修订继续引用自己的固定版本。
|
||||
4. 证书以校验和、gzip 保存于既有 timeline 索引集合。独立持久化校验队列负责冷源;轻量修订等待时让出执行槽,不消耗崩溃重试次数。校验租约续期,超时可恢复。
|
||||
|
||||
旧时间轴队列只建立原有索引,不因启用新校验器而生成固定源副本。当前用户确认创建的 `source-v1:` 请求优先于历史时间轴工作,使用现有 ID/状态索引,不新增迁移或改写旧队列记录。
|
||||
旧时间轴队列的早期兼容规则见下方 2026-11-11 更新;当前用户确认创建的 `source-v1:` 请求优先于历史时间轴工作,使用现有 ID/状态索引。
|
||||
5. 后续每个修订只写修订清单、每片 annotation 和 synchronization JSON。记录半开硬件时间窗、双目各自帧区间及播放偏移,保留完整覆盖、舍弃理由、动作与审核冻结校验。
|
||||
6. 最终验收使用已固定的完整源媒体和切片逻辑时间映射;不依赖重新生成的逐片视频、PTS、IMU。切片本地时间和双目源时间分别转换,元数据就绪后才挂载播放器。
|
||||
7. 旧目录交付仍在终审之后按帧生成保留切片媒体和 CSV,舍弃区间不产生交付媒体。该阶段仍有转码成本,与交互式切片队列分离。
|
||||
@ -40,6 +40,8 @@ B06/part0002、B14/part0001、B18/part0003 的本地样本均为连续 30fps,p
|
||||
|
||||
## 成本、兼容性与回退
|
||||
|
||||
2026-11-11 用户要求完整源校验通过后才能领取,替代旧时间轴成功及旧任务免校验的兼容放行。所有新任务和已经排队的旧任务必须完成媒体与传感器校验,成功作业写入源指纹;只完成时间轴、无完整源指纹的历史 `completed` 记录保持待补验,不得直接视为有效。读取和领取不触发解码或批量补写;旧完成记录通过受控重校验入口恢复。已领取任务保留标注、草稿、版本、归属和历史,失败不自动回池,补验不自动重跑工作流。API 和校验器须协调升级,旧任务补验成本及生产授权边界见[源数据校验与标注准入](../architecture/source-validation-admission.md)。
|
||||
|
||||
2026-10-22 补充:普通失败重试不能以旧确认覆盖页面恢复的较新草稿。重试核对确认内容指纹;内容不同需操作者显式按当前保存内容重新确认,保留旧快照及已有动作。后台完成时再次核对,旧队列作业亦适用,不自动回填或重算历史时间。具体契约见 [标注时间完整性](../annotation-time-integrity.zh-CN.md)。
|
||||
|
||||
- 固定源每 Run/源版本复制一次,不是跨 Run 去重;首用仍消耗解码 CPU、读取带宽与一份源大小的存储,之后修订为 JSON。
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
## 状态与准入
|
||||
|
||||
- “文件齐全”只证明所选目录的必需对象存在、非空并稳定,不代表 PTS、IMU、视频或 meta 内容有效。
|
||||
- 现代完整视频任务(`sourceIsFullVideo && templateVersion >= 5 && artifactId`)必须有本任务的时间轴校验成功记录。记录缺失、排队、运行或失败时不进入可领取集合;既有后台队列负责实际校验,不在轮询或领取时重复解析整个源文件。
|
||||
- 所有标注任务(含旧模板、缺少旧版标志的任务)领取前必须有本任务、组织、项目及 Run 匹配的完整源校验证据:作业为 `completed` 且包含实际完整校验成功后写入的 `sourceFingerprint`。仅有旧时间轴的 `completed` 不构成放行依据。缺记录、缺完整证据、排队、运行或失败均不进入可领取集合;既有后台队列负责实际校验,不在轮询或领取时重复解析整个源文件。
|
||||
- 本任务当前切片/送检 outbox 所引用的源证书作业如果排队或失败,同样阻断分配。新 outbox 明确保存私有 `sourceIndex` 标志;已物化的 `materialization.sourceIndex` 也构成必须有证书的证据。已知源索引任务缺少所需作业时不放行。
|
||||
- 历史物理切片 outbox 也带 `sourceFingerprint`,该字段单独存在不能证明它使用源证书协议。无源索引证据、无校验作业的旧格式任务保持旧路径,展示为未核验而非伪称校验成功;任何已存在的失败记录仍生效。
|
||||
- 历史物理切片 outbox 也带 `sourceFingerprint`,该字段单独存在不能证明它已完成源校验。新旧任务均需要完整证据;未知格式、元数据不足或无法完整校验的旧任务保持阻断,不能以旧路径兜底放行。已领取任务的工作区、草稿、归属及审核历史不因此清空或回池。
|
||||
- 随机候选列表、可领取数量与最终原子领取都核对同一条件,指定领取也在存储层核对。失败不会清空任务、解除已有归属或重写标注草稿。指定领取以持久化的当前源状态为准;即使 outbox 变化未改变任务版本,陈旧领取快照也不能覆盖新作业。管理员仍可查看异常任务和既有资料。
|
||||
|
||||
## 诊断与恢复
|
||||
@ -24,7 +24,11 @@
|
||||
|
||||
工作台若在已通过的任务中发现新的源校验错误,会按读取时的作业代次把该记录标为失败。新一轮重校验开始后,迟到的旧请求或旧校验器不能覆盖它。存储写入与领取使用既有项目写保护;不持锁解析视频。读取取消、超时或网络故障不作为内容错误撤销准入。
|
||||
|
||||
旧任务缺少校验记录时仍沿用兼容路径;但时间轴实际发现内容异常后,会原子插入失败记录并提供管理员重校验入口。插入不能覆盖并发开始或完成的新校验,不要求所有历史任务批量重验。只有历史 `materialization.sourceIndex` 标志、没有 outbox 指纹的任务,明确重校验成功且记录当前源指纹后才能恢复;后续出现新 outbox 指纹仍必须核对其校验状态。
|
||||
旧任务缺少校验记录或完整证据时显示待校验,不能领取。新增任务自动排入完整校验;已经排队的旧时间轴作业也必须完整校验后才能发布成功证据。既有 `completed` 记录不会在读取时自动重置、补造指纹或发起大规模回填,需通过明确的重校验入口补验。只有历史 `materialization.sourceIndex` 标志、没有 outbox 指纹的任务,明确重校验成功且记录当前源指纹后才能恢复;后续出现新 outbox 指纹仍必须核对其校验状态。
|
||||
|
||||
只读委托映射仍可解析已有时间轴,但若没有完整校验所需的合法固定源输出位置,不得标记成功或领取;需要由管理员明确配置输出权限,不能擅自扩大源目录权限。
|
||||
|
||||
上线须同时升级 API 与校验器;旧校验器只能产生时间轴成功时,新 API 仍会阻断。历史补验会增加视频解码、源文件读取及固定源副本成本,应先盘点待补验任务,再按现有校验并发分批执行,生产补验需另行授权。严格准入启用后,可领取数可能减少,这是排除未完整校验任务后的结果,不应通过忽略缺证据记录恢复数量。已领取任务保持占位和已保存内容,补验通过后继续原任务,不重跑整条工作流、不自动重放失败送检。
|
||||
|
||||
源文件由责任方明确修复;平台不自动改写、舍弃或删除源文件。舍弃仍需原有明确业务操作。
|
||||
|
||||
|
||||
@ -30,6 +30,12 @@ func TestAdminAnnotationPoolTotalsAndOldPageSearch(t *testing.T) {
|
||||
if i >= 606 {
|
||||
item.CurrentStageID = "quality_review"
|
||||
}
|
||||
task := f.task
|
||||
task.ID = item.LegacyTaskID
|
||||
if err := f.store.UpsertAnnotationTask(f.ctx, task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
completeFixtureSourceValidation(t, combinedDraftFixture{ctx: f.ctx, store: f.store}, task)
|
||||
if e := f.store.UpsertHumanItem(f.ctx, item); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func TestAdminSourceFailureRemainsDiscoverableButUnavailable(t *testing.T) {
|
||||
f := randomClaimFixture(t, 1)
|
||||
f := randomClaimFixture(t, 1, false)
|
||||
task, _ := f.store.GetAnnotationTask(f.ctx, "random-task-0")
|
||||
task.SourceIsFullVideo, task.TemplateVersion, task.ArtifactID = true, 5, "original-left"
|
||||
if err := f.store.UpsertAnnotationTask(f.ctx, *task); err != nil {
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@ -57,6 +58,23 @@ func TestDelegatedReadOnlyFrameTimelineIncludesIMUSource(t *testing.T) {
|
||||
if pending.Code != http.StatusUnprocessableEntity || !strings.Contains(pending.Body.String(), "source_validation_pending") {
|
||||
t.Fatalf("unvalidated delegated source was admitted: %d %s", pending.Code, pending.Body.String())
|
||||
}
|
||||
// Reading a delegated timeline remains supported. It cannot stand in for
|
||||
// full proof when this mapping has no authorized pinned-source output.
|
||||
reader := &server{store: f.store, workspaceMountPath: workspace}
|
||||
for _, camera := range []string{"left", "right"} {
|
||||
if _, err := reader.annotationFrameTimelineForTask(f.ctx, f.task, camera); err != nil {
|
||||
t.Fatalf("%s delegated timeline read: %v", camera, err)
|
||||
}
|
||||
}
|
||||
before, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
||||
job, err := f.store.ClaimAnnotationIndex(f.ctx, "legacy-readonly", nowISO(), time.Now().Add(time.Minute).UTC().Format(time.RFC3339Nano))
|
||||
if err != nil || job == nil {
|
||||
t.Fatal("missing validation job", err)
|
||||
}
|
||||
job.Status, job.Attempt = "queued", 4
|
||||
if ok, err := f.store.FinishAnnotationIndex(f.ctx, *job); err != nil || !ok {
|
||||
t.Fatal("failed to prepare final validation attempt", err)
|
||||
}
|
||||
ctx, cancel := context.WithCancel(f.ctx)
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
@ -69,20 +87,27 @@ func TestDelegatedReadOnlyFrameTimelineIncludesIMUSource(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if job != nil && job.Status == "completed" {
|
||||
if job != nil && job.Status == "failed" {
|
||||
if job.SourceFingerprint != "" || !strings.Contains(job.Error, "read-only") {
|
||||
t.Fatalf("incomplete read-only proof published: %+v", job)
|
||||
}
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("delegated read-only validation did not complete: %+v", job)
|
||||
t.Fatalf("delegated read-only validation did not fail closed: %+v", job)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
for _, camera := range []string{"left", "right"} {
|
||||
r := f.request(http.MethodGet, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/frame-timeline?camera="+camera+"&encoding=compact", f.annotator, nil)
|
||||
if r.Code != 200 {
|
||||
t.Fatalf("%s frame timeline: %d %s", camera, r.Code, r.Body.String())
|
||||
if r.Code != http.StatusUnprocessableEntity {
|
||||
t.Fatalf("%s admitted an incomplete source: %d %s", camera, r.Code, r.Body.String())
|
||||
}
|
||||
}
|
||||
after, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
||||
if !reflect.DeepEqual(before, after) {
|
||||
t.Fatal("read-only validation changed saved work or ownership")
|
||||
}
|
||||
s := &server{store: f.store, workspaceMountPath: workspace}
|
||||
if _, _, _, err := s.annotationWorkspaceObject(f.ctx, f.task.OrganizationID, filepath.Join(root, "imu.csv")); err == nil {
|
||||
t.Fatal("source write allowed after read")
|
||||
|
||||
@ -77,7 +77,9 @@ func newCombinedDraftFixture(t *testing.T, supplierIDs ...string) combinedDraftF
|
||||
if err := dataStore.UpsertHumanItem(ctx, item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return combinedDraftFixture{ctx: ctx, store: dataStore, handler: NewHandler(dataStore, nil), admin: admin, annotator: annotator, reviewer: reviewer, task: task, item: item}
|
||||
f := combinedDraftFixture{ctx: ctx, store: dataStore, handler: NewHandler(dataStore, nil), admin: admin, annotator: annotator, reviewer: reviewer, task: task, item: item}
|
||||
completeFixtureSourceValidation(t, f, task)
|
||||
return f
|
||||
}
|
||||
|
||||
func (fixture combinedDraftFixture) request(method string, target string, user domain.UserRecord, body any) *httptest.ResponseRecorder {
|
||||
|
||||
@ -186,9 +186,10 @@ func RunAnnotationProcessor(ctx context.Context, db store.Store, cfg config.AppC
|
||||
}
|
||||
if readErr == nil && task != nil {
|
||||
_, readErr = s.annotationFrameTimelineForTask(indexCtx, *task, "left")
|
||||
// Legacy timeline jobs may predate this release. They must
|
||||
// not silently trigger full-media validation/source copies.
|
||||
if readErr == nil && (s.annotationSourceIndex && j.TaskID != "" || j.RevalidateSource) {
|
||||
// Queued legacy timeline jobs must also prove the full source,
|
||||
// not publish a weaker "completed" admission result. Already
|
||||
// completed records are not silently reset by this worker.
|
||||
if readErr == nil {
|
||||
run, err := db.GetRun(indexCtx, task.RunID)
|
||||
if err != nil {
|
||||
readErr = err
|
||||
@ -201,7 +202,7 @@ func RunAnnotationProcessor(ctx context.Context, db store.Store, cfg config.AppC
|
||||
} else {
|
||||
_, readErr = s.annotationSourceCertificate(indexCtx, *task, *run, key)
|
||||
if readErr == nil {
|
||||
j.SourceFingerprint = key
|
||||
j.SourceFingerprint, j.RevalidateSource = key, true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,6 +62,9 @@ func annotationProcessorFixture(t *testing.T) (combinedDraftFixture, string) {
|
||||
f.store.UpsertRun(f.ctx, domain.RunRecord{ID: task.RunID, OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, WorkflowID: task.WorkflowID, NodeExecutions: []domain.NodeExecutionRecord{{NodeID: task.NodeID, InputBindings: bindings}}})
|
||||
f.store.UpsertAnnotationTask(f.ctx, task)
|
||||
f.task = task
|
||||
if err := f.store.RetryAnnotationSourceValidation(f.ctx, task, true, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.handler = NewHandlerWithConfig(f.store, nil, config.AppConfig{WorkspaceMountPath: root})
|
||||
return f, root
|
||||
}
|
||||
|
||||
@ -7,10 +7,14 @@ import (
|
||||
"net/http"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func randomClaimFixture(t *testing.T, n int) combinedDraftFixture {
|
||||
func randomClaimFixture(t *testing.T, n int, sourceReady ...bool) combinedDraftFixture {
|
||||
f := newCombinedDraftFixture(t, "random-supplier")
|
||||
if n > 0 {
|
||||
completeFixtureSourceValidation(t, f, f.task)
|
||||
}
|
||||
supplier := domain.SupplierRecord{ID: "random-supplier", OrganizationID: domain.DefaultOrganizationID, Name: "Random vendor", Status: "active"}
|
||||
if e := f.store.UpsertSupplier(f.ctx, supplier); e != nil {
|
||||
t.Fatal(e)
|
||||
@ -33,6 +37,9 @@ func randomClaimFixture(t *testing.T, n int) combinedDraftFixture {
|
||||
if e := f.store.UpsertAnnotationTask(f.ctx, task); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(sourceReady) == 0 || sourceReady[0] {
|
||||
completeFixtureSourceValidation(t, f, task)
|
||||
}
|
||||
item := f.item
|
||||
item.ID = fmt.Sprintf("random-item-%d", i)
|
||||
item.LegacyTaskID = task.ID
|
||||
@ -47,6 +54,27 @@ func randomClaimFixture(t *testing.T, n int) combinedDraftFixture {
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
// Tests outside the source validator use an explicit synthetic complete proof,
|
||||
// rather than relying on the removed waiver for legacy/missing timeline jobs.
|
||||
func completeFixtureSourceValidation(t *testing.T, f combinedDraftFixture, task domain.AnnotationTaskRecord) {
|
||||
t.Helper()
|
||||
if current, err := f.store.GetAnnotationIndexJob(f.ctx, task.ID); err == nil && current != nil && current.Status == "completed" && current.SourceFingerprint != "" {
|
||||
return
|
||||
}
|
||||
if err := f.store.EnqueueAnnotationIndex(f.ctx, task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
job, err := f.store.ClaimAnnotationIndex(f.ctx, "fixture-validation", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
if err != nil || job == nil || job.ID != task.ID {
|
||||
t.Fatalf("expected fixture validation for %s: %+v %v", task.ID, job, err)
|
||||
}
|
||||
job.Status, job.SourceFingerprint = "completed", "fixture-full-source-"+task.ID
|
||||
if ok, err := f.store.FinishAnnotationIndex(f.ctx, *job); err != nil || !ok {
|
||||
t.Fatal("fixture validation completion", err)
|
||||
}
|
||||
}
|
||||
func claimRandom(t *testing.T, f combinedDraftFixture, requestID string) domain.HumanItemRecord {
|
||||
t.Helper()
|
||||
r := f.request(http.MethodPost, "/api/plugins/annotation-qa/random-claims", f.annotator, map[string]any{"projectId": f.task.ProjectID, "requestId": requestID})
|
||||
|
||||
@ -186,7 +186,9 @@ func (s *server) handleAnnotationSourceValidationRetry(w http.ResponseWriter, r
|
||||
renderJSON(w, 503, map[string]string{"error": "校验服务暂不可用"})
|
||||
return
|
||||
}
|
||||
verifySource := s.annotationSourceIndex
|
||||
// This endpoint explicitly repairs source validity, even on legacy physical
|
||||
// workflows where source-index materialization is disabled.
|
||||
verifySource := true
|
||||
supersededFingerprint := ""
|
||||
if item != nil && store.AnnotationSourceCertificateRequired(*item) {
|
||||
verifySource = true
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSourceValidationFailureBlocksRandomClaimWithoutLosingDraft(t *testing.T) {
|
||||
f := randomClaimFixture(t, 1)
|
||||
f := randomClaimFixture(t, 1, false)
|
||||
task, err := f.store.GetAnnotationTask(f.ctx, "random-task-0")
|
||||
if err != nil || task == nil {
|
||||
t.Fatal(err)
|
||||
@ -56,7 +56,7 @@ func TestSourceValidationFailureBlocksRandomClaimWithoutLosingDraft(t *testing.T
|
||||
}
|
||||
|
||||
func TestPendingSourceValidationIsNotAssigned(t *testing.T) {
|
||||
f := randomClaimFixture(t, 1)
|
||||
f := randomClaimFixture(t, 1, false)
|
||||
task, _ := f.store.GetAnnotationTask(f.ctx, "random-task-0")
|
||||
task.SourceIsFullVideo, task.TemplateVersion, task.ArtifactID = true, 5, "source-left"
|
||||
if err := f.store.UpsertAnnotationTask(f.ctx, *task); err != nil {
|
||||
@ -68,7 +68,7 @@ func TestPendingSourceValidationIsNotAssigned(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSourceValidationRetryRequiresAdminAndResumesOnlyAfterPass(t *testing.T) {
|
||||
f := randomClaimFixture(t, 1)
|
||||
f := randomClaimFixture(t, 1, false)
|
||||
task, _ := f.store.GetAnnotationTask(f.ctx, "random-task-0")
|
||||
task.SourceIsFullVideo, task.TemplateVersion, task.ArtifactID = true, 5, "source-left"
|
||||
if e := f.store.UpsertAnnotationTask(f.ctx, *task); e != nil {
|
||||
@ -111,7 +111,7 @@ func TestSourceValidationRetryRequiresAdminAndResumesOnlyAfterPass(t *testing.T)
|
||||
if e != nil || replacement == nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
replacement.Status, replacement.Error = "completed", ""
|
||||
replacement.Status, replacement.Error, replacement.SourceFingerprint = "completed", "", "validated-source"
|
||||
if ok, e := f.store.FinishAnnotationIndex(f.ctx, *replacement); !ok || e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
@ -125,6 +125,9 @@ func TestSourceValidationStatusIsSafeSpecificAndPreservesOwnedTask(t *testing.T)
|
||||
task := f.task
|
||||
task.SourceIsFullVideo, task.ArtifactID = true, "source-left"
|
||||
f.store.UpsertAnnotationTask(f.ctx, task)
|
||||
if err := f.store.RetryAnnotationSourceValidation(f.ctx, task, true, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
job, _ := f.store.ClaimAnnotationIndex(f.ctx, "validator", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
job.Status, job.Error = "failed", `IMU CSV /private/credential-root/imu.csv invalid type "gyr" at row 418451`
|
||||
@ -149,12 +152,12 @@ func TestSourceValidationStatusIsSafeSpecificAndPreservesOwnedTask(t *testing.T)
|
||||
}
|
||||
|
||||
func TestCurrentPreparedSourceFailureBlocksClaimAfterTimelinePass(t *testing.T) {
|
||||
f := randomClaimFixture(t, 1)
|
||||
f := randomClaimFixture(t, 1, false)
|
||||
task, _ := f.store.GetAnnotationTask(f.ctx, "random-task-0")
|
||||
f.store.EnqueueAnnotationIndex(f.ctx, *task)
|
||||
now := time.Now().UTC()
|
||||
job, _ := f.store.ClaimAnnotationIndex(f.ctx, "timeline", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
job.Status = "completed"
|
||||
job.Status, job.SourceFingerprint = "completed", "validated-source"
|
||||
f.store.FinishAnnotationIndex(f.ctx, *job)
|
||||
f.store.EnqueueAnnotationSourceIndex(f.ctx, *task, "current-source", false)
|
||||
job, _ = f.store.ClaimAnnotationIndex(f.ctx, "source", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
@ -171,17 +174,17 @@ func TestCurrentPreparedSourceFailureBlocksClaimAfterTimelinePass(t *testing.T)
|
||||
f.store.UpsertHumanItem(f.ctx, *item)
|
||||
f.store.EnqueueAnnotationSourceIndex(f.ctx, *task, "repaired-source", false)
|
||||
job, _ = f.store.ClaimAnnotationIndex(f.ctx, "repaired", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
job.Status = "completed"
|
||||
job.Status, job.SourceFingerprint = "completed", "repaired-source"
|
||||
f.store.FinishAnnotationIndex(f.ctx, *job)
|
||||
if got := claimRandom(t, f, "prepared-passed-0001"); got.ID != "random-item-0" {
|
||||
t.Fatal("stale source failure poisoned repaired task")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceValidationLegacyWithoutJobKeepsExistingEligibility(t *testing.T) {
|
||||
f := randomClaimFixture(t, 1)
|
||||
if got := claimRandom(t, f, "legacy-source-000001"); got.ID != "random-item-0" {
|
||||
t.Fatal("unrelated legacy task blocked")
|
||||
func TestSourceValidationLegacyWithoutJobCannotBeClaimed(t *testing.T) {
|
||||
f := randomClaimFixture(t, 1, false)
|
||||
if got := claimRandom(t, f, "legacy-source-000001"); got.ID != "" {
|
||||
t.Fatal("legacy task without complete proof was admitted")
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,12 +291,12 @@ func TestSourceRepairRevalidatesChangedFilesWithoutReusingFailedCertificateID(t
|
||||
}
|
||||
|
||||
func TestRequiredSourceCertificateCannotBeMissing(t *testing.T) {
|
||||
f := randomClaimFixture(t, 1)
|
||||
f := randomClaimFixture(t, 1, false)
|
||||
task, _ := f.store.GetAnnotationTask(f.ctx, "random-task-0")
|
||||
f.store.EnqueueAnnotationIndex(f.ctx, *task)
|
||||
now := time.Now().UTC()
|
||||
job, _ := f.store.ClaimAnnotationIndex(f.ctx, "timeline", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
job.Status = "completed"
|
||||
job.Status, job.SourceFingerprint = "completed", "validated-source"
|
||||
f.store.FinishAnnotationIndex(f.ctx, *job)
|
||||
item, _ := f.store.GetHumanItem(f.ctx, "random-item-0")
|
||||
item.ProcessingJob = &domain.AnnotationProcessingJob{SourceFingerprint: "not-enqueued-yet", SourceIndex: true}
|
||||
@ -312,7 +315,7 @@ func TestSourceFailureDetectedAfterPriorSuccessRevokesAdmission(t *testing.T) {
|
||||
f, root := annotationProcessorFixture(t)
|
||||
now := time.Now().UTC()
|
||||
job, _ := f.store.ClaimAnnotationIndex(f.ctx, "old-valid", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
job.Status = "completed"
|
||||
job.Status, job.SourceFingerprint = "completed", "validated-source"
|
||||
f.store.FinishAnnotationIndex(f.ctx, *job)
|
||||
path := filepath.Join(root, "imu.csv")
|
||||
b, _ := os.ReadFile(path)
|
||||
@ -343,7 +346,7 @@ func TestSourceValidationCanceledTimelineDoesNotQuarantineSource(t *testing.T) {
|
||||
if err != nil || job == nil {
|
||||
t.Fatal("validation job missing", err)
|
||||
}
|
||||
job.Status = "completed"
|
||||
job.Status, job.SourceFingerprint = "completed", "validated-source"
|
||||
if ok, err := f.store.FinishAnnotationIndex(f.ctx, *job); !ok || err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -375,10 +378,11 @@ func TestSourceValidationRejectsNonFiniteIMUSamples(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceValidationKnownInvalidLegacySourceCanRecoverWithoutLosingWork(t *testing.T) {
|
||||
func TestSourceValidationUnverifiedLegacySourceCanRecoverWithoutLosingWork(t *testing.T) {
|
||||
t.Setenv("ANNOTATION_PROCESSOR_MODE", "external")
|
||||
t.Setenv("ANNOTATION_PROCESSOR_ROLE", "validation")
|
||||
f, root := annotationProcessorFixture(t)
|
||||
completeFixtureSourceValidation(t, f, f.task)
|
||||
f.task.ID, f.task.TemplateVersion = "legacy-source-task", 4
|
||||
f.item.ID, f.item.LegacyTaskID = "legacy-source-item", f.task.ID
|
||||
f.item.Subject.ItemKey = "legacy-source"
|
||||
@ -389,8 +393,14 @@ func TestSourceValidationKnownInvalidLegacySourceCanRecoverWithoutLosingWork(t *
|
||||
if err := f.store.UpsertHumanItem(f.ctx, f.item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if job, err := f.store.GetAnnotationIndexJob(f.ctx, f.task.ID); err != nil || job != nil {
|
||||
t.Fatal("legacy task unexpectedly requires validation", err)
|
||||
now := time.Now().UTC()
|
||||
weak, err := f.store.ClaimAnnotationIndex(f.ctx, "legacy-timeline", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
if err != nil || weak == nil || weak.ID != f.task.ID {
|
||||
t.Fatal("missing legacy fixture", err)
|
||||
}
|
||||
weak.Status, weak.RevalidateSource, weak.SourceFingerprint = "completed", false, ""
|
||||
if ok, err := f.store.FinishAnnotationIndex(f.ctx, *weak); !ok || err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
read := func(ctx context.Context, user domain.UserRecord, org string) *httptest.ResponseRecorder {
|
||||
ctx = context.WithValue(ctx, authContextKey{}, &authenticatedPrincipal{User: user, Organization: domain.OrganizationRecord{ID: org, Status: domain.OrganizationStatusActive}})
|
||||
@ -401,7 +411,7 @@ func TestSourceValidationKnownInvalidLegacySourceCanRecoverWithoutLosingWork(t *
|
||||
}
|
||||
canceled, cancelRead := context.WithCancel(f.ctx)
|
||||
cancelRead()
|
||||
if response := read(canceled, f.admin, f.task.OrganizationID); response.Code != 503 {
|
||||
if response := read(canceled, f.admin, f.task.OrganizationID); response.Code != 422 {
|
||||
t.Fatalf("canceled legacy read: %d %s", response.Code, response.Body.String())
|
||||
}
|
||||
foreign := f.admin
|
||||
@ -409,8 +419,8 @@ func TestSourceValidationKnownInvalidLegacySourceCanRecoverWithoutLosingWork(t *
|
||||
if response := read(f.ctx, foreign, foreign.OrganizationID); response.Code != 403 && response.Code != 404 {
|
||||
t.Fatalf("cross-organization legacy read allowed: %d", response.Code)
|
||||
}
|
||||
if job, err := f.store.GetAnnotationIndexJob(f.ctx, f.task.ID); err != nil || job != nil {
|
||||
t.Fatal("canceled/unauthorized read quarantined legacy source", err)
|
||||
if job, err := f.store.GetAnnotationIndexJob(f.ctx, f.task.ID); err != nil || job == nil || job.Status != "completed" || job.SourceFingerprint != "" {
|
||||
t.Fatal("canceled/unauthorized read changed legacy source", err)
|
||||
}
|
||||
path := filepath.Join(root, "imu.csv")
|
||||
original, err := os.ReadFile(path)
|
||||
@ -421,12 +431,12 @@ func TestSourceValidationKnownInvalidLegacySourceCanRecoverWithoutLosingWork(t *
|
||||
t.Fatal(err)
|
||||
}
|
||||
response := f.request(http.MethodGet, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/frame-timeline", f.admin, nil)
|
||||
if response.Code != 422 || !strings.Contains(response.Body.String(), `"retryAllowed":true`) || !strings.Contains(response.Body.String(), "gyr") {
|
||||
if response.Code != 422 || !strings.Contains(response.Body.String(), `"retryAllowed":true`) || !strings.Contains(response.Body.String(), "source_validation_unverified") {
|
||||
t.Fatalf("known bad legacy source has no recovery: %d %s", response.Code, response.Body.String())
|
||||
}
|
||||
job, err := f.store.GetAnnotationIndexJob(f.ctx, f.task.ID)
|
||||
if err != nil || job == nil || job.Status != "failed" {
|
||||
t.Fatalf("legacy source failure not durable: %+v %v", job, err)
|
||||
if err != nil || job == nil || job.Status != "completed" || job.SourceFingerprint != "" {
|
||||
t.Fatalf("unverified legacy read mutated validation state: %+v %v", job, err)
|
||||
}
|
||||
response = f.request(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/source-validation-retries", f.annotator, map[string]any{"sourceRepaired": true})
|
||||
if response.Code != 403 {
|
||||
@ -471,33 +481,8 @@ func TestSourceValidationKnownInvalidLegacySourceCanRecoverWithoutLosingWork(t *
|
||||
if err := f.store.UpsertHumanItem(f.ctx, *item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
response = f.request(http.MethodGet, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/frame-timeline", f.admin, nil)
|
||||
if response.Code != 422 || !strings.Contains(response.Body.String(), "source_validation_unverified") {
|
||||
t.Fatalf("historical source marker without proof admitted: %d %s", response.Code, response.Body.String())
|
||||
}
|
||||
response = f.request(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/source-validation-retries", f.admin, map[string]any{"sourceRepaired": true})
|
||||
if response.Code != 202 {
|
||||
t.Fatal(response.Code, response.Body.String())
|
||||
}
|
||||
deadline = time.Now().Add(10 * time.Second)
|
||||
for {
|
||||
job, err = f.store.GetAnnotationIndexJob(f.ctx, f.task.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if job.Status == "completed" {
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("payload-only validation did not finish: %+v", job)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
if !job.RevalidateSource || job.SourceFingerprint == "" || job.SupersededSourceFingerprint != "" {
|
||||
t.Fatalf("missing identity-bound historical proof: %+v", job)
|
||||
}
|
||||
response = f.request(http.MethodGet, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/frame-timeline", f.annotator, nil)
|
||||
if response.Code != 200 {
|
||||
t.Fatalf("validated payload-only source remained blocked: %d %s", response.Code, response.Body.String())
|
||||
t.Fatalf("complete current proof was not reusable: %d %s", response.Code, response.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
143
internal/api/annotation_source_full_admission_test.go
Normal file
143
internal/api/annotation_source_full_admission_test.go
Normal file
@ -0,0 +1,143 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"droboticflow/internal/config"
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
func TestSourceValidationFullProofPrecedesLegacyClaimAndPreservesOwnedWork(t *testing.T) {
|
||||
for _, owned := range []bool{false, true} {
|
||||
t.Run(map[bool]string{true: "owned", false: "unclaimed"}[owned], func(t *testing.T) {
|
||||
t.Setenv("ANNOTATION_PROCESSOR_MODE", "external")
|
||||
t.Setenv("ANNOTATION_PROCESSOR_ROLE", "validation")
|
||||
f, root := annotationProcessorFixture(t)
|
||||
f.item.Subject.Payload["annotationWorkspace"] = map[string]any{
|
||||
"sliceSegments": []domain.SliceSegment{{ID: "retained-slice", Name: "测试切片", Start: 0, End: 4}},
|
||||
"segments": []domain.AnnotationSegment{{ID: "retained-action", Start: 0, End: 4, Description: "保留的人工标注", Status: "described"}},
|
||||
"userId": f.annotator.ID, "savedAt": nowISO(),
|
||||
}
|
||||
f.item.Subject.Payload["annotationDraft"] = map[string]any{
|
||||
"sliceSegments": []domain.SliceSegment{{ID: "retained-slice", Name: "测试切片", Start: 0, End: 4}},
|
||||
"segments": []domain.AnnotationSegment{{ID: "newer-draft", Start: 0, End: 4, Description: "较新的本地保存内容", Status: "described"}},
|
||||
"userId": f.annotator.ID, "savedAt": nowISO(),
|
||||
}
|
||||
if !owned {
|
||||
f.item.Status, f.item.AssignedUserID = domain.HumanItemReady, ""
|
||||
}
|
||||
if err := f.store.UpsertHumanItem(f.ctx, f.item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
||||
originals := map[string][]byte{}
|
||||
// Remove the matching frame and hardware timestamp from both eyes.
|
||||
// Counts still match, and a hardware-time gap is legal; only the
|
||||
// complete media-clock check catches the retained presentation gap.
|
||||
for _, side := range []string{"left", "right"} {
|
||||
path := filepath.Join(root, side+".mp4")
|
||||
pts := filepath.Join(root, side+"_pts.csv")
|
||||
for _, name := range []string{path, pts} {
|
||||
body, err := os.ReadFile(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
originals[name] = body
|
||||
}
|
||||
if out, err := exec.Command("ffmpeg", "-v", "error", "-y", "-f", "lavfi", "-i", "testsrc2=s=64x48:r=8:d=4", "-vf", "select=not(eq(n\\,16))", "-fps_mode", "vfr", "-c:v", "libx264", "-pix_fmt", "yuv420p", path).CombinedOutput(); err != nil {
|
||||
t.Fatalf("damaged fixture: %v %s", err, out)
|
||||
}
|
||||
if err := os.WriteFile(pts, []byte(strings.Replace(string(originals[pts]), "3000000\n", "", 1)), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
engine := &server{store: f.store, workspaceMountPath: root}
|
||||
if _, err := engine.annotationFrameTimelineForTask(f.ctx, f.task, "left"); err != nil {
|
||||
t.Fatalf("fixture did not reach the weaker legacy timeline path: %v", err)
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
old, err := f.store.ClaimAnnotationIndex(f.ctx, "legacy-validator", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
if err != nil || old == nil {
|
||||
t.Fatal("missing validation fixture", err)
|
||||
}
|
||||
old.Status, old.RevalidateSource, old.SourceFingerprint, old.Attempt = "queued", false, "", 4
|
||||
if ok, err := f.store.FinishAnnotationIndex(f.ctx, *old); !ok || err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// A fresh processor instance must finish the actual source check,
|
||||
// including old queued records without the new validation flag.
|
||||
runUntil := func(want string) {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
done <- RunAnnotationProcessor(ctx, f.store, config.AppConfig{WorkspaceMountPath: root}, 1, false)
|
||||
}()
|
||||
defer func() { cancel(); <-done }()
|
||||
deadline := time.Now().Add(8 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
job, err := f.store.GetAnnotationIndexJob(f.ctx, f.task.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if job.Status == want {
|
||||
return
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
t.Fatalf("validation did not reach %s", want)
|
||||
}
|
||||
runUntil("failed")
|
||||
job, _ := f.store.GetAnnotationIndexJob(f.ctx, f.task.ID)
|
||||
if job.Error == "" || job.SourceFingerprint != "" {
|
||||
t.Fatal("invalid source published a success proof")
|
||||
}
|
||||
if got := claimRandom(t, f, "full-source-failed-01"); got.ID != "" {
|
||||
t.Fatal("failed source reached a new annotator")
|
||||
}
|
||||
after, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
||||
if !reflect.DeepEqual(before, after) {
|
||||
t.Fatal("failed validation/claim changed saved annotations or ownership")
|
||||
}
|
||||
for path, original := range originals {
|
||||
if err := os.WriteFile(path, original, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
r := f.request(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/source-validation-retries", f.admin, map[string]any{"sourceRepaired": true})
|
||||
if r.Code != 202 {
|
||||
t.Fatalf("repair: %d %s", r.Code, r.Body.String())
|
||||
}
|
||||
runUntil("completed")
|
||||
job, _ = f.store.GetAnnotationIndexJob(f.ctx, f.task.ID)
|
||||
if job.SourceFingerprint == "" || !job.RevalidateSource {
|
||||
t.Fatal("complete validation did not publish identity-bound proof")
|
||||
}
|
||||
after, _ = f.store.GetHumanItem(f.ctx, f.item.ID)
|
||||
if !reflect.DeepEqual(before, after) {
|
||||
t.Fatal("repair overwrote annotation/workspace/draft/ownership")
|
||||
}
|
||||
r = f.request(http.MethodGet, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"?view=status", f.admin, nil)
|
||||
var status struct {
|
||||
SourceValidation annotationSourceValidation `json:"sourceValidation"`
|
||||
}
|
||||
if r.Code != 200 || json.Unmarshal(r.Body.Bytes(), &status) != nil || status.SourceValidation.Status != "valid" {
|
||||
t.Fatalf("invalid repaired status: %d %s", r.Code, r.Body.String())
|
||||
}
|
||||
if !owned {
|
||||
if got := claimRandom(t, f, "full-source-passed-01"); got.ID != f.item.ID {
|
||||
t.Fatal("fully verified task could not be claimed")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -71,7 +71,7 @@ func TestSourceIndexColdValidationDoesNotFailOrOccupyRevisionWorker(t *testing.T
|
||||
t.Fatal("deferred task did not resume after validation/restart")
|
||||
}
|
||||
|
||||
func TestSourceIndexLegacyTimelineQueueDoesNotBackfillSourceCopies(t *testing.T) {
|
||||
func TestSourceIndexLegacyTimelineQueueRequiresCompleteSourceProof(t *testing.T) {
|
||||
t.Setenv("ANNOTATION_SOURCE_INDEX", "true")
|
||||
t.Setenv("ANNOTATION_PROCESSOR_ROLE", "validation")
|
||||
f, root := annotationProcessorFixture(t)
|
||||
@ -88,8 +88,8 @@ func TestSourceIndexLegacyTimelineQueueDoesNotBackfillSourceCopies(t *testing.T)
|
||||
t.Fatal(err)
|
||||
}
|
||||
if job != nil && job.Status == "completed" {
|
||||
if _, err := os.Stat(filepath.Join(root, "system", "runs", f.task.RunID, "annotation-sources")); !os.IsNotExist(err) {
|
||||
t.Fatal("legacy timeline job triggered source-copy backfill", err)
|
||||
if _, err := os.Stat(filepath.Join(root, "system", "runs", f.task.RunID, "annotation-sources")); err != nil || job.SourceFingerprint == "" {
|
||||
t.Fatal("queued legacy job published no complete source proof", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -87,6 +87,7 @@ func TestSourceValidationBrowserReplica(t *testing.T) {
|
||||
commandCtx, done := context.WithTimeout(t.Context(), 3*time.Minute)
|
||||
defer done()
|
||||
cmd := exec.CommandContext(commandCtx, "node", "tests/browser/annotation-source-validation-replica.mjs")
|
||||
cmd.WaitDelay = 5 * time.Second
|
||||
cmd.Dir = "../.."
|
||||
cmd.Env = append(os.Environ(), "SOURCE_VALIDATION_API="+api.URL)
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
||||
@ -21,6 +21,9 @@ func TestWorkBufferRetainsFailedSourceAndRefreshesRecovery(t *testing.T) {
|
||||
if err := f.store.UpsertAnnotationTask(f.ctx, *task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := f.store.RetryAnnotationSourceValidation(f.ctx, *task, true, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
||||
now := time.Now().UTC()
|
||||
job, err := f.store.ClaimAnnotationIndex(f.ctx, "buffer-validator", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
||||
@ -64,7 +67,7 @@ func TestWorkBufferRetainsFailedSourceAndRefreshesRecovery(t *testing.T) {
|
||||
if err != nil || job == nil {
|
||||
t.Fatal("missing repair", err)
|
||||
}
|
||||
job.Status, job.Error = "completed", ""
|
||||
job.Status, job.Error, job.SourceFingerprint = "completed", "", "repaired-full-source"
|
||||
if ok, err := f.store.FinishAnnotationIndex(f.ctx, *job); !ok || err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ func inheritedReworkFixture(t *testing.T, n int) (combinedDraftFixture, []string
|
||||
if err := f.store.UpsertAnnotationTask(f.ctx, task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
completeFixtureSourceValidation(t, f, task)
|
||||
item := f.item
|
||||
item.ID = fmt.Sprintf("inherited-item-%d", i)
|
||||
item.LegacyTaskID = task.ID
|
||||
@ -146,6 +147,7 @@ func TestDeletedAuthorReworkDoesNotBlockOrdinaryClaim(t *testing.T) {
|
||||
if err := f.store.UpsertAnnotationTask(f.ctx, task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
completeFixtureSourceValidation(t, f, task)
|
||||
item := f.item
|
||||
item.ID = "fresh-item"
|
||||
item.LegacyTaskID = task.ID
|
||||
@ -213,6 +215,7 @@ func TestDeletedAuthorReworkLegacyFormalRevisionFallback(t *testing.T) {
|
||||
if err := f.store.UpsertAnnotationTask(f.ctx, task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
completeFixtureSourceValidation(t, f, task)
|
||||
item := f.item
|
||||
item.ID = "legacy-reviewed-item"
|
||||
item.LegacyTaskID = task.ID
|
||||
|
||||
@ -74,6 +74,7 @@ func newFanyuV5FourStageFixture(t *testing.T, stageID string, status domain.Huma
|
||||
if err := dataStore.UpsertAnnotationTask(ctx, task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
completeFixtureSourceValidation(t, combinedDraftFixture{ctx: ctx, store: dataStore}, task)
|
||||
item := domain.HumanItemRecord{
|
||||
ID: "item-v5-four-stage", OrganizationID: domain.DefaultOrganizationID, PluginID: "annotation-qa", BatchID: batch.ID,
|
||||
ProjectID: batch.ProjectID, WorkflowID: batch.WorkflowID, RunID: batch.RunID, GateNodeID: batch.GateNodeID,
|
||||
|
||||
@ -160,6 +160,14 @@ func TestPoolPerformanceCountMatchesExistingMembershipPredicate(t *testing.T) {
|
||||
if internal {
|
||||
candidate.ProcessingScope = "internal"
|
||||
}
|
||||
// Keep this authorization equivalence fixture source-valid so it
|
||||
// measures membership independently of the source admission gate.
|
||||
validatedTask := f.task
|
||||
validatedTask.ID = candidate.LegacyTaskID
|
||||
if err := f.store.UpsertAnnotationTask(f.ctx, validatedTask); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
completeFixtureSourceValidation(t, f, validatedTask)
|
||||
if err := f.store.UpsertHumanItem(f.ctx, candidate); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -40,6 +40,7 @@ func TestFanyuCaptureClaimBindsAnnotatorSupplierAtomically(t *testing.T) {
|
||||
if err := dataStore.UpsertAnnotationTask(ctx, task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
completeFixtureSourceValidation(t, combinedDraftFixture{ctx: ctx, store: dataStore}, task)
|
||||
item := domain.HumanItemRecord{ID: "item-capture-claim", OrganizationID: organization.ID, PluginID: "annotation-qa", BatchID: batch.ID, ProjectID: project.ID, WorkflowID: batch.WorkflowID, RunID: batch.RunID, LegacyTaskID: task.ID, CurrentStageID: domain.FanyuV58StageAnnotationCombined, Status: domain.HumanItemReady, Version: 1}
|
||||
if err := dataStore.UpsertHumanItem(ctx, item); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@ -37,11 +37,11 @@ func TestAdminAnnotationPoolMongoMetadataLimitAndCursor(t *testing.T) {
|
||||
}
|
||||
items = append(items, item)
|
||||
tasks = append(tasks, domain.AnnotationTaskRecord{ID: item.LegacyTaskID, OrganizationID: org, SourceIsFullVideo: true, TemplateVersion: 6, ArtifactID: "video"})
|
||||
status := "failed"
|
||||
status, fingerprint := "failed", ""
|
||||
if n >= 224 {
|
||||
status = "completed"
|
||||
status, fingerprint = "completed", "fixture-full-source-"+item.LegacyTaskID
|
||||
}
|
||||
jobs = append(jobs, domain.AnnotationIndexJob{ID: item.LegacyTaskID, OrganizationID: org, Status: status})
|
||||
jobs = append(jobs, domain.AnnotationIndexJob{ID: item.LegacyTaskID, OrganizationID: org, Status: status, SourceFingerprint: fingerprint})
|
||||
}
|
||||
for name, rows := range map[string][]any{"humanItems": items, "annotationTasks": tasks, "annotationIndexJobs": jobs} {
|
||||
if _, err := s.db.Collection(name).InsertMany(ctx, rows); err != nil {
|
||||
|
||||
@ -26,8 +26,9 @@ func testAdminSourceExceptions(t *testing.T, s Store) {
|
||||
name, timeline, fingerprint, source, superseded, want string
|
||||
modern, revalidate bool
|
||||
}{
|
||||
{name: "legacy"},
|
||||
{name: "legacy", want: "unverified"},
|
||||
{name: "valid", modern: true, timeline: "completed"},
|
||||
{name: "timeline-only", modern: true, timeline: "completed", want: "unverified"},
|
||||
{name: "failed", modern: true, timeline: "failed", want: "failed"},
|
||||
{name: "pending", modern: true, timeline: "queued", want: "pending"},
|
||||
{name: "missing", modern: true, want: "unverified"},
|
||||
@ -48,7 +49,7 @@ func testAdminSourceExceptions(t *testing.T, s Store) {
|
||||
case *MemoryStore:
|
||||
st.annotationIndexJobs[job.ID] = job
|
||||
case *MongoStore:
|
||||
if err := mongoUpsert(ctx, st.db.Collection("annotationIndexJobs"), job.ID, job); err != nil {
|
||||
if _, err := st.db.Collection("annotationIndexJobs").ReplaceOne(ctx, bson.M{"id": job.ID}, job, options.Replace().SetUpsert(true)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -83,7 +84,7 @@ func testAdminSourceExceptions(t *testing.T, s Store) {
|
||||
j.Status = sc.timeline
|
||||
j.RevalidateSource = sc.revalidate
|
||||
j.SupersededSourceFingerprint = fp(sc.superseded)
|
||||
if sc.revalidate {
|
||||
if (sc.timeline == "completed" || sc.revalidate) && sc.name != "timeline-only" {
|
||||
j.SourceFingerprint = fp("B")
|
||||
}
|
||||
writeJob(j)
|
||||
@ -100,7 +101,7 @@ func testAdminSourceExceptions(t *testing.T, s Store) {
|
||||
if sc.source != "" {
|
||||
j := annotationIndexJob(task)
|
||||
j.ID = AnnotationSourceJobID(org, fp(sc.fingerprint))
|
||||
j.Status = sc.source
|
||||
j.Status, j.SourceFingerprint = sc.source, fp(sc.fingerprint)
|
||||
writeJob(j)
|
||||
}
|
||||
wantStatuses[id] = sc.want
|
||||
|
||||
@ -47,6 +47,12 @@ func TestSourceAdmissionMongoClaimReadPlan(t *testing.T) {
|
||||
}
|
||||
}
|
||||
base := bson.M{"organizationId": "org", "projectId": "project", "pluginId": "annotation-qa", "legacyTaskId": "legacy", "assignedUserId": "", "status": "ready", "supplierId": "vendor"}
|
||||
if _, err := db.Collection("annotationTasks").InsertOne(ctx, domain.AnnotationTaskRecord{ID: "legacy", OrganizationID: "org", ProjectID: "project"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := db.Collection("annotationIndexJobs").InsertOne(ctx, domain.AnnotationIndexJob{ID: "legacy", OrganizationID: "org", ProjectID: "project", Status: "completed", SourceFingerprint: "fixture-complete-proof"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
docs := []any{}
|
||||
for _, name := range []string{"valid", "rework", "assigned", "foreign-supplier", "internal-unbound", "missing-task", "foreign-project"} {
|
||||
d := bson.M{}
|
||||
|
||||
@ -318,7 +318,7 @@ func (store *MemoryStore) upsertAnnotationTaskLocked(item domain.AnnotationTaskR
|
||||
}
|
||||
item.UpdatedAt = now
|
||||
store.annotationTasks[item.ID] = item
|
||||
if item.SourceIsFullVideo && item.TemplateVersion >= 5 && item.ArtifactID != "" {
|
||||
if AnnotationSourceValidationRequired(item) {
|
||||
if store.annotationIndexJobs == nil {
|
||||
store.annotationIndexJobs = map[string]domain.AnnotationIndexJob{}
|
||||
}
|
||||
@ -873,7 +873,7 @@ func (store *MongoStore) UpsertAnnotationTask(ctx context.Context, item domain.A
|
||||
if err := upsertAnnotationEpoch(ctx, store.annotationTasks, item.ID, item, item.AnnotationEpoch); err != nil {
|
||||
return err
|
||||
}
|
||||
if item.SourceIsFullVideo && item.TemplateVersion >= 5 && item.ArtifactID != "" {
|
||||
if AnnotationSourceValidationRequired(item) {
|
||||
if err := store.EnqueueAnnotationIndex(ctx, item); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ func (s *MongoStore) PutAnnotationTimelineIndex(ctx context.Context, v domain.An
|
||||
}
|
||||
|
||||
func annotationIndexJob(t domain.AnnotationTaskRecord) domain.AnnotationIndexJob {
|
||||
return domain.AnnotationIndexJob{ID: t.ID, OrganizationID: t.OrganizationID, ProjectID: t.ProjectID, WorkflowID: t.WorkflowID, RunID: t.RunID, Status: "queued", CreatedAt: nowISO(), NextAttemptAt: ""}
|
||||
return domain.AnnotationIndexJob{ID: t.ID, OrganizationID: t.OrganizationID, ProjectID: t.ProjectID, WorkflowID: t.WorkflowID, RunID: t.RunID, RevalidateSource: true, Status: "queued", CreatedAt: nowISO(), NextAttemptAt: ""}
|
||||
}
|
||||
func (s *MemoryStore) EnqueueAnnotationIndex(_ context.Context, t domain.AnnotationTaskRecord) error {
|
||||
s.mu.Lock()
|
||||
|
||||
@ -12,16 +12,18 @@ import (
|
||||
|
||||
var ErrSourceValidationActive = errors.New("source validation is already running")
|
||||
|
||||
func AnnotationSourceValidationRequired(task domain.AnnotationTaskRecord) bool {
|
||||
return task.SourceIsFullVideo && task.TemplateVersion >= 5 && task.ArtifactID != ""
|
||||
func AnnotationSourceValidationRequired(_ domain.AnnotationTaskRecord) bool {
|
||||
// Legacy flags and template versions are not evidence of source validity.
|
||||
// Keep old records readable, but never use missing metadata as a claim waiver.
|
||||
return true
|
||||
}
|
||||
|
||||
func AnnotationSourceJobsReady(task domain.AnnotationTaskRecord, timeline, source *domain.AnnotationIndexJob) bool {
|
||||
if timeline == nil && AnnotationSourceValidationRequired(task) {
|
||||
if timeline == nil || timeline.SourceFingerprint == "" {
|
||||
return false
|
||||
}
|
||||
for _, job := range []*domain.AnnotationIndexJob{timeline, source} {
|
||||
if job != nil && (job.Status != "completed" || job.OrganizationID != task.OrganizationID || job.ProjectID != task.ProjectID || job.RunID != task.RunID) {
|
||||
if job != nil && (job.Status != "completed" || job.SourceFingerprint == "" || job.OrganizationID != task.OrganizationID || job.ProjectID != task.ProjectID || job.RunID != task.RunID) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -61,6 +63,9 @@ func AnnotationItemSourceJobsReady(task domain.AnnotationTaskRecord, item domain
|
||||
return true
|
||||
}
|
||||
}
|
||||
if source != nil && item.ProcessingJob != nil && source.SourceFingerprint != item.ProcessingJob.SourceFingerprint {
|
||||
return false
|
||||
}
|
||||
if AnnotationSourceCertificateRequired(item) && source == nil {
|
||||
if !annotationSourceHasCurrentProof(item, timeline) {
|
||||
return false
|
||||
@ -79,8 +84,8 @@ func sourceJobForItem(item domain.HumanItemRecord) string {
|
||||
func (s *MemoryStore) annotationSourceReadyLocked(item domain.HumanItemRecord) bool {
|
||||
task, exists := s.annotationTasks[item.LegacyTaskID]
|
||||
if !exists {
|
||||
return true
|
||||
} // Existing claim validation rejects a missing task.
|
||||
return item.LegacyTaskID == ""
|
||||
}
|
||||
var timeline, source *domain.AnnotationIndexJob
|
||||
if job, ok := s.annotationIndexJobs[task.ID]; ok {
|
||||
timeline = &job
|
||||
@ -107,6 +112,9 @@ func (s *MongoStore) annotationSourceReady(ctx context.Context, item domain.Huma
|
||||
}
|
||||
|
||||
func AnnotationSourceAdmissionStatus(task domain.AnnotationTaskRecord, item domain.HumanItemRecord, timeline, source *domain.AnnotationIndexJob) string {
|
||||
if task.ID == "" {
|
||||
return "unverified"
|
||||
}
|
||||
if AnnotationSourceJobSuperseded(item, timeline) {
|
||||
source = nil
|
||||
}
|
||||
@ -118,8 +126,16 @@ func AnnotationSourceAdmissionStatus(task domain.AnnotationTaskRecord, item doma
|
||||
return "failed"
|
||||
}
|
||||
}
|
||||
for _, job := range []*domain.AnnotationIndexJob{timeline, source} {
|
||||
if job != nil && job.Status == "completed" && job.SourceFingerprint == "" {
|
||||
return "unverified"
|
||||
}
|
||||
}
|
||||
if source != nil && item.ProcessingJob != nil && source.SourceFingerprint != item.ProcessingJob.SourceFingerprint {
|
||||
return "unverified"
|
||||
}
|
||||
currentProof := annotationSourceHasCurrentProof(item, timeline)
|
||||
if timeline == nil && AnnotationSourceValidationRequired(task) || timeline != nil && timeline.RevalidateSource && timeline.Status == "completed" && timeline.SourceFingerprint == "" || !currentProof && !AnnotationSourceJobSuperseded(item, timeline) && AnnotationSourceCertificateRequired(item) && source == nil {
|
||||
if timeline == nil || timeline.Status == "completed" && timeline.SourceFingerprint == "" || !currentProof && !AnnotationSourceJobSuperseded(item, timeline) && AnnotationSourceCertificateRequired(item) && source == nil {
|
||||
return "unverified"
|
||||
}
|
||||
return "pending"
|
||||
@ -130,7 +146,6 @@ func AnnotationSourceAdmissionStatus(task domain.AnnotationTaskRecord, item doma
|
||||
func annotationSourceAdmissionStatusPipeline() mongo.Pipeline {
|
||||
first := func(path string) bson.M { return bson.M{"$arrayElemAt": bson.A{path, 0}} }
|
||||
nonempty := func(v any) bson.M { return bson.M{"$ne": bson.A{bson.M{"$ifNull": bson.A{v, ""}}, ""}} }
|
||||
needsTimeline := bson.M{"$and": bson.A{bson.M{"$eq": bson.A{first("$_sourceTask.sourceIsFullVideo"), true}}, bson.M{"$gte": bson.A{first("$_sourceTask.templateVersion"), 5}}, nonempty(first("$_sourceTask.artifactId"))}}
|
||||
revalidated := bson.M{"$eq": bson.A{first("$_sourceTimeline.revalidateSource"), true}}
|
||||
superseded := bson.M{"$and": bson.A{revalidated, nonempty(first("$_sourceTimeline.supersededSourceFingerprint")), bson.M{"$eq": bson.A{"$processingJob.sourceFingerprint", first("$_sourceTimeline.supersededSourceFingerprint")}}}}
|
||||
missingReferenceProof := bson.M{"$and": bson.A{bson.M{"$eq": bson.A{"$subject.payload.materialization.sourceIndex", true}}, bson.M{"$not": bson.A{nonempty("$processingJob.sourceFingerprint")}}, bson.M{"$not": bson.A{nonempty(first("$_sourceTimeline.supersededSourceFingerprint"))}}}}
|
||||
@ -138,19 +153,26 @@ func annotationSourceAdmissionStatusPipeline() mongo.Pipeline {
|
||||
needsCertificate := bson.M{"$or": bson.A{bson.M{"$eq": bson.A{"$processingJob.sourceIndex", true}}, bson.M{"$eq": bson.A{"$subject.payload.materialization.sourceIndex", true}}}}
|
||||
jobs := bson.M{"$concatArrays": bson.A{"$_sourceTimeline", "$_sourcePrepared"}}
|
||||
matchingScope := bson.M{"$and": bson.A{bson.M{"$eq": bson.A{"$$job.organizationId", "$organizationId"}}, bson.M{"$eq": bson.A{"$$job.projectId", "$projectId"}}, bson.M{"$eq": bson.A{"$$job.runId", "$runId"}}}}
|
||||
safeJob := bson.M{"$and": bson.A{bson.M{"$eq": bson.A{"$$job.status", "completed"}}, matchingScope}}
|
||||
safeJob := bson.M{"$and": bson.A{bson.M{"$eq": bson.A{"$$job.status", "completed"}}, nonempty("$$job.sourceFingerprint"), matchingScope}}
|
||||
timelinePresent := bson.M{"$gt": bson.A{bson.M{"$size": "$_sourceTimeline"}, 0}}
|
||||
taskPresent := bson.M{"$gt": bson.A{bson.M{"$size": "$_sourceTask"}, 0}}
|
||||
certificatePresent := bson.M{"$gt": bson.A{bson.M{"$size": "$_sourcePrepared"}, 0}}
|
||||
sourceVersionMatches := bson.M{"$or": bson.A{bson.M{"$not": bson.A{certificatePresent}}, bson.M{"$eq": bson.A{first("$_sourcePrepared.sourceFingerprint"), "$processingJob.sourceFingerprint"}}}}
|
||||
certificateSatisfied := bson.M{"$or": bson.A{bson.M{"$not": bson.A{needsCertificate}}, certificatePresent, superseded, currentProof}}
|
||||
missing := bson.M{"$or": bson.A{
|
||||
bson.M{"$and": bson.A{needsTimeline, bson.M{"$not": bson.A{timelinePresent}}}},
|
||||
bson.M{"$and": bson.A{revalidated, bson.M{"$eq": bson.A{first("$_sourceTimeline.status"), "completed"}}, bson.M{"$not": bson.A{nonempty(first("$_sourceTimeline.sourceFingerprint"))}}}},
|
||||
bson.M{"$not": bson.A{taskPresent}},
|
||||
bson.M{"$not": bson.A{timelinePresent}},
|
||||
bson.M{"$and": bson.A{bson.M{"$eq": bson.A{first("$_sourceTimeline.status"), "completed"}}, bson.M{"$not": bson.A{nonempty(first("$_sourceTimeline.sourceFingerprint"))}}}},
|
||||
bson.M{"$not": bson.A{certificateSatisfied}},
|
||||
bson.M{"$not": bson.A{sourceVersionMatches}},
|
||||
bson.M{"$anyElementTrue": bson.A{bson.M{"$map": bson.M{"input": jobs, "as": "job", "in": bson.M{"$and": bson.A{bson.M{"$eq": bson.A{"$$job.status", "completed"}}, bson.M{"$not": bson.A{nonempty("$$job.sourceFingerprint")}}}}}}}},
|
||||
}}
|
||||
ready := bson.M{"$and": bson.A{
|
||||
bson.M{"$or": bson.A{timelinePresent, bson.M{"$not": bson.A{needsTimeline}}}},
|
||||
bson.M{"$or": bson.A{bson.M{"$not": bson.A{revalidated}}, nonempty(first("$_sourceTimeline.sourceFingerprint"))}},
|
||||
taskPresent,
|
||||
timelinePresent,
|
||||
nonempty(first("$_sourceTimeline.sourceFingerprint")),
|
||||
certificateSatisfied,
|
||||
sourceVersionMatches,
|
||||
bson.M{"$allElementsTrue": bson.A{bson.M{"$map": bson.M{"input": jobs, "as": "job", "in": safeJob}}}},
|
||||
}}
|
||||
failed := bson.M{"$anyElementTrue": bson.A{bson.M{"$map": bson.M{"input": jobs, "as": "job", "in": bson.M{"$or": bson.A{bson.M{"$eq": bson.A{"$$job.status", "failed"}}, bson.M{"$not": bson.A{matchingScope}}}}}}}}
|
||||
@ -188,7 +210,7 @@ func (s *MemoryStore) RetryAnnotationSourceValidation(_ context.Context, task do
|
||||
s.annotationIndexJobs = map[string]domain.AnnotationIndexJob{}
|
||||
}
|
||||
job := annotationIndexJob(task)
|
||||
job.RevalidateSource = verifySource
|
||||
job.RevalidateSource = verifySource || AnnotationSourceValidationRequired(task)
|
||||
job.SupersededSourceFingerprint = supersededFingerprint
|
||||
s.annotationIndexJobs[task.ID] = job
|
||||
return nil
|
||||
@ -203,7 +225,7 @@ func (s *MongoStore) RetryAnnotationSourceValidation(ctx context.Context, task d
|
||||
return nil, ErrSourceValidationActive
|
||||
}
|
||||
next := annotationIndexJob(task)
|
||||
next.RevalidateSource = verifySource
|
||||
next.RevalidateSource = verifySource || AnnotationSourceValidationRequired(task)
|
||||
next.SupersededSourceFingerprint = supersededFingerprint
|
||||
return nil, mongoUpsert(ctx, s.db.Collection("annotationIndexJobs"), task.ID, next)
|
||||
})
|
||||
|
||||
@ -38,12 +38,17 @@ func testSourceAdmissionAndClaimFence(t *testing.T, s Store) {
|
||||
t.Fatal(e)
|
||||
}
|
||||
tasks := map[string]domain.AnnotationTaskRecord{}
|
||||
for _, id := range []string{"failed", "pending", "valid", "legacy"} {
|
||||
for _, id := range []string{"failed", "pending", "valid", "legacy", "timeline-only"} {
|
||||
task := domain.AnnotationTaskRecord{ID: "source-" + id, OrganizationID: org, ProjectID: project, RunID: batch.RunID, SourceIsFullVideo: id != "legacy", TemplateVersion: 6, ArtifactID: "source-left", Status: domain.AnnotationTaskStatusPendingAnnotation}
|
||||
if e := s.UpsertAnnotationTask(ctx, task); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
tasks[id] = task
|
||||
if id == "legacy" {
|
||||
if e := queue.EnqueueAnnotationIndex(ctx, task); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
item := domain.HumanItemRecord{ID: task.ID, OrganizationID: org, ProjectID: project, RunID: batch.RunID, BatchID: batch.ID, PluginID: "annotation-qa", LegacyTaskID: task.ID, CurrentStageID: domain.FanyuV58StageAnnotationCombined, Status: domain.HumanItemReady, Version: 1, Subject: domain.HumanSubjectRef{ItemKey: task.ID, Payload: map[string]any{"draft": "preserved"}}}
|
||||
if e := s.UpsertHumanItem(ctx, item); e != nil {
|
||||
t.Fatal(e)
|
||||
@ -52,7 +57,7 @@ func testSourceAdmissionAndClaimFence(t *testing.T, s Store) {
|
||||
now := time.Now().UTC()
|
||||
stamp := now.Format(time.RFC3339Nano)
|
||||
until := now.Add(time.Minute).Format(time.RFC3339Nano)
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := 0; i < 5; i++ {
|
||||
job, e := queue.ClaimAnnotationIndex(ctx, fmt.Sprintf("validator-%d", i), stamp, until)
|
||||
if e != nil || job == nil {
|
||||
t.Fatal("job not queued", e)
|
||||
@ -60,8 +65,10 @@ func testSourceAdmissionAndClaimFence(t *testing.T, s Store) {
|
||||
switch job.ID {
|
||||
case tasks["failed"].ID:
|
||||
job.Status, job.Error = "failed", "IMU row 7 invalid type gyr"
|
||||
case tasks["valid"].ID:
|
||||
job.Status = "completed"
|
||||
case tasks["valid"].ID, tasks["legacy"].ID:
|
||||
job.Status, job.SourceFingerprint = "completed", "validated-source"
|
||||
case tasks["timeline-only"].ID:
|
||||
job.Status, job.SourceFingerprint = "completed", ""
|
||||
default:
|
||||
job.Status = "running"
|
||||
}
|
||||
@ -166,10 +173,11 @@ func testSourceAdmissionAndClaimFence(t *testing.T, s Store) {
|
||||
}
|
||||
|
||||
legacy := tasks["legacy"]
|
||||
if job, e := queue.GetAnnotationIndexJob(ctx, legacy.ID); e != nil || job != nil {
|
||||
t.Fatal("legacy record unexpectedly present", e)
|
||||
legacyProof, e := queue.GetAnnotationIndexJob(ctx, legacy.ID)
|
||||
if e != nil || legacyProof == nil {
|
||||
t.Fatal("missing complete legacy proof", e)
|
||||
}
|
||||
if changed, e := queue.FailAnnotationSourceValidation(ctx, legacy, "", "IMU invalid type gyr at row 9"); e != nil || !changed {
|
||||
if changed, e := queue.FailAnnotationSourceValidation(ctx, legacy, legacyProof.CreatedAt, "IMU invalid type gyr at row 9"); e != nil || !changed {
|
||||
t.Fatalf("newly discovered legacy failure was not recorded: %v %v", changed, e)
|
||||
}
|
||||
if n, e := s.CountAnnotationClaimCandidates(ctx, org, q); e != nil || n != 0 {
|
||||
@ -194,7 +202,7 @@ func testSourceAdmissionAndClaimFence(t *testing.T, s Store) {
|
||||
if e != nil || job == nil || job.ID != legacy.ID {
|
||||
t.Fatal("missing legacy recovery job", e)
|
||||
}
|
||||
job.Status = "completed"
|
||||
job.Status, job.SourceFingerprint = "completed", "validated-legacy-source"
|
||||
if ok, e := queue.FinishAnnotationIndex(ctx, *job); !ok || e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
@ -213,8 +221,8 @@ func testSourceAdmissionAndClaimFence(t *testing.T, s Store) {
|
||||
if e := s.UpsertHumanItem(ctx, *afterLegacy); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if n, e := s.CountAnnotationClaimCandidates(ctx, org, q); e != nil || n != 0 {
|
||||
t.Fatalf("payload-only source missing proof admitted: %d %v", n, e)
|
||||
if n, e := s.CountAnnotationClaimCandidates(ctx, org, q); e != nil || n != 1 {
|
||||
t.Fatalf("complete task-level proof did not cover legacy source marker: %d %v", n, e)
|
||||
}
|
||||
if e := queue.RetryAnnotationSourceValidation(ctx, legacy, true, ""); e != nil {
|
||||
t.Fatal(e)
|
||||
@ -263,7 +271,7 @@ func testSourceAdmissionAndClaimFence(t *testing.T, s Store) {
|
||||
if e != nil || newSource == nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
newSource.Status = "completed"
|
||||
newSource.Status, newSource.SourceFingerprint = "completed", "new-after-payload-repair"
|
||||
if ok, e := queue.FinishAnnotationIndex(ctx, *newSource); !ok || e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
@ -348,7 +356,7 @@ func TestSourceAdmissionMongoLargePool(t *testing.T) {
|
||||
id := fmt.Sprintf("source-load-%04d", i)
|
||||
tasks = append(tasks, domain.AnnotationTaskRecord{ID: id, OrganizationID: org, ProjectID: project, RunID: id, SourceIsFullVideo: true, TemplateVersion: 6, ArtifactID: "left", Status: domain.AnnotationTaskStatusPendingAnnotation})
|
||||
items = append(items, domain.HumanItemRecord{ID: id, OrganizationID: org, ProjectID: project, RunID: id, PluginID: "annotation-qa", BatchID: batch.ID, LegacyTaskID: id, CurrentStageID: domain.FanyuV58StageAnnotationCombined, Status: domain.HumanItemReady, Subject: domain.HumanSubjectRef{ItemKey: id, Payload: map[string]any{"large": strings.Repeat("x", 64*1024)}}})
|
||||
jobs = append(jobs, domain.AnnotationIndexJob{ID: id, OrganizationID: org, ProjectID: project, RunID: id, Status: "completed"})
|
||||
jobs = append(jobs, domain.AnnotationIndexJob{ID: id, OrganizationID: org, ProjectID: project, RunID: id, Status: "completed", SourceFingerprint: "source-proof-" + id})
|
||||
}
|
||||
for name, docs := range map[string][]any{"annotationTasks": tasks, "humanItems": items, "annotationIndexJobs": jobs} {
|
||||
if _, e := db.Collection(name).InsertMany(ctx, docs); e != nil {
|
||||
@ -473,7 +481,7 @@ func TestSourceAdmissionMongoBatchMatchesLegacyPipeline(t *testing.T) {
|
||||
if foreign {
|
||||
org = "other"
|
||||
}
|
||||
_, err = db.Collection("annotationIndexJobs").InsertOne(ctx, domain.AnnotationIndexJob{ID: id, OrganizationID: org, ProjectID: "p", RunID: "r", Status: status})
|
||||
_, err = db.Collection("annotationIndexJobs").InsertOne(ctx, domain.AnnotationIndexJob{ID: id, OrganizationID: org, ProjectID: "p", RunID: "r", Status: status, SourceFingerprint: map[bool]string{true: "source-proof", false: ""}[len(items)%2 == 0]})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
72
internal/store/annotation_source_full_admission_test.go
Normal file
72
internal/store/annotation_source_full_admission_test.go
Normal file
@ -0,0 +1,72 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
// Non-validator store tests explicitly model healthy sources. This helper is
|
||||
// confined to their isolated fixtures and never grants production eligibility.
|
||||
func completeSourceAdmissionTestProof(t *testing.T, s Store, task domain.AnnotationTaskRecord) {
|
||||
t.Helper()
|
||||
job := annotationIndexJob(task)
|
||||
job.Status, job.SourceFingerprint = "completed", "fixture-full-source-"+task.ID
|
||||
switch st := s.(type) {
|
||||
case *MemoryStore:
|
||||
st.mu.Lock()
|
||||
st.annotationIndexJobs[task.ID] = job
|
||||
st.mu.Unlock()
|
||||
case *MongoStore:
|
||||
if err := mongoUpsert(t.Context(), st.db.Collection("annotationIndexJobs"), job.ID, job); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
default:
|
||||
t.Fatal("unsupported isolated source fixture")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceAdmissionRequiresCompleteProofForLegacyTasks(t *testing.T) {
|
||||
for _, legacy := range []bool{false, true} {
|
||||
task := domain.AnnotationTaskRecord{ID: "task", OrganizationID: "org", ProjectID: "project", RunID: "run", SourceIsFullVideo: !legacy, TemplateVersion: 6, ArtifactID: "left"}
|
||||
if legacy {
|
||||
task.TemplateVersion, task.ArtifactID = 4, ""
|
||||
}
|
||||
for _, state := range []string{"missing", "timeline-only", "queued", "failed", "complete", "wrong-run"} {
|
||||
t.Run(map[bool]string{true: "legacy", false: "current"}[legacy]+"/"+state, func(t *testing.T) {
|
||||
var job *domain.AnnotationIndexJob
|
||||
if state != "missing" {
|
||||
job = &domain.AnnotationIndexJob{ID: task.ID, OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, RunID: task.RunID, Status: "completed"}
|
||||
if state != "timeline-only" {
|
||||
job.SourceFingerprint = "fully-validated-source"
|
||||
}
|
||||
if state == "queued" || state == "failed" {
|
||||
job.Status = state
|
||||
}
|
||||
if state == "wrong-run" {
|
||||
job.RunID = "another-run"
|
||||
}
|
||||
}
|
||||
if got := AnnotationItemSourceJobsReady(task, domain.HumanItemRecord{}, job, nil); got != (state == "complete") {
|
||||
t.Fatalf("incomplete or mismatched source proof admitted task: ready=%v state=%s legacy=%v", got, state, legacy)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceAdmissionRequiresCurrentCompleteCertificate(t *testing.T) {
|
||||
task := domain.AnnotationTaskRecord{ID: "task", OrganizationID: "org", ProjectID: "project", RunID: "run"}
|
||||
item := domain.HumanItemRecord{ProcessingJob: &domain.AnnotationProcessingJob{SourceIndex: true, SourceFingerprint: "current"}}
|
||||
timeline := domain.AnnotationIndexJob{ID: task.ID, OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, RunID: task.RunID, Status: "completed", SourceFingerprint: "current"}
|
||||
for _, fingerprint := range []string{"", "stale", "current"} {
|
||||
t.Run("certificate-"+fingerprint, func(t *testing.T) {
|
||||
source := timeline
|
||||
source.ID = AnnotationSourceJobID(task.OrganizationID, "current")
|
||||
source.SourceFingerprint = fingerprint
|
||||
if got := AnnotationItemSourceJobsReady(task, item, &timeline, &source); got != (fingerprint == "current") {
|
||||
t.Fatalf("certificate fingerprint %q admitted=%v", fingerprint, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -38,6 +38,7 @@ func deletedAnnotatorStoreContract(t *testing.T, s Store) {
|
||||
batch := domain.HumanBatchRecord{ID: "batch-" + project, OrganizationID: org, ProjectID: project, PluginID: "annotation-qa", Status: domain.HumanBatchActive, Stages: domain.DefaultFanyuV58HumanStages()}
|
||||
must(s.UpsertHumanBatch(ctx, batch))
|
||||
must(s.UpsertAnnotationTask(ctx, domain.AnnotationTaskRecord{ID: taskID, OrganizationID: org, ProjectID: project, SupplierID: supplier, Status: domain.AnnotationTaskStatusRework, CurrentRevision: 1}))
|
||||
completeSourceAdmissionTestProof(t, s, domain.AnnotationTaskRecord{ID: taskID, OrganizationID: org, ProjectID: project})
|
||||
item := domain.HumanItemRecord{ID: id, OrganizationID: org, ProjectID: project, SupplierID: supplier, BatchID: batch.ID, LegacyTaskID: taskID, PluginID: "annotation-qa", Status: domain.HumanItemRework, CurrentStageID: domain.FanyuV58StageAnnotationCombined, Version: 1, ReviewRound: 1, CurrentRevision: 1, InheritedRework: true, Subject: domain.HumanSubjectRef{ItemKey: id, Payload: map[string]any{"annotationDraft": map[string]any{"userId": "deleted", "marker": "old private draft"}}}}
|
||||
must(s.UpsertHumanItem(ctx, item))
|
||||
must(s.UpsertReworkBaseline(ctx, domain.ReworkBaselineRecord{ID: ReworkBaselineID(id, 1), OrganizationID: org, ProjectID: project, ItemID: id, Round: 1, Slices: []domain.SliceSegment{{ID: "s", Start: 0, End: 10}}, Actions: []domain.AnnotationSegment{{ID: "a", Start: 0, End: 10, Description: "正式内容"}}, Problems: []domain.ReviewProblem{{ID: "opinion", Text: "保留质检意见"}}}))
|
||||
|
||||
@ -22,7 +22,7 @@ func testPoolCountPredicates(t *testing.T, s Store) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
org, project := "pool-fixture-org", "pool-fixture-project"
|
||||
legacy := domain.HumanBatchRecord{ID: "pool-legacy", OrganizationID: org, ProjectID: project, Stages: domain.DefaultFanyuV58HumanStages(), Status: domain.HumanBatchActive}
|
||||
legacy := domain.HumanBatchRecord{ID: "pool-legacy", OrganizationID: org, ProjectID: project, RunID: "pool-fixture-run", Stages: domain.DefaultFanyuV58HumanStages(), Status: domain.HumanBatchActive}
|
||||
pooled := legacy
|
||||
pooled.ID = "pool-shared"
|
||||
pooled.ProcessingProfile = domain.ProcessingProfileRawHuman
|
||||
@ -46,7 +46,7 @@ func testPoolCountPredicates(t *testing.T, s Store) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
base := domain.HumanItemRecord{ID: "candidate", OrganizationID: org, ProjectID: project, PluginID: "annotation-qa", BatchID: legacy.ID, LegacyTaskID: "legacy-task", CurrentStageID: domain.FanyuV58StageAnnotationCombined, Status: domain.HumanItemReady, CreatedAt: "2026-10-01T00:00:00Z"}
|
||||
base := domain.HumanItemRecord{ID: "candidate", OrganizationID: org, ProjectID: project, PluginID: "annotation-qa", BatchID: legacy.ID, RunID: legacy.RunID, LegacyTaskID: "legacy-task", CurrentStageID: domain.FanyuV58StageAnnotationCombined, Status: domain.HumanItemReady, CreatedAt: "2026-10-01T00:00:00Z"}
|
||||
items := []domain.HumanItemRecord{}
|
||||
add := func(id string, edit func(*domain.HumanItemRecord)) {
|
||||
v := base
|
||||
@ -55,6 +55,16 @@ func testPoolCountPredicates(t *testing.T, s Store) {
|
||||
if edit != nil {
|
||||
edit(&v)
|
||||
}
|
||||
if v.LegacyTaskID != "" {
|
||||
if v.LegacyTaskID == base.LegacyTaskID {
|
||||
v.LegacyTaskID = id + "-task"
|
||||
}
|
||||
task := domain.AnnotationTaskRecord{ID: v.LegacyTaskID, OrganizationID: v.OrganizationID, ProjectID: v.ProjectID, RunID: v.RunID}
|
||||
if err := s.UpsertAnnotationTask(ctx, task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
completeSourceAdmissionTestProof(t, s, task)
|
||||
}
|
||||
items = append(items, v)
|
||||
if err := s.UpsertHumanItem(ctx, v); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -276,6 +286,11 @@ func testPoolStageRoleCountAndVisibility(t *testing.T, ctx context.Context, s *M
|
||||
if err := s.UpsertHumanItem(ctx, item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
validatedTask := domain.AnnotationTaskRecord{ID: key, OrganizationID: org, ProjectID: key}
|
||||
if err := s.UpsertAnnotationTask(ctx, validatedTask); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
completeSourceAdmissionTestProof(t, s, validatedTask)
|
||||
want := 0
|
||||
if domain.AnnotationRoleForHumanStage(stage) == domain.AnnotationRoleAnnotator {
|
||||
want = 1
|
||||
|
||||
@ -178,6 +178,8 @@
|
||||
"^src/(pages/AnnotationOperations\\.tsx|services/api/annotation-operations\\.ts)$",
|
||||
"^internal/(api|store)/annotation_(source|work_buffer|claim_read|claim_visit|random_claim)",
|
||||
"^internal/store/human_claim",
|
||||
"^internal/store/admin_source_exceptions_test\\.go$",
|
||||
"^internal/store/pool_count_performance_test\\.go$",
|
||||
"^tests/browser/annotation-source-validation-replica\\.mjs$"
|
||||
],
|
||||
"frontend": [
|
||||
@ -200,7 +202,7 @@
|
||||
"test",
|
||||
"./internal/store",
|
||||
"-run",
|
||||
"^TestSourceAdmissionMongo(ClaimFence|BatchMatchesLegacyPipeline|ClaimReadPlan)$",
|
||||
"^TestSourceAdmissionMongo(ClaimFence|BatchMatchesLegacyPipeline|ClaimReadPlan|LargePool)$|^TestAdminSourceExceptionsMongo$",
|
||||
"-count=1",
|
||||
"-timeout=3m",
|
||||
"-v"
|
||||
@ -210,6 +212,22 @@
|
||||
},
|
||||
"tests": true
|
||||
},
|
||||
{
|
||||
"argv": [
|
||||
"go",
|
||||
"test",
|
||||
"./internal/store",
|
||||
"-run",
|
||||
"^TestPoolCountPredicatesMongo$|^TestPoolStageRoleCountAndVisibilityMatchesDomainMongo$",
|
||||
"-count=1",
|
||||
"-timeout=3m",
|
||||
"-v"
|
||||
],
|
||||
"env": {
|
||||
"POOL_LOCAL_MONGO_URI": "mongodb://127.0.0.1:27018/?directConnection=true"
|
||||
},
|
||||
"tests": true
|
||||
},
|
||||
{
|
||||
"argv": [
|
||||
"go",
|
||||
|
||||
@ -163,5 +163,7 @@ try {
|
||||
} finally {
|
||||
fs.writeFileSync(output + "/report.json", JSON.stringify(report, null, 2));
|
||||
await browser?.close();
|
||||
// Stop fixture proxy connections before waiting for the local server to close.
|
||||
vite.httpServer?.closeAllConnections();
|
||||
await vite.close();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user