Skip to content

fix(size/L): Preserve folder order from seq attribute - #8213

Merged
sid-bruno merged 4 commits into
usebruno:mainfrom
sachin-bruno:sachin-bruno/fix-preserve-folder-order
Jun 10, 2026
Merged

sid-bruno merged 4 commits into
usebruno:mainfrom
sachin-bruno:sachin-bruno/fix-preserve-folder-order

Conversation

@sachin-bruno

@sachin-bruno sachin-bruno commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

A user organizes their Bruno collection with folders ordered using the seq attribute. When they run "Generate Docs", they expect the HTML output to reflect that order. Today the order is non-deterministic — each regeneration produces a different folder order in the rendered output and in the JSON blob embedded in the HTML.

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

  • Bug Fixes

    • Generated documentation now maintains the same item ordering as displayed in the sidebar, ensuring consistency between UI and exported documentation.
  • Tests

    • Added comprehensive test suite for documentation generation ordering.
    • Added end-to-end tests verifying documentation matches sidebar organization.
  • Chores

    • Updated dependencies to support enhanced documentation generation.
image

@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a294e5dd-b32a-466e-94d3-f4ecf3a6ef56

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR adds sidebar-aware item ordering to documentation generation. A new sortItemsBySidebarOrder utility preserves the UI's folder and request sequencing when exporting docs. Unit tests cover the sorting logic; E2E tests with fixtures verify generated documentation matches both the sidebar tree and the embedded order payload.

Changes

Documentation generation item ordering

Layer / File(s) Summary
Core sorting utility and dependencies
package.json, packages/bruno-app/src/utils/collections/index.js
Adds @types/js-yaml dev dependency and exports sortItemsBySidebarOrder(items), which recursively filters transient items, groups folders before requests (sorted by name then seq), orders requests by seq, and applies the same rules to nested items.
Export integration with sorting
packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/index.js
Imports and applies sortItemsBySidebarOrder to reorder the cloned collection immediately before export, ensuring generated documentation reflects the sidebar tree structure.
Unit tests for sorting utility
packages/bruno-app/src/utils/common/sort-items-by-sidebar-order.spec.js
Jest test suite validates folder-first grouping, seq-based ordering within folders and requests, recursive nesting, filtering of isTransient items, input immutability, and empty-input handling.
E2E test helpers and locators
tests/utils/page/actions.ts, tests/utils/page/locators.ts
Adds generateCollectionDocs helper that waits for collection mount, opens the Generate Docs menu, intercepts the generated Blob and filename via renderer-side hooks, and returns { content, fileName }; adds Playwright locators for the Generate Docs modal and buttons.
E2E test collection fixtures and initialization
tests/collection/generate-docs/fixtures/collection/*, tests/collection/generate-docs/init-user-data/preferences.json
Defines a test collection (GenerateDocsOrder) with Zoo and Aviary folders, each with ordered requests (ReqBeta, ReqAlpha at root; Lion, Bear; Parrot respectively); initializes user preferences.
End-to-end test specifications
tests/collection/generate-docs/generate-docs.spec.ts
Playwright tests that define the expected document order (EXPECTED_ORDER), parse embedded collectionData YAML from generated HTML, reduce both generated and live sidebar data into NameTree form, and assert all match; also verifies Generate Documentation modal UI flow.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant GenerateDocs as Generate Docs Handler
  participant Utility as sortItemsBySidebarOrder
  participant CollectionCopy as Cloned Collection
  participant ExportFlow as Export/Serialize
  
  User->>GenerateDocs: Click "Generate Documentation"
  GenerateDocs->>CollectionCopy: Deep clone collection
  GenerateDocs->>Utility: Sort items
  Utility->>Utility: Filter transient
  Utility->>Utility: Separate folders/requests
  Utility->>Utility: Sort each group
  Utility->>Utility: Recurse nested items
  Utility->>CollectionCopy: Return sorted structure
  GenerateDocs->>ExportFlow: Export sorted collection
  ExportFlow->>ExportFlow: Serialize to HTML
  ExportFlow->>User: Download documentation
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • usebruno/bruno#6583: Introduces the GenerateDocumentation component that this PR extends with sidebar-order preservation logic.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • bijin-bruno
  • naman-bruno

Poem

📚 Docs now flow in sidebar's song,
Each folder, request in perfect place—
The order's right, the tree's long,
Generation meets the UI's face. ✨

🚥 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 PR title clearly and concisely describes the main fix: preserving folder order based on the seq attribute during documentation generation.
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: 2

🧹 Nitpick comments (1)
packages/bruno-app/src/utils/common/sort-items-by-sidebar-order.spec.js (1)

1-2: ⚡ Quick win

Test file location doesn't match function location.

The test file is at packages/bruno-app/src/utils/common/sort-items-by-sidebar-order.spec.js but the function under test is in packages/bruno-app/src/utils/collections/index.js.

Consider moving this test file to packages/bruno-app/src/utils/collections/sort-items-by-sidebar-order.spec.js to co-locate it with the function being tested, improving discoverability and maintainability.

🤖 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 `@packages/bruno-app/src/utils/common/sort-items-by-sidebar-order.spec.js`
around lines 1 - 2, Move the spec to live next to the implementation: relocate
the test file named sort-items-by-sidebar-order.spec.js into the same folder
containing the collections index module so it directly tests
sortItemsBySidebarOrder; update its require/import to reference ../index (or the
local module) if necessary and run tests to ensure paths resolve correctly.
🤖 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/utils/collections/index.js`:
- Around line 891-905: The JSDoc claims code/data files are preserved but
sortItemsBySidebarOrder currently only keeps folders and requests (using
sortByNameThenSequence, isItemAFolder, isItemARequest) and drops other item
types; update the function to collect "other" items (those not matching
isItemAFolder and not matching isItemARequest), preserve their original order,
and include them after requestItems when building the returned array (still
recursively sorting folder.items via sortItemsBySidebarOrder), or alternatively
update the JSDoc to reflect that only folders and requests are preserved — pick
the behavior you want and make the code or JSDoc consistent with
sortItemsBySidebarOrder.

In `@tests/collection/generate-docs/generate-docs.spec.ts`:
- Around line 55-66: The test fallback uses new Function(...) when
JSON.parse(literal) fails because jsesc emitted JS-only escapes; instead
configure jsesc in GenerateDocumentation/index.js to produce JSON-compatible
output (e.g., enable the json option / disable JS-only escapes) so the literal
is always valid JSON, then remove the catch fallback in generate-docs.spec.ts
(the literal / yamlContent flow) and rely solely on JSON.parse; if you cannot
guarantee JSON-compatible output, add a brief comment in generate-docs.spec.ts
explaining why using new Function is safe in this controlled test context and
keep the fallback.

---

Nitpick comments:
In `@packages/bruno-app/src/utils/common/sort-items-by-sidebar-order.spec.js`:
- Around line 1-2: Move the spec to live next to the implementation: relocate
the test file named sort-items-by-sidebar-order.spec.js into the same folder
containing the collections index module so it directly tests
sortItemsBySidebarOrder; update its require/import to reference ../index (or the
local module) if necessary and run tests to ensure paths resolve correctly.
🪄 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: 79b826b2-6162-46f1-9871-398476dc0dd6

📥 Commits

Reviewing files that changed from the base of the PR and between 13a48a2 and 38de159.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (18)
  • package.json
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/index.js
  • packages/bruno-app/src/utils/collections/index.js
  • packages/bruno-app/src/utils/common/sort-items-by-sidebar-order.spec.js
  • tests/collection/generate-docs/fixtures/collection/Aviary/Parrot.bru
  • tests/collection/generate-docs/fixtures/collection/Aviary/folder.bru
  • tests/collection/generate-docs/fixtures/collection/ReqAlpha.bru
  • tests/collection/generate-docs/fixtures/collection/ReqBeta.bru
  • tests/collection/generate-docs/fixtures/collection/Zoo/Bear.bru
  • tests/collection/generate-docs/fixtures/collection/Zoo/Lion.bru
  • tests/collection/generate-docs/fixtures/collection/Zoo/Reptiles/Gecko.bru
  • tests/collection/generate-docs/fixtures/collection/Zoo/Reptiles/Snake.bru
  • tests/collection/generate-docs/fixtures/collection/Zoo/Reptiles/folder.bru
  • tests/collection/generate-docs/fixtures/collection/Zoo/folder.bru
  • tests/collection/generate-docs/fixtures/collection/bruno.json
  • tests/collection/generate-docs/generate-docs.spec.ts
  • tests/collection/generate-docs/init-user-data/preferences.json
  • tests/utils/page/actions.ts

@sid-bruno
sid-bruno merged commit 377cdb4 into usebruno:main Jun 10, 2026
22 of 25 checks passed
abhishekp-bruno pushed a commit to abhishekp-bruno/bruno that referenced this pull request Jun 17, 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.

2 participants