Skip to content

feat: add clone path and related test#752

Open
batleforc wants to merge 1 commit into
che-incubator:mainfrom
batleforc:clone-path
Open

feat: add clone path and related test#752
batleforc wants to merge 1 commit into
che-incubator:mainfrom
batleforc:clone-path

Conversation

@batleforc

@batleforc batleforc commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

In code-workspace, either use the clonePath if it exist or the project name to find the folder.

What issues does this PR fix?

eclipse-che/che#23909

How to test this PR?

Does this PR contain changes that override default upstream Code-OSS behavior?

  • the PR contains changes in the code folder (you can skip it if your changes are placed in a che extension )
  • the corresponding items were added to the CHANGELOG.md file
  • rules for automatic git rebase were added to the .rebase folder

Summary by CodeRabbit

  • New Features

    • Workspace generation now supports custom project clone paths, so folder locations can follow the configured directory layout.
  • Bug Fixes

    • Folder paths are now derived from the clone path when provided (with fallback to the project name).
    • Project synchronization validates the resolved root and safely skips projects with invalid/out-of-root locations.
    • Existing workspace folders and workspace files are no longer duplicated/overwritten unnecessarily.
  • Tests

    • Added new fixtures and expanded coverage for clone-path scenarios in both workspace generation and project synchronization.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Click here to review and test in web IDE: Contribute

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c810a80a-a7a1-4162-8e7f-4e3d50ffb3d5

📥 Commits

Reviewing files that changed from the base of the PR and between c991724 and d0cac29.

📒 Files selected for processing (4)
  • launcher/src/code-workspace.ts
  • launcher/src/flattened-devfile.ts
  • launcher/tests/_data/flattened.devworkspace.with-clone-path.yaml
  • launcher/tests/code-workspace.spec.ts
✅ Files skipped from review due to trivial changes (2)
  • launcher/src/flattened-devfile.ts
  • launcher/tests/_data/flattened.devworkspace.with-clone-path.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • launcher/src/code-workspace.ts
  • launcher/tests/code-workspace.spec.ts

📝 Walkthrough

Walkthrough

This PR adds an optional clonePath field to the Project interface and changes CodeWorkspace.synchronizeProjects to resolve project directories from clonePath when present, otherwise from project.name. The method now requires PROJECTS_ROOT, rejects paths that escape that root, and uses the resolved path for existence checks and workspace folder entries. New fixture data and tests cover clone-path generation, fallback behavior, missing directories, and duplicate folder handling.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CodeWorkspace
  participant path
  participant FileSystem
  CodeWorkspace->>path: resolve(PROJECTS_ROOT, clonePath or name)
  CodeWorkspace->>FileSystem: check resolved path exists
  CodeWorkspace->>CodeWorkspace: skip if path escapes PROJECTS_ROOT
  CodeWorkspace->>CodeWorkspace: add workspace folder with resolved path
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise, imperative, and accurately summarizes the clonePath support and test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Rebase Rules For Upstream Changes ✅ Passed Only launcher/* files changed; no files under code/ or .rebase/ were modified, so the rebase-rule requirement does not apply.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@launcher/src/code-workspace.ts`:
- Around line 156-161: `clonePath` in `code-workspace.ts` is being used directly
in `workspace.folders` path construction, which allows path traversal outside
`env.PROJECTS_ROOT`. Update the workspace-building logic around `pathProject` so
`clonePath` is validated/sanitized to ensure it stays relative to the projects
root before calling `fs.pathExists` or pushing a folder. Use the
`workspace.folders` append flow and the `project.clonePath || project.name`
assignment as the main place to enforce the check, and reject or ignore any
value that resolves outside `env.PROJECTS_ROOT`.

In `@launcher/tests/code-workspace.spec.ts`:
- Around line 525-557: Add a test in CodeWorkspace.generate() for the existing
single-project workspace case where the .code-workspace file already exists
under PROJECTS_ROOT using clonePath, not project.name. Update the
pathExists/readFile setup to return true for ${clonePath}/.code-workspace and
verify generate() looks up that exact location. This should cover the branch
that currently uses the wrong lookup key and ensure no writeFile occurs when the
workspace already exists.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 58ef240a-5a03-4d01-8b05-e7b1da04b9a5

📥 Commits

Reviewing files that changed from the base of the PR and between 828719e and f6e4d9f.

📒 Files selected for processing (4)
  • launcher/src/code-workspace.ts
  • launcher/src/flattened-devfile.ts
  • launcher/tests/_data/flattened.devworkspace.with-clone-path.yaml
  • launcher/tests/code-workspace.spec.ts

Comment thread launcher/src/code-workspace.ts Outdated
Comment thread launcher/tests/code-workspace.spec.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
launcher/src/code-workspace.ts (1)

162-162: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use const instead of let for pathProject.

pathProject is never reassigned.

♻️ Proposed fix
-      let pathProject = project.clonePath || project.name;
+      const pathProject = project.clonePath || project.name;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@launcher/src/code-workspace.ts` at line 162, Use const instead of let for
pathProject in the code-workspace logic because the value is never reassigned.
Update the declaration in the code that builds the workspace path (around the
pathProject assignment) so it remains immutable and matches the existing naming
in this section.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@launcher/src/code-workspace.ts`:
- Around line 163-167: The workspace-folder path validation in code-workspace.ts
is using a string-prefix check that can be bypassed by paths like sibling
directories with the same prefix. Update the fullPath validation in the
project-iteration logic to use a real path-boundary check based on path.relative
against env.PROJECTS_ROOT, and keep the existing skip/continue behavior when the
resolved path escapes the root.

---

Nitpick comments:
In `@launcher/src/code-workspace.ts`:
- Line 162: Use const instead of let for pathProject in the code-workspace logic
because the value is never reassigned. Update the declaration in the code that
builds the workspace path (around the pathProject assignment) so it remains
immutable and matches the existing naming in this section.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8bf1dbc1-438d-44fc-8113-055887b34452

📥 Commits

Reviewing files that changed from the base of the PR and between f6e4d9f and c991724.

📒 Files selected for processing (4)
  • launcher/src/code-workspace.ts
  • launcher/src/flattened-devfile.ts
  • launcher/tests/_data/flattened.devworkspace.with-clone-path.yaml
  • launcher/tests/code-workspace.spec.ts
✅ Files skipped from review due to trivial changes (1)
  • launcher/tests/_data/flattened.devworkspace.with-clone-path.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • launcher/src/flattened-devfile.ts
  • launcher/tests/code-workspace.spec.ts

Comment thread launcher/src/code-workspace.ts Outdated
Comment on lines +163 to +167
const fullPath = path.resolve(env.PROJECTS_ROOT, pathProject);
if (!fullPath.startsWith(path.resolve(env.PROJECTS_ROOT))) {
console.log(`> Skipping project ${project.name}: clonePath escapes projects root`);
continue;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Path traversal check is bypassable via string-prefix false positives.

fullPath.startsWith(path.resolve(env.PROJECTS_ROOT)) is a string comparison, not a path boundary check. If PROJECTS_ROOT is /projects, a clonePath like ../projects-evil/data resolves to /projects-evil/data, which passes startsWith('/projects') because /projects is a string prefix of /projects-evil. This allows directories outside the intended root to be added as workspace folders.

Use path.relative to ensure the resolved path stays within the root:

🔒 Proposed fix using path.relative
       const fullPath = path.resolve(env.PROJECTS_ROOT, pathProject);
-      if (!fullPath.startsWith(path.resolve(env.PROJECTS_ROOT))) {
+      const relative = path.relative(path.resolve(env.PROJECTS_ROOT), fullPath);
+      if (relative.startsWith('..') || path.isAbsolute(relative)) {
         console.log(`> Skipping project ${project.name}: clonePath escapes projects root`);
         continue;
       }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@launcher/src/code-workspace.ts` around lines 163 - 167, The workspace-folder
path validation in code-workspace.ts is using a string-prefix check that can be
bypassed by paths like sibling directories with the same prefix. Update the
fullPath validation in the project-iteration logic to use a real path-boundary
check based on path.relative against env.PROJECTS_ROOT, and keep the existing
skip/continue behavior when the resolved path escapes the root.

Signed-off-by: Max Batleforc <maxleriche.60@gmail.com>
Assisted-by: CodeRabbit review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant