Show milestone progress bar for post generation queue jobs

Add percentage-by-stage progress in the queue UI, a progress rendering
test script, and clearer Chrome focus error details in the ChatGPT worker.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Loma Bot Ops
2026-11-23 15:36:52 +07:00
parent 53d39ae4cd
commit 4c691b5dde
6 changed files with 97 additions and 4 deletions
+17 -1
View File
@@ -59,7 +59,9 @@ try {
const managed = processes.find((item) => item.name === "page-post-generation" && item.pm2_env.status === "online");
if (managed) {
assert.equal(path.resolve(managed.pm2_env.pm_cwd).toLowerCase(), process.cwd().toLowerCase(), "Do not stop a worker belonging to another workspace");
assert.equal((process.env.POST_QUEUE_APP_URL || "").replace(/\/+$/, ""), base, "Managed worker must target the local test app");
const managedUrl = new URL(managed.pm2_env.POST_QUEUE_APP_URL || process.env.POST_QUEUE_APP_URL || "");
assert.ok(["localhost", "127.0.0.1"].includes(managedUrl.hostname), "Never pause a worker targeting a remote app");
assert.equal(await prisma.postGenerationJob.count({ where: { status: { in: ["QUEUED", "RUNNING"] } } }), 0, "Do not interrupt a live queue");
await pm2Call("stop", "page-post-generation"); restorePm2 = true;
}
const cookies = { manager: await login("manager"), viewer: await login("viewer"), outsider: await login("outsider") };
@@ -151,6 +153,18 @@ try {
if (last[job.id] !== current) { report.observations.push({ jobId: job.id, status: job.status, stage: job.stage, at: new Date().toISOString() }); last[job.id] = current; console.log(`${job.id}: ${current}`); await checkpoint(); }
}
const running = jobs.find((job) => job.id === first.id && job.status === "RUNNING");
if (running && ["content", "image"].includes(running.stage)) {
const minimum = running.stage === "content" ? 10 : 50;
report.progressScreenshots ??= [];
if (!report.progressScreenshots.includes(minimum)) {
const label = `ความคืบหน้าของ ${topicA}`;
await tab.waitForFunction(({ label, minimum }) => [...document.querySelectorAll("progress")].some((element) => element.getAttribute("aria-label") === label && element.value >= minimum), { label, minimum }, { timeout: 15_000 });
const bar = tab.getByRole("progressbar", { name: label, exact: true });
assert.equal(await bar.getAttribute("max"), "100");
await tab.screenshot({ path: path.join(directory, `running-${minimum}.png`), fullPage: true });
report.progressScreenshots.push(minimum);
}
}
if (running && !restarted) {
worker.kill(); worker = startWorker(); restarted = true;
const claims = await Promise.all([api("/api/cron/post-generation", null, null, "POST", config.POST_QUEUE_SECRET), api("/api/cron/post-generation", null, null, "POST", config.POST_QUEUE_SECRET)]);
@@ -194,6 +208,8 @@ try {
await tab.reload({ waitUntil: "networkidle" });
await tab.getByRole("link", { name: "เปิดฉบับร่าง" }).first().waitFor();
assert.equal(await tab.getByRole("link", { name: "เปิดฉบับร่าง" }).count(), 2);
assert.equal(await tab.getByText("100%", { exact: true }).count(), 2);
for (const bar of await tab.getByRole("progressbar").all()) assert.equal(await bar.getAttribute("value"), "100");
await tab.screenshot({ path: path.join(directory, "completed-desktop.png"), fullPage: true });
await tab.setViewportSize({ width: 390, height: 844 });
await tab.screenshot({ path: path.join(directory, "completed-mobile.png"), fullPage: true });