Skip to content

test(browser): dialog specs press Escape only once the page's script listens - #1414

Merged
allisonmahmood merged 1 commit into
mainfrom
t3/fix-dialog-escape-readiness
Nov 12, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
t3/fix-dialog-escape-readiness

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

What changed

Tier 1 specs pressed Escape on a dialog page once its field took autofocus or its dialog or refusal showed. The dialog's Escape, close link and place in history come from the deferred /assets/ui.js, which can run after those appear. On a loaded CI runner the Escape did nothing, and the page sat on the dialog's URL for 15 s (#1377: shell.spec.ts, patch-page.spec.ts, sharing.spec.ts).

A new helper, loadDialog(page, act) in test/browser-tier1/dialog.ts, runs the act that loads a dialog page (a link to one, or a submission it refuses). It then waits for that page's DOMContentLoaded, which a browser fires only after deferred scripts have run. Every spec that acts on a freshly loaded dialog page now goes through it.

Closes #1377

Look at

1. The signal is DOMContentLoaded, armed before the act. ui.js loads with defer, so once DOMContentLoaded fires its listeners are attached, and the served pages need no new marker. The wait is set up before the click, so it catches the new page's event even when the old page looks the same: a second refusal already shows aria-invalid. The signal holds only while ui.js stays defer, which Server.test.ts asserts.

2. Red, then green, with ui.js held 1.5 s by a scratch route (a context.route delay in prepare, not committed).

Before the fix, 7 of the 23 tests in the five files fail, each at an Escape, a close link or a Back on a dialog page:

✘ shell.spec.ts       › closing a dialog puts focus back on the sidebar link that opened it, …
    Expected: …/~focus/page                 Received: …/~focus/dialog
✘ patch-page.spec.ts  › Delete and Retire ask in a dialog over Settings, …
    Expected: …/patches/desk-map/settings   Received: …/patches/desk-map/delete
✘ people.spec.ts      › an admin invites in a dialog over People, …
    Expected: …/settings/people             Received: …/settings/people/invites
✘ sharing.spec.ts     › a row of All patches opens its patch from anywhere on it, …
    Expected: …/patches                     Received: …/patches?share=tier-one-acceptance
✘ ui.spec.ts          › the keyboard opens and closes menus and dialogs, and focus comes back
    Expected: /\/~ui$/                      Received: …/~ui/dialog
✘ ui.spec.ts          › a refused submission draws the dialog again, and closing it skips the submission
    Expected: /\/~ui\/index\?page=2$/       Received: …/~ui/dialog
✘ ui.spec.ts          › Back from a refused submission closes the dialog to the page that opened it
    Expected: /\/~ui\/index\?page=2$/       Received: …/~ui/dialog

After the fix, with the same delay: 23 passed (2.4m).

3. Could a person hit it? Only by pressing Escape between the dialog appearing and ui.js running, about one fetch of ui.js, which is served no-cache. Pressing Escape again then works. Closing any sooner would take a second inline script admitted by hash, or a ui.js that blocks rendering, which isn't worth it for a gap that short, so this PR doesn't change the product.

How it was verified

  • --repeat-each=5 on the five touched files: 115 passed in the headless shell with the repo's config, and 115 passed in desktop Chromium (channel: "chromium", through a throwaway config outside the repo).
  • pnpm typecheck:tests, pnpm lint and bun fmt are clean.
  • I searched every Escape press under test/. In the switcher, shortcut-setting, Tell Patchy, starting and hotkeys specs, it closes a menu or a <dialog> that an already-running script opened, not a freshly loaded dialog page. ui.spec.ts's page.goto cases already wait for load. Retire submits a form, which needs no script. Reassign passed under the delay only because its refused page leaves focus to the script, so it goes through the helper too.

Release impact

  • Breaking — requires action from anyone already running this

  • Not breaking — no action required: tests only.

  • What does a revert leave behind? Nothing; only test files change.

  • Does the release before it still work with that? Yes.

Built by Claude Opus 5.5 (claude-opus-5-5) in Claude Code, through T3 Code.

@github-actions github-actions Bot added area:ci CI, shared testing infrastructure, development scripts and tooling size:s Under 100 changed lines labels Nov 12, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review (GPT 6.1 Sol), at 2bb2431: nothing blocking.

  • The signal is sound. ui.js installs its Escape, close-link and history handling synchronously, and as a deferred script it finishes before DOMContentLoaded.
  • No stale document. No path lets an old document's event satisfy the wait. Redirects fire the final document's event, and so do 422 refusals.
  • Coverage is complete. The remaining Escape presses target dialogs that an already-running script opened, or follow a goto that waits for load.
  • Leaving the product unchanged is reasonable. The early-Escape gap is real for people, but the close link works while the script loads.

A Chromium probe with ui.js delayed 300 ms passed: direct and redirected navigation, repeated 422s, and Escape, close-link and Back chains.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 2bb24313dd27628bbe12bc0ffc2426ee584a2de5 (base b9dc456b243559fe5c49e3e758d8cf46167141eb), with the tier 1 suite's own instances and brightline, by Claude Opus 5.5 in Claude Code (T3 Code).

Done means (#1377: every spec that presses Escape on a freshly loaded dialog page waits for its script)

  • Red without the fix: passed. At the base, I ran the five touched files with /assets/ui.js held for 1.5 s. 7 of 23 failed, each at an Escape or a Back on a dialog page. These are the same 7 cases the PR lists, at the same steps.

  • Green with the fix: passed. At the head, with the same 1.5 s hold, 23 passed (2.3m). With a 4 s hold, 23 passed (4.9m). The slowest case, Back from a refused submission, took 48.8 s of its 120 s budget. So the helper really waits for the script; the 1.5 s pass isn't a matter of timing.

  • No other spec has this race: passed. I grepped every Escape, goBack and Close under test/. Each one outside the PR's cases is one of these:

    • It follows a page.goto, which waits for load: ui.spec.ts:46,51.
    • It closes a native popover menu, which needs no script: the second Escape at sharing.spec.ts:64 (menus are popovertarget).
    • It is the Back in a no-script context: people.spec.ts:84, ui.spec.ts:224.
    • It moves through a patch frame's routes rather than a portal dialog: the four Backs in tier1.spec.ts.
    • It closes a switcher, panel, sheet or <dialog> that an already-running script opened: switcher, tell-patchy, shortcut-setting, starting, hotkeys.

    home and whats-new press no key on a dialog. Retire's confirmation is a plain form submit. This matches the PR's own account.

  • Both browsers: passed. Five files with --repeat-each=3, one run at a time: 69 passed (1.8m) in the headless shell with the repo's config, and 69 passed (1.9m) in desktop Chromium. During the desktop run, the process list showed chromium-1243/chrome-linux64/chrome rather than the shell.

  • CI on the head: every required check passes, including browser. Only attio-live and imap-live are skipped.

Commands and output

The hold lives in a scratch Playwright config outside the checkout, never committed. It wraps every context.route handler through Playwright's client instrumentation, so the delay sits inside prepare's own route:

core._instrumentation.addListener({
  runAfterCreateBrowserContext: async (context) => {
    const route = context.route.bind(context);
    context.route = (url, handler, options) =>
      route(url, async (r, q) => {
        if (delay > 0 && new URL(q.url()).pathname === "/assets/ui.js")
          await new Promise((done) => setTimeout(done, delay));
        return handler(r, q);
      }, options);
  }
});
// the rest mirrors playwright.tier1.config.ts, with maxFailures: 0 and testDir in the checkout

Red, at the base:

$ git checkout --detach b9dc456b
$ WT=<checkout> UI_DELAY_MS=1500 pnpm exec playwright test -c <scratch>/delay.config.ts \
    patch-page.spec.ts people.spec.ts sharing.spec.ts shell.spec.ts ui.spec.ts
  ✘ patch-page.spec.ts:8   Delete and Retire ask in a dialog over Settings …   (16.9s)
      > 27 | await expect(browser).toHaveURL(`${card}/settings`)
      Expected …/patches/desk-map/settings   Received …/patches/desk-map/delete
  ✘ people.spec.ts:3       an admin invites in a dialog over People …           (16.8s)
      > 22 | await expect(page).toHaveURL(people)
      Expected …/settings/people             Received …/settings/people/invites
  ✘ sharing.spec.ts:47     a row of All patches opens its patch …               (16.8s)
      > 59 | await expect(page).toHaveURL(`${instance.origin}/patches`)
      Expected …/patches                     Received …/patches?share=tier-one-acceptance
  ✘ shell.spec.ts:113      closing a dialog puts focus back on the sidebar link … (16.6s)
      > 130 | await expect(page).toHaveURL(`${instance.origin}/~focus/page`)
      Expected …/~focus/page                 Received …/~focus/dialog
  ✘ ui.spec.ts:6           the keyboard opens and closes menus and dialogs …    (16.8s)
      > 30 | await expect(page).toHaveURL(/\/~ui$/)                 Received …/~ui/dialog
  ✘ ui.spec.ts:52          a refused submission draws the dialog again …        (18.4s)
      > 67 | await expect(page).toHaveURL(/\/~ui\/index\?page=2$/)   Received …/~ui/dialog
  ✘ ui.spec.ts:74          Back from a refused submission closes the dialog …   (18.4s)
      > 98 | await expect(page).toHaveURL(/\/~ui\/index\?page=2$/)   Received …/~ui/dialog
  7 failed
  16 passed (3.8m)

Green, at the head (the build is identical; only test/ differs):

$ git checkout --detach 2bb24313
$ WT=<checkout> UI_DELAY_MS=1500 PATCHY_TIER1_SKIP_BUILD=1 pnpm exec playwright test -c <scratch>/delay.config.ts <same five files>
  23 passed (2.3m)
$ WT=<checkout> UI_DELAY_MS=4000 PATCHY_TIER1_SKIP_BUILD=1 pnpm exec playwright test -c <scratch>/delay.config.ts <same five files>
  ✓ patch-page.spec.ts:9   Delete and Retire …                          (17.2s)
  ✓ sharing.spec.ts:48     a row of All patches …                       (8.4s)
  ✓ shell.spec.ts:114      closing a dialog puts focus back …
  ✓ ui.spec.ts:7           the keyboard opens and closes …              (33.2s)
  ✓ ui.spec.ts:79          Back from a refused submission …             (48.8s)
  23 passed (4.9m)

Both browsers, at the head, with no delay:

$ PATCHY_TIER1_SKIP_BUILD=1 pnpm exec playwright test -c playwright.tier1.config.ts --project=chromium --repeat-each=3 <same five files>
  69 passed (1.8m)
$ WT=<checkout> PATCHY_TIER1_SKIP_BUILD=1 pnpm exec playwright test -c <scratch>/desktop.config.ts --repeat-each=3 <same five files>
  # desktop.config.ts: the repo's config with channel: "chromium"
  69 passed (1.9m)

A person's view (brightline at the head, as Allison, the Delete dialog on Harbor & Pine's kickoff brief from its Settings)

I drove it with a Playwright script and pressed Escape the moment the dialog showed. A page-side capture listener logged each keydown and each DOMContentLoaded into sessionStorage.

  • The whole page throttled to DevTools' 3G (562.5 ms latency, 1.6 Mbit/s down): the first Escape closed the dialog every time, landing on Settings with focus on Delete…. That was 4 of 4 runs: three in the headless shell, one in desktop Chromium. ui.js arrives with the page, so it had already run by the time the key landed.

    1350 ms  ui.js arrived
    1526 ms  dialog visible on /patches/harbor-pine-kickoff/delete
    1529 ms  Escape pressed (1st)
    1731 ms  DOMContentLoaded on …/delete
    2531 ms  DOMContentLoaded on …/settings
    3300 ms  focus on: Delete…
    
  • Only ui.js slow (held 2 s, as the tests hold it): the first Escape does nothing, and the dialog stays. A second Escape once the script has run closes it, with focus back on Delete….

    …/delete: keydown Escape, readyState interactive   ← before ui.js; nothing happens
    …/delete: DOMContentLoaded
    …/delete: keydown Escape, readyState complete      ← closes to Settings
    
  • Close pressed before ui.js runs works as the plain link it is without script. It lands on Settings, but focus starts at the top of the page, and Back returns to the dialog.

Leaving the product unchanged seems acceptable to me. The gap opens only when ui.js arrives well after the page. A lost Escape is safe on every dialog, Delete included, which still needs the typed name and a submit. Pressing again works, and Close always works.

Golden journeys: none touched. The diff is six files under test/browser-tier1/, and no product code changes.

Rollback answers: they match the diff. Only test files change, so a revert leaves nothing behind, and no one-way label is needed.

Not run

  • Firefox: the five touched files run only in the Chromium project, both in the repo's config and on CI.

Notes

  • pnpm dev up hit pnpm dev up fails installing the environment's CLI: pinned npm 12 refuses the local tarball (EALLOWREMOTE) #1240. The pinned npm 12 refused the environment's CLI tarball with EALLOWREMOTE. I ran the dev runner directly (bun --conditions=development scripts/dev/src/main.ts up brightline) with a Node 24 / npm 11.19.0 first on PATH, and it finished. This is not this PR's problem.
  • The defer assertion the signal relies on is narrower than the claim. Server.test.ts:893 checks <script defer src="/assets/ui.js"> on the /~ui gallery pages only. Every portal page gets the same uiScriptTag constant (packages/core/src/ui/enhancer.ts:5), though, so the signal holds wherever the helper is used.

@allisonmahmood
allisonmahmood force-pushed the t3/fix-dialog-escape-readiness branch from 2bb2431 to ea131e6 Compare November 12, 2026 17:22
@allisonmahmood
allisonmahmood merged commit 18c619a into main Nov 12, 2026
26 checks passed
@allisonmahmood
allisonmahmood deleted the t3/fix-dialog-escape-readiness branch November 12, 2026 17:34
allisonmahmood added a commit that referenced this pull request Nov 12, 2026
… its own process (#1302)

## What changed

CI's browser tier ran Playwright's `chrome-headless-shell`, which keeps
a patch's sandboxed frame in the shell's process. Desktop Chrome gives
it its own process. That's how #1299 shipped: in desktop Chrome a patch
didn't hear the keyboard until clicked, while CI was green. #1298 fixed
#1299 on `main`.

This PR moves the tier 1 suite's `chromium` project to desktop Chromium,
so a focus or keyboard bug that only Chrome shows fails CI. It no longer
holds anything back: every test in the suite runs in desktop Chromium.
#1407's `firefox` project still runs `focus.spec.ts` alone.

Closes #1299

## Look at

**`playwright.tier1.config.ts`.** The `chromium` project sets `channel:
"chromium"`, the full build in new headless mode, and #1407's `firefox`
project sits beside it unchanged. The headless-shell hold-out is gone.
#1406 fixed the local-hotkeys test's accessibility helper, which
couldn't read an out-of-process frame, and the test now passes in
desktop Chromium. `pnpm test:browser` runs `chromium`, as on `main`, so
`package.json` doesn't change.

**What landed first.** In desktop Chromium on CI, `switcher.spec.ts`
failed often (#1402). #1412 fixed that on `main`, with one real
desktop-Chrome focus race fixed in the shell's broker and switcher tests
that acted too early. One of #1412's tests, the tab switch in
`switcher.spec.ts`, skips in the headless shell, which keeps every tab
focused. It starts running on CI with this PR.

**The frame really is out of process.** CDP's `Target.getTargets` lists
it as its own `iframe` target in desktop Chromium, and not in the
headless shell.

## How it was verified

- **On CI at this head, `a92a7f1`:** the `browser` job passed twice in a
row. Each time desktop Chromium passed 180 and Firefox 8, with none
failed or skipped. The local-hotkeys test and the tab-switch test ran in
desktop Chromium.
- **Locally:** the local-hotkeys test passed 3 of 3 in desktop Chromium,
and the Firefox project 8 of 8.
- **Earlier heads, stacked on #1412 before it merged:**
- Five passes in a row at its first head, and two or three at each later
one.
  - One failure was the #1377 flake, since fixed on `main` by #1414.
- One `test (bun)` failure was a `Fleet.test.ts` clock-step case, which
passed on rerun.
- The other failures were gaps in #1412's own fix, each fixed in #1412.
- **CI cost.** No new download. `playwright install chromium` without
`--only-shell` already puts both Chromium builds in Chromium's cache
entry, and the action's comment says why it stays that way.
- **Not checked:** headed Chrome on a real display. New headless is the
same browser build and runs the frame out of process, as the target
count shows.

Hit every surface:
- **Dev loop docs:** `docs/DEVELOPMENT.md` says the browser job runs
desktop Chromium with `focus.spec.ts` also in Firefox, and that a script
launching its own browser for a focus check passes the same channel. The
CI job's and the Playwright action's comments say the same.
- **Doesn't apply:** served pages, the wire contract, the CLI,
vocabulary, migrations, company resources, reverse states and the repo
layout.

## Release impact

Tick exactly one.

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required. Test and CI configuration
and doc lines; nothing ships.

- **What does a revert leave behind?** Nothing. CI goes back to the
headless shell.
- **Does the release before it still work with that?** Yes.

Built by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, through T3
Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
allisonmahmood added a commit that referenced this pull request Nov 12, 2026
…ey shortcuts (#1421)

## What changed

This adds release 42's What's new entry, written from `1cd6d12`. It
covers everything merged since release 41's `through` (`a25a9c5`), and
sets the `patchy` release to `0.42.0` in `packages/patchy/package.json`
and `CURRENT_RELEASE`.

| Change | PRs |
| --- | --- |
| New: Tell Patchy what it's missing | #1217, #1218, #1219, #1227, #1228
|
| New: Turn off single-key shortcuts | #1276, #1279, #1301 |
| Fixed: Typing reaches the patch again | #1407, #1412 |
| Fixed: Dialogs in patches keep your place | #1420, #1255 |
| Behind the scenes: plainer facts for agents building patches | #1249,
#1256, #1297, #1418 |
| Behind the scenes: Patchy stores teams and audiences ahead of teams |
#1416 |
| Patch changes: Mod+/ and `client.close()` in patchy/hotkeys;
single-key shortcuts can be off; Tab wraps in plain modal dialogs |
#1279, #1301, #1420 |

#1376 is release 41's own entry. #1400, #1406, #1414, #1415, #1302,
#1413 and #1419 are test, CI and dev tooling and need no line.

The teams bridge (#1416) ships alone in this release so teams (#1417)
can follow in the next one with a release to roll back to that reads its
data closed.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`.
- **Rollback safety, from the live commit `7f93b91` (release 41) to this
PR's merge.** No PR in the range is labelled `one-way`, and every
Release impact answer says release 41 still works:
- **#1217** adds migration `0037_feedback`, a schema release 41 never
reads. **#1227** and **#1228** write into it.
- **#1276** adds migration `0038_single_key_shortcuts`, a column with a
default that release 41 never selects.
- **#1416** adds migrations `0039_company_teams` to
`0041_connection_audiences`, which hold tables that stay empty until
teams ship, and widens one scope check. Its CI rehearsal ran `7f93b91 →
head → 7f93b91 → head` on one set of data, and all four steps passed.
- **#1279**, **#1301**, **#1255** and **#1420** change the SDK and the
shell. Patches built on this release carry a `shortcutSetting` manifest
field that release 41 reads without refusing, and its shell names no
frame, so every shortcut stays on.
- **#1218** and **#1219** add CLI commands and an optional
`feedbackHint` in `--json` failures. A CLI from this release refuses to
publish to an older instance before sending anything, as any mismatched
release does.
  - Everything else is skill text, docs, tests and CI.

If this release misbehaves, roll back to `7f93b91` (release 41).

Written by Claude Opus 5.5 in Claude Code, through T3 Code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky: shell dialog focus case presses Escape before the dialog script listens

1 participant