Skip to content

fix(tests): flaky bound action tests - #8071

Merged
sid-bruno merged 32 commits into
usebruno:mainfrom
shubh-bruno:fix/shortcut-keys
Jun 22, 2026
Merged

sid-bruno merged 32 commits into
usebruno:mainfrom
shubh-bruno:fix/shortcut-keys

Conversation

@shubh-bruno

@shubh-bruno shubh-bruno commented May 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

JIRA-1 - create new request in folder
JIRA-2 - fix flaky shortcuts tests and make them run parallel without any data dependency to previous test

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • New Features

    • Added a context-aware New Request keyboard shortcut in the sidebar: when the focused row is a folder, it opens the New Request modal.
  • Behavior Changes

    • Updated hotkey handling so New Request is driven by the sidebar context rather than a global shortcut.
  • Tests

    • Expanded Playwright E2E coverage for remappable bound keyboard shortcuts across sidebar, search, requests, tabs, environments, developer tools, and preferences; added shared shortcut helpers and initial preference data, and removed an older bound-actions spec.

@coderabbitai

coderabbitai Bot commented May 22, 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

The newRequest keyboard shortcut is removed from the global HotkeysProvider and re-implemented as focus-scoped useKeybinding hooks inside Collection and CollectionItem (folder context only). The monolithic bound-actions.spec.ts Playwright file (2016 lines) is deleted and replaced with seven focused per-domain spec files backed by a new shared helpers.ts module.

Changes

New Request Hotkey Relocation

Layer / File(s) Summary
Collection and CollectionItem focus-scoped handlers
packages/bruno-app/src/providers/Hotkeys/index.js, packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js, packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
Global Mousetrap newRequest binding and cleanup removed from HotkeysProvider; useKeybinding('newRequest') added to Collection (opens modal when collection is focused) and to CollectionItem (opens modal when a folder row is focused).

Playwright Shortcut Test Refactor

Layer / File(s) Summary
Shared test helpers
tests/shortcuts/helpers.ts, tests/shortcuts/init-user-data/preferences.json
New module exporting platform modifier constants, setupBoundActionsData, remapKeybinding, openKeybindingsTab, closePreferencesTab, closeTabByName, openFolderSettingsTab, reopenClosedTab, and getTabIndex. Includes test preferences fixture with onboarding flags.
Collections & Environments shortcuts
tests/shortcuts/collections-env.spec.ts
Tests import collection, edit environment, and new request shortcuts (default and remapped) for both collection and folder contexts with remap and reset flows.
Sidebar actions shortcuts
tests/shortcuts/sidebar-actions.spec.ts
Tests sidebar search, new request, rename, clone, copy/paste, and sidebar collapse/expand shortcuts with default and remapped variants.
Tabs actions shortcuts
tests/shortcuts/tabs-actions.spec.ts
Tests close, close all, save, save all, switch, move left/right, switch-by-position, and reopen last closed tab shortcuts with default and remapped variants and draft-state assertions.
Request send & layout shortcuts
tests/shortcuts/reqeust-actions.spec.ts
Tests Cmd/Ctrl+Enter send from three editor contexts, remapped Shift+Enter, and layout-orientation toggle (default and remapped).
Global search shortcuts
tests/shortcuts/search-actions.spec.ts
Tests default Cmd/Ctrl+K and remapped Shift+K global search open/dismiss.
Developer tools shortcuts
tests/shortcuts/developer-tool.spec.ts
Tests default Cmd/Ctrl+T and remapped Alt+T terminal sessions at workspace and folder levels.
Preferences shortcuts
tests/shortcuts/other-actions.spec.ts
Tests default Cmd/Ctrl+Comma and remapped Cmd/Ctrl+P preferences open shortcuts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • usebruno/bruno#7603: Introduces the useKeybinding hook infrastructure that this PR relies on for focus-scoped newRequest handlers in sidebar components.
  • usebruno/bruno#7853: Updates the removed tests/shortcuts/bound-actions.spec.ts file with additional sendRequest keyboard shortcut context tests, indicating this PR's test split replaces that coverage.

Suggested reviewers

  • helloanoop
  • bijin-bruno
  • lohit-bruno
  • sid-bruno

Poem

🎹 The hotkey once roamed globally free,
Now it listens where the focus shall be.
The monolith test file, 2016 lines tall,
Split into seven, one spec for each call.
Focus the folder, press N — behold!
Context-aware shortcuts, clean and controlled. 🗂️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title "fix: flaky bound action tests" directly relates to the changeset, which refactors keyboard shortcut handling by moving newRequest logic from HotkeysProvider to CollectionItem/Collection components, and adds comprehensive Playwright test coverage for bound actions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

@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
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js`:
- Around line 130-133: Update the stale comment above the "Folder rows" block in
CollectionItem to remove the reference to a global override in HotkeysProvider
and instead state that the migration moved keyboard handling to scoped handlers;
keep the note that when the row has keyboard focus its handler mounts the New
Request modal with `item={item}` so new requests are created inside the folder
rather than at the collection root, and reword to reflect current ownership by
scoped handlers rather than a global binding path.
🪄 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: d22cf10e-c427-481a-9d3b-52df63a5109d

📥 Commits

Reviewing files that changed from the base of the PR and between 8cd7c26 and 0cb0b41.

📒 Files selected for processing (3)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js
  • packages/bruno-app/src/providers/Hotkeys/index.js
💤 Files with no reviewable changes (1)
  • packages/bruno-app/src/providers/Hotkeys/index.js

@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: 2

🤖 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 `@tests/shortcuts/collections-env.spec.ts`:
- Around line 145-147: The suite-level hook uses the test-scoped page fixture:
replace test.afterAll(async ({ page }) => await closeAllCollections(page)) with
an afterEach hook (or remove if cleanup is done elsewhere) so you no longer
access the per-test page in a suite-level hook; also change reopenClosedTab to
remove static waits (replace page.waitForTimeout(150/200) with
locator.waitFor()/page.waitForEvent()/expect(locator).toBeVisible() style waits)
to avoid flakiness, and deduplicate the duplicated "Edit Environment" scenario
by removing or consolidating the duplicate under the “customized Alt+E” describe
so each scenario appears only once (references: closeAllCollections,
reopenClosedTab, the two Describe blocks containing the Cmd/Ctrl+E and
customized Alt+E tests).

In `@tests/shortcuts/sidebar-actions.spec.ts`:
- Around line 257-266: The assertion mismatches the renamed value: after filling
requestNameInput with 'req-1-renamed' and clicking
getByTestId('rename-item-button'), update the
locator('.collection-item-name').filter({ hasText: ... }) check to look for
'req-1-renamed' (match the exact string used in requestNameInput) so the test
verifies the correct renamed label.
🪄 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: 1a44e4ab-7096-43df-9f8d-7fdce21dca11

📥 Commits

Reviewing files that changed from the base of the PR and between 03c205b and e4b5a83.

📒 Files selected for processing (8)
  • tests/shortcuts/bound-actions.spec.ts
  • tests/shortcuts/collections-env.spec.ts
  • tests/shortcuts/developer-tool.spec.ts
  • tests/shortcuts/other-actions.spec.ts
  • tests/shortcuts/reqeust-actions.spec.ts
  • tests/shortcuts/search-actions.spec.ts
  • tests/shortcuts/sidebar-actions.spec.ts
  • tests/shortcuts/tabs-actions.spec.ts
💤 Files with no reviewable changes (1)
  • tests/shortcuts/bound-actions.spec.ts

Comment thread tests/shortcuts/collections-env.spec.ts Resolved
Comment thread tests/shortcuts/sidebar-actions.spec.ts Resolved

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (8)
tests/shortcuts/search-actions.spec.ts (1)

32-34: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Assert that global search closes after Escape in both tests.

Escape is triggered, but the close behavior is not verified. This can let dismissal regressions pass.

Suggested patch
-        await page.keyboard.down('Escape');
-        await page.keyboard.up('Escape');
+        await page.keyboard.press('Escape');
+        await expect(page.getByTestId('global-search-input')).toBeHidden({ timeout: 2000 });
...
-        await page.keyboard.down('Escape');
-        await page.keyboard.up('Escape');
+        await page.keyboard.press('Escape');
+        await expect(page.getByTestId('global-search-input')).toBeHidden({ timeout: 2000 });

As per coding guidelines, "Use multiple assertions" and "E2E tests must verify user-visible behaviour, not implementation details."

Also applies to: 59-60

🤖 Prompt for 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.

In `@tests/shortcuts/search-actions.spec.ts` around lines 32 - 34, The tests call
page.keyboard.down('Escape') / page.keyboard.up('Escape') but never assert the
global search actually closed; after each Escape press (the occurrences around
page.keyboard.down('Escape') / page.keyboard.up('Escape')), add an assertion
that the global search UI is dismissed — e.g. verify the search dialog/overlay
locator used elsewhere in the spec is not visible or not present (use the same
locator/role the test suite uses for global search) so both instances (the one
at the first Escape and the second at lines ~59-60) explicitly assert the closed
state.
tests/shortcuts/other-actions.spec.ts (2)

41-55: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Customized shortcut test currently allows a false positive.

Line 41 opens Keybindings/Preferences first, then Line 54 asserts “Preferences” is visible, so this can pass even if the remapped shortcut never works. Validate from a non-Preferences context and assert before/after state around the shortcut trigger.

Suggested test-shape fix
-        await openKeybindingsTab(page);
+        await openKeybindingsTab(page);
         const row = page.getByTestId('keybinding-row-openPreferences');
         await row.hover();
         await page.getByTestId('keybinding-edit-openPreferences').click();
         await expect(page.getByTestId('keybinding-input-openPreferences')).toBeVisible({ timeout: 2000 });

-        await page.keyboard.down('Backspace');
+        await page.keyboard.press('Backspace');

         await page.keyboard.down(modifier);
         await page.keyboard.down('KeyP');
         await page.keyboard.up('KeyP');
         await page.keyboard.up(modifier);

-        await expect(page.locator('.request-tab').filter({ hasText: 'Preferences' })).toBeVisible({ timeout: 3000 });
+        // Move focus to a non-Preferences context, then verify shortcut opens Preferences.
+        await page.getByTestId('sidebar-collections').click();
+        await expect(page.getByTestId('tab-preferences')).not.toBeVisible();
+        await page.keyboard.press(`${modifier}+KeyP`);
+        await expect(page.getByTestId('tab-preferences')).toBeVisible({ timeout: 3000 });

As per coding guidelines, "Every E2E test should follow the Arrange-Act-Assert-Cleanup shape" and "Use multiple assertions".

🤖 Prompt for 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.

In `@tests/shortcuts/other-actions.spec.ts` around lines 41 - 55, The test
currently opens the Keybindings UI then triggers the remapped shortcut and
asserts that the Preferences tab is visible, which can give a false positive;
modify the test around openKeybindingsTab, keybinding-row-openPreferences,
keybinding-edit-openPreferences and keybinding-input-openPreferences so it first
navigates to a different context (e.g., ensure
page.locator('.request-tab').filter({ hasText: 'Preferences' }) is not visible),
then close the Keybindings panel or navigate away, trigger the shortcut via
page.keyboard.down/up (using modifier + KeyP) and finally assert the Preferences
tab is visible—also add an assertion that the tab was absent before the shortcut
to validate before/after state and optionally reset the keybinding as cleanup.

47-53: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix stuck Backspace key simulation in shortcut test

  • tests/shortcuts/other-actions.spec.ts line 47 uses await page.keyboard.down('Backspace'); without any matching keyboard.up('Backspace')/keyboard.press('Backspace'), so Backspace can remain held and make later key chords flaky. Replace with await page.keyboard.press('Backspace');.
🤖 Prompt for 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.

In `@tests/shortcuts/other-actions.spec.ts` around lines 47 - 53, Replace the
unmatched key-down call that can leave Backspace held: change the usage of
page.keyboard.down('Backspace') in the test (the call to
page.keyboard.down('Backspace')) to a one-shot key action by using
page.keyboard.press('Backspace') so the Backspace key is released immediately
and downstream modifier chords (the subsequent page.keyboard.down(modifier) /
page.keyboard.down('KeyP') sequence) won’t be affected.
tests/shortcuts/reqeust-actions.spec.ts (2)

148-148: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix sticky Backspace key handling in Playwright shortcut tests

tests/shortcuts/reqeust-actions.spec.ts presses Backspace with page.keyboard.down('Backspace') at lines 148, 197, 253, and 333, but never releases it (keyboard.up('Backspace') isn’t present), which can make shortcut-capture flaky. Replace with keyboard.press('Backspace').

✅ Suggested fix
-        await page.keyboard.down('Backspace');
+        await page.keyboard.press('Backspace');
🤖 Prompt for 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.

In `@tests/shortcuts/reqeust-actions.spec.ts` at line 148, In the Playwright
shortcut tests in reqeust-actions.spec.ts, replace each await
page.keyboard.down('Backspace') (found in the test cases around the occurrences
at lines where Backspace is used) with await page.keyboard.press('Backspace') so
the key is both pressed and released; this removes the missing
keyboard.up('Backspace') problem that can leave Backspace "stuck" and makes the
shortcut-capture deterministic.

18-20: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Fix Playwright hook fixture misuse: don’t use test-scoped page in test.afterAll.

tests/shortcuts/reqeust-actions.spec.ts (lines 18-20) uses test.afterAll(async ({ page }) => ...), but page is a test-scoped fixture; suite-level hooks should use afterEach (or a worker-scoped fixture) for cleanup.

Suggested fix
-  test.afterAll(async ({ page }) => {
+  test.afterEach(async ({ page }) => {
     await closeAllCollections(page);
   });
🤖 Prompt for 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.

In `@tests/shortcuts/reqeust-actions.spec.ts` around lines 18 - 20, Replace the
suite-level hook that incorrectly uses the test-scoped page fixture: change
test.afterAll(async ({ page }) => { await closeAllCollections(page); }); to a
test-scoped cleanup such as test.afterEach(async ({ page }) => { await
closeAllCollections(page); }); (or, alternatively, convert closeAllCollections
to use a worker-scoped fixture and call it from test.afterAll without the page
argument); update the hook name to test.afterEach and keep the call to
closeAllCollections(page) so the test-scoped page fixture is used correctly.
tests/shortcuts/developer-tool.spec.ts (2)

54-56: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Replace fixed sleeps with event-driven assertions in shortcut tests

  • tests/shortcuts/developer-tool.spec.ts lines 54-56 and 110-113: remove the page.waitForTimeout(1000) after clicking session-close-1; wait on the concrete UI transition (e.g., await expect(page.getByTestId('session-list-1')).not.toBeVisible({ timeout: 3000 });) before proceeding to click session-close-0.
  • lines 85-86: remove page.waitForTimeout(500); the following expect(page.getByTestId('session-list-0')).toBeVisible(...) already provides the event-driven wait.
🤖 Prompt for 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.

In `@tests/shortcuts/developer-tool.spec.ts` around lines 54 - 56, Replace
hard-coded sleep waits with event-driven assertions: remove the
page.waitForTimeout(1000) after clicking the 'session-close-1' button and
instead await the concrete UI transition by asserting that
getByTestId('session-list-1') is not visible (e.g., await
expect(page.getByTestId('session-list-1')).not.toBeVisible({ timeout: 3000 }))
before proceeding to click getByTestId('session-close-0'); likewise remove the
page.waitForTimeout(500) before checking getByTestId('session-list-0') since the
subsequent expect(page.getByTestId('session-list-0')).toBeVisible(...) already
performs the event-driven wait.

17-19: ⚠️ Potential issue | 🟠 Major

Fix page fixture usage in tests/shortcuts/developer-tool.spec.ts test.afterAll
page comes from the default (test-scoped) fixture in playwright/index.ts (no { scope: 'worker' }), so using { page } in test.afterAll for closeAllCollections(page) risks lifecycle/teardown ordering issues; move this cleanup to test.afterEach or introduce a worker-scoped fixture for the shared app/page if you truly need afterAll semantics.

🤖 Prompt for 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.

In `@tests/shortcuts/developer-tool.spec.ts` around lines 17 - 19, The teardown
uses the test-scoped Playwright page in test.afterAll which can cause lifecycle
issues; move the call to closeAllCollections(page) into test.afterEach so it
receives the default test-scoped page fixture, or alternatively create a
worker-scoped fixture in playwright/index.ts (e.g., a shared app/page) and use
that worker-scoped fixture in test.afterAll; update references to
closeAllCollections, test.afterAll, and test.afterEach accordingly so the
cleanup runs with the correct fixture scope.
tests/shortcuts/tabs-actions.spec.ts (1)

370-373: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Remove unrelated Alt+Y keypress at test end

Line 370-Line 373 dispatches Alt+Y in a save-all-tabs test without asserting its outcome. This introduces hidden state coupling and can create flaky behavior.

Suggested patch
-        await page.keyboard.down('Alt');
-        await page.keyboard.down('KeyY');
-        await page.keyboard.up('KeyY');
-        await page.keyboard.up('Alt');

As per coding guidelines, “Every E2E test should follow the Arrange-Act-Assert-Cleanup shape”.

🤖 Prompt for 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.

In `@tests/shortcuts/tabs-actions.spec.ts` around lines 370 - 373, In the
save-all-tabs test remove the stray Alt+Y keypress sequence
(page.keyboard.down/up for 'Alt' and 'KeyY') or replace it with an explicit
Arrange/Act/Assert/Cleanup action: either delete the four lines dispatching
'Alt'+'KeyY' or, if that key combo is required, assert its expected effect
(e.g., check UI/state) immediately after invoking it; locate the sequence by
searching for the page.keyboard.down('Alt') / page.keyboard.down('KeyY') /
page.keyboard.up('KeyY') / page.keyboard.up('Alt') calls and update accordingly
to eliminate hidden state coupling and flakiness.
♻️ Duplicate comments (2)
tests/shortcuts/collections-env.spec.ts (1)

19-21: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use afterEach (or remove this hook) instead of afterAll with page.

page is test-scoped; this suite-level teardown can fail or behave inconsistently.

Proposed fix
-  test.afterAll(async ({ page }) => {
+  test.afterEach(async ({ page }) => {
     await closeAllCollections(page);
   });
#!/bin/bash
rg -n "test\\.afterAll\\(async \\(\\{ page \\}\\)" tests/shortcuts/*.spec.ts

As per coding guidelines, "Follow best practices for Playwright code and e2e automation".

🤖 Prompt for 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.

In `@tests/shortcuts/collections-env.spec.ts` around lines 19 - 21, The teardown
is using test.afterAll with the test-scoped fixture page, which can be unstable;
change the suite-level hook to a per-test hook by replacing test.afterAll(async
({ page }) => closeAllCollections(page)); with test.afterEach(async ({ page })
=> closeAllCollections(page)); or remove the hook entirely if per-test cleanup
is not needed; ensure you update the hook name where test.afterAll is used and
keep the closeAllCollections(page) call intact so it runs with the page fixture.
tests/shortcuts/helpers.ts (1)

78-89: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Replace fixed sleeps in reopenClosedTab with event-driven waits.

The retry path uses hardcoded delays, which makes the shared helper flaky under variable CI timing.

Proposed fix
 export const reopenClosedTab = async (page: Page, shortcut: () => Promise<void>, expectedTabName: string | RegExp) => {
   for (let attempt = 0; attempt < 3; attempt++) {
     await page.locator('.request-tab').first().click();
-    await page.waitForTimeout(150);
     await shortcut();
     const reopenedTab = page.locator('.request-tab').filter({ hasText: expectedTabName });
-    if ((await reopenedTab.count()) > 0) {
-      await expect(reopenedTab).toBeVisible({ timeout: 3000 });
+    if (await reopenedTab.isVisible({ timeout: 1000 }).catch(() => false)) {
       return;
     }
-    await page.waitForTimeout(200);
   }
 
   await expect(page.locator('.request-tab').filter({ hasText: expectedTabName })).toBeVisible({ timeout: 5000 });
 };
#!/bin/bash
rg -n "waitForTimeout\\(" tests/shortcuts/helpers.ts

As per coding guidelines, "Try to reduce usage of page.waitForTimeout(); in code unless absolutely necessary and the locator cannot be found using existing expect() playwright calls".

🤖 Prompt for 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.

In `@tests/shortcuts/helpers.ts` around lines 78 - 89, The helper reopenClosedTab
currently relies on fixed waits (page.waitForTimeout) causing flakiness; replace
those sleeps with event-driven waits by waiting for the expected tab locator to
appear after triggering the shortcut. Specifically, in reopenClosedTab keep the
retry loop and calls to page.locator('.request-tab').first().click() and await
shortcut(), then replace the fixed delays with an explicit wait for the
reopenedTab (the locator filtered by hasText(expectedTabName)) using an
event-driven API such as reopenedTab.waitFor({ state: 'visible', timeout: 3000
}) or await expect(reopenedTab).toBeVisible({ timeout: 3000 }); remove the
page.waitForTimeout(150) and page.waitForTimeout(200) calls so the function
relies on the locator readiness instead of hardcoded sleeps.
🧹 Nitpick comments (5)
tests/shortcuts/search-actions.spec.ts (1)

23-61: ⚡ Quick win

Use test.step blocks and a shared locator variable per test flow.

Both tests are readable, but wrapping Arrange/Act/Assert in test.step and reusing a globalSearchInput locator will make reports clearer and reduce selector duplication as this suite grows.

Suggested pattern
       test('default Cmd/Ctrl+K Global Search Modal', async ({ page, createTmpDir }) => {
+        const globalSearchInput = page.getByTestId('global-search-input');
+
+        await test.step('Act: trigger global search shortcut', async () => {
+          await page.keyboard.down(modifier);
+          await page.keyboard.down('KeyK');
+          await page.keyboard.up('KeyK');
+          await page.keyboard.up(modifier);
+        });

-        await page.keyboard.down(modifier);
-        await page.keyboard.down('KeyK');
-        await page.keyboard.up('KeyK');
-        await page.keyboard.up(modifier);
-
-        await page.getByTestId('global-search-input').click();
-        await expect(page.getByTestId('global-search-input')).toBeVisible({ timeout: 2000 });
+        await test.step('Assert: search opens', async () => {
+          await globalSearchInput.click();
+          await expect(globalSearchInput).toBeVisible({ timeout: 2000 });
+        });

-        await page.keyboard.down('Escape');
-        await page.keyboard.up('Escape');
+        await test.step('Assert: search closes', async () => {
+          await page.keyboard.press('Escape');
+          await expect(globalSearchInput).toBeHidden({ timeout: 2000 });
+        });
       });

As per coding guidelines, "Promote the use of test.step as much as possible so the generated reports are easier to read", "Use locator variables for locators", and "Every E2E test should follow the Arrange-Act-Assert-Cleanup shape."

🤖 Prompt for 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.

In `@tests/shortcuts/search-actions.spec.ts` around lines 23 - 61, The two tests
("default Cmd/Ctrl+K Global Search Modal" and "customized Alt+K Global Search
Modal") should be refactored to use test.step blocks and a shared locator
variable to improve readability and reporting: declare a locator (e.g.,
globalSearchInput = page.getByTestId('global-search-input')) at the start of
each test, then wrap the Arrange, Act, Assert, and Cleanup portions in separate
test.step(...) calls (for example steps named "Arrange", "Act", "Assert",
"Cleanup") and replace direct page.getByTestId usages with the shared
globalSearchInput locator; also apply the same pattern when interacting with
keybinding elements (e.g., row, keybinding-edit-globalSearch,
keybinding-input-globalSearch) to reduce selector duplication and follow the
required AAA shape and reporting guidelines.
tests/shortcuts/other-actions.spec.ts (1)

1-58: ⚡ Quick win

Add semicolons to satisfy repository TS/JS style rules.

Statements in this file consistently omit semicolons, which violates the project style requirement.

As per coding guidelines, "Always add semicolons at the end of statements".

🤖 Prompt for 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.

In `@tests/shortcuts/other-actions.spec.ts` around lines 1 - 58, Add missing
semicolons across this test file to satisfy the TS/JS style rules: terminate all
import lines (import { test, expect } ..., import { closeAllCollections } ...,
import { modifier, setupBoundActionsData, openKeybindingsTab } ...), end
standalone await statements and expression statements with semicolons (e.g.,
await page.locator(...).waitFor(...);, await setupBoundActionsData(page,
createTmpDir);, await closeAllCollections(page);, all await page.keyboard.*
calls;), and ensure any other statement lines inside the test blocks (expect
assertions and variable declarations like const row = ...) also end with
semicolons so functions/identifiers such as setupBoundActionsData,
openKeybindingsTab, closeAllCollections, modifier, and row are all used in
semicolon-terminated statements.
tests/shortcuts/developer-tool.spec.ts (1)

25-26: ⚡ Quick win

Prefer stable selectors and locator variables for sidebar interactions.

Class+text selectors here are brittle for UI evolution. Please switch these actions to stable test-id/role-based locators and keep them in local locator variables.

As per coding guidelines, "Use locator variables for locators" and "Replace brittle text/index selectors with role, label, test id, or stable user-facing selectors."

Also applies to: 41-43, 77-79, 95-96

🤖 Prompt for 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.

In `@tests/shortcuts/developer-tool.spec.ts` around lines 25 - 26, Replace brittle
class+text selectors with stable role/test-id locators and store them in local
locator variables: create variables like collectionNameLocator =
page.getByTestId('collection-name') or page.getByRole('link', { name:
/kb-collection/i }) and requestTabLocator = page.getByTestId('request-tab') or
page.getByRole('tab', { name: /collection/i }); then use
collectionNameLocator.click() and await expect(requestTabLocator).toBeVisible({
timeout: 2000 }). Apply the same pattern for the other occurrences mentioned
(lines ~41-43, ~77-79, ~95-96) so all sidebar interactions use stable
test-id/role-based locators stored in local variables.
tests/shortcuts/tabs-actions.spec.ts (2)

1-729: ⚡ Quick win

Apply required semicolon style consistently

This file omits semicolons across statements, which violates repository TS/JS formatting rules. Please run the configured formatter/linter autofix for this file.

As per coding guidelines, “Always add semicolons at the end of statements”.

🤖 Prompt for 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.

In `@tests/shortcuts/tabs-actions.spec.ts` around lines 1 - 729, The file is
missing semicolons across many statements (imports and async calls) violating
the project's semicolon style; run the repository's formatter/linter autofix
(e.g., eslint --fix / Prettier) on the file and ensure semicolons are added
consistently at the end of statements such as the import lines, all const/let
declarations, and standalone awaits/expressions in functions like
setupBoundActionsData, openKeybindingsTab, remapKeybinding, openRequest,
closeTabByName, and reopenClosedTab; after autofix, run tests/lint to verify no
remaining style errors.

285-374: ⚡ Quick win

Use test.step for multi-phase shortcut flows

This scenario has distinct phases (remap, edit tabs, save, verify). Wrapping those phases in test.step will improve trace readability and failure triage.

As per coding guidelines, “Promote the use of test.step as much as possible so the generated reports are easier to read”.

🤖 Prompt for 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.

In `@tests/shortcuts/tabs-actions.spec.ts` around lines 285 - 374, This test
('Save all tabs customized (Alt+Shift+S)') performs multiple phases — wrap each
phase in await test.step(...) to improve report clarity: 1) the "remap
saveAllTabs" phase (calls using openKeybindingsTab, getByTestId edits and
keyboard inputs), 2) the "edit collection tab headers" phase (locating
collectionTab, clicking headers, editing nameEditor/valueEditor and asserting
draft icons), 3) the "edit folder tab headers" phase (opening kb-draft-folder,
editing folderNameEditor/folderValueEditor and asserting draft icons), and 4)
the "save and verify" phase (sending Alt+Shift+S and assertions that
has-changes-icon is gone for folderTab and collectionTab); wrap the existing
blocks in descriptive test.step calls (e.g., await test.step('Remap
saveAllTabs', async () => { ... })) keeping current awaits and helper calls
(openKeybindingsTab, closePreferencesTab) intact.
🤖 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.

Outside diff comments:
In `@tests/shortcuts/developer-tool.spec.ts`:
- Around line 54-56: Replace hard-coded sleep waits with event-driven
assertions: remove the page.waitForTimeout(1000) after clicking the
'session-close-1' button and instead await the concrete UI transition by
asserting that getByTestId('session-list-1') is not visible (e.g., await
expect(page.getByTestId('session-list-1')).not.toBeVisible({ timeout: 3000 }))
before proceeding to click getByTestId('session-close-0'); likewise remove the
page.waitForTimeout(500) before checking getByTestId('session-list-0') since the
subsequent expect(page.getByTestId('session-list-0')).toBeVisible(...) already
performs the event-driven wait.
- Around line 17-19: The teardown uses the test-scoped Playwright page in
test.afterAll which can cause lifecycle issues; move the call to
closeAllCollections(page) into test.afterEach so it receives the default
test-scoped page fixture, or alternatively create a worker-scoped fixture in
playwright/index.ts (e.g., a shared app/page) and use that worker-scoped fixture
in test.afterAll; update references to closeAllCollections, test.afterAll, and
test.afterEach accordingly so the cleanup runs with the correct fixture scope.

In `@tests/shortcuts/other-actions.spec.ts`:
- Around line 41-55: The test currently opens the Keybindings UI then triggers
the remapped shortcut and asserts that the Preferences tab is visible, which can
give a false positive; modify the test around openKeybindingsTab,
keybinding-row-openPreferences, keybinding-edit-openPreferences and
keybinding-input-openPreferences so it first navigates to a different context
(e.g., ensure page.locator('.request-tab').filter({ hasText: 'Preferences' }) is
not visible), then close the Keybindings panel or navigate away, trigger the
shortcut via page.keyboard.down/up (using modifier + KeyP) and finally assert
the Preferences tab is visible—also add an assertion that the tab was absent
before the shortcut to validate before/after state and optionally reset the
keybinding as cleanup.
- Around line 47-53: Replace the unmatched key-down call that can leave
Backspace held: change the usage of page.keyboard.down('Backspace') in the test
(the call to page.keyboard.down('Backspace')) to a one-shot key action by using
page.keyboard.press('Backspace') so the Backspace key is released immediately
and downstream modifier chords (the subsequent page.keyboard.down(modifier) /
page.keyboard.down('KeyP') sequence) won’t be affected.

In `@tests/shortcuts/reqeust-actions.spec.ts`:
- Line 148: In the Playwright shortcut tests in reqeust-actions.spec.ts, replace
each await page.keyboard.down('Backspace') (found in the test cases around the
occurrences at lines where Backspace is used) with await
page.keyboard.press('Backspace') so the key is both pressed and released; this
removes the missing keyboard.up('Backspace') problem that can leave Backspace
"stuck" and makes the shortcut-capture deterministic.
- Around line 18-20: Replace the suite-level hook that incorrectly uses the
test-scoped page fixture: change test.afterAll(async ({ page }) => { await
closeAllCollections(page); }); to a test-scoped cleanup such as
test.afterEach(async ({ page }) => { await closeAllCollections(page); }); (or,
alternatively, convert closeAllCollections to use a worker-scoped fixture and
call it from test.afterAll without the page argument); update the hook name to
test.afterEach and keep the call to closeAllCollections(page) so the test-scoped
page fixture is used correctly.

In `@tests/shortcuts/search-actions.spec.ts`:
- Around line 32-34: The tests call page.keyboard.down('Escape') /
page.keyboard.up('Escape') but never assert the global search actually closed;
after each Escape press (the occurrences around page.keyboard.down('Escape') /
page.keyboard.up('Escape')), add an assertion that the global search UI is
dismissed — e.g. verify the search dialog/overlay locator used elsewhere in the
spec is not visible or not present (use the same locator/role the test suite
uses for global search) so both instances (the one at the first Escape and the
second at lines ~59-60) explicitly assert the closed state.

In `@tests/shortcuts/tabs-actions.spec.ts`:
- Around line 370-373: In the save-all-tabs test remove the stray Alt+Y keypress
sequence (page.keyboard.down/up for 'Alt' and 'KeyY') or replace it with an
explicit Arrange/Act/Assert/Cleanup action: either delete the four lines
dispatching 'Alt'+'KeyY' or, if that key combo is required, assert its expected
effect (e.g., check UI/state) immediately after invoking it; locate the sequence
by searching for the page.keyboard.down('Alt') / page.keyboard.down('KeyY') /
page.keyboard.up('KeyY') / page.keyboard.up('Alt') calls and update accordingly
to eliminate hidden state coupling and flakiness.

---

Duplicate comments:
In `@tests/shortcuts/collections-env.spec.ts`:
- Around line 19-21: The teardown is using test.afterAll with the test-scoped
fixture page, which can be unstable; change the suite-level hook to a per-test
hook by replacing test.afterAll(async ({ page }) => closeAllCollections(page));
with test.afterEach(async ({ page }) => closeAllCollections(page)); or remove
the hook entirely if per-test cleanup is not needed; ensure you update the hook
name where test.afterAll is used and keep the closeAllCollections(page) call
intact so it runs with the page fixture.

In `@tests/shortcuts/helpers.ts`:
- Around line 78-89: The helper reopenClosedTab currently relies on fixed waits
(page.waitForTimeout) causing flakiness; replace those sleeps with event-driven
waits by waiting for the expected tab locator to appear after triggering the
shortcut. Specifically, in reopenClosedTab keep the retry loop and calls to
page.locator('.request-tab').first().click() and await shortcut(), then replace
the fixed delays with an explicit wait for the reopenedTab (the locator filtered
by hasText(expectedTabName)) using an event-driven API such as
reopenedTab.waitFor({ state: 'visible', timeout: 3000 }) or await
expect(reopenedTab).toBeVisible({ timeout: 3000 }); remove the
page.waitForTimeout(150) and page.waitForTimeout(200) calls so the function
relies on the locator readiness instead of hardcoded sleeps.

---

Nitpick comments:
In `@tests/shortcuts/developer-tool.spec.ts`:
- Around line 25-26: Replace brittle class+text selectors with stable
role/test-id locators and store them in local locator variables: create
variables like collectionNameLocator = page.getByTestId('collection-name') or
page.getByRole('link', { name: /kb-collection/i }) and requestTabLocator =
page.getByTestId('request-tab') or page.getByRole('tab', { name: /collection/i
}); then use collectionNameLocator.click() and await
expect(requestTabLocator).toBeVisible({ timeout: 2000 }). Apply the same pattern
for the other occurrences mentioned (lines ~41-43, ~77-79, ~95-96) so all
sidebar interactions use stable test-id/role-based locators stored in local
variables.

In `@tests/shortcuts/other-actions.spec.ts`:
- Around line 1-58: Add missing semicolons across this test file to satisfy the
TS/JS style rules: terminate all import lines (import { test, expect } ...,
import { closeAllCollections } ..., import { modifier, setupBoundActionsData,
openKeybindingsTab } ...), end standalone await statements and expression
statements with semicolons (e.g., await page.locator(...).waitFor(...);, await
setupBoundActionsData(page, createTmpDir);, await closeAllCollections(page);,
all await page.keyboard.* calls;), and ensure any other statement lines inside
the test blocks (expect assertions and variable declarations like const row =
...) also end with semicolons so functions/identifiers such as
setupBoundActionsData, openKeybindingsTab, closeAllCollections, modifier, and
row are all used in semicolon-terminated statements.

In `@tests/shortcuts/search-actions.spec.ts`:
- Around line 23-61: The two tests ("default Cmd/Ctrl+K Global Search Modal" and
"customized Alt+K Global Search Modal") should be refactored to use test.step
blocks and a shared locator variable to improve readability and reporting:
declare a locator (e.g., globalSearchInput =
page.getByTestId('global-search-input')) at the start of each test, then wrap
the Arrange, Act, Assert, and Cleanup portions in separate test.step(...) calls
(for example steps named "Arrange", "Act", "Assert", "Cleanup") and replace
direct page.getByTestId usages with the shared globalSearchInput locator; also
apply the same pattern when interacting with keybinding elements (e.g., row,
keybinding-edit-globalSearch, keybinding-input-globalSearch) to reduce selector
duplication and follow the required AAA shape and reporting guidelines.

In `@tests/shortcuts/tabs-actions.spec.ts`:
- Around line 1-729: The file is missing semicolons across many statements
(imports and async calls) violating the project's semicolon style; run the
repository's formatter/linter autofix (e.g., eslint --fix / Prettier) on the
file and ensure semicolons are added consistently at the end of statements such
as the import lines, all const/let declarations, and standalone
awaits/expressions in functions like setupBoundActionsData, openKeybindingsTab,
remapKeybinding, openRequest, closeTabByName, and reopenClosedTab; after
autofix, run tests/lint to verify no remaining style errors.
- Around line 285-374: This test ('Save all tabs customized (Alt+Shift+S)')
performs multiple phases — wrap each phase in await test.step(...) to improve
report clarity: 1) the "remap saveAllTabs" phase (calls using
openKeybindingsTab, getByTestId edits and keyboard inputs), 2) the "edit
collection tab headers" phase (locating collectionTab, clicking headers, editing
nameEditor/valueEditor and asserting draft icons), 3) the "edit folder tab
headers" phase (opening kb-draft-folder, editing
folderNameEditor/folderValueEditor and asserting draft icons), and 4) the "save
and verify" phase (sending Alt+Shift+S and assertions that has-changes-icon is
gone for folderTab and collectionTab); wrap the existing blocks in descriptive
test.step calls (e.g., await test.step('Remap saveAllTabs', async () => { ...
})) keeping current awaits and helper calls (openKeybindingsTab,
closePreferencesTab) intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e4bfc688-7ad9-419a-823d-d62c1cfd2fa9

📥 Commits

Reviewing files that changed from the base of the PR and between e4b5a83 and e0a6f3d.

📒 Files selected for processing (8)
  • tests/shortcuts/collections-env.spec.ts
  • tests/shortcuts/developer-tool.spec.ts
  • tests/shortcuts/helpers.ts
  • tests/shortcuts/other-actions.spec.ts
  • tests/shortcuts/reqeust-actions.spec.ts
  • tests/shortcuts/search-actions.spec.ts
  • tests/shortcuts/sidebar-actions.spec.ts
  • tests/shortcuts/tabs-actions.spec.ts

@shubh-bruno
shubh-bruno marked this pull request as draft May 26, 2026 10:24
@shubh-bruno
shubh-bruno marked this pull request as ready for review June 9, 2026 10:48
@shubh-bruno shubh-bruno changed the title fix: new request in folder fix: flaky bound action tests Jun 9, 2026

@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

🧹 Nitpick comments (1)
tests/shortcuts/tabs-actions.spec.ts (1)

35-35: ⚡ Quick win

Remove placeholder // ; comments across the spec.

These markers add non-functional noise and make this already large test file harder to review/maintain. Please remove them (or replace only with meaningful comments where context is actually needed).

As per coding guidelines, “No diffs unless an actual change is made…” and “Add in meaningful comments instead of obvious ones where complex code flow is explained properly.”

🤖 Prompt for 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.

In `@tests/shortcuts/tabs-actions.spec.ts` at line 35, Remove all placeholder `//
;` comments from the tabs-actions.spec.ts file as they add non-functional noise
and violate coding guidelines that require meaningful comments only. Search
through the entire spec file and delete these empty comment markers wherever
they appear, keeping only comments that provide actual context or explanation
for complex code flow.

Source: Coding guidelines

🤖 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 `@tests/shortcuts/search-actions.spec.ts`:
- Around line 42-52: The keyboard.down('Backspace') call on line 42 is never
paired with a corresponding keyboard.up('Backspace'), leaving the Backspace key
in a pressed state during the subsequent Shift+K keyboard sequences. Replace the
keyboard.down('Backspace') call with keyboard.press('Backspace') which
automatically handles both the down and up actions to properly release the key
state before the Shift+K sequences execute.

---

Nitpick comments:
In `@tests/shortcuts/tabs-actions.spec.ts`:
- Line 35: Remove all placeholder `// ;` comments from the tabs-actions.spec.ts
file as they add non-functional noise and violate coding guidelines that require
meaningful comments only. Search through the entire spec file and delete these
empty comment markers wherever they appear, keeping only comments that provide
actual context or explanation for complex code flow.
🪄 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: 2fa64214-9f8e-4766-9950-dc7c7ccd5547

📥 Commits

Reviewing files that changed from the base of the PR and between a21d2dd and ca281db.

📒 Files selected for processing (8)
  • tests/shortcuts/collections-env.spec.ts
  • tests/shortcuts/developer-tool.spec.ts
  • tests/shortcuts/helpers.ts
  • tests/shortcuts/other-actions.spec.ts
  • tests/shortcuts/reqeust-actions.spec.ts
  • tests/shortcuts/search-actions.spec.ts
  • tests/shortcuts/sidebar-actions.spec.ts
  • tests/shortcuts/tabs-actions.spec.ts
💤 Files with no reviewable changes (4)
  • tests/shortcuts/other-actions.spec.ts
  • tests/shortcuts/reqeust-actions.spec.ts
  • tests/shortcuts/developer-tool.spec.ts
  • tests/shortcuts/collections-env.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/shortcuts/helpers.ts
  • tests/shortcuts/sidebar-actions.spec.ts

Comment thread tests/shortcuts/search-actions.spec.ts Resolved
Comment thread tests/shortcuts/collections-env.spec.ts Resolved
Comment thread tests/shortcuts/helpers.ts Resolved
Comment thread tests/shortcuts/other-actions.spec.ts Resolved
@sid-bruno
sid-bruno merged commit 46498e8 into usebruno:main Jun 22, 2026
19 of 20 checks passed
@shubh-bruno shubh-bruno changed the title fix: flaky bound action tests fix(tests): flaky bound action tests Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants