Repository navigation
fix(snapshot): active workspace restoration from snapshot #8392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bijin-bruno
merged 13 commits into
usebruno:main
from
sid-bruno:feat/workspace-checks-for-snapshot
Jul 4, 2026
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
763974f
feat(workspaces): implement active workspace restoration from snapshot
sid-bruno 090d20a
feat(snapshot): refactor snapshot serialization and add environment p…
sid-bruno ae61c5f
Add tests for missing and invalid environment files
sid-bruno 76506eb
feat(snapshot): refactor devTools normalization and add saveToken to …
sid-bruno 95ae2f2
refactor(snapshot): remove saveToken from IPC handler for renderer:sn…
sid-bruno ffc2a44
Merge branch 'main' into feat/workspace-checks-for-snapshot
sid-bruno e977596
feat(snapshot): implement collection deduplication logic in SnapshotM…
sid-bruno caf27af
feat(snapshot): enhance workspace-specific environment handling for s…
sid-bruno 5ab45a0
feat(snapshot): remove sourceWorkspacePathname from snapshot serializ…
sid-bruno c8e5205
feat(snapshot): remove sourceWorkspacePathname from SnapshotManager a…
sid-bruno e9399d3
feat(snapshot): refactor collection deduplication tests and enhance s…
sid-bruno 2c34323
feat(snapshot): enhance workspace path normalization and improve snap…
sid-bruno 94aad9f
Merge branch 'main' into feat/workspace-checks-for-snapshot
engineering-bruno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const snapshotManager = require('../services/snapshot'); | ||
| const { readWorkspaceConfig, validateWorkspaceConfig } = require('./workspace-config'); | ||
|
|
||
| const normalizeWorkspacePathname = (workspacePath) => { | ||
| if (typeof workspacePath !== 'string' || !workspacePath.length) { | ||
| return ''; | ||
| } | ||
|
|
||
| return path.normalize(workspacePath.replace(/\\+$/, '').replace(/\/+$/, '')); | ||
| }; | ||
|
|
||
| const prioritizeActiveWorkspacePath = (workspacePaths, activeWorkspacePath) => { | ||
| if (!activeWorkspacePath || !Array.isArray(workspacePaths) || workspacePaths.length <= 1) { | ||
| return workspacePaths; | ||
| } | ||
|
|
||
| const normalizedActivePath = normalizeWorkspacePathname(activeWorkspacePath); | ||
| if (!normalizedActivePath) { | ||
| return workspacePaths; | ||
| } | ||
|
|
||
| const activeIndex = workspacePaths.findIndex( | ||
| (workspacePath) => normalizeWorkspacePathname(workspacePath) === normalizedActivePath | ||
| ); | ||
|
|
||
| if (activeIndex <= 0) { | ||
| return workspacePaths; | ||
| } | ||
|
|
||
| const prioritizedPaths = [...workspacePaths]; | ||
| const [activePath] = prioritizedPaths.splice(activeIndex, 1); | ||
| prioritizedPaths.unshift(activePath); | ||
| return prioritizedPaths; | ||
| }; | ||
|
|
||
| const isValidWorkspacePathOnDisk = (workspacePath, { validateConfig = false } = {}) => { | ||
| const workspaceYmlPath = path.join(workspacePath, 'workspace.yml'); | ||
|
|
||
| if (!fs.existsSync(workspaceYmlPath)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!validateConfig) { | ||
| return true; | ||
| } | ||
|
|
||
| try { | ||
| const workspaceConfig = readWorkspaceConfig(workspacePath); | ||
| validateWorkspaceConfig(workspaceConfig); | ||
| return true; | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| const resolveLastOpenedWorkspacePaths = (lastOpenedWorkspaces, { | ||
| defaultWorkspacePath = null, | ||
| validateConfig = false | ||
| } = {}) => { | ||
| const workspacePaths = lastOpenedWorkspaces.getAll(); | ||
| const activeWorkspacePath = snapshotManager.getSnapshot()?.activeWorkspacePath; | ||
| const validWorkspaces = []; | ||
| const invalidPaths = []; | ||
| for (const workspacePath of workspacePaths) { | ||
| if (defaultWorkspacePath && workspacePath === defaultWorkspacePath) { | ||
| continue; | ||
| } | ||
|
|
||
| if (isValidWorkspacePathOnDisk(workspacePath, { validateConfig })) { | ||
| validWorkspaces.push(workspacePath); | ||
| } else { | ||
| invalidPaths.push(workspacePath); | ||
| } | ||
| } | ||
|
|
||
| let prioritizedWorkspaces = prioritizeActiveWorkspacePath(validWorkspaces, activeWorkspacePath); | ||
|
|
||
| if (activeWorkspacePath) { | ||
| const normalizedActivePath = normalizeWorkspacePathname(activeWorkspacePath); | ||
| const alreadyIncluded = prioritizedWorkspaces.some( | ||
| (workspacePath) => normalizeWorkspacePathname(workspacePath) === normalizedActivePath | ||
| ); | ||
|
|
||
| if ( | ||
| !alreadyIncluded | ||
| && normalizedActivePath | ||
| && (!defaultWorkspacePath || activeWorkspacePath !== defaultWorkspacePath) | ||
|
sid-bruno marked this conversation as resolved.
Resolved
|
||
| && isValidWorkspacePathOnDisk(activeWorkspacePath, { validateConfig }) | ||
| ) { | ||
| prioritizedWorkspaces.unshift(activeWorkspacePath); | ||
| } | ||
| } | ||
|
|
||
| for (const invalidPath of invalidPaths) { | ||
| lastOpenedWorkspaces.remove(invalidPath); | ||
| } | ||
|
|
||
| return { | ||
| validWorkspaces: prioritizedWorkspaces, | ||
| invalidPaths | ||
| }; | ||
| }; | ||
|
|
||
| module.exports = { | ||
| normalizeWorkspacePathname, | ||
| prioritizeActiveWorkspacePath, | ||
| isValidWorkspacePathOnDisk, | ||
| resolveLastOpenedWorkspacePaths | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.