From ac5179ebc641e834944f7395decb4f6da95f8bbb Mon Sep 17 00:00:00 2001 From: bruno-sachin Date: Tue, 30 Jun 2026 13:39:53 +0530 Subject: [PATCH 1/6] feat:Added the option for bruno version edit --- .../Overview/Info/StyledWrapper.js | 9 ++ .../CollectionSettings/Overview/Info/index.js | 24 ++- .../ChangeCollectionVersion/StyledWrapper.js | 145 ++++++++++++++++++ .../ChangeCollectionVersion/index.js | 141 +++++++++++++++++ .../ChangeCollectionVersion/index.spec.js | 121 +++++++++++++++ .../CollectionVersionInfo/index.js | 4 +- .../GenerateDocumentation/StyledWrapper.js | 4 + .../Collection/GenerateDocumentation/index.js | 5 +- .../ReduxStore/slices/collections/actions.js | 37 +++++ .../ReduxStore/slices/collections/index.js | 22 ++- .../bruno-app/src/utils/collections/index.js | 14 ++ .../opencollection/bruno-to-opencollection.ts | 16 +- .../opencollection/opencollection-to-bruno.ts | 4 + .../src/opencollection/types.ts | 4 + .../opencollection/collection-version.spec.js | 45 ++++++ .../bruno-electron/src/app/collections.js | 8 +- packages/bruno-electron/src/ipc/collection.js | 43 +++++- .../src/utils/collection-import.js | 7 + .../src/formats/yml/parseCollection.spec.ts | 17 ++ .../src/formats/yml/parseCollection.ts | 4 + .../formats/yml/stringifyCollection.spec.ts | 28 ++++ .../src/formats/yml/stringifyCollection.ts | 4 + .../change-version-bru.spec.ts | 50 ++++++ .../fixtures/collection/bruno.json | 5 + .../init-user-data/preferences.json | 10 ++ .../change-version/change-version.spec.ts | 60 ++++++++ .../fixtures/collection/opencollection.yml | 4 + .../init-user-data/preferences.json | 10 ++ .../fixtures/collection/bruno.json | 1 + .../generate-docs/generate-docs.spec.ts | 2 +- .../fixtures/collection/bruno.json | 1 + .../migrate-to-yml/migrate-to-yml.spec.ts | 4 + 32 files changed, 834 insertions(+), 19 deletions(-) create mode 100644 packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/StyledWrapper.js create mode 100644 packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.js create mode 100644 packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js create mode 100644 packages/bruno-converters/tests/opencollection/collection-version.spec.js create mode 100644 tests/collection/change-version-bru/change-version-bru.spec.ts create mode 100644 tests/collection/change-version-bru/fixtures/collection/bruno.json create mode 100644 tests/collection/change-version-bru/init-user-data/preferences.json create mode 100644 tests/collection/change-version/change-version.spec.ts create mode 100644 tests/collection/change-version/fixtures/collection/opencollection.yml create mode 100644 tests/collection/change-version/init-user-data/preferences.json diff --git a/packages/bruno-app/src/components/CollectionSettings/Overview/Info/StyledWrapper.js b/packages/bruno-app/src/components/CollectionSettings/Overview/Info/StyledWrapper.js index 8b1938e49ef..75a578d77f9 100644 --- a/packages/bruno-app/src/components/CollectionSettings/Overview/Info/StyledWrapper.js +++ b/packages/bruno-app/src/components/CollectionSettings/Overview/Info/StyledWrapper.js @@ -39,6 +39,15 @@ const StyledWrapper = styled.div` } } + &.version { + background-color: ${(props) => rgba(props.theme.colors.text.yellow, 0.1)}; + border: 1px solid ${(props) => rgba(props.theme.colors.text.yellow, 0.1)}; + + svg { + color: ${(props) => props.theme.colors.text.yellow}; + } + } + &.generate-docs { background-color: ${(props) => rgba(props.theme.accents.primary, 0.08)}; border: 1px solid ${(props) => rgba(props.theme.accents.primary, 0.09)}; diff --git a/packages/bruno-app/src/components/CollectionSettings/Overview/Info/index.js b/packages/bruno-app/src/components/CollectionSettings/Overview/Info/index.js index 86e38d3fcd6..6be8ef1fcb3 100644 --- a/packages/bruno-app/src/components/CollectionSettings/Overview/Info/index.js +++ b/packages/bruno-app/src/components/CollectionSettings/Overview/Info/index.js @@ -1,11 +1,12 @@ import React from 'react'; import { getTotalRequestCountInCollection } from 'utils/collections/'; -import { IconFolder, IconWorld, IconApi, IconShare, IconBook } from '@tabler/icons'; -import { areItemsLoading, getItemsLoadStats } from 'utils/collections/index'; +import { IconFolder, IconWorld, IconApi, IconShare, IconBook, IconTag } from '@tabler/icons'; +import { areItemsLoading, getItemsLoadStats, getCollectionVersion } from 'utils/collections/index'; import { useState } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import ShareCollection from 'components/ShareCollection/index'; import GenerateDocumentation from 'components/Sidebar/Collections/Collection/GenerateDocumentation'; +import ChangeCollectionVersion from 'components/Sidebar/Collections/Collection/ChangeCollectionVersion'; import { addTab } from 'providers/ReduxStore/slices/tabs'; import StyledWrapper from './StyledWrapper'; import Migration from '../Migration'; @@ -18,6 +19,9 @@ const Info = ({ collection }) => { const { loading: itemsLoadingCount, total: totalItems } = getItemsLoadStats(collection); const [showShareCollectionModal, toggleShowShareCollectionModal] = useState(false); const [showGenerateDocumentationModal, setShowGenerateDocumentationModal] = useState(false); + const [showChangeVersionModal, setShowChangeVersionModal] = useState(false); + + const collectionVersion = getCollectionVersion(collection); const globalEnvironments = useSelector((state) => state.globalEnvironments.globalEnvironments); @@ -45,6 +49,22 @@ const Info = ({ collection }) => { +
setShowChangeVersionModal(true)} data-testid="info-version-row"> +
+ +
+
+
Version
+
+ {collectionVersion + ? {collectionVersion} + : Not Set} + Change +
+
+
+ {showChangeVersionModal && setShowChangeVersionModal(false)} />} + {/* Environments Row */}
diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/StyledWrapper.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/StyledWrapper.js new file mode 100644 index 00000000000..48051991595 --- /dev/null +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/StyledWrapper.js @@ -0,0 +1,145 @@ +import styled from 'styled-components'; + +export const ModalTitle = styled.div` + color: ${(props) => props.theme.colors.text.subtext2}; + font-weight: 600; + font-size: ${(props) => props.theme.font.size.base}; + line-height: 18px; +`; + +const StyledWrapper = styled.div` + width: 100%; + .subheader { + margin-bottom: 0.5rem; + color: ${(props) => props.theme.colors.text.muted}; + font-weight: 400; + font-size: ${(props) => props.theme.font.size.base}; + line-height: 18px; + + .collection-name { + color: ${(props) => props.theme.text}; + font-weight: 600; + } + } + + .version-card { + width: 100%; + border: 1px solid ${(props) => props.theme.border.border1}; + border-radius: ${(props) => props.theme.border.radius.md}; + overflow: hidden; + + .version-row { + display: flex; + align-items: flex-start; + gap: 1rem; + padding: 1rem; + } + + .version-col { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; + gap: 0.5rem; + } + + .col-label { + color: ${(props) => props.theme.text}; + font-weight: 500; + font-size: ${(props) => props.theme.font.size.base}; + line-height: 20px; + } + + .current-value { + color: ${(props) => props.theme.text}; + font-weight: 400; + font-size: ${(props) => props.theme.font.size.sm}; + line-height: 20px; + + .unset { + font-family: inherit; + font-style: italic; + } + } + + .arrow { + align-self: center; + color: ${(props) => props.theme.colors.text.muted}; + flex-shrink: 0; + } + + .input-wrap { + position: relative; + + .textbox { + padding-right: 2.25rem; + color: ${(props) => props.theme.text}; + font-weight: 400; + font-size: ${(props) => props.theme.font.size.sm}; + line-height: 20px; + } + + .copy-btn { + position: absolute; + top: 50%; + right: 0.5rem; + transform: translateY(-50%); + display: inline-flex; + align-items: center; + justify-content: center; + padding: 0.25rem; + background: transparent; + border: none; + cursor: pointer; + color: ${(props) => props.theme.colors.text.muted}; + + &:hover:not(:disabled) { + color: ${(props) => props.theme.text}; + } + + &:disabled { + opacity: 0.5; + cursor: default; + } + } + } + } + + .preview { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 0.25rem; + padding: 0.625rem 1rem; + border-top: 1px solid ${(props) => props.theme.border.border1}; + background-color: ${(props) => props.theme.background.mantle}; + color: ${(props) => props.theme.text}; + font-weight: 400; + font-size: ${(props) => props.theme.font.size.sm}; + line-height: 20px; + + strong { + font-weight: 700; + } + + .old { + color: ${(props) => props.theme.colors.text.danger}; + font-weight: 700; + word-break: break-all; + } + + .new { + font-family: monospace; + color: ${(props) => props.theme.colors.text.green}; + font-weight: 700; + word-break: break-all; + } + + .preview-arrow { + color: ${(props) => props.theme.colors.text.muted}; + flex-shrink: 0; + } + } +`; + +export default StyledWrapper; diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.js new file mode 100644 index 00000000000..32d123e81d2 --- /dev/null +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.js @@ -0,0 +1,141 @@ +import React, { useEffect, useMemo, useRef, useState } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import { IconArrowRight, IconCopy, IconCheck, IconAlertTriangle } from '@tabler/icons'; + +import Modal from 'components/Modal'; +import Portal from 'components/Portal'; +import { findCollectionByUid, getCollectionVersion, isOpenCollectionFormat } from 'utils/collections/index'; +import { saveCollectionVersion } from 'providers/ReduxStore/slices/collections/actions'; +import StyledWrapper, { ModalTitle } from './StyledWrapper'; + +const CollectionNotFound = ({ onClose }) => ( + + + +
+ + Collection not found. It may have been deleted or is no longer available. +
+
+
+
+); + +const ChangeCollectionVersion = ({ collectionUid, onClose }) => { + const dispatch = useDispatch(); + const inputRef = useRef(null); + const collection = useSelector((state) => findCollectionByUid(state.collections.collections, collectionUid)); + + const currentVersion = getCollectionVersion(collection); + const isYml = isOpenCollectionFormat(collection); + const targetKey = isYml ? 'info.version' : 'collectionVersion'; + const targetFile = isYml ? 'opencollection.yml' : 'bruno.json'; + const [newVersion, setNewVersion] = useState(currentVersion); + const [isSaving, setIsSaving] = useState(false); + const [copied, setCopied] = useState(false); + + useEffect(() => { + if (inputRef.current) { + inputRef.current.focus(); + inputRef.current.select(); + } + }, []); + + const trimmedVersion = newVersion.trim(); + const canSubmit = useMemo( + () => trimmedVersion.length > 0 && trimmedVersion !== currentVersion, + [trimmedVersion, currentVersion] + ); + + const handleConfirm = () => { + if (!canSubmit || isSaving) return; + setIsSaving(true); + dispatch(saveCollectionVersion(collectionUid, trimmedVersion)) + .then(() => onClose()) + .catch(() => setIsSaving(false)); + }; + + const handleCopy = () => { + if (!trimmedVersion) return; + navigator.clipboard?.writeText(trimmedVersion); + setCopied(true); + setTimeout(() => setCopied(false), 1500); + }; + + if (!collection) { + return ; + } + + return ( + + Change Collection Version} + confirmText={isSaving ? 'Updating...' : 'Update Version'} + cancelText="Cancel" + handleConfirm={handleConfirm} + handleCancel={onClose} + confirmDisabled={!canSubmit || isSaving} + dataTestId="change-version" + > + +
+ Collection: {collection.name} +
+ +
+
+
+
Current Version
+
+ {currentVersion || Not Set} +
+
+ + + +
+
New Version
+
+ setNewVersion(e.target.value)} + data-testid="change-version-input" + /> + +
+
+
+ +

+ Updates {targetKey} in {targetFile} from{' '} + {currentVersion || '(none)'} + + {trimmedVersion || '…'} +

+
+
+
+
+ ); +}; + +export default ChangeCollectionVersion; diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js new file mode 100644 index 00000000000..f3c75f70cf6 --- /dev/null +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js @@ -0,0 +1,121 @@ +import '@testing-library/jest-dom'; +import React from 'react'; +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; +import { Provider } from 'react-redux'; +import { configureStore, createSlice } from '@reduxjs/toolkit'; +import ChangeCollectionVersion from './index'; + +const mockSaveCollectionVersion = jest.fn(); + +jest.mock('providers/ReduxStore/slices/collections/actions', () => ({ + saveCollectionVersion: (collectionUid, version) => { + mockSaveCollectionVersion(collectionUid, version); + return () => Promise.resolve(); + } +})); + +jest.mock('components/Portal', () => ({ + __esModule: true, + default: ({ children }) =>
{children}
+})); + +jest.mock('./StyledWrapper', () => ({ + __esModule: true, + default: ({ children, className }) =>
{children}
+})); + +jest.mock('components/Modal', () => ({ + __esModule: true, + default: (props) => ( +
+
{props.title}
+ {props.children} + +
+ ) +})); + +const buildCollection = (overrides = {}) => ({ + uid: 'collection-1', + name: 'Bruno-Testbench', + pathname: '/tmp/bruno-testbench', + brunoConfig: { opencollection: '1.0.0', name: 'Bruno-Testbench', version: 'v1.0.0' }, + ...overrides +}); + +const renderModal = (collection, onClose = jest.fn()) => { + const collections = collection ? [collection] : []; + const slice = createSlice({ name: 'collections', initialState: { collections }, reducers: {} }); + const store = configureStore({ reducer: { collections: slice.reducer } }); + const utils = render( + + + + ); + return { ...utils, onClose }; +}; + +beforeEach(() => { + mockSaveCollectionVersion.mockClear(); +}); + +describe('ChangeCollectionVersion', () => { + it('lets you save only when the new version is different from the current one', () => { + renderModal(buildCollection()); + const submit = screen.getByTestId('change-version-submit-btn'); + const input = screen.getByTestId('change-version-input'); + + expect(submit).toBeDisabled(); + fireEvent.change(input, { target: { value: '2' } }); + expect(submit).toBeEnabled(); + fireEvent.change(input, { target: { value: 'v1.0.0' } }); + expect(submit).toBeDisabled(); + }); + + it('does not let you save an empty or blank version', () => { + renderModal(buildCollection()); + fireEvent.change(screen.getByTestId('change-version-input'), { target: { value: ' ' } }); + expect(screen.getByTestId('change-version-submit-btn')).toBeDisabled(); + }); + + it('removes extra spaces around the version before saving, then closes', async () => { + const { onClose } = renderModal(buildCollection()); + + fireEvent.change(screen.getByTestId('change-version-input'), { target: { value: ' 2.0.0 ' } }); + fireEvent.click(screen.getByTestId('change-version-submit-btn')); + + expect(mockSaveCollectionVersion).toHaveBeenCalledWith('collection-1', '2.0.0'); + await waitFor(() => expect(onClose).toHaveBeenCalled()); + }); + + it('for a bru collection, the preview mentions bruno.json and collectionVersion', () => { + renderModal(buildCollection({ brunoConfig: { version: '1', name: 'Legacy', type: 'collection' } })); + fireEvent.change(screen.getByTestId('change-version-input'), { target: { value: '2' } }); + + const preview = screen.getByTestId('change-version-preview'); + expect(preview).toHaveTextContent('collectionVersion'); + expect(preview).toHaveTextContent('bruno.json'); + expect(preview).not.toHaveTextContent('info.version'); + }); + + it('shows "1" for a yml collection that has no version yet', () => { + renderModal(buildCollection({ brunoConfig: { opencollection: '1.0.0', name: 'Bruno-Testbench' } })); + + expect(screen.getByTestId('change-version-current')).toHaveTextContent('1'); + expect(screen.getByTestId('change-version-input')).toHaveValue('1'); + }); + + it('shows a "Collection not found" message when the collection is missing', () => { + renderModal(null); + + expect(screen.getByTestId('modal-title')).toHaveTextContent('Change Collection Version'); + expect(screen.getByText(/Collection not found/i)).toBeInTheDocument(); + expect(screen.queryByTestId('change-version-input')).not.toBeInTheDocument(); + }); +}); diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.js index d37eb98de1e..2410488cfa8 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.js @@ -10,7 +10,9 @@ const CollectionVersionInfo = ({ name, version, folderCount = 0, requestCount = {name} {version ? ( {`Version: ${version}`} - ) : null} + ) : ( + Not Set + )}

{`${folderCount} ${folderLabel}`} diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/StyledWrapper.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/StyledWrapper.js index ccd67dbd008..2ea55552e47 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/StyledWrapper.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/StyledWrapper.js @@ -44,6 +44,10 @@ const StyledWrapper = styled.div` white-space: nowrap; } + .version-value.unset { + font-style: italic; + } + .version-summary { display: flex; align-items: center; diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/index.js index bac6ff49928..82c3cf630da 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/index.js @@ -13,7 +13,7 @@ import StyledWrapper from './StyledWrapper'; import CollectionVersionInfo from './CollectionVersionInfo'; import EnvironmentSelectionList from './EnvironmentSelectionList'; import { useApp } from 'providers/App'; -import { transformCollectionToSaveToExportAsFile, findCollectionByUid, areItemsLoading, sortItemsBySidebarOrder, getCollectionItemCounts } from 'utils/collections/index'; +import { transformCollectionToSaveToExportAsFile, findCollectionByUid, areItemsLoading, sortItemsBySidebarOrder, getCollectionItemCounts, getCollectionVersion } from 'utils/collections/index'; import { brunoToOpenCollection } from '@usebruno/converters'; import { sanitizeName } from 'utils/common/regex'; import { escapeHtml } from 'utils/response'; @@ -76,8 +76,7 @@ const GenerateDocumentation = ({ onClose, collectionUid }) => { [collection] ); - // The collection's current version (read-only here); formatted for display below. - const currentVersion = collection?.version; + const currentVersion = getCollectionVersion(collection); // Folder + request counts, computed from the collection tree (recursively). const { folderCount, requestCount } = useMemo( diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index 16b7f2c0a9a..37abc83c406 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -44,6 +44,7 @@ import { responseReceived, updateLastAction, setCollectionSecurityConfig, + updateCollectionVersion as _updateCollectionVersion, collectionAddOauth2CredentialsByUrl, collectionClearOauth2CredentialsByUrlAndCredentialsId, initRunRequestEvent, @@ -313,6 +314,42 @@ export const saveCollectionRoot = (collectionUid) => (dispatch, getState) => { }); }; +export const saveCollectionVersion = (collectionUid, version) => (dispatch, getState) => { + const state = getState(); + const collection = findCollectionByUid(state.collections.collections, collectionUid); + + return new Promise((resolve, reject) => { + if (!collection) { + return reject(new Error('Collection not found')); + } + + const updatedVersion = typeof version === 'string' ? version.trim() : ''; + + const isYml = Boolean(collection.brunoConfig?.opencollection); + const versionKey = isYml ? 'version' : 'collectionVersion'; + const brunoConfigToSave = { ...(collection.brunoConfig || {}) }; + if (updatedVersion) { + brunoConfigToSave[versionKey] = updatedVersion; + } else { + delete brunoConfigToSave[versionKey]; + } + + const { ipcRenderer } = window; + + ipcRenderer + .invoke('renderer:update-bruno-config', brunoConfigToSave, collection.pathname, collection.root) + .then(() => { + dispatch(_updateCollectionVersion({ collectionUid, version: updatedVersion })); + toast.success('Collection version updated'); + }) + .then(resolve) + .catch((err) => { + toast.error('Failed to update collection version'); + reject(err); + }); + }); +}; + export const saveFolderRoot = (collectionUid, folderUid, silent = false) => (dispatch, getState) => { const state = getState(); const collection = findCollectionByUid(state.collections.collections, collectionUid); diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index 2dc35d5cc4e..19ae8e5a903 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -287,6 +287,25 @@ export const collectionsSlice = createSlice({ collection.securityConfig = action.payload.securityConfig; } }, + updateCollectionVersion: (state, action) => { + const collection = findCollectionByUid(state.collections, action.payload.collectionUid); + if (collection) { + const version = action.payload.version; + const versionKey = collection.brunoConfig?.opencollection ? 'version' : 'collectionVersion'; + const applyVersion = (target) => { + if (!target) return; + if (version) { + target[versionKey] = version; + } else { + delete target[versionKey]; + } + }; + collection.brunoConfig = collection.brunoConfig || {}; + applyVersion(collection.brunoConfig); + // Keep any unsaved brunoConfig draft in sync so a later settings-save can't wipe it. + applyVersion(collection.draft?.brunoConfig); + } + }, brunoConfigUpdateEvent: (state, action) => { const { collectionUid, brunoConfig } = action.payload; const collection = findCollectionByUid(state.collections, collectionUid); @@ -3046,7 +3065,7 @@ export const collectionsSlice = createSlice({ // Persist the selection to the UI state snapshot const { ipcRenderer } = window; if (ipcRenderer) { - const extension = collection?.brunoConfig?.version === '1' ? 'bru' : 'yml'; + const extension = collection?.brunoConfig?.opencollection ? 'yml' : 'bru'; const environmentPath = environment?.pathname || (environment?.name && collection?.pathname ? path.join(collection.pathname, 'environments', `${environment.name}.${extension}`) @@ -3889,6 +3908,7 @@ export const { updateCollectionLoadingState, collectionLoadedFromTree, setCollectionSecurityConfig, + updateCollectionVersion, brunoConfigUpdateEvent, renameCollection, removeCollection, diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index 0c10eb31bce..5c06039a110 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -1256,6 +1256,20 @@ const getPathParams = (item) => { return pathParams; }; +export const isOpenCollectionFormat = (collection) => Boolean(collection?.brunoConfig?.opencollection); + +export const getCollectionVersion = (collection) => { + const brunoConfig = collection?.brunoConfig; + if (!brunoConfig) return ''; + if (isOpenCollectionFormat(collection)) { + // yml: the user version is info.version (brunoConfig.version). When the file has none, + // default to '1' (mirroring the schema version) so a yml collection always shows a version. + return brunoConfig.version || '1'; + } + // bru: only the explicit collectionVersion; an existing bru collection without one shows "Not Set". + return brunoConfig.collectionVersion || ''; +}; + export const getTotalRequestCountInCollection = (collection) => { let count = 0; each(collection.items, (item) => { diff --git a/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts b/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts index 0bc59b372bb..015062419b8 100644 --- a/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts +++ b/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts @@ -93,7 +93,15 @@ export const brunoToOpenCollection = (collection: BrunoCollection): OpenCollecti } }; - const config = toOpenCollectionConfig(collection.brunoConfig as BrunoConfig); + const brunoConfig = collection.brunoConfig as BrunoConfig | undefined; + + const isOpenCollectionFormat = Boolean(brunoConfig?.opencollection); + const collectionVersion = isOpenCollectionFormat ? brunoConfig?.version : brunoConfig?.collectionVersion; + if (openCollection.info && collectionVersion != null && collectionVersion !== '') { + openCollection.info.version = String(collectionVersion); + } + + const config = toOpenCollectionConfig(brunoConfig); if (config) { openCollection.config = config; } @@ -150,11 +158,11 @@ export const brunoToOpenCollection = (collection: BrunoCollection): OpenCollecti presets?: BrunoPresets; } = {}; - if ((collection.brunoConfig as BrunoConfig)?.ignore?.length) { - brunoExtension.ignore = (collection.brunoConfig as BrunoConfig).ignore; + if (brunoConfig?.ignore?.length) { + brunoExtension.ignore = brunoConfig.ignore; } - const presets = (collection.brunoConfig as BrunoConfig)?.presets; + const presets = brunoConfig?.presets; if (presets?.requestType || presets?.requestUrl) { brunoExtension.presets = {}; if (presets.requestType) { diff --git a/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts b/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts index 2b8d0a5bcf0..1c377f64f3a 100644 --- a/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts +++ b/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts @@ -23,6 +23,10 @@ const fromOpenCollectionConfig = (oc: OpenCollection): BrunoConfig => { ignore: ignoreList }; + if (oc.info?.version != null && oc.info.version !== '') { + brunoConfig.collectionVersion = String(oc.info.version); + } + if (brunoExtension?.presets?.requestType || brunoExtension?.presets?.requestUrl) { brunoConfig.presets = {}; if (brunoExtension.presets.requestType) { diff --git a/packages/bruno-converters/src/opencollection/types.ts b/packages/bruno-converters/src/opencollection/types.ts index 0be53a34c53..ef39a41bbd9 100644 --- a/packages/bruno-converters/src/opencollection/types.ts +++ b/packages/bruno-converters/src/opencollection/types.ts @@ -175,6 +175,10 @@ export interface BrunoPresets { export interface BrunoConfig { version?: string; + // bru only: the user-facing collection version (bruno.json key, sibling of the marker). + collectionVersion?: string; + // present only for OpenCollection (yml) collections; its presence marks the format. + opencollection?: string; name?: string; type?: string; ignore?: string[]; diff --git a/packages/bruno-converters/tests/opencollection/collection-version.spec.js b/packages/bruno-converters/tests/opencollection/collection-version.spec.js new file mode 100644 index 00000000000..cb82198bf64 --- /dev/null +++ b/packages/bruno-converters/tests/opencollection/collection-version.spec.js @@ -0,0 +1,45 @@ +import { describe, it, expect } from '@jest/globals'; +import { brunoToOpenCollection } from '../../src/opencollection/bruno-to-opencollection'; +import { openCollectionToBruno } from '../../src/opencollection/opencollection-to-bruno'; + +describe('openCollectionToBruno (import): keeps the collection version', () => { + it('keeps the version as-is when importing', () => { + const { brunoConfig } = openCollectionToBruno({ opencollection: '1.0.0', info: { name: 'API', version: 'v2.3.4' } }); + expect(brunoConfig.collectionVersion).toBe('v2.3.4'); + }); + + it('turns a number version into text (2 becomes "2")', () => { + const { brunoConfig } = openCollectionToBruno({ opencollection: '1.0.0', info: { name: 'API', version: 2 } }); + expect(brunoConfig.collectionVersion).toBe('2'); + }); + + it('has no version when the imported file has none', () => { + const { brunoConfig } = openCollectionToBruno({ opencollection: '1.0.0', info: { name: 'API' } }); + expect(brunoConfig.collectionVersion).toBeUndefined(); + }); +}); + +describe('brunoToOpenCollection (export): writes the collection version', () => { + it('uses the bru version (collectionVersion) for a bru collection', () => { + const oc = brunoToOpenCollection({ name: 'API', brunoConfig: { version: '1', collectionVersion: 'v2.3.4' }, items: [] }); + expect(oc.info.version).toBe('v2.3.4'); + }); + + it('uses the yml version (info.version) for a yml collection', () => { + const oc = brunoToOpenCollection({ name: 'API', brunoConfig: { opencollection: '1.0.0', version: 'v9.9' }, items: [] }); + expect(oc.info.version).toBe('v9.9'); + }); + + it('writes no version when the collection has none', () => { + const oc = brunoToOpenCollection({ name: 'API', brunoConfig: {}, items: [] }); + expect(oc.info.version).toBeUndefined(); + }); +}); + +describe('collection version: export then import keeps it the same', () => { + it('keeps the same version after exporting and importing again', () => { + const oc = brunoToOpenCollection({ name: 'API', brunoConfig: { collectionVersion: '1.2.3-beta' }, items: [] }); + const { brunoConfig } = openCollectionToBruno(oc); + expect(brunoConfig.collectionVersion).toBe('1.2.3-beta'); + }); +}); diff --git a/packages/bruno-electron/src/app/collections.js b/packages/bruno-electron/src/app/collections.js index f5c8a8080db..a2b8ee41469 100644 --- a/packages/bruno-electron/src/app/collections.js +++ b/packages/bruno-electron/src/app/collections.js @@ -19,10 +19,14 @@ const registerScratchCollectionPath = (scratchPath) => { const configSchema = Yup.object({ name: Yup.string().max(256, 'name must be 256 characters or less').required('name is required'), type: Yup.string().oneOf(['collection']).required('type is required'), - // For BRU format collections - version: Yup.string().oneOf(['1']).notRequired(), + version: Yup.string().when('opencollection', { + is: (opencollection) => Boolean(opencollection), + then: Yup.string().notRequired(), + otherwise: Yup.string().oneOf(['1']).notRequired() + }), // For YAML format collections (opencollection) opencollection: Yup.string().notRequired(), + collectionVersion: Yup.string().notRequired(), // OpenAPI sync configuration (array, one entry per synced spec) openapi: Yup.array().of( Yup.object({ diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index bc2b759c60d..cd3501633c6 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -203,6 +203,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { const uid = generateUidBasedOnHash(dirPath); let brunoConfig = { version: '1', + collectionVersion: '1', name: collectionName, type: 'collection', ignore: ['node_modules', '.git'] @@ -214,9 +215,9 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { name: collectionName } }; - // For YAML collections, set opencollection instead of version brunoConfig = { opencollection: '1.0.0', + version: '1', name: collectionName, type: 'collection', ignore: ['node_modules', '.git'] @@ -313,7 +314,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { brunoConfig.filesCount = filesCount; mainWindow.webContents.send('main:collection-opened', dirPath, uid, brunoConfig); - ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid); + ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid, brunoConfig); } ); @@ -1386,10 +1387,15 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { if (!brunoConfig) { brunoConfig = { version: '1', + collectionVersion: '1', name: collection.name, type: 'collection', ignore: ['node_modules', '.git'] }; + } else if (!brunoConfig.collectionVersion) { + // Imports create new collection files; default the user-facing version when the + // source didn't carry one (a present version, e.g. OpenCollection info.version, is kept). + brunoConfig.collectionVersion = '1'; } if (brunoConfig.proxy) { brunoConfig.proxy = transformProxyConfig(brunoConfig.proxy); @@ -1413,6 +1419,12 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { if (format === 'yml') { brunoConfig.opencollection = '1.0.0'; + // For yml the user-facing version is info.version (brunoConfig.version); map the + // neutral collectionVersion onto it and keep collectionVersion out of the yaml. + if (brunoConfig.collectionVersion) { + brunoConfig.version = brunoConfig.collectionVersion; + } + delete brunoConfig.collectionVersion; const collectionContent = await stringifyCollection(coll.root, brunoConfig, { format }); await writeFile(path.join(collectionPath, 'opencollection.yml'), collectionContent); } else if (format === 'bru') { @@ -1692,7 +1704,22 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { const content = await stringifyJson(transformedBrunoConfig); await writeFile(brunoConfigPath, content); } else if (format === 'yml') { - const content = await stringifyCollection(collectionRoot, transformedBrunoConfig, { format }); + // opencollection.yml holds both config AND the collection root. If the caller + // didn't supply a root (e.g. a config-only update before the tree finished + // loading), recover it from disk so request defaults/docs/scripts aren't wiped. + let rootToWrite = collectionRoot; + if (!rootToWrite) { + const ocYmlPath = path.join(collectionPath, 'opencollection.yml'); + if (fs.existsSync(ocYmlPath)) { + try { + const existing = fs.readFileSync(ocYmlPath, 'utf8'); + rootToWrite = parseCollection(existing, { format }).collectionRoot; + } catch (e) { + rootToWrite = collectionRoot; + } + } + } + const content = await stringifyCollection(rootToWrite, transformedBrunoConfig, { format }); await writeFile(path.join(collectionPath, 'opencollection.yml'), content); } else { throw new Error(`Invalid collection format: ${format}`); @@ -2202,6 +2229,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { const brunoConfig = { opencollection: '1.0.0', + version: '1', name: 'Scratch', type: 'collection', ignore: ['node_modules', '.git'] @@ -2587,7 +2615,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { } let collectionName = 'Imported Collection'; - let brunoConfig = { name: collectionName, version: '1', type: 'collection', ignore: ['node_modules', '.git'] }; + let brunoConfig = { name: collectionName, version: '1', collectionVersion: '1', type: 'collection', ignore: ['node_modules', '.git'] }; if (fs.existsSync(openCollectionYmlPath)) { try { const content = fs.readFileSync(openCollectionYmlPath, 'utf8'); @@ -2667,8 +2695,13 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { } const ymlBrunoConfig = { ...brunoConfig }; - delete ymlBrunoConfig.version; + delete ymlBrunoConfig.version; // drop the bru format marker ymlBrunoConfig.opencollection = '1.0.0'; + // Carry the user-facing version: bru's collectionVersion becomes yml's info.version. + if (ymlBrunoConfig.collectionVersion) { + ymlBrunoConfig.version = ymlBrunoConfig.collectionVersion; + } + delete ymlBrunoConfig.collectionVersion; const ocYmlPath = path.join(collectionPathname, 'opencollection.yml'); const ymlCollectionContent = stringifyCollection(collectionRoot, ymlBrunoConfig, { format: 'yml' }); diff --git a/packages/bruno-electron/src/utils/collection-import.js b/packages/bruno-electron/src/utils/collection-import.js index 4d541d60f07..763b1154799 100644 --- a/packages/bruno-electron/src/utils/collection-import.js +++ b/packages/bruno-electron/src/utils/collection-import.js @@ -88,10 +88,13 @@ async function importCollection(collection, collectionLocation, mainWindow, uniq if (!brunoConfig) { brunoConfig = { version: '1', + collectionVersion: '1', name: collection.name, type: 'collection', ignore: ['node_modules', '.git'] }; + } else if (!brunoConfig.collectionVersion) { + brunoConfig.collectionVersion = '1'; } if (brunoConfig.proxy) { @@ -107,6 +110,10 @@ async function importCollection(collection, collectionLocation, mainWindow, uniq let brunoConfig = getBrunoJsonConfig(collection); if (format === 'yml') { + if (brunoConfig.collectionVersion) { + brunoConfig.version = brunoConfig.collectionVersion; + } + delete brunoConfig.collectionVersion; const collectionContent = await stringifyCollection(collection.root, brunoConfig, { format }); await writeFile(path.join(collectionPath, 'opencollection.yml'), collectionContent); } else if (format === 'bru') { diff --git a/packages/bruno-filestore/src/formats/yml/parseCollection.spec.ts b/packages/bruno-filestore/src/formats/yml/parseCollection.spec.ts index 93c169be5e1..826dba04ac9 100644 --- a/packages/bruno-filestore/src/formats/yml/parseCollection.spec.ts +++ b/packages/bruno-filestore/src/formats/yml/parseCollection.spec.ts @@ -51,3 +51,20 @@ request: expect(reqVars[5]).toMatchObject({ name: 'cfg', value: 'not-json', dataType: 'object' }); }); }); + +describe('parseCollection — reading the collection version', () => { + it('reads the version from the file as text', () => { + const { brunoConfig } = parseCollection('opencollection: "1.0.0"\ninfo:\n name: c\n version: v1.0.0\n'); + expect(brunoConfig.version).toBe('v1.0.0'); + }); + + it('turns a number version into text (2 becomes "2")', () => { + const { brunoConfig } = parseCollection('opencollection: "1.0.0"\ninfo:\n name: c\n version: 2\n'); + expect(brunoConfig.version).toBe('2'); + }); + + it('has no version when the file does not have one', () => { + const { brunoConfig } = parseCollection('opencollection: "1.0.0"\ninfo:\n name: c\n'); + expect(brunoConfig.version).toBeUndefined(); + }); +}); diff --git a/packages/bruno-filestore/src/formats/yml/parseCollection.ts b/packages/bruno-filestore/src/formats/yml/parseCollection.ts index ecb57bbf24b..da3789fc513 100644 --- a/packages/bruno-filestore/src/formats/yml/parseCollection.ts +++ b/packages/bruno-filestore/src/formats/yml/parseCollection.ts @@ -26,6 +26,10 @@ const parseCollection = (ymlString: string): ParsedCollection => { ignore: [] }; + if (oc.info?.version != null && oc.info.version !== '') { + brunoConfig.version = ensureString(oc.info.version, ''); + } + const brunoExtension = (oc.extensions as any)?.bruno; if (brunoExtension?.ignore && Array.isArray(brunoExtension.ignore)) { brunoConfig.ignore = brunoExtension.ignore; diff --git a/packages/bruno-filestore/src/formats/yml/stringifyCollection.spec.ts b/packages/bruno-filestore/src/formats/yml/stringifyCollection.spec.ts index fddb8985bbd..f6f1608dcc8 100644 --- a/packages/bruno-filestore/src/formats/yml/stringifyCollection.spec.ts +++ b/packages/bruno-filestore/src/formats/yml/stringifyCollection.spec.ts @@ -47,3 +47,31 @@ describe('stringifyCollection — typed request.variables', () => { expect(reqVars[4].dataType).toBeUndefined(); }); }); + +describe('stringifyCollection — writing the collection version', () => { + const baseRoot = { + meta: null, + request: { headers: [], auth: { mode: 'none' }, script: { req: null, res: null }, tests: null, vars: { req: [], res: [] } }, + docs: null + } as any; + + it('writes the version as-is and reads back the same value', () => { + const yml = stringifyCollection(baseRoot, { name: 'c', version: '2' }); + expect(yml).toMatch(/version:\s*['"]?2['"]?/); + expect(parseCollection(yml).brunoConfig.version).toBe('2'); + }); + + it('writes no version when the collection has none', () => { + const yml = stringifyCollection(baseRoot, { name: 'c' }); + expect(parseCollection(yml).brunoConfig.version).toBeUndefined(); + }); + + it('accepts any version text — there is no check on the format', () => { + // The version is free-form: users can set whatever they like. Each of these should be + // saved and read back exactly the same, without changing the format or rejecting it. + ['v1.0.0', '2', '1.2.3-beta', '2024.01.15', 'release-2024-Q3', 'anything-goes'].forEach((version) => { + const yml = stringifyCollection(baseRoot, { name: 'c', version }); + expect(parseCollection(yml).brunoConfig.version).toBe(version); + }); + }); +}); diff --git a/packages/bruno-filestore/src/formats/yml/stringifyCollection.ts b/packages/bruno-filestore/src/formats/yml/stringifyCollection.ts index d006510d433..a313e93f3dc 100644 --- a/packages/bruno-filestore/src/formats/yml/stringifyCollection.ts +++ b/packages/bruno-filestore/src/formats/yml/stringifyCollection.ts @@ -73,6 +73,10 @@ const stringifyCollection = (collectionRoot: any, brunoConfig: any): string => { name: brunoConfig.name || 'Untitled Collection' }; + if (brunoConfig.version != null && brunoConfig.version !== '') { + oc.info.version = String(brunoConfig.version); + } + // collection config if (hasCollectionConfig(brunoConfig)) { oc.config = {}; diff --git a/tests/collection/change-version-bru/change-version-bru.spec.ts b/tests/collection/change-version-bru/change-version-bru.spec.ts new file mode 100644 index 00000000000..3d156057e15 --- /dev/null +++ b/tests/collection/change-version-bru/change-version-bru.spec.ts @@ -0,0 +1,50 @@ +import fs from 'fs'; +import path from 'path'; +import { test, expect } from '../../../playwright'; +import { closeAllCollections, openCollectionSettings, selectCollectionPaneTab } from '../../utils/page'; + +const COLLECTION_NAME = 'BruVersionTest'; + +test.describe('Change Collection Version (bru collection)', () => { + test.afterEach(async ({ page }) => { + await closeAllCollections(page); + }); + + test('a bru collection with no version shows "Not Set", and saving writes it to bruno.json', async ({ + pageWithUserData: page, + collectionFixturePath + }) => { + const collectionPath = collectionFixturePath!; + const brunoJsonPath = path.join(collectionPath, 'bruno.json'); + + await test.step('the collection has no version yet (only the internal "1" marker)', async () => { + const config = JSON.parse(fs.readFileSync(brunoJsonPath, 'utf-8')); + expect(config.collectionVersion).toBeUndefined(); + expect(config.version).toBe('1'); // the format marker is untouched + }); + + await test.step('the overview shows the version as "Not Set"', async () => { + await openCollectionSettings(page, COLLECTION_NAME); + await selectCollectionPaneTab(page, 'overview'); + await expect(page.getByTestId('info-version-value')).toHaveText('Not Set'); + }); + + await test.step('a new version can be set in the popup', async () => { + await page.getByTestId('info-version-change').click(); + await expect(page.getByTestId('change-version-current')).toHaveText('Not Set'); + await expect(page.getByTestId('change-version-input')).toHaveValue(''); + + await page.getByTestId('change-version-input').fill('v2.3.4'); + await page.getByTestId('change-version-submit-btn').click(); + await expect(page.getByText('Collection version updated')).toBeVisible(); + }); + + await test.step('the screen shows the new version and bruno.json now has it (the "1" marker stays)', async () => { + await expect(page.getByTestId('info-version-value')).toHaveText('v2.3.4'); + + await expect + .poll(async () => JSON.parse(fs.readFileSync(brunoJsonPath, 'utf-8')), { timeout: 5000 }) + .toMatchObject({ version: '1', collectionVersion: 'v2.3.4' }); + }); + }); +}); diff --git a/tests/collection/change-version-bru/fixtures/collection/bruno.json b/tests/collection/change-version-bru/fixtures/collection/bruno.json new file mode 100644 index 00000000000..225d3b4cbaa --- /dev/null +++ b/tests/collection/change-version-bru/fixtures/collection/bruno.json @@ -0,0 +1,5 @@ +{ + "version": "1", + "name": "BruVersionTest", + "type": "collection" +} diff --git a/tests/collection/change-version-bru/init-user-data/preferences.json b/tests/collection/change-version-bru/init-user-data/preferences.json new file mode 100644 index 00000000000..e8528c5e91e --- /dev/null +++ b/tests/collection/change-version-bru/init-user-data/preferences.json @@ -0,0 +1,10 @@ +{ + "maximized": false, + "lastOpenedCollections": ["{{collectionPath}}"], + "preferences": { + "onboarding": { + "hasLaunchedBefore": true, + "hasSeenWelcomeModal": true + } + } +} diff --git a/tests/collection/change-version/change-version.spec.ts b/tests/collection/change-version/change-version.spec.ts new file mode 100644 index 00000000000..6bfe4c12016 --- /dev/null +++ b/tests/collection/change-version/change-version.spec.ts @@ -0,0 +1,60 @@ +import fs from 'fs'; +import path from 'path'; +import { test, expect } from '../../../playwright'; +import { closeAllCollections, openCollectionSettings, selectCollectionPaneTab } from '../../utils/page'; + +const COLLECTION_NAME = 'VersionEditTest'; + +test.describe('Change Collection Version (yml collection)', () => { + test.afterEach(async ({ page }) => { + await closeAllCollections(page); + }); + + test('changing the version updates the yml file and the screen', async ({ + pageWithUserData: page, + collectionFixturePath + }) => { + const collectionPath = collectionFixturePath!; + const ymlPath = path.join(collectionPath, 'opencollection.yml'); + + await test.step('the collection starts at version 1.0.0 on disk', async () => { + expect(fs.readFileSync(ymlPath, 'utf-8')).toMatch(/version:\s*["']?1\.0\.0["']?/); + }); + + await test.step('open the collection overview and read the current version', async () => { + await openCollectionSettings(page, COLLECTION_NAME); + await selectCollectionPaneTab(page, 'overview'); + await expect(page.getByTestId('info-version-value')).toHaveText('1.0.0'); + }); + + await test.step('open the Change Collection Version modal', async () => { + await page.getByTestId('info-version-change').click(); + await expect(page.getByTestId('change-version-current')).toHaveText('1.0.0'); + await expect(page.getByTestId('change-version-input')).toHaveValue('1.0.0'); + }); + + await test.step('the Update button stays off until the version is changed', async () => { + const submit = page.getByTestId('change-version-submit-btn'); + await expect(submit).toBeDisabled(); + await page.getByTestId('change-version-input').fill('2.0.0'); + await expect(submit).toBeEnabled(); + }); + + await test.step('the preview shows the old version changing to the new one', async () => { + const preview = page.getByTestId('change-version-preview'); + await expect(preview).toContainText('info.version'); + await expect(preview.locator('.old')).toHaveText('1.0.0'); + await expect(preview.locator('.new')).toHaveText('2.0.0'); + }); + + await test.step('saving updates both the file on disk and the screen', async () => { + await page.getByTestId('change-version-submit-btn').click(); + await expect(page.getByText('Collection version updated')).toBeVisible(); + await expect(page.getByTestId('info-version-value')).toHaveText('2.0.0'); + + await expect + .poll(async () => fs.readFileSync(ymlPath, 'utf-8'), { timeout: 5000 }) + .toMatch(/version:\s*["']?2\.0\.0["']?/); + }); + }); +}); diff --git a/tests/collection/change-version/fixtures/collection/opencollection.yml b/tests/collection/change-version/fixtures/collection/opencollection.yml new file mode 100644 index 00000000000..3173cff5f2a --- /dev/null +++ b/tests/collection/change-version/fixtures/collection/opencollection.yml @@ -0,0 +1,4 @@ +opencollection: "1.0.0" +info: + name: VersionEditTest + version: 1.0.0 diff --git a/tests/collection/change-version/init-user-data/preferences.json b/tests/collection/change-version/init-user-data/preferences.json new file mode 100644 index 00000000000..e8528c5e91e --- /dev/null +++ b/tests/collection/change-version/init-user-data/preferences.json @@ -0,0 +1,10 @@ +{ + "maximized": false, + "lastOpenedCollections": ["{{collectionPath}}"], + "preferences": { + "onboarding": { + "hasLaunchedBefore": true, + "hasSeenWelcomeModal": true + } + } +} diff --git a/tests/collection/generate-docs/fixtures/collection/bruno.json b/tests/collection/generate-docs/fixtures/collection/bruno.json index 6d5f1edfb2e..35709f5c98e 100644 --- a/tests/collection/generate-docs/fixtures/collection/bruno.json +++ b/tests/collection/generate-docs/fixtures/collection/bruno.json @@ -1,5 +1,6 @@ { "version": "1", + "collectionVersion": "2.5", "name": "GenerateDocsOrder", "type": "collection" } diff --git a/tests/collection/generate-docs/generate-docs.spec.ts b/tests/collection/generate-docs/generate-docs.spec.ts index 308ee66e78a..3c0cbb9a885 100644 --- a/tests/collection/generate-docs/generate-docs.spec.ts +++ b/tests/collection/generate-docs/generate-docs.spec.ts @@ -164,7 +164,7 @@ test.describe('Generate Documentation', () => { await expect(modal).toBeHidden(); }); - test('shows the collection name alongside the raw collection version', async ({ + test('shows the current collection version verbatim, consistent with the settings page', async ({ pageWithUserData: page }) => { const locators = buildCommonLocators(page); diff --git a/tests/collection/migrate-to-yml/fixtures/collection/bruno.json b/tests/collection/migrate-to-yml/fixtures/collection/bruno.json index ae83c17ca72..51ea9994a57 100644 --- a/tests/collection/migrate-to-yml/fixtures/collection/bruno.json +++ b/tests/collection/migrate-to-yml/fixtures/collection/bruno.json @@ -2,6 +2,7 @@ "version": "1", "name": "migration-test", "type": "collection", + "collectionVersion": "v9.9.9", "ignore": [ "node_modules", ".git" diff --git a/tests/collection/migrate-to-yml/migrate-to-yml.spec.ts b/tests/collection/migrate-to-yml/migrate-to-yml.spec.ts index 6abec54e0b8..4c4a54715d1 100644 --- a/tests/collection/migrate-to-yml/migrate-to-yml.spec.ts +++ b/tests/collection/migrate-to-yml/migrate-to-yml.spec.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import path from 'path'; +import jsyaml from 'js-yaml'; import { test, expect } from '../../../playwright'; import { closeAllCollections, openCollection, selectEnvironment, sendRequestAndWaitForResponse } from '../../utils/page'; @@ -81,6 +82,9 @@ test.describe('Migrate collection from bru to yml format', () => { const ocContent = fs.readFileSync(path.join(collectionPath, 'opencollection.yml'), 'utf8'); expect(ocContent).toContain('opencollection'); expect(ocContent).toContain('migration-test'); + + const oc = jsyaml.load(ocContent) as { info?: { version?: string } }; + expect(oc.info?.version).toBe('v9.9.9'); }); await test.step('Verify request yml files preserve data', async () => { From 65a9d0890373ba04f092f2f230fb34d3d57ab540 Mon Sep 17 00:00:00 2001 From: bruno-sachin Date: Thu, 2 Jul 2026 00:11:11 +0530 Subject: [PATCH 2/6] Conflicts resolved --- .../GenerateDocumentation/CollectionVersionInfo/index.spec.js | 4 ++-- tests/collection/generate-docs/generate-docs.spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.spec.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.spec.js index e05df180972..8b6806d411d 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.spec.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.spec.js @@ -14,9 +14,9 @@ describe('CollectionVersionInfo', () => { expect(screen.getByTestId('version-value')).toHaveTextContent('Version: 2.3-beta'); }); - it('omits the version when the collection has none', () => { + it('shows "Not Set" when the collection has no version', () => { render(); - expect(screen.queryByTestId('version-value')).not.toBeInTheDocument(); + expect(screen.getByTestId('version-value')).toHaveTextContent('Not Set'); }); it('renders folder and request counts and pluralizes them', () => { diff --git a/tests/collection/generate-docs/generate-docs.spec.ts b/tests/collection/generate-docs/generate-docs.spec.ts index 3c0cbb9a885..956f7778bf7 100644 --- a/tests/collection/generate-docs/generate-docs.spec.ts +++ b/tests/collection/generate-docs/generate-docs.spec.ts @@ -178,8 +178,8 @@ test.describe('Generate Documentation', () => { await expect(locators.generateDocs.collectionName()).toHaveText(COLLECTION_NAME); - // The version is shown exactly as the collection sets it. - await expect(locators.generateDocs.versionValue()).toHaveText('Version: 1'); + // The user-facing collection version (bruno.json `collectionVersion`), not the schema `version`. + await expect(locators.generateDocs.versionValue()).toHaveText('Version: 2.5'); // The fixture has 2 folders (Zoo, Aviary) and 5 requests (Lion, Bear, Parrot, // ReqAlpha, ReqBeta), counted recursively across the whole tree. From 7789f05dd26313c88150301579cee91226a28f35 Mon Sep 17 00:00:00 2001 From: bruno-sachin Date: Thu, 2 Jul 2026 14:02:18 +0530 Subject: [PATCH 3/6] Comments resolved --- .../ChangeCollectionVersion/StyledWrapper.js | 3 ++- .../Collection/ChangeCollectionVersion/index.js | 14 ++++++++------ .../ChangeCollectionVersion/index.spec.js | 5 +++++ .../CollectionVersionInfo/index.js | 6 +----- .../opencollection/bruno-to-opencollection.ts | 17 ++++++++--------- packages/bruno-electron/src/app/collections.js | 6 +----- .../change-version-bru.spec.ts | 13 +++++++++++++ .../init-user-data/preferences.json | 9 +-------- 8 files changed, 39 insertions(+), 34 deletions(-) diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/StyledWrapper.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/StyledWrapper.js index 48051991595..1d9ae067cb1 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/StyledWrapper.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/StyledWrapper.js @@ -8,7 +8,7 @@ export const ModalTitle = styled.div` `; const StyledWrapper = styled.div` - width: 100%; + max-width: 100%; .subheader { margin-bottom: 0.5rem; color: ${(props) => props.theme.colors.text.muted}; @@ -55,6 +55,7 @@ const StyledWrapper = styled.div` font-weight: 400; font-size: ${(props) => props.theme.font.size.sm}; line-height: 20px; + overflow-wrap: anywhere; .unset { font-family: inherit; diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.js index 32d123e81d2..a351fcc564b 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.js @@ -56,10 +56,12 @@ const ChangeCollectionVersion = ({ collectionUid, onClose }) => { }; const handleCopy = () => { - if (!trimmedVersion) return; - navigator.clipboard?.writeText(trimmedVersion); - setCopied(true); - setTimeout(() => setCopied(false), 1500); + if (!trimmedVersion || !navigator.clipboard) return; + navigator.clipboard.writeText(trimmedVersion) + .then(() => { + setCopied(true); + setTimeout(() => setCopied(false), 1500); + }).catch(() => {}); }; if (!collection) { @@ -70,7 +72,6 @@ const ChangeCollectionVersion = ({ collectionUid, onClose }) => { Change Collection Version} confirmText={isSaving ? 'Updating...' : 'Update Version'} cancelText="Cancel" @@ -106,7 +107,8 @@ const ChangeCollectionVersion = ({ collectionUid, onClose }) => { autoCorrect="off" autoCapitalize="off" spellCheck="false" - placeholder="e.g. 1.0.0" + placeholder="e.g. v1.0.0" + maxLength={50} value={newVersion} onChange={(e) => setNewVersion(e.target.value)} data-testid="change-version-input" diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js index f3c75f70cf6..1973f05c1e7 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js @@ -78,6 +78,11 @@ describe('ChangeCollectionVersion', () => { expect(submit).toBeDisabled(); }); + it('limits the version input at 50 characters', () => { + renderModal(buildCollection()); + expect(screen.getByTestId('change-version-input')).toHaveAttribute('maxlength', '50'); + }); + it('does not let you save an empty or blank version', () => { renderModal(buildCollection()); fireEvent.change(screen.getByTestId('change-version-input'), { target: { value: ' ' } }); diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.js index 2410488cfa8..f03cdbbeac9 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/GenerateDocumentation/CollectionVersionInfo/index.js @@ -8,11 +8,7 @@ const CollectionVersionInfo = ({ name, version, folderCount = 0, requestCount =

{name} - {version ? ( - {`Version: ${version}`} - ) : ( - Not Set - )} + {`Version: ${version || 'Not Set'}`}

{`${folderCount} ${folderLabel}`} diff --git a/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts b/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts index 015062419b8..26fe405ca11 100644 --- a/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts +++ b/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts @@ -86,21 +86,20 @@ const hasRequestDefaults = (root: BrunoCollectionRoot | undefined): boolean => { }; export const brunoToOpenCollection = (collection: BrunoCollection): OpenCollection => { + const brunoConfig = collection.brunoConfig as BrunoConfig | undefined; + + const isOpenCollectionFormat = Boolean(brunoConfig?.opencollection); + const collectionVersion = isOpenCollectionFormat ? brunoConfig?.version : brunoConfig?.collectionVersion; + const hasCollectionVersion = collectionVersion != null && collectionVersion !== ''; + const openCollection: OpenCollection = { opencollection: '1.0.0', info: { - name: collection.name || 'Untitled Collection' + name: collection.name || 'Untitled Collection', + ...(hasCollectionVersion ? { version: String(collectionVersion) } : {}) } }; - const brunoConfig = collection.brunoConfig as BrunoConfig | undefined; - - const isOpenCollectionFormat = Boolean(brunoConfig?.opencollection); - const collectionVersion = isOpenCollectionFormat ? brunoConfig?.version : brunoConfig?.collectionVersion; - if (openCollection.info && collectionVersion != null && collectionVersion !== '') { - openCollection.info.version = String(collectionVersion); - } - const config = toOpenCollectionConfig(brunoConfig); if (config) { openCollection.config = config; diff --git a/packages/bruno-electron/src/app/collections.js b/packages/bruno-electron/src/app/collections.js index a2b8ee41469..3e1ad7934c0 100644 --- a/packages/bruno-electron/src/app/collections.js +++ b/packages/bruno-electron/src/app/collections.js @@ -19,11 +19,7 @@ const registerScratchCollectionPath = (scratchPath) => { const configSchema = Yup.object({ name: Yup.string().max(256, 'name must be 256 characters or less').required('name is required'), type: Yup.string().oneOf(['collection']).required('type is required'), - version: Yup.string().when('opencollection', { - is: (opencollection) => Boolean(opencollection), - then: Yup.string().notRequired(), - otherwise: Yup.string().oneOf(['1']).notRequired() - }), + version: Yup.string().notRequired(), // For YAML format collections (opencollection) opencollection: Yup.string().notRequired(), collectionVersion: Yup.string().notRequired(), diff --git a/tests/collection/change-version-bru/change-version-bru.spec.ts b/tests/collection/change-version-bru/change-version-bru.spec.ts index 3d156057e15..50abbbbb488 100644 --- a/tests/collection/change-version-bru/change-version-bru.spec.ts +++ b/tests/collection/change-version-bru/change-version-bru.spec.ts @@ -47,4 +47,17 @@ test.describe('Change Collection Version (bru collection)', () => { .toMatchObject({ version: '1', collectionVersion: 'v2.3.4' }); }); }); + + test('limits the version input at 50 characters', async ({ pageWithUserData: page }) => { + await openCollectionSettings(page, COLLECTION_NAME); + await selectCollectionPaneTab(page, 'overview'); + await page.getByTestId('info-version-change').click(); + + const input = page.getByTestId('change-version-input'); + await expect(input).toHaveAttribute('maxlength', '50'); + + await input.fill(''); + await input.pressSequentially('9'.repeat(55)); + await expect(input).toHaveValue('9'.repeat(50)); + }); }); diff --git a/tests/collection/change-version-bru/init-user-data/preferences.json b/tests/collection/change-version-bru/init-user-data/preferences.json index e8528c5e91e..ec5499c273e 100644 --- a/tests/collection/change-version-bru/init-user-data/preferences.json +++ b/tests/collection/change-version-bru/init-user-data/preferences.json @@ -1,10 +1,3 @@ { - "maximized": false, - "lastOpenedCollections": ["{{collectionPath}}"], - "preferences": { - "onboarding": { - "hasLaunchedBefore": true, - "hasSeenWelcomeModal": true - } - } + "lastOpenedCollections": ["{{collectionPath}}"] } From 519934ef86a76d98306f0fbb76ce75fbadbeebb4 Mon Sep 17 00:00:00 2001 From: bruno-sachin Date: Thu, 2 Jul 2026 19:12:51 +0530 Subject: [PATCH 4/6] Comments fixed --- .../CollectionSettings/Overview/Info/index.js | 2 +- .../ChangeCollectionVersion/index.spec.js | 6 +-- .../ReduxStore/slices/collections/actions.js | 6 +-- .../ReduxStore/slices/collections/index.js | 5 +-- .../bruno-app/src/utils/collections/index.js | 12 +----- .../opencollection/bruno-to-opencollection.ts | 3 +- .../opencollection/opencollection-to-bruno.ts | 3 +- .../src/opencollection/types.ts | 2 - .../opencollection/collection-version.spec.js | 16 ++++---- packages/bruno-electron/src/ipc/collection.js | 38 +++++++++---------- .../src/utils/collection-import.js | 17 ++++----- .../src/utils/transformBrunoConfig.js | 19 ++++++++++ .../create/create-collection.spec.ts | 11 +++++- 13 files changed, 73 insertions(+), 67 deletions(-) diff --git a/packages/bruno-app/src/components/CollectionSettings/Overview/Info/index.js b/packages/bruno-app/src/components/CollectionSettings/Overview/Info/index.js index 6be8ef1fcb3..98e5911d22b 100644 --- a/packages/bruno-app/src/components/CollectionSettings/Overview/Info/index.js +++ b/packages/bruno-app/src/components/CollectionSettings/Overview/Info/index.js @@ -59,7 +59,7 @@ const Info = ({ collection }) => { {collectionVersion ? {collectionVersion} : Not Set} - Change + change

diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js index 1973f05c1e7..eda5e485265 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/ChangeCollectionVersion/index.spec.js @@ -109,11 +109,11 @@ describe('ChangeCollectionVersion', () => { expect(preview).not.toHaveTextContent('info.version'); }); - it('shows "1" for a yml collection that has no version yet', () => { + it('shows "Not Set" for a yml collection that has no version yet', () => { renderModal(buildCollection({ brunoConfig: { opencollection: '1.0.0', name: 'Bruno-Testbench' } })); - expect(screen.getByTestId('change-version-current')).toHaveTextContent('1'); - expect(screen.getByTestId('change-version-input')).toHaveValue('1'); + expect(screen.getByTestId('change-version-current')).toHaveTextContent('Not Set'); + expect(screen.getByTestId('change-version-input')).toHaveValue(''); }); it('shows a "Collection not found" message when the collection is missing', () => { diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index 37abc83c406..2d7221c02c6 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -325,13 +325,11 @@ export const saveCollectionVersion = (collectionUid, version) => (dispatch, getS const updatedVersion = typeof version === 'string' ? version.trim() : ''; - const isYml = Boolean(collection.brunoConfig?.opencollection); - const versionKey = isYml ? 'version' : 'collectionVersion'; const brunoConfigToSave = { ...(collection.brunoConfig || {}) }; if (updatedVersion) { - brunoConfigToSave[versionKey] = updatedVersion; + brunoConfigToSave.version = updatedVersion; } else { - delete brunoConfigToSave[versionKey]; + delete brunoConfigToSave.version; } const { ipcRenderer } = window; diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index 19ae8e5a903..99a6c5ede95 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -291,13 +291,12 @@ export const collectionsSlice = createSlice({ const collection = findCollectionByUid(state.collections, action.payload.collectionUid); if (collection) { const version = action.payload.version; - const versionKey = collection.brunoConfig?.opencollection ? 'version' : 'collectionVersion'; const applyVersion = (target) => { if (!target) return; if (version) { - target[versionKey] = version; + target.version = version; } else { - delete target[versionKey]; + delete target.version; } }; collection.brunoConfig = collection.brunoConfig || {}; diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index 5c06039a110..9baa952111f 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -1258,17 +1258,7 @@ const getPathParams = (item) => { export const isOpenCollectionFormat = (collection) => Boolean(collection?.brunoConfig?.opencollection); -export const getCollectionVersion = (collection) => { - const brunoConfig = collection?.brunoConfig; - if (!brunoConfig) return ''; - if (isOpenCollectionFormat(collection)) { - // yml: the user version is info.version (brunoConfig.version). When the file has none, - // default to '1' (mirroring the schema version) so a yml collection always shows a version. - return brunoConfig.version || '1'; - } - // bru: only the explicit collectionVersion; an existing bru collection without one shows "Not Set". - return brunoConfig.collectionVersion || ''; -}; +export const getCollectionVersion = (collection) => collection?.brunoConfig?.version || ''; export const getTotalRequestCountInCollection = (collection) => { let count = 0; diff --git a/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts b/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts index 26fe405ca11..7cf10046f61 100644 --- a/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts +++ b/packages/bruno-converters/src/opencollection/bruno-to-opencollection.ts @@ -88,8 +88,7 @@ const hasRequestDefaults = (root: BrunoCollectionRoot | undefined): boolean => { export const brunoToOpenCollection = (collection: BrunoCollection): OpenCollection => { const brunoConfig = collection.brunoConfig as BrunoConfig | undefined; - const isOpenCollectionFormat = Boolean(brunoConfig?.opencollection); - const collectionVersion = isOpenCollectionFormat ? brunoConfig?.version : brunoConfig?.collectionVersion; + const collectionVersion = brunoConfig?.version; const hasCollectionVersion = collectionVersion != null && collectionVersion !== ''; const openCollection: OpenCollection = { diff --git a/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts b/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts index 1c377f64f3a..9d1415f21f9 100644 --- a/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts +++ b/packages/bruno-converters/src/opencollection/opencollection-to-bruno.ts @@ -17,14 +17,13 @@ const fromOpenCollectionConfig = (oc: OpenCollection): BrunoConfig => { : ['node_modules', '.git']; const brunoConfig: BrunoConfig = { - version: '1', name: oc.info?.name || 'Untitled Collection', type: 'collection', ignore: ignoreList }; if (oc.info?.version != null && oc.info.version !== '') { - brunoConfig.collectionVersion = String(oc.info.version); + brunoConfig.version = String(oc.info.version); } if (brunoExtension?.presets?.requestType || brunoExtension?.presets?.requestUrl) { diff --git a/packages/bruno-converters/src/opencollection/types.ts b/packages/bruno-converters/src/opencollection/types.ts index ef39a41bbd9..4029bcc902c 100644 --- a/packages/bruno-converters/src/opencollection/types.ts +++ b/packages/bruno-converters/src/opencollection/types.ts @@ -175,8 +175,6 @@ export interface BrunoPresets { export interface BrunoConfig { version?: string; - // bru only: the user-facing collection version (bruno.json key, sibling of the marker). - collectionVersion?: string; // present only for OpenCollection (yml) collections; its presence marks the format. opencollection?: string; name?: string; diff --git a/packages/bruno-converters/tests/opencollection/collection-version.spec.js b/packages/bruno-converters/tests/opencollection/collection-version.spec.js index cb82198bf64..e73998aa718 100644 --- a/packages/bruno-converters/tests/opencollection/collection-version.spec.js +++ b/packages/bruno-converters/tests/opencollection/collection-version.spec.js @@ -5,27 +5,27 @@ import { openCollectionToBruno } from '../../src/opencollection/opencollection-t describe('openCollectionToBruno (import): keeps the collection version', () => { it('keeps the version as-is when importing', () => { const { brunoConfig } = openCollectionToBruno({ opencollection: '1.0.0', info: { name: 'API', version: 'v2.3.4' } }); - expect(brunoConfig.collectionVersion).toBe('v2.3.4'); + expect(brunoConfig.version).toBe('v2.3.4'); }); it('turns a number version into text (2 becomes "2")', () => { const { brunoConfig } = openCollectionToBruno({ opencollection: '1.0.0', info: { name: 'API', version: 2 } }); - expect(brunoConfig.collectionVersion).toBe('2'); + expect(brunoConfig.version).toBe('2'); }); it('has no version when the imported file has none', () => { const { brunoConfig } = openCollectionToBruno({ opencollection: '1.0.0', info: { name: 'API' } }); - expect(brunoConfig.collectionVersion).toBeUndefined(); + expect(brunoConfig.version).toBeUndefined(); }); }); describe('brunoToOpenCollection (export): writes the collection version', () => { - it('uses the bru version (collectionVersion) for a bru collection', () => { - const oc = brunoToOpenCollection({ name: 'API', brunoConfig: { version: '1', collectionVersion: 'v2.3.4' }, items: [] }); + it('uses the agnostic version for a bru collection', () => { + const oc = brunoToOpenCollection({ name: 'API', brunoConfig: { version: 'v2.3.4' }, items: [] }); expect(oc.info.version).toBe('v2.3.4'); }); - it('uses the yml version (info.version) for a yml collection', () => { + it('uses the agnostic version for a yml collection', () => { const oc = brunoToOpenCollection({ name: 'API', brunoConfig: { opencollection: '1.0.0', version: 'v9.9' }, items: [] }); expect(oc.info.version).toBe('v9.9'); }); @@ -38,8 +38,8 @@ describe('brunoToOpenCollection (export): writes the collection version', () => describe('collection version: export then import keeps it the same', () => { it('keeps the same version after exporting and importing again', () => { - const oc = brunoToOpenCollection({ name: 'API', brunoConfig: { collectionVersion: '1.2.3-beta' }, items: [] }); + const oc = brunoToOpenCollection({ name: 'API', brunoConfig: { version: '1.2.3-beta' }, items: [] }); const { brunoConfig } = openCollectionToBruno(oc); - expect(brunoConfig.collectionVersion).toBe('1.2.3-beta'); + expect(brunoConfig.version).toBe('1.2.3-beta'); }); }); diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index cd3501633c6..77bf7bbad24 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -76,7 +76,7 @@ const { getProcessEnvVars } = require('../store/process-env'); const { getOAuth2TokenUsingAuthorizationCode, getOAuth2TokenUsingClientCredentials, getOAuth2TokenUsingPasswordCredentials, getOAuth2TokenUsingImplicitGrant, refreshOauth2Token } = require('../utils/oauth2'); const { getCertsAndProxyConfig } = require('./network/cert-utils'); const collectionWatcher = require('../app/collection-watcher'); -const { transformBrunoConfigBeforeSave } = require('../utils/transformBrunoConfig'); +const { transformBrunoConfigBeforeSave, transformBrunoConfigAfterRead } = require('../utils/transformBrunoConfig'); const { REQUEST_TYPES } = require('../utils/constants'); const { cancelOAuth2AuthorizationRequest, isOauth2AuthorizationRequestInProgress } = require('../utils/oauth2-protocol-handler'); const { findUniqueFolderName } = require('../utils/collection-import'); @@ -203,7 +203,6 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { const uid = generateUidBasedOnHash(dirPath); let brunoConfig = { version: '1', - collectionVersion: '1', name: collectionName, type: 'collection', ignore: ['node_modules', '.git'] @@ -217,7 +216,6 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { }; brunoConfig = { opencollection: '1.0.0', - version: '1', name: collectionName, type: 'collection', ignore: ['node_modules', '.git'] @@ -233,12 +231,15 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { await writeFile(path.join(dirPath, '.gitignore'), DEFAULT_GITIGNORE); + let persistedConfig = await getCollectionConfigFile(dirPath); + persistedConfig = await transformBrunoConfigAfterRead(persistedConfig, dirPath); + const { size, filesCount } = await getCollectionStats(dirPath); - brunoConfig.size = size; - brunoConfig.filesCount = filesCount; + persistedConfig.size = size; + persistedConfig.filesCount = filesCount; - mainWindow.webContents.send('main:collection-opened', dirPath, uid, brunoConfig); - ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid, brunoConfig); + mainWindow.webContents.send('main:collection-opened', dirPath, uid, persistedConfig); + ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid, persistedConfig); } catch (error) { return Promise.reject(error); } @@ -1386,16 +1387,10 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { if (!brunoConfig) { brunoConfig = { - version: '1', - collectionVersion: '1', name: collection.name, type: 'collection', ignore: ['node_modules', '.git'] }; - } else if (!brunoConfig.collectionVersion) { - // Imports create new collection files; default the user-facing version when the - // source didn't carry one (a present version, e.g. OpenCollection info.version, is kept). - brunoConfig.collectionVersion = '1'; } if (brunoConfig.proxy) { brunoConfig.proxy = transformProxyConfig(brunoConfig.proxy); @@ -1419,16 +1414,16 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { if (format === 'yml') { brunoConfig.opencollection = '1.0.0'; - // For yml the user-facing version is info.version (brunoConfig.version); map the - // neutral collectionVersion onto it and keep collectionVersion out of the yaml. - if (brunoConfig.collectionVersion) { - brunoConfig.version = brunoConfig.collectionVersion; - } - delete brunoConfig.collectionVersion; const collectionContent = await stringifyCollection(coll.root, brunoConfig, { format }); await writeFile(path.join(collectionPath, 'opencollection.yml'), collectionContent); } else if (format === 'bru') { - const stringifiedBrunoConfig = await stringifyJson(brunoConfig); + const bruJsonConfig = { ...brunoConfig, version: '1' }; + if (brunoConfig.version) { + bruJsonConfig.collectionVersion = brunoConfig.version; + } else { + delete bruJsonConfig.collectionVersion; + } + const stringifiedBrunoConfig = await stringifyJson(bruJsonConfig); await writeFile(path.join(collectionPath, 'bruno.json'), stringifiedBrunoConfig); const collectionContent = await stringifyCollection(coll.root, brunoConfig, { format }); @@ -2615,7 +2610,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { } let collectionName = 'Imported Collection'; - let brunoConfig = { name: collectionName, version: '1', collectionVersion: '1', type: 'collection', ignore: ['node_modules', '.git'] }; + let brunoConfig = { name: collectionName, version: '1', type: 'collection', ignore: ['node_modules', '.git'] }; if (fs.existsSync(openCollectionYmlPath)) { try { const content = fs.readFileSync(openCollectionYmlPath, 'utf8'); @@ -2651,6 +2646,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { } const uid = generateUidBasedOnHash(finalCollectionPath); + brunoConfig = await transformBrunoConfigAfterRead(brunoConfig, finalCollectionPath); const { size, filesCount } = await getCollectionStats(finalCollectionPath); brunoConfig.size = size; brunoConfig.filesCount = filesCount; diff --git a/packages/bruno-electron/src/utils/collection-import.js b/packages/bruno-electron/src/utils/collection-import.js index 763b1154799..2246dfd78cc 100644 --- a/packages/bruno-electron/src/utils/collection-import.js +++ b/packages/bruno-electron/src/utils/collection-import.js @@ -87,14 +87,10 @@ async function importCollection(collection, collectionLocation, mainWindow, uniq if (!brunoConfig) { brunoConfig = { - version: '1', - collectionVersion: '1', name: collection.name, type: 'collection', ignore: ['node_modules', '.git'] }; - } else if (!brunoConfig.collectionVersion) { - brunoConfig.collectionVersion = '1'; } if (brunoConfig.proxy) { @@ -110,14 +106,17 @@ async function importCollection(collection, collectionLocation, mainWindow, uniq let brunoConfig = getBrunoJsonConfig(collection); if (format === 'yml') { - if (brunoConfig.collectionVersion) { - brunoConfig.version = brunoConfig.collectionVersion; - } - delete brunoConfig.collectionVersion; + brunoConfig.opencollection = '1.0.0'; const collectionContent = await stringifyCollection(collection.root, brunoConfig, { format }); await writeFile(path.join(collectionPath, 'opencollection.yml'), collectionContent); } else if (format === 'bru') { - const stringifiedBrunoConfig = await stringifyJson(brunoConfig); + const bruJsonConfig = { ...brunoConfig, version: '1' }; + if (brunoConfig.version) { + bruJsonConfig.collectionVersion = brunoConfig.version; + } else { + delete bruJsonConfig.collectionVersion; + } + const stringifiedBrunoConfig = await stringifyJson(bruJsonConfig); await writeFile(path.join(collectionPath, 'bruno.json'), stringifiedBrunoConfig); const collectionContent = await stringifyCollection(collection.root, brunoConfig, { format }); diff --git a/packages/bruno-electron/src/utils/transformBrunoConfig.js b/packages/bruno-electron/src/utils/transformBrunoConfig.js index 60b59fd7f75..37b639a4568 100644 --- a/packages/bruno-electron/src/utils/transformBrunoConfig.js +++ b/packages/bruno-electron/src/utils/transformBrunoConfig.js @@ -3,6 +3,16 @@ const { isFile, isDirectory } = require('./filesystem'); const { transformProxyConfig } = require('@usebruno/requests'); function transformBrunoConfigBeforeSave(brunoConfig) { + if (brunoConfig && !brunoConfig.opencollection) { + const userVersion = brunoConfig.version; + brunoConfig.version = '1'; // bru schema marker + if (userVersion) { + brunoConfig.collectionVersion = userVersion; + } else { + delete brunoConfig.collectionVersion; + } + } + // remove exists from importPaths and protoFiles if (brunoConfig.protobuf?.importPaths) { brunoConfig.protobuf.importPaths = brunoConfig.protobuf.importPaths.map((importPath) => { @@ -33,6 +43,15 @@ function transformBrunoConfigBeforeSave(brunoConfig) { } async function transformBrunoConfigAfterRead(brunoConfig, collectionPathname) { + if (brunoConfig && !brunoConfig.opencollection) { + if (brunoConfig.collectionVersion) { + brunoConfig.version = brunoConfig.collectionVersion; + } else { + delete brunoConfig.version; + } + delete brunoConfig.collectionVersion; + } + // add exists to importPaths and protoFiles by checking actual file/directory existence if (brunoConfig.protobuf?.importPaths) { brunoConfig.protobuf.importPaths = await Promise.all(brunoConfig.protobuf.importPaths.map(async (importPath) => { diff --git a/tests/collection/create/create-collection.spec.ts b/tests/collection/create/create-collection.spec.ts index 0dc68ed16ea..72cdfae05fa 100644 --- a/tests/collection/create/create-collection.spec.ts +++ b/tests/collection/create/create-collection.spec.ts @@ -1,5 +1,5 @@ import { test, expect } from '../../../playwright'; -import { closeAllCollections, createCollection, createRequest } from '../../utils/page'; +import { closeAllCollections, createCollection, createRequest, openCollectionSettings, selectCollectionPaneTab } from '../../utils/page'; test.describe('Create collection', () => { test.afterEach(async ({ page }) => { @@ -76,4 +76,13 @@ test.describe('Create collection', () => { // Verify the response await expect(page.getByRole('main')).toContainText('200 OK'); }); + + test('a newly created collection has no version set (shows "Not Set")', async ({ page, createTmpDir }) => { + const collectionName = 'versioned-collection'; + await createCollection(page, collectionName, await createTmpDir(collectionName)); + + await openCollectionSettings(page, collectionName); + await selectCollectionPaneTab(page, 'overview'); + await expect(page.getByTestId('info-version-value')).toHaveText('Not Set'); + }); }); From 8edeae5b44414d19dd841251f09f2e298f0fc806 Mon Sep 17 00:00:00 2001 From: bruno-sachin Date: Fri, 3 Jul 2026 12:23:03 +0530 Subject: [PATCH 5/6] Comments addressed --- packages/bruno-electron/src/app/collections.js | 1 - packages/bruno-electron/src/ipc/collection.js | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/bruno-electron/src/app/collections.js b/packages/bruno-electron/src/app/collections.js index 3e1ad7934c0..e1691e80467 100644 --- a/packages/bruno-electron/src/app/collections.js +++ b/packages/bruno-electron/src/app/collections.js @@ -22,7 +22,6 @@ const configSchema = Yup.object({ version: Yup.string().notRequired(), // For YAML format collections (opencollection) opencollection: Yup.string().notRequired(), - collectionVersion: Yup.string().notRequired(), // OpenAPI sync configuration (array, one entry per synced spec) openapi: Yup.array().of( Yup.object({ diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 77bf7bbad24..9c07ecee71e 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -2224,7 +2224,6 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { const brunoConfig = { opencollection: '1.0.0', - version: '1', name: 'Scratch', type: 'collection', ignore: ['node_modules', '.git'] From 665eeea1f44f55a5eb7ec74c2418a1978074c6c5 Mon Sep 17 00:00:00 2001 From: bruno-sachin Date: Fri, 3 Jul 2026 17:28:08 +0530 Subject: [PATCH 6/6] Comments addressed --- packages/bruno-electron/src/ipc/collection.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 9c07ecee71e..eecd3e0cc4c 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -1420,8 +1420,6 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { const bruJsonConfig = { ...brunoConfig, version: '1' }; if (brunoConfig.version) { bruJsonConfig.collectionVersion = brunoConfig.version; - } else { - delete bruJsonConfig.collectionVersion; } const stringifiedBrunoConfig = await stringifyJson(bruJsonConfig); await writeFile(path.join(collectionPath, 'bruno.json'), stringifiedBrunoConfig);