forked from longtao.wu/droboticflow
Server: reject NEW task-scope problems on draft PUT (409 review_task_scope_deprecated, ID-matched against stored entries; existing entries round-trip unchanged, full-replace semantics kept); formal-rejection flattening no longer emits 整体任务 lines or expands ProblemSliceIDs; rework-baseline reads hide task problems (read-only narrowing); workforce stats stop counting task scope. Frontend: remove task from composer scope lists and card cycle; hide stored task opinions in rework banner/soft reminder/rail, QC panel groups and history, acceptance source projection, stats panel rows, frozen-comment displays (stripTaskOpinionLines); submit/approve gates count visible problems only; stats panel documents the 2026-10-14 scope switch. Data untouched: no migration, no deletion, audit trail intact.
110 lines
6.1 KiB
Go
110 lines
6.1 KiB
Go
package api
|
||
|
||
import (
|
||
"droboticflow/internal/domain"
|
||
"net/http"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
// ADR 0009:整体(task)作用域审核意见停用——服务端拒绝新增,存量原样回传。
|
||
// 新旧判定按意见身份:存量 = 草稿中已存在的 task 作用域问题 ID。
|
||
|
||
func TestReviewDraftRejectsNewTaskScopeProblems(t *testing.T) {
|
||
f := qualityReviewDraftFixture(t)
|
||
rv, h := openReviewDraftSession(t, f)
|
||
ep := "/api/human-items/" + f.item.ID + "/review-draft"
|
||
w := reviewSessionRequest(f, http.MethodPut, ep, f.reviewer, map[string]any{"modelVersion": 2, "version": 0, "resultVersion": rv, "operationId": "new-task", "problems": []map[string]any{{"id": "fresh", "scope": "task", "text": "新整体意见"}}}, h)
|
||
if w.Code != 409 || !strings.Contains(w.Body.String(), "review_task_scope_deprecated") {
|
||
t.Fatalf("new task problem accepted: %d %s", w.Code, w.Body.String())
|
||
}
|
||
if d := readReviewDraft(t, f, ep); len(d.Problems) != 0 {
|
||
t.Fatal("rejected save mutated draft")
|
||
}
|
||
w = reviewSessionRequest(f, http.MethodPut, ep, f.reviewer, map[string]any{"modelVersion": 2, "version": 0, "resultVersion": rv, "operationId": "slice-ok", "problems": []map[string]any{{"id": "s1", "scope": "slice", "sliceId": "left", "text": "切片意见", "atSeconds": 1}}}, h)
|
||
if w.Code != 200 {
|
||
t.Fatalf("slice save after rejection stranded session: %d %s", w.Code, w.Body.String())
|
||
}
|
||
}
|
||
|
||
func TestReviewDraftRoundTripsStoredTaskScopeProblems(t *testing.T) {
|
||
f := qualityReviewDraftFixture(t)
|
||
rv, h := openReviewDraftSession(t, f)
|
||
ep := "/api/human-items/" + f.item.ID + "/review-draft"
|
||
stored := []domain.ReviewProblem{
|
||
{ID: "legacy-task", Scope: "task", Text: "存量整体意见", TimeBasis: "task"},
|
||
{ID: "s1", Scope: "slice", SliceID: "left", Text: "切片意见", AtSeconds: 1, Start: 0, End: 5, TimeBasis: "capture-seconds"},
|
||
}
|
||
seedLegacyOpinionDraft(t, f, ep, stored)
|
||
d := readReviewDraft(t, f, ep)
|
||
checkProblemList(t, d, "legacy-task", "s1")
|
||
|
||
// GET 到的草稿原样 PUT:不报错、不丢失(隐藏存量不能被回传意外删除)。
|
||
w := reviewSessionRequest(f, http.MethodPut, ep, f.reviewer, map[string]any{"modelVersion": 2, "version": d.Version, "resultVersion": rv, "operationId": "roundtrip", "problems": d.Problems}, h)
|
||
if w.Code != 200 {
|
||
t.Fatalf("round trip rejected: %d %s", w.Code, w.Body.String())
|
||
}
|
||
after := readReviewDraft(t, f, ep)
|
||
p := checkProblemList(t, after, "legacy-task", "s1")
|
||
if p[0].Text != "存量整体意见" || p[0].TimeBasis != "task" {
|
||
t.Fatalf("stored task problem changed: %+v", p[0])
|
||
}
|
||
|
||
// 同 ID 的存量 task 条目随草稿原样保存不阻断(含文本整理)。
|
||
w = reviewSessionRequest(f, http.MethodPut, ep, f.reviewer, map[string]any{"modelVersion": 2, "version": after.Version, "resultVersion": rv, "operationId": "keep-task", "problems": []domain.ReviewProblem{{ID: "legacy-task", Scope: "task", Text: "存量整体意见", TimeBasis: "task"}, {ID: "s1", Scope: "slice", SliceID: "left", Text: "切片意见", AtSeconds: 1, Start: 0, End: 5, TimeBasis: "capture-seconds"}}}, h)
|
||
if w.Code != 200 {
|
||
t.Fatalf("stored task entry blocked: %d %s", w.Code, w.Body.String())
|
||
}
|
||
|
||
// 新 task 条目混入存量草稿仍被拒绝(ID 对账:新 ID ≠ 存量 ID)。
|
||
w = reviewSessionRequest(f, http.MethodPut, ep, f.reviewer, map[string]any{"modelVersion": 2, "version": readReviewDraft(t, f, ep).Version, "resultVersion": rv, "operationId": "sneak-task", "problems": []domain.ReviewProblem{{ID: "legacy-task", Scope: "task", Text: "存量整体意见", TimeBasis: "task"}, {ID: "sneaky", Scope: "task", Text: "冒名新增", TimeBasis: "task"}}}, h)
|
||
if w.Code != 409 || !strings.Contains(w.Body.String(), "review_task_scope_deprecated") {
|
||
t.Fatalf("sneaked task problem accepted: %d %s", w.Code, w.Body.String())
|
||
}
|
||
|
||
// 全量替换语义保持:显式清空(含 task 条目)依旧合法,PUT 是完整载荷。
|
||
w = reviewSessionRequest(f, http.MethodPut, ep, f.reviewer, map[string]any{"modelVersion": 2, "version": readReviewDraft(t, f, ep).Version, "resultVersion": rv, "operationId": "clear-all", "problems": []domain.ReviewProblem{}}, h)
|
||
if w.Code != 200 {
|
||
t.Fatalf("clear all blocked: %d %s", w.Code, w.Body.String())
|
||
}
|
||
if d := readReviewDraft(t, f, ep); len(d.Problems) != 0 {
|
||
t.Fatal("clear did not replace")
|
||
}
|
||
}
|
||
|
||
func TestReviewOpinionFlattenSkipsTaskScope(t *testing.T) {
|
||
evidence := []reviewTargetEvidence{{slices: []domain.SliceSegment{{ID: "left", Start: 0, End: 5}, {ID: "right", Start: 5, End: 10}}, actions: []domain.AnnotationSegment{{ID: "left-action", Start: 0, End: 5}}}}
|
||
problems := []domain.ReviewProblem{
|
||
{ID: "t1", Scope: "task", Text: "存量整体意见", TimeBasis: "task"},
|
||
{ID: "s1", Scope: "slice", SliceID: "left", Text: "切片意见", TimeBasis: "capture-seconds"},
|
||
}
|
||
if comment := reviewOpinionComment(problems, evidence); strings.Contains(comment, "整体") || !strings.Contains(comment, "切片 1:切片意见") {
|
||
t.Fatalf("task line leaked or slice line missing: %q", comment)
|
||
}
|
||
if ids := reviewOpinionSliceIDs(problems, evidence); len(ids) != 1 || ids[0] != "left" {
|
||
t.Fatalf("task scope expanded to slices: %v", ids)
|
||
}
|
||
// 存量 task-only 草稿:扁平化为空、不展开切片(正式打回不再生成「整体任务:」行)。
|
||
taskOnly := []domain.ReviewProblem{{ID: "t1", Scope: "task", Text: "只有整体", TimeBasis: "task"}}
|
||
if comment := reviewOpinionComment(taskOnly, evidence); comment != "" {
|
||
t.Fatalf("task-only comment not empty: %q", comment)
|
||
}
|
||
if ids := reviewOpinionSliceIDs(taskOnly, evidence); len(ids) != 0 {
|
||
t.Fatalf("task-only expanded slices: %v", ids)
|
||
}
|
||
}
|
||
|
||
func TestVisibleReworkBaselineProblemsHidesTaskScope(t *testing.T) {
|
||
baseline := &domain.ReworkBaselineRecord{Round: 1, Problems: []domain.ReviewProblem{
|
||
{ID: "t1", Scope: "task", Text: "整体意见", TimeBasis: "task"},
|
||
{ID: "s1", Scope: "slice", SliceID: "left", Text: "切片意见"},
|
||
}}
|
||
visible := visibleReworkBaselineProblems(baseline, nil)
|
||
if len(visible) != 1 || visible[0].ID != "s1" {
|
||
t.Fatalf("task problem visible in baseline: %+v", visible)
|
||
}
|
||
if len(baseline.Problems) != 2 {
|
||
t.Fatal("narrowing view mutated stored baseline")
|
||
}
|
||
}
|