Skip to content

test(e2e): workspace auth refresh races — cloud E2E coverage - #12940

Merged
christian-byrne merged 12 commits into
mainfrom
e2e/workspace-auth-refresh-races
Aug 9, 2026
Merged

christian-byrne merged 12 commits into
mainfrom
e2e/workspace-auth-refresh-races

Conversation

@christian-byrne

@christian-byrne christian-byrne commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds browser_tests/tests/workspaceAuthRefresh.spec.ts with 4 @cloud-tagged Playwright tests covering the workspace auth refresh race conditions fixed in fix: guard workspace auth refresh races #11726.
  • Tests use route mocking only — no dynamic store imports, no waitForTimeout.
Test What it verifies
token is persisted to sessionStorage after switching workspace switchWorkspace writes token + expiry to sessionStorage
switching to a different workspace replaces sessionStorage token second switch overwrites the first workspace's token
transient token refresh failure preserves the active workspace session 500 from /api/auth/token must not clear Comfy.Workspace.Token
permanent auth failure (ACCESS_DENIED) clears the workspace session 403 from /api/auth/token must null out token + workspace

The timer-based refresh is triggered by setting expiresInMs just below TOKEN_REFRESH_BUFFER_MS (5 min − 500 ms), causing scheduleTokenRefresh to fire with delay ≈ 0 — no fake timers needed.

Test plan

  • CI @cloud Playwright job passes all 4 tests
  • pnpm typecheck:browser — clean
  • pnpm exec eslint + pnpm exec oxlint — clean

Followup to #11726.

🤖 Generated with Claude Code


🔀 Rebase & handoff status (2026-07-13)

Status: APPROVED + green months ago → rotted on main (merge-skew) → now rebased onto current main → ready to merge.

  • Rebased onto current main; refreshed a stale CLA.

  • Note: one flaky templates.spec.ts shard is UNRELATED to this PR (209 tests passed in that shard). A CI re-run clears it.

  • Rebased onto current main

  • Stale CLA refreshed

  • Re-run CI to clear the unrelated templates.spec.ts flake

  • Ready to merge — assigned to @christian-byrne

@christian-byrne
christian-byrne requested a review from a team June 18, 2026 01:53
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 18, 2026
@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds workspaceAuthRefresh.spec.ts, a new Playwright browser test suite tagged @cloud. It defines mock workspaces and a token response helper, extends comfyPageFixture with route intercepts for /api/features and /api/workspaces, and implements four tests covering token persistence on workspace switching and sessionStorage state after transient (HTTP 500) and permanent (HTTP 403) token refresh failures.

Changes

Workspace Auth Refresh Browser Tests

Layer / File(s) Summary
Test setup: mocks, fixtures, and helpers
browser_tests/tests/workspaceAuthRefresh.spec.ts
Imports Playwright and shared fixtures, defines mock remote config with team_workspaces_enabled: true, creates personal and team workspace objects, implements makeTokenResponse helper that constructs WorkspaceTokenResponse objects with computed expiry timestamps, extends comfyPageFixture to intercept /api/features and /api/workspaces endpoints, and adds openSwitcherPanel helper to access the workspace switcher UI.
Workspace token persistence on switch
browser_tests/tests/workspaceAuthRefresh.spec.ts
First test selects Team Workspace and asserts Comfy.Workspace.Token and Comfy.Workspace.ExpiresAt are written to sessionStorage with expiry in the future. Second test switches from Team Workspace to Personal Workspace and asserts the stored token changes to the personal token and Comfy.Workspace.Current reflects the personal workspace id.
Token refresh failure handling
browser_tests/tests/workspaceAuthRefresh.spec.ts
Third test creates a near-expiry token to trigger immediate refresh, mocks the refresh endpoint to return HTTP 500, and asserts the original token persists in sessionStorage. Fourth test triggers refresh with a near-expiry token, mocks HTTP 403 response, and asserts Comfy.Workspace.Token is cleared and Comfy.Workspace.Current becomes null.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Comfy-Org/ComfyUI_frontend#11726: This PR's new Playwright tests exercise the same workspace auth token/sessionStorage persistence and refresh-failure state transitions that the referenced PR implements in workspaceAuthStore (e.g., token switching and refresh error handling).

Suggested labels

`size:S`, `cloud/1.45`, `cloud/1.46`

Poem

🐇 Hoppy little tokens, stored with care,
In sessionStorage, fresh beyond compare.
When 500 strikes, the old key stays tight,
But 403 clears it—poof! Out of sight.
I mock the routes and watch the tests run,
Auth refresh verified—my work here is done! ✨

🚥 Pre-merge checks | ✅ 6 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding E2E tests for workspace auth refresh race conditions with cloud tag coverage.
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.
End-To-End Regression Coverage For Fixes ✅ Passed PR only adds regression tests under browser_tests/ with no changes to src/ or packages/, so E2E test requirement does not apply.
Adr Compliance For Entity/Litegraph Changes ✅ Passed PR modifies only browser_tests/tests/workspaceAuthRefresh.spec.ts, which is outside all ADR-relevant paths (src/lib/litegraph/, src/ecs/, graph entities). Check does not apply.
Description check ✅ Passed The description clearly explains the change, rationale, and test plan, covering the core information despite not matching the template exactly.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch e2e/workspace-auth-refresh-races

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright: ✅ 1723 passed, 0 failed · 2 flaky

📊 Browser Reports
  • chromium: View Report (✅ 1702 / ❌ 0 / ⚠️ 2 / ⏭️ 5)
  • chromium-2x: View Report (✅ 2 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • chromium-0.5x: View Report (✅ 1 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • mobile-chrome: View Report (✅ 18 / ❌ 0 / ⚠️ 0 / ⏭️ 0)

📦 Bundle: 8.03 MB gzip ⚪ 0 B

Details

Summary

  • Raw size: 33.7 MB baseline 33.7 MB — ⚪ 0 B
  • Gzip: 8.03 MB baseline 8.03 MB — ⚪ 0 B
  • Brotli: 5.55 MB baseline 5.55 MB — ⚪ 0 B
  • Bundles: 416 current • 416 baseline

Category Glance
Vendor & Third-Party ⚪ 0 B (15.7 MB) · Other ⚪ 0 B (12.1 MB) · Utilities & Hooks ⚪ 0 B (3.45 MB) · Graph Workspace ⚪ 0 B (1.25 MB) · Panels & Settings ⚪ 0 B (551 kB) · Data & Services ⚪ 0 B (271 kB) · + 5 more

App Entry Points — 47.5 kB (baseline 47.5 kB) • ⚪ 0 B

Main entry bundles and manifests

Status: 1 unchanged

Graph Workspace — 1.25 MB (baseline 1.25 MB) • ⚪ 0 B

Graph editor runtime, canvas, workflow orchestration

Status: 2 unchanged

Views & Navigation — 112 kB (baseline 112 kB) • ⚪ 0 B

Top-level views, pages, and routed surfaces

Status: 16 unchanged

Panels & Settings — 551 kB (baseline 551 kB) • ⚪ 0 B

Configuration panels, inspectors, and settings screens

Status: 26 unchanged

User & Accounts — 29.1 kB (baseline 29.1 kB) • ⚪ 0 B

Authentication, profile, and account management bundles

Status: 10 unchanged

Editors & Dialogs — 121 kB (baseline 121 kB) • ⚪ 0 B

Modals, dialogs, drawers, and in-app editors

Status: 6 unchanged

UI Components — 64.7 kB (baseline 64.7 kB) • ⚪ 0 B

Reusable component library chunks

Status: 14 unchanged

Data & Services — 271 kB (baseline 271 kB) • ⚪ 0 B

Stores, services, APIs, and repositories

Status: 16 unchanged

Utilities & Hooks — 3.45 MB (baseline 3.45 MB) • ⚪ 0 B

Helpers, composables, and utility bundles

Status: 36 unchanged

Vendor & Third-Party — 15.7 MB (baseline 15.7 MB) • ⚪ 0 B

External libraries and shared vendor chunks

Status: 16 unchanged

Other — 12.1 MB (baseline 12.1 MB) • ⚪ 0 B

Bundles that do not match a named category

Status: 273 unchanged

⚡ Performance

⏳ Performance tests in progress…

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@browser_tests/tests/workspaceAuthRefresh.spec.ts`:
- Around line 186-190: The exact equality check in the await expect.poll
assertion on callCount is brittle and causes race conditions where refresh
retries might increment callCount beyond 2 before the poll samples the value,
creating nondeterministic test failures. Replace the `.toBe(2)` assertion with
`.toBeGreaterThanOrEqual(2)` to allow the test to pass with callCount 2 or
higher, or instead assert an external state condition (such as verifying the
token is preserved or the session state) that validates the actual behavior
being tested rather than checking an exact timing snapshot.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a2d9466b-831d-4923-8792-a1b8e74244ad

📥 Commits

Reviewing files that changed from the base of the PR and between 0a4021d and d67f251.

📒 Files selected for processing (1)
  • browser_tests/tests/workspaceAuthRefresh.spec.ts

@codecov

codecov Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##             main   #12940      +/-   ##
==========================================
- Coverage   78.92%   78.84%   -0.08%     
==========================================
  Files        1692     1692              
  Lines       95679    95890     +211     
  Branches    29601    29568      -33     
==========================================
+ Hits        75513    75609      +96     
- Misses      19779    19891     +112     
- Partials      387      390       +3     
Flag Coverage Δ
unit 67.93% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vercel

vercel Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
comfyui-frontend-node-search-preview Error Error Jun 18, 2026 9:59pm

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 18, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 18, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 19, 2026
dante01yoon
dante01yoon previously approved these changes Jun 20, 2026
christian-byrne added a commit that referenced this pull request Jun 24, 2026
christian-byrne added a commit that referenced this pull request Jun 24, 2026
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jun 24, 2026
dante01yoon
dante01yoon previously approved these changes Jun 26, 2026
christian-byrne added a commit that referenced this pull request Jul 14, 2026
christian-byrne added a commit that referenced this pull request Jul 14, 2026
@christian-byrne
christian-byrne force-pushed the e2e/workspace-auth-refresh-races branch from 8917704 to a4ddb3f Compare July 14, 2026 02:18
christian-byrne and others added 11 commits July 23, 2026 00:58
Covers token persistence, workspace-switch replacement, transient 500
preservation, and 403 ACCESS_DENIED session clearing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ertions

- Add two-step open: profile popover → workspace-switcher-trigger → workspace item
  (clicking the trigger div opens the panel; only clicking an item calls switchWorkspace)
- Replace bare expect() after click with expect.poll() to wait for async switchWorkspace
- Import Page type from @playwright/test instead of inline import()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…licit switches

teamWorkspaceStore.initialize() auto-selects Personal Workspace on boot and
calls switchWorkspace → /api/auth/token. useWorkspaceSwitch skips switchWorkspace
when the target is already active, so clicking Personal Workspace in the panel
after init is a no-op.

Fix:
- Add default /api/auth/token stub in the fixture to absorb the init call
- Switch to Team Workspace in tests (not the auto-selected Personal one) so
  the explicit click is always a genuine workspace change
- Per-test route mocks are matched LIFO and override the fixture default

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add Escape before re-opening profile popover to avoid toggle-close on
  double-click, and wait for workspace-switcher-panel to be visible before
  clicking an item (prevents stale-panel click timeouts)
- Remove intermediate 'original-token' assertion in ACCESS_DENIED test:
  the refresh timer fires at delay≈0 so the token is cleared before the
  poll can observe it — wait for callCount=2 instead then assert null

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…us matches

getByText() without scoping could match the trigger row label or other
text on the page. Scope all workspace name clicks to
getByTestId('workspace-switcher-panel') to ensure only the list item
button is targeted.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e reloads

teamWorkspaceStore.switchWorkspace() calls window.location.reload() after
clearing context. The second switch in the back-and-forth test never lands
because the page reloads and re-runs init with the fixture-default token mock.
Single-switch token persistence is already covered by the first test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@christian-byrne
christian-byrne force-pushed the e2e/workspace-auth-refresh-races branch from a4ddb3f to a31be1b Compare July 23, 2026 00:58
@christian-byrne

Copy link
Copy Markdown
Contributor Author

🔀 Rebase & handoff status (2026-07-23)

Status: Rebased onto current `main` (was 88 commits behind), ready for final CI pass and merge.

Checklist:

  • Rebased onto current `main`
  • `playwright-tests (cloud)` passed on previous CI run
  • Waiting for CI to pass on new push (re-run to clear templates flake if it recurs)
  • APPROVED by @dante01yoon
  • Ready to merge

useSessionCookie (introduced in #13832) calls /api/auth/session during
workspace auth init. Without the stub the cloud test env hangs waiting
for the real endpoint, causing workspace-switcher-trigger to never
become clickable.

Mirrors the same stub already present in workspaceSwitcher.spec.ts.
@christian-byrne
christian-byrne merged commit e544b2a into main Aug 9, 2026
59 checks passed
@christian-byrne
christian-byrne deleted the e2e/workspace-auth-refresh-races branch August 9, 2026 01:43
@christian-byrne

Copy link
Copy Markdown
Contributor Author

This PR's browser_tests/fixtures/data/workspaceAuthFixtures.ts is breaking
typecheck:browser on main:

workspaceAuthFixtures.ts(6,3): error TS2353: Object literal may only specify
known properties, and 'team_workspaces_enabled' does not exist in type
'RemoteConfig'.

Consequence is bigger than one failing job: the merge queue re-runs CI: Lint
Format
against the queue branch, so every PR in the repo is being dequeued
instead of merged
. Fix is up in #14959.

One thing worth your eye rather than mine, since it's your feature: I removed
the key rather than adding it to RemoteConfig, because it appears exactly once
in the repo (that line), nothing in src/ reads it, and team workspaces are
gated on the workspace's own type rather than a remote flag — so the fixture
was enabling nothing.

If you intended to gate on a server flag and the frontend side of it simply
isn't written yet, then #14959 is the right unblock but you have a real gap: the
e2e helper reads as though it turns team workspaces on, and it doesn't.

mattmillerai added a commit that referenced this pull request Aug 9, 2026
- Select the nudge and its controls by role/accessible name instead of
  data-testid, and assert cooldown with toBeDisabled().
- Drop the @/i18n mock so the composable tests exercise real translation
  key resolution.
- Run the shared composable inside an effectScope stopped after each test
  so its window focus listener does not leak across tests.
- Use fake timers for the whole resend suite and clear pending timers on
  teardown.
- Cover the focus-triggered refresh after dismissal and the concurrent
  refresh guard.
- Cover emailVerificationNudgeEnabled resolution in useFeatureFlags.

Also drop the retired team_workspaces_enabled key from the workspace auth
E2E fixture: #14613 removed it from RemoteConfig after #12940 was written,
so typecheck:browser fails on main and on every PR that merges it.
christian-byrne added a commit that referenced this pull request Aug 9, 2026
## The merge queue is down repo-wide

`typecheck:browser` fails on `main`:

```
browser_tests/fixtures/data/workspaceAuthFixtures.ts(6,3): error TS2353:
Object literal may only specify known properties, and
'team_workspaces_enabled' does not exist in type 'RemoteConfig'.
```

Because the merge queue re-runs **CI: Lint Format** against the queue
branch,
this fails there too — so PRs are being **added to the queue and then
dequeued
without merging**, whatever their own CI said. Two of mine were dequeued
this
way in the last hour (#14691 at 02:59Z, #14669 at 03:05Z), and four
unrelated
branches hit the sibling `validate-pins` breakage in the same window.

Introduced by #12940 (`e544b2ad90`), merged ~4 hours ago.

## Why removing the key is the right fix

`team_workspaces_enabled` appears **exactly once in the entire
repository** —
this line. No `src/` code reads it. Team workspaces are gated on the
workspace's own `type` (`'personal' | 'team'`), not on a remote-config
flag,
and there is no corresponding entry in `useFeatureFlags`. The fixture
was
enabling nothing, so `{}` is behaviour-identical.

The alternative — adding the key to `RemoteConfig` — would invent
frontend API
surface that nothing consumes.

## Verification

Matched control, same machine, same install:

| tree | `pnpm run typecheck:browser` |
| ---- | --- |
| `origin/main` | **exit 2**, the error above |
| this branch | **exit 0** |

`pnpm run format:check` clean.

## Relationship to #14955

#14955 contains this same one-line fix, but bundled with an unrelated
litegraph
subgraph-serialization change. That change looks sound to me, but it
deserves
review on its own merits by someone who owns litegraph — and the queue
outage
shouldn't wait on it. This PR is the fixture fix alone so it can land
immediately. Whichever merges first, the other's hunk drops out
trivially.

Co-authored-by: t <t@t.t>
mattmillerai added a commit that referenced this pull request Aug 28, 2026
- Select the nudge and its controls by role/accessible name instead of
  data-testid, and assert cooldown with toBeDisabled().
- Drop the @/i18n mock so the composable tests exercise real translation
  key resolution.
- Run the shared composable inside an effectScope stopped after each test
  so its window focus listener does not leak across tests.
- Use fake timers for the whole resend suite and clear pending timers on
  teardown.
- Cover the focus-triggered refresh after dismissal and the concurrent
  refresh guard.
- Cover emailVerificationNudgeEnabled resolution in useFeatureFlags.

Also drop the retired team_workspaces_enabled key from the workspace auth
E2E fixture: #14613 removed it from RemoteConfig after #12940 was written,
so typecheck:browser fails on main and on every PR that merges it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants