Skip to content

test(relay): unmount every tree and run its pending sheet step before the fake window goes - #4495

Merged
devswha merged 1 commit into
mainfrom
fix/relay-shell-test-leak
Nov 23, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/relay-shell-test-leak

Conversation

@devswha

@devswha devswha commented Nov 23, 2026

Copy link
Copy Markdown
Owner

main's Fast checks failed at a22661f (the squash of #4492) with an unhandled error between two tests of src/components/RelayShell.test.tsx:

TypeError: undefined is not an object (evaluating 'window.history.state')
  at src/lib/sheetHistory.ts:320

Cause

A closed sheet does not leave its history entry right away. leaveSheet leaves it on a setTimeout(0). #4492 gave Add a PC over My PCs such an entry. The sheet closes in a test's last step (a sign-in landing on My PCs), or when the tree unmounts in afterEach. Either way, the timer was still pending when afterEach put the globals back. Under load it then ran between hooks, against the outer describe's window ({ location }, no history). Whether it ran before or after the restore depended on timing, so the PR's own CI passed and main's failed.

Production cannot reach this path: a page always has its window. So sheetHistory.ts is unchanged, with no guard.

Fix (tests only)

Each of the three relay test files (RelayShell.test.tsx, RelayShellScreens.test.tsx, RelayShell.history.test.tsx) now:

  • tracks every tree it draws;
  • unmounts all of them at the test's end, not only the one kept in renderer (RelayShellScreens' provider tests never unmounted theirs);
  • then runs a few timer turns (setTimeout(resolve, 0)) inside act, while its fake window is still in place.

The history test's fake history.back() now does nothing on the first entry, as a browser's does, so a leave that steps back at the end cannot throw.

No changelog fragment: this changes nothing a user notices (changelog.d/README.md).

Validation

  • Loop under load: each file run 30 times with bun test --timeout 60000 ./<file> (how scripts/ci-tests.ts runs one unit file), while a bun run check fast ran beside it:

    File Before the fix After the fix
    RelayShell.test.tsx 15/30 runs with this unhandled error 0/30
    RelayShell.history.test.tsx 0/30 0/30
    RelayShellScreens.test.tsx 0/30 0/30

    The check fast run beside the before-loop also hit the error once in its own unit run.

  • bun run check fast on the head (f9dd0db): every step ok, unit tests 23,761 pass, 0 fail.

  • Skipped: integration, browser, Windows and macOS lanes. The change is test files only.

🤖 Generated with Claude Code

… the fake window goes

main's Fast checks failed at a22661f with an unhandled TypeError at
sheetHistory.ts:320 (window.history.state) between two tests of
RelayShell.test.tsx. A sheet that closes (Add a PC over My PCs) leaves its
history entry on a setTimeout(0) (leaveSheet). When it closed in a test's last
step, or as the tree unmounted in afterEach, that timer was still pending when
afterEach put the globals back, and under load it ran between hooks against the
outer describe's window, which has no history.

Each of the three relay test files now tracks every tree it draws, unmounts all
of them at the test's end, and runs a few timer turns while its fake window is
still in place; RelayShellScreens' provider tests had left their trees mounted.
The history test's afterAll does the same, and its fake Back does nothing on the
first entry, as a browser's does.

Under a concurrent check fast, 30 runs of RelayShell.test.tsx failed 15 times
before and 0 times after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Improved browser-history test behavior at the first history entry.
    • Added cleanup for mounted test renderers and delayed restoration of browser globals until pending updates have settled.

The RelayShell tests now track renderer instances during teardown, wait for pending timer work before restoring browser globals, and prevent the history mock from traversing back past its first entry.

Changes: RelayShell test cleanup

Layer / File(s) Summary
Track and clean up renderers
src/components/RelayShell.test.tsx, src/components/RelayShellScreens.test.tsx
Both suites track created renderers, unmount any that remain during cleanup, and wait three timer turns before restoring browser globals.
Guard history traversal and teardown
src/components/RelayShell.history.test.tsx
The history mock skips traverseBack() at the first entry. Teardown waits one turn after unmounting while the mocked window remains available.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: Minimal · up to f9dd0

This change only adjusts test cleanup to remove an intermittent test error. It has no production impact, and the reported validation shows the flake is fixed. The risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: test-only fixes that unmount every rendered tree and run pending sheet timers before the fake window is removed. It matches the changeset and the PR objectives, and it…
Description check Passed The description covers the problem and cause, the fix across the three test files, and validation with before/after loop results and skipped lanes. The template's Change and Validation sections are bo…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: test-only fixes that unmount every rendered tree and run pending sheet timers before the fake window is removed. It matches the changeset and the PR objectives, and it is specific enough for history scanning.

Full details: Description check

Explanation

The description covers the problem and cause, the fix across the three test files, and validation with before/after loop results and skipped lanes. The template's Change and Validation sections are both present. It does not link an issue for a feature, but this is a bug fix, so that requirement does not apply. It also states that no changelog fragment is needed, with a reason. Contract-test coverage is not mentioned, but the PR does not touch HTTP/WS code, so this is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 87b5796 and f9dd0db.

Files selected for processing: 3

  • src/components/RelayShell.history.test.tsx
  • src/components/RelayShell.test.tsx
  • src/components/RelayShellScreens.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@devswha
devswha merged commit 02bb848 into main Nov 23, 2026
13 checks passed
@devswha

devswha commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head f9dd0db27. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit reviewed this head.

Merged by the lead session to stop a flaky failure on main that this session's own #4492 introduced (owner told this session to go on, 2026-11-23). Test files only: the three RelayShell test files unmount every tree they drew and let pending sheet-history timers run before restoring the globals; no product code changed. Evidence in the PR: RelayShell.test.tsx failed 15 of 30 runs under load before, 0 of 30 after. Reviews: CodeRabbit only; no adversarial review (test-only change). Checks: bun run check fast locally; GitHub checks green at this head.

@devswha
devswha deleted the fix/relay-shell-test-leak branch November 23, 2026 03:44
devswha added a commit that referenced this pull request Nov 23, 2026
…anager, in the hosted look (#4498)

## What changes for a person

**Hosted-home build (the default).** The hosted Connect a PC screen is
the app's home (#4490). The app's own page is no longer a three-tab
connect page; it is one column of what works with no internet, in the
hosted page's look:

- As the fallback (home did not load): the sheep, "Can't connect to the
internet" / 「인터넷에 연결할 수 없어요」 and Try again (`goHome`), then **Connect by
address** / 「주소로 직접 연결」: one field that does what the Tailscale tab's
field and Add by address did (the public-http warning, `demo` for the
bundled demo, and on Android, while Tailscale is off and a Tailscale
address is typed or listed, a line with Open Tailscale), **Scan a QR
code** (a Tailscale QR or a PC's QR still opens on a home network; the
camera check is as before), **Connect over SSH** / 「SSH로 연결」 (a row
whose field takes `user@host` and opens the SSH setup; only in an app
with `OvisSsh`), the PCs an SSH PC knows, and **PCs this phone is on**:
every PC the phone saved in one list (relay scopes by name, else the
start of the id; Tailscale; plain addresses; SSH), each opening as
before, Forget where it was, Manage on SSH PCs.
- Choosing another PC while offline: "‹ <PC>" back and that PC marked In
use now / 「지금 사용 중」, as before.
- Opened by home for an SSH setup: straight to the SSH setup with the
login filled in. Opened to manage an SSH PC (Change PC where one did not
open): that PC's Manage opens (rename, phone key, set up again, forget
host key, remove), the one last opened, else the only SSH PC. Both with
"‹ Back" to home, as #4490 built it.
- A pairing link from outside the app (Android) goes into the address
field and opens, as before.

**Bundled-home build (`OVIS_APP_HOME=bundled`, or
`OVIS_APP_ACCOUNT=0`).** Nothing a person can do changes: the three
tabs, the sign-in buttons, every list, Manage. Only the look changes.

**One look.** `index.html`, `error.html`, the SSH manager and the native
SSH setup screen (Android `SshSetupActivity`, iOS `SshSetupView`) take
the hosted Connect a PC screen's look: the Codex theme's colours, light
or dark as the phone is, and the hosted type sizes, radii, buttons, tabs
and list rows. `shell.css` copies the values from `src/styles.css` (the
Codex theme blocks and the `:root` scale) and
`src/components/RelayShell.css` / `RelayAddPc.css`, naming each source.
The pages use the hosted typeface: `build-web.ts` writes
`pretendard.css`, which points upstream's dynamic-subset stylesheet at
the font files the bundled demo already carries, so the app holds the
font once; a chunk the demo lacks fails the build. The warm palette and
the "Ovis" top bar are gone. Every page sets its `theme-color` to its
own colour in both themes, which both apps' bars follow (Android's
`MainActivity`, iOS's native follow from #4497); `error.html` does too
(it was dark only). The pages' own iOS `SystemBars.setStyle` call is
gone: #4497 made it redundant. The native SSH setup screen takes the
phone's mode when it opens (it is not recreated on a mode change, by
design).

**Native parts of the hand-over, colours only.** #4490's covers
("Opening Ovis…", "Opening <PC>…", Keep waiting, Try again, Change PC),
the web view before a page paints, Android 12's launch screen and the
SSH setup screen take the same palette, light or dark as the phone is,
so nothing flashes dark before a light page. No behaviour, timing or
text of #4490 changed. On Android the bars take the cover's colour while
it is up and the page's `theme-color` once it lifts (before, a page's
colour could arrive under a still-raised cover). Native files touched,
for the reader of the diff:

- `app/android/app/src/main/java/sh/ovis/app/MainActivity.java`: the
cover's colour values (`showOpening`), the web view's first-paint
colour, and the bars under the cover (`pageBarColor`, one `paintBars`
line each in `showOpening` and `hideOpening`, one posted after
SystemBars' own style).
- `app/android/app/src/main/res/values/colors.xml`, new
`values-night/colors.xml`, `values/styles.xml`: the page colours light
and dark; the window background and the launch screen's background take
them.
- `app/android/app/src/main/java/sh/ovis/app/SshSetupActivity.java`:
colour fields from the phone's mode at open, rounded field and button
boxes, flat buttons.
- `app/ios/App/App/HerdrBridgeViewController.swift`: dynamic colours for
the cover and the SSH wait screen, and
`instanceDescriptor().backgroundColor` for the first paint.
- `app/ios/App/App/SshSetupView.swift`: dynamic colours, no forced dark
scheme.
- `app/ios/App/App/Info.plist`, `ko.lproj/InfoPlist.strings`: the camera
text.

**Words (en + ko).** The hosted page's words for the same things: In use
now / 지금 사용 중 (was Connected / 연결됨), the tags Relay / Address, the
scanner's "Point at the QR code on the PC's screen". "Settings → Phone &
devices" is "Settings → Devices and PCs → Add a connection" / 「설정 → 기기와
PC → 연결 추가」 everywhere under `app/`, the iOS camera usage string
included. The pages' Korean is in 해요체 throughout (the open failures take
#4492's hosted Korean word for word). No failure title under `app/` said
머신; 「Linux와 macOS 기기만」 says PC. A PC at a Tailscale IP was listed as
"100" (its first dotted word); it is listed by its address now, as the
hosted My PCs does.

## Removed

From the hosted-home build's own page: the three tabs, the relay tab and
its sign-in buttons (they need the internet and the hosted page), and
the separate Tailscale and SSH lists (one list now). From every page:
the warm palette and the top bar. Nothing native was removed.

## Store notes

- `app/store/ios.md` and `app/store/android.md`: the review notes no
longer send reviewers to a "Direct" tab. The steps that work in both
builds: on the first screen, Connect a PC, tap the SSH tab, then Add by
address, type `demo` and tap Connect; with no internet, type `demo` in
the app's own address field. The Android App access text is 491
characters.
- `app/store/ios.md`: the guideline 4.2 paragraph now says the first
screen is the hosted page and lists what is native: the offline connect
screen, the SSH client with its keys kept on the device, the QR scanner,
push through the app (once the APNs build ships), direct connections on
the local network, the bridge, and the offline demo; the fallback plan
is a build with `OVIS_APP_HOME=bundled`.
- The descriptions and the camera text name Settings > Devices and PCs >
Add a connection. Both files note that the store screenshots predate
this look. Nothing was submitted anywhere.

## Validation

On this PC (Linux):

- `bun run check fast`: passed (typecheck, build, 23787 unit tests), on
main with #4495 and #4497 merged in. Android `:app:testDebugUnitTest`:
177 pass on the same head.
- `bun test scripts/app-shell.test.ts scripts/app-web-connect.test.ts
src/lib/i18n.test.ts`: all pass (73 in the two app files). The new page
tests were written first and failed against #4490's page: the column (no
tabs, no sign-in, its order, one list with relay scopes, Forget and
Manage), Try again, the Korean words, the address field and its
public-http warning, a relay row opening its scope, QR, the SSH row and
a handed-over SSH setup, Manage opened for `manage`, choosing and both
back ways, `demo`, Tailscale off; the bundled build's three tabs, the
providers the service names, no relay tab without the account, In use
now and Manage on SSH. Static tests cover the layouts, the stale
Settings path and 머신 under `app/`, 합니다체 on the pages, and
`pretendard.css`.
- Android, android-35 emulator (a fresh AVD of my own, WebView 124),
debug builds of a QA twin (`sh.ovis.app.previewqa`,
`OVIS_APP_URL=https://relay-0510.ovis-app.pages.dev`), `build:web` and
`cap sync android` from the same environment each time, state read with
`getState` over the WebView's devtools; light and dark, English and
Korean:
- airplane mode, first launch: the column with "Can't connect to the
internet"; the theme switched live with the bars following (dark icons
on white, light on #181818);
- network back: nothing moved by itself; an address typed in the field
(a throwaway Ovis server on this PC's Tailscale address, isolated herdr
test session) opened that PC; a cold start opened it again;
- from that PC, Connect a PC (`chooseAnother`) in airplane mode: the
column with "‹ <PC>", the PC marked 지금 사용 중, `getState` `{choosing:
true, fallback: true, back: "current"}`; Try again with the network
back: hosted home (`home: true`), screenshots of both side by side in
the report folder;
- hosted home › SSH tab › `user@host` › Connect: the native SSH setup,
in the Codex palette in both modes (a QA-only patch lifted `FLAG_SECURE`
to take its screenshots); Back: the column with the SSH row open and the
login filled in;
  - `demo` in the address field: the bundled demo;
- `OVIS_APP_HOME=bundled` build: first launch on the three tabs with the
sign-in buttons, new look, light and dark; SSH tab › Add by address ›
`demo` opened the demo.
- Android, the same twin with the native colours: the start in light and
in dark (launch screen, the PC's cover, its loading page, the PC), first
launch onto home (launch screen, "Opening Ovis…", home) and offline
(launch screen, the column): every step in the phone's mode, the bars'
icons readable on each. `:app:testDebugUnitTest` 177 pass; instrumented
`ChangePcTest`, `BackToPageTest`, `BackRacesTest` 6 pass on that
emulator.
- iOS, on the test Mac (macOS 27.0.1, Xcode 27.2), from a git bundle in
a fresh `/tmp` clone, deleted afterwards: `xcodebuild` for the iOS
Simulator, Debug, `CODE_SIGNING_ALLOWED=NO`, once with hosted home and
once with `OVIS_APP_HOME=bundled`, both succeeded (the "Check the hosted
origin" phase passed); in the iPhone 18 Pro simulator (iOS 27.0): the
hosted build with its origin pointed at a host that does not resolve
(`OvisAppOrigin` and `public/shell.js` patched on the built app) came up
on the column, the status bar icons following light and dark; the real
hosted build opened home; the bundled build opened the three tabs, light
and dark; its SSH tab handed `user@host` to the native SSH setup sheet,
whose colours followed a live light/dark switch. With the native
colours: one more simulator build and a launch in light and in dark onto
home ("Opening Ovis…" cover, then home), and the offline variant in dark
onto the column.
- After #4497 merged: main merged in, the iOS `SystemBars.setStyle`
block removed, and one more simulator build (iPhone 18 Pro, iOS 27): the
hosted build launched in light and in dark (a burst of screenshots
through the launch image, the cover and home), the column (origin
pointed at a host that does not resolve), and `error.html` (an
unreachable address typed in the column), with the bars' icons readable
on each.
- Review fixes (an independent Opus review of 3e74a05): Remove's
warning that the phone's key is still in the PC's `authorized_keys` now
shows under the list instead of off-screen under the address field; the
page's live regions stay in the page while empty (they were `display:
none`, so their text would not be announced); and the tabs in a hosted
build without the account got their test back. Each has a test, the
first two written first and failing before the fix.

Not done:

- No real phone, no device or store build, no sign-in.
- Not seen on a device: Manage opened by `manage` after an SSH PC failed
(no SSH PC was set up on the emulator; it rests on the page test), the
Android pairing link from outside the app, the camera.
- The SSH setup could not finish on the simulator (an unsigned build's
Keychain refuses the key, -34018), and on the emulator no SSH PC was
added; only the screen's look was checked there.

Follow-ups and things seen:

- iOS status bar icons: #4497 (merged first) makes them follow the
page's `theme-color`, the cover's colour and, before a page paints, the
web view's background, which this PR sets to the page colour. Seen on
the simulator after merging it: dark icons on the white "Opening Ovis…"
cover and hosted home in light mode, light icons in dark; the column and
`error.html` likewise, `error.html` following a live switch.
- The hosted page's `theme-color` is its panel colour (`#f9f9f9` /
`#1f1f1f`) while its page is `#ffffff` / `#181818`, so its bars differ
slightly from its page; the app's own pages keep bars equal to their
page. To align, the hosted page would take `--bg` (a `src/` follow-up).
- The launch images (iOS `Splash.imageset`, Android's pre-12
`splash.png`) are unchanged: dark with the sheep in both modes, so a
light-mode start shows them for a moment before the white cover.
Regenerating them with `@capacitor/assets generate
--splashBackgroundColor '#ffffff' --splashBackgroundColorDark '#181818'`
is a follow-up.
- In a bundled-home build, Back from the demo leaves the app; main does
the same.

🤖 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant