Skip to content

add: oc support for cli - #6661

Merged
helloanoop merged 1 commit into
usebruno:mainfrom
naman-bruno:cli/opencollection
Jan 5, 2026
Merged

helloanoop merged 1 commit into
usebruno:mainfrom
naman-bruno:cli/opencollection

Conversation

@naman-bruno

@naman-bruno naman-bruno commented Jan 5, 2026 •

Copy link
Copy Markdown
Collaborator

Description

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

  • New Features
    • Added support for OpenCollection YAML format collections in addition to the existing Bruno format
    • Added support for YAML environment files (.yml/.yaml) for environment configuration alongside JSON and Bruno formats
    • Improved environment file handling with dynamic format-aware extension support

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 5, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

The PR introduces multi-format support for Bruno CLI collections, enabling YAML-based OpenCollection format alongside the existing Bruno format. Changes include: dynamic file extension handling via FORMAT_CONFIG, format detection logic, environment file parsing for YAML/JSON/Bruno formats, and refactored collection traversal with format-specific metadata loading.

Changes

Cohort / File(s) Change Summary
Format Infrastructure
packages/bruno-cli/src/utils/collection.js
Introduces FORMAT_CONFIG constant with per-format metadata (ext, collectionFile, folderFile); adds getCollectionFormat() for format detection (yml/bru); adds getCollectionConfig() for format-specific config loading; adds getFolderRoot() for format-aware folder metadata retrieval. Refactors createCollectionJsonFromPathname to use detected format for parsing, folder traversal, and item collection with skip logic for node_modules/.git and format-specific metadata files.
CLI Environment & Extension Handling
packages/bruno-cli/src/commands/run.js
Imports FORMAT_CONFIG; replaces hardcoded .bru extension with dynamic ext from FORMAT_CONFIG[collection.format].ext; updates environment parsing to support JSON (via parseEnvironmentJson + name assignment), YAML (via parseEnvironment with format 'yml'), and Bruno format fallback; adjusts error messages and file path resolution for environment files accordingly.
Test Fixtures – OpenCollection Structure
packages/bruno-cli/tests/runner/fixtures/opencollection/collection/opencollection.yml, packages/bruno-cli/tests/runner/fixtures/opencollection/collection/get-users.yml, packages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/folder.yml, packages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/create-user.yml
Adds OpenCollection YAML fixtures defining collection metadata (version, info, headers, ignore patterns) and request structure with YAML-based requests (GET /users, POST /users with JSON body) and folder metadata.
Test Fixtures – Environment
packages/bruno-cli/tests/runner/fixtures/opencollection/collection/environments/dev.yml
Adds YAML environment configuration with Development environment variables (baseUrl, apiKey).
Test Coverage
packages/bruno-cli/tests/runner/collection-json-from-pathname.spec.js
Updates test suite to import and exercise new public APIs: getCollectionFormat() for format detection, FORMAT_CONFIG for format metadata, parseEnvironment for YAML environment parsing; adds test cases validating OpenCollection YAML parsing and environment structure.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI/run.js
    participant Detector as Format Detector
    participant Config as Format Config
    participant Parser as Format Parser
    participant FS as File System

    rect rgb(200, 220, 255)
    Note over CLI,FS: Collection Initialization
    CLI->>Detector: getCollectionFormat(collectionPath)
    Detector->>FS: Check opencollection.yml exists
    Detector->>FS: Check bruno.json exists
    Detector-->>CLI: format (yml | bru)
    end

    rect rgb(220, 255, 220)
    Note over CLI,Parser: Load Collection by Format
    CLI->>Config: FORMAT_CONFIG[format]
    Config-->>CLI: {ext, collectionFile, folderFile}
    CLI->>Parser: createCollectionJsonFromPathname(path, format)
    
    alt Format: YAML
        Parser->>FS: Read opencollection.yml
        Parser->>Parser: parseCollection() [YAML parser]
    else Format: Bruno
        Parser->>FS: Read bruno.json + *.bru files
        Parser->>Parser: Parse Bruno format
    end
    Parser-->>CLI: Collection JSON
    end

    rect rgb(255, 240, 200)
    Note over CLI,Parser: Load Environment by Format
    CLI->>Parser: Load env file (baseDir + envName + ext)
    
    alt Env Format: JSON
        Parser->>Parser: parseEnvironmentJson()
        Parser->>Parser: Assign __name__ from envName
    else Env Format: YAML
        Parser->>Parser: parseEnvironment(content, 'yml')
        Parser->>Parser: Assign __name__ from envName
    else Fallback
        Parser->>Parser: Parse as Bruno format
    end
    Parser-->>CLI: Environment Variables
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • #6534 – Modifies environment-loading logic in run.js to add YAML parsing and alter environment file location/merge behavior.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • bijin-bruno

Poem

🎨 YAML flows where BRU once stood,
Format-agnostic, as it should—
One config true, extensions dance free,
Collections bloom in harmony! 🌿✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'add: oc support for cli' refers to a real and substantial part of the changeset—adding OpenCollection (OC) support to the CLI—but lacks clarity about what 'oc' specifically means and uses abbreviation instead of full terms. Consider expanding to 'add: OpenCollection format support for CLI' or 'add: OpenCollection (.yml) support to CLI' for clarity without sacrificing brevity.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

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: 0

Caution

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

⚠️ Outside diff range comments (1)
packages/bruno-cli/src/commands/run.js (1)

660-665: Hardcoded .bru extension won't strip .yml for OpenCollection format.

The suitename construction uses a hardcoded .bru replacement, which will leave the .yml extension in place for OpenCollection requests.

🔎 Proposed fix
+      const ext = FORMAT_CONFIG[collection.format].ext;
       results.push({
         ...result,
         runDuration: process.hrtime(start)[0] + process.hrtime(start)[1] / 1e9,
-        suitename: pathname.replace('.bru', ''),
+        suitename: pathname.replace(ext, ''),
         name
       });
🧹 Nitpick comments (2)
packages/bruno-cli/src/utils/collection.js (1)

21-33: Consider adding error handling for parse failures.

Both JSON.parse and parseCollection can throw on malformed content. While the file existence is implicitly guaranteed by getCollectionFormat, invalid file content could cause unhandled exceptions.

🔎 Suggested improvement
 const getCollectionConfig = (collectionPath, format) => {
+  try {
     if (format === 'yml') {
       const content = fs.readFileSync(path.join(collectionPath, 'opencollection.yml'), 'utf8');
       const parsed = parseCollection(content, { format: 'yml' });
       return { brunoConfig: parsed.brunoConfig, collectionRoot: parsed.collectionRoot || {} };
     }
     const brunoConfig = JSON.parse(fs.readFileSync(path.join(collectionPath, 'bruno.json'), 'utf8'));
     const collectionBruPath = path.join(collectionPath, 'collection.bru');
     const collectionRoot = fs.existsSync(collectionBruPath)
       ? parseCollection(fs.readFileSync(collectionBruPath, 'utf8'), { format: 'bru' })
       : {};
     return { brunoConfig, collectionRoot };
+  } catch (err) {
+    console.error(chalk.red(`Failed to parse collection config: ${err.message}`));
+    process.exit(constants.EXIT_STATUS.ERROR_INVALID_FILE);
+  }
 };
packages/bruno-cli/tests/runner/collection-json-from-pathname.spec.js (1)

175-214: Solid test coverage for OpenCollection format.

The test validates the core structure, metadata, and request properties for YAML-based collections. Good work exercising the new format support.

Minor optimization: eliminate redundant array traversal

Lines 193-194 traverse the items array twice—once to check existence with some(), then again to retrieve with find(). Consider consolidating:

-    // folder
-    expect(c.items.some((i) => i.type === 'folder' && i.name === 'users')).toBe(true);
-    const usersFolder = c.items.find((i) => i.name === 'users');
+    // folder
+    const usersFolder = c.items.find((i) => i.name === 'users');
+    expect(usersFolder).toBeDefined();
+    expect(usersFolder.type).toBe('folder');
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97e43c4 and afd49d1.

📒 Files selected for processing (8)
  • packages/bruno-cli/src/commands/run.js
  • packages/bruno-cli/src/utils/collection.js
  • packages/bruno-cli/tests/runner/collection-json-from-pathname.spec.js
  • packages/bruno-cli/tests/runner/fixtures/opencollection/collection/environments/dev.yml
  • packages/bruno-cli/tests/runner/fixtures/opencollection/collection/get-users.yml
  • packages/bruno-cli/tests/runner/fixtures/opencollection/collection/opencollection.yml
  • packages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/create-user.yml
  • packages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/folder.yml
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-cli/src/commands/run.js
  • packages/bruno-cli/src/utils/collection.js
  • packages/bruno-cli/tests/runner/collection-json-from-pathname.spec.js
🧠 Learnings (3)
📚 Learning: 2025-12-16T07:16:23.647Z
Learnt from: sanish-bruno
Repo: usebruno/bruno PR: 6090
File: tests/scripting/hooks/init-user-data/ui-state-snapshot.json:1-8
Timestamp: 2025-12-16T07:16:23.647Z
Learning: For e2e tests in the bruno repository: Collections that are shared between CLI and UI tests (comprehensive test suites testing core functionality) should be placed in `packages/bruno-tests/` to avoid duplication. The `tests/**/fixtures/collection` pattern should be used for test-specific collections that test particular UI behaviors or are specific to a single test file.

Applied to files:

  • packages/bruno-cli/tests/runner/fixtures/opencollection/collection/environments/dev.yml
  • packages/bruno-cli/tests/runner/fixtures/opencollection/collection/get-users.yml
  • packages/bruno-cli/src/commands/run.js
  • packages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/create-user.yml
  • packages/bruno-cli/src/utils/collection.js
  • packages/bruno-cli/tests/runner/fixtures/opencollection/collection/opencollection.yml
  • packages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/folder.yml
  • packages/bruno-cli/tests/runner/collection-json-from-pathname.spec.js
📚 Learning: 2025-12-17T21:41:24.730Z
Learnt from: naman-bruno
Repo: usebruno/bruno PR: 6407
File: packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js:5-41
Timestamp: 2025-12-17T21:41:24.730Z
Learning: Do not suggest PropTypes validation for React components in the Bruno codebase. The project does not use PropTypes, so reviews should avoid proposing PropTypes and rely on the existing typing/validation approach (e.g., TypeScript or alternative runtime checks) if applicable. This guideline applies broadly to all JavaScript/JSX components in the repo.

Applied to files:

  • packages/bruno-cli/src/commands/run.js
  • packages/bruno-cli/src/utils/collection.js
  • packages/bruno-cli/tests/runner/collection-json-from-pathname.spec.js
📚 Learning: 2025-12-05T20:31:33.005Z
Learnt from: CR
Repo: usebruno/bruno PR: 0
File: CODING_STANDARDS.md:0-0
Timestamp: 2025-12-05T20:31:33.005Z
Learning: Applies to **/*.test.{js,jsx,ts,tsx} : Add tests for any new functionality or meaningful changes. If code is added, removed, or significantly modified, corresponding tests should be updated or created

Applied to files:

  • packages/bruno-cli/tests/runner/collection-json-from-pathname.spec.js
🧬 Code graph analysis (3)
packages/bruno-cli/src/commands/run.js (3)
packages/bruno-cli/src/utils/collection.js (2)
  • FORMAT_CONFIG (10-13)
  • FORMAT_CONFIG (49-49)
packages/bruno-filestore/src/index.ts (1)
  • parseEnvironment (115-122)
packages/bruno-cli/src/utils/bru.js (2)
  • envVars (136-136)
  • getEnvVars (130-144)
packages/bruno-cli/src/utils/collection.js (1)
packages/bruno-filestore/src/index.ts (3)
  • parseCollection (77-84)
  • parseFolder (96-103)
  • parseRequest (31-38)
packages/bruno-cli/tests/runner/collection-json-from-pathname.spec.js (2)
packages/bruno-cli/src/utils/collection.js (6)
  • fs (3-3)
  • require (1-1)
  • require (5-5)
  • require (6-6)
  • FORMAT_CONFIG (10-13)
  • FORMAT_CONFIG (49-49)
packages/bruno-filestore/src/index.ts (1)
  • parseEnvironment (115-122)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - macOS
  • GitHub Check: Unit Tests
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: CLI Tests
🔇 Additional comments (18)
packages/bruno-cli/tests/runner/fixtures/opencollection/collection/environments/dev.yml (1)

1-6: LGTM!

Environment fixture is well-structured with name and variables array matching the expected OpenCollection YAML environment schema. Good test coverage for the new YAML environment parsing path.

packages/bruno-cli/tests/runner/fixtures/opencollection/collection/opencollection.yml (1)

1-14: LGTM!

OpenCollection root fixture covers essential config fields including version, info, extensions, and collection-level request headers. Provides good test coverage for parseCollection with format: 'yml'.

packages/bruno-cli/src/commands/run.js (4)

18-18: LGTM!

Clean import of FORMAT_CONFIG from the collection utilities to support dynamic file extension handling.


362-365: LGTM!

Dynamic extension derivation from FORMAT_CONFIG[collection.format].ext correctly adapts environment file resolution per collection format.


390-394: LGTM!

YAML environment parsing correctly delegates to parseEnvironment with format: 'yml' and properly assigns __name__ based on whether an explicit envFile path or environment name was provided.


603-608: LGTM!

Dynamic extension handling in runSingleRequestByPathname properly uses FORMAT_CONFIG to determine the correct file extension for the collection format.

packages/bruno-cli/src/utils/collection.js (5)

10-13: LGTM!

Clean configuration object mapping format identifiers to their corresponding file extensions and metadata filenames. Well-structured for extensibility.


15-19: LGTM!

Format detection prioritizes OpenCollection (opencollection.yml) over Bruno format (bruno.json). Returning null when neither is found allows the caller to handle the error appropriately.


35-39: LGTM!

Clean helper for folder metadata retrieval. Gracefully returns null when folder config doesn't exist.


41-94: LGTM!

Well-structured refactor of createCollectionJsonFromPathname to support format-aware collection parsing. The traverse function properly:

  • Skips system directories (node_modules, .git) and environments folder
  • Applies format-specific file extension filtering
  • Preserves folder metadata and sequence information
  • Sorts folders by name/sequence and requests by sequence

588-591: LGTM!

Clean public API extension exposing FORMAT_CONFIG and getCollectionFormat for use by downstream consumers like run.js.

packages/bruno-cli/tests/runner/fixtures/opencollection/collection/get-users.yml (1)

1-8: LGTM!

Well-formed HTTP GET request fixture for testing OpenCollection YAML parsing. Covers essential metadata (info) and request definition (http) blocks.

packages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/create-user.yml (1)

1-14: LGTM!

Good test fixture covering HTTP POST with JSON body mode. Exercises the YAML parser's handling of multiline literal strings for request bodies.

packages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/folder.yml (1)

1-3: No action required—folder YAML schema is correctly normalized.

The parseYmlFolder function from @usebruno/filestore correctly normalizes the info object to meta (see parseFolder.ts lines 14–23). The fixture structure is valid and the sequence number is properly extracted.

packages/bruno-cli/tests/runner/collection-json-from-pathname.spec.js (4)

2-2: LGTM on imports.

The new imports are properly structured and necessary for testing the multi-format collection support and environment parsing functionality.

Also applies to: 5-6


217-232: LGTM on format detection tests.

Complete coverage of the getCollectionFormat API—validates yml, bru, and null (invalid) cases.


234-250: Public API contract validation looks correct.

These tests lock down the structure of FORMAT_CONFIG since it's exported as a public API. While this tests implementation details, it's appropriate for ensuring external consumers can rely on a stable interface.


252-266: This test is appropriately placed and validates actual CLI functionality.

The CLI actively uses parseEnvironment with the format: 'yml' option in packages/bruno-cli/src/commands/run.js (lines 392 and 449) when processing OpenCollection environment files. This test correctly validates that integration and belongs in the CLI test suite.

Likely an incorrect or invalid review comment.

@helloanoop
helloanoop merged commit d616be7 into usebruno:main Jan 5, 2026
maxenceleblanc pushed a commit to maxenceleblanc/curly_cats2 that referenced this pull request Jul 20, 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