Skip to content

FE-1578: Replace fixed sleeps in Playwright tests with condition-based waits - #9529

Merged
claude[bot] merged 3 commits into
mainfrom
claude/fe-1578-replace-fixed-sleeps-in-playwright-tests
Sep 3, 2026
Merged

FE-1578: Replace fixed sleeps in Playwright tests with condition-based waits#9529
claude[bot] merged 3 commits into
mainfrom
claude/fe-1578-replace-fixed-sleeps-in-playwright-tests

Conversation

@claude

@claude claude Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Requested by Tim Diekmann · Slack thread

🌟 What is the purpose of this PR?

Before: four Playwright specs under tests/hash-playwright paused with fixed sleep(...) calls — 100 ms between editor keystrokes, 500 ms before clicking buttons, 2 s before a reload, 12 s for a notification poll. On a loaded runner the app can take longer than the sleep, so the next step runs too early and the test fails; in the merge queue that dequeues the whole batch. When the app is faster, the sleep only adds wall time.

After: each sleep is replaced by a wait on the state it stood in for — an element attached or visible, the editor's DOM reflecting the last keystroke, the document title reflecting the committed page title, or the updateBlockCollectionContents mutation's response. Sleeps that a following auto-waiting step already covered are deleted.

🔗 Related links

🚫 Blocked by

  • Nothing.

🔍 What does this change?

File Was Now
page-creation.spec.ts 500 ms before clicking the create-page button (both tests) openHomeReadyToCreatePage (new shared helper): opens /, waits for the response to the sidebar's queryEntitySubgraph request for the web owner (useCreatePage only navigates to the new page once that shortname is known, and nothing in the sidebar renders from that query), then for pages-tree to be attached (addPage is a no-op while pages load)
100 ms after the formatting shortcuts expect(em).toHaveText("italics")
100 ms after Enter expect(blockHandles).toHaveCount(2)
100 ms after typing /divider suggester list item matching /divider/i visible
100 ms after choosing the divider deleted — the next steps already wait for the hr
100 ms before typing the second paragraph expect(blockHandles).toHaveCount(3)
100 ms after typing text expect(blockRegion).toContainText(...)
100 ms after each Shift+Enter expect(hardBreaks).toHaveCount(n) on br:not(.ProseMirror-trailingBreak)
100 ms after the final Enter deleted — toHaveCount(4) follows
2 s "give collab time to sync" before reload waitForResponse for the updateBlockCollectionContents response whose returned contents hold 4 blocks, armed before the final Enter
3 × 500 ms before re-filling the page title expect(page).toHaveTitle(...) with the committed name — the document title comes from the refetched page query, so it changes only once the saved title has propagated back to the page
page-readonly-mode.spec.ts 500 ms before clicking the create-page button openHomeReadyToCreatePage, which also supplies the navigation this test was missing
inbox-page.spec.ts 2 × 12 s for the notification poll (default interval 10 s), with test.setTimeout(60_000) to fit them page.reload() after creating each notification, then toBeVisible() with the default timeout — the notifications query is a network-only useQuery mounted by the page, so a reload fetches at once instead of waiting for the poll; test.setTimeout removed
profile-page.spec.ts 5 s for the bio editor to mount (×2) placeholder text visible — the placeholder plugin renders it only when the editor is loaded, empty and focused
2 s after "Save Bio" before reload (×2) waitForResponse for the updateBlockCollectionContents request carrying the bio text, armed before typing
2 s after reload (×2) deleted — auto-retrying toBeVisible assertions follow

Left as they are: the poll interval in shared/get-kratos-verification-code.ts, the TOTP window wait in shared/totp-utils.ts, the debounce helper in extension/browser-plugin.spec.ts, and the sleep(500) in entity-editing.spec.ts, which #9526 removes.

playwright.config.ts is unchanged: no retries, no timeouts.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

⚠️ Known issues

  • Unverified by execution: the environment this was written in has no Docker, so the suite has not been run. CI is the first run.
  • Three of the four specs (page-creation, page-readonly-mode, profile-page) are test.skip'd, so CI exercises only inbox-page.spec.ts.
  • The block-count waits in page-creation.spec.ts (3 blocks after inserting the divider) take the counts the test already asserted as correct; they are not re-verified here.

🐾 Next steps

  • If the create-page button gained a readiness state in the UI, the tests could wait on that instead of on the shortname query's response.

🛡 What tests cover this?

  • The changed specs themselves; only inbox-page.spec.ts runs in CI.

❓ How to test this?

  1. Run yarn test:integration in tests/hash-playwright against a local stack.
  2. Confirm inbox-page.spec.ts passes in a few seconds rather than the 24 s it used to sleep.

Wait for the state each sleep stood in for: an element attached or
visible, the editor DOM reflecting the last keystroke, the document
title reflecting the committed page title, or the
updateBlockCollectionContents response. Drop sleeps that a following
auto-waiting step already covers.
@vercel

vercel Bot commented Sep 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

4 Skipped Deployments
Project Deployment Actions Updated
hash Ignored Ignored Preview Sep 3, 2026 6:39pm UTC
hashdotdesign-tokens Ignored Ignored Preview Sep 3, 2026 6:39pm UTC
petrinaut Skipped Skipped Sep 3, 2026 6:39pm UTC
petrinaut-docs Skipped Skipped Sep 3, 2026 6:39pm UTC

Request Review

Copilot AI left a comment

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.

🟡 Changes recommended

Page creation needs a reliable shortname-readiness condition, and the inbox test timeout needs additional headroom.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Replaces fixed Playwright sleeps with condition- and response-based waits to reduce test flakiness and runtime.

Changes:

  • Adds DOM, title, visibility, and mutation-response waits.
  • Removes obsolete fixed delays.
  • Synchronizes notification and editor interactions with observable state.
File summaries
File Review
tests/hash-playwright/tests/features/profile-page.spec.ts Waits for editor readiness and bio-save responses; no issues found.
tests/hash-playwright/tests/features/page-readonly-mode.spec.ts Waits for pages-tree, but this does not guarantee the separately queried owner shortname is ready before page creation.
tests/hash-playwright/tests/features/page-creation.spec.ts Adds editor, title, and persistence waits; the page-tree wait can race with owner-shortname readiness and prevent navigation.
tests/hash-playwright/tests/features/inbox-page.spec.ts Replaces polling sleeps with visibility assertions, but the 60-second test timeout lacks sufficient headroom for two 30-second waits plus setup.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/hash-playwright/tests/features/inbox-page.spec.ts Outdated
Comment thread tests/hash-playwright/tests/features/page-creation.spec.ts Outdated
…ox instead of polling

The sidebar's create-page button only navigates to the new page once
`useCreatePage` knows the web owner's shortname, which comes from a
separate `queryEntitySubgraph` request that renders nothing in the
sidebar. Waiting for `pages-tree` alone therefore left a race. A shared
helper opens the home page, waits for that request's response and for
the page list, and replaces the three call sites.

The notifications page mounts a `network-only` query, so reloading it
after creating each notification shows the new one at once. Assert with
the default expect timeout and drop the test-level timeout, rather than
waiting on the 10 s poll.
@vercel
vercel Bot temporarily deployed to Preview – petrinaut September 3, 2026 18:24 Inactive
@vercel
vercel Bot temporarily deployed to Preview – petrinaut-docs September 3, 2026 18:24 Inactive
…page helper

`getUser` returns the first root of the `me` subgraph, which is typed as
possibly undefined under `noUncheckedIndexedAccess`, so `lint:tsc` failed
with TS18048 on the unguarded access. Throw when no user comes back, as
the inbox spec does.
@vercel
vercel Bot temporarily deployed to Preview – petrinaut-docs September 3, 2026 18:38 Inactive
@vercel
vercel Bot temporarily deployed to Preview – petrinaut September 3, 2026 18:38 Inactive
@claude
claude Bot requested a review from TimDiekmann September 3, 2026 19:01
@claude
claude Bot marked this pull request as ready for review September 3, 2026 19:02
@cursor

cursor Bot commented Sep 3, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Test-only changes with no application or library behavior modified; CI impact is limited to integration test timing and stability.

Overview
Playwright specs under tests/hash-playwright no longer rely on fixed sleep(...) delays. Waits now track the UI or network state each pause was meant to cover, which should cut flaky failures on slow runners and wasted time when the app is fast.

A new shared helper openHomeReadyToCreatePage opens /, waits for the sidebar’s queryEntitySubgraph response for the web owner (so create-page navigation has the shortname), then for pages-tree to attach. Page-creation and read-only specs use it instead of a 500 ms delay before Create page.

inbox-page.spec.ts reloads after each API-created notification instead of waiting ~12 s for polling, and drops the 60 s test timeout. page-creation.spec.ts ties editor steps to DOM signals (block handles, italic text, divider suggester, hard breaks) and waits for a GraphQL updateBlockCollectionContents response with four blocks before reload; rename flows wait on toHaveTitle for the saved name. profile-page.spec.ts waits for the editor placeholder and for the bio save mutation in the request body.

Production code is unchanged; only test helpers and assertions.

Reviewed by Cursor Bugbot for commit 7223b79. Bugbot is set up for automated code reviews on this repo. Configure here.

@TimDiekmann
TimDiekmann added this pull request to the merge queue Sep 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 3, 2026
@claude

claude Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Dequeued at 22:00 UTC by an unrelated Playwright failure in the queue run (run 33808993925): tests/extension/browser-plugin.spec.ts:256 "user can configure a one-off inference, and the settings are persisted" — the Actor chip never appeared (toHaveCount(1) got 0, then the 30 s test timeout). This PR does not touch that spec; the same head passed Playwright in its parallel queue group, on the PR branch, and main is green. This is the same flake that dequeued #9526 earlier today. Re-enabling auto-merge to re-enqueue.


Generated by Claude Code

@claude
claude Bot added this pull request to the merge queue Sep 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 3, 2026
@claude

claude Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Dequeued again at 22:29 UTC by the same test, in run 33811421092: tests/extension/browser-plugin.spec.ts:256 "user can configure a one-off inference, and the settings are persisted" hit its 30 s test timeout while re-opening the popup after sign-out (openPopupTab at line 276, then page.evaluate: Target page, context or browser has been closed). Different failure point from the 22:00 run, same test, still a file this PR does not touch and a different Playwright project. This PR was alone in its queue group both times; its own CI on this head is green. Re-enabling auto-merge once more.


Generated by Claude Code

@claude
claude Bot added this pull request to the merge queue Sep 3, 2026
Merged via the queue into main with commit 875ca53 Sep 3, 2026
59 checks passed
@claude
claude Bot deleted the claude/fe-1578-replace-fixed-sleeps-in-playwright-tests branch September 3, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/tests > playwright New or updated Playwright tests area/tests New or updated tests

Development

Successfully merging this pull request may close these issues.

3 participants