Skip to content

fix(plugins): allow relative paths inside a drive-root workspace - #1739

Merged
vastsa merged 2 commits into
vastsa:mainfrom
Frank-zhu2000:fix/1715-drive-root-plugin-paths
Oct 19, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
Frank-zhu2000:fix/1715-drive-root-plugin-paths

Conversation

@Frank-zhu2000

@Frank-zhu2000 Frank-zhu2000 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1715

When a workspace is opened at a drive root (C:\, E:\), every plugin relative path such as .workflow/knowhow/x.md was rejected as escaping the workspace.

Root cause: the containment checks build the boundary as root + sep. A Windows drive root (C:\), a UNC share root, and the POSIX root (/) already end with a separator, so the boundary became C:\\ and no child path could ever match it. The fix only appends the separator when the root does not already end with one.

Changed call sites (same one-line rule in each):

  • packages/host-runtime/src/workspace-files.ts — resolveWithinRoot (plugin file APIs / workspace files)
  • packages/agent-runtime/src/project-instructions.ts — isWithinRoot (project instruction reads)
  • apps/desktop/electron/main/browser-view.ts — isWithinRoot (local-file preview)

resolveWithinRoot and isWithinRoot take an optional path implementation (defaulting to node:path) so the Windows behavior can be tested with path.win32 on Linux CI. The agent-runtime index now re-exports the existing public names explicitly so the newly exported isWithinRoot helper does not become part of the package API. Runtime behavior for non-root workspaces is unchanged.

Specs / ADRs / E2E

  • No spec or ADR change: this restores the intended containment contract; it does not change it.
  • No new E2E scenario: the bug only reproduces with a real Windows drive-root workspace, which the Linux E2E runners cannot open. It is covered by unit tests using path.win32 instead.

Tests

New apps/desktop/test/drive-root-path-containment.test.mjs (6 tests, all pass):

  • drive roots C:/, C:\, E:/, E:\ contain relative plugin paths
  • a UNC share root contains a relative path
  • escapes are still rejected (../code-evil/x, E:\code-evil\x, C:/Windows/x from C:/Users/su, sibling-prefix ../project-evil/x, empty root)
  • non-root Windows directories still resolve normally; .. at a drive root stays on the drive
  • the POSIX root / contains a relative path; sibling-prefix escape under /srv/app is rejected
  • project-instruction containment accepts a drive root and still rejects C:\Users\su-evil

Local run of the PR workflows (ci.yml jobs js, rust, trusted-extensions-e2e, and pr-base.yml) on head ccded1b18, Node 24.21.0, rustc 1.99.1:

step result
pnpm check:pr-base / check-pr-base-main.mjs + its unit test pass
pnpm install --frozen-lockfile, pnpm build:js pass
desktop typecheck, pnpm lint, architecture check, pi-patch-hash test pass
cargo fmt --all -- --check, cargo clippy --workspace --all-targets --all-features pass
trusted-extensions E2E (incl. browser-capture and transcript E2E) pass, SUMMARY 57/57 passed
pnpm -r --if-present test 4070 pass / 12 fail / 7 skipped — baseline, see below
cargo test -p host-core --locked 960 pass / 1 fail / 1 ignored — baseline, see below

Pre-existing local failures (same on merge-base)

Both failing steps were re-run on the merge-base e219a3e4c (current upstream/main) and fail identically there, so they are environment/baseline failures and not caused by this diff:

  • pnpm -r --if-present test — 12 apps/desktop *-user-path / plugin-view-bounds-sync tests fail with Electron binary missing from scripts/e2e/boot.mjs, because pnpm install --frozen-lockfile does not download the Electron binary (CI installs it later, in the trusted-extensions-e2e job). Same 12 tests, same error on both commits. Totals: head 4089 tests / 4070 pass / 12 fail; base 4083 / 4064 / 12. The +6 on head are the new tests above, all passing.
  • cargo test -p host-core --locked — tools::tests::bash_inherits_user_login_path panics with every injected login-PATH entry is present on both commits (960 passed, 1 failed, 1 ignored on each). The local host's login shell rewrites a PATH entry. This PR changes no Rust sources.

NOT RUN

  • ci.yml / rust-windows (windows-latest) — no Windows host available locally. The diff touches no Rust code. The Windows path behavior is covered by the path.win32 unit tests above; the remaining risk is that a real Windows run differs from path.win32, which is low.

Compatibility / security

The containment checks are a security boundary. The change only accepts children of a root that already ends with a separator; sibling-prefix escapes (C:\code vs C:\code-evil) and .. escapes are still rejected, and the tests assert that. No migration.

AI disclosure

This change was prepared with AI assistance (code, tests, and this description). The diff was reviewed and every check listed above was actually run locally; nothing is reported as passing that was not executed.

Baseline comparison (refresh onto main 589e580)

Local CI mirror at 585c641 (merge of current main 589e580): all steps pass except js-unit-tests (Electron binary unavailable in the local sandbox) and rust-test (bash_inherits_user_login_path). Both fail identically on unmodified 589e580, so they are environment/baseline failures unrelated to this diff.

Windows drive and UNC roots, and the POSIX root, already end with a
separator. Containment that always appended another separator rejected
every child as an escape, so plugin file APIs, project-instruction
reads, and local-file preview failed for a workspace opened at C:\ or
E:\.

fixes vastsa#1715
@muzimu217

Copy link
Copy Markdown
Contributor

Follow-up on my scope note: checked the third surface I flagged — plugin-runtime.ts:4777-4778 imports resolveRealPathWithinRoot/resolveRealPathForCreateWithinRoot from @pi-desktop/host-runtime, which this PR patches (workspace-files.ts boundary dedup), so the host fs gateway from #1715 is covered. The defense-in-depth check at plugin-runtime.ts:1197 already deduped the separator before this PR. All containment surfaces are addressed.

@muzimu217

Copy link
Copy Markdown
Contributor

Status ping: this is now MERGEABLE/CLEAN with all checks green (JS, docs, base freshness, Rust fmt/lint/test, Rust Windows, Trusted extensions E2E). I reviewed the containment logic earlier and confirmed it covers all three surfaces (browser-view, project-instructions, workspace-files, with plugin-runtime importing the patched helper), and the new path.win32-driven regression passes 6/6 locally.

#1715 is the only open report for the drive-root containment bug, so merging this closes it. Flagging in case it fell off the queue during the beta.4 release.

@muzimu217

Copy link
Copy Markdown
Contributor

Merge-readiness check, done locally so it does not need another CI cycle:

  • Merged current upstream/main into head ccded1b1 in an isolated worktree: clean, no conflicts (branch is 9 commits behind).
  • After that merge, apps/desktop/test/drive-root-path-containment.test.mjs: 6/6 pass — including the drive-root, UNC-root and POSIX-root containment cases, plus the negative cases (.. escapes, absolute out-of-root, empty root).

So this is safe to merge as-is; the merge is a no-op conflict-wise. It is the only fix for #1715 (plugin relative paths rejected when the workspace is a drive root), and the failure it addresses is a hard blocker for any Windows user whose project sits at C:\ or E:\.

If it is easier for you, I can push the merge commit to my fork and open it as a refreshed head — say the word and I will; otherwise a plain merge button works.

vastsa commented Oct 19, 2026

Copy link
Copy Markdown
Owner

I confirmed #1715's root cause: appending a separator to a filesystem root that already ends with one creates a boundary prefix that rejects every child. The proposed normalization fixes the drive/UNC/POSIX root cases while preserving sibling and .. escape rejection, and the regression tests cover those boundaries.

The passing checks are for head ccded1b based on e219a3e; current main is 589e580. Please refresh this branch against current main and rerun the required checks on that candidate before merge. Thanks for the focused fix and cross-platform path coverage.

@vastsa
vastsa merged commit 17a0c30 into vastsa:main Oct 19, 2026
6 checks passed

This branch was previously deployed

1 inactive deployment
Preview — 585c6413 Deployed Oct 19, 2026 by vercel[bot]
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.

[Bug] 工作区为盘符根(C:\ 或 E:\)时,插件的相对路径读写全部被判越界

3 participants