forked from longtao.wu/droboticflow
🐛 Distinguish prior review decisions from current rework tasks
This commit is contained in:
parent
45981287be
commit
2b81adf2bf
38
.scratch/review-history-context-20261016/spec.md
Normal file
38
.scratch/review-history-context-20261016/spec.md
Normal file
@ -0,0 +1,38 @@
|
||||
# Distinguish past review decisions from current rework
|
||||
Status: resolved
|
||||
|
||||
Approved: preserve actual mine/reviewed membership, expose the requesting user's
|
||||
latest formal review decision (stage/round/revision/time) only in reviewed list
|
||||
responses, and display history separately from live workflow status. Identify
|
||||
rework review before generic quality/acceptance states. No customer data repair,
|
||||
new filter or migration; no push, PR or deployment in this task. Existing
|
||||
reviewHistoryStatus acceptance projection stays compatible. Legacy decision
|
||||
events without revision/time display only available evidence. Batch enrichment
|
||||
must not add one database query per item. Preserve server claim capabilities.
|
||||
|
||||
Reproduction: main repo local-data/verification/review-pool-20261016/findings.md.
|
||||
|
||||
|
||||
## Result
|
||||
|
||||
Implemented optional requesting-user reviewHistory summary, batched visible-page
|
||||
Mongo aggregation and matching memory behavior. Review history and live workflow
|
||||
status render separately; rework-review precedence and filter repaired, existing
|
||||
claim permissions and mine/reviewed membership unchanged. Acceptance cards also
|
||||
render summaries when returned. No migration or task writes.
|
||||
|
||||
## Verification
|
||||
|
||||
Red: API regression failed with missing past-decision summary; executable actual
|
||||
frontend status function returned pending_quality instead of rework_review.
|
||||
Green: reviewed/acceptance API regressions, memory and real local Mongo aggregate
|
||||
tests, executable status and actual React-render summary tests all passed.
|
||||
Full Go gate: 70 known / 70 baseline, no new failures. Full frontend gate: 13 known
|
||||
/ 14 baseline, no new failures; baseline untouched. Lint, formatting and web build
|
||||
passed. CUA switched synthetic UI between mine/history and confirmed prior
|
||||
rejected revision/round/date alongside current owned rework, history read-only.
|
||||
This browser fixture does not simulate a production save or claim; backend
|
||||
membership/summary behavior is verified via real handler and local Mongo tests.
|
||||
No production writes, new online verification, PR, push or deployment performed.
|
||||
Logs: local-data/pr-checks/review-history-* in this worktree. Screenshot: main
|
||||
repo local-data/verification/review-pool-20261016/fixed-history.png.
|
||||
@ -116,3 +116,12 @@
|
||||
| Shift+Delete | 清除选中卡片本轮意见 |
|
||||
|
||||
标注工作台快捷键(C 分割、E 切片重设面板、冲突清单键位等)见《标注键盘指南》,返工沿用同一套。
|
||||
|
||||
|
||||
## 审核历史与当前待办(2026-10-16)
|
||||
|
||||
“我的任务”表示当前归本人处理的任务;“我已审核”表示本人曾正式通过或打回的历史任务,按任务去重。同一任务被打回、返工重提并重新领取后,会同时出现在两处:上轮的审核已经完成,新一轮仍待复审。不要通过清空领取人或伪造审核完成来消除交集。
|
||||
|
||||
“我已审核”的列表另列“上次审核”结果、已审版本、轮次和时间;任务状态徽标仍表示当前流程进度。返工重提的质检/终审优先显示“返工复审”,已完成的最终状态优先于复审标记。“我的任务”中的本人已领复审显示“当前:返工待复审 · 您已领取”。历史查看不授予编辑权,服务端权限及领取能力不变。
|
||||
|
||||
接口兼容:`GET /api/human-items?pool=reviewed` 新增可选只读字段 `reviewHistory`(decision/stageId/revision/round/reviewedAt),只取当前请求人的最近正式决策,按 itemVersion、createdAt、id 倒序选取。其他池不返回该字段;原 `reviewHistoryStatus` 的终审进度投影保持不变。旧事件缺少版本/轮次/时间时省略未知值,不推定新一轮已完成。不修改历史记录,不需要数据迁移,旧客户端可忽略新增字段。摘要按已通过权限检查的可见页一次聚合,不逐任务查库。
|
||||
|
||||
@ -436,6 +436,24 @@ func (server *server) handleHumanItemsList(writer http.ResponseWriter, request *
|
||||
hasMore = true
|
||||
}
|
||||
if pool == "reviewed" {
|
||||
ids := make([]string, 0, len(filtered))
|
||||
for _, item := range filtered {
|
||||
ids = append(ids, item.ID)
|
||||
}
|
||||
events, err := server.store.ListLatestReviewEvents(request.Context(), server.requestOrganizationID(request), principal.User.ID, ids)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
for index := range filtered {
|
||||
if event, ok := events[filtered[index].ID]; ok {
|
||||
filtered[index].ReviewHistory = &domain.HumanReviewHistory{Decision: strings.TrimPrefix(event.EventType, "combined_quality_"), StageID: event.StageID, Revision: intValue(event.Payload["reviewedRevision"]), ReviewedAt: event.CreatedAt}
|
||||
if event.Round > 0 || filtered[index].ReviewHistory.Revision > 0 {
|
||||
round := event.Round
|
||||
filtered[index].ReviewHistory.Round = &round
|
||||
}
|
||||
}
|
||||
}
|
||||
acceptanceIDs := []string{}
|
||||
for _, item := range filtered {
|
||||
if item.Status == domain.HumanItemAccepted && isFanyuV58ThreeRoleBatch(batchByID[item.BatchID]) {
|
||||
|
||||
@ -165,3 +165,80 @@ func TestAcceptanceReviewedPoolOwnDecisions(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestReviewedPoolSeparatesPastDecisionFromCurrentOwnedRework(t *testing.T) {
|
||||
f := newCombinedDraftFixture(t)
|
||||
item := f.item
|
||||
item.CurrentStageID = "quality_review"
|
||||
item.Status = domain.HumanItemClaimed
|
||||
item.AssignedUserID = f.reviewer.ID
|
||||
item.CurrentRevision = 3
|
||||
item.ReviewRound = 1
|
||||
if err := f.store.UpsertHumanItem(f.ctx, item); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, event := range []domain.HumanEventRecord{
|
||||
{ID: "old", OrganizationID: item.OrganizationID, ItemID: item.ID, ActorUserID: f.reviewer.ID, StageID: "quality_review", EventType: "combined_quality_rejected", Round: 0, CreatedAt: "2026-10-12T08:00:00Z", Payload: map[string]any{"reviewedRevision": 2}},
|
||||
{ID: "other-newer", OrganizationID: item.OrganizationID, ItemID: item.ID, ActorUserID: "someone-else", EventType: "approved", CreatedAt: "2026-10-14T08:00:00Z"},
|
||||
{ID: "claimed-newer", OrganizationID: item.OrganizationID, ItemID: item.ID, ActorUserID: f.reviewer.ID, EventType: "claimed", CreatedAt: "2026-10-13T08:00:00Z"},
|
||||
} {
|
||||
if err := f.store.AppendHumanEvent(f.ctx, event); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, pool := range []string{"mine", "reviewed"} {
|
||||
res := f.request(http.MethodGet, "/api/human-items?pool="+pool+"&projectId="+item.ProjectID, f.reviewer, nil)
|
||||
var body struct {
|
||||
Items []map[string]any `json:"items"`
|
||||
}
|
||||
if err := json.Unmarshal(res.Body.Bytes(), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.Code != 200 || len(body.Items) != 1 {
|
||||
t.Fatalf("%s: %d %s", pool, res.Code, res.Body.String())
|
||||
}
|
||||
row := body.Items[0]
|
||||
if row["status"] != "claimed" || row["currentStageId"] != "quality_review" || row["assignedUserId"] != f.reviewer.ID {
|
||||
t.Fatalf("live task changed: %v", row)
|
||||
}
|
||||
summary, ok := row["reviewHistory"].(map[string]any)
|
||||
if pool == "mine" {
|
||||
if ok {
|
||||
t.Fatal("history leaked into live pool")
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !ok || summary["decision"] != "rejected" || summary["revision"] != float64(2) || summary["round"] != float64(0) || summary["reviewedAt"] != "2026-10-12T08:00:00Z" {
|
||||
t.Fatalf("past decision missing: %v", summary)
|
||||
}
|
||||
}
|
||||
source, _ := f.store.GetHumanItem(f.ctx, item.ID)
|
||||
if source.Status != domain.HumanItemClaimed || source.Version != item.Version {
|
||||
t.Fatal("list mutated source")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReviewedPoolLegacyDecisionDoesNotInventRevisionOrRound(t *testing.T) {
|
||||
f := newCombinedDraftFixture(t)
|
||||
if err := f.store.AppendHumanEvent(f.ctx, domain.HumanEventRecord{ID: "legacy-decision", OrganizationID: f.item.OrganizationID, ItemID: f.item.ID, ActorUserID: f.reviewer.ID, EventType: "rejected"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res := f.request(http.MethodGet, "/api/human-items?pool=reviewed", f.reviewer, nil)
|
||||
var body struct {
|
||||
Items []map[string]any `json:"items"`
|
||||
}
|
||||
_ = json.Unmarshal(res.Body.Bytes(), &body)
|
||||
if res.Code != 200 || len(body.Items) != 1 {
|
||||
t.Fatalf("%d %s", res.Code, res.Body.String())
|
||||
}
|
||||
summary, ok := body.Items[0]["reviewHistory"].(map[string]any)
|
||||
if !ok || summary["decision"] != "rejected" {
|
||||
t.Fatalf("legacy decision missing: %v", summary)
|
||||
}
|
||||
if _, ok := summary["revision"]; ok {
|
||||
t.Fatal("invented legacy revision")
|
||||
}
|
||||
if _, ok := summary["round"]; ok {
|
||||
t.Fatal("invented legacy round")
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,7 +132,18 @@ type HumanBatchRecord struct {
|
||||
UpdatedAt string `json:"updatedAt" bson:"updatedAt"`
|
||||
}
|
||||
|
||||
// HumanReviewHistory is a read-only summary of the requesting user's last
|
||||
// formal decision, not the current workflow state or a permission credential.
|
||||
type HumanReviewHistory struct {
|
||||
Decision string `json:"decision"`
|
||||
StageID string `json:"stageId,omitempty"`
|
||||
Revision int `json:"revision,omitempty"`
|
||||
Round *int `json:"round,omitempty"`
|
||||
ReviewedAt string `json:"reviewedAt,omitempty"`
|
||||
}
|
||||
|
||||
type HumanItemRecord struct {
|
||||
ReviewHistory *HumanReviewHistory `json:"reviewHistory,omitempty" bson:"-"`
|
||||
CanClaim *bool `json:"canClaim,omitempty" bson:"-"`
|
||||
AcceptanceClaim *AcceptanceClaimAccess `json:"acceptanceClaim,omitempty" bson:"acceptanceClaim,omitempty"`
|
||||
ReviewHistoryStatus string `json:"reviewHistoryStatus,omitempty" bson:"-"`
|
||||
|
||||
@ -966,3 +966,51 @@ func (store *MongoStore) ListReviewedHumanItemIDs(ctx context.Context, organizat
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// Only enrich the visible page; the caller still applies normal task access
|
||||
// checks. One aggregate for the page, never one history query per task.
|
||||
func (store *MongoStore) ListLatestReviewEvents(ctx context.Context, org, actor string, ids []string) (map[string]domain.HumanEventRecord, error) {
|
||||
result := map[string]domain.HumanEventRecord{}
|
||||
if len(ids) == 0 {
|
||||
return result, nil
|
||||
}
|
||||
cursor, err := store.humanEvents.Aggregate(ctx, mongo.Pipeline{
|
||||
{{Key: "$match", Value: bson.M{"organizationId": normalizedOrganizationID(org), "actorUserId": actor, "itemId": bson.M{"$in": ids}, "eventType": bson.M{"$in": []string{"approved", "rejected", "combined_quality_approved", "combined_quality_rejected"}}}}},
|
||||
{{Key: "$project", Value: bson.M{"_id": 0, "id": 1, "itemId": 1, "eventType": 1, "stageId": 1, "round": 1, "createdAt": 1, "itemVersion": 1, "payload.reviewedRevision": 1}}},
|
||||
{{Key: "$sort", Value: bson.D{{Key: "itemId", Value: 1}, {Key: "itemVersion", Value: -1}, {Key: "createdAt", Value: -1}, {Key: "id", Value: -1}}}},
|
||||
{{Key: "$group", Value: bson.M{"_id": "$itemId", "event": bson.M{"$first": "$$ROOT"}}}},
|
||||
{{Key: "$replaceRoot", Value: bson.M{"newRoot": "$event"}}},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close(ctx)
|
||||
for cursor.Next(ctx) {
|
||||
var event domain.HumanEventRecord
|
||||
if err := cursor.Decode(&event); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result[event.ItemID] = event
|
||||
}
|
||||
return result, cursor.Err()
|
||||
}
|
||||
func (store *MemoryStore) ListLatestReviewEvents(_ context.Context, org, actor string, ids []string) (map[string]domain.HumanEventRecord, error) {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
result := map[string]domain.HumanEventRecord{}
|
||||
for _, event := range store.humanEvents {
|
||||
if !humanOrganizationMatches(event.OrganizationID, org) || event.ActorUserID != actor || !containsHumanItemID(ids, event.ItemID) {
|
||||
continue
|
||||
}
|
||||
switch event.EventType {
|
||||
case "approved", "rejected", "combined_quality_approved", "combined_quality_rejected":
|
||||
default:
|
||||
continue
|
||||
}
|
||||
old, found := result[event.ItemID]
|
||||
if !found || event.ItemVersion > old.ItemVersion || (event.ItemVersion == old.ItemVersion && (event.CreatedAt > old.CreatedAt || (event.CreatedAt == old.CreatedAt && event.ID > old.ID))) {
|
||||
result[event.ItemID] = event
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
61
internal/store/review_history_context_test.go
Normal file
61
internal/store/review_history_context_test.go
Normal file
@ -0,0 +1,61 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"droboticflow/internal/domain"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func testLatestReviewEvents(t *testing.T, s Store) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
events := []domain.HumanEventRecord{
|
||||
{ID: "first-reject", OrganizationID: "history-org", ItemID: "one", ActorUserID: "reviewer", EventType: "combined_quality_rejected", ItemVersion: 2, Payload: map[string]any{"reviewedRevision": 1}},
|
||||
{ID: "later-approve", OrganizationID: "history-org", ItemID: "one", ActorUserID: "reviewer", EventType: "combined_quality_approved", ItemVersion: 5, Round: 1, Payload: map[string]any{"reviewedRevision": 2}},
|
||||
{ID: "later-claim", OrganizationID: "history-org", ItemID: "one", ActorUserID: "reviewer", EventType: "claimed", ItemVersion: 6},
|
||||
{ID: "other-person", OrganizationID: "history-org", ItemID: "one", ActorUserID: "other", EventType: "rejected", ItemVersion: 7},
|
||||
{ID: "other-org", OrganizationID: "foreign-org", ItemID: "one", ActorUserID: "reviewer", EventType: "rejected", ItemVersion: 8},
|
||||
{ID: "outside-page", OrganizationID: "history-org", ItemID: "two", ActorUserID: "reviewer", EventType: "approved", ItemVersion: 9},
|
||||
{ID: "legacy", OrganizationID: "history-org", ItemID: "legacy", ActorUserID: "reviewer", EventType: "rejected"},
|
||||
}
|
||||
for _, e := range events {
|
||||
if err := s.AppendHumanEvent(ctx, e); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
got, err := s.ListLatestReviewEvents(ctx, "history-org", "reviewer", []string{"one", "legacy"})
|
||||
if err != nil || len(got) != 2 || got["one"].ID != "later-approve" || got["legacy"].ID != "legacy" {
|
||||
t.Fatalf("wrong history projection: %v %v", got, err)
|
||||
}
|
||||
empty, err := s.ListLatestReviewEvents(ctx, "history-org", "reviewer", nil)
|
||||
if err != nil || len(empty) != 0 {
|
||||
t.Fatalf("empty page expanded: %v %v", empty, err)
|
||||
}
|
||||
}
|
||||
func TestLatestReviewEventsMemory(t *testing.T) { testLatestReviewEvents(t, NewMemoryStore()) }
|
||||
func TestLatestReviewEventsMongo(t *testing.T) {
|
||||
uri := os.Getenv("POOL_LOCAL_MONGO_URI")
|
||||
if uri == "" {
|
||||
t.Skip("POOL_LOCAL_MONGO_URI required")
|
||||
}
|
||||
u, e := url.Parse(uri)
|
||||
if e != nil || u.Scheme != "mongodb" || u.Host != "127.0.0.1:27018" {
|
||||
t.Fatal("isolated local snapshot Mongo only")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
client, e := mongo.Connect(ctx, options.Client().ApplyURI(uri))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer client.Disconnect(ctx)
|
||||
db := client.Database(fmt.Sprintf("test_review_history_%d", time.Now().UnixNano()))
|
||||
defer db.Drop(ctx)
|
||||
testLatestReviewEvents(t, &MongoStore{humanEvents: db.Collection("humanEvents")})
|
||||
}
|
||||
@ -314,6 +314,7 @@ type Store interface {
|
||||
ListHumanStageAttempts(context.Context, string, string) ([]domain.HumanStageAttemptRecord, error)
|
||||
UpsertHumanStageAttempt(context.Context, domain.HumanStageAttemptRecord) error
|
||||
ListReviewedHumanItemIDs(context.Context, string, string) ([]string, error)
|
||||
ListLatestReviewEvents(context.Context, string, string, []string) (map[string]domain.HumanEventRecord, error)
|
||||
ListHumanEvents(context.Context, string, string) ([]domain.HumanEventRecord, error)
|
||||
AppendHumanEvent(context.Context, domain.HumanEventRecord) error
|
||||
ListHumanRejects(context.Context, string, domain.HumanRejectQuery) ([]domain.HumanRejectRecord, error)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import type { HumanItem } from "../types";
|
||||
import { ReviewHistorySummary } from "./ReviewHistorySummary";
|
||||
import { cn } from "../lib/utils";
|
||||
import { acceptanceTaskAction } from "../lib/acceptance-workspace.js";
|
||||
|
||||
@ -27,6 +28,7 @@ export function AcceptanceTaskCard({
|
||||
onContinue?: () => void;
|
||||
}) {
|
||||
const completed = ["accepted", "released"].includes(item.status);
|
||||
const reworkReview = !completed && item.status !== "rejected" && Number(item.reviewRound || 0) > 0;
|
||||
const entries = Array.isArray(item.subject?.payload?.items) ? item.subject.payload.items : [];
|
||||
const seconds = entries.reduce(
|
||||
(total: number, entry: any) => total + Math.max(0, Number(entry.materialization?.coverage?.durationSeconds) || 0),
|
||||
@ -50,12 +52,13 @@ export function AcceptanceTaskCard({
|
||||
{name}
|
||||
</span>
|
||||
<span className="shrink-0 rounded-full border border-blue-300 bg-blue-50 px-2 py-0.5 text-[9px] text-blue-700">
|
||||
{completed ? "已完成" : item.status === "rejected" ? "已打回" : "待验收"}
|
||||
{completed ? "已完成" : item.status === "rejected" ? "已打回" : reworkReview ? "返工复审" : "待验收"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-1 text-[10px] text-slate-500">
|
||||
{seconds > 0 ? `${seconds.toFixed(2)}s` : "Capture 验收任务"}
|
||||
</div>
|
||||
{item.reviewHistory && <ReviewHistorySummary history={item.reviewHistory} />}
|
||||
<div className="mt-2 truncate text-[10px] text-slate-500">
|
||||
{item.status === "rejected"
|
||||
? "已退回质检"
|
||||
|
||||
16
src/components/ReviewHistorySummary.tsx
Normal file
16
src/components/ReviewHistorySummary.tsx
Normal file
@ -0,0 +1,16 @@
|
||||
import type { HumanItem } from "../types";
|
||||
|
||||
/** History never replaces current task status and never grants edit access. */
|
||||
export function ReviewHistorySummary({ history }: { history?: HumanItem["reviewHistory"] }) {
|
||||
if (!history) return <div className="mt-1 text-[10px] text-slate-500">审核历史:旧记录缺少结果摘要</div>;
|
||||
const date = history.reviewedAt ? new Date(history.reviewedAt) : undefined;
|
||||
const time = date && !Number.isNaN(date.getTime()) ? date.toLocaleString("zh-CN", { hour12: false }) : "";
|
||||
return (
|
||||
<div data-testid="review-history-summary" className="mt-1 text-[10px] text-slate-600 dark:text-slate-400">
|
||||
上次审核:{history.decision === "rejected" ? "已打回" : "已通过"}
|
||||
{history.revision ? ` · 版本 ${history.revision}` : ""}
|
||||
{typeof history.round === "number" ? ` · 第 ${history.round + 1} 轮` : ""}
|
||||
{time && <span className="block">{time}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -14,6 +14,7 @@ import { formatAnnotationTime } from "../lib/annotation-time.js";
|
||||
* - acceptance workspace render ...... `<FinalAcceptanceWorkspace` (stats/draft/comment/onApprove wiring)
|
||||
* - review session status bars ....... `review-session-status` · `review-decision-status` (pending-decision banner)
|
||||
*/
|
||||
import { ReviewHistorySummary } from "../components/ReviewHistorySummary";
|
||||
import { userErrorMessage } from "../lib/user-error-message.js";
|
||||
import { WorkforceStatisticsPanel } from "../components/WorkforceStatisticsPanel";
|
||||
import { useReviewProjectScope } from "../hooks/useReviewProjectScope";
|
||||
@ -262,6 +263,14 @@ export const deriveDetailedTaskStatus = (
|
||||
): DetailedTaskStatus => {
|
||||
if (humanItem?.reviewHistoryStatus) return humanItem.reviewHistoryStatus;
|
||||
if (humanItem?.status === "accepted" || task.status === "accepted") return "accepted";
|
||||
// B03 返工复查徽标:退回后再送检的质检任务(spec §5.4-6 队列徽标,不新造队列)。
|
||||
if (
|
||||
Number(humanItem?.reviewRound || 0) > 0 &&
|
||||
(humanItem?.currentStageId === "quality_review" ||
|
||||
humanItem?.currentStageId === "prepackage_acceptance" ||
|
||||
humanItem?.currentStageId === "acceptance")
|
||||
)
|
||||
return "rework_review";
|
||||
if (
|
||||
task.status === "pending_quality" ||
|
||||
humanItem?.currentStageId === "quality_review" ||
|
||||
@ -287,12 +296,6 @@ export const deriveDetailedTaskStatus = (
|
||||
(Number(humanItem?.reviewRound || 0) > 0 && humanItem?.currentStageId === "annotation_combined")
|
||||
)
|
||||
return "rework";
|
||||
// B03 返工复查徽标:退回后再送检的质检任务(spec §5.4-6 队列徽标,不新造队列)。
|
||||
if (
|
||||
Number(humanItem?.reviewRound || 0) > 0 &&
|
||||
(humanItem?.currentStageId === "quality_review" || humanItem?.currentStageId === "prepackage_acceptance")
|
||||
)
|
||||
return "rework_review";
|
||||
|
||||
if (livePhase === "materializing" || sliceWorkflow?.status === "processing") {
|
||||
return "slicing";
|
||||
@ -1680,17 +1683,29 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
...current,
|
||||
available: current.available.map((item) =>
|
||||
item.id === next.humanItem?.id
|
||||
? { ...next.humanItem!, reviewHistoryStatus: item.reviewHistoryStatus }
|
||||
? {
|
||||
...next.humanItem!,
|
||||
reviewHistoryStatus: item.reviewHistoryStatus,
|
||||
reviewHistory: item.reviewHistory,
|
||||
}
|
||||
: item,
|
||||
),
|
||||
mine: current.mine.map((item) =>
|
||||
item.id === next.humanItem?.id
|
||||
? { ...next.humanItem!, reviewHistoryStatus: item.reviewHistoryStatus }
|
||||
? {
|
||||
...next.humanItem!,
|
||||
reviewHistoryStatus: item.reviewHistoryStatus,
|
||||
reviewHistory: item.reviewHistory,
|
||||
}
|
||||
: item,
|
||||
),
|
||||
all: current.all.map((item) =>
|
||||
item.id === next.humanItem?.id
|
||||
? { ...next.humanItem!, reviewHistoryStatus: item.reviewHistoryStatus }
|
||||
? {
|
||||
...next.humanItem!,
|
||||
reviewHistoryStatus: item.reviewHistoryStatus,
|
||||
reviewHistory: item.reviewHistory,
|
||||
}
|
||||
: item,
|
||||
),
|
||||
}));
|
||||
@ -2384,7 +2399,11 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
const poolItem = visiblePoolItems.find((item) => item.legacyTaskId === task.id);
|
||||
const humanItem =
|
||||
task.id === selectedTaskId && detail?.humanItem
|
||||
? { ...detail.humanItem, reviewHistoryStatus: poolItem?.reviewHistoryStatus }
|
||||
? {
|
||||
...detail.humanItem,
|
||||
reviewHistoryStatus: poolItem?.reviewHistoryStatus,
|
||||
reviewHistory: poolItem?.reviewHistory,
|
||||
}
|
||||
: poolItem;
|
||||
const livePhase = task.id === selectedTaskId ? combinedEditorPhase : undefined;
|
||||
return [
|
||||
@ -6349,6 +6368,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
<option value="pending_annotation">待标注</option>
|
||||
<option value="rework">打回</option>
|
||||
<option value="pending_quality">已送检</option>
|
||||
<option value="rework_review">返工复审</option>
|
||||
<option value="pending_acceptance">待验收</option>
|
||||
<option value="accepted">已通过</option>
|
||||
</select>
|
||||
@ -6416,7 +6436,11 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
const poolItem = visibleHumanItemByTaskId.get(task.id);
|
||||
const humanItem =
|
||||
task.id === selectedTaskId && detail?.humanItem
|
||||
? { ...detail.humanItem, reviewHistoryStatus: poolItem?.reviewHistoryStatus }
|
||||
? {
|
||||
...detail.humanItem,
|
||||
reviewHistoryStatus: poolItem?.reviewHistoryStatus,
|
||||
reviewHistory: poolItem?.reviewHistory,
|
||||
}
|
||||
: poolItem;
|
||||
const livePhase = task.id === selectedTaskId ? combinedEditorPhase : undefined;
|
||||
const detailedStatus = deriveDetailedTaskStatus(task, humanItem, livePhase);
|
||||
@ -6440,7 +6464,10 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
const isTaskAccepted = detailedStatus === "accepted";
|
||||
const awaitingDownstream =
|
||||
workspaceMode === "annotate" &&
|
||||
(isTaskPendingQuality || isTaskPendingAcceptance || isTaskAccepted);
|
||||
(isTaskPendingQuality ||
|
||||
detailedStatus === "rework_review" ||
|
||||
isTaskPendingAcceptance ||
|
||||
isTaskAccepted);
|
||||
const taskAction = annotationTaskAction({
|
||||
awaitingDownstream: taskPoolView !== "reviewed" && awaitingDownstream,
|
||||
status: detailedStatus,
|
||||
@ -6541,7 +6568,15 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
}
|
||||
})()}
|
||||
</div>
|
||||
{taskPoolView === "reviewed" && (
|
||||
<ReviewHistorySummary history={poolItem?.reviewHistory} />
|
||||
)}
|
||||
<div className="mt-1.5 text-[10px] text-gray-500">
|
||||
{detailedStatus === "rework_review" &&
|
||||
(humanItem?.assignedUserId === currentUser?.id
|
||||
? "当前:返工待复审 · 您已领取。"
|
||||
: "当前:返工待复审。")}
|
||||
|
||||
{humanItem?.assignedUserId
|
||||
? `领取人:${assignee?.name || humanItem.assignedUserId}`
|
||||
: detailedStatus === "pending_quality"
|
||||
|
||||
@ -2192,6 +2192,14 @@ export interface HumanItem {
|
||||
/** Server-computed acceptance claim capability; never used as a write credential. */
|
||||
canClaim?: boolean;
|
||||
reviewHistoryStatus?: "pending_acceptance" | "accepted";
|
||||
/** Requesting user's last formal review; independent of current workflow. */
|
||||
reviewHistory?: {
|
||||
decision: "approved" | "rejected";
|
||||
stageId?: string;
|
||||
revision?: number;
|
||||
round?: number;
|
||||
reviewedAt?: string;
|
||||
};
|
||||
claimedAt?: string;
|
||||
processingScope?: "public" | "internal" | "supplier";
|
||||
processingProfile?: string;
|
||||
|
||||
1
tests/browser/fixtures/review-history.html
Normal file
1
tests/browser/fixtures/review-history.html
Normal file
@ -0,0 +1 @@
|
||||
<!doctype html><html><head><meta charset="utf-8"/><title>审核历史与返工待办回归</title></head><body><div id="root"></div><script type="module" src="/tests/browser/fixtures/review-history.tsx"></script></body></html>
|
||||
37
tests/browser/fixtures/review-history.tsx
Normal file
37
tests/browser/fixtures/review-history.tsx
Normal file
@ -0,0 +1,37 @@
|
||||
import { useState } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { ReviewHistorySummary } from "../../../src/components/ReviewHistorySummary";
|
||||
import { deriveDetailedTaskStatus } from "../../../src/pages/AnnotationOperations";
|
||||
import "../../../src/index.css";
|
||||
import type { HumanItem, AnnotationTaskRecord } from "../../../src/types";
|
||||
|
||||
const item = {
|
||||
id: "synthetic-history",
|
||||
status: "claimed",
|
||||
currentStageId: "quality_review",
|
||||
assignedUserId: "synthetic-reviewer",
|
||||
reviewRound: 1,
|
||||
reviewHistory: { decision: "rejected", revision: 2, round: 0, reviewedAt: "2026-10-12T08:25:07Z" },
|
||||
} as HumanItem;
|
||||
const task = { id: "synthetic-task", status: "pending_quality", currentRevision: 3 } as AnnotationTaskRecord;
|
||||
function Fixture() {
|
||||
const [view, setView] = useState("mine");
|
||||
const status = deriveDetailedTaskStatus(task, item);
|
||||
return (
|
||||
<main className="mx-auto max-w-xl space-y-4 p-8">
|
||||
<h1 className="text-xl font-semibold">审核历史与当前待办(合成数据)</h1>
|
||||
<p>上轮已打回,返工重提后重新领取;当前轮尚未审核。</p>
|
||||
<nav className="flex gap-4">
|
||||
<button onClick={() => setView("mine")}>我的任务</button>
|
||||
<button onClick={() => setView("reviewed")}>我已审核</button>
|
||||
</nav>
|
||||
<article className="rounded border p-4" data-testid="history-card">
|
||||
<h2>合成 Capture / part0001</h2>
|
||||
<p data-testid="current-status">{status === "rework_review" ? "当前:返工待复审 · 您已领取" : status}</p>
|
||||
{view === "reviewed" && <ReviewHistorySummary history={item.reviewHistory} />}
|
||||
<button disabled={view === "reviewed"}>{view === "reviewed" ? "历史只读" : "继续处理"}</button>
|
||||
</article>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
createRoot(document.getElementById("root")!).render(<Fixture />);
|
||||
67
tests/frontend/review-history-context.test.mjs
Normal file
67
tests/frontend/review-history-context.test.mjs
Normal file
@ -0,0 +1,67 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import ts from "typescript";
|
||||
const source = fs.readFileSync(new URL("../../src/pages/AnnotationOperations.tsx", import.meta.url), "utf8");
|
||||
const ast = ts.createSourceFile("page.tsx", source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
||||
const declaration = ast.statements.find(
|
||||
(s) =>
|
||||
ts.isVariableStatement(s) &&
|
||||
s.declarationList.declarations.some((d) => d.name.getText(ast) === "deriveDetailedTaskStatus"),
|
||||
);
|
||||
const js = ts.transpileModule(declaration.getText(ast), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
|
||||
}).outputText;
|
||||
const exports = {};
|
||||
new Function("exports", js)(exports);
|
||||
const derive = exports.deriveDetailedTaskStatus;
|
||||
test("rework review wins over generic sent-to-quality but terminal states remain final", () => {
|
||||
for (const stage of ["quality_review", "prepackage_acceptance", "acceptance"]) {
|
||||
assert.equal(
|
||||
derive(
|
||||
{ status: stage === "quality_review" ? "pending_quality" : "pending_acceptance" },
|
||||
{ currentStageId: stage, status: "claimed", reviewRound: 1 },
|
||||
),
|
||||
"rework_review",
|
||||
);
|
||||
}
|
||||
assert.equal(
|
||||
derive({ status: "accepted" }, { currentStageId: "quality_review", status: "accepted", reviewRound: 1 }),
|
||||
"accepted",
|
||||
);
|
||||
assert.equal(
|
||||
derive({ status: "pending_quality" }, { currentStageId: "quality_review", status: "claimed", reviewRound: 0 }),
|
||||
"pending_quality",
|
||||
);
|
||||
assert.equal(
|
||||
derive({ status: "rework" }, { currentStageId: "annotation_combined", status: "claimed", reviewRound: 1 }),
|
||||
"rework",
|
||||
);
|
||||
assert.equal(
|
||||
derive({ status: "accepted" }, { reviewHistoryStatus: "pending_acceptance", reviewRound: 1 }),
|
||||
"pending_acceptance",
|
||||
);
|
||||
});
|
||||
|
||||
test("history summary renders actual previous result and keeps missing legacy evidence unknown", async () => {
|
||||
const { createRequire } = await import("node:module");
|
||||
const require = createRequire(import.meta.url);
|
||||
const { renderToStaticMarkup } = require("react-dom/server");
|
||||
const { createElement } = require("react");
|
||||
const code = ts.transpileModule(
|
||||
fs.readFileSync(new URL("../../src/components/ReviewHistorySummary.tsx", import.meta.url), "utf8"),
|
||||
{ compilerOptions: { module: ts.ModuleKind.CommonJS, jsx: ts.JsxEmit.ReactJSX } },
|
||||
).outputText;
|
||||
const component = {};
|
||||
new Function("require", "exports", code)(require, component);
|
||||
const render = (history) => renderToStaticMarkup(createElement(component.ReviewHistorySummary, { history }));
|
||||
assert.match(
|
||||
render({ decision: "rejected", revision: 2, round: 0, reviewedAt: "2026-10-12T08:00:00Z" }),
|
||||
/上次审核:已打回.*版本 2.*第 1 轮/,
|
||||
);
|
||||
assert.match(render({ decision: "approved", revision: 3, round: 1 }), /上次审核:已通过.*版本 3.*第 2 轮/);
|
||||
const legacy = render({ decision: "rejected" });
|
||||
assert.match(legacy, /上次审核:已打回/);
|
||||
assert.doesNotMatch(legacy, /版本|第.*轮|Invalid/);
|
||||
assert.match(render(undefined), /旧记录缺少结果摘要/);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user