Skip to content

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

Open
sachin-bruno wants to merge 2 commits into
usebruno:mainfrom
sachin-bruno:sachin-bruno/fix-preserve-folder-order
Open

fix(size/L): Preserve folder order from seq attribute#8213
sachin-bruno wants to merge 2 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

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.

Ref: https://usebruno.atlassian.net/browse/BRU-3403

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

  • Improvements

    • Generated documentation now preserves the same item ordering seen in the sidebar for consistent exports.
  • New Features

    • Added a test helper to trigger and capture generated documentation from the UI.
  • Tests

    • End-to-end tests and fixtures added to verify exported doc order and the Generate Documentation modal behavior.
  • Chores

    • Added a development dependency to support YAML handling in tests.
image

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR adds deterministic item ordering to the "Generate Documentation" export by introducing sortItemsBySidebarOrder, applying it during export, and adding unit and end-to-end tests with fixtures and a test helper to verify generated docs match the live sidebar order.

Changes

Documentation generation item ordering and E2E verification

Layer / File(s) Summary
Dependencies and core ordering utility
package.json, packages/bruno-app/src/utils/collections/index.js
@types/js-yaml is added to devDependencies. A new exported sortItemsBySidebarOrder function recursively sorts collection items by sidebar rendering order: non-transient folders first (sorted by name then sequence), followed by non-transient requests sorted by ascending sequence, with the same rules applied recursively to nested item arrays.
Export integration with sorting
packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/index.js
The GenerateDocumentation component imports and applies sortItemsBySidebarOrder after deep-cloning the selected collection, ensuring the exported documentation reflects the sidebar's item order at all nesting levels.
Unit tests for sorting utility
packages/bruno-app/src/utils/common/sort-items-by-sidebar-order.spec.js
A Jest test suite validates sortItemsBySidebarOrder across grouping (folders before requests), sequence-based sorting within categories, recursive application to nested structures, filtering of transient items, input array non-mutation, and empty/missing input handling.
E2E test helper and collection fixtures
tests/utils/page/actions.ts, tests/collection/generate-docs/fixtures/collection/*, tests/collection/generate-docs/init-user-data/preferences.json
A generateCollectionDocs test helper intercepts browser downloads to capture generated documentation. A hierarchical collection fixture tree (Zoo with nested Reptiles; Aviary) with requests and folders each assigned seq ordering metadata, plus a preferences template for test initialization.
End-to-end test cases
tests/collection/generate-docs/generate-docs.spec.ts
Playwright tests extract embedded collection data from generated HTML, decode and parse the item structure, validate it matches a deterministic expected order (folders then requests at each depth), and assert the embedded order matches the live sidebar rendering. A secondary test verifies the "Generate Documentation" modal UI appears and can be invoked from the collection context menu.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • usebruno/bruno#6583: Introduced the initial GenerateDocumentation component and export flow, which this PR extends with item-order preservation logic.
  • usebruno/bruno#7581: Implements similar deterministic folder-first, seq-aware recursive ordering rules elsewhere (used here for generated docs ordering).

Suggested reviewers

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

Poem

📋✨ Items march in sidebar order now,
Docs and browser dance and bow,
Folders lead with seq so bright,
Tests confirm the marching right,
Exported pages hum in sync — hooray! 🥳

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(size/L): Preserve folder order from seq attribute' accurately describes the main change—reordering collection items by their 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.
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.

@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

Comment thread packages/bruno-app/src/utils/collections/index.js
Comment thread tests/collection/generate-docs/generate-docs.spec.ts Outdated
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.

1 participant