( metadata: WorkspaceMetadataForRuntime, runtime: Runtime )
| 37 | * sub-project directory twice and miss the parent project's guidance entirely. |
| 38 | */ |
| 39 | export function resolveWorkspaceRootPath( |
| 40 | metadata: WorkspaceMetadataForRuntime, |
| 41 | runtime: Runtime |
| 42 | ): string { |
| 43 | if (metadata.projectPath === metadata.name) { |
| 44 | // In-place workspaces (CLI/benchmarks) execute directly in their project root instead of a |
| 45 | // named sibling checkout, so deriving a worktree path would be reconstructing the wrong shape. |
| 46 | return metadata.projectPath; |
| 47 | } |
| 48 | |
| 49 | const runtimeWorkspacePath = runtime.getWorkspacePath(metadata.projectPath, metadata.name); |
| 50 | assert(runtimeWorkspacePath, `Workspace ${metadata.name} resolved to an empty runtime path`); |
| 51 | |
| 52 | if (isDockerRuntime(metadata.runtimeConfig)) { |
| 53 | return runtimeWorkspacePath; |
| 54 | } |
| 55 | |
| 56 | const persistedWorkspacePath = metadata.namedWorkspacePath?.trim(); |
| 57 | if (!persistedWorkspacePath) { |
| 58 | // SSH workspaces must keep using the persisted checkout root from config so upgraded legacy |
| 59 | // workspaces do not silently fall back to the reconstructed hashed path and miss their real cwd. |
| 60 | assert( |
| 61 | !isSSHRuntime(metadata.runtimeConfig), |
| 62 | `SSH workspace ${metadata.name} is missing a persisted workspace path` |
| 63 | ); |
| 64 | |
| 65 | // Other runtimes can still fall back to their canonical derived path when only identity metadata |
| 66 | // is available (for example in narrow unit tests). |
| 67 | return runtimeWorkspacePath; |
| 68 | } |
| 69 | |
| 70 | if (isLocalProjectRuntime(metadata.runtimeConfig)) { |
| 71 | // Project-dir local runtimes always execute directly in the project root. |
| 72 | assert( |
| 73 | persistedWorkspacePath === runtimeWorkspacePath, |
| 74 | `Project-dir local workspace ${metadata.name} path mismatch: persisted=${persistedWorkspacePath} runtime=${runtimeWorkspacePath}` |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | return persistedWorkspacePath; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Append `metadata.subProjectPath` (if any) to a workspace root path, using the |
no test coverage detected