Skip to content

Commit dbcd323

Browse files
committed
fix(harness): keep the workspace subtree invisible to the project layer
## Description With the default local filesystem, the project layer reaches across namespaces in three ways: - Enumeration: `grep(pattern, "")` returns matches from another user's `MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the sibling namespaces. The overlay hands the same path to the upper (workspace) and lower (project) layers, the default workspace is a subtree of the project directory, and the lower layer carries no namespace. - Direct content access: `read`, `exists`, `edit` (copy-on-write), `downloadFiles` and `move` fall back to the lower layer too, so a relative path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md` - reads alice's file, and `edit` copies it into the caller's namespace before modifying it. - Absolute paths: the namespace prefix is skipped for absolute spellings, so without a boundary the `projectFs` write route would run a delete or move against an absolute path inside the workspace subtree. Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace prefix unchanged, so it resolved to the workspace root; the physical layout was reachable whenever the caller named it. ### What changed - A blank key is resolved as `.` before the namespace is applied, so an empty path means "the caller's root" instead of the shared workspace root. Deployments without a namespace resolve to the same directory as before. - `LocalFilesystem` can hide a subtree entirely: enumeration skips it while walking, and the content operations - reads, edits, writes, deletes, moves, downloads, uploads and existence checks - see nothing there. `delete` treats the subtree as absent (an idempotent no-op that never walks it), `move` can neither move a file out of or into the subtree, and both `move` and recursive `delete` refuse a directory that contains it outright rather than partially touch it. Explicitly addressing a hidden subtree as a search root yields nothing rather than walking it, and a `walkFileTree` visitor that cannot enter a directory skips and continues instead of propagating. The check resolves the path first, so a symbolic link that points into the subtree is hidden too; `delete` and `move` still act on the link entry itself, which never reaches the hidden target. Every rejection reads like a missing path, so refusing a hidden path does not announce that something is hidden. - `LocalFilesystemSpec` hides the workspace from the project layers when the workspace is a proper subtree of the project and namespace scoping is on - both the read-only lower layer and, for the same reason, the `projectFs` write route, whose absolute paths skip the namespace prefix. A workspace equal to or outside the project has no nesting to hide, a shared workspace belongs to every caller equally, and project files outside the workspace subtree stay shared, like `AGENTS.md` and `knowledge/`. - The ripgrep path of `grep` runs rg with its working directory set to the search root: `--glob` patterns match against paths relative to the working directory, so the excluded-subtree globs missed whenever the parent process was started outside the search root. Output paths do not depend on the working directory, so entry-path resolution is unaffected. - `relativeForGlob` compares the first path name instead of the string, so a legitimate directory literally named `..cache` is a descendant, not a traversal escape. - `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the Overlay filesystem section, the project-writable read behavior, and the mode table. Absolute paths in the upper (workspace) layer and `..` segments are out of scope: #3292 covers the former, #3378 the latter. Symbolic links are covered here - the path is resolved before the boundary is applied. The shell keeps its own project-rooted working directory, so `execute` is not bound by these guards (#2329). The `walkFileTree` fallback of `grep` applies the same exclusions directly. ### Tests - New: as one user, a blank, relative or glob search sees nothing under another user's namespace - in both the default and the writable-project construction - and the content operations answer "not found" for a sibling namespace spelled through the physical layout, while project files outside the workspace and the caller's own namespace stay readable. - New: a symbolic link planted in the project that points into the workspace subtree stays hidden - `read`, `ls` and `write` see nothing through it, and the target file is untouched. The case skips on hosts that cannot create links. - New: direct use of the hidden lower layer - `delete` leaves the subtree untouched, `move` cannot cross the boundary in either direction, writes cannot land inside it (the target does not exist yet, so the assertion cannot pass merely because the file is there), and operations that start at an ancestor (recursive delete, directory move) are refused outright instead of partially touching the hidden subtree. Each of these assertions was verified to fail with its guard removed. - New: the ripgrep path of `grep` keeps the boundary when the parent process cwd is unrelated to the search root - the pinned directory is deliberately not hidden, so ripgrep's default hidden-file skip cannot mask the result (verified to fail with the working-directory alignment removed). Skipped when ripgrep is not installed. - New: a shared workspace stays enumerable through the project layer, so the boundary does not over-reach into single-tenant deployments. - `mvn -pl agentscope-harness test`: 1628 tests, 0 failures, 37 skipped (Docker, ripgrep and symlink cases that this host cannot run). Fixes #4069
1 parent c52d1fc commit dbcd323

6 files changed

Lines changed: 596 additions & 41 deletions

File tree

0 commit comments

Comments
 (0)