Skip to content

refactor: remove idx from HeaderList, extend ReadOnlyPropertyList, add positional method translations#7917

Merged
bijin-bruno merged 6 commits intousebruno:mainfrom
sanish-bruno:fix/rm-autocomplete-for--removed-apis
May 6, 2026
Merged

refactor: remove idx from HeaderList, extend ReadOnlyPropertyList, add positional method translations#7917
bijin-bruno merged 6 commits intousebruno:mainfrom
sanish-bruno:fix/rm-autocomplete-for--removed-apis

Conversation

@sanish-bruno
Copy link
Copy Markdown
Collaborator

@sanish-bruno sanish-bruno commented May 5, 2026

Summary

Cleans up the HeaderList API surface by removing idx, switching the parent class from PropertyList to ReadOnlyPropertyList, adding missing translator mappings, and ensuring full regex fallback coverage.

Changes

1. HeaderList now extends ReadOnlyPropertyList directly

HeaderList was extending PropertyList, but it overrode every mutation method with its own implementation that operates on the request config. The PropertyList layer only contributed methods (add, upsert, remove, prepend, insert, insertAfter) that HeaderList either renamed or doesn't support — none of them were actually used.

By extending ReadOnlyPropertyList directly, those methods simply don't exist on HeaderList. No need to block them with throwing stubs.

Only two inherited methods need explicit blocking:

  • idx — set to undefined (not part of the HeaderList API)
  • each — set to undefined (renamed to forEach)

2. idx removed from API surface

  • Removed from QuickJS sandbox shims (syncReadObjectMethods in bruno-request.js and bruno-response.js)
  • Removed from autocomplete hints (autocomplete.js)
  • Removed unit tests from header-list.spec.js
  • Removed integration tests from req/headerList/read-methods.bru and res/headerList/read-methods.bru

3. each fully removed from QuickJS sandbox

The bridge generates each (shared with CookieList), then aliases forEach = each for HeaderList. Now also deletes each after aliasing, so only forEach exists in the sandbox — consistent with the native side.

4. Postman positional header methods → append (complex transform)

Added complex AST transformations for pm.request.headers.prepend, .insert, .insertAfterreq.headerList.append. These drop the second positional argument (e.g., insert({key, value}, "ref") becomes append({key, value})) since position is irrelevant for headers stored as a plain object.

5. Missing toString / toJSON translations added

Added toString and toJSON translations for both request and response headers across all three layers:

  • AST translator (postman-to-bruno and bruno-to-postman)
  • Regex fallback

6. Complete regex fallback coverage for headerList

Added all missing headerList method entries to the regex fallback (postman-translations.js), ensuring parity with the AST translator:

Request headers: get, has, one, all, count, indexOf, find, filter, eachforEach, map, reduce, toObject, toString, toJSON, clear, addappend, upsertset, populate, repopulate, assimilate, prepend/insert/insertAfterappend

Response headers: has, one, all, count, indexOf, find, filter, eachforEach, map, reduce, toObject, toString, toJSON

Test plan

  • npm run test --workspace=packages/bruno-js — 488 tests pass
  • npm run test --workspace=packages/bruno-converters — 950 tests pass
  • Run E2E tests against .bru integration test files

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.

- Eliminated the 'idx' method from both req.headerList and res.headerList to streamline header management.
- Updated associated tests and documentation to reflect the removal, ensuring clarity in the API usage and maintaining consistency across the header management system.
@sanish-bruno sanish-bruno changed the title refactor: remove 'idx' method from headerList and update related tests refactor: rename HeaderList methods to MDN Headers naming and fix populate/repopulate behavior May 5, 2026
@sanish-bruno sanish-bruno changed the title refactor: rename HeaderList methods to MDN Headers naming and fix populate/repopulate behavior refactor: remove idx from HeaderList API surface May 5, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

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

HeaderList no longer exposes an indexed accessor (idx). The class now inherits from ReadOnlyPropertyList and explicitly blocks inherited idx/each. QuickJS shims drop idx from bridge sync-read methods and remove temporary aliases. Autocomplete entries and tests referencing idx were removed; Postman→Bruno header mappings for positional inserts were added (mapped lossy to append).

Changes

HeaderList idx Removal & Blocking

Layer / File(s) Summary
Core Inheritance
packages/bruno-js/src/header-list.js
HeaderList now extends ReadOnlyPropertyList (replaces PropertyList).
Blocked inherited methods
packages/bruno-js/src/header-list.js
Class fields idx and each declared undefined to block inherited method exposure.
Bridge Wiring
packages/bruno-js/src/sandbox/quickjs/shims/bruno-request.js, packages/bruno-js/src/sandbox/quickjs/shims/bruno-response.js
createPropertyListBridge config for req.headerList and res.headerList removes 'idx' from syncReadObjectMethods (['one','all','toJSON']); post-setup eval assigns forEach from internal impl then deletes the temporary each alias.
Editor Hints
packages/bruno-app/src/utils/codemirror/autocomplete.js
Removed static autocomplete entries for req.headerList.idx(index) and res.headerList.idx(index).
Tests / Scripts
packages/bruno-js/tests/header-list.spec.js, packages/bruno-tests/collection/scripting/api/req/headerList/read-methods.bru, packages/bruno-tests/collection/scripting/api/res/headerList/read-methods.bru
Deleted test cases asserting headerList.idx(...); updated req.headerList.all() expectation to include x-custom; inheritance test updated to expect ReadOnlyPropertyList.
Translators & Tests
packages/bruno-converters/src/utils/postman-to-bruno-translator.js, packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/request.test.js
Added simpleTranslations mappings for pm.request.headers.prepend, insert, insertAfter → mapped to req.headerList.append (lossy positional mapping) and tests validating these translations.

Sequence Diagram(s)

sequenceDiagram
    participant Editor
    participant QuickJS
    participant Host
    participant Tests
    participant Translator

    Editor->>QuickJS: remove static idx autocomplete hints
    QuickJS->>Host: createPropertyListBridge without 'idx' in syncReadObjectMethods
    QuickJS->>Host: assign forEach from internal each
    QuickJS->>Host: delete temporary each alias
    Tests->>Host: drop idx() testcases and run updated read-method tests
    Translator->>Host: map pm.request.headers.{prepend,insert,insertAfter} → req.headerList.append
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • usebruno/bruno#7673: Modifies HeaderList API surface and wiring for idx across header-list, shims, autocomplete, and tests.
  • usebruno/bruno#7052: Related adjustments to Postman→Bruno header translation mappings.
  • usebruno/bruno#7073: Related changes around ReadOnlyPropertyList/PropertyList and the sandbox property-list bridge.

Suggested labels

size/L

Suggested reviewers

  • helloanoop
  • sid-bruno
  • lohit-bruno

A header once indexed, now set free,
idx steps down from the header tree.
Hints and shims fold back their sails,
Tests trimmed clear along the rails.
Translators append what order fails. 🚀

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title accurately summarizes the main changes: removing idx from HeaderList, changing the parent class to ReadOnlyPropertyList, and adding translations for positional header methods.
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.

- Added error handling for unimplemented methods in HeaderList, including idx, add, upsert, remove, each, prepend, insert, and insertAfter.
- Each method now throws a descriptive error indicating the appropriate alternative methods to use, enhancing clarity in the API and guiding users towards correct usage.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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-js/src/header-list.js`:
- Around line 159-162: The idx() method in HeaderList throws an error that
misleads users to use get(name) or all(), but idx() returns a numeric index and
the correct replacement is indexOf(); update the error message in the idx()
method (HeaderList::idx or ReadOnlyPropertyList::idx override) to recommend
using indexOf(name) instead of get(name)/all() so it correctly directs callers
to the numeric-index API.
🪄 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: b049edd7-6072-4571-a786-72f61c886fcd

📥 Commits

Reviewing files that changed from the base of the PR and between b90257d and 9cdbb0e.

📒 Files selected for processing (1)
  • packages/bruno-js/src/header-list.js

Comment thread packages/bruno-js/src/header-list.js Outdated
- Modified the error message in the idx() method to guide users towards using all()[index] or get(name) instead of the unsupported idx() method, enhancing the clarity of the API documentation.
… unimplemented methods

- Changed HeaderList to extend ReadOnlyPropertyList instead of PropertyList, streamlining its functionality.
- Removed unimplemented methods (prepend, insert, insertAfter) from HeaderList, clarifying the API and guiding users towards using supported methods.
- Updated related tests to reflect these changes, ensuring consistency and accuracy in header management.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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)
packages/bruno-js/tests/header-list.spec.js (1)

1-25: ⚡ Quick win

Missing test coverage for the blocked idx and each API surface.

Removing the idx tests is right, but there's no assertion that the properties are actually undefined/non-callable. Without this, a future change that accidentally re-exposes these (e.g. removing the class field declarations) would go undetected.

✅ Suggested tests to add
+  test('idx is not exposed (blocked inherited method)', () => {
+    const { list } = createReqHeaders();
+    expect(list.idx).toBeUndefined();
+    expect(() => list.idx(0)).toThrow(TypeError);
+  });
+
+  test('each is not exposed (blocked inherited method)', () => {
+    const { list } = createReqHeaders();
+    expect(list.each).toBeUndefined();
+    expect(() => list.each(() => {})).toThrow(TypeError);
+  });

Note: If the blocked methods are changed to throw descriptive errors (see comment on header-list.js), update toThrow(TypeError) to toThrow('...') to assert the specific message.

As per coding guidelines: "If code is added, removed, or significantly modified, corresponding tests should be updated or created."

🤖 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-js/tests/header-list.spec.js` around lines 1 - 25, Add
assertions to the header-list.spec.js tests that ensure the blocked API surface
on HeaderList is not exposed: verify that the instance properties list.idx and
list.each are undefined (or not functions) and, if desired, assert that calling
them throws a TypeError (or the specific error string if header-list.js was
changed to throw descriptive errors). Refer to the HeaderList instance produced
by createReqHeaders() and add expectations that explicitly check list.idx and
list.each are absent/non-callable to prevent regressions.
🤖 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-js/src/header-list.js`:
- Around line 153-157: The class currently shadows inherited methods by setting
the fields idx = undefined and each = undefined on HeaderList, causing generic
"is not a function" TypeErrors; replace those class fields with explicit methods
(e.g., idx(...){ throw new TypeError('HeaderList.idx is not supported; use
HeaderList.get(...) or HeaderList.at(...) instead'); } and each(...){ throw new
TypeError('HeaderList.each is not supported; use HeaderList.forEach(...) or
HeaderList.iterateHeaders(...) instead'); }) so callers receive descriptive
errors directing them to the correct HeaderList API; update the HeaderList class
in place of the idx and each fields (they shadow ReadOnlyPropertyList) to
implement these throwing methods.

---

Nitpick comments:
In `@packages/bruno-js/tests/header-list.spec.js`:
- Around line 1-25: Add assertions to the header-list.spec.js tests that ensure
the blocked API surface on HeaderList is not exposed: verify that the instance
properties list.idx and list.each are undefined (or not functions) and, if
desired, assert that calling them throws a TypeError (or the specific error
string if header-list.js was changed to throw descriptive errors). Refer to the
HeaderList instance produced by createReqHeaders() and add expectations that
explicitly check list.idx and list.each are absent/non-callable to prevent
regressions.
🪄 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: 9dd1f45d-dc3c-4dce-b99e-24bd86d91c8a

📥 Commits

Reviewing files that changed from the base of the PR and between cc31d09 and c115c19.

📒 Files selected for processing (5)
  • packages/bruno-converters/src/utils/postman-to-bruno-translator.js
  • packages/bruno-js/src/header-list.js
  • packages/bruno-js/src/sandbox/quickjs/shims/bruno-request.js
  • packages/bruno-js/src/sandbox/quickjs/shims/bruno-response.js
  • packages/bruno-js/tests/header-list.spec.js

Comment thread packages/bruno-js/src/header-list.js
- Introduced new tests to validate the translation of pm.request.headers methods (prepend, insert, insertAfter) to their corresponding req.headerList.append method.
- Enhanced existing tests to ensure accurate conversion and functionality of header management in the Bruno converters.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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-converters/tests/postman/postman-translations/transpiler-tests/request.test.js`:
- Around line 210-220: The tests currently expect the translator to preserve the
second positional "ref" argument for pm.request.headers.insert and
pm.request.headers.insertAfter, but the translator should drop that removed API
semantic and emit a pure append call; update the expectations in the two tests
that reference translateCode to assert that req.headerList.append only receives
the header object (i.e., expect translatedCode toBe 'req.headerList.append({key:
"X-Mid", value: "2"});' and 'req.headerList.append({key: "X-After", value:
"3"});' respectively), referencing the pm.request.headers.insert /
pm.request.headers.insertAfter inputs and the req.headerList.append output to
locate the assertions.
🪄 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: 38ac1643-b758-45ba-8e75-3b751c67a58e

📥 Commits

Reviewing files that changed from the base of the PR and between c115c19 and a632937.

📒 Files selected for processing (1)
  • packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/request.test.js

@sanish-bruno sanish-bruno changed the title refactor: remove idx from HeaderList API surface refactor: remove idx from HeaderList, extend ReadOnlyPropertyList, add positional method translations May 6, 2026
- Added translations for additional pm.request.headers methods (get, has, one, all, count, indexOf, find, filter, each, map, reduce, toObject, clear) to their corresponding req.headerList methods.
- Updated tests to validate the new translations and ensure accurate header management functionality in the Bruno converters.
@pull-request-size pull-request-size Bot added size/L and removed size/M labels May 6, 2026
@bijin-bruno bijin-bruno merged commit d39d5ef into usebruno:main May 6, 2026
12 checks passed
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