Repository navigation
add: oc support for cli - #6661
Conversation
WalkthroughThe 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
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.bruextension won't strip.ymlfor OpenCollection format.The
suitenameconstruction uses a hardcoded.brureplacement, which will leave the.ymlextension 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.parseandparseCollectioncan throw on malformed content. While the file existence is implicitly guaranteed bygetCollectionFormat, 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 withfind(). 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
📒 Files selected for processing (8)
packages/bruno-cli/src/commands/run.jspackages/bruno-cli/src/utils/collection.jspackages/bruno-cli/tests/runner/collection-json-from-pathname.spec.jspackages/bruno-cli/tests/runner/fixtures/opencollection/collection/environments/dev.ymlpackages/bruno-cli/tests/runner/fixtures/opencollection/collection/get-users.ymlpackages/bruno-cli/tests/runner/fixtures/opencollection/collection/opencollection.ymlpackages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/create-user.ymlpackages/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()notfunc ()
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.jspackages/bruno-cli/src/utils/collection.jspackages/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.ymlpackages/bruno-cli/tests/runner/fixtures/opencollection/collection/get-users.ymlpackages/bruno-cli/src/commands/run.jspackages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/create-user.ymlpackages/bruno-cli/src/utils/collection.jspackages/bruno-cli/tests/runner/fixtures/opencollection/collection/opencollection.ymlpackages/bruno-cli/tests/runner/fixtures/opencollection/collection/users/folder.ymlpackages/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.jspackages/bruno-cli/src/utils/collection.jspackages/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
nameandvariablesarray 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
parseCollectionwithformat: 'yml'.packages/bruno-cli/src/commands/run.js (4)
18-18: LGTM!Clean import of
FORMAT_CONFIGfrom the collection utilities to support dynamic file extension handling.
362-365: LGTM!Dynamic extension derivation from
FORMAT_CONFIG[collection.format].extcorrectly adapts environment file resolution per collection format.
390-394: LGTM!YAML environment parsing correctly delegates to
parseEnvironmentwithformat: 'yml'and properly assigns__name__based on whether an explicitenvFilepath or environment name was provided.
603-608: LGTM!Dynamic extension handling in
runSingleRequestByPathnameproperly usesFORMAT_CONFIGto 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). Returningnullwhen neither is found allows the caller to handle the error appropriately.
35-39: LGTM!Clean helper for folder metadata retrieval. Gracefully returns
nullwhen folder config doesn't exist.
41-94: LGTM!Well-structured refactor of
createCollectionJsonFromPathnameto 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_CONFIGandgetCollectionFormatfor use by downstream consumers likerun.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
parseYmlFolderfunction from@usebruno/filestorecorrectly normalizes theinfoobject tometa(seeparseFolder.tslines 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
getCollectionFormatAPI—validates yml, bru, and null (invalid) cases.
234-250: Public API contract validation looks correct.These tests lock down the structure of
FORMAT_CONFIGsince 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
parseEnvironmentwith theformat: 'yml'option inpackages/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.
add: oc support for cli
Description
Contribution Checklist:
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
✏️ Tip: You can customize this high-level summary in your review settings.