test(ui): wait for the settings notification before the company home redirect assertion (#22528)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The company home redirect sends a user to Dashboard or to
Responsibilities, based on an experimental flag
> - A UI test for this redirect fails on slow CI runners. The master
Release for 7a4a5bba8a failed two attempts on this test.
> - The product code is correct. The test has a timing race with React
Query.
> - React Query sends its update to React in a `setTimeout(0)` callback.
The test started its own 1 ms timer in the same `act` call, before that
callback was scheduled. When the runner crosses a millisecond boundary
between the two timers, the test timer fires alone, `act` ends, and the
assertion runs before React gets the flag.
> - This pull request makes the test wait on the condition (`vi.waitFor`
on the redirect target) instead of a fixed 1 ms timer, as in
`App.activity-routing.test.tsx`.
> - The benefit is that releases are no longer blocked by this test.

## Linked Issues or Issue Description

**What happened?**

The master Release for 7a4a5bba8a failed in "Reuse exact-source
verification". Its Cloud readiness run failed on two attempts in `verify
/ General tests (workspaces-a (1/2))`. One test failed:
`ui/src/components/CompanyHomeRedirect.test.tsx > CompanyHomeRedirect >
renders nothing while the flag loads, then a single redirect`, with
`AssertionError: expected undefined to be '/responsibilities'`. 532 of
533 files passed. The same test passed on master commits 782bd8d8eb,
ac02de7732 and 7e30ba2c45, so master CI is not consistently red.

**Expected behavior**

The test passes on every runner. It checks that the redirect renders
nothing while the flag loads, and then one redirect to Responsibilities.

**Steps to reproduce**

1. Add a temporary 3 ms busy wait to the mocked settings response (this
models a slow runner).
2. Keep the old wait: `await act(async () => { resolve(...); await new
Promise((done) => setTimeout(done, 1)); })`.
3. Run `pnpm --filter @paperclipai/ui exec vitest run
src/components/CompanyHomeRedirect.test.tsx`.
4. The test fails with the same CI error on every run (3 of 3).

**Paperclip version or commit**

origin/master 7e30ba2c45 (also 7a4a5bba8a). The test came from #22069.
No later commit changed the redirect code, so this is not a regression.

## What Changed

- The test resolves the settings response in `act`. It then uses
`vi.waitFor` until the redirect goes to `/responsibilities`, instead of
a fixed 1 ms timer.
- The assertion that nothing renders while the flag loads stays. No
product code changed.

## Verification

- Red: with a temporary 3 ms busy wait on the mocked response and the
old fixed 1 ms wait, the test failed 3 of 3 runs with `expected
undefined to be '/responsibilities'`.
- Green: with the same temporary busy wait and the new condition wait,
the test passed 3 of 3 runs. Without it, the file passed 10 of 10 runs
with no act warnings.
- The test still fails if the redirect is wrong: with the flag resolved
off, it fails with `expected '/dashboard' to be '/responsibilities'`.
- `pnpm --filter @paperclipai/ui exec vitest run
src/components/CompanyHomeRedirect.test.tsx`

## Risks

- Low risk. The change is test-only. The assertions are the same.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Claude Opus 5.5 (Anthropic), model ID `claude-opus-5-5`, used in
Claude Code with tool use (shell, file edits, GitHub CLI) and code
execution.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DottaandClaude Opus 5.5 authored and GitHub committed 2026-11-21 22:39:37 -06:00
1 parent 7e30ba2c45
commit 324ec1f537
1 file changed
+2 -2
@@ -58,8 +58,8 @@ describe("CompanyHomeRedirect", () => {
experimental.getExperimental.mockReturnValue(new Promise((done) => { resolve = done; })); experimental.getExperimental.mockReturnValue(new Promise((done) => { resolve = done; }));
const host = await render(<CompanyHomeRedirect />, false); const host = await render(<CompanyHomeRedirect />, false);
expect(host.querySelector('[data-testid="navigate"]')).toBeNull(); expect(host.querySelector('[data-testid="navigate"]')).toBeNull();
await act(async () => { resolve({ enableResponsibilities: true }); await new Promise((done) => setTimeout(done, 1)); }); await act(async () => { resolve({ enableResponsibilities: true }); });
expect(host.querySelector('[data-testid="navigate"]')?.getAttribute("data-to")).toBe("/responsibilities"); await vi.waitFor(() => expect(host.querySelector('[data-testid="navigate"]')?.getAttribute("data-to")).toBe("/responsibilities"));
}); });
}); });