diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index fd8772f3d..547ac6404 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -112,8 +112,9 @@ const getTransientScratchPrefix = () => { // Check if a path is within the transient directory const isTransientPath = (filePath) => { + const normalizedFilePath = path.normalize(filePath); const transientBase = getTransientDirectoryBase(); - return filePath.startsWith(transientBase + path.sep) || filePath.startsWith(transientBase); + return normalizedFilePath.startsWith(transientBase + path.sep) || normalizedFilePath === transientBase; }; const envHasSecrets = (environment = {}) => { @@ -123,11 +124,14 @@ const envHasSecrets = (environment = {}) => { }; const findCollectionPathByItemPath = (filePath) => { - const parts = filePath.split(path.sep); - const index = parts.findIndex((part) => part.startsWith('bruno-')); + const normalizedFilePath = path.normalize(filePath); - if (isTransientPath(filePath) && index !== -1) { - const transientDirPath = parts.slice(0, index + 1).join(path.sep); + if (isTransientPath(normalizedFilePath)) { + const transientBase = getTransientDirectoryBase(); + const transientDirName = path.relative(transientBase, normalizedFilePath).split(path.sep)[0]; + if (!transientDirName) return null; + + const transientDirPath = path.join(transientBase, transientDirName); const metadataPath = path.join(transientDirPath, 'metadata.json'); try { const metadataContent = fs.readFileSync(metadataPath, 'utf8'); @@ -152,9 +156,6 @@ const findCollectionPathByItemPath = (filePath) => { // Sort by length descending to find the most specific (deepest) match first const sortedPaths = allCollectionPaths.sort((a, b) => b.length - a.length); - // Normalize the file path for comparison - const normalizedFilePath = path.normalize(filePath); - for (const collectionPath of sortedPaths) { const normalizedCollectionPath = path.normalize(collectionPath); if (normalizedFilePath.startsWith(normalizedCollectionPath + path.sep) || normalizedFilePath === normalizedCollectionPath) {