forked from longtao.wu/droboticflow
Compare commits
No commits in common. "dev" and "dev" have entirely different histories.
@ -110,7 +110,7 @@ _Avoid_:公共可领取任务池(其中的任务尚未归属当前标注员
|
||||
|
||||
## 审查
|
||||
|
||||
**审查追溯**:已授权任务的只读事件投影。任务来源与流转记录合并为右栏顶部的一张可折叠卡片,标题行显示当前版本与打回次数,默认展示最近两条流转;普通任务卡可批量附加人员、供应商和退回统计。缺失值用 `-`,已知零次保留 `0`;版本来自修订字段,退回次数来自正式退回事件,不使用轮数或版本相减。历史没有创建起点时,首次提交和总退回次数保留未知。最终验收按当前来源分段展示送检与质检流转和验收所依据的标注版本,分别显示该分段的质检退回次数与验收任务的验收退回次数。来源流转不展示人员身份,供应商继续遵守匿名规则。辅助统计失败不阻断任务列表,不回填或改写历史数据。
|
||||
**审查追溯**:已授权任务的只读事件投影。任务来源与流转记录合并为右栏顶部的一张可折叠卡片,标题行显示当前版本与打回次数,默认展示最近两条流转;普通任务卡可批量附加人员、供应商和退回统计。缺失值用 `-`,已知零次保留 `0`;版本来自修订字段,退回次数来自正式退回事件,不使用轮数或版本相减。历史没有创建起点时,首次提交和总退回次数保留未知。最终验收继续遵守供应商匿名规则。辅助统计失败不阻断任务列表,不回填或改写历史数据。
|
||||
|
||||
**审查**:质检审核与最终验收的统称,操作者核对已有结果、记录问题并作出通过或退回决定,不直接修改原标注结果。
|
||||
|
||||
|
||||
@ -2639,7 +2639,6 @@ func parseISOTime(value string) time.Time {
|
||||
}
|
||||
|
||||
const fanyuV5PrePackageAcceptanceStageID = "prepackage_acceptance"
|
||||
const acceptanceAssembledAtKey = "assembledAt"
|
||||
|
||||
func fanyuV5PrePackageAcceptanceBatchID(sourceBatchID string) string {
|
||||
return "human-batch-fanyu-v5-prepackage-acceptance-" + strings.TrimSpace(sourceBatchID)
|
||||
@ -2887,19 +2886,13 @@ func (server *server) ensureFanyuV5PrePackageAcceptance(ctx context.Context, sou
|
||||
}
|
||||
aggregate = append(aggregate, map[string]any{
|
||||
"taskId": task.ID, "runId": task.RunID, "sourceHumanItemId": humanItem.ID,
|
||||
"annotationRevision": latestRevision.Revision,
|
||||
"clipArtifactId": task.ArtifactID, "sourceVideo": task.SourceVideo,
|
||||
"clipArtifactId": task.ArtifactID, "sourceVideo": task.SourceVideo,
|
||||
"clipStart": task.ClipStart, "clipEnd": task.ClipEnd,
|
||||
"finalSlices": acceptanceSlices, "annotation": latestRevision.Segments,
|
||||
"poseSummary": poseSummary, "materialization": materialization,
|
||||
})
|
||||
}
|
||||
now := nowISO()
|
||||
payload := map[string]any{
|
||||
"sourceBatchId": source.ID, "items": aggregate, "statistics": statistics,
|
||||
"strictThreeRole": domain.IsFanyuV58ThreeRoleHumanLoop(source.Stages),
|
||||
acceptanceAssembledAtKey: now,
|
||||
}
|
||||
if acceptanceItem == nil {
|
||||
supplierID := items[0].SupplierID
|
||||
legacyAssignment := items[0].LegacyAssignment
|
||||
@ -2913,13 +2906,13 @@ func (server *server) ensureFanyuV5PrePackageAcceptance(ctx context.Context, sou
|
||||
ProcessingProfile: source.ProcessingProfile,
|
||||
ID: acceptanceID, OrganizationID: source.OrganizationID, PluginID: source.PluginID, BatchID: batchID,
|
||||
ProjectID: source.ProjectID, WorkflowID: source.WorkflowID, RunID: source.RunID, GateNodeID: acceptanceBatch.GateNodeID,
|
||||
Subject: domain.HumanSubjectRef{ItemKey: source.ID, MediaType: "application/json", Payload: payload},
|
||||
Subject: domain.HumanSubjectRef{ItemKey: source.ID, MediaType: "application/json", Payload: map[string]any{"sourceBatchId": source.ID, "items": aggregate, "statistics": statistics, "strictThreeRole": domain.IsFanyuV58ThreeRoleHumanLoop(source.Stages)}},
|
||||
CurrentStageID: fanyuV5PrePackageAcceptanceStageID, Status: domain.HumanItemReady,
|
||||
SupplierID: supplierID, LegacyAssignment: legacyAssignment,
|
||||
WorkgroupID: workgroupID, VendorID: vendorID, MaxReworkRounds: source.MaxReworkRounds, Version: 1, CreatedAt: now, UpdatedAt: now,
|
||||
}
|
||||
} else {
|
||||
acceptanceItem.Subject.Payload = payload
|
||||
acceptanceItem.Subject.Payload = map[string]any{"sourceBatchId": source.ID, "items": aggregate, "statistics": statistics, "strictThreeRole": domain.IsFanyuV58ThreeRoleHumanLoop(source.Stages)}
|
||||
acceptanceItem.Status = domain.HumanItemReady
|
||||
acceptanceItem.AssignedUserID = ""
|
||||
acceptanceItem.ClaimedAt = ""
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"droboticflow/internal/domain"
|
||||
"net/http"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type reviewTraceEvent struct {
|
||||
@ -17,15 +14,14 @@ type reviewTraceEvent struct {
|
||||
Revision int `json:"revision"`
|
||||
}
|
||||
type reviewTrace struct {
|
||||
Author string `json:"author"`
|
||||
AuthorID string `json:"authorId"`
|
||||
Supplier string `json:"supplier"`
|
||||
FirstSubmittedAt string `json:"firstSubmittedAt"`
|
||||
Revision int `json:"revision"`
|
||||
Reviewer string `json:"reviewer"`
|
||||
Rejections *int `json:"rejections"`
|
||||
QualityRejections *int `json:"qualityRejections"`
|
||||
Events []reviewTraceEvent `json:"events"`
|
||||
Author string `json:"author"`
|
||||
AuthorID string `json:"authorId"`
|
||||
Supplier string `json:"supplier"`
|
||||
FirstSubmittedAt string `json:"firstSubmittedAt"`
|
||||
Revision int `json:"revision"`
|
||||
Reviewer string `json:"reviewer"`
|
||||
Rejections *int `json:"rejections"`
|
||||
Events []reviewTraceEvent `json:"events"`
|
||||
}
|
||||
|
||||
// This projection reads existing audit evidence; it never repairs or invents
|
||||
@ -81,7 +77,6 @@ func (s *server) handleReviewTrace(w http.ResponseWriter, r *http.Request) {
|
||||
complete := false
|
||||
rejected := 0
|
||||
first := ""
|
||||
acceptance := item.CurrentStageID == fanyuV5PrePackageAcceptanceStageID
|
||||
for _, e := range events {
|
||||
if e.EventType == "created" {
|
||||
complete = true
|
||||
@ -97,14 +92,8 @@ func (s *server) handleReviewTrace(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
case "approved", "combined_quality_approved":
|
||||
kind = "审核通过"
|
||||
if acceptance {
|
||||
kind = "验收通过"
|
||||
}
|
||||
case "rejected", "combined_quality_rejected":
|
||||
kind = "审核退回"
|
||||
if acceptance {
|
||||
kind = "验收退回"
|
||||
}
|
||||
rejected++
|
||||
case "aggregate_acceptance_rejected":
|
||||
kind = "验收退回"
|
||||
@ -119,7 +108,14 @@ func (s *server) handleReviewTrace(w http.ResponseWriter, r *http.Request) {
|
||||
if kind == "" {
|
||||
continue
|
||||
}
|
||||
out.Events = append(out.Events, reviewTraceEvent{ID: e.ID, Kind: kind, Actor: name(e.ActorUserID), At: e.CreatedAt, Revision: traceEventRevision(e)})
|
||||
revision := intValue(e.Payload["revision"])
|
||||
if revision == 0 {
|
||||
revision = intValue(e.Payload["annotationRevision"])
|
||||
}
|
||||
if revision == 0 {
|
||||
revision = intValue(e.Payload["reviewedRevision"])
|
||||
}
|
||||
out.Events = append(out.Events, reviewTraceEvent{ID: e.ID, Kind: kind, Actor: name(e.ActorUserID), At: e.CreatedAt, Revision: revision})
|
||||
}
|
||||
if complete {
|
||||
out.FirstSubmittedAt = first
|
||||
@ -129,117 +125,12 @@ func (s *server) handleReviewTrace(w http.ResponseWriter, r *http.Request) {
|
||||
renderError(w, 500, err)
|
||||
return
|
||||
}
|
||||
slices.Reverse(out.Events)
|
||||
if acceptance {
|
||||
if err := s.addAcceptanceSourceTrace(ctx, *item, events, r.URL.Query().Get("sourceItemId"), &out); err != nil {
|
||||
renderError(w, 500, err)
|
||||
return
|
||||
}
|
||||
// Latest events first, identically in the compact panel and full history.
|
||||
for i, j := 0, len(out.Events)-1; i < j; i, j = i+1, j-1 {
|
||||
out.Events[i], out.Events[j] = out.Events[j], out.Events[i]
|
||||
}
|
||||
sort.SliceStable(out.Events, func(i, j int) bool {
|
||||
return parseISOTime(out.Events[j].At).Before(parseISOTime(out.Events[i].At))
|
||||
})
|
||||
renderJSON(w, http.StatusOK, out)
|
||||
}
|
||||
|
||||
func traceEventRevision(event domain.HumanEventRecord) int {
|
||||
for _, key := range []string{"revision", "annotationRevision", "reviewedRevision"} {
|
||||
if revision := intValue(event.Payload[key]); revision > 0 {
|
||||
return revision
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (s *server) addAcceptanceSourceTrace(ctx context.Context, item domain.HumanItemRecord, events []domain.HumanEventRecord, sourceID string, out *reviewTrace) error {
|
||||
entries, _ := normalizeStructuredValue(item.Subject.Payload["items"]).([]any)
|
||||
var entry map[string]any
|
||||
for _, raw := range entries {
|
||||
candidate, _ := raw.(map[string]any)
|
||||
if (sourceID != "" && stringValue(candidate["sourceHumanItemId"]) == sourceID) || (sourceID == "" && len(entries) == 1) {
|
||||
entry = candidate
|
||||
break
|
||||
}
|
||||
}
|
||||
sourceID = stringValue(entry["sourceHumanItemId"])
|
||||
taskID := stringValue(entry["taskId"])
|
||||
if sourceID == "" || sourceID == item.ID || taskID == "" || stringValue(entry["runId"]) != item.RunID {
|
||||
return nil
|
||||
}
|
||||
batch, err := s.humanBatchForListRead(ctx, item.BatchID)
|
||||
if err != nil || batch == nil || strings.TrimSpace(batch.SourceBatchID) == "" {
|
||||
return err
|
||||
}
|
||||
sources, err := s.store.ListHumanItems(ctx, item.OrganizationID, domain.HumanItemQuery{
|
||||
IDs: []string{sourceID}, BatchID: batch.SourceBatchID, ProjectID: item.ProjectID, WorkflowID: item.WorkflowID,
|
||||
RunID: item.RunID, LegacyTaskID: taskID, IdentityProjection: true, Limit: 1,
|
||||
})
|
||||
if err != nil || len(sources) == 0 {
|
||||
return err
|
||||
}
|
||||
// The cutoff is saved with the evidence. The separate audit event can fail
|
||||
// after the evidence is already persisted.
|
||||
cutoff := parseISOTime(stringValue(item.Subject.Payload[acceptanceAssembledAtKey]))
|
||||
if cutoff.IsZero() {
|
||||
cutoff = parseISOTime(item.CreatedAt)
|
||||
for _, event := range events {
|
||||
if at := parseISOTime(event.CreatedAt); event.EventType == "created" && at.After(cutoff) {
|
||||
cutoff = at
|
||||
}
|
||||
}
|
||||
}
|
||||
if cutoff.IsZero() {
|
||||
return nil
|
||||
}
|
||||
sourceEvents, err := s.store.ListHumanTraceEvents(ctx, item.OrganizationID, sourceID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sort.SliceStable(sourceEvents, func(i, j int) bool {
|
||||
return parseISOTime(sourceEvents[i].CreatedAt).Before(parseISOTime(sourceEvents[j].CreatedAt))
|
||||
})
|
||||
complete := false
|
||||
rejections := 0
|
||||
first := ""
|
||||
revision := 0
|
||||
for _, event := range sourceEvents {
|
||||
if at := parseISOTime(event.CreatedAt); at.IsZero() || at.After(cutoff) {
|
||||
continue
|
||||
}
|
||||
eventRevision := traceEventRevision(event)
|
||||
var kind string
|
||||
switch event.EventType {
|
||||
case "created":
|
||||
complete = true
|
||||
case "combined_submitted":
|
||||
kind = "提交审核"
|
||||
if first == "" {
|
||||
first = event.CreatedAt
|
||||
} else {
|
||||
kind = "重新提交"
|
||||
}
|
||||
case "combined_quality_approved":
|
||||
kind = "质检通过"
|
||||
revision = eventRevision
|
||||
case "combined_quality_rejected":
|
||||
kind = "质检退回"
|
||||
rejections++
|
||||
}
|
||||
if kind != "" {
|
||||
// Source actors and supplier details stay private in acceptance.
|
||||
out.Events = append(out.Events, reviewTraceEvent{ID: event.ID, Kind: kind, At: event.CreatedAt, Revision: eventRevision})
|
||||
}
|
||||
}
|
||||
out.Revision = intValue(entry["annotationRevision"])
|
||||
if out.Revision <= 0 {
|
||||
out.Revision = revision
|
||||
}
|
||||
if complete {
|
||||
out.FirstSubmittedAt = first
|
||||
out.QualityRejections = &rejections
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func normalizedTraceOrg(org string) string {
|
||||
if org == "" {
|
||||
return domain.DefaultOrganizationID
|
||||
|
||||
@ -26,61 +26,29 @@ func runReviewTraceBrowser(t *testing.T, mode string) {
|
||||
f = acceptanceReviewDraftFixture(t)
|
||||
}
|
||||
receipt := mode == "acceptance-receipt"
|
||||
traceSource := f.item.ID
|
||||
if mode != "quality" {
|
||||
if receipt {
|
||||
batch, err := f.store.GetHumanBatch(f.ctx, f.item.BatchID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sourceBatch := *batch
|
||||
sourceBatch.ID = "focus-source-batch"
|
||||
if receipt {
|
||||
sourceBatch.Stages = domain.DefaultFanyuV58HumanStages()
|
||||
sourceBatch.RequirePrePackageAcceptance = true
|
||||
}
|
||||
if err := f.store.UpsertHumanBatch(f.ctx, sourceBatch); err != nil {
|
||||
source := *batch
|
||||
source.ID = "focus-source-batch"
|
||||
source.Stages = domain.DefaultFanyuV58HumanStages()
|
||||
source.RequirePrePackageAcceptance = true
|
||||
if err := f.store.UpsertHumanBatch(f.ctx, source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
batch.SourceBatchID = sourceBatch.ID
|
||||
batch.SourceBatchID = source.ID
|
||||
if err := f.store.UpsertHumanBatch(f.ctx, *batch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, raw := range f.item.Subject.Payload["items"].([]any) {
|
||||
entry := raw.(map[string]any)
|
||||
entry["runId"] = f.item.RunID
|
||||
entry["annotationRevision"] = i + 3
|
||||
source := domain.HumanItemRecord{
|
||||
ID: stringValue(entry["sourceHumanItemId"]), OrganizationID: f.item.OrganizationID,
|
||||
ProjectID: f.item.ProjectID, WorkflowID: f.item.WorkflowID, RunID: f.item.RunID,
|
||||
BatchID: sourceBatch.ID, LegacyTaskID: stringValue(entry["taskId"]),
|
||||
}
|
||||
if err := f.store.UpsertHumanItem(f.ctx, source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
f.item.LatestAuthorUserID = ""
|
||||
if err := f.store.UpsertHumanItem(f.ctx, f.item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
traceSource = "source-a"
|
||||
for _, kind := range []string{"created", "claimed"} {
|
||||
if err := f.store.AppendHumanEvent(f.ctx, domain.HumanEventRecord{
|
||||
OrganizationID: f.item.OrganizationID, ItemID: f.item.ID, EventType: kind,
|
||||
ActorUserID: f.reviewer.ID, CreatedAt: "2026-01-08T00:00:00Z",
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
mode = "acceptance"
|
||||
}
|
||||
if err := f.store.UpsertOrganizationPlugin(f.ctx, domain.OrganizationPluginRecord{OrganizationID: domain.DefaultOrganizationID, PluginID: "annotation-qa", Enabled: true, Config: defaultAnnotationPluginConfig()}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, kind := range []string{"created", "combined_submitted", "combined_quality_rejected", "combined_submitted", "combined_quality_approved"} {
|
||||
if mode == "quality" && kind == "combined_quality_approved" {
|
||||
continue
|
||||
}
|
||||
if err := f.store.AppendHumanEvent(f.ctx, domain.HumanEventRecord{OrganizationID: f.item.OrganizationID, ItemID: traceSource, EventType: kind, ActorUserID: f.annotator.ID, CreatedAt: time.Date(2026, 1, 1+i, 0, 0, 0, 0, time.UTC).Format(time.RFC3339), Payload: map[string]any{"annotationRevision": 3}}); err != nil {
|
||||
for i, kind := range []string{"created", "combined_submitted", "combined_quality_rejected", "combined_submitted"} {
|
||||
if err := f.store.AppendHumanEvent(f.ctx, domain.HumanEventRecord{OrganizationID: f.item.OrganizationID, ItemID: f.item.ID, EventType: kind, ActorUserID: f.annotator.ID, CreatedAt: time.Date(2026, 1, 1+i, 0, 0, 0, 0, time.UTC).Format(time.RFC3339), Payload: map[string]any{"annotationRevision": i + 1}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestReviewTraceExistingEvidenceAndMissingHistory(t *testing.T) {
|
||||
@ -89,200 +88,3 @@ func TestReviewTraceSummaryFailureDoesNotHideTaskPool(t *testing.T) {
|
||||
t.Fatalf("metadata failure hid work: %d %s", res.Code, res.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestReviewTraceAcceptanceProjectsOnlySelectedSource(t *testing.T) {
|
||||
f := sharedAcceptanceFixture(t)
|
||||
batch, err := f.store.GetHumanBatch(f.ctx, f.item.BatchID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.item.CreatedAt = "2026-01-08T00:00:00Z"
|
||||
f.item.AssignedUserID = f.reviewer.ID
|
||||
f.item.CurrentRevision = 0
|
||||
f.item.LatestAuthorUserID = ""
|
||||
entries := f.item.Subject.Payload["items"].([]any)
|
||||
for i, raw := range entries {
|
||||
entry := raw.(map[string]any)
|
||||
entry["runId"] = f.item.RunID
|
||||
source := domain.HumanItemRecord{
|
||||
ID: stringValue(entry["sourceHumanItemId"]), OrganizationID: f.item.OrganizationID,
|
||||
ProjectID: f.item.ProjectID, WorkflowID: f.item.WorkflowID, RunID: f.item.RunID,
|
||||
BatchID: batch.SourceBatchID, LegacyTaskID: stringValue(entry["taskId"]),
|
||||
CurrentRevision: 9, LatestAuthorUserID: f.annotator.ID, SupplierID: f.annotator.SupplierID,
|
||||
}
|
||||
if i == 1 {
|
||||
entry["annotationRevision"] = 4
|
||||
}
|
||||
if err := f.store.UpsertHumanItem(f.ctx, source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
foreign := entries[0].(map[string]any)
|
||||
entries = append(entries, map[string]any{"sourceHumanItemId": "wrong-batch", "taskId": foreign["taskId"], "runId": f.item.RunID})
|
||||
f.item.Subject.Payload["items"] = entries
|
||||
if err := f.store.UpsertHumanItem(f.ctx, f.item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := f.store.UpsertHumanItem(f.ctx, domain.HumanItemRecord{
|
||||
ID: "wrong-batch", OrganizationID: f.item.OrganizationID, ProjectID: f.item.ProjectID,
|
||||
WorkflowID: f.item.WorkflowID, RunID: f.item.RunID, BatchID: "other", LegacyTaskID: stringValue(foreign["taskId"]),
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
add := func(itemID, kind, day string, revision int) {
|
||||
t.Helper()
|
||||
err := f.store.AppendHumanEvent(f.ctx, domain.HumanEventRecord{
|
||||
ID: itemID + "-" + day, ItemID: itemID, OrganizationID: f.item.OrganizationID, EventType: kind,
|
||||
CreatedAt: "2026-01-" + day + "T00:00:00Z", ActorUserID: f.annotator.ID,
|
||||
Payload: map[string]any{"reviewedRevision": revision, "comment": "private comment"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
add(f.item.ID, "created", "08", 0)
|
||||
add(f.item.ID, "rejected", "09", 0)
|
||||
add(f.item.ID, "created", "12", 0)
|
||||
add("source-a", "created", "01", 0)
|
||||
add("source-a", "combined_submitted", "02", 2)
|
||||
add("source-a", "combined_quality_rejected", "03", 2)
|
||||
add("source-a", "combined_submitted", "04", 3)
|
||||
add("source-a", "combined_quality_approved", "05", 3)
|
||||
add("source-a", "aggregate_acceptance_rejected", "09", 0)
|
||||
add("source-a", "combined_quality_approved", "11", 3)
|
||||
add("source-a", "combined_quality_approved", "13", 9)
|
||||
add("source-b", "combined_submitted", "06", 4)
|
||||
add("wrong-batch", "combined_quality_approved", "05", 7)
|
||||
read := func(query string) reviewTrace {
|
||||
t.Helper()
|
||||
res := f.request(http.MethodGet, "/api/human-items/"+f.item.ID+"/review-trace"+query, f.reviewer, nil)
|
||||
var trace reviewTrace
|
||||
if res.Code != http.StatusOK || json.Unmarshal(res.Body.Bytes(), &trace) != nil {
|
||||
t.Fatalf("trace status=%d body=%s", res.Code, res.Body.String())
|
||||
}
|
||||
if trace.AuthorID != "" || trace.Author != "" || trace.Supplier != "" || strings.Contains(res.Body.String(), "private comment") {
|
||||
t.Fatalf("anonymous acceptance disclosed source metadata: %+v", trace)
|
||||
}
|
||||
return trace
|
||||
}
|
||||
a := read("?sourceItemId=source-a")
|
||||
if a.Revision != 3 || a.FirstSubmittedAt != "2026-01-02T00:00:00Z" ||
|
||||
a.QualityRejections == nil || *a.QualityRejections != 1 || a.Rejections == nil || *a.Rejections != 1 ||
|
||||
len(a.Events) != 6 || a.Events[0].Kind != "质检通过" || a.Events[1].Kind != "验收退回" {
|
||||
t.Fatalf("wrong source history: %+v", a)
|
||||
}
|
||||
for _, event := range a.Events {
|
||||
if strings.HasPrefix(event.ID, "source-") && (event.Actor != "" || event.Revision == 9) {
|
||||
t.Fatalf("source actor or newer revision exposed: %+v", event)
|
||||
}
|
||||
}
|
||||
b := read("?sourceItemId=source-b")
|
||||
if b.Revision != 4 || b.QualityRejections != nil || b.FirstSubmittedAt != "" || len(b.Events) != 2 {
|
||||
t.Fatalf("wrong legacy source history: %+v", b)
|
||||
}
|
||||
for _, query := range []string{"", "?sourceItemId=wrong-batch", "?sourceItemId=unlisted"} {
|
||||
got := read(query)
|
||||
if got.Revision != 0 || got.QualityRejections != nil || len(got.Events) != 1 {
|
||||
t.Fatalf("unexpected source read for %q: %+v", query, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type acceptanceAssemblyEventFailure struct {
|
||||
store.Store
|
||||
itemID string
|
||||
err error
|
||||
}
|
||||
|
||||
func (s acceptanceAssemblyEventFailure) AppendHumanEvent(ctx context.Context, event domain.HumanEventRecord) error {
|
||||
if event.ItemID == s.itemID && event.EventType == "created" {
|
||||
return s.err
|
||||
}
|
||||
return s.Store.AppendHumanEvent(ctx, event)
|
||||
}
|
||||
|
||||
func TestReviewTraceAcceptanceReassemblySurvivesMissingCreatedEvent(t *testing.T) {
|
||||
data, handler, quality, acceptance, source, aggregate := acceptanceProjectionFixture(t)
|
||||
ctx := t.Context()
|
||||
must := func(err error) {
|
||||
t.Helper()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
batch, err := data.GetHumanBatch(ctx, source.BatchID)
|
||||
must(err)
|
||||
task, err := data.GetAnnotationTask(ctx, source.LegacyTaskID)
|
||||
must(err)
|
||||
path := "/api/human-items/" + aggregate.ID + "/review-trace"
|
||||
read := func() reviewTrace {
|
||||
t.Helper()
|
||||
res := acceptanceProjectionRequest(handler, http.MethodGet, path, acceptance, nil)
|
||||
var trace reviewTrace
|
||||
if res.Code != http.StatusOK || json.Unmarshal(res.Body.Bytes(), &trace) != nil {
|
||||
t.Fatalf("trace status=%d body=%s", res.Code, res.Body.String())
|
||||
}
|
||||
return trace
|
||||
}
|
||||
add := func(id, kind, at string, revision int) {
|
||||
t.Helper()
|
||||
must(data.AppendHumanEvent(ctx, domain.HumanEventRecord{
|
||||
ID: id, ItemID: source.ID, OrganizationID: source.OrganizationID, EventType: kind,
|
||||
ActorUserID: quality.ID, CreatedAt: at, Payload: map[string]any{"annotationRevision": revision},
|
||||
}))
|
||||
}
|
||||
add("source-created", "created", "2026-01-01T00:00:00Z", 0)
|
||||
add("source-original-submit", "combined_submitted", "2026-01-02T00:00:00Z", 1)
|
||||
add("source-original-approval", "combined_quality_approved", "2026-01-03T00:00:00Z", 1)
|
||||
if original := read(); original.Revision != 1 || len(original.Events) != 2 {
|
||||
t.Fatalf("unexpected original trace: %+v", original)
|
||||
}
|
||||
|
||||
aggregate.Status = domain.HumanItemRejected
|
||||
must(data.UpsertHumanItem(ctx, *aggregate))
|
||||
task.CurrentRevision = 2
|
||||
must(data.UpsertAnnotationTask(ctx, *task))
|
||||
source.Subject.Payload = map[string]any{"materialization": map[string]any{"artifactId": "reassembled-artifact", "revision": 2}}
|
||||
must(data.UpsertHumanItem(ctx, *source))
|
||||
must(data.UpsertAnnotationRevision(ctx, domain.AnnotationRevisionRecord{
|
||||
ID: "reassembled-revision", OrganizationID: task.OrganizationID, TaskID: task.ID, Revision: 2,
|
||||
}))
|
||||
add("source-rework-rejected", "combined_quality_rejected", nowISO(), 1)
|
||||
add("source-rework-submit", "combined_submitted", nowISO(), 2)
|
||||
add("source-rework-approval", "combined_quality_approved", nowISO(), 2)
|
||||
|
||||
writeFailure := errors.New("injected failure after saving assembled acceptance payload")
|
||||
assembly := &server{store: acceptanceAssemblyEventFailure{Store: data, itemID: aggregate.ID, err: writeFailure}}
|
||||
if _, err := assembly.ensureFanyuV5PrePackageAcceptance(ctx, batch); !errors.Is(err, writeFailure) {
|
||||
t.Fatalf("expected injected event failure, got %v", err)
|
||||
}
|
||||
// The restarted assembly sees a complete ready payload and returns without
|
||||
// appending another event or overwriting the saved snapshots.
|
||||
restarted := &server{store: data}
|
||||
confirmed, err := restarted.ensureFanyuV5PrePackageAcceptance(ctx, batch)
|
||||
must(err)
|
||||
if confirmed {
|
||||
t.Fatal("reassembly must leave the item awaiting acceptance")
|
||||
}
|
||||
persisted, err := data.GetHumanItem(ctx, aggregate.ID)
|
||||
must(err)
|
||||
if persisted.Status != domain.HumanItemReady || persisted.Version != aggregate.Version+1 {
|
||||
t.Fatalf("reassembly was not persisted exactly once: %+v", persisted)
|
||||
}
|
||||
events, err := data.ListHumanTraceEvents(ctx, aggregate.OrganizationID, aggregate.ID)
|
||||
must(err)
|
||||
if len(events) != 1 || events[0].EventType != "created" || events[0].CreatedAt != aggregate.CreatedAt {
|
||||
t.Fatalf("expected only the original assembly event: %+v", events)
|
||||
}
|
||||
|
||||
later := parseISOTime(persisted.UpdatedAt).Add(time.Minute).Format(time.RFC3339Nano)
|
||||
add("source-post-assembly", "combined_quality_approved", later, 3)
|
||||
persisted.UpdatedAt = later
|
||||
must(data.UpsertHumanItem(ctx, *persisted))
|
||||
got := read()
|
||||
if got.Revision != 2 || got.QualityRejections == nil || *got.QualityRejections != 1 ||
|
||||
len(got.Events) != 5 || got.Events[0].ID != "source-rework-approval" ||
|
||||
got.Events[1].ID != "source-rework-submit" || got.Events[2].ID != "source-rework-rejected" {
|
||||
t.Fatalf("trace diverged from the saved assembly: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ import {
|
||||
import { userErrorMessage } from "../lib/user-error-message.js";
|
||||
import { stripTaskOpinionLines } from "../lib/task-scope-visibility.js";
|
||||
import { AcceptanceSourceOpinions } from "./AcceptanceSourceOpinions";
|
||||
import { ReviewTracePanel, useReviewTrace } from "./ReviewTrace";
|
||||
import { reviewCommandRequiresWrite, reviewShortcut } from "../lib/review-shortcuts.js";
|
||||
import type { ReviewViewingProps, ReviewViewingController, ReviewPosition } from "./review-viewing";
|
||||
import { ReviewCaptionDetails } from "./ReviewCaptions";
|
||||
@ -51,7 +50,6 @@ type PoseDraft = {
|
||||
overallGrade: string;
|
||||
};
|
||||
type Props = ReviewViewingProps & {
|
||||
reviewTraceEnabled?: boolean;
|
||||
key?: string;
|
||||
item: HumanItem;
|
||||
mine: boolean;
|
||||
@ -110,7 +108,7 @@ export function FinalAcceptanceWorkspace({
|
||||
onReviewEscape,
|
||||
reviewTimestampOpinions,
|
||||
reviewProblemPanel,
|
||||
reviewTraceEnabled,
|
||||
reviewTracePanel,
|
||||
}: Props) {
|
||||
const rawHuman = item.processingProfile === "raw_human";
|
||||
const payload = (item.subject?.payload || {}) as Record<string, any>;
|
||||
@ -257,8 +255,6 @@ export function FinalAcceptanceWorkspace({
|
||||
|
||||
const groups = useMemo(() => acceptanceSliceGroups(entries, responses), [entries, responses]);
|
||||
const active = groups.find((g) => g.id === activeId) || groups[0];
|
||||
const traceSource = (active?.entry ?? entries[0])?.sourceHumanItemId || "";
|
||||
const reviewTrace = useReviewTrace(reviewTraceEnabled ? item.id : "", item.version, traceSource);
|
||||
const activeKey = active ? acceptanceMetadataKey(item.id, active) : "";
|
||||
const member = (name: string) => active?.members.find((m: any) => m.name === name && m.contentAvailable);
|
||||
const left = member("left.mp4"),
|
||||
@ -1121,7 +1117,7 @@ export function FinalAcceptanceWorkspace({
|
||||
</div>
|
||||
<aside className="space-y-5 border-t border-[color:var(--app-border)] p-4 @min-[980px]:overflow-y-auto @min-[980px]:border-l @min-[980px]:border-t-0">
|
||||
<h3 className="text-sm font-semibold">验收面板</h3>
|
||||
{reviewTraceEnabled && <ReviewTracePanel key={traceSource} {...reviewTrace} stageId={item.currentStageId} />}
|
||||
{reviewTracePanel}
|
||||
<ReviewCaptionDetails caption={reviewCaption} sliceStart={0} originalVideoOffset={originalVideoStart} />
|
||||
{reviewProblemPanel}
|
||||
<AcceptanceSourceOpinions itemId={item.id} />
|
||||
|
||||
@ -12,7 +12,6 @@ export type ReviewTraceData = {
|
||||
revision: number;
|
||||
reviewer: string;
|
||||
rejections: number | null;
|
||||
qualityRejections?: number | null;
|
||||
events: TraceEvent[];
|
||||
};
|
||||
const text = (value: string | number | null | undefined) => (value === "" || value == null ? "-" : String(value));
|
||||
@ -25,25 +24,24 @@ const shortDate = (value?: string) => {
|
||||
return full.startsWith(year) ? full.slice(year.length) : full;
|
||||
};
|
||||
const version = (revision: number) => (revision > 0 ? `V${revision}` : "-");
|
||||
export function useReviewTrace(itemId: string, version: number, sourceItemId = "") {
|
||||
const [result, setResult] = useState<{ key: string; data: ReviewTraceData | null } | null>(null);
|
||||
const key = JSON.stringify([itemId, version, sourceItemId]);
|
||||
export function useReviewTrace(itemId: string, version: number) {
|
||||
const [result, setResult] = useState<{ key: string; data: ReviewTraceData } | null>(null);
|
||||
const key = `${itemId}:${version}`;
|
||||
useEffect(() => {
|
||||
if (!itemId) return;
|
||||
const controller = new AbortController();
|
||||
const query = sourceItemId ? `?${new URLSearchParams({ sourceItemId })}` : "";
|
||||
void apiRequest<ReviewTraceData>(`/api/human-items/${encodeURIComponent(itemId)}/review-trace${query}`, {
|
||||
void apiRequest<ReviewTraceData>(`/api/human-items/${encodeURIComponent(itemId)}/review-trace`, {
|
||||
signal: controller.signal,
|
||||
})
|
||||
.then((data) => {
|
||||
if (!controller.signal.aborted) setResult({ key, data });
|
||||
})
|
||||
.catch(() => {
|
||||
if (!controller.signal.aborted) setResult({ key, data: null });
|
||||
if (!controller.signal.aborted) setResult(null);
|
||||
});
|
||||
return () => controller.abort();
|
||||
}, [itemId, key, sourceItemId]);
|
||||
return result?.key === key ? { data: result.data, failed: !result.data } : { data: null, failed: false };
|
||||
}, [itemId, key]);
|
||||
return result?.key === key ? result.data : null;
|
||||
}
|
||||
function TraceRows({ events, compact }: { events: TraceEvent[]; compact?: boolean }) {
|
||||
if (!events.length) return <li className="py-1 text-xs text-slate-500 dark:text-slate-400">-</li>;
|
||||
@ -54,11 +52,9 @@ function TraceRows({ events, compact }: { events: TraceEvent[]; compact?: boolea
|
||||
<span className="review-trace-version">{version(event.revision)}</span>
|
||||
<span className="min-w-0 truncate">
|
||||
<span className="font-medium">{event.kind}</span>
|
||||
{event.actor && (
|
||||
<span className="ml-1.5 text-slate-500 dark:text-slate-400" title={event.actor}>
|
||||
{event.actor}
|
||||
</span>
|
||||
)}
|
||||
<span className="ml-1.5 text-slate-500 dark:text-slate-400" title={text(event.actor)}>
|
||||
{text(event.actor)}
|
||||
</span>
|
||||
</span>
|
||||
<time className="tabular-nums text-slate-500 dark:text-slate-400" dateTime={event.at}>
|
||||
{compact ? shortDate(event.at) : date(event.at)}
|
||||
@ -69,16 +65,7 @@ function TraceRows({ events, compact }: { events: TraceEvent[]; compact?: boolea
|
||||
);
|
||||
}
|
||||
/** Source facts and the latest transitions share one card at the top of the review side column. */
|
||||
export function ReviewTracePanel({
|
||||
data,
|
||||
stageId,
|
||||
failed,
|
||||
}: {
|
||||
data: ReviewTraceData | null;
|
||||
stageId?: string;
|
||||
failed: boolean;
|
||||
key?: string;
|
||||
}) {
|
||||
export function ReviewTracePanel({ data, stageId }: { data: ReviewTraceData | null; stageId?: string; key?: string }) {
|
||||
const dialog = useRef<HTMLDialogElement>(null);
|
||||
const events = data?.events || [];
|
||||
const rejections = data?.rejections;
|
||||
@ -86,45 +73,30 @@ export function ReviewTracePanel({
|
||||
const fields: [string, string, string?][] = [
|
||||
["标注员", text(data?.author)],
|
||||
["供应商", text(data?.supplier)],
|
||||
[acceptance ? "验收员" : "审核员", text(data?.reviewer)],
|
||||
["审核员", text(acceptance ? null : data?.reviewer)],
|
||||
["验收员", text(acceptance ? data?.reviewer : null)],
|
||||
["标注员ID", text(data?.authorId), "font-mono"],
|
||||
["首次提交", date(data?.firstSubmittedAt), "col-span-2"],
|
||||
];
|
||||
if (!acceptance) {
|
||||
fields.splice(3, 0, ["验收员", "-"]);
|
||||
}
|
||||
const visibleFields = acceptance
|
||||
? fields.filter(([label, value]) => value !== "-" || label === "验收员" || label === "首次提交")
|
||||
: fields;
|
||||
return (
|
||||
<section data-testid="review-trace-panel" className="review-trace-card" aria-label="审查追溯">
|
||||
<details open>
|
||||
<summary className="review-trace-summary">
|
||||
<span className="shrink-0 whitespace-nowrap font-semibold">审查追溯</span>
|
||||
<span className="ml-auto flex flex-wrap items-center justify-end gap-1.5">
|
||||
<span className="font-semibold">审查追溯</span>
|
||||
<span className="ml-auto flex items-center gap-1.5">
|
||||
<span className="review-trace-chip" title="当前版本">
|
||||
{version(data?.revision || 0)}
|
||||
</span>
|
||||
{acceptance && (
|
||||
<span className={cn("review-trace-chip", (data?.qualityRejections ?? 0) > 0 && "is-warning")}>
|
||||
质检退回 {text(data?.qualityRejections)}
|
||||
</span>
|
||||
)}
|
||||
<span
|
||||
className={cn("review-trace-chip", typeof rejections === "number" && rejections > 0 && "is-warning")}
|
||||
title={acceptance ? "验收退回次数" : "打回次数"}
|
||||
title="打回次数"
|
||||
>
|
||||
{acceptance ? "验收退回" : "打回"} {text(rejections)}
|
||||
打回 {text(rejections)}
|
||||
</span>
|
||||
</span>
|
||||
</summary>
|
||||
{!data && (
|
||||
<p className="px-2 py-1 text-xs" role="status">
|
||||
{failed ? "审查追溯加载失败" : "加载中…"}
|
||||
</p>
|
||||
)}
|
||||
<dl className="review-trace-fields" data-testid="review-trace-source">
|
||||
{visibleFields.map(([label, value, variant]) => (
|
||||
{fields.map(([label, value, variant]) => (
|
||||
<div key={label} className={cn("min-w-0", variant === "col-span-2" && "col-span-2")}>
|
||||
<dt>{label}</dt>
|
||||
<dd className={cn("truncate", variant === "font-mono" && "font-mono")} title={value}>
|
||||
|
||||
@ -2628,10 +2628,10 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
reviewOnVerdict(focusId, resolved, resolved ? "" : previous && !previous.resolved ? previous.note || "" : "");
|
||||
if (!resolved) setReviewVerdictNoteFocus((current) => ({ opinionId: focusId, seq: (current?.seq || 0) + 1 }));
|
||||
};
|
||||
const traceItem = reviewOnly && workspaceMode !== "acceptance" ? reviewSessionItem : null;
|
||||
const traceItem = reviewOnly ? reviewSessionItem : null;
|
||||
const reviewTrace = useReviewTrace(traceItem?.id || "", traceItem?.version || 0);
|
||||
const reviewTracePanel = traceItem ? (
|
||||
<ReviewTracePanel key={traceItem.id} {...reviewTrace} stageId={traceItem.currentStageId} />
|
||||
<ReviewTracePanel key={traceItem.id} data={reviewTrace} stageId={traceItem.currentStageId} />
|
||||
) : null;
|
||||
const reviewProblemPanel =
|
||||
reviewSessionEnabled && reviewReceiptSupported ? (
|
||||
@ -7768,7 +7768,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
Boolean(reviewDraft.draft?.problems.some((problem) => problem.scope !== "task"))
|
||||
}
|
||||
reviewProblemPanel={reviewProblemPanel}
|
||||
reviewTraceEnabled={reviewOnly}
|
||||
reviewTracePanel={reviewTracePanel}
|
||||
onReviewNavigate={reviewDraft.onNavigate}
|
||||
onReviewPositionChange={reviewDraft.onPosition}
|
||||
onReviewController={reviewDraft.onController}
|
||||
|
||||
@ -112,22 +112,25 @@ try {
|
||||
console.log(await page.locator("body").innerText());
|
||||
throw e;
|
||||
}
|
||||
const latest = panel.getByRole("list", { name: "最近流转" });
|
||||
await latest.getByText(mode === "acceptance" ? "质检通过" : "审核退回", { exact: true }).waitFor();
|
||||
await page.waitForFunction(() =>
|
||||
document.querySelector('[data-testid="review-trace-panel"]')?.textContent.includes("审核退回"),
|
||||
);
|
||||
assert.equal(await panel.locator("details ol li").count(), 2);
|
||||
assert.equal(await page.getByTestId("review-source-strip").count(), 0, "no full-width source strip");
|
||||
const source = panel.getByTestId("review-trace-source");
|
||||
const summary = await panel.locator("summary").innerText();
|
||||
if (mode === "acceptance") {
|
||||
assert.match(summary, /V3[\s\S]*质检退回 1[\s\S]*验收退回 0/);
|
||||
assert.match(await source.innerText(), /验收员[\s\S]*首次提交[\s\S]*2026-01-02/);
|
||||
assert.equal(await source.getByText("审核员", { exact: true }).count(), 0);
|
||||
assert.equal(await latest.getByText("领取任务", { exact: true }).count(), 1);
|
||||
} else {
|
||||
for (const label of ["标注员", "供应商", "首次提交", "审核员", "验收员", "标注员ID"])
|
||||
assert.equal(await source.getByText(label, { exact: true }).count(), 1, label);
|
||||
assert.match(summary, /V\d+[\s\S]*打回 \d+/);
|
||||
}
|
||||
const source = await panel.getByTestId("review-trace-source").innerText();
|
||||
for (const label of ["标注员", "供应商", "首次提交", "审核员", "验收员", "标注员ID"])
|
||||
assert.ok(source.includes(label), label);
|
||||
const inactiveRole = mode === "acceptance" ? "审核员" : "验收员";
|
||||
assert.equal(
|
||||
await panel
|
||||
.locator("dl > div")
|
||||
.filter({ has: page.locator("dt", { hasText: new RegExp(`^${inactiveRole}$`) }) })
|
||||
.locator("dd")
|
||||
.innerText(),
|
||||
"-",
|
||||
"current reviewer identity must not be copied into the other role",
|
||||
);
|
||||
assert.match(await panel.locator("summary").innerText(), /V\d+[\s\S]*打回 \d+/);
|
||||
const pb = await panel.boundingBox(),
|
||||
side = await panel.evaluate((node) => node.parentElement.getBoundingClientRect().toJSON());
|
||||
assert.ok(pb.y - side.y <= 72, "trace card at top of side column");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user