Skip to content

fix(snapshot): folder nested script tab interactivity and tests - #8225

Merged
lohit-bruno merged 2 commits into
usebruno:mainfrom
sid-bruno:fix/folder-script-interactivity
Jun 12, 2026
Merged

lohit-bruno merged 2 commits into
usebruno:mainfrom
sid-bruno:fix/folder-script-interactivity

Conversation

@sid-bruno

@sid-bruno sid-bruno commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

Description

JIRA

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

Release Notes

  • Bug Fixes

    • Fixed folder and collection settings tabs to maintain proper state synchronization when switching between workspaces
    • Improved persistence of folder and collection settings tabs after app restart
    • Enhanced tab interactivity restoration for script panes (pre-request and post-response tabs)
  • Tests

    • Added comprehensive test coverage for tab behavior across workspace switches and app restarts
    • Improved test reliability with enhanced snapshot and UI interaction utilities

@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR fixes state synchronization for folder and collection settings tabs in the Bruno app. Core Redux reducer logic and tab selection now properly distinguish between parent folder UIDs and individual settings tab UIDs, with new snapshot-based tests validating that both folder and collection settings panes remain interactive across workspace switches and app restarts.

Changes

Settings Tab Persistence and Sync

Layer / File(s) Summary
Folder script tab selection and Redux sync
packages/bruno-app/src/components/FolderSettings/Script/index.js, packages/bruno-app/src/components/RequestTabs/RequestTab/index.js, packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
Folder script pane now matches focused tabs by UID or pathname and dispatches Redux actions using the derived tabUid. Request tabs UID-sync logic expanded to include folder-settings type. Tabs reducer updates folderUid alongside uid when syncing folder-settings tabs.
Snapshot and test action/locator utilities
tests/utils/snapshot.ts, tests/utils/page/actions.ts, tests/utils/page/locators.ts, tests/utils/page/index.ts
New snapshot module provides IO utilities, path resolution, and helpers to locate folder-settings and collection-settings tab entries in the UI state. Test actions and locators added for navigating folder/collection script panes and refocusing settings tabs.
Folder settings tab interactivity tests
tests/snapshots/folder.spec.ts
Refactored to use shared snapshot utilities. Added new test verifying folder script pane sub-tabs remain interactive after app restart. Workspace-switch and restart tests now use focusFolderSettingsTab helper.
Collection settings tab interactivity tests
tests/snapshots/collection.spec.ts
New test suite with three scenarios: workspace-switch interactivity, app restart persistence with snapshot validation, and script pane navigation after restart. Validates collection-settings tabs are marked permanent and restored correctly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • usebruno/bruno#8097: Addresses tab deserialization and defaults for folder-settings tabs to prevent state overrides during snapshot restore.
  • usebruno/bruno#6947: Redux persistence of the currently active script tab via updateScriptPaneTab, which this PR now correctly routes through derived tabUid.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno

Poem

📌 A tab by any path or UID,
Now syncs its state with clarity,
Through snapshots warm and tests so bright,
Folder and collection—both set right! 🎭

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix addressing folder nested script tab interactivity and the corresponding test additions.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

@sid-bruno
sid-bruno marked this pull request as ready for review June 10, 2026 13:03

@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

🧹 Nitpick comments (3)
tests/utils/snapshot.ts (1)

22-32: 💤 Low value

Consider more precise folder matching.

Line 27 uses t.pathname.includes(folderName), which will match partial strings. For example, "Folder" would match both "TestFolder" and "MyFolder", potentially returning the wrong tab in tests with similarly-named folders.

If the pathname format is predictable, consider using endsWith or a path-based comparison.

🤖 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/utils/snapshot.ts` around lines 22 - 32, findSnapshotFolderTab
currently uses t.pathname.includes(folderName) which matches substrings and can
return the wrong tab; update the pathname check in findSnapshotFolderTab to a
stricter comparison (for example use t.pathname.endsWith(folderName) or compare
the last path segment: t.pathname.split('/').pop() === folderName) so only exact
folder matches are returned while keeping the existing null/array guards.
tests/snapshots/collection.spec.ts (1)

32-32: ⚡ Quick win

Consider replacing hardcoded timeouts with event-driven waits.

Lines 32, 67, and 109 use page.waitForTimeout() with fixed 2-second delays. Per coding guidelines, prefer event-driven waits over magic timeouts.

If this timeout is necessary for background snapshot flushing, add a comment documenting the requirement and consider waiting for an observable state change instead.

Also applies to: 67-67, 109-109

🤖 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/snapshots/collection.spec.ts` at line 32, Replace the hardcoded delays
using page.waitForTimeout(2000) in the test file by waiting for an observable
event or state change instead: identify the operation that requires waiting
(e.g., snapshot flush/response/update) and use Playwright's event-driven waits
such as page.waitForResponse, page.waitForSelector, or page.waitForFunction to
detect completion; if the sleep is truly unavoidable, add a clear comment above
each page.waitForTimeout call explaining why the timeout is required (background
snapshot flushing) and consider creating a helper (e.g., waitForSnapshotFlush)
that polls the application state via page.evaluate or an API endpoint so tests
are deterministic.
tests/snapshots/folder.spec.ts (1)

33-33: ⚡ Quick win

Consider replacing hardcoded timeouts with event-driven waits.

Lines 33, 69, and 112 use page.waitForTimeout() with fixed delays. Per coding guidelines, these should be replaced with assertions or locator waits where possible.

If the timeout is needed for background state flushing, add a comment explaining why the specific duration is required.

Also applies to: 69-69, 112-112

🤖 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/snapshots/folder.spec.ts` at line 33, Replace the three instances of
the hardcoded await page.waitForTimeout(1000); in folder.spec.ts with
event-driven waits: use locator.waitFor(), page.waitForSelector(),
expect(locator).toHaveText()/toBeVisible(), or page.waitForResponse() that
matches the UI/network event you care about; if a fixed delay truly is required
for background flushing, keep the timeout but add a comment explaining why
1000ms is necessary and consider extracting it to a named constant (e.g.,
FLUSH_DELAY_MS) so intent is clear.
🤖 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/utils/snapshot.ts`:
- Line 34: The function findSnapshotCollectionTab currently declares
collectionPath as required but checks it as optional; change the signature to
make collectionPath optional (collectionPath?: string) so the type matches the
runtime check in findSnapshotCollectionTab, and update any callers if they
relied on it being required or add non-null assertions where callers must pass a
string.
- Around line 12-16: The readSnapshot function currently calls JSON.parse on
fs.readFileSync which will throw on malformed ui-state-snapshot.json; update
readSnapshot (and keep getSnapshotPath usage) to wrap the fs.readFileSync +
JSON.parse in a try-catch, and on parse errors return null (or rethrow a new
Error with a descriptive message), ensuring malformed snapshot files do not
crash tests and that the error path is clear.

---

Nitpick comments:
In `@tests/snapshots/collection.spec.ts`:
- Line 32: Replace the hardcoded delays using page.waitForTimeout(2000) in the
test file by waiting for an observable event or state change instead: identify
the operation that requires waiting (e.g., snapshot flush/response/update) and
use Playwright's event-driven waits such as page.waitForResponse,
page.waitForSelector, or page.waitForFunction to detect completion; if the sleep
is truly unavoidable, add a clear comment above each page.waitForTimeout call
explaining why the timeout is required (background snapshot flushing) and
consider creating a helper (e.g., waitForSnapshotFlush) that polls the
application state via page.evaluate or an API endpoint so tests are
deterministic.

In `@tests/snapshots/folder.spec.ts`:
- Line 33: Replace the three instances of the hardcoded await
page.waitForTimeout(1000); in folder.spec.ts with event-driven waits: use
locator.waitFor(), page.waitForSelector(),
expect(locator).toHaveText()/toBeVisible(), or page.waitForResponse() that
matches the UI/network event you care about; if a fixed delay truly is required
for background flushing, keep the timeout but add a comment explaining why
1000ms is necessary and consider extracting it to a named constant (e.g.,
FLUSH_DELAY_MS) so intent is clear.

In `@tests/utils/snapshot.ts`:
- Around line 22-32: findSnapshotFolderTab currently uses
t.pathname.includes(folderName) which matches substrings and can return the
wrong tab; update the pathname check in findSnapshotFolderTab to a stricter
comparison (for example use t.pathname.endsWith(folderName) or compare the last
path segment: t.pathname.split('/').pop() === folderName) so only exact folder
matches are returned while keeping the existing null/array guards.
🪄 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: a42ba347-ce61-45e4-aad6-841bb0021c7a

📥 Commits

Reviewing files that changed from the base of the PR and between 6791e0a and 4706de8.

📒 Files selected for processing (9)
  • packages/bruno-app/src/components/FolderSettings/Script/index.js
  • packages/bruno-app/src/components/RequestTabs/RequestTab/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
  • tests/snapshots/collection.spec.ts
  • tests/snapshots/folder.spec.ts
  • tests/utils/page/actions.ts
  • tests/utils/page/index.ts
  • tests/utils/page/locators.ts
  • tests/utils/snapshot.ts

Comment thread tests/utils/snapshot.ts Resolved
Comment thread tests/utils/snapshot.ts Resolved
vijayh-bruno

This comment was marked as spam.

@vijayh-bruno

Copy link
Copy Markdown
Collaborator

Did local testing, ran folder specific tests. LGTM!

@lohit-bruno can you take final look and merge if no concerns?

@lohit-bruno
lohit-bruno merged commit 0d73e38 into usebruno:main Jun 12, 2026
19 of 20 checks passed
lohit-bruno pushed a commit that referenced this pull request Jun 15, 2026
* fix(snapshot): folder script interactivity

* fix: add tests for collection scripts
abhishekp-bruno pushed a commit to abhishekp-bruno/bruno that referenced this pull request Jun 17, 2026
…runo#8225)

* fix(snapshot): folder script interactivity

* fix: add tests for collection scripts
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