Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/browser/strict-selection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,7 @@ for (const selection of ["strict", "practice"]) {
if (!page) return;
await preflight(page);
await page.locator("#editor:not([disabled])").waitFor();
await page.waitForFunction(() => window.roomJoins.length === 1);
await page.locator("#editor").fill("active attempt must survive");
await page.waitForFunction(() => {
const event = new Event("beforeunload", { cancelable: true });
Expand Down
87 changes: 50 additions & 37 deletions tests/browser/task-workspace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3224,44 +3224,57 @@ test("a Finish dialog open when the attempt ends closes and finishes nothing", a
}
});

test("a result poll still on its way neither repeats nor replaces the delivered result", async (t) => {
const ctx = await pageFor(t);
if (!ctx) return;
const { page } = ctx;
let held = 0;
const releases = [];
try {
await start(page);
await page.route("**/api/task-reviews/**", async (route) => {
held += 1;
await new Promise((resolve) => releases.push(resolve));
await route.fulfill({
status: 202,
contentType: "application/json",
body: JSON.stringify({ pending: true }),
});
test(
"a result poll still on its way neither repeats nor replaces the delivered result",
{ timeout: 30000 },
async (t) => {
const ctx = await pageFor(t);
if (!ctx) return;
const { page } = ctx;
let held = 0;
const releases = [];
let polling;
const pollStarted = new Promise((resolve) => {
polling = resolve;
});
await page.evaluate(() => document.exitFullscreen());
// Past the delivery window, with the first poll still unanswered.
await page.clock.runFor(301000);
assert.equal(held, 1);
await page.evaluate(
(value) => globalThis.taskHarness.publish("task_review", value),
result("invalid", "fullscreen"),
);
await page.locator("#review").waitFor({ state: "visible" });
for (const release of releases) release();
await page.clock.runFor(1000);
assert.match(await page.locator("#outcome").textContent(), /invalid/);
assert.doesNotMatch(
await page.locator("#review-content").textContent(),
/still being finalized|unavailable/i,
);
} finally {
for (const release of releases) release();
await page.close();
}
});
try {
await start(page);
await page.route("**/api/task-reviews/**", async (route) => {
held += 1;
polling();
await new Promise((resolve) => releases.push(resolve));
await route.fulfill({
status: 202,
contentType: "application/json",
body: JSON.stringify({ pending: true }),
});
});
await page.evaluate(() => document.exitFullscreen());
// Past the delivery window, with the first poll still unanswered.
await page.clock.runFor(301000);
// Advancing the page clock does not flush Playwright's network events.
await pollStarted;
assert.equal(held, 1);
await page.evaluate(
(value) => globalThis.taskHarness.publish("task_review", value),
result("invalid", "fullscreen"),
);
await page.locator("#review").waitFor({ state: "visible" });
const answered = page.waitForResponse("**/api/task-reviews/**");
for (const release of releases) release();
await answered;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: await answered only waits for the network response event, not for pollReview to finish handling it. The late 202 can still be processed after the #outcome and #review-content assertions, so the test can pass without covering the guard. Wait for the page-side effect, for example by polling st.reviewPolling or the rendered state, before advancing the clock and asserting.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/browser/task-workspace.test.js, line 3265:

<comment>`await answered` only waits for the network response event, not for `pollReview` to finish handling it. The late 202 can still be processed after the `#outcome` and `#review-content` assertions, so the test can pass without covering the guard. Wait for the page-side effect, for example by polling `st.reviewPolling` or the rendered state, before advancing the clock and asserting.</comment>

<file context>
@@ -3260,7 +3260,9 @@ test(
       await page.locator("#review").waitFor({ state: "visible" });
+      const answered = page.waitForResponse("**/api/task-reviews/**");
       for (const release of releases) release();
+      await answered;
       await page.clock.runFor(1000);
       assert.match(await page.locator("#outcome").textContent(), /invalid/);
</file context>

await page.clock.runFor(1000);
Comment thread
MorganHo001 marked this conversation as resolved.
Resolved
assert.match(await page.locator("#outcome").textContent(), /invalid/);
assert.doesNotMatch(
await page.locator("#review-content").textContent(),
/still being finalized|unavailable/i,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is named for a poll that "neither repeats", but held is checked only once, before the result is published. A regression that starts another poll after the delivered result still passes: the route holds that request and nothing counts it again. Check the count once the late answer has been handled:

Suggested change
);
);
assert.equal(held, 1);

} finally {
for (const release of releases) release();
await page.close();
}
},
);

test("an ended attempt lets go of a wake lock granted late and of its detector", async (t) => {
const ctx = await pageFor(t);
Expand Down
Loading