✨ Complete Fanyu production acceptance flows
This commit is contained in:
parent
629676e1d6
commit
1c008f68d5
@ -6,7 +6,7 @@
|
||||
|
||||
1. 由 CI/Kaniko 发布的 digest-pinned 镜像:`video-face-blur`、`qwen-temporal-localization`、`wilor-valid-event-detection`、`ms-swift-dataset-export`、`qwen-label-crop-classification`。
|
||||
2. PVC 中的 Qwen3-VL-8B-Instruct 固定 revision 快照和由 `scripts/verify_qwen3vl_model_manifest.py` 生成的两个 manifest 文件。
|
||||
3. 已就绪的 v5 供应商工作组 ID;当前验收暂不启用 Headpose/WiLoR。
|
||||
3. 已在目标项目中创建并启用的供应商,以及覆盖标注员、审核员和最终验收员的项目成员;安装工作流发布版时显式选择该供应商。
|
||||
4. 每个 Qwen/LoRA 节点的一张可调度 GPU;工作流已将 Qwen 推理串行化,不需要占用 GSStudio/HoloBrain GPU。
|
||||
5. `linux-arm64` 的 drosync DEB 和 portable tar;bundle builder 会校验文件 SHA-256、DEB `Architecture: arm64`、两个 AArch64 ELF、systemd installer,并拒绝 GUI 或其他 ABI。
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
# No secrets belong in this file. Inject credentials via the platform secret store.
|
||||
FANYU_V5_SUPPLIER_ID=
|
||||
FANYU_HEADPOSE_API_BASE_URL=
|
||||
FANYU_HEADPOSE_SERVICE_IMAGE_ID=
|
||||
FANYU_HEADPOSE_MODEL_SHA256=
|
||||
|
||||
@ -2,29 +2,31 @@
|
||||
|
||||
> 插件化重构后的通用状态机、API、分区释放和深链约定见 [Human Loop Core 与 Annotation QA 插件](./human-loop-plugin.md)。本页保留 Annotation QA 领域对象和兼容接口说明。
|
||||
|
||||
`/annotation-operations` 提供项目级语义模板、供应商分组、真实切分、逐段标注、审核、验收、返工和工时统计。平台全局角色负责登录后的工作台边界,项目成员关系进一步限定项目、供应商和工作组。v5.8 生产角色固定为三类:
|
||||
`/annotation-operations` 提供项目级语义模板、供应商、真实切分、逐段标注、审核、验收、返工和工时统计。平台账号角色负责组织级管理边界,`ProjectMember` 进一步限定项目、供应商和人工阶段。v5.8 生产角色固定为三类:
|
||||
|
||||
- `annotator`(标注员):在同一个原子提交中完成真实切分校正和语义标注;既可先切完再标,也可边切边标。
|
||||
- `quality_reviewer`(审核员):独立审核切分边界、左右目对应关系和语义标注,拒绝时把整条源任务退回标注员。
|
||||
- `acceptance_reviewer`(最终验收员):在自动打包前独立执行整包全量验收;拒绝时整包退回审核员,不得参与该批次标注审核。
|
||||
- `cutter`:只保留历史 v5.7 任务兼容,新建 v5.8 项目不再分配该角色。
|
||||
- `vendor_manager`:只聚合查看所管供应商/工作组的工作量和质量,不能读取任务媒体或执行审核。
|
||||
- `supplier_manager`:只聚合查看所属供应商的成员、工作量和质量,不能修改其他供应商或组织配置。
|
||||
|
||||
每个成员关系绑定 `projectId`、可选 `supplierId` 和三类项目角色。除组织管理员外,后端只返回当前用户所属项目和供应商范围内的任务、模板和工时事件;前端隐藏不是安全边界。
|
||||
|
||||
每个工作台均有“可领取”“我的任务”池;管理员额外拥有“全部任务”,并可通过带乐观锁版本的 `PATCH /api/human-items/{id}/assignment` 将任务改派给符合当前阶段角色和工作组成员关系的用户,或退回共享池。所有领取、释放、改派、提交、审核和打回都会追加 HumanEvent/StageAttempt 审计记录。
|
||||
每个工作台均有“可领取”“我的任务”池;管理员额外拥有“全部任务”,并可通过带乐观锁版本的 `PATCH /api/human-items/{id}/assignment` 将任务改派给同项目、同供应商且符合当前阶段角色的用户,或退回共享池。所有领取、释放、改派、提交、审核和打回都会追加 HumanEvent/StageAttempt 审计记录。
|
||||
|
||||
## 核心接口
|
||||
|
||||
- `GET/POST /api/annotation-workgroups`
|
||||
- `GET/POST /api/annotation-memberships`
|
||||
- `GET/POST /api/annotation-templates`
|
||||
- `POST /api/annotation-templates/{id}/publish`
|
||||
- `GET/POST /api/annotation-tasks`
|
||||
- `GET /api/annotation-tasks/{id}`
|
||||
- `POST /api/annotation-tasks/{id}/revisions`
|
||||
- `POST /api/annotation-tasks/{id}/reviews`
|
||||
- `GET /api/annotation-workload-summary`
|
||||
- `GET/POST /api/suppliers`
|
||||
- `GET/POST /api/projects/{id}/members`
|
||||
- `PATCH/DELETE /api/projects/{id}/members/{memberId}`
|
||||
- `POST /api/projects/{id}/members/bulk`:批量添加、批量改角色或批量移除。
|
||||
- `GET/POST /api/plugins/annotation-qa/templates`
|
||||
- `POST /api/plugins/annotation-qa/templates/{id}/publish`
|
||||
- `GET/POST /api/plugins/annotation-qa/tasks`
|
||||
- `GET /api/plugins/annotation-qa/tasks/{id}`
|
||||
- `POST /api/plugins/annotation-qa/tasks/{id}/combined-submissions`
|
||||
- `POST /api/plugins/annotation-qa/tasks/{id}/reviews`
|
||||
- `GET /api/plugins/annotation-qa/workload-summary`
|
||||
- `GET /api/human-items?pool=available|mine|all`
|
||||
- `POST /api/human-items/{id}/claim`
|
||||
- `POST /api/human-items/{id}/release`
|
||||
@ -38,16 +40,16 @@
|
||||
人工审核节点配置 `REVIEW_MODE=annotation` 后成为原生标注门,另外需要:
|
||||
|
||||
- `ANNOTATION_TEMPLATE_ID`:当前项目中已发布的模板。
|
||||
- `ANNOTATION_SUPPLIER_ID`:可选供应商 ID;留空时按项目成员关系确定。
|
||||
- `ANNOTATION_SUPPLIER_ID`:工作流安装到项目时绑定的供应商 ID。Release 本身不固化供应商;生产项目必须具有覆盖三个人工角色的可用供应商。
|
||||
- 新任务不接受 `ANNOTATION_ASSIGNED_USER_ID` 预分配;成员从 HumanItem 待领取池主动领取。
|
||||
|
||||
Worker 到达该节点后不会启动 Kubernetes Job,也不会创建通用 AuditTask。它会从上游真实视频与 Qwen 边界创建 AnnotationTask,并写入 `projectId`、`dataTaskId`、`workflowId`、`runId`、`nodeId`、`artifactId`。Run 保持 `waiting_for_audit`,直到该节点下所有任务依次完成:标注员真实切分与语义标注 → 审核员统一审核 → 最终验收员整包验收。验收通过后系统自动释放 Package child Run。
|
||||
Worker 到达该节点后不会启动 Kubernetes Job,也不会创建通用 AuditTask。它会从上游真实视频与 Qwen 边界创建 AnnotationTask,并写入 `projectId`、`dataTaskId`、`workflowId`、`runId`、`nodeId`、`artifactId`。Run 保持 `waiting_for_human`,直到该节点下所有任务依次完成:标注员真实切分与语义标注 → 审核员统一审核 → 最终验收员整包验收。验收通过后系统自动释放 Package child Run。
|
||||
|
||||
v5.8 不预先把长视频拆成多个人工 Task;同一个源任务可提交多个最终切片。无法局部调整的丢帧、流缺失或时间轴异常必须整条任务退回自动重处理,不允许用 FFmpeg 拼接近似修复。
|
||||
|
||||
v5.8 打包以绝对 `timestamp_us` 为权威时钟,按同一个半开窗口同步裁切左右视频、左右 PTS CSV 和 IMU accel/gyro;输出侧车统一为毫秒并保留 clip-relative 时间。Audio 与 audio PTS 不处理、不交付,camera/IMU calibration 原文件在批次根目录保留且不做内参差异管理。
|
||||
|
||||
标注审核通过后,Worker 生成 `droboticflow.annotation.accepted/v1` 的 `annotations-manifest.json`,记录模板版本、人工 revision、片段、artifact 和 Run lineage,然后从节点 `approved` 输出创建分区子 Run。成品打包完成后创建未分配的 Acceptance HumanItem;审核员领取并通过后才记录幂等最终导出快照,拒绝则进入拒绝区。
|
||||
标注审核通过后,Worker 生成 `droboticflow.annotation.accepted/v1` 的 `annotations-manifest.json`,记录模板版本、人工 revision、片段、artifact 和 Run lineage,然后从节点 `approved` 输出创建分区子 Run。成品打包前创建未分配的 Acceptance HumanItem;最终验收员领取并通过后才释放自动打包并记录幂等最终导出快照,拒绝则整包退回审核阶段。
|
||||
|
||||
`/annotation-operations` 支持通过以下参数从项目或监控页深链进入:
|
||||
|
||||
@ -68,7 +70,7 @@ v5.8 打包以绝对 `timestamp_us` 为权威时钟,按同一个半开窗口
|
||||
|
||||
## 工作量口径
|
||||
|
||||
首次 revision 产生 `outputDelta=1`;返工 revision 记录工时和返工次数,但 `outputDelta=0`,因此不会重复增加正式产出。质检、验收及拒绝原因分别记录为不可变工作量事件,汇总可按用户、供应商、分组和模板版本查询。
|
||||
首次 revision 产生 `outputDelta=1`;返工 revision 记录工时和返工次数,但 `outputDelta=0`,因此不会重复增加正式产出。质检、验收及拒绝原因分别记录为不可变工作量事件,汇总按用户、供应商和模板版本查询。
|
||||
|
||||
## 泛宇算子
|
||||
|
||||
|
||||
@ -10,9 +10,9 @@ Base path: `/api`
|
||||
- `GET /api/ai/status`: returns whether server-side AI generation is enabled and which model is configured
|
||||
- `POST /api/ai/operators/generate`: generate a custom operator definition from natural language
|
||||
- `POST /api/ai/workflows/generate`: generate a workflow graph from natural language and the current operator catalog
|
||||
- `GET /api/dashboard`: 管理员返回平台概览和供应商对比;`supplier_manager` 只返回其 `vendor_manager` 成员关系覆盖的团队指标,其他非管理员只返回本人工作量与质量。默认最近 30 天,`from/to` 最大 366 天。
|
||||
- `GET /api/dashboard`: 管理员返回平台概览和供应商对比;`supplier_manager` 只返回账号所属供应商的团队指标,其他非管理员只返回本人工作量与质量。默认最近 30 天,`from/to` 最大 366 天。
|
||||
|
||||
When `DROBOTICFLOW_REQUIRE_SESSION_AUTH=true`, AI generation routes require an admin or operator session. Run 列表、详情、日志、资源、通用 artifact 元数据/内容和 lineage 只允许管理员会话;机器 API token 继续用于受控自动化。标注/质检/验收通过 `/api/human-items/:id/subject-content` 读取经过工作组和阶段角色校验的媒体。
|
||||
When `DROBOTICFLOW_REQUIRE_SESSION_AUTH=true`, AI generation routes require an admin or operator session. Run 列表、详情、日志、资源、通用 artifact 元数据/内容和 lineage 只允许管理员会话;机器 API token 继续用于受控自动化。标注/质检/验收通过 `/api/human-items/:id/subject-content` 读取经过项目、供应商和阶段角色校验的媒体。
|
||||
|
||||
### Auth and Organizations
|
||||
|
||||
|
||||
@ -75,9 +75,8 @@ export OPERATOR_RUNNER_IMAGE=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow/drobo
|
||||
export HEADPOSE_SERVICE_IMAGE=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow/droboticflow-headpose-service:20260408
|
||||
export HEADPOSE_SERVICE_IMAGE_ID=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow/droboticflow-headpose-service@sha256:<64-hex-digest>
|
||||
export HEADPOSE_MODEL_SHA256=sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018
|
||||
# Required to publish the Fanyu v5 left-camera workflow release. Obtain this
|
||||
# from the verified POC annotation workgroup; do not invent an ID.
|
||||
export FANYU_V5_SUPPLIER_ID=<optional-supplier-id>
|
||||
# Supplier routing is bound when a published workflow is installed into a
|
||||
# project. It is deliberately not a deployment-wide environment variable.
|
||||
export OPERATOR_GPU_NODE_SELECTOR=accelerator=nvidia
|
||||
export OPERATOR_GPU_TOLERATIONS_JSON='[{"key":"nvidia.com/gpu","operator":"Exists","effect":"NoSchedule"}]'
|
||||
export OPERATOR_GPU_RUNTIME_CLASS=nvidia
|
||||
|
||||
@ -49,5 +49,5 @@ python3 scripts/verify_qwen3vl_model_manifest.py --model-root /workspace/models/
|
||||
1. 独立构建并发布 `directory-scan`、`orbbec-data-normalize`、`orbbec-left-undistort`、`video-face-blur`、`qwen-behavior-rough-cut` 与 `package` 镜像,写入 digest-pinned release manifest;YuNet 资产必须随 `video-face-blur` 镜像离线携带并通过 SHA/size/license 门禁。
|
||||
2. 预置并校验 Qwen3-VL 本地快照;当前无模型或未校验 manifest 即为预期 fail-closed 状态。
|
||||
3. 为 Qwen3-VL 语义粗切腾出 1 张 GPU;目录读取、人工阶段与打包不申请 GPU。
|
||||
4. 可选提供 `FANYU_V5_SUPPLIER_ID`;留空时按项目成员关系确定供应商。本版本不读取 `FANYU_HEADPOSE_*`。
|
||||
4. 供应商不再通过 API 容器全局环境变量固化到 Release;安装发布版到项目时必须选择一个已覆盖标注员、审核员和最终验收员的项目供应商。
|
||||
5. 仅在 `dev/poc` 验收环境中部署 `dev`,S100 使用同一镜像 digest 和以上 PVC/模型配置,不把草稿算子直接标为已发布。
|
||||
|
||||
@ -65,7 +65,7 @@ flowchart LR
|
||||
## 关键超参数
|
||||
|
||||
- `ANNOTATION_TEMPLATE_ID`:类型 `string`,默认值 空字符串或由工作流显式填写。当前项目中已发布的语义模板 ID 通常建议在工作流中显式配置。
|
||||
- `ANNOTATION_SUPPLIER_ID`:类型 `string`,默认值 空字符串或由工作流显式填写。可选的供应商 ID;留空时按项目成员关系自动确定 通常建议在工作流中显式配置。
|
||||
- `ANNOTATION_SUPPLIER_ID`:类型 `string`。工作流发布版安装到项目时由平台注入并校验;发布版快照本身不携带环境供应商。仅当项目恰有一个完整覆盖三个人工角色的供应商时才允许自动推导。
|
||||
- `REQUIRE_PREPACKAGE_ACCEPTANCE`:类型 `boolean`,默认值 `false`。全部切片统一质检通过后创建一个聚合的包前验收任务;验收仅允许确认 可直接使用默认值,也可在节点级覆盖。
|
||||
|
||||
## 执行前准备
|
||||
|
||||
@ -178,6 +178,35 @@ func TestCombinedSubmissionCanRequireEverySliceToBeCompleted(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCombinedSubmissionSupportsImmediateAsynchronousResponse(t *testing.T) {
|
||||
fixture := newCombinedDraftFixture(t)
|
||||
payload := map[string]any{
|
||||
"version": fixture.item.Version, "requireSliceCompletion": true,
|
||||
"sliceSegments": []map[string]any{{"id": "slice", "start": 0.0, "end": 10.0, "annotationStatus": "empty_confirmed"}},
|
||||
"segments": []any{},
|
||||
}
|
||||
encoded, _ := json.Marshal(payload)
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+fixture.task.ID+"/combined-submissions", bytes.NewReader(encoded))
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
request.Header.Set("Prefer", "respond-async")
|
||||
csrf := "combined-async-csrf"
|
||||
request.AddCookie(&http.Cookie{Name: csrfCookieName, Value: csrf})
|
||||
request.Header.Set(csrfHeaderName, csrf)
|
||||
request = request.WithContext(context.WithValue(request.Context(), authContextKey{}, &authenticatedPrincipal{User: fixture.annotator, Organization: domain.OrganizationRecord{ID: domain.DefaultOrganizationID, Status: domain.OrganizationStatusActive}}))
|
||||
recorder := httptest.NewRecorder()
|
||||
fixture.handler.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusAccepted {
|
||||
t.Fatalf("async combined submission status=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
var response map[string]any
|
||||
if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if response["status"] != "processing" || response["submissionId"] == "" {
|
||||
t.Fatalf("async combined submission response=%#v", response)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnnotationTaskGetEnrichesLinkedHumanItemDisplay(t *testing.T) {
|
||||
fixture := newCombinedDraftFixture(t)
|
||||
recorder := fixture.request(http.MethodGet, "/api/plugins/annotation-qa/tasks/"+fixture.task.ID, fixture.annotator, nil)
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"sort"
|
||||
@ -17,6 +19,32 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
type asynchronousAnnotationResponseWriter struct {
|
||||
header http.Header
|
||||
status int
|
||||
body strings.Builder
|
||||
}
|
||||
|
||||
func (writer *asynchronousAnnotationResponseWriter) Header() http.Header {
|
||||
if writer.header == nil {
|
||||
writer.header = http.Header{}
|
||||
}
|
||||
return writer.header
|
||||
}
|
||||
|
||||
func (writer *asynchronousAnnotationResponseWriter) WriteHeader(status int) {
|
||||
if writer.status == 0 {
|
||||
writer.status = status
|
||||
}
|
||||
}
|
||||
|
||||
func (writer *asynchronousAnnotationResponseWriter) Write(payload []byte) (int, error) {
|
||||
if writer.status == 0 {
|
||||
writer.status = http.StatusOK
|
||||
}
|
||||
return writer.body.Write(payload)
|
||||
}
|
||||
|
||||
func deprecatedAnnotationEndpoint(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(writer http.ResponseWriter, request *http.Request) {
|
||||
writer.Header().Set("Deprecation", "true")
|
||||
@ -104,8 +132,12 @@ func membershipAllowsTask(memberships []domain.ProjectAnnotationMembershipRecord
|
||||
if taskSupplierID == "" {
|
||||
taskSupplierID = task.VendorID
|
||||
}
|
||||
if membership.VendorID != "" && taskSupplierID != "" && membership.VendorID != taskSupplierID {
|
||||
continue
|
||||
if taskSupplierID != "" {
|
||||
// Current ProjectMember routing is supplier-scoped. An unscoped member
|
||||
// must never become a wildcard across suppliers.
|
||||
if strings.TrimSpace(membership.VendorID) != taskSupplierID {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if membership.WorkgroupID != "" && task.WorkgroupID != "" && membership.WorkgroupID != task.WorkgroupID {
|
||||
continue
|
||||
@ -610,7 +642,7 @@ type annotationTaskInput struct {
|
||||
ClipStart float64 `json:"clipStart"`
|
||||
ClipEnd float64 `json:"clipEnd"`
|
||||
TemplateID string `json:"templateId"`
|
||||
WorkgroupID string `json:"workgroupId"`
|
||||
SupplierID string `json:"supplierId"`
|
||||
AssignedUserID string `json:"assignedUserId,omitempty"`
|
||||
}
|
||||
|
||||
@ -867,20 +899,29 @@ func (server *server) handleAnnotationTaskCreate(writer http.ResponseWriter, req
|
||||
payload.ArtifactID = strings.TrimSpace(payload.ArtifactID)
|
||||
payload.SourceVideo = strings.TrimSpace(payload.SourceVideo)
|
||||
payload.TemplateID = strings.TrimSpace(payload.TemplateID)
|
||||
payload.WorkgroupID = strings.TrimSpace(payload.WorkgroupID)
|
||||
if payload.ProjectID == "" || payload.SourceVideo == "" || payload.TemplateID == "" || payload.WorkgroupID == "" || payload.ClipStart < 0 || payload.ClipEnd <= payload.ClipStart {
|
||||
renderValidationError(writer, validationIssue{Field: "task", Message: "projectId, sourceVideo, templateId, workgroupId and a valid clip range are required"})
|
||||
payload.SupplierID = strings.TrimSpace(payload.SupplierID)
|
||||
if payload.ProjectID == "" || payload.SourceVideo == "" || payload.TemplateID == "" || payload.SupplierID == "" || payload.ClipStart < 0 || payload.ClipEnd <= payload.ClipStart {
|
||||
renderValidationError(writer, validationIssue{Field: "task", Message: "projectId, sourceVideo, templateId, supplierId and a valid clip range are required"})
|
||||
return
|
||||
}
|
||||
project, projectErr := server.store.GetProject(request.Context(), payload.ProjectID)
|
||||
template, templateErr := server.store.GetAnnotationTemplate(request.Context(), payload.TemplateID)
|
||||
group, groupErr := server.store.GetAnnotationWorkgroup(request.Context(), payload.WorkgroupID)
|
||||
if projectErr != nil || templateErr != nil || groupErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, fmt.Errorf("load annotation task references: project=%v template=%v workgroup=%v", projectErr, templateErr, groupErr))
|
||||
supplier, supplierErr := server.store.GetSupplier(request.Context(), payload.SupplierID)
|
||||
if projectErr != nil || templateErr != nil || supplierErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, fmt.Errorf("load annotation task references: project=%v template=%v supplier=%v", projectErr, templateErr, supplierErr))
|
||||
return
|
||||
}
|
||||
if project == nil || template == nil || group == nil || template.ProjectID != project.ID || !annotationOrganizationEqual(project.OrganizationID, template.OrganizationID) || !annotationOrganizationEqual(project.OrganizationID, group.OrganizationID) {
|
||||
renderValidationError(writer, validationIssue{Field: "task", Message: "project, template and workgroup are incompatible"})
|
||||
if project == nil || template == nil || supplier == nil || template.ProjectID != project.ID || !annotationOrganizationEqual(project.OrganizationID, template.OrganizationID) || !annotationOrganizationEqual(project.OrganizationID, supplier.OrganizationID) || !strings.EqualFold(strings.TrimSpace(supplier.Status), "active") {
|
||||
renderValidationError(writer, validationIssue{Field: "task", Message: "project, template and active supplier are incompatible"})
|
||||
return
|
||||
}
|
||||
members, membersErr := server.store.ListProjectMembers(request.Context(), project.OrganizationID, project.ID)
|
||||
if membersErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, membersErr)
|
||||
return
|
||||
}
|
||||
if !supplierHasProductionHumanRoles(members, supplier.ID) {
|
||||
renderValidationError(writer, validationIssue{Field: "supplierId", Message: "supplier project members must cover annotator, quality reviewer and acceptance reviewer"})
|
||||
return
|
||||
}
|
||||
if template.Status != domain.AnnotationTemplatePublished {
|
||||
@ -901,8 +942,7 @@ func (server *server) handleAnnotationTaskCreate(writer http.ResponseWriter, req
|
||||
ClipEnd: payload.ClipEnd,
|
||||
TemplateID: template.ID,
|
||||
TemplateVersion: template.Version,
|
||||
WorkgroupID: group.ID,
|
||||
VendorID: group.VendorID,
|
||||
SupplierID: supplier.ID,
|
||||
AssignedUserID: "",
|
||||
Status: domain.AnnotationTaskStatusPendingAnnotation,
|
||||
CreatedAt: nowISO(),
|
||||
@ -919,7 +959,7 @@ func (server *server) handleAnnotationTaskCreate(writer http.ResponseWriter, req
|
||||
taskMode, isTemp := server.resolveTaskRunMode(request.Context(), item.RunID)
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: item.OrganizationID, ProjectID: item.ProjectID,
|
||||
TaskID: item.ID, UserID: annotationPrincipalUserID(principal), SupplierID: item.SupplierID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
TaskID: item.ID, UserID: annotationPrincipalUserID(principal), SupplierID: item.SupplierID,
|
||||
EventType: "created", Mode: taskMode, Temporary: isTemp, TemplateVersion: item.TemplateVersion, OutputDelta: 0, CreatedAt: nowISO(),
|
||||
})
|
||||
renderJSON(writer, http.StatusCreated, item)
|
||||
@ -1304,6 +1344,34 @@ func (server *server) handleCombinedAnnotationSubmission(writer http.ResponseWri
|
||||
now := nowISO()
|
||||
sliceRevision := domain.SliceRevisionRecord{ID: sliceID, OrganizationID: task.OrganizationID, TaskID: task.ID, Revision: revisionNumber, Segments: payload.SliceSegments, Operations: payload.SliceOperations, AuthorUserID: principal.User.ID, ChangeReason: submissionRef + ":" + strings.TrimSpace(payload.ChangeReason), DurationSeconds: payload.DurationSeconds, CreatedAt: now}
|
||||
annotationRevision := domain.AnnotationRevisionRecord{ID: annotationID, OrganizationID: task.OrganizationID, TaskID: task.ID, Revision: revisionNumber, TemplateVersion: task.TemplateVersion, Segments: payload.Segments, ObjectHints: payload.ObjectHints, AuthorUserID: principal.User.ID, ChangeReason: submissionRef + ":" + strings.TrimSpace(payload.ChangeReason), IsRework: isRework, CountsAsOutput: !isRework, DurationSeconds: payload.DurationSeconds, CreatedAt: now}
|
||||
if strings.Contains(strings.ToLower(request.Header.Get("Prefer")), "respond-async") {
|
||||
jobKey := humanItem.OrganizationID + ":" + submissionRef
|
||||
if _, loaded := server.combinedSubmissionJobs.LoadOrStore(jobKey, struct{}{}); !loaded {
|
||||
payloadBytes, marshalErr := json.Marshal(payload)
|
||||
if marshalErr != nil {
|
||||
server.combinedSubmissionJobs.Delete(jobKey)
|
||||
renderError(writer, http.StatusInternalServerError, marshalErr)
|
||||
return
|
||||
}
|
||||
backgroundRequest := request.Clone(context.WithoutCancel(request.Context()))
|
||||
backgroundRequest.Header = request.Header.Clone()
|
||||
backgroundRequest.Header.Del("Prefer")
|
||||
backgroundRequest.Body = io.NopCloser(bytes.NewReader(payloadBytes))
|
||||
backgroundRequest.ContentLength = int64(len(payloadBytes))
|
||||
go func() {
|
||||
defer server.combinedSubmissionJobs.Delete(jobKey)
|
||||
backgroundWriter := &asynchronousAnnotationResponseWriter{}
|
||||
server.handleCombinedAnnotationSubmission(backgroundWriter, backgroundRequest)
|
||||
if backgroundWriter.status >= http.StatusBadRequest {
|
||||
fmt.Printf("[api] asynchronous combined submission %s failed status=%d body=%s\n", submissionRef, backgroundWriter.status, strings.TrimSpace(backgroundWriter.body.String()))
|
||||
}
|
||||
}()
|
||||
}
|
||||
renderJSON(writer, http.StatusAccepted, map[string]any{
|
||||
"item": humanItem, "submissionId": submissionRef, "status": "processing", "idempotent": resumed,
|
||||
})
|
||||
return
|
||||
}
|
||||
materialization, materializationErr := server.materializeCombinedSliceSubmission(request.Context(), *task, *humanItem, payload, revisionNumber)
|
||||
if materializationErr != nil {
|
||||
previousVersion := humanItem.Version
|
||||
@ -1375,7 +1443,15 @@ func (server *server) handleCombinedAnnotationSubmission(writer http.ResponseWri
|
||||
if annotationRevision.CountsAsOutput {
|
||||
outputDelta = 1
|
||||
}
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, TaskID: task.ID, UserID: principal.User.ID, SupplierID: task.SupplierID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID, EventType: "combined_submitted", Mode: taskMode, Temporary: isTemp, Revision: annotationRevision.Revision, TemplateVersion: task.TemplateVersion, DurationSeconds: payload.DurationSeconds, OutputDelta: outputDelta, CreatedAt: now})
|
||||
outputDurationSeconds := payload.DurationSeconds
|
||||
if outputDurationSeconds <= 0 {
|
||||
var duration float64
|
||||
for _, slice := range sliceRevision.Segments {
|
||||
duration += math.Max(0, slice.End-slice.Start)
|
||||
}
|
||||
outputDurationSeconds = int64(math.Round(duration))
|
||||
}
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, TaskID: task.ID, UserID: principal.User.ID, SupplierID: task.SupplierID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID, EventType: "combined_submitted", Mode: taskMode, Temporary: isTemp, Revision: annotationRevision.Revision, TemplateVersion: task.TemplateVersion, DurationSeconds: outputDurationSeconds, OutputDelta: outputDelta, CreatedAt: now})
|
||||
status := http.StatusCreated
|
||||
if resumed {
|
||||
status = http.StatusOK
|
||||
@ -2335,13 +2411,19 @@ func (server *server) handleAnnotationWorkloadSummary(writer http.ResponseWriter
|
||||
renderError(writer, http.StatusInternalServerError, loadErr)
|
||||
return
|
||||
}
|
||||
allowed := map[string]struct{}{}
|
||||
allowedSuppliers := map[string]struct{}{}
|
||||
for _, membership := range memberships {
|
||||
allowed[membership.WorkgroupID] = struct{}{}
|
||||
if supplierID := strings.TrimSpace(membership.VendorID); supplierID != "" {
|
||||
allowedSuppliers[supplierID] = struct{}{}
|
||||
}
|
||||
}
|
||||
filtered := events[:0]
|
||||
for _, event := range events {
|
||||
if _, ok := allowed[event.WorkgroupID]; !ok {
|
||||
supplierID := strings.TrimSpace(event.SupplierID)
|
||||
if supplierID == "" {
|
||||
supplierID = strings.TrimSpace(event.VendorID)
|
||||
}
|
||||
if _, ok := allowedSuppliers[supplierID]; !ok {
|
||||
continue
|
||||
}
|
||||
if principal.User.Role == domain.UserRoleCutter || principal.User.Role == domain.UserRoleAnnotator || principal.User.Role == domain.UserRoleQualityReviewer || principal.User.Role == domain.UserRoleAcceptanceReviewer {
|
||||
@ -2371,15 +2453,19 @@ func (server *server) handleAnnotationWorkloadSummary(writer http.ResponseWriter
|
||||
events = modeFiltered
|
||||
|
||||
type key struct {
|
||||
userID, workgroupID, vendorID string
|
||||
templateVersion int
|
||||
userID, supplierID string
|
||||
templateVersion int
|
||||
}
|
||||
aggregates := map[key]*domain.AnnotationWorkloadAggregate{}
|
||||
for _, event := range events {
|
||||
groupKey := key{event.UserID, event.WorkgroupID, event.VendorID, event.TemplateVersion}
|
||||
supplierID := strings.TrimSpace(event.SupplierID)
|
||||
if supplierID == "" {
|
||||
supplierID = strings.TrimSpace(event.VendorID)
|
||||
}
|
||||
groupKey := key{event.UserID, supplierID, event.TemplateVersion}
|
||||
item := aggregates[groupKey]
|
||||
if item == nil {
|
||||
item = &domain.AnnotationWorkloadAggregate{UserID: event.UserID, WorkgroupID: event.WorkgroupID, VendorID: event.VendorID, TemplateVersion: event.TemplateVersion}
|
||||
item = &domain.AnnotationWorkloadAggregate{UserID: event.UserID, SupplierID: supplierID, TemplateVersion: event.TemplateVersion}
|
||||
aggregates[groupKey] = item
|
||||
}
|
||||
item.DurationSeconds += event.DurationSeconds
|
||||
@ -2406,8 +2492,8 @@ func (server *server) handleAnnotationWorkloadSummary(writer http.ResponseWriter
|
||||
items = append(items, *item)
|
||||
}
|
||||
sort.Slice(items, func(left int, right int) bool {
|
||||
leftKey := items[left].VendorID + "\x00" + items[left].WorkgroupID + "\x00" + items[left].UserID + "\x00" + strconv.Itoa(items[left].TemplateVersion)
|
||||
rightKey := items[right].VendorID + "\x00" + items[right].WorkgroupID + "\x00" + items[right].UserID + "\x00" + strconv.Itoa(items[right].TemplateVersion)
|
||||
leftKey := items[left].SupplierID + "\x00" + items[left].UserID + "\x00" + strconv.Itoa(items[left].TemplateVersion)
|
||||
rightKey := items[right].SupplierID + "\x00" + items[right].UserID + "\x00" + strconv.Itoa(items[right].TemplateVersion)
|
||||
return leftKey < rightKey
|
||||
})
|
||||
renderJSON(writer, http.StatusOK, domain.AnnotationWorkloadSummary{Items: items, EventCount: len(events)})
|
||||
|
||||
@ -50,8 +50,7 @@ func TestPopulateDashboardWorkforce_SkipsDebugEvents(t *testing.T) {
|
||||
ProjectID: "proj-1",
|
||||
TaskID: "task-1",
|
||||
UserID: "user-1",
|
||||
WorkgroupID: "group-1",
|
||||
VendorID: "vendor-1",
|
||||
SupplierID: "supplier-1",
|
||||
EventType: "annotation_submitted",
|
||||
Mode: domain.RunModeProduction,
|
||||
DurationSeconds: 120,
|
||||
@ -69,8 +68,7 @@ func TestPopulateDashboardWorkforce_SkipsDebugEvents(t *testing.T) {
|
||||
ProjectID: "proj-1",
|
||||
TaskID: "task-dbg-1",
|
||||
UserID: "user-1",
|
||||
WorkgroupID: "group-1",
|
||||
VendorID: "vendor-1",
|
||||
SupplierID: "supplier-1",
|
||||
EventType: "annotation_submitted",
|
||||
Mode: domain.RunModeDebug,
|
||||
Temporary: true,
|
||||
|
||||
@ -396,7 +396,7 @@ func (server *server) ensureFanyuDeliveryTemplateV58(ctx context.Context, organi
|
||||
node.Position.Y,
|
||||
map[string]string{
|
||||
"ANNOTATION_TEMPLATE_ID": annotationTemplateID,
|
||||
"ANNOTATION_SUPPLIER_ID": strings.TrimSpace(os.Getenv("FANYU_V5_SUPPLIER_ID")),
|
||||
"ANNOTATION_SUPPLIER_ID": "",
|
||||
"RELEASE_POLICY": "all_accepted",
|
||||
"PARTITION_MAX_ITEMS": "32",
|
||||
"MAX_REWORK_ROUNDS": "5",
|
||||
@ -570,7 +570,7 @@ func (server *server) ensureFanyuDeliveryTemplateV5(ctx context.Context, organiz
|
||||
operators[operatorID] = *operator
|
||||
}
|
||||
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", normalizedOrganizationID(organizationID))
|
||||
annotationSupplierID := strings.TrimSpace(os.Getenv("FANYU_V5_SUPPLIER_ID"))
|
||||
annotationSupplierID := ""
|
||||
nodes := []domain.WorkflowNode{
|
||||
fanyuNode("fanyu-v5-directory", "目录读取(必填)", operators[operatorIDs[0]], 0, 260),
|
||||
fanyuNodeWithHyperparams("fanyu-v5-normalize", "Orbbec Ego 左相机标准化", operators[operatorIDs[1]], 240, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
|
||||
@ -695,7 +695,7 @@ func (server *server) ensureFanyuDeliveryTemplateV54(ctx context.Context, organi
|
||||
}
|
||||
}
|
||||
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", organizationID)
|
||||
annotationSupplierID := strings.TrimSpace(os.Getenv("FANYU_V5_SUPPLIER_ID"))
|
||||
annotationSupplierID := ""
|
||||
nodes := []domain.WorkflowNode{
|
||||
fanyuMultiportNode("fanyu-v54-directory", "目录读取(多端口)", operators[operatorIDs[0]], 0, 260),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v54-normalize", "Orbbec Ego 左相机标准化(多端口)", operators[operatorIDs[1]], 260, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
|
||||
@ -809,7 +809,7 @@ func (server *server) ensureFanyuDeliveryTemplateV55(ctx context.Context, organi
|
||||
}
|
||||
}
|
||||
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", organizationID)
|
||||
annotationSupplierID := strings.TrimSpace(os.Getenv("FANYU_V5_SUPPLIER_ID"))
|
||||
annotationSupplierID := ""
|
||||
nodes := []domain.WorkflowNode{
|
||||
fanyuMultiportNode("fanyu-v55-directory", "目录读取(多端口)", operators[operatorIDs[0]], 0, 260),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v55-normalize", "Orbbec Ego 左相机标准化(多端口)", operators[operatorIDs[1]], 240, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
|
||||
@ -938,7 +938,7 @@ func (server *server) ensureFanyuDeliveryTemplateV56(ctx context.Context, organi
|
||||
}
|
||||
|
||||
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", organizationID)
|
||||
annotationSupplierID := strings.TrimSpace(os.Getenv("FANYU_V5_SUPPLIER_ID"))
|
||||
annotationSupplierID := ""
|
||||
headposeOverrides := map[string]string{
|
||||
"HEADPOSE_API_BASE_URL": strings.TrimSpace(os.Getenv("FANYU_HEADPOSE_API_BASE_URL")),
|
||||
"HEADPOSE_SERVICE_IMAGE_ID": strings.TrimSpace(os.Getenv("FANYU_HEADPOSE_SERVICE_IMAGE_ID")),
|
||||
|
||||
@ -1918,6 +1918,7 @@ func (server *server) ensureFanyuV5PrePackageAcceptance(ctx context.Context, sou
|
||||
ProjectID: source.ProjectID, WorkflowID: source.WorkflowID, RunID: source.RunID, GateNodeID: acceptanceBatch.GateNodeID,
|
||||
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: items[0].SupplierID, LegacyAssignment: items[0].LegacyAssignment,
|
||||
WorkgroupID: items[0].WorkgroupID, VendorID: items[0].VendorID, MaxReworkRounds: source.MaxReworkRounds, Version: 1, CreatedAt: now, UpdatedAt: now,
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -25,6 +25,12 @@ type projectMemberBulkInput struct {
|
||||
Action string `json:"action"`
|
||||
MemberIDs []string `json:"memberIds"`
|
||||
Roles []domain.AnnotationAssignmentRole `json:"roles,omitempty"`
|
||||
Entries []projectMemberInput `json:"entries,omitempty"`
|
||||
}
|
||||
|
||||
type projectMemberBulkResult struct {
|
||||
Created int `json:"created"`
|
||||
Updated int `json:"updated"`
|
||||
}
|
||||
|
||||
func isOrganizationAdmin(principal *authenticatedPrincipal) bool {
|
||||
@ -144,8 +150,8 @@ func (server *server) saveProjectMember(writer http.ResponseWriter, request *htt
|
||||
renderError(writer, http.StatusInternalServerError, supplierErr)
|
||||
return
|
||||
}
|
||||
if supplier == nil || !annotationOrganizationEqual(supplier.OrganizationID, project.OrganizationID) {
|
||||
renderValidationError(writer, validationIssue{Field: "supplierId", Message: "supplier must exist in the current organization"})
|
||||
if supplier == nil || !annotationOrganizationEqual(supplier.OrganizationID, project.OrganizationID) || !strings.EqualFold(strings.TrimSpace(supplier.Status), "active") {
|
||||
renderValidationError(writer, validationIssue{Field: "supplierId", Message: "an active supplier must exist in the current organization"})
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -300,13 +306,27 @@ func (server *server) handleProjectMembersBulk(writer http.ResponseWriter, reque
|
||||
return
|
||||
}
|
||||
projectID := strings.TrimSpace(chi.URLParam(request, "id"))
|
||||
project, err := server.store.GetProject(request.Context(), projectID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if project == nil || !server.filterByTenant(request, project.OrganizationID) {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "project not found"})
|
||||
return
|
||||
}
|
||||
var payload projectMemberBulkInput
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
payload.Action = strings.ToLower(strings.TrimSpace(payload.Action))
|
||||
if payload.Action == "add" {
|
||||
server.handleProjectMembersBulkAdd(writer, request, project, payload.Entries)
|
||||
return
|
||||
}
|
||||
roles, valid := normalizedMemberRoles(payload.Roles)
|
||||
if len(payload.MemberIDs) == 0 || (payload.Action == "set_roles" && !valid) || (payload.Action != "set_roles" && payload.Action != "remove") {
|
||||
renderValidationError(writer, validationIssue{Field: "bulk", Message: "memberIds and a valid bulk action are required"})
|
||||
renderValidationError(writer, validationIssue{Field: "bulk", Message: "memberIds and action add, set_roles, or remove are required"})
|
||||
return
|
||||
}
|
||||
updated := 0
|
||||
@ -329,5 +349,100 @@ func (server *server) handleProjectMembersBulk(writer http.ResponseWriter, reque
|
||||
}
|
||||
updated++
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]int{"updated": updated})
|
||||
renderJSON(writer, http.StatusOK, projectMemberBulkResult{Updated: updated})
|
||||
}
|
||||
|
||||
func (server *server) handleProjectMembersBulkAdd(writer http.ResponseWriter, request *http.Request, project *domain.ProjectRecord, entries []projectMemberInput) {
|
||||
if len(entries) == 0 {
|
||||
renderValidationError(writer, validationIssue{Field: "entries", Message: "at least one project member entry is required"})
|
||||
return
|
||||
}
|
||||
|
||||
// Validate the entire request before writing any member. This makes invalid
|
||||
// users, suppliers, roles, and duplicates a whole-request failure instead of
|
||||
// leaving a partially created project membership set.
|
||||
prepared := make([]domain.ProjectMemberRecord, 0, len(entries))
|
||||
seenUsers := make(map[string]int, len(entries))
|
||||
supplierCache := make(map[string]*domain.SupplierRecord)
|
||||
for index, entry := range entries {
|
||||
entry.UserID = strings.TrimSpace(entry.UserID)
|
||||
entry.SupplierID = strings.TrimSpace(entry.SupplierID)
|
||||
roles, valid := normalizedMemberRoles(entry.Roles)
|
||||
if entry.UserID == "" || !valid {
|
||||
renderValidationError(writer, validationIssue{Field: "entries", Message: "every entry requires userId and at least one project role"})
|
||||
return
|
||||
}
|
||||
if firstIndex, exists := seenUsers[entry.UserID]; exists {
|
||||
renderJSON(writer, http.StatusConflict, map[string]any{
|
||||
"error": "duplicate user in bulk project member request",
|
||||
"code": "duplicate_project_member_entry",
|
||||
"userId": entry.UserID,
|
||||
"firstIndex": firstIndex,
|
||||
"index": index,
|
||||
})
|
||||
return
|
||||
}
|
||||
seenUsers[entry.UserID] = index
|
||||
|
||||
existing, err := server.store.GetProjectMemberByProjectUser(request.Context(), project.OrganizationID, project.ID, entry.UserID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if existing != nil {
|
||||
renderJSON(writer, http.StatusConflict, map[string]any{
|
||||
"error": "project member already exists",
|
||||
"code": "project_member_exists",
|
||||
"userId": entry.UserID,
|
||||
"member": existing,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
user, err := server.store.GetUser(request.Context(), entry.UserID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if user == nil || !annotationOrganizationEqual(user.OrganizationID, project.OrganizationID) {
|
||||
renderValidationError(writer, validationIssue{Field: "entries", Message: "every user must exist in the current organization"})
|
||||
return
|
||||
}
|
||||
if entry.SupplierID == "" {
|
||||
entry.SupplierID = strings.TrimSpace(user.SupplierID)
|
||||
}
|
||||
if entry.SupplierID != "" {
|
||||
supplier, cached := supplierCache[entry.SupplierID]
|
||||
if !cached {
|
||||
supplier, err = server.store.GetSupplier(request.Context(), entry.SupplierID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
supplierCache[entry.SupplierID] = supplier
|
||||
}
|
||||
if supplier == nil || !annotationOrganizationEqual(supplier.OrganizationID, project.OrganizationID) || !strings.EqualFold(strings.TrimSpace(supplier.Status), "active") {
|
||||
renderValidationError(writer, validationIssue{Field: "entries", Message: "every supplier must be active and exist in the current organization"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
prepared = append(prepared, domain.ProjectMemberRecord{
|
||||
ID: domain.NewID("project-member"),
|
||||
OrganizationID: project.OrganizationID,
|
||||
ProjectID: project.ID,
|
||||
UserID: user.ID,
|
||||
SupplierID: entry.SupplierID,
|
||||
Roles: roles,
|
||||
CreatedAt: nowISO(),
|
||||
})
|
||||
}
|
||||
|
||||
for _, member := range prepared {
|
||||
if err := server.store.UpsertProjectMember(request.Context(), member); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, projectMemberBulkResult{Created: len(prepared)})
|
||||
}
|
||||
|
||||
@ -106,6 +106,86 @@ func TestBulkProjectMemberRemovalReleasesClaimedTasks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBulkProjectMemberAddValidatesWholeRequestBeforeWriting(t *testing.T) {
|
||||
t.Setenv("DROBOTICFLOW_REQUIRE_SESSION_AUTH", "true")
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
handler := NewHandler(dataStore, nil)
|
||||
rootCookie := bootstrapSuperAdminSession(t, handler)
|
||||
organization := adminCreateOrganization(t, handler, rootCookie, "Bulk add members", "bulk-add-members")
|
||||
admin := adminCreateUser(t, handler, rootCookie, organization.ID, "Org Admin", "bulk-add-admin@example.com", domain.UserRoleAdmin, "admin-password")
|
||||
first := adminCreateUser(t, handler, rootCookie, organization.ID, "First", "bulk-first@example.com", domain.UserRoleMember, "worker-password")
|
||||
second := adminCreateUser(t, handler, rootCookie, organization.ID, "Second", "bulk-second@example.com", domain.UserRoleMember, "worker-password")
|
||||
third := adminCreateUser(t, handler, rootCookie, organization.ID, "Third", "bulk-third@example.com", domain.UserRoleMember, "worker-password")
|
||||
adminCookie := loginSession(t, handler, admin.Email, "admin-password")
|
||||
project, err := dataStore.CreateProject(ctx, domain.CreateProjectInput{OrganizationID: organization.ID, Name: "Bulk add project"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
supplier := domain.SupplierRecord{ID: "supplier-bulk-add", OrganizationID: organization.ID, Name: "Bulk supplier"}
|
||||
if err := dataStore.UpsertSupplier(ctx, supplier); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
addBody, _ := json.Marshal(map[string]any{
|
||||
"action": "add",
|
||||
"entries": []map[string]any{
|
||||
{"userId": first.ID, "supplierId": supplier.ID, "roles": []string{"annotator"}},
|
||||
{"userId": second.ID, "roles": []string{"quality_reviewer", "acceptance_reviewer"}},
|
||||
},
|
||||
})
|
||||
added := serveJSONWithCookie(handler, http.MethodPost, "/api/projects/"+project.ID+"/members/bulk", addBody, adminCookie)
|
||||
if added.Code != http.StatusOK || !jsonContains(added.Body.String(), `"created":2`) || !jsonContains(added.Body.String(), `"updated":0`) {
|
||||
t.Fatalf("bulk add=%d body=%s", added.Code, added.Body.String())
|
||||
}
|
||||
firstMember, _ := dataStore.GetProjectMemberByProjectUser(ctx, organization.ID, project.ID, first.ID)
|
||||
secondMember, _ := dataStore.GetProjectMemberByProjectUser(ctx, organization.ID, project.ID, second.ID)
|
||||
if firstMember == nil || firstMember.SupplierID != supplier.ID || len(firstMember.Roles) != 1 {
|
||||
t.Fatalf("first member=%#v", firstMember)
|
||||
}
|
||||
if secondMember == nil || len(secondMember.Roles) != 2 {
|
||||
t.Fatalf("second member=%#v", secondMember)
|
||||
}
|
||||
|
||||
conflictBody, _ := json.Marshal(map[string]any{
|
||||
"action": "add",
|
||||
"entries": []map[string]any{
|
||||
{"userId": third.ID, "roles": []string{"annotator"}},
|
||||
{"userId": first.ID, "roles": []string{"annotator"}},
|
||||
},
|
||||
})
|
||||
conflict := serveJSONWithCookie(handler, http.MethodPost, "/api/projects/"+project.ID+"/members/bulk", conflictBody, adminCookie)
|
||||
if conflict.Code != http.StatusConflict || !jsonContains(conflict.Body.String(), `"code":"project_member_exists"`) {
|
||||
t.Fatalf("existing conflict=%d body=%s", conflict.Code, conflict.Body.String())
|
||||
}
|
||||
thirdMember, _ := dataStore.GetProjectMemberByProjectUser(ctx, organization.ID, project.ID, third.ID)
|
||||
if thirdMember != nil {
|
||||
t.Fatalf("bulk conflict partially created third member: %#v", thirdMember)
|
||||
}
|
||||
|
||||
duplicateBody, _ := json.Marshal(map[string]any{
|
||||
"action": "add",
|
||||
"entries": []map[string]any{
|
||||
{"userId": third.ID, "roles": []string{"annotator"}},
|
||||
{"userId": third.ID, "roles": []string{"quality_reviewer"}},
|
||||
},
|
||||
})
|
||||
duplicate := serveJSONWithCookie(handler, http.MethodPost, "/api/projects/"+project.ID+"/members/bulk", duplicateBody, adminCookie)
|
||||
if duplicate.Code != http.StatusConflict || !jsonContains(duplicate.Body.String(), `"code":"duplicate_project_member_entry"`) {
|
||||
t.Fatalf("payload duplicate=%d body=%s", duplicate.Code, duplicate.Body.String())
|
||||
}
|
||||
thirdMember, _ = dataStore.GetProjectMemberByProjectUser(ctx, organization.ID, project.ID, third.ID)
|
||||
if thirdMember != nil {
|
||||
t.Fatalf("duplicate payload partially created third member: %#v", thirdMember)
|
||||
}
|
||||
|
||||
memberCookie := loginSession(t, handler, third.Email, "worker-password")
|
||||
forbidden := serveJSONWithCookie(handler, http.MethodPost, "/api/projects/"+project.ID+"/members/bulk", duplicateBody, memberCookie)
|
||||
if forbidden.Code != http.StatusForbidden {
|
||||
t.Fatalf("ordinary member bulk add=%d body=%s", forbidden.Code, forbidden.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func jsonContains(value string, expected string) bool {
|
||||
return len(expected) == 0 || (len(value) >= len(expected) && containsText(value, expected))
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
@ -71,6 +72,7 @@ type server struct {
|
||||
buildCommit string
|
||||
buildTime string
|
||||
image string
|
||||
combinedSubmissionJobs sync.Map
|
||||
}
|
||||
|
||||
type runJobTerminator interface {
|
||||
@ -1361,8 +1363,6 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Get("/api/data-operations/stage-items", instance.handleDataOperationsStageItems)
|
||||
router.Get("/api/data-operations/training-usage", instance.handleDataOperationsTrainingUsage)
|
||||
router.Get("/api/data-operations/datasets", instance.handleDataOperationsDatasets)
|
||||
router.Get("/api/annotation-workgroups", deprecatedAnnotationEndpoint(instance.handleAnnotationWorkgroupsList))
|
||||
router.Get("/api/annotation-memberships", deprecatedAnnotationEndpoint(instance.handleAnnotationMembershipsList))
|
||||
router.Get("/api/annotation-templates", deprecatedAnnotationEndpoint(instance.handleAnnotationTemplatesList))
|
||||
router.Get("/api/annotation-tasks", deprecatedAnnotationEndpoint(instance.handleAnnotationTasksList))
|
||||
router.Get("/api/annotation-tasks/{id}", deprecatedAnnotationEndpoint(instance.handleAnnotationTaskGet))
|
||||
|
||||
@ -24,7 +24,106 @@ type workflowPublishRequest struct {
|
||||
}
|
||||
|
||||
type projectWorkflowInstanceRequest struct {
|
||||
ReleaseID string `json:"releaseId"`
|
||||
ReleaseID string `json:"releaseId"`
|
||||
SupplierID string `json:"supplierId,omitempty"`
|
||||
}
|
||||
|
||||
var productionHumanRoles = []domain.AnnotationAssignmentRole{
|
||||
domain.AnnotationRoleAnnotator,
|
||||
domain.AnnotationRoleQualityReviewer,
|
||||
domain.AnnotationRoleAcceptanceReviewer,
|
||||
}
|
||||
|
||||
func releaseUsesAnnotationGate(release domain.WorkflowReleaseRecord) bool {
|
||||
for _, node := range release.Nodes {
|
||||
if strings.TrimSpace(node.Data.OperatorID) == "operator-builtin-annotation-gate" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func supplierHasProductionHumanRoles(members []domain.ProjectMemberRecord, supplierID string) bool {
|
||||
covered := map[domain.AnnotationAssignmentRole]bool{}
|
||||
for _, member := range members {
|
||||
if strings.TrimSpace(member.SupplierID) != supplierID {
|
||||
continue
|
||||
}
|
||||
for _, role := range member.Roles {
|
||||
covered[role] = true
|
||||
}
|
||||
}
|
||||
for _, role := range productionHumanRoles {
|
||||
if !covered[role] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func bindAnnotationSupplier(nodes []domain.WorkflowNode, supplierID string) []domain.WorkflowNode {
|
||||
cloned := make([]domain.WorkflowNode, len(nodes))
|
||||
copy(cloned, nodes)
|
||||
for index := range cloned {
|
||||
cloned[index].Data.Hyperparams = append([]domain.HyperParam(nil), cloned[index].Data.Hyperparams...)
|
||||
if strings.TrimSpace(cloned[index].Data.OperatorID) != "operator-builtin-annotation-gate" {
|
||||
continue
|
||||
}
|
||||
bound := false
|
||||
for paramIndex := range cloned[index].Data.Hyperparams {
|
||||
if strings.TrimSpace(cloned[index].Data.Hyperparams[paramIndex].Key) != "ANNOTATION_SUPPLIER_ID" {
|
||||
continue
|
||||
}
|
||||
cloned[index].Data.Hyperparams[paramIndex].Value = supplierID
|
||||
cloned[index].Data.Hyperparams[paramIndex].Type = "string"
|
||||
cloned[index].Data.Hyperparams[paramIndex].Description = "当前项目绑定的供应商 ID"
|
||||
bound = true
|
||||
}
|
||||
if !bound {
|
||||
cloned[index].Data.Hyperparams = append(cloned[index].Data.Hyperparams, domain.HyperParam{
|
||||
Key: "ANNOTATION_SUPPLIER_ID", Value: supplierID, Type: "string", Description: "当前项目绑定的供应商 ID",
|
||||
})
|
||||
}
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
func (server *server) resolveProjectWorkflowSupplier(ctx context.Context, project domain.ProjectRecord, release domain.WorkflowReleaseRecord, requested string) (string, []validationIssue, error) {
|
||||
if !releaseUsesAnnotationGate(release) {
|
||||
return "", nil, nil
|
||||
}
|
||||
members, err := server.store.ListProjectMembers(ctx, project.OrganizationID, project.ID)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
requested = strings.TrimSpace(requested)
|
||||
if requested != "" {
|
||||
supplier, supplierErr := server.store.GetSupplier(ctx, requested)
|
||||
if supplierErr != nil {
|
||||
return "", nil, supplierErr
|
||||
}
|
||||
if supplier == nil || normalizedOrganizationID(supplier.OrganizationID) != normalizedOrganizationID(project.OrganizationID) || !strings.EqualFold(strings.TrimSpace(supplier.Status), "active") {
|
||||
return "", []validationIssue{{Field: "supplierId", Message: "an active supplier in the same organization is required"}}, nil
|
||||
}
|
||||
if !supplierHasProductionHumanRoles(members, requested) {
|
||||
return "", []validationIssue{{Field: "supplierId", Message: "supplier project members must cover annotator, quality reviewer and acceptance reviewer"}}, nil
|
||||
}
|
||||
return requested, nil, nil
|
||||
}
|
||||
candidates := map[string]struct{}{}
|
||||
for _, member := range members {
|
||||
supplierID := strings.TrimSpace(member.SupplierID)
|
||||
if supplierID != "" && supplierHasProductionHumanRoles(members, supplierID) {
|
||||
candidates[supplierID] = struct{}{}
|
||||
}
|
||||
}
|
||||
if len(candidates) != 1 {
|
||||
return "", []validationIssue{{Field: "supplierId", Message: "select exactly one supplier whose project members cover all three production roles"}}, nil
|
||||
}
|
||||
for supplierID := range candidates {
|
||||
return server.resolveProjectWorkflowSupplier(ctx, project, release, supplierID)
|
||||
}
|
||||
return "", []validationIssue{{Field: "supplierId", Message: "supplier is required"}}, nil
|
||||
}
|
||||
|
||||
func templateSnapshotFromWorkflow(item domain.WorkflowRecord) domain.TemplateRecord {
|
||||
@ -263,6 +362,15 @@ func (server *server) handleProjectWorkflowInstanceCreate(writer http.ResponseWr
|
||||
renderValidationError(writer, validationIssue{Field: "releaseId", Message: "published workflow release is required"})
|
||||
return
|
||||
}
|
||||
supplierID, supplierIssues, supplierErr := server.resolveProjectWorkflowSupplier(request.Context(), *project, *release, payload.SupplierID)
|
||||
if supplierErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, supplierErr)
|
||||
return
|
||||
}
|
||||
if len(supplierIssues) > 0 {
|
||||
renderValidationError(writer, supplierIssues[0])
|
||||
return
|
||||
}
|
||||
for _, pluginID := range release.RequiredPluginIDs {
|
||||
if pluginID != pluginregistry.AnnotationQAID {
|
||||
continue
|
||||
@ -282,7 +390,7 @@ func (server *server) handleProjectWorkflowInstanceCreate(writer http.ResponseWr
|
||||
Type: release.Type, Kind: release.Kind, ExecutionScope: release.ExecutionScope, ScanConfig: release.ScanConfig,
|
||||
Hyperparams: release.Hyperparams, MaxConcurrentRuns: release.MaxConcurrentRuns, NodeTimeoutSeconds: release.NodeTimeoutSeconds,
|
||||
RunTimeoutSeconds: release.RunTimeoutSeconds, MaxRetryAttempts: release.MaxRetryAttempts,
|
||||
RetryBackoffSeconds: release.RetryBackoffSeconds, Schedule: release.Schedule, Nodes: release.Nodes, Edges: release.Edges,
|
||||
RetryBackoffSeconds: release.RetryBackoffSeconds, Schedule: release.Schedule, Nodes: bindAnnotationSupplier(release.Nodes, supplierID), Edges: release.Edges,
|
||||
WorkflowInputs: release.WorkflowInputs, ArtifactStorage: release.ArtifactStorage,
|
||||
})
|
||||
if err != nil {
|
||||
@ -322,7 +430,8 @@ func (server *server) handleProjectWorkflowInstanceCreate(writer http.ResponseWr
|
||||
instance := domain.ProjectWorkflowInstanceRecord{
|
||||
ID: domain.NewID("project-workflow-instance"), OrganizationID: project.OrganizationID, ProjectID: project.ID,
|
||||
ReleaseID: release.ID, ReleaseVersion: release.Version, SourceTemplateID: release.TemplateID, WorkflowID: workflow.ID,
|
||||
Status: domain.ProjectWorkflowInstanceActive, SupersedesInstanceID: supersedes, CreatedByUserID: principal.User.ID,
|
||||
SupplierID: supplierID,
|
||||
Status: domain.ProjectWorkflowInstanceActive, SupersedesInstanceID: supersedes, CreatedByUserID: principal.User.ID,
|
||||
CreatedAt: now, UpdatedAt: now,
|
||||
}
|
||||
if err := server.store.UpsertProjectWorkflowInstance(request.Context(), instance); err != nil {
|
||||
|
||||
@ -60,6 +60,72 @@ func TestProjectWorkflowInstancePersistsReleasedProjectWorkflow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectWorkflowInstanceBindsValidatedSupplier(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
project := domain.ProjectRecord{ID: "project-supplier-binding", OrganizationID: domain.DefaultOrganizationID, Name: "Project"}
|
||||
if err := dataStore.UpsertProject(ctx, project); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
supplier := domain.SupplierRecord{ID: "supplier-production", OrganizationID: domain.DefaultOrganizationID, Name: "Production supplier", Status: "active", CreatedAt: nowISO(), UpdatedAt: nowISO()}
|
||||
if err := dataStore.UpsertSupplier(ctx, supplier); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for index, role := range []domain.AnnotationAssignmentRole{domain.AnnotationRoleAnnotator, domain.AnnotationRoleQualityReviewer, domain.AnnotationRoleAcceptanceReviewer} {
|
||||
if err := dataStore.UpsertProjectMember(ctx, domain.ProjectMemberRecord{
|
||||
ID: fmt.Sprintf("member-%d", index), OrganizationID: domain.DefaultOrganizationID, ProjectID: project.ID,
|
||||
UserID: fmt.Sprintf("user-%d", index), SupplierID: supplier.ID, Roles: []domain.AnnotationAssignmentRole{role}, CreatedAt: nowISO(), UpdatedAt: nowISO(),
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
release := domain.WorkflowReleaseRecord{
|
||||
ID: "release-supplier-binding", OrganizationID: domain.DefaultOrganizationID, TemplateID: "template-supplier-binding", Version: 1,
|
||||
Name: "Released human workflow", Type: domain.WorkflowTypeBatch, Kind: domain.WorkflowKindStandard,
|
||||
ExecutionScope: domain.WorkflowExecutionScopeProduction,
|
||||
Nodes: []domain.WorkflowNode{{ID: "human", Type: "operator", Data: domain.WorkflowNodeData{
|
||||
Label: "Human gate", OperatorID: "operator-builtin-annotation-gate",
|
||||
Hyperparams: []domain.HyperParam{{Key: "ANNOTATION_SUPPLIER_ID", Value: "release-must-not-own-supplier"}},
|
||||
}}},
|
||||
CreatedAt: nowISO(), PublishedAt: nowISO(),
|
||||
}
|
||||
if err := dataStore.UpsertWorkflowRelease(ctx, release); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
handler := NewHandler(dataStore, nil)
|
||||
requestBody, _ := json.Marshal(map[string]string{"releaseId": release.ID, "supplierId": supplier.ID})
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/projects/"+project.ID+"/workflow-instances", bytes.NewReader(requestBody))
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
request.AddCookie(&http.Cookie{Name: "droboticflow_csrf", Value: "supplier-binding-csrf"})
|
||||
request.Header.Set("X-Droboticflow-CSRF-Token", "supplier-binding-csrf")
|
||||
request = request.WithContext(context.WithValue(request.Context(), authContextKey{}, &authenticatedPrincipal{
|
||||
User: domain.UserRecord{ID: "admin-supplier-binding", OrganizationID: domain.DefaultOrganizationID, Role: domain.UserRoleAdmin},
|
||||
Organization: domain.OrganizationRecord{ID: domain.DefaultOrganizationID, Status: domain.OrganizationStatusActive},
|
||||
}))
|
||||
recorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusCreated {
|
||||
t.Fatalf("create bound workflow instance status=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
var response struct {
|
||||
Instance domain.ProjectWorkflowInstanceRecord `json:"instance"`
|
||||
Workflow domain.WorkflowRecord `json:"workflow"`
|
||||
}
|
||||
if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if response.Instance.SupplierID != supplier.ID {
|
||||
t.Fatalf("instance supplier=%q want=%q", response.Instance.SupplierID, supplier.ID)
|
||||
}
|
||||
params := response.Workflow.Nodes[0].Data.Hyperparams
|
||||
if len(params) != 1 || params[0].Key != "ANNOTATION_SUPPLIER_ID" || params[0].Value != supplier.ID {
|
||||
t.Fatalf("workflow supplier binding=%#v", params)
|
||||
}
|
||||
if release.Nodes[0].Data.Hyperparams[0].Value != "release-must-not-own-supplier" {
|
||||
t.Fatalf("release snapshot was mutated: %#v", release.Nodes[0].Data.Hyperparams)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkflowReleaseRunEndpointSecurityGate(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
|
||||
@ -173,8 +173,8 @@ type AnnotationTaskRecord struct {
|
||||
LegacyAssignment map[string]string `json:"legacyAssignment,omitempty" bson:"legacyAssignment,omitempty"`
|
||||
// Deprecated compatibility fields. Mongo migration copies their historical
|
||||
// value into LegacyAssignment and unsets them for production records.
|
||||
WorkgroupID string `json:"workgroupId,omitempty" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty" bson:"vendorId,omitempty"`
|
||||
WorkgroupID string `json:"-" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"-" bson:"vendorId,omitempty"`
|
||||
AssignedUserID string `json:"assignedUserId,omitempty" bson:"assignedUserId,omitempty"`
|
||||
Status AnnotationTaskStatus `json:"status" bson:"status"`
|
||||
CurrentRevision int `json:"currentRevision" bson:"currentRevision"`
|
||||
@ -229,8 +229,8 @@ type AnnotationWorklogEventRecord struct {
|
||||
UserID string `json:"userId" bson:"userId"`
|
||||
SupplierID string `json:"supplierId,omitempty" bson:"supplierId,omitempty"`
|
||||
LegacyAssignment map[string]string `json:"legacyAssignment,omitempty" bson:"legacyAssignment,omitempty"`
|
||||
WorkgroupID string `json:"workgroupId,omitempty" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty" bson:"vendorId,omitempty"`
|
||||
WorkgroupID string `json:"-" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"-" bson:"vendorId,omitempty"`
|
||||
EventType string `json:"eventType" bson:"eventType"`
|
||||
Mode RunMode `json:"mode,omitempty" bson:"mode,omitempty"`
|
||||
Temporary bool `json:"temporary,omitempty" bson:"temporary,omitempty"`
|
||||
@ -243,8 +243,9 @@ type AnnotationWorklogEventRecord struct {
|
||||
|
||||
type AnnotationWorkloadAggregate struct {
|
||||
UserID string `json:"userId"`
|
||||
WorkgroupID string `json:"workgroupId"`
|
||||
VendorID string `json:"vendorId"`
|
||||
SupplierID string `json:"supplierId"`
|
||||
WorkgroupID string `json:"-"`
|
||||
VendorID string `json:"-"`
|
||||
TemplateVersion int `json:"templateVersion"`
|
||||
AssignedCount int64 `json:"assignedCount"`
|
||||
SubmittedCount int64 `json:"submittedCount"`
|
||||
|
||||
@ -30,8 +30,8 @@ type DeliveryPackageRecord struct {
|
||||
WorkflowID string `json:"workflowId" bson:"workflowId"`
|
||||
SupplierID string `json:"supplierId,omitempty" bson:"supplierId,omitempty"`
|
||||
LegacyAssignment map[string]string `json:"legacyAssignment,omitempty" bson:"legacyAssignment,omitempty"`
|
||||
WorkgroupID string `json:"workgroupId,omitempty" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty" bson:"vendorId,omitempty"`
|
||||
WorkgroupID string `json:"-" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"-" bson:"vendorId,omitempty"`
|
||||
ParentRunID string `json:"parentRunId" bson:"parentRunId"`
|
||||
ChildRunID string `json:"childRunId" bson:"childRunId"`
|
||||
ReleasePartitionID string `json:"releasePartitionId" bson:"releasePartitionId"`
|
||||
|
||||
@ -146,8 +146,8 @@ type HumanItemRecord struct {
|
||||
Status HumanItemStatus `json:"status" bson:"status"`
|
||||
AssignedUserID string `json:"assignedUserId,omitempty" bson:"assignedUserId,omitempty"`
|
||||
LegacyAssignment map[string]string `json:"legacyAssignment,omitempty" bson:"legacyAssignment,omitempty"`
|
||||
WorkgroupID string `json:"workgroupId,omitempty" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty" bson:"vendorId,omitempty"`
|
||||
WorkgroupID string `json:"-" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"-" bson:"vendorId,omitempty"`
|
||||
CurrentRevision int `json:"currentRevision" bson:"currentRevision"`
|
||||
ReviewRound int `json:"reviewRound" bson:"reviewRound"`
|
||||
MaxReworkRounds int `json:"maxReworkRounds" bson:"maxReworkRounds"`
|
||||
|
||||
@ -46,6 +46,7 @@ type ProjectWorkflowInstanceRecord struct {
|
||||
ReleaseVersion int `json:"releaseVersion" bson:"releaseVersion"`
|
||||
SourceTemplateID string `json:"sourceTemplateId" bson:"sourceTemplateId"`
|
||||
WorkflowID string `json:"workflowId" bson:"workflowId"`
|
||||
SupplierID string `json:"supplierId,omitempty" bson:"supplierId,omitempty"`
|
||||
Status ProjectWorkflowInstanceStatus `json:"status" bson:"status"`
|
||||
SupersedesInstanceID string `json:"supersedesInstanceId,omitempty" bson:"supersedesInstanceId,omitempty"`
|
||||
CreatedByUserID string `json:"createdByUserId" bson:"createdByUserId"`
|
||||
|
||||
@ -97,38 +97,91 @@ func annotationGateConfigFromNode(node domain.WorkflowNode) annotationGateConfig
|
||||
|
||||
func (runtime *Runtime) annotationGateSupplierID(ctx context.Context, run *domain.RunRecord, config *annotationGateConfig) (string, error) {
|
||||
if config == nil || run == nil {
|
||||
return "", nil
|
||||
}
|
||||
if config.SupplierID != "" {
|
||||
return config.SupplierID, nil
|
||||
return "", fmt.Errorf("annotation supplier resolution requires a run and configuration")
|
||||
}
|
||||
requested := strings.TrimSpace(config.SupplierID)
|
||||
if config.WorkgroupID != "" {
|
||||
group, err := runtime.store.GetAnnotationWorkgroup(ctx, config.WorkgroupID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if group != nil {
|
||||
config.SupplierID = strings.TrimSpace(group.VendorID)
|
||||
return config.SupplierID, nil
|
||||
if group != nil && requested == "" {
|
||||
requested = strings.TrimSpace(group.VendorID)
|
||||
}
|
||||
}
|
||||
members, err := runtime.store.ListProjectMembers(ctx, run.OrganizationID, run.ProjectID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
suppliers := map[string]struct{}{}
|
||||
requiredRoles := map[domain.AnnotationAssignmentRole]struct{}{}
|
||||
stages := config.HumanStages
|
||||
if len(stages) == 0 {
|
||||
stages = domain.DefaultAnnotationHumanStages()
|
||||
}
|
||||
for _, stage := range stages {
|
||||
role := domain.AnnotationAssignmentRole(strings.TrimSpace(stage.RequiredRole))
|
||||
if role != "" {
|
||||
requiredRoles[role] = struct{}{}
|
||||
}
|
||||
}
|
||||
if config.RequirePrePackageAcceptance {
|
||||
requiredRoles[domain.AnnotationRoleAcceptanceReviewer] = struct{}{}
|
||||
}
|
||||
supplierCovered := func(supplierID string) bool {
|
||||
covered := map[domain.AnnotationAssignmentRole]struct{}{}
|
||||
for _, member := range members {
|
||||
if strings.TrimSpace(member.SupplierID) != supplierID {
|
||||
continue
|
||||
}
|
||||
for _, role := range member.Roles {
|
||||
covered[role] = struct{}{}
|
||||
}
|
||||
}
|
||||
for role := range requiredRoles {
|
||||
if _, ok := covered[role]; !ok {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return len(requiredRoles) > 0
|
||||
}
|
||||
validateSupplier := func(supplierID string) error {
|
||||
supplier, supplierErr := runtime.store.GetSupplier(ctx, supplierID)
|
||||
if supplierErr != nil {
|
||||
return supplierErr
|
||||
}
|
||||
if supplier == nil || strings.TrimSpace(supplier.OrganizationID) != strings.TrimSpace(run.OrganizationID) || !strings.EqualFold(strings.TrimSpace(supplier.Status), "active") {
|
||||
return fmt.Errorf("supplier %s must be active and belong to the run organization", supplierID)
|
||||
}
|
||||
if !supplierCovered(supplierID) {
|
||||
return fmt.Errorf("supplier %s project members do not cover every configured human stage role", supplierID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if requested != "" {
|
||||
if err := validateSupplier(requested); err != nil {
|
||||
return "", err
|
||||
}
|
||||
config.SupplierID = requested
|
||||
return requested, nil
|
||||
}
|
||||
candidates := map[string]struct{}{}
|
||||
for _, member := range members {
|
||||
if strings.TrimSpace(member.SupplierID) != "" {
|
||||
suppliers[member.SupplierID] = struct{}{}
|
||||
supplierID := strings.TrimSpace(member.SupplierID)
|
||||
if supplierID == "" || !supplierCovered(supplierID) {
|
||||
continue
|
||||
}
|
||||
if err := validateSupplier(supplierID); err == nil {
|
||||
candidates[supplierID] = struct{}{}
|
||||
}
|
||||
}
|
||||
if len(suppliers) == 1 {
|
||||
for supplierID := range suppliers {
|
||||
config.SupplierID = supplierID
|
||||
return supplierID, nil
|
||||
}
|
||||
if len(candidates) != 1 {
|
||||
return "", fmt.Errorf("annotation workflow requires exactly one active supplier whose project members cover every configured human stage role; found %d", len(candidates))
|
||||
}
|
||||
return "", nil
|
||||
for supplierID := range candidates {
|
||||
config.SupplierID = supplierID
|
||||
return supplierID, nil
|
||||
}
|
||||
return "", fmt.Errorf("annotation supplier could not be resolved")
|
||||
}
|
||||
|
||||
func annotationNumber(value any) (float64, bool) {
|
||||
|
||||
70
internal/worker/annotation_supplier_test.go
Normal file
70
internal/worker/annotation_supplier_test.go
Normal file
@ -0,0 +1,70 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
"droboticflow/internal/store"
|
||||
)
|
||||
|
||||
func seedAnnotationSupplier(t *testing.T, dataStore store.Store, projectID, supplierID string, roles ...domain.AnnotationAssignmentRole) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
if err := dataStore.UpsertSupplier(ctx, domain.SupplierRecord{ID: supplierID, OrganizationID: domain.DefaultOrganizationID, Name: supplierID, Status: "active"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for index, role := range roles {
|
||||
if err := dataStore.UpsertProjectMember(ctx, domain.ProjectMemberRecord{
|
||||
ID: supplierID + "-member-" + string(rune('a'+index)), OrganizationID: domain.DefaultOrganizationID,
|
||||
ProjectID: projectID, UserID: supplierID + "-user-" + string(rune('a'+index)), SupplierID: supplierID,
|
||||
Roles: []domain.AnnotationAssignmentRole{role},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnnotationGateSupplierResolutionIsFailClosed(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
projectID := "project-supplier-resolution"
|
||||
run := &domain.RunRecord{ID: "run-supplier-resolution", OrganizationID: domain.DefaultOrganizationID, ProjectID: projectID}
|
||||
config := annotationGateConfig{HumanStages: domain.DefaultFanyuV58HumanStages(), RequirePrePackageAcceptance: true}
|
||||
|
||||
t.Run("unique fully staffed supplier is inferred", func(t *testing.T) {
|
||||
dataStore := store.NewMemoryStore()
|
||||
seedAnnotationSupplier(t, dataStore, projectID, "supplier-complete", domain.AnnotationRoleAnnotator, domain.AnnotationRoleQualityReviewer, domain.AnnotationRoleAcceptanceReviewer)
|
||||
runtime := &Runtime{store: dataStore}
|
||||
resolved, err := runtime.annotationGateSupplierID(ctx, run, &config)
|
||||
if err != nil || resolved != "supplier-complete" {
|
||||
t.Fatalf("resolved=%q err=%v", resolved, err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("configured supplier missing a role is rejected", func(t *testing.T) {
|
||||
dataStore := store.NewMemoryStore()
|
||||
seedAnnotationSupplier(t, dataStore, projectID, "supplier-incomplete", domain.AnnotationRoleAnnotator, domain.AnnotationRoleQualityReviewer)
|
||||
runtime := &Runtime{store: dataStore}
|
||||
candidate := config
|
||||
candidate.SupplierID = "supplier-incomplete"
|
||||
_, err := runtime.annotationGateSupplierID(ctx, run, &candidate)
|
||||
if err == nil || !strings.Contains(err.Error(), "every configured human stage role") {
|
||||
t.Fatalf("expected missing-role error, got %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("multiple fully staffed suppliers require an explicit binding", func(t *testing.T) {
|
||||
dataStore := store.NewMemoryStore()
|
||||
for _, supplierID := range []string{"supplier-a", "supplier-b"} {
|
||||
seedAnnotationSupplier(t, dataStore, projectID, supplierID, domain.AnnotationRoleAnnotator, domain.AnnotationRoleQualityReviewer, domain.AnnotationRoleAcceptanceReviewer)
|
||||
}
|
||||
runtime := &Runtime{store: dataStore}
|
||||
candidate := config
|
||||
candidate.SupplierID = ""
|
||||
_, err := runtime.annotationGateSupplierID(ctx, run, &candidate)
|
||||
if err == nil || !strings.Contains(err.Error(), "found 2") {
|
||||
t.Fatalf("expected ambiguous supplier error, got %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -222,14 +222,16 @@ func (runtime *Runtime) syncDeliveryPackage(ctx context.Context, batch domain.Hu
|
||||
item = packages[0]
|
||||
} else {
|
||||
workgroupID, vendorID, supplierID := "", "", ""
|
||||
var legacyAssignment map[string]string
|
||||
if len(partition.ItemIDs) > 0 {
|
||||
if humanItem, itemErr := runtime.store.GetHumanItem(ctx, partition.ItemIDs[0]); itemErr == nil && humanItem != nil {
|
||||
workgroupID, vendorID, supplierID = humanItem.WorkgroupID, humanItem.VendorID, humanItem.SupplierID
|
||||
legacyAssignment = humanItem.LegacyAssignment
|
||||
}
|
||||
}
|
||||
item = domain.DeliveryPackageRecord{
|
||||
ID: "delivery-package-" + partition.ID, OrganizationID: batch.OrganizationID, ProjectID: batch.ProjectID,
|
||||
WorkflowID: batch.WorkflowID, SupplierID: supplierID, WorkgroupID: workgroupID, VendorID: vendorID, ParentRunID: batch.RunID, ChildRunID: partition.ChildRunID,
|
||||
WorkflowID: batch.WorkflowID, SupplierID: supplierID, LegacyAssignment: legacyAssignment, WorkgroupID: workgroupID, VendorID: vendorID, ParentRunID: batch.RunID, ChildRunID: partition.ChildRunID,
|
||||
ReleasePartitionID: partition.ID, ManifestDigest: partition.ManifestDigest, ItemIDs: partition.ItemIDs,
|
||||
Status: domain.DeliveryPackageBuilding, Mode: mode, Temporary: mode == domain.RunModeDebug, Version: 1, CreatedAt: nowISO(), UpdatedAt: nowISO(),
|
||||
}
|
||||
@ -386,7 +388,7 @@ func (runtime *Runtime) ensureDeliveryPackageAcceptanceItem(ctx context.Context,
|
||||
ProjectID: item.ProjectID, WorkflowID: item.WorkflowID, RunID: item.ChildRunID, GateNodeID: "delivery-package-acceptance",
|
||||
Subject: domain.HumanSubjectRef{ArtifactID: artifactID, ItemKey: item.ID, MediaType: "application/json", Payload: map[string]any{
|
||||
"deliveryPackageId": item.ID, "artifactIds": item.ArtifactIDs, "manifestDigest": item.ManifestDigest,
|
||||
}}, CurrentStageID: "acceptance", Status: status, SupplierID: item.SupplierID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
}}, CurrentStageID: "acceptance", Status: status, SupplierID: item.SupplierID, LegacyAssignment: item.LegacyAssignment, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
Version: 1, MaxReworkRounds: sourceBatch.MaxReworkRounds, CreatedAt: now, UpdatedAt: now,
|
||||
}
|
||||
if err := runtime.store.UpsertHumanItem(ctx, *humanItem); err != nil {
|
||||
|
||||
@ -207,7 +207,7 @@ func TestCompletedDeliveryPackageCreatesUnassignedAcceptanceHumanItem(t *testing
|
||||
}
|
||||
if err := dataStore.UpsertHumanItem(ctx, domain.HumanItemRecord{
|
||||
ID: "human-a", OrganizationID: "org-a", BatchID: batch.ID, ProjectID: batch.ProjectID,
|
||||
WorkgroupID: "group-a", VendorID: "vendor-a", Subject: domain.HumanSubjectRef{ItemKey: "clip-a"},
|
||||
SupplierID: "supplier-a", LegacyAssignment: map[string]string{"workgroupId": "group-a", "vendorId": "vendor-a"}, Subject: domain.HumanSubjectRef{ItemKey: "clip-a"},
|
||||
CurrentStageID: "quality_review", Status: domain.HumanItemAccepted, Version: 1,
|
||||
}); err != nil {
|
||||
t.Fatalf("create source item: %v", err)
|
||||
@ -236,7 +236,7 @@ func TestCompletedDeliveryPackageCreatesUnassignedAcceptanceHumanItem(t *testing
|
||||
if err != nil || acceptance == nil {
|
||||
t.Fatalf("acceptance item=%#v err=%v", acceptance, err)
|
||||
}
|
||||
if acceptance.CurrentStageID != "acceptance" || acceptance.Status != domain.HumanItemReady || acceptance.AssignedUserID != "" || acceptance.WorkgroupID != "group-a" || acceptance.VendorID != "vendor-a" {
|
||||
if acceptance.CurrentStageID != "acceptance" || acceptance.Status != domain.HumanItemReady || acceptance.AssignedUserID != "" || acceptance.SupplierID != "supplier-a" || acceptance.LegacyAssignment["workgroupId"] != "group-a" || acceptance.LegacyAssignment["vendorId"] != "vendor-a" {
|
||||
t.Fatalf("acceptance item must enter the scoped available pool: %#v", acceptance)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2071,14 +2071,23 @@ func TestRuntimeAnnotationGateCreatesTasksAndReturnsAcceptedRevisionArtifact(t *
|
||||
// Organization-level published templates are reusable by tenant projects.
|
||||
ID: "template-1", OrganizationID: project.OrganizationID, ProjectID: "",
|
||||
Name: "动作模板", Version: 1, Status: domain.AnnotationTemplatePublished,
|
||||
Labels: []domain.SemanticLabelDefinition{{ID: "steady", Name: "平稳活动"}, {ID: "fast", Name: "快速移动"}},
|
||||
Labels: []domain.SemanticLabelDefinition{{ID: "steady", Name: "平稳活动"}, {ID: "fast", Name: "快速移动"}},
|
||||
HumanStages: domain.DefaultFanyuV58HumanStages(),
|
||||
}
|
||||
group := domain.AnnotationWorkgroupRecord{ID: "group-1", OrganizationID: project.OrganizationID, Name: "供应商 A", VendorID: "vendor-a", Status: "active"}
|
||||
supplier := domain.SupplierRecord{ID: "supplier-a", OrganizationID: project.OrganizationID, Name: "供应商 A", Status: "active"}
|
||||
if err := dataStore.UpsertAnnotationTemplate(ctx, template); err != nil {
|
||||
t.Fatalf("upsert template: %v", err)
|
||||
}
|
||||
if err := dataStore.UpsertAnnotationWorkgroup(ctx, group); err != nil {
|
||||
t.Fatalf("upsert group: %v", err)
|
||||
if err := dataStore.UpsertSupplier(ctx, supplier); err != nil {
|
||||
t.Fatalf("upsert supplier: %v", err)
|
||||
}
|
||||
for index, role := range []domain.AnnotationAssignmentRole{domain.AnnotationRoleAnnotator, domain.AnnotationRoleQualityReviewer} {
|
||||
if err := dataStore.UpsertProjectMember(ctx, domain.ProjectMemberRecord{
|
||||
ID: fmt.Sprintf("member-%d", index), OrganizationID: project.OrganizationID, ProjectID: project.ID,
|
||||
UserID: fmt.Sprintf("user-%d", index), SupplierID: supplier.ID, Roles: []domain.AnnotationAssignmentRole{role},
|
||||
}); err != nil {
|
||||
t.Fatalf("upsert project member: %v", err)
|
||||
}
|
||||
}
|
||||
workflow, err := dataStore.CreateWorkflow(ctx, domain.CreateWorkflowInput{
|
||||
OrganizationID: project.OrganizationID,
|
||||
@ -2094,7 +2103,7 @@ func TestRuntimeAnnotationGateCreatesTasksAndReturnsAcceptedRevisionArtifact(t *
|
||||
Hyperparams: []domain.HyperParam{
|
||||
{Key: "REVIEW_MODE", Value: "annotation"},
|
||||
{Key: "ANNOTATION_TEMPLATE_ID", Value: template.ID},
|
||||
{Key: "ANNOTATION_WORKGROUP_ID", Value: group.ID},
|
||||
{Key: "ANNOTATION_SUPPLIER_ID", Value: supplier.ID},
|
||||
},
|
||||
}},
|
||||
},
|
||||
@ -2171,7 +2180,7 @@ func TestRuntimeAnnotationGateCreatesTasksAndReturnsAcceptedRevisionArtifact(t *
|
||||
t.Fatalf("human batches = %#v err=%v", batches, err)
|
||||
}
|
||||
humanItems, err := dataStore.ListHumanItems(ctx, project.OrganizationID, domain.HumanItemQuery{BatchID: batches[0].ID})
|
||||
if err != nil || len(humanItems) != 1 || humanItems[0].LegacyTaskID != tasks[0].ID || humanItems[0].CurrentStageID != "split_annotation" {
|
||||
if err != nil || len(humanItems) != 1 || humanItems[0].LegacyTaskID != tasks[0].ID || humanItems[0].CurrentStageID != domain.FanyuV58StageAnnotationCombined {
|
||||
t.Fatalf("human items = %#v err=%v", humanItems, err)
|
||||
}
|
||||
revisions, err := dataStore.ListAnnotationRevisions(ctx, project.OrganizationID, tasks[0].ID)
|
||||
|
||||
@ -173,9 +173,6 @@ data:
|
||||
FANYU_HEADPOSE_SERVICE_IMAGE_ID: "__HEADPOSE_SERVICE_IMAGE_ID__"
|
||||
FANYU_HEADPOSE_MODEL_SHA256: "__HEADPOSE_MODEL_SHA256__"
|
||||
FANYU_HEADPOSE_LICENSE_ID: "MIT"
|
||||
# Empty keeps the v5 template draft/fail-closed. Set the real published
|
||||
# annotation workgroup ID in the POC deployment environment before release.
|
||||
FANYU_V5_SUPPLIER_ID: "__FANYU_V5_SUPPLIER_ID__"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
@ -371,11 +368,6 @@ spec:
|
||||
configMapKeyRef:
|
||||
name: droboticflow-config
|
||||
key: FANYU_HEADPOSE_LICENSE_ID
|
||||
- name: FANYU_V5_SUPPLIER_ID
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: droboticflow-config
|
||||
key: FANYU_V5_SUPPLIER_ID
|
||||
- name: AI_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
|
||||
@ -57,4 +57,3 @@ export AI_MODEL="${AI_MODEL:-}"
|
||||
export HEADPOSE_MODEL_SHA256="${HEADPOSE_MODEL_SHA256:-sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018}"
|
||||
# Required only to publish/run the Fanyu v5 release. Keep blank until the
|
||||
# live POC annotation workgroup has been created and verified.
|
||||
export FANYU_V5_SUPPLIER_ID="${FANYU_V5_SUPPLIER_ID:-}"
|
||||
|
||||
@ -56,7 +56,6 @@ fi
|
||||
HEADPOSE_SERVICE_IMAGE="${HEADPOSE_SERVICE_IMAGE:-droboticflow-headpose-service:latest}"
|
||||
HEADPOSE_SERVICE_IMAGE_ID="${HEADPOSE_SERVICE_IMAGE_ID:-}"
|
||||
HEADPOSE_MODEL_SHA256="${HEADPOSE_MODEL_SHA256:-sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018}"
|
||||
FANYU_V5_SUPPLIER_ID="${FANYU_V5_SUPPLIER_ID:-}"
|
||||
DROBOTICFLOW_BUILD_COMMIT="${DROBOTICFLOW_BUILD_COMMIT:-$(git -C "$ROOT_DIR" rev-parse HEAD)}"
|
||||
DROBOTICFLOW_BUILD_TIME="${DROBOTICFLOW_BUILD_TIME:-}"
|
||||
OPERATOR_RUNNER_BUILD_COMMIT="${OPERATOR_RUNNER_BUILD_COMMIT:-$DROBOTICFLOW_BUILD_COMMIT}"
|
||||
@ -226,7 +225,6 @@ env \
|
||||
HEADPOSE_SERVICE_IMAGE="$HEADPOSE_SERVICE_IMAGE" \
|
||||
HEADPOSE_SERVICE_IMAGE_ID="$HEADPOSE_SERVICE_IMAGE_ID" \
|
||||
HEADPOSE_MODEL_SHA256="$HEADPOSE_MODEL_SHA256" \
|
||||
FANYU_V5_SUPPLIER_ID="$FANYU_V5_SUPPLIER_ID" \
|
||||
OPERATOR_RUNNER_BUILD_COMMIT="$OPERATOR_RUNNER_BUILD_COMMIT" \
|
||||
OPERATOR_RUNNER_BUILD_TIME="$OPERATOR_RUNNER_BUILD_TIME" \
|
||||
DROBOTICFLOW_BUILD_COMMIT="$DROBOTICFLOW_BUILD_COMMIT" \
|
||||
|
||||
@ -6,20 +6,19 @@ const apiURL = String(process.env.FANYU_API_URL || "http://120.48.180.80").repla
|
||||
const statePath = process.env.FANYU_ACCEPTANCE_STATE_PATH;
|
||||
const outputDir = process.env.FANYU_ACCEPTANCE_BROWSER_OUTPUT || "/tmp/fanyu-100-browser-acceptance";
|
||||
if (!statePath) throw new Error("FANYU_ACCEPTANCE_STATE_PATH is required");
|
||||
|
||||
const state = JSON.parse(fs.readFileSync(statePath, "utf8"));
|
||||
const projectId = state.projectId;
|
||||
const workflowId = state.workflowId;
|
||||
if (!projectId || !workflowId) throw new Error("acceptance state must include projectId and workflowId");
|
||||
|
||||
const projectId = String(state.projectId || "").trim();
|
||||
const workflowId = String(state.workflowId || "").trim();
|
||||
const browserFixture = state.browserFixture;
|
||||
const reportPath = path.join(outputDir, "browser-acceptance.json");
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
executablePath: process.env.CHROME_EXECUTABLE_PATH || "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
||||
});
|
||||
|
||||
const checks = [];
|
||||
const screenshots = [];
|
||||
const diagnostics = [];
|
||||
let browser;
|
||||
let fatalError = "";
|
||||
|
||||
function requireEnv(name) {
|
||||
const value = String(process.env[name] || "").trim();
|
||||
@ -27,101 +26,575 @@ function requireEnv(name) {
|
||||
return value;
|
||||
}
|
||||
|
||||
async function authenticatedContext(emailName, passwordName) {
|
||||
const context = await browser.newContext({ baseURL: apiURL, viewport: { width: 1920, height: 1080 } });
|
||||
const response = await context.request.post("/api/auth/login", {
|
||||
data: { email: requireEnv(emailName), password: requireEnv(passwordName) },
|
||||
});
|
||||
if (!response.ok()) throw new Error(`${emailName} login failed: ${response.status()}`);
|
||||
return context;
|
||||
function required(value, label) {
|
||||
const normalized = String(value || "").trim();
|
||||
if (!normalized) throw new Error(`state.browserFixture.${label} is required`);
|
||||
return normalized;
|
||||
}
|
||||
|
||||
async function screenshot(page, name) {
|
||||
const file = path.join(outputDir, `${name}.png`);
|
||||
await page.screenshot({ path: file, fullPage: false });
|
||||
screenshots.push(file);
|
||||
function record(name, passed, evidence = {}) {
|
||||
const item = { name, passed: Boolean(passed), evidence };
|
||||
checks.push(item);
|
||||
if (!item.passed) throw new Error(`${name} failed: ${JSON.stringify(evidence)}`);
|
||||
return item;
|
||||
}
|
||||
|
||||
async function checkPage(page, name, expectedText) {
|
||||
const issues = [];
|
||||
page.on("console", (message) => {
|
||||
if (["error", "warning"].includes(message.type())) issues.push(`${message.type()}: ${message.text()}`);
|
||||
});
|
||||
page.on("pageerror", (error) => issues.push(`pageerror: ${error.message}`));
|
||||
await page.getByText(expectedText, { exact: true }).waitFor({ state: "visible", timeout: 30_000 });
|
||||
const overlayCount = await page
|
||||
.locator("text=/Internal Server Error|Failed to compile|Vite Error|Webpack Error/i")
|
||||
.count();
|
||||
checks.push({
|
||||
name,
|
||||
passed: overlayCount === 0 && issues.length === 0,
|
||||
url: page.url(),
|
||||
overlayCount,
|
||||
consoleIssues: issues,
|
||||
});
|
||||
}
|
||||
|
||||
const adminContext = await authenticatedContext("DROBOTICFLOW_ACCEPTANCE_EMAIL", "DROBOTICFLOW_ACCEPTANCE_PASSWORD");
|
||||
const adminPage = await adminContext.newPage();
|
||||
await adminPage.goto(`/project/${projectId}`, { waitUntil: "domcontentloaded", timeout: 60_000 });
|
||||
await adminPage.getByText("成员与角色", { exact: true }).waitFor({ state: "visible", timeout: 30_000 });
|
||||
const membersTab = adminPage.getByText("成员与角色", { exact: true });
|
||||
if ((await membersTab.count()) !== 1) throw new Error("members tab is not unique");
|
||||
await membersTab.click();
|
||||
await adminPage.getByPlaceholder("搜索姓名、账号、供应商或角色").waitFor({ state: "visible", timeout: 15_000 });
|
||||
await adminPage.getByPlaceholder("搜索姓名、账号、供应商或角色").fill(String(state.acceptanceId || "acceptance"));
|
||||
const roleFilter = adminPage.getByLabel("按项目角色筛选");
|
||||
await roleFilter.selectOption("annotator");
|
||||
checks.push({
|
||||
name: "project_member_search_and_role_filter",
|
||||
passed: (await roleFilter.inputValue()) === "annotator",
|
||||
});
|
||||
await screenshot(adminPage, "admin-project-members");
|
||||
|
||||
await adminPage.goto(
|
||||
`/plugins/annotation-qa/workflows/${workflowId}/annotate?projectId=${projectId}&workflowId=${workflowId}`,
|
||||
{ waitUntil: "domcontentloaded", timeout: 60_000 },
|
||||
);
|
||||
await checkPage(adminPage, "admin_annotation_workbench", "任务池");
|
||||
for (const label of ["1. 项目", "2. 工作流", "3. Capture 子目录", "可领取", "我的任务", "全部任务"]) {
|
||||
if ((await adminPage.getByText(label, { exact: true }).count()) === 0) {
|
||||
checks.push({ name: `annotation_control_${label}`, passed: false });
|
||||
} else {
|
||||
checks.push({ name: `annotation_control_${label}`, passed: true });
|
||||
async function runCheck(name, action) {
|
||||
try {
|
||||
const evidence = (await action()) || {};
|
||||
checks.push({ name, passed: true, evidence });
|
||||
return true;
|
||||
} catch (error) {
|
||||
checks.push({ name, passed: false, evidence: { error: error instanceof Error ? error.message : String(error) } });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
await screenshot(adminPage, "admin-annotation-workbench");
|
||||
|
||||
const rolePages = [
|
||||
["annotator", "FANYU_ANNOTATOR_EMAIL", "FANYU_ANNOTATOR_PASSWORD", "annotate", "切分与语义标注"],
|
||||
["quality", "FANYU_QUALITY_EMAIL", "FANYU_QUALITY_PASSWORD", "quality", "切分与标注审核"],
|
||||
["acceptance", "FANYU_ACCEPTANCE_EMAIL", "FANYU_ACCEPTANCE_PASSWORD", "acceptance", "最终验收"],
|
||||
];
|
||||
for (const [name, emailName, passwordName, route, expectedText] of rolePages) {
|
||||
const context = await authenticatedContext(emailName, passwordName);
|
||||
const page = await context.newPage();
|
||||
await page.goto(
|
||||
`/plugins/annotation-qa/workflows/${workflowId}/${route}?projectId=${projectId}&workflowId=${workflowId}`,
|
||||
{ waitUntil: "domcontentloaded", timeout: 60_000 },
|
||||
);
|
||||
await checkPage(page, `${name}_role_workbench`, expectedText);
|
||||
await screenshot(page, `${name}-workbench`);
|
||||
await context.close();
|
||||
function validateFixtureContract() {
|
||||
const issues = [];
|
||||
if (!projectId) issues.push("projectId");
|
||||
if (!workflowId) issues.push("workflowId");
|
||||
if (!browserFixture || typeof browserFixture !== "object") {
|
||||
issues.push("browserFixture");
|
||||
} else {
|
||||
for (const stage of ["annotation", "quality", "acceptance"]) {
|
||||
if (!browserFixture[stage] || typeof browserFixture[stage] !== "object") issues.push(`browserFixture.${stage}`);
|
||||
}
|
||||
if (!browserFixture.member || typeof browserFixture.member !== "object") issues.push("browserFixture.member");
|
||||
const annotation = browserFixture.annotation || {};
|
||||
const quality = browserFixture.quality || {};
|
||||
const acceptance = browserFixture.acceptance || {};
|
||||
const member = browserFixture.member || {};
|
||||
if (!annotation.captureDirectory) issues.push("browserFixture.annotation.captureDirectory");
|
||||
if (!annotation.taskId) issues.push("browserFixture.annotation.taskId");
|
||||
if (!quality.captureDirectory) issues.push("browserFixture.quality.captureDirectory");
|
||||
if (!quality.taskId) issues.push("browserFixture.quality.taskId");
|
||||
if (!acceptance.captureDirectory) issues.push("browserFixture.acceptance.captureDirectory");
|
||||
if (!acceptance.humanItemId) issues.push("browserFixture.acceptance.humanItemId");
|
||||
if (!member.userId) issues.push("browserFixture.member.userId");
|
||||
if (!member.email) issues.push("browserFixture.member.email");
|
||||
if (member.disposable !== true) issues.push("browserFixture.member.disposable=true");
|
||||
}
|
||||
if (issues.length) {
|
||||
throw new Error(
|
||||
`browser fixture is incomplete (${issues.join(", ")}); refusing to replace real interaction acceptance with a title-only smoke test`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await adminContext.close();
|
||||
await browser.close();
|
||||
function watchPage(page, name) {
|
||||
const state = { name, consoleIssues: [], pageErrors: [], requestFailures: [], serverErrors: [] };
|
||||
page.on("console", (message) => {
|
||||
if (["error", "warning"].includes(message.type())) {
|
||||
state.consoleIssues.push(`${message.type()}: ${message.text()}`);
|
||||
}
|
||||
});
|
||||
page.on("pageerror", (error) => state.pageErrors.push(error.message));
|
||||
page.on("requestfailed", (request) => {
|
||||
const failure = request.failure()?.errorText || "failed";
|
||||
if (failure === "net::ERR_ABORTED") return;
|
||||
if (new URL(request.url()).origin !== apiURL) return;
|
||||
state.requestFailures.push(`${request.method()} ${request.url()} ${failure}`);
|
||||
});
|
||||
page.on("response", (response) => {
|
||||
if (response.status() >= 500 && new URL(response.url()).origin === apiURL) {
|
||||
state.serverErrors.push(`${response.status()} ${response.url()}`);
|
||||
}
|
||||
});
|
||||
diagnostics.push(state);
|
||||
return state;
|
||||
}
|
||||
|
||||
const report = {
|
||||
schemaVersion: "droboticflow.fanyu.browser-acceptance/v1",
|
||||
projectId,
|
||||
workflowId,
|
||||
passed: checks.every((item) => item.passed),
|
||||
checks,
|
||||
screenshots,
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
const reportPath = path.join(outputDir, "browser-acceptance.json");
|
||||
fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
|
||||
console.log(JSON.stringify({ passed: report.passed, reportPath, screenshots }, null, 2));
|
||||
if (!report.passed) process.exitCode = 1;
|
||||
function assertDiagnosticsHealthy(state, checkpoint) {
|
||||
const issues = [
|
||||
...state.consoleIssues,
|
||||
...state.pageErrors.map((value) => `pageerror: ${value}`),
|
||||
...state.requestFailures.map((value) => `requestfailed: ${value}`),
|
||||
...state.serverErrors.map((value) => `server: ${value}`),
|
||||
];
|
||||
if (issues.length) throw new Error(`${checkpoint} emitted browser/network errors: ${issues.join(" | ")}`);
|
||||
return { console: 0, pageErrors: 0, requestFailures: 0, serverErrors: 0 };
|
||||
}
|
||||
|
||||
async function authenticatedContext(emailName, passwordName, allowedRoles, viewport = { width: 1920, height: 1080 }) {
|
||||
const email = requireEnv(emailName).toLowerCase();
|
||||
const context = await browser.newContext({ baseURL: apiURL, viewport });
|
||||
const response = await context.request.post("/api/auth/login", {
|
||||
data: { email, password: requireEnv(passwordName) },
|
||||
});
|
||||
if (!response.ok()) throw new Error(`${emailName} login failed: ${response.status()}`);
|
||||
const meResponse = await context.request.get("/api/auth/me");
|
||||
if (!meResponse.ok()) throw new Error(`${emailName} identity lookup failed: ${meResponse.status()}`);
|
||||
const session = await meResponse.json();
|
||||
const actualEmail = String(session?.user?.email || "").toLowerCase();
|
||||
const actualRole = String(session?.user?.role || "");
|
||||
record(`identity_${emailName.toLowerCase()}`, actualEmail === email && allowedRoles.includes(actualRole), {
|
||||
expectedEmail: email,
|
||||
actualEmail,
|
||||
allowedRoles,
|
||||
actualRole,
|
||||
userId: session?.user?.id,
|
||||
});
|
||||
return { context, session };
|
||||
}
|
||||
|
||||
async function capture(page, name, fullPage = false) {
|
||||
const file = path.join(outputDir, `${name}.png`);
|
||||
await page.screenshot({ path: file, fullPage });
|
||||
screenshots.push(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
async function unique(locator, label) {
|
||||
await locator.waitFor({ state: "visible", timeout: 30_000 });
|
||||
const count = await locator.count();
|
||||
if (count !== 1) throw new Error(`${label} expected exactly one element, found ${count}`);
|
||||
return locator;
|
||||
}
|
||||
|
||||
function annotationURL(route, fixture) {
|
||||
const params = new URLSearchParams({
|
||||
projectId,
|
||||
workflowId,
|
||||
capture: required(fixture.captureDirectory, `${route}.captureDirectory`),
|
||||
});
|
||||
if (fixture.taskId) params.set("taskId", fixture.taskId);
|
||||
if (fixture.runId) params.set("runId", fixture.runId);
|
||||
return `/plugins/annotation-qa/workflows/${workflowId}/${route}?${params}`;
|
||||
}
|
||||
|
||||
async function selectPool(page, pool) {
|
||||
const button = page.getByTestId(`human-task-pool-${pool}`);
|
||||
if ((await button.count()) !== 1) return;
|
||||
if ((await button.getAttribute("aria-pressed")) === "true") return;
|
||||
const responsePromise = page.waitForResponse((response) => {
|
||||
const url = new URL(response.url());
|
||||
return url.pathname === "/api/human-items" && url.searchParams.get("pool") === pool;
|
||||
});
|
||||
await button.click();
|
||||
const response = await responsePromise;
|
||||
if (!response.ok()) throw new Error(`task pool ${pool} failed to load: ${response.status()}`);
|
||||
}
|
||||
|
||||
async function locateFixturePool(page, fixture, { acceptance = false } = {}) {
|
||||
const selector = acceptance
|
||||
? `[data-testid="acceptance-human-item"][data-human-item-id="${required(fixture.humanItemId, "acceptance.humanItemId")}"]`
|
||||
: `[data-testid="annotation-task-card"][data-task-id="${required(fixture.taskId, "taskId")}"]`;
|
||||
const candidates = [...new Set([fixture.pool, "mine", "available"].filter(Boolean))];
|
||||
for (const pool of candidates) {
|
||||
await selectPool(page, pool);
|
||||
const target = page.locator(selector);
|
||||
try {
|
||||
await target.waitFor({ state: "visible", timeout: 10_000 });
|
||||
return pool;
|
||||
} catch {
|
||||
// A resumable fixture can be unclaimed on the first run and already
|
||||
// claimed by the same role account on a later run.
|
||||
}
|
||||
}
|
||||
throw new Error(`fixture is not visible in task pools ${candidates.join(", ")}`);
|
||||
}
|
||||
|
||||
async function assertHierarchy(page, fixture, { taskRequired = true } = {}) {
|
||||
const projectSelect = await unique(page.getByLabel("1. 项目", { exact: true }), "project selector");
|
||||
const workflowSelect = await unique(page.getByLabel("2. 工作流", { exact: true }), "workflow selector");
|
||||
const captureSelect = await unique(page.getByLabel("3. Capture 子目录", { exact: true }), "Capture selector");
|
||||
const captureDirectory = required(fixture.captureDirectory, "captureDirectory");
|
||||
if ((await projectSelect.inputValue()) !== projectId)
|
||||
throw new Error("project selector does not hold the fixture project");
|
||||
if ((await workflowSelect.inputValue()) !== workflowId)
|
||||
throw new Error("workflow selector does not hold the fixture workflow");
|
||||
if ((await captureSelect.inputValue()) !== captureDirectory)
|
||||
throw new Error("Capture selector does not hold the fixture directory");
|
||||
const url = new URL(page.url());
|
||||
if (url.searchParams.get("projectId") !== projectId || url.searchParams.get("workflowId") !== workflowId) {
|
||||
throw new Error(`project/workflow URL scope is wrong: ${url}`);
|
||||
}
|
||||
if (url.searchParams.get("capture") !== captureDirectory) throw new Error(`Capture URL scope is wrong: ${url}`);
|
||||
|
||||
let taskEvidence = {};
|
||||
if (taskRequired) {
|
||||
const taskId = required(fixture.taskId, "taskId");
|
||||
const card = await unique(
|
||||
page.locator(`[data-testid="annotation-task-card"][data-task-id="${taskId}"]`),
|
||||
"fixture task card",
|
||||
);
|
||||
const displayedCapture = await card.getAttribute("data-capture-directory");
|
||||
const firstLine =
|
||||
String(await card.innerText())
|
||||
.split("\n")
|
||||
.map((value) => value.trim())
|
||||
.filter(Boolean)[0] || "";
|
||||
if (displayedCapture !== captureDirectory || firstLine !== captureDirectory) {
|
||||
throw new Error(`task card does not lead with Capture (${displayedCapture}; ${firstLine})`);
|
||||
}
|
||||
taskEvidence = { taskId, displayedCapture, firstLine };
|
||||
}
|
||||
return { projectId, workflowId, captureDirectory, url: page.url(), ...taskEvidence };
|
||||
}
|
||||
|
||||
async function exerciseHierarchyCascade(page, fixture) {
|
||||
const captureDirectory = required(fixture.captureDirectory, "annotation.captureDirectory");
|
||||
const taskId = required(fixture.taskId, "annotation.taskId");
|
||||
await page.goto(`/plugins/annotation-qa/workflows/all/annotate?projectId=${encodeURIComponent(projectId)}`, {
|
||||
waitUntil: "domcontentloaded",
|
||||
timeout: 60_000,
|
||||
});
|
||||
const projectSelect = await unique(page.getByLabel("1. 项目", { exact: true }), "cascade project selector");
|
||||
if ((await projectSelect.inputValue()) !== projectId) await projectSelect.selectOption(projectId);
|
||||
|
||||
const workflowSelect = await unique(page.getByLabel("2. 工作流", { exact: true }), "cascade workflow selector");
|
||||
await workflowSelect.selectOption(workflowId, { timeout: 30_000 });
|
||||
await page.waitForURL((url) => url.searchParams.get("workflowId") === workflowId, { timeout: 30_000 });
|
||||
|
||||
const captureSelect = await unique(page.getByLabel("3. Capture 子目录", { exact: true }), "cascade Capture selector");
|
||||
await captureSelect.selectOption(captureDirectory, { timeout: 30_000 });
|
||||
await page.waitForURL((url) => url.searchParams.get("capture") === captureDirectory, { timeout: 30_000 });
|
||||
|
||||
await selectPool(page, "all");
|
||||
const card = await unique(
|
||||
page.locator(`[data-testid="annotation-task-card"][data-task-id="${taskId}"]`),
|
||||
"cascade fixture task card",
|
||||
);
|
||||
await card.click();
|
||||
await page.waitForURL((url) => url.searchParams.get("taskId") === taskId, { timeout: 30_000 });
|
||||
return assertHierarchy(page, fixture);
|
||||
}
|
||||
|
||||
function rectanglesOverlap(left, right) {
|
||||
return (
|
||||
Math.max(0, Math.min(left.right, right.right) - Math.max(left.left, right.left)) > 1 &&
|
||||
Math.max(0, Math.min(left.bottom, right.bottom) - Math.max(left.top, right.top)) > 1
|
||||
);
|
||||
}
|
||||
|
||||
async function assertWorkbenchLayout(page, viewport) {
|
||||
await page.setViewportSize(viewport);
|
||||
const editor = await unique(page.getByTestId("annotation-workbench-editor"), "annotation editor");
|
||||
await editor.scrollIntoViewIfNeeded();
|
||||
const toolbarLocator = await unique(page.getByTestId("sticky-annotation-toolbar"), "annotation toolbar");
|
||||
await toolbarLocator.scrollIntoViewIfNeeded();
|
||||
const layout = await page.evaluate(() => {
|
||||
const rect = (selector) => {
|
||||
const element = document.querySelector(selector);
|
||||
if (!element) return null;
|
||||
const value = element.getBoundingClientRect();
|
||||
return {
|
||||
left: value.left,
|
||||
right: value.right,
|
||||
top: value.top,
|
||||
bottom: value.bottom,
|
||||
width: value.width,
|
||||
height: value.height,
|
||||
};
|
||||
};
|
||||
const toolbarElement = document.querySelector('[data-testid="sticky-annotation-toolbar"]');
|
||||
const toolbarRect = toolbarElement?.getBoundingClientRect();
|
||||
const toolbarHit = toolbarRect
|
||||
? document.elementFromPoint(toolbarRect.left + toolbarRect.width / 2, toolbarRect.top + toolbarRect.height / 2)
|
||||
: null;
|
||||
return {
|
||||
viewport: { width: window.innerWidth, height: window.innerHeight },
|
||||
editor: rect('[data-testid="annotation-workbench-editor"]'),
|
||||
video: rect('[data-testid="annotation-workbench-editor"] video'),
|
||||
timeline: rect('[data-testid="compact-annotation-timeline"]'),
|
||||
toolbar: rect('[data-testid="sticky-annotation-toolbar"]'),
|
||||
actions: rect('[data-testid="annotation-sticky-actions"]'),
|
||||
navigator: rect('[data-testid="slice-event-navigator"]'),
|
||||
toolbarUncovered: Boolean(toolbarElement && toolbarHit && toolbarElement.contains(toolbarHit)),
|
||||
};
|
||||
});
|
||||
for (const key of ["editor", "video", "timeline", "toolbar", "actions", "navigator"]) {
|
||||
if (!layout[key] || layout[key].width <= 0 || layout[key].height <= 0)
|
||||
throw new Error(`${key} has no rendered box`);
|
||||
}
|
||||
if (rectanglesOverlap(layout.toolbar, layout.actions))
|
||||
throw new Error("annotation toolbar is covered by submit actions");
|
||||
if (rectanglesOverlap(layout.navigator, layout.actions))
|
||||
throw new Error("slice navigator is covered by submit actions");
|
||||
if (layout.toolbar.top < 0 || layout.toolbar.bottom > layout.viewport.height || !layout.toolbarUncovered) {
|
||||
throw new Error("annotation toolbar is outside the viewport or covered by another layer");
|
||||
}
|
||||
const screenshot = await capture(page, `annotator-layout-${viewport.width}x${viewport.height}`);
|
||||
return { ...layout, screenshot };
|
||||
}
|
||||
|
||||
async function openMembers(page) {
|
||||
await page.goto(`/project/${projectId}`, { waitUntil: "domcontentloaded", timeout: 60_000 });
|
||||
const membersTab = await unique(page.getByText("成员与角色", { exact: true }), "members tab");
|
||||
await membersTab.click();
|
||||
await unique(page.getByTestId("project-members-panel"), "project members panel");
|
||||
}
|
||||
|
||||
function memberRow(page, userId) {
|
||||
return page.locator(`[data-testid="project-member-row"][data-user-id="${userId}"]`);
|
||||
}
|
||||
|
||||
async function searchMember(page, email, role = "all") {
|
||||
await page.getByTestId("project-member-search").fill(email);
|
||||
await page.getByTestId("project-member-role-filter").selectOption(role);
|
||||
}
|
||||
|
||||
async function ensureDisposableMember(page, fixture) {
|
||||
const userId = required(fixture.userId, "member.userId");
|
||||
const email = required(fixture.email, "member.email");
|
||||
await searchMember(page, email);
|
||||
if ((await memberRow(page, userId).count()) === 1) return;
|
||||
|
||||
await page.getByTestId("project-member-add").click();
|
||||
await unique(page.getByTestId("project-member-editor"), "member editor");
|
||||
await page.getByTestId("project-member-user").selectOption(userId);
|
||||
if (fixture.supplierId) await page.getByTestId("project-member-supplier").selectOption(fixture.supplierId);
|
||||
const initialRoles = fixture.initialRoles || ["annotator"];
|
||||
for (const role of ["annotator", "quality_reviewer", "acceptance_reviewer"]) {
|
||||
await page.getByTestId(`project-member-role-${role}`).setChecked(initialRoles.includes(role));
|
||||
}
|
||||
const responsePromise = page.waitForResponse(
|
||||
(response) =>
|
||||
response.request().method() === "POST" && response.url().endsWith(`/api/projects/${projectId}/members`),
|
||||
);
|
||||
await page.getByTestId("project-member-save").click();
|
||||
const response = await responsePromise;
|
||||
if (!response.ok()) throw new Error(`member fixture creation failed: ${response.status()}`);
|
||||
await searchMember(page, email);
|
||||
await memberRow(page, userId).waitFor({ state: "visible", timeout: 30_000 });
|
||||
}
|
||||
|
||||
async function exerciseMemberBulkOperations(page, fixture) {
|
||||
if (fixture.disposable !== true) throw new Error("member fixture must be explicitly disposable");
|
||||
const userId = required(fixture.userId, "member.userId");
|
||||
const email = required(fixture.email, "member.email");
|
||||
const targetRoles = fixture.bulkRoles || ["annotator", "quality_reviewer"];
|
||||
await ensureDisposableMember(page, fixture);
|
||||
|
||||
await searchMember(page, email, "annotator");
|
||||
let row = await unique(memberRow(page, userId), "disposable member row after search/filter");
|
||||
const selection = row.getByLabel(`选择成员 ${email}`, { exact: true });
|
||||
await selection.check();
|
||||
for (const role of ["annotator", "quality_reviewer", "acceptance_reviewer"]) {
|
||||
await page.getByTestId(`project-member-bulk-role-${role}`).setChecked(targetRoles.includes(role));
|
||||
}
|
||||
const setRolesResponse = page.waitForResponse(
|
||||
(response) =>
|
||||
response.request().method() === "POST" && response.url().endsWith(`/api/projects/${projectId}/members/bulk`),
|
||||
);
|
||||
await page.getByTestId("project-member-bulk-set-roles").click();
|
||||
const updated = await setRolesResponse;
|
||||
if (!updated.ok()) throw new Error(`bulk role update failed: ${updated.status()}`);
|
||||
await searchMember(page, email, targetRoles[0]);
|
||||
row = await unique(memberRow(page, userId), "member row after bulk role update");
|
||||
const renderedRoles = await row
|
||||
.locator("[data-role]")
|
||||
.evaluateAll((nodes) => nodes.map((node) => node.getAttribute("data-role")));
|
||||
if (targetRoles.some((role) => !renderedRoles.includes(role)) || renderedRoles.length !== targetRoles.length) {
|
||||
throw new Error(`bulk roles were not rendered exactly: ${JSON.stringify(renderedRoles)}`);
|
||||
}
|
||||
await capture(page, "admin-project-members-bulk-roles");
|
||||
|
||||
await page.reload({ waitUntil: "domcontentloaded", timeout: 60_000 });
|
||||
const membersTab = await unique(page.getByText("成员与角色", { exact: true }), "members tab after reload");
|
||||
await membersTab.click();
|
||||
await searchMember(page, email, targetRoles[0]);
|
||||
row = await unique(memberRow(page, userId), "persisted member row");
|
||||
const persistedRoles = await row
|
||||
.locator("[data-role]")
|
||||
.evaluateAll((nodes) => nodes.map((node) => node.getAttribute("data-role")));
|
||||
if (JSON.stringify([...persistedRoles].sort()) !== JSON.stringify([...targetRoles].sort())) {
|
||||
throw new Error(`bulk role update did not persist: ${JSON.stringify(persistedRoles)}`);
|
||||
}
|
||||
|
||||
await page.getByTestId("project-member-role-filter").selectOption("all");
|
||||
row = await unique(memberRow(page, userId), "member row before bulk removal");
|
||||
await row.getByLabel(`选择成员 ${email}`, { exact: true }).check();
|
||||
const removeResponse = page.waitForResponse(
|
||||
(response) =>
|
||||
response.request().method() === "POST" && response.url().endsWith(`/api/projects/${projectId}/members/bulk`),
|
||||
);
|
||||
await page.getByTestId("project-member-bulk-remove").click();
|
||||
const removed = await removeResponse;
|
||||
if (!removed.ok()) throw new Error(`bulk member removal failed: ${removed.status()}`);
|
||||
await memberRow(page, userId).waitFor({ state: "detached", timeout: 30_000 });
|
||||
await capture(page, "admin-project-members-bulk-removed");
|
||||
return { userId, email, targetRoles, persistedRoles, removed: true };
|
||||
}
|
||||
|
||||
async function inspectRoleWorkbench({ name, emailName, passwordName, allowedRoles, route, expectedText, fixture }) {
|
||||
const { context, session } = await authenticatedContext(emailName, passwordName, allowedRoles);
|
||||
const page = await context.newPage();
|
||||
const pageDiagnostics = watchPage(page, `${name}-workbench`);
|
||||
try {
|
||||
await page.goto(annotationURL(route, fixture), { waitUntil: "domcontentloaded", timeout: 60_000 });
|
||||
await unique(page.getByText(expectedText, { exact: true }), `${name} workbench title`);
|
||||
const pool = await locateFixturePool(page, fixture, { acceptance: name === "acceptance" });
|
||||
const hierarchy = await assertHierarchy(page, fixture, { taskRequired: name !== "acceptance" });
|
||||
if (name === "annotator") {
|
||||
const claim = page.getByText("领取标注任务", { exact: true });
|
||||
if ((await claim.count()) === 1) {
|
||||
await claim.click();
|
||||
await unique(page.getByText("释放任务", { exact: true }), "claimed annotator task");
|
||||
} else {
|
||||
await unique(page.getByText("释放任务", { exact: true }), "annotator task already claimed by this user");
|
||||
}
|
||||
await unique(page.getByTestId("annotation-workbench-editor"), "annotator workbench editor");
|
||||
} else if (name === "quality") {
|
||||
const claim = page.getByText("领取标注审核", { exact: true });
|
||||
if ((await claim.count()) === 1) {
|
||||
await claim.click();
|
||||
await unique(page.getByText("释放任务", { exact: true }), "claimed quality task");
|
||||
} else {
|
||||
await unique(page.getByText("释放任务", { exact: true }), "quality task already claimed by this user");
|
||||
}
|
||||
await unique(page.getByTestId("materialized-slice-workbench"), "quality materialized slice workbench");
|
||||
} else {
|
||||
const humanItemId = required(fixture.humanItemId, "acceptance.humanItemId");
|
||||
const item = await unique(
|
||||
page.locator(`[data-testid="acceptance-human-item"][data-human-item-id="${humanItemId}"]`),
|
||||
"acceptance fixture item",
|
||||
);
|
||||
const claim = item.getByText("领取最终验收", { exact: true });
|
||||
if ((await claim.count()) === 1) {
|
||||
await claim.click();
|
||||
await unique(item.getByText("释放任务", { exact: true }), "claimed final acceptance task");
|
||||
} else {
|
||||
await unique(item.getByText("释放任务", { exact: true }), "acceptance task already claimed by this user");
|
||||
}
|
||||
await unique(item.getByTestId("materialized-slice-workbench"), "acceptance materialized slice workbench");
|
||||
}
|
||||
await capture(page, `${name}-workbench-1920x1080`);
|
||||
return {
|
||||
session: { id: session.user.id, email: session.user.email, role: session.user.role },
|
||||
pool,
|
||||
hierarchy,
|
||||
diagnostics: assertDiagnosticsHealthy(pageDiagnostics, `${name} workbench`),
|
||||
};
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
validateFixtureContract();
|
||||
record("browser_fixture_contract", true, {
|
||||
projectId,
|
||||
workflowId,
|
||||
annotation: {
|
||||
captureDirectory: browserFixture.annotation.captureDirectory,
|
||||
taskId: browserFixture.annotation.taskId,
|
||||
humanItemId: browserFixture.annotation.humanItemId,
|
||||
runId: browserFixture.annotation.runId,
|
||||
},
|
||||
quality: {
|
||||
captureDirectory: browserFixture.quality.captureDirectory,
|
||||
taskId: browserFixture.quality.taskId,
|
||||
humanItemId: browserFixture.quality.humanItemId,
|
||||
runId: browserFixture.quality.runId,
|
||||
},
|
||||
acceptance: {
|
||||
captureDirectory: browserFixture.acceptance.captureDirectory,
|
||||
humanItemId: browserFixture.acceptance.humanItemId,
|
||||
runId: browserFixture.acceptance.runId,
|
||||
},
|
||||
member: {
|
||||
userId: browserFixture.member.userId,
|
||||
email: browserFixture.member.email,
|
||||
supplierId: browserFixture.member.supplierId,
|
||||
bulkRoles: browserFixture.member.bulkRoles,
|
||||
disposable: browserFixture.member.disposable,
|
||||
},
|
||||
});
|
||||
|
||||
browser = await chromium.launch({
|
||||
headless: true,
|
||||
executablePath:
|
||||
process.env.CHROME_EXECUTABLE_PATH || "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
||||
});
|
||||
|
||||
const { context: adminContext } = await authenticatedContext(
|
||||
"DROBOTICFLOW_ACCEPTANCE_EMAIL",
|
||||
"DROBOTICFLOW_ACCEPTANCE_PASSWORD",
|
||||
["admin", "organization_admin"],
|
||||
);
|
||||
const adminPage = await adminContext.newPage();
|
||||
const adminDiagnostics = watchPage(adminPage, "admin");
|
||||
try {
|
||||
await runCheck("project_member_real_bulk_operations", async () => {
|
||||
await openMembers(adminPage);
|
||||
return exerciseMemberBulkOperations(adminPage, browserFixture.member);
|
||||
});
|
||||
|
||||
await runCheck("admin_project_workflow_capture_cascade", async () => {
|
||||
const hierarchy = await exerciseHierarchyCascade(adminPage, browserFixture.annotation);
|
||||
await capture(adminPage, "admin-project-workflow-capture");
|
||||
return hierarchy;
|
||||
});
|
||||
|
||||
await runCheck("annotation_layout_1920_no_overlap", () =>
|
||||
assertWorkbenchLayout(adminPage, { width: 1920, height: 1080 }),
|
||||
);
|
||||
await runCheck("annotation_layout_1366_no_overlap", () =>
|
||||
assertWorkbenchLayout(adminPage, { width: 1366, height: 768 }),
|
||||
);
|
||||
await runCheck("admin_browser_diagnostics", () => assertDiagnosticsHealthy(adminDiagnostics, "admin interactions"));
|
||||
} finally {
|
||||
await adminContext.close();
|
||||
}
|
||||
|
||||
const rolePages = [
|
||||
{
|
||||
name: "annotator",
|
||||
emailName: "FANYU_ANNOTATOR_EMAIL",
|
||||
passwordName: "FANYU_ANNOTATOR_PASSWORD",
|
||||
allowedRoles: ["member", "annotator", "data_operator"],
|
||||
route: "annotate",
|
||||
expectedText: "切分与语义标注",
|
||||
fixture: browserFixture.annotation,
|
||||
},
|
||||
{
|
||||
name: "quality",
|
||||
emailName: "FANYU_QUALITY_EMAIL",
|
||||
passwordName: "FANYU_QUALITY_PASSWORD",
|
||||
allowedRoles: ["member", "quality_reviewer", "qa_reviewer", "auditor"],
|
||||
route: "quality",
|
||||
expectedText: "切分与标注审核",
|
||||
fixture: browserFixture.quality,
|
||||
},
|
||||
{
|
||||
name: "acceptance",
|
||||
emailName: "FANYU_ACCEPTANCE_EMAIL",
|
||||
passwordName: "FANYU_ACCEPTANCE_PASSWORD",
|
||||
allowedRoles: ["member", "acceptance_reviewer"],
|
||||
route: "acceptance",
|
||||
expectedText: "最终验收",
|
||||
fixture: browserFixture.acceptance,
|
||||
},
|
||||
];
|
||||
for (const rolePage of rolePages) {
|
||||
await runCheck(`${rolePage.name}_real_fixture_workbench`, () => inspectRoleWorkbench(rolePage));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await run();
|
||||
} catch (error) {
|
||||
fatalError = error instanceof Error ? error.message : String(error);
|
||||
checks.push({ name: "fatal_browser_acceptance", passed: false, evidence: { error: fatalError } });
|
||||
} finally {
|
||||
if (browser) await browser.close();
|
||||
const report = {
|
||||
schemaVersion: "droboticflow.fanyu.browser-acceptance/v2",
|
||||
projectId,
|
||||
workflowId,
|
||||
passed: !fatalError && checks.length > 0 && checks.every((item) => item.passed),
|
||||
checks,
|
||||
diagnostics,
|
||||
screenshots,
|
||||
statePath,
|
||||
createdAt: new Date().toISOString(),
|
||||
...(fatalError ? { error: fatalError } : {}),
|
||||
};
|
||||
fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
|
||||
console.log(
|
||||
JSON.stringify({ passed: report.passed, reportPath, screenshots, error: fatalError || undefined }, null, 2),
|
||||
);
|
||||
if (!report.passed) process.exitCode = 1;
|
||||
}
|
||||
|
||||
@ -153,7 +153,6 @@ validate_manifest_startup_configuration() {
|
||||
validate_http_service_url WORKER_API_BASE_URL "$WORKER_API_BASE_URL"
|
||||
validate_ai_runtime_configuration
|
||||
validate_optional_http_service_url BOS_ENDPOINT "$BOS_ENDPOINT"
|
||||
validate_optional_token_value FANYU_V5_SUPPLIER_ID "${FANYU_V5_SUPPLIER_ID:-}"
|
||||
validate_integer_min MONGO_CONNECT_RETRIES "$MONGO_CONNECT_RETRIES" 1
|
||||
validate_integer_min MONGO_CONNECT_RETRY_DELAY_MS "$MONGO_CONNECT_RETRY_DELAY_MS" 1
|
||||
validate_integer_min WORKER_POLL_INTERVAL_MS "$WORKER_POLL_INTERVAL_MS" 1
|
||||
|
||||
@ -70,7 +70,6 @@ DROBOTICFLOW_TRUSTED_PROXY_CIDRS="${DROBOTICFLOW_TRUSTED_PROXY_CIDRS:-}"
|
||||
HEADPOSE_SERVICE_IMAGE="${HEADPOSE_SERVICE_IMAGE:-droboticflow-headpose-service:latest}"
|
||||
HEADPOSE_SERVICE_IMAGE_ID="${HEADPOSE_SERVICE_IMAGE_ID:-}"
|
||||
HEADPOSE_MODEL_SHA256="${HEADPOSE_MODEL_SHA256:-sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018}"
|
||||
FANYU_V5_SUPPLIER_ID="${FANYU_V5_SUPPLIER_ID:-}"
|
||||
# shellcheck source=scripts/lib/image-config.sh
|
||||
source "$ROOT_DIR/scripts/lib/image-config.sh"
|
||||
REGISTRY_HOST="${REGISTRY_HOST:-}"
|
||||
@ -178,7 +177,6 @@ export \
|
||||
HEADPOSE_SERVICE_IMAGE \
|
||||
HEADPOSE_SERVICE_IMAGE_ID \
|
||||
HEADPOSE_MODEL_SHA256 \
|
||||
FANYU_V5_SUPPLIER_ID
|
||||
|
||||
python3 - <<'PY'
|
||||
import os
|
||||
@ -242,7 +240,6 @@ replacements = {
|
||||
"__HEADPOSE_SERVICE_IMAGE__": os.environ["HEADPOSE_SERVICE_IMAGE"],
|
||||
"__HEADPOSE_SERVICE_IMAGE_ID__": os.environ["HEADPOSE_SERVICE_IMAGE_ID"],
|
||||
"__HEADPOSE_MODEL_SHA256__": os.environ["HEADPOSE_MODEL_SHA256"],
|
||||
"__FANYU_V5_SUPPLIER_ID__": os.environ["FANYU_V5_SUPPLIER_ID"],
|
||||
}
|
||||
|
||||
rendered = template
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -35,6 +35,8 @@ export function ProjectMembersPanel({
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [addOpen, setAddOpen] = useState(false);
|
||||
const [batchAdd, setBatchAdd] = useState(false);
|
||||
const [batchUserIds, setBatchUserIds] = useState<string[]>([]);
|
||||
const [draft, setDraft] = useState<{ userId: string; supplierId: string; roles: ProjectMemberRole[] }>({
|
||||
userId: "",
|
||||
supplierId: "",
|
||||
@ -78,12 +80,22 @@ export function ProjectMembersPanel({
|
||||
};
|
||||
|
||||
const saveNew = async () => {
|
||||
if (!draft.userId || draft.roles.length === 0) return;
|
||||
const userIds = batchAdd ? batchUserIds : draft.userId ? [draft.userId] : [];
|
||||
if (userIds.length === 0 || draft.roles.length === 0) return;
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await projectsApi.createMember(projectId, draft);
|
||||
if (batchAdd) {
|
||||
await projectsApi.bulkMembers(projectId, {
|
||||
action: "add",
|
||||
entries: userIds.map((userId) => ({ userId, supplierId: draft.supplierId || undefined, roles: draft.roles })),
|
||||
});
|
||||
} else {
|
||||
await projectsApi.createMember(projectId, draft);
|
||||
}
|
||||
setAddOpen(false);
|
||||
setBatchAdd(false);
|
||||
setBatchUserIds([]);
|
||||
setDraft({ userId: "", supplierId: "", roles: ["annotator"] });
|
||||
await reload();
|
||||
} catch (cause) {
|
||||
@ -146,7 +158,7 @@ export function ProjectMembersPanel({
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="space-y-4">
|
||||
<section className="space-y-4" data-testid="project-members-panel">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 rounded-xl border border-[#2a2b2f] bg-[#151619] p-5">
|
||||
<div>
|
||||
<div className="flex items-center gap-2 text-lg font-semibold text-white">
|
||||
@ -159,6 +171,7 @@ export function ProjectMembersPanel({
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setAddOpen(true)}
|
||||
data-testid="project-member-add"
|
||||
className="inline-flex items-center gap-2 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white"
|
||||
>
|
||||
<UserPlus className="h-4 w-4" />
|
||||
@ -173,6 +186,7 @@ export function ProjectMembersPanel({
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="搜索姓名、账号、供应商或角色"
|
||||
data-testid="project-member-search"
|
||||
className="w-full rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] py-2 pl-9 pr-3 text-sm text-white"
|
||||
/>
|
||||
</label>
|
||||
@ -180,6 +194,7 @@ export function ProjectMembersPanel({
|
||||
value={roleFilter}
|
||||
onChange={(event) => setRoleFilter(event.target.value as "all" | ProjectMemberRole)}
|
||||
aria-label="按项目角色筛选"
|
||||
data-testid="project-member-role-filter"
|
||||
className="rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-2 text-sm text-white"
|
||||
>
|
||||
<option value="all">全部角色</option>
|
||||
@ -197,6 +212,8 @@ export function ProjectMembersPanel({
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={bulkRoles.includes(item.value)}
|
||||
aria-label={`批量角色 ${item.label}`}
|
||||
data-testid={`project-member-bulk-role-${item.value}`}
|
||||
onChange={() =>
|
||||
setBulkRoles((current) =>
|
||||
current.includes(item.value)
|
||||
@ -212,6 +229,7 @@ export function ProjectMembersPanel({
|
||||
type="button"
|
||||
onClick={() => void bulk("set_roles")}
|
||||
disabled={saving}
|
||||
data-testid="project-member-bulk-set-roles"
|
||||
className="rounded-lg border border-blue-500/30 px-3 py-2 text-xs text-blue-200"
|
||||
>
|
||||
应用批量角色
|
||||
@ -220,6 +238,7 @@ export function ProjectMembersPanel({
|
||||
type="button"
|
||||
onClick={() => void bulk("remove")}
|
||||
disabled={saving}
|
||||
data-testid="project-member-bulk-remove"
|
||||
className="rounded-lg border border-red-500/30 px-3 py-2 text-xs text-red-200"
|
||||
>
|
||||
批量移出
|
||||
@ -238,6 +257,8 @@ export function ProjectMembersPanel({
|
||||
<th className="px-4 py-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
aria-label="选择当前筛选结果中的全部成员"
|
||||
data-testid="project-members-select-all"
|
||||
checked={visibleMembers.length > 0 && visibleMembers.every((item) => selectedIds.includes(item.id))}
|
||||
onChange={(event) =>
|
||||
setSelectedIds(event.target.checked ? visibleMembers.map((item) => item.id) : [])
|
||||
@ -256,11 +277,20 @@ export function ProjectMembersPanel({
|
||||
const user = users.find((item) => item.id === member.userId);
|
||||
const supplier = suppliers.find((item) => item.id === member.supplierId);
|
||||
return (
|
||||
<tr key={member.id} className="hover:bg-white/[0.02]">
|
||||
<tr
|
||||
key={member.id}
|
||||
className="hover:bg-white/[0.02]"
|
||||
data-testid="project-member-row"
|
||||
data-member-id={member.id}
|
||||
data-user-id={member.userId}
|
||||
data-user-email={user?.email || ""}
|
||||
>
|
||||
{canManage ? (
|
||||
<td className="px-4 py-4">
|
||||
<input
|
||||
type="checkbox"
|
||||
aria-label={`选择成员 ${user?.email || member.userId}`}
|
||||
data-testid={`project-member-select-${member.id}`}
|
||||
checked={selectedIds.includes(member.id)}
|
||||
onChange={(event) =>
|
||||
setSelectedIds((current) =>
|
||||
@ -280,6 +310,7 @@ export function ProjectMembersPanel({
|
||||
{member.roles.map((role) => (
|
||||
<span
|
||||
key={role}
|
||||
data-role={role}
|
||||
className="rounded-md border border-blue-500/25 bg-blue-500/10 px-2 py-1 text-xs text-blue-200"
|
||||
>
|
||||
{roleOptions.find((item) => item.value === role)?.label}
|
||||
@ -293,6 +324,7 @@ export function ProjectMembersPanel({
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setEditing({ ...member, roles: [...member.roles] })}
|
||||
aria-label={`编辑成员 ${user?.email || member.userId}`}
|
||||
className="rounded border border-[#2a2b2f] p-1.5 text-gray-300"
|
||||
>
|
||||
<Edit3 className="h-3.5 w-3.5" />
|
||||
@ -301,6 +333,7 @@ export function ProjectMembersPanel({
|
||||
type="button"
|
||||
onClick={() => void remove(member)}
|
||||
disabled={saving}
|
||||
aria-label={`移出成员 ${user?.email || member.userId}`}
|
||||
className="rounded border border-red-500/20 p-1.5 text-red-300"
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
@ -322,7 +355,7 @@ export function ProjectMembersPanel({
|
||||
</table>
|
||||
</div>
|
||||
{addOpen || editing ? (
|
||||
<div className="rounded-xl border border-blue-500/30 bg-[#151619] p-5">
|
||||
<div className="rounded-xl border border-blue-500/30 bg-[#151619] p-5" data-testid="project-member-editor">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="font-semibold text-white">{editing ? "编辑项目角色" : "添加项目成员"}</h3>
|
||||
<button
|
||||
@ -337,23 +370,64 @@ export function ProjectMembersPanel({
|
||||
</button>
|
||||
</div>
|
||||
{!editing ? (
|
||||
<label className="mt-4 block text-xs text-gray-400">
|
||||
用户
|
||||
<select
|
||||
value={draft.userId}
|
||||
onChange={(event) => setDraft((current) => ({ ...current, userId: event.target.value }))}
|
||||
className="mt-1 w-full rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] p-2 text-sm text-white"
|
||||
>
|
||||
<option value="">选择用户</option>
|
||||
{users
|
||||
.filter((user) => user.status !== "disabled")
|
||||
.map((user) => (
|
||||
<option key={user.id} value={user.id}>
|
||||
{user.name} · {user.email}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<div className="mt-4 space-y-3">
|
||||
<label className="inline-flex items-center gap-2 text-xs text-gray-300">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={batchAdd}
|
||||
data-testid="project-member-batch-add-toggle"
|
||||
onChange={(event) => {
|
||||
setBatchAdd(event.target.checked);
|
||||
setBatchUserIds([]);
|
||||
setDraft((current) => ({ ...current, userId: "" }));
|
||||
}}
|
||||
/>
|
||||
一次添加多名成员
|
||||
</label>
|
||||
{batchAdd ? (
|
||||
<fieldset className="max-h-48 space-y-1 overflow-y-auto rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] p-3">
|
||||
<legend className="px-1 text-xs text-gray-400">选择用户</legend>
|
||||
{users
|
||||
.filter((user) => user.status !== "disabled" && !members.some((member) => member.userId === user.id))
|
||||
.map((user) => (
|
||||
<label key={user.id} className="flex items-center gap-2 rounded px-2 py-1.5 text-sm text-gray-200">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={batchUserIds.includes(user.id)}
|
||||
data-testid={`project-member-batch-user-${user.id}`}
|
||||
onChange={(event) =>
|
||||
setBatchUserIds((current) =>
|
||||
event.target.checked
|
||||
? [...current, user.id]
|
||||
: current.filter((userId) => userId !== user.id),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<span>{user.name} · {user.email}</span>
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
) : (
|
||||
<label className="block text-xs text-gray-400">
|
||||
用户
|
||||
<select
|
||||
value={draft.userId}
|
||||
onChange={(event) => setDraft((current) => ({ ...current, userId: event.target.value }))}
|
||||
data-testid="project-member-user"
|
||||
className="mt-1 w-full rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] p-2 text-sm text-white"
|
||||
>
|
||||
<option value="">选择用户</option>
|
||||
{users
|
||||
.filter((user) => user.status !== "disabled" && !members.some((member) => member.userId === user.id))
|
||||
.map((user) => (
|
||||
<option key={user.id} value={user.id}>
|
||||
{user.name} · {user.email}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="mt-4 text-sm text-gray-300">
|
||||
{users.find((user) => user.id === editing.userId)?.name || editing.userId}
|
||||
@ -368,6 +442,7 @@ export function ProjectMembersPanel({
|
||||
? setEditing({ ...editing, supplierId: event.target.value })
|
||||
: setDraft((current) => ({ ...current, supplierId: event.target.value }))
|
||||
}
|
||||
data-testid="project-member-supplier"
|
||||
className="mt-1 w-full rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] p-2 text-sm text-white"
|
||||
>
|
||||
<option value="">内部成员 / 不限定供应商</option>
|
||||
@ -390,6 +465,8 @@ export function ProjectMembersPanel({
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
aria-label={`项目角色 ${option.label}`}
|
||||
data-testid={`project-member-role-${option.value}`}
|
||||
onChange={() =>
|
||||
editing
|
||||
? setEditing({
|
||||
@ -413,6 +490,7 @@ export function ProjectMembersPanel({
|
||||
type="button"
|
||||
onClick={() => void (editing ? saveEdit() : saveNew())}
|
||||
disabled={saving}
|
||||
data-testid="project-member-save"
|
||||
className="mt-4 inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm text-white"
|
||||
>
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Check className="h-4 w-4" />} 保存
|
||||
|
||||
@ -38,8 +38,8 @@ import type {
|
||||
ExecutionData,
|
||||
ExecutionRun,
|
||||
Project,
|
||||
ProjectAnnotationMembership,
|
||||
ProjectMember,
|
||||
ProjectMemberRole,
|
||||
SliceOperation,
|
||||
SliceSegment,
|
||||
Workflow,
|
||||
@ -275,7 +275,9 @@ function humanItemVisibleInMode(item: HumanItem, mode: WorkspaceMode) {
|
||||
return item.currentStageId === "acceptance" || item.currentStageId === "prepackage_acceptance";
|
||||
}
|
||||
|
||||
function assignmentRoleForStage(stageId: string): ProjectAnnotationMembership["assignmentRole"] {
|
||||
type HumanAssignmentRole = ProjectMemberRole | "cutter";
|
||||
|
||||
function assignmentRoleForStage(stageId: string): HumanAssignmentRole {
|
||||
if (stageId === "split_annotation" || stageId === "cut_adjustment") return "cutter";
|
||||
if (
|
||||
stageId === "split_quality_review" ||
|
||||
@ -289,14 +291,11 @@ function assignmentRoleForStage(stageId: string): ProjectAnnotationMembership["a
|
||||
return "quality_reviewer";
|
||||
}
|
||||
|
||||
function assignmentRoleMatches(
|
||||
actual: ProjectAnnotationMembership["assignmentRole"],
|
||||
required: ProjectAnnotationMembership["assignmentRole"],
|
||||
) {
|
||||
function assignmentRoleMatches(actual: HumanAssignmentRole, required: HumanAssignmentRole) {
|
||||
return actual === required;
|
||||
}
|
||||
|
||||
function assignmentRoleLabel(role: ProjectAnnotationMembership["assignmentRole"]) {
|
||||
function assignmentRoleLabel(role: HumanAssignmentRole) {
|
||||
if (role === "cutter") return "人工剪切员";
|
||||
if (role === "annotator") return "标注员";
|
||||
if (role === "quality_reviewer") return "审核员";
|
||||
@ -388,6 +387,7 @@ export default function AnnotationOperations() {
|
||||
const [error, setError] = useState("");
|
||||
const [projectLoadError, setProjectLoadError] = useState("");
|
||||
const [projectLoadRecoveryNotice, setProjectLoadRecoveryNotice] = useState("");
|
||||
const [combinedSubmissionNotice, setCombinedSubmissionNotice] = useState("");
|
||||
const [projectLoadRetryVersion, setProjectLoadRetryVersion] = useState(0);
|
||||
|
||||
const [previewTab, setPreviewTab] = useState<"video" | "rerun">("video");
|
||||
@ -880,7 +880,7 @@ export default function AnnotationOperations() {
|
||||
const eligibleAssigneesForScope = useCallback(
|
||||
(
|
||||
supplierId: string | undefined,
|
||||
requiredRole: ProjectAnnotationMembership["assignmentRole"],
|
||||
requiredRole: HumanAssignmentRole,
|
||||
currentAssigneeId = "",
|
||||
) => {
|
||||
if (!isManager) return [];
|
||||
@ -889,7 +889,7 @@ export default function AnnotationOperations() {
|
||||
.filter(
|
||||
(member) =>
|
||||
member.roles.includes(requiredRole as ProjectMember["roles"][number]) &&
|
||||
(!member.supplierId || !supplierId || member.supplierId === supplierId),
|
||||
(supplierId ? member.supplierId === supplierId : true),
|
||||
)
|
||||
.map((member) => member.userId),
|
||||
);
|
||||
@ -918,6 +918,7 @@ export default function AnnotationOperations() {
|
||||
const isV5CombinedQuality = Boolean(
|
||||
detail && detail.task.templateVersion >= 5 && selectedHumanItem?.currentStageId === "quality_review",
|
||||
);
|
||||
const combinedSubmissionProcessing = Boolean(detail?.humanItem?.pendingCombinedSubmissionId);
|
||||
const selectedClaimedByMe = Boolean(
|
||||
selectedHumanItem &&
|
||||
selectedHumanItem.assignedUserId === currentUser?.id &&
|
||||
@ -1157,7 +1158,7 @@ export default function AnnotationOperations() {
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await annotationOperationsApi.submitCombined(detail.task.id, {
|
||||
const submission = await annotationOperationsApi.submitCombined(detail.task.id, {
|
||||
version: detail.humanItem.version,
|
||||
sliceSegments: applySliceStatuses(sliceSegments, progress.statuses),
|
||||
sliceOperations,
|
||||
@ -1165,10 +1166,17 @@ export default function AnnotationOperations() {
|
||||
requireSliceCompletion: true,
|
||||
changeReason: detail.task.currentRevision > 0 ? "v5 同任务返工切片与语义修订" : "v5 同任务首次切片与语义标注",
|
||||
});
|
||||
if (submission.status === "processing") {
|
||||
setCombinedSubmissionNotice("已提交,系统正在后台生成左右视频、PTS 和 IMU 同步切片;可继续处理其他任务。");
|
||||
}
|
||||
setSliceOperations([]);
|
||||
setSliceHistory([]);
|
||||
await loadProject();
|
||||
setDetail(await annotationOperationsApi.getTask(detail.task.id));
|
||||
try {
|
||||
setDetail(await annotationOperationsApi.getTask(detail.task.id));
|
||||
} catch {
|
||||
setDetail(null);
|
||||
}
|
||||
} catch (saveError) {
|
||||
setError(getActionErrorMessage(saveError, "提交切片与语义标注失败"));
|
||||
} finally {
|
||||
@ -1176,6 +1184,30 @@ export default function AnnotationOperations() {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!detail?.task.id || !combinedSubmissionProcessing) return;
|
||||
const taskId = detail.task.id;
|
||||
const timer = window.setInterval(() => {
|
||||
annotationOperationsApi
|
||||
.getTask(taskId)
|
||||
.then((nextDetail) => {
|
||||
if (!nextDetail.humanItem?.pendingCombinedSubmissionId) {
|
||||
setCombinedSubmissionNotice("同步切片已生成,任务已进入审核池。");
|
||||
window.clearInterval(timer);
|
||||
void loadProject();
|
||||
}
|
||||
setDetail(nextDetail);
|
||||
})
|
||||
.catch(() => {
|
||||
window.clearInterval(timer);
|
||||
setCombinedSubmissionNotice("同步切片已生成,任务已进入审核池。");
|
||||
setDetail(null);
|
||||
void loadProject();
|
||||
});
|
||||
}, 3000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [combinedSubmissionProcessing, detail?.task.id, loadProject]);
|
||||
|
||||
const saveCombinedDraft = async () => {
|
||||
if (!detail?.humanItem || !isV5Combined || !selectedClaimedByMe) return false;
|
||||
if (annotationWorkspaceIssues.length > 0) {
|
||||
@ -1281,10 +1313,10 @@ export default function AnnotationOperations() {
|
||||
: ["quality_review"]
|
||||
: undefined,
|
||||
reasonCodes: decision === "rejected" ? ["manual_review_reject"] : undefined,
|
||||
videoQuality: qualityDraft.videoQuality,
|
||||
annotationAccuracy: Number(qualityDraft.annotationAccuracy),
|
||||
annotationCompleteness: Number(qualityDraft.annotationCompleteness),
|
||||
overallGrade: qualityDraft.overallGrade,
|
||||
videoQuality: isV5CombinedQuality ? undefined : qualityDraft.videoQuality,
|
||||
annotationAccuracy: isV5CombinedQuality ? undefined : Number(qualityDraft.annotationAccuracy),
|
||||
annotationCompleteness: isV5CombinedQuality ? undefined : Number(qualityDraft.annotationCompleteness),
|
||||
overallGrade: isV5CombinedQuality ? undefined : qualityDraft.overallGrade,
|
||||
});
|
||||
setReviewComment("");
|
||||
await loadProject();
|
||||
@ -1791,6 +1823,15 @@ export default function AnnotationOperations() {
|
||||
<div role="alert" className="rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-200">
|
||||
{error || projectLoadError}
|
||||
</div>
|
||||
) : combinedSubmissionNotice ? (
|
||||
<div
|
||||
role="status"
|
||||
data-testid="combined-submission-status"
|
||||
className="flex items-center gap-2 rounded-xl border border-blue-500/30 bg-blue-500/10 px-4 py-3 text-sm text-blue-100"
|
||||
>
|
||||
{combinedSubmissionProcessing ? <Loader2 className="h-4 w-4 animate-spin" /> : <CheckCircle2 className="h-4 w-4" />}
|
||||
{combinedSubmissionNotice}
|
||||
</div>
|
||||
) : projectLoadRecoveryNotice ? (
|
||||
<div
|
||||
role="status"
|
||||
@ -1908,6 +1949,8 @@ export default function AnnotationOperations() {
|
||||
key={value}
|
||||
type="button"
|
||||
onClick={() => setTaskPoolView(value)}
|
||||
data-testid={`human-task-pool-${value}`}
|
||||
aria-pressed={taskPoolView === value}
|
||||
className={`rounded-lg border px-3 py-2 text-xs transition-colors ${taskPoolView === value ? "border-blue-500 bg-blue-500/10 text-blue-200" : "border-[#2a2b2f] text-gray-400 hover:text-white"}`}
|
||||
>
|
||||
{label} {count}
|
||||
@ -1949,7 +1992,12 @@ export default function AnnotationOperations() {
|
||||
item.assignedUserId,
|
||||
);
|
||||
return (
|
||||
<div key={item.id} className={`${panelClass} space-y-4 border-blue-500/30 p-5`}>
|
||||
<div
|
||||
key={item.id}
|
||||
className={`${panelClass} space-y-4 border-blue-500/30 p-5`}
|
||||
data-testid="acceptance-human-item"
|
||||
data-human-item-id={item.id}
|
||||
>
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<div className="text-base font-semibold text-white">整包最终验收 · 全部切片汇总</div>
|
||||
@ -2542,6 +2590,8 @@ export default function AnnotationOperations() {
|
||||
key={value}
|
||||
type="button"
|
||||
onClick={() => setTaskPoolView(value)}
|
||||
data-testid={`human-task-pool-${value}`}
|
||||
aria-pressed={taskPoolView === value}
|
||||
className={`rounded-lg border px-3 py-2 text-xs transition-colors ${taskPoolView === value ? "border-blue-500 bg-blue-500/10 text-blue-200" : "border-[#2a2b2f] text-gray-400 hover:text-white"}`}
|
||||
>
|
||||
{label} {count}
|
||||
@ -2584,6 +2634,9 @@ export default function AnnotationOperations() {
|
||||
key={task.id}
|
||||
type="button"
|
||||
onClick={() => selectTask(task.id)}
|
||||
data-testid="annotation-task-card"
|
||||
data-task-id={task.id}
|
||||
data-capture-directory={captureLabel}
|
||||
className={`w-full rounded-lg border px-3 py-2.5 text-left ${selectedTaskId === task.id ? "border-blue-500 bg-blue-500/10" : "border-[#2a2b2f] bg-[#0f1012] hover:border-blue-500/30"}`}
|
||||
>
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
@ -3186,7 +3239,7 @@ export default function AnnotationOperations() {
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{workspaceMode === "clip-quality" || workspaceMode === "quality" ? (
|
||||
{(workspaceMode === "clip-quality" || workspaceMode === "quality") && !isV5CombinedQuality ? (
|
||||
<div className="grid gap-3 rounded-xl border border-[#2a2b2f] bg-[#101114] p-4 md:grid-cols-4">
|
||||
<label className="space-y-1 text-xs text-gray-400">
|
||||
<span>视频质量</span>
|
||||
@ -3310,6 +3363,7 @@ export default function AnnotationOperations() {
|
||||
onClick={() => void submitCombined()}
|
||||
disabled={
|
||||
saving ||
|
||||
combinedSubmissionProcessing ||
|
||||
!sliceCoverage.complete ||
|
||||
!selectedClaimedByMe ||
|
||||
sliceProgress.pending > 0 ||
|
||||
|
||||
@ -8,6 +8,7 @@ import {
|
||||
Loader2,
|
||||
Play,
|
||||
RefreshCw,
|
||||
Search,
|
||||
Server,
|
||||
XCircle,
|
||||
Bug,
|
||||
@ -44,14 +45,22 @@ const emptyWorkbench: WorkbenchState = { running: [], failed: [], waitingForAudi
|
||||
const formatRate = (value: number | null | undefined) => (value == null ? "--" : `${value.toFixed(1)}%`);
|
||||
|
||||
function WorkforceSummaryPanel({ summary }: { summary: DashboardSummary | null }) {
|
||||
const [memberQuery, setMemberQuery] = useState("");
|
||||
const workforce = summary?.workforce;
|
||||
const totals = workforce?.totals;
|
||||
const cards: Array<[string, string | number]> = [
|
||||
["正式产出", totals?.outputCount ?? 0],
|
||||
["产出时长", `${((totals?.durationSeconds || 0) / 3600).toFixed(2)} h`],
|
||||
["返工率", formatRate(totals?.reworkRate)],
|
||||
["质检通过率", formatRate(totals?.qualityPassRate)],
|
||||
["验收通过率", formatRate(totals?.acceptancePassRate)],
|
||||
];
|
||||
const normalizedMemberQuery = memberQuery.trim().toLowerCase();
|
||||
const visibleItems = (workforce?.items || []).filter((item) =>
|
||||
`${item.userName || ""} ${item.userId || ""} ${item.supplierId || ""}`
|
||||
.toLowerCase()
|
||||
.includes(normalizedMemberQuery),
|
||||
);
|
||||
return (
|
||||
<section className="space-y-4">
|
||||
<div>
|
||||
@ -66,7 +75,7 @@ function WorkforceSummaryPanel({ summary }: { summary: DashboardSummary | null }
|
||||
统计区间:{workforce?.from || "--"} 至 {workforce?.to || "--"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-5">
|
||||
{cards.map(([label, value]) => (
|
||||
<div key={label} className="rounded-xl border border-[#2a2b2f] bg-[#151619] p-4">
|
||||
<div className="text-xs text-gray-500">{label}</div>
|
||||
@ -74,30 +83,49 @@ function WorkforceSummaryPanel({ summary }: { summary: DashboardSummary | null }
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid gap-3 rounded-xl border border-[#2a2b2f] bg-[#111214] p-4 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-center">
|
||||
<label className="relative">
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-500" />
|
||||
<input
|
||||
value={memberQuery}
|
||||
onChange={(event) => setMemberQuery(event.target.value)}
|
||||
placeholder="按成员姓名、账号或供应商筛选"
|
||||
aria-label="筛选供应商成员指标"
|
||||
className="w-full rounded-lg border border-[#2a2b2f] bg-black py-2 pl-9 pr-3 text-sm text-white focus:border-blue-500 focus:outline-none"
|
||||
/>
|
||||
</label>
|
||||
<p className="text-xs leading-5 text-gray-500">
|
||||
返工率 = 返工提交 ÷ 全部提交;质检/验收通过率 = 通过 ÷(通过 + 打回)
|
||||
</p>
|
||||
</div>
|
||||
<div className="overflow-hidden rounded-xl border border-[#2a2b2f] bg-[#151619]">
|
||||
<div className="grid grid-cols-[1.2fr_1fr_repeat(4,0.8fr)] gap-3 border-b border-[#2a2b2f] px-4 py-3 text-xs text-gray-500">
|
||||
<div className="grid grid-cols-[1.2fr_1fr_repeat(5,0.8fr)] gap-3 border-b border-[#2a2b2f] px-4 py-3 text-xs text-gray-500">
|
||||
<span>成员</span>
|
||||
<span>供应商</span>
|
||||
<span>产出</span>
|
||||
<span>工时</span>
|
||||
<span>返工率</span>
|
||||
<span>质检</span>
|
||||
<span>验收</span>
|
||||
</div>
|
||||
{(workforce?.items || []).map((item: DashboardWorkforceMetric, index) => (
|
||||
{visibleItems.map((item: DashboardWorkforceMetric, index) => (
|
||||
<div
|
||||
key={`${item.userId}-${item.supplierId}-${index}`}
|
||||
className="grid grid-cols-[1.2fr_1fr_repeat(4,0.8fr)] gap-3 border-b border-[#202227] px-4 py-3 text-sm text-gray-300"
|
||||
className="grid grid-cols-[1.2fr_1fr_repeat(5,0.8fr)] gap-3 border-b border-[#202227] px-4 py-3 text-sm text-gray-300"
|
||||
>
|
||||
<span>{item.userName || item.userId || "系统"}</span>
|
||||
<span>{item.supplierId || "内部成员"}</span>
|
||||
<span>{item.outputCount}</span>
|
||||
<span>{(item.durationSeconds / 3600).toFixed(2)} h</span>
|
||||
<span>{formatRate(item.reworkRate)}</span>
|
||||
<span>{formatRate(item.qualityPassRate)}</span>
|
||||
<span>{formatRate(item.acceptancePassRate)}</span>
|
||||
</div>
|
||||
))}
|
||||
{!workforce?.items?.length ? (
|
||||
<div className="px-4 py-10 text-center text-sm text-gray-500">当前统计区间暂无工作量事件</div>
|
||||
{!visibleItems.length ? (
|
||||
<div className="px-4 py-10 text-center text-sm text-gray-500">
|
||||
{workforce?.items?.length ? "没有匹配的成员指标" : "当前统计区间暂无工作量事件"}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@ -32,8 +32,9 @@ import { canManagePipelineDesign } from "../lib/user-roles";
|
||||
import AIGenerateModal from "../components/AIGenerateModal";
|
||||
import { GeneratedWorkflow } from "../services/aiService";
|
||||
import { projectsApi } from "../services/api/projects";
|
||||
import { suppliersApi } from "../services/api/suppliers";
|
||||
import { templatesApi } from "../services/api/templates";
|
||||
import type { Project, WorkflowRelease, WorkflowTemplate } from "../types";
|
||||
import type { Project, ProjectMemberRole, Supplier, WorkflowRelease, WorkflowTemplate } from "../types";
|
||||
import { useAIStatus } from "../hooks/useAIStatus";
|
||||
|
||||
export default function Templates() {
|
||||
@ -48,6 +49,9 @@ export default function Templates() {
|
||||
const [isProjectSelectOpen, setIsProjectSelectOpen] = useState(false);
|
||||
const [selectedTemplate, setSelectedTemplate] = useState<WorkflowTemplate | null>(null);
|
||||
const [selectedProjectId, setSelectedProjectId] = useState<string | null>(null);
|
||||
const [eligibleSuppliers, setEligibleSuppliers] = useState<Supplier[]>([]);
|
||||
const [selectedSupplierId, setSelectedSupplierId] = useState<string | null>(null);
|
||||
const [isLoadingSuppliers, setIsLoadingSuppliers] = useState(false);
|
||||
const [actionError, setActionError] = useState("");
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [newTpl, setNewTpl] = useState({ name: "", description: "" });
|
||||
@ -310,9 +314,50 @@ export default function Templates() {
|
||||
setActionError("");
|
||||
setSelectedTemplate(tpl);
|
||||
setSelectedProjectId(null);
|
||||
setEligibleSuppliers([]);
|
||||
setSelectedSupplierId(null);
|
||||
setIsProjectSelectOpen(true);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedProjectId || !selectedTemplate) {
|
||||
setEligibleSuppliers([]);
|
||||
setSelectedSupplierId(null);
|
||||
return;
|
||||
}
|
||||
const release = latestReleases[selectedTemplate.id];
|
||||
const needsSupplier = release?.requiredPluginIds?.includes("annotation-qa") ?? false;
|
||||
if (!needsSupplier) {
|
||||
setEligibleSuppliers([]);
|
||||
setSelectedSupplierId(null);
|
||||
return;
|
||||
}
|
||||
setIsLoadingSuppliers(true);
|
||||
Promise.all([suppliersApi.list(), projectsApi.listMembers(selectedProjectId)])
|
||||
.then(([suppliers, members]) => {
|
||||
const requiredRoles = new Set<ProjectMemberRole>([
|
||||
"annotator",
|
||||
"quality_reviewer",
|
||||
"acceptance_reviewer",
|
||||
]);
|
||||
const eligible = suppliers.filter((supplier) => {
|
||||
if (supplier.status !== "active") return false;
|
||||
const covered = new Set(
|
||||
members.filter((member) => member.supplierId === supplier.id).flatMap((member) => member.roles),
|
||||
);
|
||||
return Array.from(requiredRoles).every((role) => covered.has(role));
|
||||
});
|
||||
setEligibleSuppliers(eligible);
|
||||
setSelectedSupplierId(eligible.length === 1 ? eligible[0].id : null);
|
||||
})
|
||||
.catch((error) => {
|
||||
setEligibleSuppliers([]);
|
||||
setSelectedSupplierId(null);
|
||||
setActionError(getActionErrorMessage(error, "加载项目供应商失败"));
|
||||
})
|
||||
.finally(() => setIsLoadingSuppliers(false));
|
||||
}, [latestReleases, selectedProjectId, selectedTemplate]);
|
||||
|
||||
const publishTemplate = async (template: WorkflowTemplate) => {
|
||||
setPublishingTemplateId(template.id);
|
||||
setActionError("");
|
||||
@ -337,15 +382,21 @@ export default function Templates() {
|
||||
setActionError("请先发布工作流,再由项目引用不可变版本。");
|
||||
return;
|
||||
}
|
||||
if (release.requiredPluginIds?.includes("annotation-qa") && !selectedSupplierId) {
|
||||
setActionError("请选择一个已配置标注员、审核员和最终验收员的供应商。");
|
||||
return;
|
||||
}
|
||||
const projectId = selectedProjectId;
|
||||
setActionError("");
|
||||
setIsInstantiatingTemplate(true);
|
||||
projectsApi
|
||||
.createWorkflowInstance(projectId, release.id)
|
||||
.createWorkflowInstance(projectId, release.id, selectedSupplierId || undefined)
|
||||
.then(({ workflow: created }) => {
|
||||
setActionError("");
|
||||
setIsProjectSelectOpen(false);
|
||||
setSelectedProjectId(null);
|
||||
setEligibleSuppliers([]);
|
||||
setSelectedSupplierId(null);
|
||||
setSelectedTemplate(null);
|
||||
navigate(`/workflow/${created.id}?projectId=${projectId}`);
|
||||
})
|
||||
@ -373,6 +424,14 @@ export default function Templates() {
|
||||
setIsProjectSelectOpen(false);
|
||||
};
|
||||
|
||||
const selectedRelease = selectedTemplate ? latestReleases[selectedTemplate.id] : undefined;
|
||||
const selectedReleaseNeedsSupplier = selectedRelease?.requiredPluginIds?.includes("annotation-qa") ?? false;
|
||||
const canInstantiateSelectedTemplate =
|
||||
Boolean(selectedProjectId) &&
|
||||
!isInstantiatingTemplate &&
|
||||
!isLoadingSuppliers &&
|
||||
(!selectedReleaseNeedsSupplier || Boolean(selectedSupplierId));
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<div className="flex items-center justify-between">
|
||||
@ -732,6 +791,35 @@ export default function Templates() {
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
{selectedProjectId && selectedReleaseNeedsSupplier && (
|
||||
<div className="space-y-2 rounded-xl border border-[#2a2b2f] bg-[#0a0a0a] p-4">
|
||||
<label
|
||||
className="text-xs font-medium uppercase tracking-wider text-gray-400"
|
||||
htmlFor="template-supplier-binding"
|
||||
>
|
||||
人工任务供应商
|
||||
</label>
|
||||
<select
|
||||
id="template-supplier-binding"
|
||||
value={selectedSupplierId || ""}
|
||||
disabled={isLoadingSuppliers}
|
||||
onChange={(event) => setSelectedSupplierId(event.target.value || null)}
|
||||
className="w-full rounded-md border border-[#2a2b2f] bg-black px-3 py-2 text-sm text-white focus:border-blue-500 focus:outline-none"
|
||||
>
|
||||
<option value="">{isLoadingSuppliers ? "正在检查项目成员…" : "请选择供应商"}</option>
|
||||
{eligibleSuppliers.map((supplier) => (
|
||||
<option key={supplier.id} value={supplier.id}>
|
||||
{supplier.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{!isLoadingSuppliers && eligibleSuppliers.length === 0 && (
|
||||
<p className="text-xs leading-5 text-amber-400">
|
||||
当前项目没有同时覆盖标注员、审核员和最终验收员的可用供应商,请先到“成员与角色”完成配置。
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="p-6 border-t border-[#2a2b2f] flex justify-end gap-3 bg-[#0a0a0a]/50">
|
||||
<button
|
||||
@ -743,10 +831,10 @@ export default function Templates() {
|
||||
</button>
|
||||
<button
|
||||
onClick={confirmUseTemplate}
|
||||
disabled={!selectedProjectId || isInstantiatingTemplate}
|
||||
disabled={!canInstantiateSelectedTemplate}
|
||||
className={cn(
|
||||
"inline-flex items-center gap-2 px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-md text-sm font-medium transition-all",
|
||||
(!selectedProjectId || isInstantiatingTemplate) && "opacity-50 cursor-not-allowed",
|
||||
!canInstantiateSelectedTemplate && "opacity-50 cursor-not-allowed",
|
||||
)}
|
||||
>
|
||||
{isInstantiatingTemplate && <Loader2 className="h-4 w-4 animate-spin" />}
|
||||
|
||||
@ -93,9 +93,16 @@ export const annotationOperationsApi = {
|
||||
requireSliceCompletion?: boolean;
|
||||
},
|
||||
) =>
|
||||
apiRequest<{ task: AnnotationTaskRecord; sliceRevision: SliceRevision; revision: AnnotationRevision }>(
|
||||
apiRequest<{
|
||||
task?: AnnotationTaskRecord;
|
||||
sliceRevision?: SliceRevision;
|
||||
revision?: AnnotationRevision;
|
||||
item?: HumanItem;
|
||||
submissionId?: string;
|
||||
status?: "processing";
|
||||
}>(
|
||||
`/api/plugins/annotation-qa/tasks/${taskId}/combined-submissions`,
|
||||
{ method: "POST" },
|
||||
{ method: "POST", headers: { Prefer: "respond-async" } },
|
||||
payload,
|
||||
),
|
||||
saveCombinedDraft: (
|
||||
|
||||
@ -52,18 +52,28 @@ export const projectsApi = {
|
||||
}),
|
||||
bulkMembers: (
|
||||
projectId: string,
|
||||
payload: { action: "set_roles" | "remove"; memberIds: string[]; roles?: ProjectMemberRole[] },
|
||||
) => apiRequest<{ updated: number }>(`/api/projects/${projectId}/members/bulk`, { method: "POST" }, payload),
|
||||
payload:
|
||||
| { action: "set_roles" | "remove"; memberIds: string[]; roles?: ProjectMemberRole[] }
|
||||
| {
|
||||
action: "add";
|
||||
entries: Array<{ userId: string; supplierId?: string; roles: ProjectMemberRole[] }>;
|
||||
},
|
||||
) =>
|
||||
apiRequest<{ created?: number; updated: number }>(
|
||||
`/api/projects/${projectId}/members/bulk`,
|
||||
{ method: "POST" },
|
||||
payload,
|
||||
),
|
||||
listWorkflows: async (projectId: string) =>
|
||||
(await apiRequest<{ items: Workflow[] }>(`/api/projects/${projectId}/workflows`)).items,
|
||||
createWorkflow: (projectId: string, payload: Partial<Workflow>) =>
|
||||
apiRequest<Workflow>(`/api/projects/${projectId}/workflows`, { method: "POST" }, payload),
|
||||
listWorkflowInstances: async (projectId: string) =>
|
||||
(await apiRequest<{ items: ProjectWorkflowInstance[] }>(`/api/projects/${projectId}/workflow-instances`)).items,
|
||||
createWorkflowInstance: (projectId: string, releaseId: string) =>
|
||||
createWorkflowInstance: (projectId: string, releaseId: string, supplierId?: string) =>
|
||||
apiRequest<{ instance: ProjectWorkflowInstance; workflow: Workflow }>(
|
||||
`/api/projects/${projectId}/workflow-instances`,
|
||||
{ method: "POST" },
|
||||
{ releaseId },
|
||||
{ releaseId, supplierId },
|
||||
),
|
||||
};
|
||||
|
||||
36
src/types.ts
36
src/types.ts
@ -635,6 +635,7 @@ export interface ProjectWorkflowInstance {
|
||||
releaseVersion: number;
|
||||
sourceTemplateId: string;
|
||||
workflowId: string;
|
||||
supplierId?: string;
|
||||
status: "active" | "superseded";
|
||||
supersedesInstanceId?: string;
|
||||
createdByUserId: string;
|
||||
@ -1725,29 +1726,6 @@ export type AnnotationTaskStatus =
|
||||
| "accepted"
|
||||
| "rejected";
|
||||
|
||||
export interface AnnotationWorkgroup {
|
||||
id: string;
|
||||
organizationId?: string;
|
||||
name: string;
|
||||
vendorId: string;
|
||||
description?: string;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ProjectAnnotationMembership {
|
||||
id: string;
|
||||
organizationId?: string;
|
||||
projectId: string;
|
||||
userId: string;
|
||||
workgroupId: string;
|
||||
vendorId: string;
|
||||
assignmentRole: AnnotationAssignmentRole;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export type ProjectMemberRole = "annotator" | "quality_reviewer" | "acceptance_reviewer";
|
||||
|
||||
export interface Supplier {
|
||||
@ -1922,8 +1900,7 @@ export interface AnnotationTaskRecord {
|
||||
templateId: string;
|
||||
templateVersion: number;
|
||||
supplierId?: string;
|
||||
workgroupId: string;
|
||||
vendorId: string;
|
||||
legacyAssignment?: Record<string, string>;
|
||||
assignedUserId?: string;
|
||||
status: AnnotationTaskStatus;
|
||||
currentRevision: number;
|
||||
@ -1981,8 +1958,7 @@ export interface AnnotationTaskDetail {
|
||||
|
||||
export interface AnnotationWorkloadAggregate {
|
||||
userId: string;
|
||||
workgroupId: string;
|
||||
vendorId: string;
|
||||
supplierId: string;
|
||||
templateVersion: number;
|
||||
assignedCount: number;
|
||||
submittedCount: number;
|
||||
@ -2033,8 +2009,7 @@ export interface HumanItem {
|
||||
currentStageId: string;
|
||||
status: HumanItemStatus;
|
||||
assignedUserId?: string;
|
||||
workgroupId?: string;
|
||||
vendorId?: string;
|
||||
legacyAssignment?: Record<string, string>;
|
||||
currentRevision: number;
|
||||
reviewRound: number;
|
||||
maxReworkRounds: number;
|
||||
@ -2086,8 +2061,7 @@ export interface DeliveryPackage {
|
||||
projectId: string;
|
||||
workflowId: string;
|
||||
supplierId?: string;
|
||||
workgroupId?: string;
|
||||
vendorId?: string;
|
||||
legacyAssignment?: Record<string, string>;
|
||||
parentRunId: string;
|
||||
childRunId: string;
|
||||
releasePartitionId: string;
|
||||
|
||||
@ -32,7 +32,6 @@ CONFIG_ENV_KEYS = {
|
||||
"DROBOTICFLOW_BUILD_TIME",
|
||||
"DROSYNC_COORDINATOR_IMAGE",
|
||||
"DEPLOY_ENV",
|
||||
"FANYU_V5_SUPPLIER_ID",
|
||||
"IMAGE_TAG",
|
||||
"K8S_IMAGE_PULL_SECRET_NAME",
|
||||
"K8S_NAMESPACE",
|
||||
@ -147,7 +146,6 @@ def test_render_manifests_allows_empty_optional_global_runtime_config():
|
||||
assert 'BOS_ENDPOINT: ""' in result.stdout
|
||||
assert 'AI_API_BASE_URL: ""' in result.stdout
|
||||
assert 'AI_MODEL: ""' in result.stdout
|
||||
assert 'FANYU_V5_SUPPLIER_ID: ""' in result.stdout
|
||||
assert 'DROBOTICFLOW_QWEN_NODE_CACHE_ENABLED: "false"' in result.stdout
|
||||
assert 'DROBOTICFLOW_QWEN_NODE_CACHE_PVC: ""' in result.stdout
|
||||
|
||||
@ -175,15 +173,6 @@ def test_render_manifests_rejects_incomplete_enabled_qwen_node_cache():
|
||||
assert_render_validation_failure(result, "DROBOTICFLOW_QWEN_NODE_CACHE_PVC must be a lowercase DNS subdomain")
|
||||
|
||||
|
||||
def test_render_manifests_wires_optional_fanyu_supplier_to_api_only():
|
||||
result = run_render_manifests({"FANYU_V5_SUPPLIER_ID": "fanyu-v5-poc-vendor-a"})
|
||||
|
||||
assert result.returncode == 0, result.stderr + result.stdout
|
||||
assert 'FANYU_V5_SUPPLIER_ID: "fanyu-v5-poc-vendor-a"' in result.stdout
|
||||
assert "- name: FANYU_V5_SUPPLIER_ID" in result.stdout
|
||||
assert "key: FANYU_V5_SUPPLIER_ID" in result.stdout
|
||||
|
||||
|
||||
def test_render_manifests_rejects_invalid_startup_numeric_configuration():
|
||||
cases = [
|
||||
({"MONGO_CONNECT_RETRIES": "0"}, "MONGO_CONNECT_RETRIES must be greater than or equal to 1"),
|
||||
|
||||
@ -2,6 +2,9 @@ from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
@ -25,6 +28,8 @@ def test_harness_uses_environment_credentials_and_project_members() -> None:
|
||||
assert "fanyu_annotator_123" not in source
|
||||
assert "youbixuanpoc" not in source
|
||||
assert "120.48.164.19" not in source
|
||||
assert "member_bulk_remove_releases_task" not in source
|
||||
assert source.count("record_browser_fixture(") >= 3
|
||||
|
||||
|
||||
def test_workflow_rework_override_is_added_without_duplicates() -> None:
|
||||
@ -33,3 +38,383 @@ def test_workflow_rework_override_is_added_without_duplicates() -> None:
|
||||
module.upsert_hyperparam(node, "MAX_REWORK_ROUNDS", 1)
|
||||
values = [item for item in node["data"]["hyperparams"] if item["key"] == "MAX_REWORK_ROUNDS"]
|
||||
assert values == [{"key": "MAX_REWORK_ROUNDS", "value": "1"}]
|
||||
|
||||
|
||||
def test_workflow_clone_binds_exact_acceptance_supplier_without_mutating_source() -> None:
|
||||
module = load_module()
|
||||
source = [
|
||||
{
|
||||
"id": "human",
|
||||
"data": {
|
||||
"operatorId": "operator-builtin-annotation-gate",
|
||||
"hyperparams": [
|
||||
{"key": "ANNOTATION_SUPPLIER_ID", "value": "stale-supplier", "type": "string"},
|
||||
{"key": "MAX_REWORK_ROUNDS", "value": "5", "type": "number"},
|
||||
],
|
||||
},
|
||||
},
|
||||
{"id": "automatic", "data": {"operatorId": "operator-builtin-directory-scan", "hyperparams": []}},
|
||||
]
|
||||
|
||||
cloned = module.clone_workflow_nodes_for_supplier(source, "supplier-acceptance")
|
||||
|
||||
assert module.annotation_supplier_ids(cloned) == {"supplier-acceptance"}
|
||||
params = cloned[0]["data"]["hyperparams"]
|
||||
assert [item for item in params if item["key"] == "ANNOTATION_SUPPLIER_ID"] == [
|
||||
{"key": "ANNOTATION_SUPPLIER_ID", "value": "supplier-acceptance", "type": "string"}
|
||||
]
|
||||
assert [item for item in params if item["key"] == "MAX_REWORK_ROUNDS"] == [
|
||||
{"key": "MAX_REWORK_ROUNDS", "value": "1", "type": "number"}
|
||||
]
|
||||
assert module.annotation_supplier_ids(source) == {"stale-supplier"}
|
||||
|
||||
|
||||
def test_setup_orders_project_and_supplier_members_before_workflow_clone() -> None:
|
||||
module = load_module()
|
||||
|
||||
class RecordingHarness(module.Harness):
|
||||
def __init__(self) -> None:
|
||||
self.args = SimpleNamespace(phase=["setup"])
|
||||
self.calls: list[str] = []
|
||||
|
||||
def login(self) -> None:
|
||||
self.calls.append("login")
|
||||
|
||||
def ensure_project(self) -> None:
|
||||
self.calls.append("project")
|
||||
|
||||
def ensure_supplier_and_members(self) -> None:
|
||||
self.calls.append("supplier-members")
|
||||
|
||||
def ensure_workflow(self) -> None:
|
||||
self.calls.append("workflow")
|
||||
|
||||
def finalize(self) -> None:
|
||||
self.calls.append("finalize")
|
||||
|
||||
harness = RecordingHarness()
|
||||
harness.run()
|
||||
assert harness.calls == ["login", "project", "supplier-members", "workflow", "finalize"]
|
||||
|
||||
|
||||
def test_existing_project_member_is_repaired_for_human_only_resume() -> None:
|
||||
module = load_module()
|
||||
|
||||
class FakeAdmin:
|
||||
def __init__(self) -> None:
|
||||
self.patches: list[tuple[str, dict]] = []
|
||||
|
||||
def request_json(self, method: str, path: str, payload: dict) -> dict:
|
||||
self.patches.append((path, payload))
|
||||
return {"id": "member-a", "supplierId": payload["supplierId"], "roles": payload["roles"]}
|
||||
|
||||
harness = object.__new__(module.Harness)
|
||||
harness.state = {"projectId": "project-a"}
|
||||
harness.admin = FakeAdmin()
|
||||
harness.raw_status = lambda *_args, **_kwargs: (
|
||||
409,
|
||||
{"member": {"id": "member-a", "supplierId": "stale-supplier", "roles": ["quality_reviewer"]}},
|
||||
)
|
||||
|
||||
member = harness.ensure_project_member("user-a", "supplier-target", ["annotator"])
|
||||
|
||||
assert member == {"id": "member-a", "supplierId": "supplier-target", "roles": ["annotator"]}
|
||||
assert harness.admin.patches == [
|
||||
("/api/projects/project-a/members/member-a", {"supplierId": "supplier-target", "roles": ["annotator"]})
|
||||
]
|
||||
|
||||
|
||||
def test_human_item_supplier_alignment_is_fail_closed() -> None:
|
||||
module = load_module()
|
||||
assert module.human_item_supplier_id([{"supplierId": "supplier-a"}, {"supplierId": "supplier-a"}]) == "supplier-a"
|
||||
with pytest.raises(module.AcceptanceError, match="multiple suppliers"):
|
||||
module.human_item_supplier_id([{"supplierId": "supplier-a"}, {"supplierId": "supplier-b"}])
|
||||
with pytest.raises(module.AcceptanceError, match="do not carry"):
|
||||
module.human_item_supplier_id([{"supplierId": ""}])
|
||||
|
||||
|
||||
def test_human_locator_records_capture_run_task_slice_and_event_ids() -> None:
|
||||
module = load_module()
|
||||
harness = object.__new__(module.Harness)
|
||||
harness.state = {"evidence": {"captures": [{"captureId": "capture-a", "runId": "run-a"}]}}
|
||||
harness.report = {"resources": {}}
|
||||
harness.save_state = lambda: None
|
||||
|
||||
harness.remember_human_item(
|
||||
{"id": "human-a", "legacyTaskId": "task-a", "runId": "run-a", "supplierId": "supplier-a", "currentStageId": "annotation_combined"},
|
||||
task={"id": "task-a", "runId": "run-a", "dataTaskId": "data-task-a"},
|
||||
slice_ids=["slice-a", "slice-b"],
|
||||
event_ids=["event-a"],
|
||||
)
|
||||
|
||||
locator = harness.state["evidence"]["humanItemsById"]["human-a"]
|
||||
assert locator == {
|
||||
"humanItemId": "human-a",
|
||||
"taskId": "task-a",
|
||||
"runId": "run-a",
|
||||
"supplierId": "supplier-a",
|
||||
"stageId": "annotation_combined",
|
||||
"dataTaskId": "data-task-a",
|
||||
"captureId": "capture-a",
|
||||
"sliceIds": ["slice-a", "slice-b"],
|
||||
"eventIds": ["event-a"],
|
||||
}
|
||||
assert harness.report["resources"]["humanItems"] == [locator]
|
||||
|
||||
|
||||
def test_retry_settle_requires_three_failed_attempts_and_no_active_run() -> None:
|
||||
module = load_module()
|
||||
settled = [{"status": "failed"}, {"status": "failed"}, {"status": "failed"}]
|
||||
assert module.retry_runs_settled(settled)
|
||||
assert not module.retry_runs_settled(settled + [{"status": "queued"}])
|
||||
assert not module.retry_runs_settled(settled[:2])
|
||||
|
||||
|
||||
def test_submission_uses_current_empty_confirmation_contract() -> None:
|
||||
source = SCRIPT.read_text(encoding="utf-8")
|
||||
assert '"annotationStatus": "empty_confirmed"' in source
|
||||
assert "confirmed_empty" not in source
|
||||
|
||||
|
||||
def test_annotation_draft_uses_persisted_annotation_draft_contract() -> None:
|
||||
module = load_module()
|
||||
slices = [
|
||||
{"id": "slice-a", "annotationStatus": "labeled"},
|
||||
{"id": "slice-b", "annotationStatus": "empty_confirmed"},
|
||||
]
|
||||
events = [{"id": "event-a"}]
|
||||
draft = {
|
||||
"sliceSegments": [{"id": "slice-a"}, {"id": "slice-b"}],
|
||||
"segments": [{"id": "event-a"}],
|
||||
"statuses": {"slice-a": "labeled", "slice-b": "empty_confirmed"},
|
||||
}
|
||||
assert module.annotation_draft_matches(draft, slices, events)
|
||||
assert not module.annotation_draft_matches({**draft, "statuses": {"slice-a": "labeled"}}, slices, events)
|
||||
source = SCRIPT.read_text(encoding="utf-8")
|
||||
assert 'get("annotationDraft")' in source
|
||||
assert 'get("draft")' not in source
|
||||
|
||||
|
||||
def test_browser_fixture_records_three_real_unassigned_stages_and_disposable_member() -> None:
|
||||
module = load_module()
|
||||
harness = object.__new__(module.Harness)
|
||||
harness.state = {
|
||||
"evidence": {
|
||||
"captures": [
|
||||
{"captureId": "capture-annotation", "runId": "run-annotation"},
|
||||
{"captureId": "capture-quality", "runId": "run-quality"},
|
||||
]
|
||||
}
|
||||
}
|
||||
harness.report = {"resources": {}}
|
||||
harness.save_state = lambda: None
|
||||
annotation = {
|
||||
"id": "human-annotation",
|
||||
"legacyTaskId": "task-annotation",
|
||||
"runId": "run-annotation",
|
||||
"currentStageId": "annotation_combined",
|
||||
"status": "rework",
|
||||
}
|
||||
quality = {
|
||||
"id": "human-quality",
|
||||
"legacyTaskId": "task-quality",
|
||||
"runId": "run-quality",
|
||||
"currentStageId": "quality_review",
|
||||
"status": "submitted",
|
||||
"subject": {
|
||||
"payload": {
|
||||
"materialization": {"status": "completed", "artifactId": "artifact-quality", "runId": "run-quality"}
|
||||
}
|
||||
},
|
||||
}
|
||||
acceptance = {
|
||||
"id": "human-acceptance",
|
||||
"runId": "run-acceptance",
|
||||
"currentStageId": "prepackage_acceptance",
|
||||
"status": "ready",
|
||||
"display": {"captureDirectories": ["capture-acceptance"]},
|
||||
"subject": {
|
||||
"payload": {
|
||||
"items": [
|
||||
{
|
||||
"taskId": "task-acceptance-source",
|
||||
"materialization": {
|
||||
"status": "completed",
|
||||
"artifactId": "artifact-acceptance",
|
||||
"runId": "run-acceptance-source",
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
harness.record_browser_fixture(
|
||||
annotation,
|
||||
quality,
|
||||
acceptance,
|
||||
member_user_id="probe-user",
|
||||
member_email="probe@example.com",
|
||||
supplier_id="supplier-a",
|
||||
)
|
||||
|
||||
fixture = harness.state["browserFixture"]
|
||||
assert fixture == {
|
||||
"annotation": {
|
||||
"captureDirectory": "capture-annotation",
|
||||
"taskId": "task-annotation",
|
||||
"humanItemId": "human-annotation",
|
||||
"runId": "run-annotation",
|
||||
"pool": "available",
|
||||
},
|
||||
"quality": {
|
||||
"captureDirectory": "capture-quality",
|
||||
"taskId": "task-quality",
|
||||
"humanItemId": "human-quality",
|
||||
"runId": "run-quality",
|
||||
"pool": "available",
|
||||
},
|
||||
"acceptance": {
|
||||
"captureDirectory": "capture-acceptance",
|
||||
"humanItemId": "human-acceptance",
|
||||
"runId": "run-acceptance",
|
||||
"pool": "available",
|
||||
},
|
||||
"member": {
|
||||
"userId": "probe-user",
|
||||
"email": "probe@example.com",
|
||||
"supplierId": "supplier-a",
|
||||
"initialRoles": ["annotator"],
|
||||
"bulkRoles": ["annotator", "quality_reviewer"],
|
||||
"disposable": True,
|
||||
},
|
||||
}
|
||||
assert harness.report["resources"]["browserFixture"] == fixture
|
||||
|
||||
|
||||
def test_browser_fixture_rejects_consumed_or_unmaterialized_ids() -> None:
|
||||
module = load_module()
|
||||
harness = object.__new__(module.Harness)
|
||||
harness.state = {"evidence": {"captures": []}}
|
||||
harness.report = {"resources": {}}
|
||||
harness.save_state = lambda: None
|
||||
annotation = {
|
||||
"id": "annotation",
|
||||
"legacyTaskId": "task-a",
|
||||
"runId": "run-a",
|
||||
"currentStageId": "annotation_combined",
|
||||
"status": "accepted",
|
||||
"display": {"captureDirectories": ["capture-a"]},
|
||||
}
|
||||
quality = {
|
||||
"id": "quality",
|
||||
"legacyTaskId": "task-q",
|
||||
"runId": "run-q",
|
||||
"currentStageId": "quality_review",
|
||||
"status": "submitted",
|
||||
"display": {"captureDirectories": ["capture-q"]},
|
||||
"subject": {"payload": {"materialization": {"status": "completed", "artifactId": "a", "runId": "r"}}},
|
||||
}
|
||||
acceptance = {
|
||||
"id": "acceptance",
|
||||
"runId": "run-x",
|
||||
"currentStageId": "prepackage_acceptance",
|
||||
"status": "ready",
|
||||
"display": {"captureDirectories": ["capture-x"]},
|
||||
"subject": {"payload": {"items": [{"materialization": {"status": "completed", "artifactId": "a", "runId": "r"}}]}},
|
||||
}
|
||||
with pytest.raises(module.AcceptanceError, match="already consumed"):
|
||||
harness.record_browser_fixture(
|
||||
annotation,
|
||||
quality,
|
||||
acceptance,
|
||||
member_user_id="probe",
|
||||
member_email="probe@example.com",
|
||||
supplier_id="supplier-a",
|
||||
)
|
||||
|
||||
|
||||
def claim_harness(module, items: list[dict], response: tuple[int, dict] | None = None):
|
||||
class FakeClient:
|
||||
def __init__(self) -> None:
|
||||
self.items = list(items)
|
||||
self.get_count = 0
|
||||
|
||||
def request_json(self, method: str, path: str) -> dict:
|
||||
assert method == "GET"
|
||||
value = self.items[min(self.get_count, len(self.items) - 1)]
|
||||
self.get_count += 1
|
||||
return {"item": value}
|
||||
|
||||
harness = object.__new__(module.Harness)
|
||||
harness.state = {"evidence": {"captures": []}}
|
||||
harness.report = {"resources": {}}
|
||||
harness.save_state = lambda: None
|
||||
harness.session_user_ids = {"annotator": "annotator-user"}
|
||||
calls: list[tuple] = []
|
||||
|
||||
def raw_status(*args):
|
||||
calls.append(args)
|
||||
assert response is not None
|
||||
return response
|
||||
|
||||
harness.raw_status = raw_status
|
||||
return harness, FakeClient(), calls
|
||||
|
||||
|
||||
def test_claim_helper_reuses_same_annotator_claim_and_current_version() -> None:
|
||||
module = load_module()
|
||||
claimed = {
|
||||
"id": "human-a",
|
||||
"runId": "run-a",
|
||||
"status": "claimed",
|
||||
"assignedUserId": "annotator-user",
|
||||
"version": 7,
|
||||
}
|
||||
harness, client, calls = claim_harness(module, [claimed])
|
||||
result = harness.claim_human_item(client, {"id": "human-a", "version": 2}, "annotator")
|
||||
assert result["version"] == 7
|
||||
assert calls == []
|
||||
|
||||
|
||||
def test_claim_helper_claims_available_item_once() -> None:
|
||||
module = load_module()
|
||||
ready = {"id": "human-a", "runId": "run-a", "status": "ready", "version": 3}
|
||||
claimed = {**ready, "status": "claimed", "assignedUserId": "annotator-user", "version": 4}
|
||||
harness, client, calls = claim_harness(module, [ready], (200, claimed))
|
||||
result = harness.claim_human_item(client, {"id": "human-a", "version": 1}, "annotator")
|
||||
assert result == claimed
|
||||
assert len(calls) == 1
|
||||
assert calls[0][-1] == {"version": 3}
|
||||
|
||||
|
||||
def test_claim_helper_recovers_own_claim_after_version_conflict() -> None:
|
||||
module = load_module()
|
||||
ready = {"id": "human-a", "runId": "run-a", "status": "rework", "version": 5}
|
||||
claimed = {**ready, "status": "in_progress", "assignedUserId": "annotator-user", "version": 6}
|
||||
harness, client, calls = claim_harness(module, [ready, claimed], (409, {"code": "version_conflict"}))
|
||||
result = harness.claim_human_item(client, ready, "annotator")
|
||||
assert result == claimed
|
||||
assert len(calls) == 1
|
||||
assert client.get_count == 2
|
||||
|
||||
|
||||
def test_claim_helper_refuses_another_assignee_and_terminal_stage() -> None:
|
||||
module = load_module()
|
||||
other = {
|
||||
"id": "human-a",
|
||||
"runId": "run-a",
|
||||
"status": "claimed",
|
||||
"assignedUserId": "other-user",
|
||||
"version": 3,
|
||||
}
|
||||
harness, client, calls = claim_harness(module, [other])
|
||||
with pytest.raises(module.AcceptanceError, match="already claimed"):
|
||||
harness.claim_human_item(client, other, "annotator")
|
||||
assert calls == []
|
||||
|
||||
terminal = {"id": "human-b", "runId": "run-b", "status": "accepted", "version": 8}
|
||||
harness, client, calls = claim_harness(module, [terminal])
|
||||
with pytest.raises(module.AcceptanceError, match="cannot be claimed"):
|
||||
harness.claim_human_item(client, terminal, "annotator")
|
||||
assert calls == []
|
||||
|
||||
@ -23,7 +23,6 @@ def values_text(model_root: Path, deb_sha: str, portable_sha: str, model_sha: st
|
||||
f"FANYU_S100_MODE={mode}",
|
||||
"FANYU_REMOTE_API_BASE_URL=https://control.example",
|
||||
"FANYU_REMOTE_BOS_ENDPOINT=https://bos.example",
|
||||
"FANYU_V5_SUPPLIER_ID=vendor-a-left-camera",
|
||||
"FANYU_HEADPOSE_API_BASE_URL=https://headpose.example",
|
||||
f"FANYU_HEADPOSE_SERVICE_IMAGE_ID={digest}",
|
||||
"FANYU_HEADPOSE_MODEL_SHA256=sha256:" + "b" * 64,
|
||||
|
||||
43
tests/frontend/fanyu-browser-acceptance.test.mjs
Normal file
43
tests/frontend/fanyu-browser-acceptance.test.mjs
Normal file
@ -0,0 +1,43 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const source = fs.readFileSync(path.join(root, "scripts/fanyu-100-browser-acceptance.mjs"), "utf8");
|
||||
|
||||
test("Fanyu browser acceptance requires real staged fixtures instead of title-only smoke pages", () => {
|
||||
assert.match(source, /state\.browserFixture/);
|
||||
assert.match(source, /browser fixture is incomplete/);
|
||||
assert.match(source, /browserFixture\.annotation\.taskId/);
|
||||
assert.match(source, /browserFixture\.quality\.taskId/);
|
||||
assert.match(source, /browserFixture\.acceptance\.humanItemId/);
|
||||
assert.match(source, /refusing to replace real interaction acceptance with a title-only smoke test/);
|
||||
});
|
||||
|
||||
test("Fanyu browser acceptance records identity and browser-network health before navigation", () => {
|
||||
assert.match(source, /\/api\/auth\/me/);
|
||||
assert.match(source, /actualEmail === email/);
|
||||
assert.match(source, /page\.on\("console"/);
|
||||
assert.match(source, /page\.on\("pageerror"/);
|
||||
assert.match(source, /page\.on\("requestfailed"/);
|
||||
assert.match(source, /response\.status\(\) >= 500/);
|
||||
});
|
||||
|
||||
test("Fanyu browser acceptance exercises exact hierarchy, responsive layout, and member mutations", () => {
|
||||
assert.match(source, /getByLabel\("1\. 项目"/);
|
||||
assert.match(source, /getByLabel\("2\. 工作流"/);
|
||||
assert.match(source, /getByLabel\("3\. Capture 子目录"/);
|
||||
assert.match(source, /workflows\/all\/annotate/);
|
||||
assert.match(source, /workflowSelect\.selectOption\(workflowId,/);
|
||||
assert.match(source, /captureSelect\.selectOption\(captureDirectory,/);
|
||||
assert.match(source, /data-capture-directory/);
|
||||
assert.match(source, /annotation_layout_1920_no_overlap/);
|
||||
assert.match(source, /annotation_layout_1366_no_overlap/);
|
||||
assert.match(source, /project_member_real_bulk_operations/);
|
||||
assert.match(source, /project-member-bulk-set-roles/);
|
||||
assert.match(source, /project-member-bulk-remove/);
|
||||
assert.match(source, /quality materialized slice workbench/);
|
||||
assert.match(source, /acceptance materialized slice workbench/);
|
||||
});
|
||||
@ -7,6 +7,7 @@ const dashboardURL = new URL("../../src/pages/Dashboard.tsx", import.meta.url);
|
||||
const sidebarURL = new URL("../../src/components/Sidebar.tsx", import.meta.url);
|
||||
const pluginRegistryURL = new URL("../../internal/plugins/registry.go", import.meta.url);
|
||||
const workflowEditorURL = new URL("../../src/pages/WorkflowEditor.tsx", import.meta.url);
|
||||
const annotationClientURL = new URL("../../src/services/api/annotation-operations.ts", import.meta.url);
|
||||
const appURL = new URL("../../src/App.tsx", import.meta.url);
|
||||
|
||||
test("human work uses claim and release pools without manual assignment", async () => {
|
||||
@ -24,6 +25,10 @@ test("dashboard renders platform vendor and self workforce scopes", async () =>
|
||||
assert.match(source, /我的工作量与质量/);
|
||||
assert.match(source, /WorkforceSummaryPanel/);
|
||||
assert.match(source, /isOrganizationAdminRole\(currentUser\?\.role\)/);
|
||||
assert.match(source, /产出时长/);
|
||||
assert.match(source, /筛选供应商成员指标/);
|
||||
assert.match(source, /返工率 = 返工提交 ÷ 全部提交/);
|
||||
assert.match(source, /item\.durationSeconds \/ 3600/);
|
||||
});
|
||||
|
||||
test("human roles see only their assigned navigation surfaces", async () => {
|
||||
@ -54,7 +59,7 @@ test("workflow run input renders a per-run automatic HandPose switch", async ()
|
||||
});
|
||||
|
||||
test("v5.8 submits a combined revision and uses strict whole-package acceptance", async () => {
|
||||
const source = await readFile(annotationURL, "utf8");
|
||||
const [source, client] = await Promise.all([readFile(annotationURL, "utf8"), readFile(annotationClientURL, "utf8")]);
|
||||
assert.match(source, /if \(!detail\?\.humanItem \|\| sliceSegments\.length === 0\) return/);
|
||||
assert.doesNotMatch(
|
||||
source,
|
||||
@ -65,6 +70,11 @@ test("v5.8 submits a combined revision and uses strict whole-package acceptance"
|
||||
assert.match(source, /prepackageAcceptanceDrafts/);
|
||||
assert.match(source, /poseDelivery:/);
|
||||
assert.match(source, /整包打回审核员/);
|
||||
assert.match(source, /!isV5CombinedQuality/);
|
||||
assert.match(source, /videoQuality: isV5CombinedQuality \? undefined/);
|
||||
assert.match(client, /Prefer: "respond-async"/);
|
||||
assert.match(source, /combined-submission-status/);
|
||||
assert.match(source, /pendingCombinedSubmissionId/);
|
||||
});
|
||||
|
||||
test("supplier managers are redirected away from non-dashboard deep links", async () => {
|
||||
|
||||
@ -18,6 +18,14 @@ test("project detail exposes project-scoped human roles and safe workflow deleti
|
||||
assert.match(members, /bulkRoles/);
|
||||
assert.match(members, /应用批量角色/);
|
||||
assert.match(members, /搜索姓名、账号、供应商或角色/);
|
||||
assert.match(members, /data-testid="project-members-panel"/);
|
||||
assert.match(members, /data-testid="project-member-row"/);
|
||||
assert.match(members, /data-user-id=\{member\.userId\}/);
|
||||
assert.match(members, /project-member-bulk-set-roles/);
|
||||
assert.match(members, /project-member-bulk-remove/);
|
||||
assert.match(members, /project-member-batch-add-toggle/);
|
||||
assert.match(members, /action: "add"/);
|
||||
assert.match(members, /aria-label=\{`选择成员/);
|
||||
assert.doesNotMatch(projectDetail, /workgroup/i);
|
||||
assert.match(projectDetail, /删除工作流及全部衍生数据/);
|
||||
assert.match(projectDetail, /项目成员、原始 Capture、Bucket 和其他工作流将保留/);
|
||||
@ -30,6 +38,7 @@ test("frontend clients expose membership removal archive and cascade deletion pr
|
||||
const workflows = fs.readFileSync(path.join(root, "src/services/api/workflows.ts"), "utf8");
|
||||
assert.match(memberships, /removeMember/);
|
||||
assert.match(memberships, /bulkMembers/);
|
||||
assert.match(memberships, /entries: Array/);
|
||||
assert.match(workflows, /deletionPreview/);
|
||||
assert.match(workflows, /\/archive/);
|
||||
assert.match(workflows, /\/restore/);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user