forked from longtao.wu/droboticflow
🐛 Avoid repeated pool count scans and add scoped count recovery
This commit is contained in:
parent
11cb09296b
commit
d5b8b5ed04
50
.scratch/acceptance-pool-count-status/work.md
Normal file
50
.scratch/acceptance-pool-count-status/work.md
Normal file
@ -0,0 +1,50 @@
|
||||
# #20 验收任务池数量和错误提示(position 593)
|
||||
|
||||
Status: resolved
|
||||
|
||||
授权:本地截图读取、诊断、实现、验证和提交;不推送、不部署。基线 dev / 11cb0929,统一 recent-integration;新鲜度确认包含 origin/dev 和线上版本。共享树原有 AGENTS/docs/管理员池测试及其他任务提交保留。
|
||||
|
||||
## 截图和实际问题
|
||||
|
||||
已通过 lark-im 的现有读取权限定位平台调优群 position 593,消息 om_x100b609ee360a8a4c33efa82e7ce19e。截图保存到忽略目录 local-data/diagnostics/issue20/customer-status.png;仅保留该目标消息的上下文。
|
||||
|
||||
| 红框 | 真实位置和来源 | 判定 |
|
||||
| --- | --- | --- |
|
||||
| 上框 | AnnotationOperations 的任务池页签:可领取、我的任务、我已验收;数据来自 GET /api/human-item-counts | 当前筛选 scope 没有成功取得 reviewPoolTotals 时渲染“—”;不是动作判断状态 |
|
||||
| 下框 | 同一侧栏的 reviewPoolCountError,位于逐段任务列表上方 | 计数请求失败后,经通用错误文案显示“系统暂时无法完成操作”;不是验收决定错误 |
|
||||
|
||||
箭头指向的“全部状态”是已有筛选控件,本截图没有展开菜单,不推断其选项本身有错。截图中的任务卡和验收播放器仍正常,是因为任务列表、详情、决定和计数是独立请求。
|
||||
|
||||
## 因果证据与历史
|
||||
|
||||
1. 线上只读核验 ready 的 buildCommit 为 1a6e61909efd2e7d4afcf5d42d2653d7eef28c47。使用既有验收测试账号读取与页面一致的全项目/acceptance+prepackage_acceptance/category=all 计数路由,HTTP 500,响应明确为 `(MaxTimeMSExpired) PlanExecutor error during aggregation :: caused by :: operation exceeded time limit`。证据 live-read.json。API 日志也存在重复计数 500;日志为范围采样,不能把各用户/各路由的采样比例当总体故障率。
|
||||
2. human_pool_count_scan.go 在该线上版本与任务基线的 SHA-256 完全相同(afbe3660a4bae652c434b79098d0b0e35cc070637d92a1fdb3c77e8ce237539c)。1dc97107 没有改 AnnotationOperations 或该后端文件,且从未推送/部署;其共用动作左栏在工作台内部,本截图红框位于外层任务池,数据源不同。因此本次客户问题是已有计数超时,不是 592 移植引入。
|
||||
3. 原 covered count 把 limit 放在 facet 的匹配分支内,facet 仍要消费剩余组织候选。匹配结果超过一页时,每页都重扫剩余候选,放大聚合工作量。前端失败后不产生有效数量,错误没有局部恢复入口;它会保留至另一次相关加载,不是把质检状态读进验收缓存。
|
||||
4. 先建立红反馈:2017 候选原实现扫描 3051 个索引键,超线性预算;缺少局部重试的真实页面用例也变红。后续用 Go overlay 将最终回归直接跑在任务基线后端,12017 候选原实现扫描 78221 个键而失败;当前实现同样候选扫描 12017 个键而通过。overlay 不改 checkout,不创建分支,不改写历史。日志 count-red.log / count-baseline-12k-red.log / mongo-final.log。
|
||||
|
||||
## 修复与兼容范围
|
||||
|
||||
- 后端:先限制每个已排序的索引候选页为 1000 条,再进入保留 null/缺失语义的投影/facet。facet 同时返回匹配行和本页最后已扫描 ID/扫描数;按扫描页推进,不能按匹配页推进或因某页无匹配提前结束。继续执行原 API 权限过滤、失败整条请求不返回部分总数、取消和已有最大时限;不增加超时,不增加生产索引或迁移。
|
||||
- 前端:数量加载、失败和真实零明确区分;失败显示“任务数量暂时无法读取”及局部“重试”,仍保留未知“—”,不拿当前分页行数补总数。重试只重读数量,不切换任务池、任务或编辑状态,不改审核决定权限。成功清除旧错误;离开计数工作台清除其错误/加载状态;旧筛选响应继续受 AbortController 保护。
|
||||
- 返回值完整性按本角色实际页签校验:验收/质检只有 available/mine/reviewed,管理员才要求 all。初版新增校验错误地将 all 视为所有角色必填,被真实 API 浏览器回归抓到;已修正且将新夹具改为真实三字段响应,未提交/上线该中间版本。
|
||||
- API、Mongo 记录、切片、动作/意见、验收冻结证据、最终验收供应商匿名及正式决定/记录契约不变;无客户业务数据/配置/索引写入。回退不需要数据迁移,回到旧版会失去本次查询限界和数量恢复体验。
|
||||
|
||||
## 验证和限制
|
||||
|
||||
执行 verify:plan;使用既有 scripts/verify-change.py 的 quick/task 执行器,对本任务文件选择任务池计数和审查决定范围,排除他人管理员池测试及未改变的标注准入/编辑流程。每份复用证据记录相关源文件、测试和依赖 SHA-256;未变后端/隔离 Mongo/三播放器证据在本任务内复用,前端角色校验修正后重新执行数量恢复、真实搜索、草稿、决定、权限和构建。最终任务报告 selected-checks-passed,inputsChangedDuringRun=false:
|
||||
|
||||
- local-data/test-results/verify-1794814631078534000/report.json;主日志 local-data/test-results/issue20/task-verified.log。
|
||||
- 类型/架构检查、141 项定向前端测试、22 项验证工具测试、Go 格式和 diff 检查通过;最终前端构建通过(既有 chunk 大小提示保留)。
|
||||
- 实际页面、本地纯合成 API:验收和质检计数超时、继续处理已有验收任务不受阻、真实三字段计数恢复、清除错误、筛选慢响应/快响应不串用、不完整响应保持未知;无业务写请求,pageErrors 为空。日志 ui-green.log,截图 browser/{acceptance,quality}-count-{failed,recovered}.png,人工查看验收两种状态。
|
||||
- 隔离本地 Mongo:12017 候选、末页仅3个匹配、前面整页无匹配,计数正确并保持线性扫描;2108 条含 null/缺失/继承返工等旧形状的等价回归通过,documents fetched=0。日志 mongo-final.log。数据库名称为本次唯一合成库,测试后清理,不碰共享快照中的任务认领状态。
|
||||
- 实际 API + 隔离 Mongo:管理员和验收角色各 12000 条计数与分页基线一致,包含正常/搜索/无匹配;取消、失败无部分总数、并发身份隔离、供应商授权撤销、QC项目范围和分页/搜索等价通过。相关日志在任务报告及 verify-1794814291784921000/09.log;并发身份隔离额外定向证据为 count-concurrent.log。
|
||||
- 真实任务池搜索/翻页/历史回查/过时响应保护通过(search-browser-final.log);草稿持久化、决定失败恢复及只读/权限保护通过。
|
||||
- native / movi / movi-fractional 实际验收整页各15次切片变化、只读/决定禁用、批注保存、刷新/恢复、短动作和双时间等通过。证据 players/report.json,执行日志在 verify-1794814291784921000/16.log。播放器实现本次未改。
|
||||
|
||||
完整 Go 门禁不能宣称通过:扩大检查触及的 TestPoolPerformanceMongoBacklog 调用另一条标注随机领取计数,返回0而预期12000;使用 npm run test:go:gate 对任务基线 overlay 和当前实现分别运行,均报同一确切用例失败。两次门禁还报告已有 local-data/statistics-baseline.go 等遗留脚本编译错误。没有改 known-failures.json、没有删除/重置他人文件,没有把这些失败算进成功;门禁日志 backlog-baseline.log / backlog-current.log 及同名日志目录。最初任务级报告 verify-1794814291784921000 因角色四字段校验失败也保留,最终修正后通过,不覆盖为成功。
|
||||
|
||||
扫描量、耗时和响应字节仅为本地合成规模证据,不证明生产并发或当前线上超时已消失。本次故障探测时线上为 1a6e6190;本任务未部署,不能据本地通过宣称客户故障已经恢复。需另行完成授权发布及业务验收。
|
||||
|
||||
本地提交仅包含本任务六个文件;使用 lint-staged --no-stash 和等价检查避免临时 stash 共享工作。提交后 agent_status --no-fetch 汇报分支状态。#18/#19/592 的既有提交及其他任务提交均保留,本修复追加到待推送 dev 批次。
|
||||
|
||||
收尾状态核对:git ls-remote 读取 origin/dev 为 11cb09296b398770a630c45448dfd9bf667cc0b7,已包含此前 #18/#19/592 和其他任务提交;本任务没有执行 push/fetch 改写远端操作。#20 作为单独新增本地提交保留,未推送;不把此前提交仍称为全部未推送。
|
||||
139
internal/store/human_pool_count_bounded_test.go
Normal file
139
internal/store/human_pool_count_bounded_test.go
Normal file
@ -0,0 +1,139 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/event"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// A covered count must not scan the remaining organization again for every
|
||||
// result page. This is an isolated local database, never a customer database.
|
||||
func TestHumanPoolCountsBoundedMongoScan(t *testing.T) {
|
||||
if os.Getenv("POOL_COUNT_LOCAL_MONGO") != "1" {
|
||||
t.Skip("isolated local Mongo opt-in")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
var mu sync.Mutex
|
||||
var commands []bson.M
|
||||
client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://127.0.0.1:27018/?directConnection=true").SetServerSelectionTimeout(3*time.Second).SetMonitor(&event.CommandMonitor{Started: func(_ context.Context, e *event.CommandStartedEvent) {
|
||||
if e.CommandName != "aggregate" {
|
||||
return
|
||||
}
|
||||
var cmd bson.M
|
||||
if bson.Unmarshal(e.Command, &cmd) != nil {
|
||||
return
|
||||
}
|
||||
if cmd["aggregate"] != "humanItems" {
|
||||
return
|
||||
}
|
||||
mu.Lock()
|
||||
commands = append(commands, cmd)
|
||||
mu.Unlock()
|
||||
}}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db := client.Database(fmt.Sprintf("pool_count_bounded_%d", time.Now().UnixNano()))
|
||||
t.Cleanup(func() {
|
||||
work, stop := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer stop()
|
||||
if err := db.Drop(work); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
client.Disconnect(work)
|
||||
})
|
||||
ds := NewMongoStore(db)
|
||||
if err := ds.EnsureIndexes(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := db.Collection("humanItems").Indexes().CreateMany(ctx, PlatformReadIndexes()["humanItems"]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const n = 12017
|
||||
rows := make([]any, 0, n)
|
||||
for i := 0; i < n; i++ {
|
||||
actor := "other"
|
||||
if i >= n-3 {
|
||||
actor = "needle"
|
||||
}
|
||||
rows = append(rows, bson.M{"id": fmt.Sprintf("item-%06d", i), "batchId": "batch", "subject": bson.M{"itemKey": fmt.Sprintf("source-%d", i)}, "organizationId": "org", "pluginId": "annotation-qa", "projectId": "p", "currentStageId": "acceptance", "status": "claimed", "assignedUserId": actor})
|
||||
}
|
||||
if _, err := db.Collection("humanItems").InsertMany(ctx, rows); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name, actor string
|
||||
want int
|
||||
}{{"all", "", n}, {"sparse-last-page", "needle", 3}} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
mu.Lock()
|
||||
commands = nil
|
||||
mu.Unlock()
|
||||
count := 0
|
||||
err := ds.VisitHumanPoolCountCandidates(ctx, "org", domain.HumanItemQuery{PluginID: "annotation-qa", StageIDs: []string{"acceptance"}, ActorUserID: tc.actor, MinePoolOnly: true}, func(items []domain.HumanItemRecord) error { count += len(items); return nil })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if count != tc.want {
|
||||
t.Fatalf("count=%d want=%d", count, tc.want)
|
||||
}
|
||||
mu.Lock()
|
||||
captured := append([]bson.M(nil), commands...)
|
||||
mu.Unlock()
|
||||
if len(captured) == 0 {
|
||||
t.Fatal("covered count was not exercised")
|
||||
}
|
||||
var examined int64
|
||||
for _, cmd := range captured {
|
||||
clean := bson.D{}
|
||||
for _, key := range []string{"aggregate", "pipeline", "cursor", "hint", "maxTimeMS"} {
|
||||
if value, ok := cmd[key]; ok {
|
||||
clean = append(clean, bson.E{Key: key, Value: value})
|
||||
}
|
||||
}
|
||||
var result bson.M
|
||||
if err := db.RunCommand(ctx, bson.D{{Key: "explain", Value: clean}, {Key: "verbosity", Value: "executionStats"}}).Decode(&result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var walk func(any)
|
||||
walk = func(v any) {
|
||||
switch x := v.(type) {
|
||||
case bson.M:
|
||||
if stats, ok := x["executionStats"].(bson.M); ok {
|
||||
switch keys := stats["totalKeysExamined"].(type) {
|
||||
case int32:
|
||||
examined += int64(keys)
|
||||
case int64:
|
||||
examined += keys
|
||||
}
|
||||
}
|
||||
for key, value := range x {
|
||||
if key != "executionStats" {
|
||||
walk(value)
|
||||
}
|
||||
}
|
||||
case bson.A:
|
||||
for _, value := range x {
|
||||
walk(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(result)
|
||||
}
|
||||
t.Logf("count=%d aggregate_calls=%d examined_keys=%d", count, len(captured), examined)
|
||||
if examined == 0 || examined > n+n/10 {
|
||||
t.Fatalf("count rescanned the organization: keys=%d, linear budget=%d", examined, n+n/10)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -99,13 +99,17 @@ func (s *MongoStore) visitCoveredHumanPoolCounts(ctx context.Context, org string
|
||||
if lastID != "" {
|
||||
anchor["id"] = bson.M{"$gt": lastID}
|
||||
}
|
||||
// $facet consumes its whole input even when its rows branch has a
|
||||
// limit. Bound the scanned index page before it, not only the matches.
|
||||
pipeline := mongo.Pipeline{
|
||||
{{Key: "$match", Value: anchor}},
|
||||
{{Key: "$sort", Value: bson.D{{Key: "id", Value: 1}}}},
|
||||
{{Key: "$limit", Value: humanPoolCountBatchSize}},
|
||||
{{Key: "$project", Value: projection}},
|
||||
{{Key: "$facet", Value: bson.M{"rows": bson.A{bson.M{"$match": filter}, bson.M{"$limit": humanPoolCountBatchSize}}}}},
|
||||
{{Key: "$unwind", Value: "$rows"}},
|
||||
{{Key: "$replaceRoot", Value: bson.M{"newRoot": "$rows"}}},
|
||||
{{Key: "$facet", Value: bson.M{
|
||||
"rows": bson.A{bson.M{"$match": filter}},
|
||||
"scan": bson.A{bson.M{"$group": bson.M{"_id": nil, "lastID": bson.M{"$last": "$id"}, "count": bson.M{"$sum": 1}}}},
|
||||
}}},
|
||||
}
|
||||
cur, err := s.humanItems.Aggregate(ctx, pipeline, options.Aggregate().SetHint(humanPoolCountIndex).SetMaxTime(8*time.Second).SetBatchSize(humanPoolCountBatchSize))
|
||||
if err != nil {
|
||||
@ -114,22 +118,33 @@ func (s *MongoStore) visitCoveredHumanPoolCounts(ctx context.Context, org string
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
var rows []domain.HumanItemRecord
|
||||
err = cur.All(ctx, &rows)
|
||||
var pages []struct {
|
||||
Rows []domain.HumanItemRecord `bson:"rows"`
|
||||
Scan []struct {
|
||||
LastID string `bson:"lastID"`
|
||||
Count int `bson:"count"`
|
||||
} `bson:"scan"`
|
||||
}
|
||||
err = cur.All(ctx, &pages)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
if len(rows) == 0 {
|
||||
if len(pages) == 0 || len(pages[0].Scan) == 0 {
|
||||
return true, nil
|
||||
}
|
||||
next := rows[len(rows)-1].ID
|
||||
page := pages[0]
|
||||
next := page.Scan[0].LastID
|
||||
if next == "" || next <= lastID {
|
||||
return true, fmt.Errorf("pool count cursor did not advance")
|
||||
}
|
||||
if err := visit(rows); err != nil {
|
||||
return true, err
|
||||
if len(page.Rows) > 0 {
|
||||
if err := visit(page.Rows); err != nil {
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
if len(rows) < humanPoolCountBatchSize {
|
||||
// Sparse matches must not terminate the scan or reuse the last
|
||||
// matching ID: entire index pages may have no visible candidates.
|
||||
if page.Scan[0].Count < humanPoolCountBatchSize {
|
||||
return true, nil
|
||||
}
|
||||
lastID = next
|
||||
|
||||
@ -340,7 +340,7 @@
|
||||
"^internal/(api|store)/(human_pool|admin_annotation_pool|human_loop)",
|
||||
"^internal/(api/(human_display|human_list_reads)|store/human_run_display)",
|
||||
"^docs/operations/acceptance-search-indexes-v2\\.json$",
|
||||
"^tests/browser/(review-pool-search|admin-annotation-pool)",
|
||||
"^tests/browser/(review-pool-search|review-pool-count-status|admin-annotation-pool)",
|
||||
"^src/lib/review-claim-candidates\\.js$"
|
||||
],
|
||||
"frontend": [
|
||||
@ -360,6 +360,24 @@
|
||||
"./internal/store": ["^TestHumanPoolCountCandidateScan", "^TestAdminSourceExceptionsMemory"]
|
||||
},
|
||||
"task": [
|
||||
{
|
||||
"argv": ["node", "tests/browser/review-pool-count-status.mjs"],
|
||||
"tests": true
|
||||
},
|
||||
{
|
||||
"argv": [
|
||||
"go",
|
||||
"test",
|
||||
"./internal/store",
|
||||
"-run",
|
||||
"^TestHumanPoolCountsBoundedMongoScan$|^TestPlatformPoolCountCoveredScanParityAndBounds$",
|
||||
"-count=1",
|
||||
"-timeout=3m",
|
||||
"-v"
|
||||
],
|
||||
"env": { "POOL_COUNT_LOCAL_MONGO": "1", "POOL_LOCAL_MONGO_URI": "mongodb://127.0.0.1:27018" },
|
||||
"tests": true
|
||||
},
|
||||
{
|
||||
"argv": [
|
||||
"go",
|
||||
|
||||
@ -757,6 +757,8 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
counts: Record<TaskPoolView, number>;
|
||||
} | null>(null);
|
||||
const [reviewPoolCountError, setReviewPoolCountError] = useState("");
|
||||
const [reviewPoolCountRevision, setReviewPoolCountRevision] = useState(0);
|
||||
const [reviewPoolCountLoading, setReviewPoolCountLoading] = useState(false);
|
||||
const [acceptancePoolDetail, setAcceptancePoolDetail] = useState<{ scope: string; item: HumanItem } | null>(null);
|
||||
const [acceptancePoolDetailError, setAcceptancePoolDetailError] = useState("");
|
||||
const [acceptanceDetailRetry, setAcceptanceDetailRetry] = useState(0);
|
||||
@ -1077,9 +1079,14 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
...(pagedReviewPool ? [adminSearch, taskStatusFilter, requestedCaptureDirectory] : []),
|
||||
]);
|
||||
useEffect(() => {
|
||||
if (!pagedReviewPool) return;
|
||||
if (!pagedReviewPool) {
|
||||
setReviewPoolCountError("");
|
||||
setReviewPoolCountLoading(false);
|
||||
return;
|
||||
}
|
||||
const controller = new AbortController();
|
||||
setReviewPoolCountError("");
|
||||
setReviewPoolCountLoading(true);
|
||||
void humanLoopApi
|
||||
.poolCounts(
|
||||
{
|
||||
@ -1098,17 +1105,26 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
{ signal: controller.signal },
|
||||
)
|
||||
.then((result) => {
|
||||
if (!controller.signal.aborted) setReviewPoolTotals({ scope: projectDataScope, counts: result.counts });
|
||||
if (controller.signal.aborted) return;
|
||||
if (
|
||||
!["available", "mine", "reviewed", ...(isManager ? ["all"] : [])].every(
|
||||
(key) => Number.isInteger(result.counts?.[key]) && result.counts[key] >= 0,
|
||||
)
|
||||
)
|
||||
throw new Error("Incomplete task counts");
|
||||
setReviewPoolTotals({ scope: projectDataScope, counts: result.counts });
|
||||
})
|
||||
.catch((cause) => {
|
||||
.catch(() => {
|
||||
if (!controller.signal.aborted) {
|
||||
setReviewPoolTotals(null);
|
||||
if (cause?.status !== 404 && cause?.status !== 405)
|
||||
setReviewPoolCountError(getActionErrorMessage(cause, "加载任务数量失败"));
|
||||
setReviewPoolCountError("任务数量暂时无法读取");
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
if (!controller.signal.aborted) setReviewPoolCountLoading(false);
|
||||
});
|
||||
return () => controller.abort();
|
||||
}, [pagedReviewPool, projectDataScope, humanPools]);
|
||||
}, [pagedReviewPool, projectDataScope, humanPools, reviewPoolCountRevision]);
|
||||
const reviewPoolViewRef = useRef(taskPoolView);
|
||||
reviewPoolViewRef.current = taskPoolView;
|
||||
const reviewActionScopeRef = useRef(projectDataScope);
|
||||
@ -7293,9 +7309,27 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
|
||||
<div className="annotation-task-list-label mt-4 text-xs font-medium text-slate-500 dark:text-gray-400">
|
||||
逐段任务
|
||||
</div>
|
||||
{pagedReviewPool && reviewPoolCountLoading && (
|
||||
<div role="status" className="mt-2 text-xs text-slate-500">
|
||||
任务数量加载中…
|
||||
</div>
|
||||
)}
|
||||
{reviewPoolCountError && (
|
||||
<div role="alert" className="mt-2 text-xs text-red-600">
|
||||
{reviewPoolCountError}
|
||||
<div
|
||||
role="alert"
|
||||
data-testid="review-pool-count-error"
|
||||
className="mt-2 flex flex-wrap items-center gap-2 text-xs text-red-600"
|
||||
>
|
||||
<span>{reviewPoolCountError}</span>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="重试任务数量"
|
||||
disabled={reviewPoolCountLoading}
|
||||
onClick={() => setReviewPoolCountRevision((value) => value + 1)}
|
||||
className="underline"
|
||||
>
|
||||
重试
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="annotation-task-list mt-3 max-h-[calc(100vh-330px)] space-y-1.5 overflow-auto pr-1">
|
||||
|
||||
159
tests/browser/review-pool-count-status.mjs
Normal file
159
tests/browser/review-pool-count-status.mjs
Normal file
@ -0,0 +1,159 @@
|
||||
// The actual application, isolated read-only API responses. No production endpoints.
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import { createServer } from "vite";
|
||||
import { chromium } from "playwright";
|
||||
import { browserExecutableOptions } from "../../scripts/lib/browser-executable.mjs";
|
||||
import { closeBrowserFixture } from "../../scripts/lib/browser-test-lifecycle.mjs";
|
||||
const out = "local-data/test-results/issue20/browser";
|
||||
await fs.mkdir(out, { recursive: true });
|
||||
let browser, server;
|
||||
try {
|
||||
server = await createServer({
|
||||
configFile: "tests/browser/vite.platform-feedback.config.ts",
|
||||
server: { host: "127.0.0.1", port: 0 },
|
||||
});
|
||||
await server.listen();
|
||||
browser = await chromium.launch({ ...browserExecutableOptions(), headless: true, args: ["--no-proxy-server"] });
|
||||
for (const [role, mode] of [
|
||||
["acceptance_reviewer", "acceptance"],
|
||||
["quality_reviewer", "quality"],
|
||||
]) {
|
||||
const page = await browser.newPage({ viewport: { width: 1500, height: 1000 } });
|
||||
page.setDefaultTimeout(10000);
|
||||
let fail = true,
|
||||
reads = 0;
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
const slowSeen = Promise.withResolvers(),
|
||||
releaseSlow = Promise.withResolvers();
|
||||
await page.route("**/worker-api/**", (route) => route.fulfill({ json: { ready: true, status: "ok" } }));
|
||||
await page.route("**/api/**", async (route) => {
|
||||
const req = route.request(),
|
||||
u = new URL(req.url()),
|
||||
p = u.pathname;
|
||||
if (!p.startsWith("/api/")) return route.continue();
|
||||
assert.equal(req.method(), "GET", "pool status verification must not write");
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (p === "/api/auth/me")
|
||||
return json({
|
||||
user: { id: "reviewer", name: "Synthetic", role, status: "active", organizationId: "org" },
|
||||
organization: { id: "org", status: "active" },
|
||||
});
|
||||
if (p === "/api/plugins")
|
||||
return json({ items: [{ enabled: true, manifest: { id: "annotation-qa", name: "标注", version: "1" } }] });
|
||||
if (p === "/api/projects")
|
||||
return json({ items: [{ id: "p", name: "Synthetic project", organizationId: "org", status: "active" }] });
|
||||
if (p.endsWith("/members")) return json({ items: [{ userId: "reviewer", projectId: "p", roles: [role] }] });
|
||||
if (p === "/api/human-item-counts") {
|
||||
reads++;
|
||||
const search = u.searchParams.get("search");
|
||||
if (search === "slow") {
|
||||
slowSeen.resolve();
|
||||
await releaseSlow.promise;
|
||||
return json({ counts: { available: 99, mine: 99, reviewed: 99 }, filtersApplied: true }).catch(() => {});
|
||||
}
|
||||
if (search === "fast") return json({ counts: { available: 3, mine: 4, reviewed: 5 }, filtersApplied: true });
|
||||
if (search === "incomplete") return json({ counts: { available: 3 }, filtersApplied: true });
|
||||
return fail
|
||||
? route.fulfill({
|
||||
status: 500,
|
||||
json: {
|
||||
error: "(MaxTimeMSExpired) PlanExecutor error during aggregation: operation exceeded time limit",
|
||||
},
|
||||
})
|
||||
: json({ counts: { available: 7, mine: 1, reviewed: 9 }, filtersApplied: true });
|
||||
}
|
||||
if (p === "/api/human-item-summaries")
|
||||
return json({
|
||||
summaries:
|
||||
mode === "acceptance" && u.searchParams.get("pool") === "mine" && !u.searchParams.get("search")
|
||||
? [
|
||||
{
|
||||
kind: "pool-summary",
|
||||
id: "owned-acceptance",
|
||||
organizationId: "org",
|
||||
projectId: "p",
|
||||
workflowId: "w",
|
||||
runId: "r",
|
||||
batchId: "b",
|
||||
pluginId: "annotation-qa",
|
||||
currentStageId: "prepackage_acceptance",
|
||||
status: "claimed",
|
||||
assignedUserId: "reviewer",
|
||||
processingProfile: "raw_human",
|
||||
version: 1,
|
||||
createdAt: "2026-11-15T00:00:00Z",
|
||||
subject: { itemKey: "synthetic-capture" },
|
||||
display: { captureDirectories: ["synthetic-capture"], projectName: "Synthetic project" },
|
||||
durationSeconds: 8,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
hasMore: false,
|
||||
filtersApplied: true,
|
||||
});
|
||||
return json({ items: [], hasMore: false, labelIds: [], sliceLabelIds: [] });
|
||||
});
|
||||
await page.goto(
|
||||
`${server.resolvedUrls.local[0]}plugins/annotation-qa/workflows/all/${mode}?projectId=p&pool=mine`,
|
||||
{ waitUntil: "domcontentloaded" },
|
||||
);
|
||||
const mine = page.getByTestId("human-task-pool-mine");
|
||||
await mine.waitFor();
|
||||
await page
|
||||
.getByRole("alert")
|
||||
.filter({ hasText: /系统暂时无法完成操作|任务数量暂时无法读取/ })
|
||||
.waitFor();
|
||||
assert.match(await mine.innerText(), /—/);
|
||||
if (mode === "acceptance") {
|
||||
const action = page.getByTestId("acceptance-task-card").getByRole("button", { name: "继续处理", exact: true });
|
||||
await action.waitFor();
|
||||
assert(!(await action.isDisabled()), "count failure must not block continuing an owned acceptance task");
|
||||
}
|
||||
// Red on the screenshot symptom: the count error currently has no scoped recovery.
|
||||
const retry = page.getByRole("button", { name: "重试任务数量", exact: true });
|
||||
await retry.waitFor({ timeout: 1500 });
|
||||
assert.match(await page.getByTestId("review-pool-count-error").innerText(), /任务数量暂时无法读取/);
|
||||
await page.screenshot({ path: `${out}/${mode}-count-failed.png`, fullPage: true });
|
||||
fail = false;
|
||||
const before = reads;
|
||||
await retry.click();
|
||||
await mine.filter({ hasText: /我的任务\s+1/ }).waitFor();
|
||||
assert.equal(await mine.getAttribute("aria-pressed"), "true", "count retry must not switch task pools");
|
||||
assert.equal(
|
||||
await page.getByTestId("review-pool-count-error").count(),
|
||||
0,
|
||||
"successful refresh clears the count error",
|
||||
);
|
||||
assert(reads > before);
|
||||
assert.match(await page.getByTestId("human-task-pool-available").innerText(), /7/);
|
||||
assert.match(await page.getByTestId("human-task-pool-reviewed").innerText(), /9/);
|
||||
await page.screenshot({ path: `${out}/${mode}-count-recovered.png`, fullPage: true });
|
||||
const search = page.getByPlaceholder("搜索 Capture");
|
||||
await search.fill("slow");
|
||||
await slowSeen.promise;
|
||||
await search.fill("fast");
|
||||
await mine.filter({ hasText: /我的任务\s+4/ }).waitFor();
|
||||
releaseSlow.resolve();
|
||||
await page.waitForTimeout(100);
|
||||
assert.match(await mine.innerText(), /我的任务\s+4/, "obsolete count response cannot overwrite the current search");
|
||||
await search.fill("incomplete");
|
||||
await page.getByTestId("review-pool-count-error").waitFor();
|
||||
assert.match(
|
||||
await mine.innerText(),
|
||||
/—/,
|
||||
"incomplete totals remain unknown, never fabricated zero or stale totals",
|
||||
);
|
||||
await search.fill("");
|
||||
await mine.filter({ hasText: /我的任务\s+1/ }).waitFor();
|
||||
assert.equal(await page.getByTestId("review-pool-count-error").count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
}
|
||||
console.log(
|
||||
"PASS acceptance and quality: count timeout remains unknown, explicit retry restores scoped totals and clears error without changing selection or writing",
|
||||
);
|
||||
} finally {
|
||||
await closeBrowserFixture({ browser, vite: server });
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user