🧪 Verify summary polling in browser and concurrent recovery

This commit is contained in:
d-robotics 2026-10-28 09:20:58 -07:00
parent e94a8d2c14
commit a2eac93e2f
3 changed files with 234 additions and 1 deletions

View File

@ -24,3 +24,12 @@ Risk: mixed-version response compatibility, permissions, in-flight workflow reco
- Go baseline gate passed with 68 known failures, no additions. Frontend gate still fails two source guards: `review-target-interaction.test.mjs :: source guard: resident editor binds the selected target with a tier label` and `scope-cycle-inline-editor.test.mjs :: source guard: resident inline editor promotes into edit state on focus`. Both reproduce unchanged at HEAD 8cdd2d79 in a separate archived baseline. The baseline full gate also had a temporary-copy local-stack/version failure and a hung devboot test that was terminated; these are not claimed as passes. Initial sandbox frontend run also needed termination of devboot before rerunning outside the sandbox.
- Global format check reports four untouched files: ReviewHistorySummary.tsx, WorkforceStatisticsPanel.tsx, useAnnotationOutputData.ts, useReviewContinuation.ts. Modified frontend files were formatted; git diff --check passes. No baseline files were altered to hide failures.
- Pending: browser end-to-end validation of this integration, batch/projected display fallback refinement, actual pool p95 and the specified repeated 81-user soak. This is not a release/capacity acceptance. No push, PR or deployment.
## 2026-10-28 browser and concurrent HTTP verification
- Added `node tests/browser/annotation-buffer-summary.mjs`: real application in Edge/Vite, every API intercepted with synthetic data and external hosts blocked. Passed real 3-second summary polling without repeated full-item hydration, old-server full-response compatibility, failed poll/reconnect, manual task selection retained after polling, and an unsaved action-description draft retained across two polls. No unexpected allocation/submission or page errors. Media playback and actual backend submission are outside this fixture.
- `node tests/browser/review-continuation-errors.mjs`: all 12 quality/acceptance compact/legacy renew, error, empty and control-loss cases passed.
- Extended `TestAnnotationBufferMongoHTTPConcurrencyAndReceipt`: mixed summary/legacy GETs alongside 16 concurrent claims per round, five rounds in a unique local Mongo database. Capacity remains two; settled summary/full state is equivalent; interrupted receipt recovery and a freshly constructed handler retain results. Passed normally and with Go `-race`.
- `-race` also passed `TestMongoAnnotationWorkBufferPollIsReadOnly` and `TestReviewContinuationCompactRenewKeepsLegacyContract`. Targeted review read-count/permission-revocation, display and continuation regressions passed.
- Browser artifacts: `local-data/test-results/annotation-buffer-summary-browser/{result.json,passed.png,page.txt}`. Initial test attempts exposed an assertion before React settled and an incorrect child-element click target; these were corrected to await the state and click the actual action block. Final run completed without source changes/HMR during execution.
- No full 81-user mixed-role harness was found in the existing scripts/tests. These small synthetic concurrent tests are functional evidence only, not pool p95, production bandwidth or CPU/memory capacity proof. The baseline/stage1/stage2 dataset, workload runner and three repeated 5-minute-warmup/30-minute-steady comparisons remain required. Existing global frontend/format gate debt from the preceding entry remains unresolved. No release or production mutation.

View File

@ -90,7 +90,14 @@ func TestAnnotationBufferMongoHTTPConcurrencyAndReceipt(t *testing.T) {
defer wg.Done()
requestID := fmt.Sprintf("mongo-buffer-%02d-request-%02d", round, n)
// Concurrent buffer polling exercises reconciliation while ownership writes finish.
_ = call(n, "GET", bufferPath, nil)
pollPath := bufferPath
if n%2 == 0 {
pollPath += "&view=summary"
}
poll := call(n, "GET", pollPath, nil)
if poll.Code != 200 {
t.Errorf("concurrent poll: %d %s", poll.Code, poll.Body.String())
}
r := call(n, "POST", "/api/plugins/annotation-qa/random-claims", map[string]any{"projectId": project, "requestId": requestID})
if r.Code == 200 {
var out struct {
@ -124,6 +131,38 @@ func TestAnnotationBufferMongoHTTPConcurrencyAndReceipt(t *testing.T) {
if r.Code != 200 || buffer.Capacity != 2 || buffer.Occupied != 2 || len(buffer.Items) != 2 {
t.Fatalf("round %d buffer: %d %s", round, r.Code, r.Body.String())
}
checkSummary := func(handler int) {
t.Helper()
old := call(handler, "GET", bufferPath, nil)
compact := call(handler, "GET", bufferPath+"&view=summary", nil)
var full struct {
Capacity int `json:"capacity"`
Occupied int `json:"occupied"`
Items []domain.HumanItemRecord `json:"items"`
}
var summary struct {
Capacity int `json:"capacity"`
Occupied int `json:"occupied"`
Summaries []annotationBufferSummary `json:"summaries"`
}
must(json.Unmarshal(old.Body.Bytes(), &full))
must(json.Unmarshal(compact.Body.Bytes(), &summary))
if old.Code != 200 || compact.Code != 200 || full.Capacity != summary.Capacity || full.Occupied != summary.Occupied || len(full.Items) != len(summary.Summaries) {
t.Fatalf("summary/full mismatch: %s / %s", old.Body.String(), compact.Body.String())
}
expected := map[string]annotationBufferSummary{}
for _, row := range summarizeAnnotationBuffer(full.Items) {
expected[row.ID] = row
}
for _, row := range summary.Summaries {
a, _ := json.Marshal(expected[row.ID])
b, _ := json.Marshal(row)
if string(a) != string(b) {
t.Fatalf("summary state differs: %s / %s", a, b)
}
}
}
checkSummary(0)
for _, result := range claims {
r = call(1, "POST", "/api/plugins/annotation-qa/random-claims", map[string]any{"projectId": project, "requestId": result.requestID})
var replay struct {
@ -166,6 +205,9 @@ func TestAnnotationBufferMongoHTTPConcurrencyAndReceipt(t *testing.T) {
if r.Code != 200 || buffer.Occupied != 2 || len(buffer.Items) != 2 {
t.Fatalf("receipt replay consumed capacity: %d %s", r.Code, r.Body.String())
}
// Fresh process-local caches after recovery must not change summaries.
handlers[1] = NewHandler(store.NewMongoStore(db), nil)
checkSummary(1)
}
}

View File

@ -0,0 +1,182 @@
// Actual application, synthetic HTTP only. Never forwards API calls to a server.
import assert from "node:assert/strict";
import fs from "node:fs/promises";
import { chromium } from "playwright";
import { createServer } from "vite";
const out = "local-data/test-results/annotation-buffer-summary-browser";
await fs.mkdir(out, { recursive: true });
const server = await createServer({ server: { host: "127.0.0.1", port: 0 } });
let browser, page;
const report = { cases: [], errors: [], writes: [], polls: [], detailReads: 0 };
try {
await server.listen();
browser = await chromium.launch({
executablePath: process.env.BROWSER_PATH || "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
headless: true,
args: ["--no-proxy-server"],
});
page = await browser.newPage({ viewport: { width: 1600, height: 1000 } });
page.setDefaultTimeout(15000);
page.on("pageerror", (e) => report.errors.push(e.message));
let legacy = false,
failed = false;
const user = { id: "annotator", name: "合成标注员", role: "annotator", status: "active", organizationId: "org" };
const item = {
id: "item",
projectId: "project",
organizationId: "org",
workflowId: "workflow",
pluginId: "annotation-qa",
legacyTaskId: "task",
assignedUserId: user.id,
currentStageId: "annotation_combined",
status: "in_progress",
version: 1,
reviewRound: 0,
processingProfile: "raw_human",
subject: { payload: { sliceWorkflow: { status: "completed", phase: "annotate" }, captureDirectory: "合成采集" } },
display: { captureDirectories: ["合成采集"] },
};
const summary = {
id: item.id,
projectId: item.projectId,
legacyTaskId: item.legacyTaskId,
assignedUserId: item.assignedUserId,
currentStageId: item.currentStageId,
status: item.status,
version: 1,
reviewRound: 0,
sliceStatus: "completed",
slicePhase: "annotate",
display: item.display,
};
const task = {
id: "task",
organizationId: "org",
projectId: "project",
workflowId: "workflow",
templateId: "template",
templateVersion: 6,
status: "pending_annotation",
humanStageId: "annotation_combined",
processingProfile: "raw_human",
continuousActions: true,
currentRevision: 1,
sourceVideo: "fixture.mp4",
clipStart: 0,
clipEnd: 10,
assignedUserId: user.id,
};
await page.route("**/*", async (route) => {
const req = route.request(),
u = new URL(req.url()),
p = u.pathname;
if (u.hostname !== "127.0.0.1" && u.hostname !== "localhost") return route.abort();
if (!p.startsWith("/api/") && !p.startsWith("/worker-api/")) return route.continue();
if (!["GET", "HEAD"].includes(req.method())) report.writes.push(p);
const json = (data) => route.fulfill({ json: data });
if (p === "/api/auth/me") return json({ user, organization: { id: "org", name: "合成组织" } });
if (p === "/api/plugins")
return json({ items: [{ enabled: true, manifest: { id: "annotation-qa", name: "标注", version: "1" } }] });
if (p.includes("health") || p.includes("ready")) return json({ status: "ok", ready: true });
if (p === "/api/projects")
return json({ items: [{ id: "project", organizationId: "org", name: "合成项目", status: "active" }] });
if (p.endsWith("/members"))
return json({
items: [{ id: "member", projectId: "project", userId: user.id, supplierId: "supplier", roles: ["annotator"] }],
});
if (p.endsWith("/workflows")) return json({ items: [{ id: "workflow", name: "合成流程", nodes: [], edges: [] }] });
if (p.endsWith("/templates"))
return json({ items: [{ id: "template", projectId: "project", version: 6, labels: [] }] });
if (p.endsWith("/work-buffer")) {
report.polls.push(Object.fromEntries(u.searchParams));
if (failed) return route.fulfill({ status: 503, json: { error: "synthetic offline" } });
return json({
enabled: true,
capacity: 2,
occupied: 1,
processing: {},
...(legacy ? { items: [item] } : { summaries: [summary] }),
});
}
if (p === "/api/human-items/item") {
report.detailReads++;
return json({ item });
}
if (p === "/api/human-items") return json({ items: u.searchParams.get("pool") === "mine" ? [item] : [] });
if (p.endsWith("/sidebar")) return json({ items: [item], tasks: [task], hasMore: false });
if (p.endsWith("/tasks")) return json({ items: [task] });
if (p.endsWith("/frame-timeline"))
return json({
rangeStartSecond: 0,
rangeEndSecond: 10,
boundariesSeconds: Array.from({ length: 11 }, (_, i) => i),
boundaryContract: "hardware-frame-v1",
});
if (p.includes("/tasks/task"))
return json({ task, humanItem: item, revisions: [], sliceRevisions: [], reviews: [], continuousActions: true });
return json({ items: [], labelIds: [], sliceLabelIds: [] });
});
await page.goto(server.resolvedUrls.local[0] + "plugins/annotation-qa/workflows/all/work?projectId=project");
await page.waitForFunction(() => document.querySelector('[aria-label="个人任务切换"]'));
assert.match(await page.getByRole("combobox", { name: "个人任务切换" }).innerText(), /合成采集/);
const before = report.polls.length,
reads = report.detailReads;
await page.waitForTimeout(6500);
assert.ok(report.polls.length >= before + 2, "actual three-second polling continues");
assert.equal(report.detailReads, reads, "stable polls do not hydrate full records again");
assert.ok(report.polls.every((p) => p.view === "summary"));
report.cases.push("actual page uses summary polling; stable polls do not reload full item");
legacy = true;
await page.waitForTimeout(3500);
assert.match(await page.getByRole("combobox", { name: "个人任务切换" }).innerText(), /合成采集/);
report.cases.push("actual page accepts legacy full buffer responses");
failed = true;
await page.waitForTimeout(3500);
assert.match(await page.getByRole("combobox", { name: "个人任务切换" }).innerText(), /合成采集/);
failed = false;
legacy = false;
await page.waitForTimeout(3500);
assert.match(await page.getByRole("combobox", { name: "个人任务切换" }).innerText(), /合成采集/);
report.cases.push("failed poll retains task switcher and reconnect resumes");
await page.getByRole("combobox", { name: "个人任务切换" }).selectOption("task");
await page.waitForURL(/taskId=task/);
await page.waitForFunction(() => document.querySelector('[aria-label="个人任务切换"]')?.value === "task");
await page.waitForTimeout(3500);
assert.equal(await page.getByRole("combobox", { name: "个人任务切换" }).inputValue(), "task");
report.cases.push("manual task selection survives subsequent summary poll");
await page.getByTestId("annotation-description-block").click();
const draft = page.getByRole("textbox", { name: "动作描述", exact: true });
await draft.fill("尚未保存的合成草稿");
const pollCount = report.polls.length;
await page.waitForTimeout(6500);
assert.ok(report.polls.length >= pollCount + 2);
assert.equal(await draft.inputValue(), "尚未保存的合成草稿");
report.cases.push("unsaved action description survives two real summary polls");
await fs.writeFile(out + "/page.txt", await page.locator("body").innerText());
assert.deepEqual(report.errors, []);
assert.ok(
!report.writes.some((p) => p.includes("random-claims") || p.includes("submissions")),
"manual polling must not allocate or submit",
);
await page.screenshot({ path: out + "/passed.png" });
report.passed = true;
console.log(JSON.stringify(report, null, 2));
} catch (e) {
report.passed = false;
report.error = String(e);
await fs.writeFile(
out + "/failure.txt",
await page
?.locator("body")
.innerText()
.catch(() => ""),
);
await page?.screenshot({ path: out + "/failure.png" }).catch(() => {});
console.error(e);
throw e;
} finally {
await fs.writeFile(out + "/result.json", JSON.stringify(report, null, 2));
await browser?.close();
await server.close();
}