-
Notifications
You must be signed in to change notification settings - Fork 796
fix(memory): toRelative strips workspace root for ROOTED local filesystem paths #1698
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import io.agentscope.harness.agent.filesystem.model.FileInfo; | ||
| import io.agentscope.harness.agent.filesystem.model.GlobResult; | ||
| import io.agentscope.harness.agent.workspace.WorkspaceManager; | ||
| import java.nio.file.Path; | ||
| import java.time.Instant; | ||
| import java.util.ArrayList; | ||
| import java.util.Comparator; | ||
|
|
@@ -264,14 +265,22 @@ private static String fileName(String path) { | |
| } | ||
|
|
||
| /** | ||
| * Converts an absolute filesystem path (e.g. {@code /memory/2025-01-01.md}) to a | ||
| * workspace-relative path ({@code memory/2025-01-01.md}) for use with | ||
| * {@link WorkspaceManager#readManagedWorkspaceFileUtf8}. | ||
| * Converts an absolute filesystem path to a workspace-relative path for use | ||
| * with {@link WorkspaceManager#readManagedWorkspaceFileUtf8}. Strips the | ||
| * workspace root prefix when the path is an absolute local filesystem path; | ||
| * strips only the leading {@code /} for SANDBOXED virtual paths. | ||
| */ | ||
| private static String toRelative(String path) { | ||
| private String toRelative(String path) { | ||
| if (path == null) { | ||
| return ""; | ||
| } | ||
| Path p = Path.of(path); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] No regression test is included for the bug being fixed. The existing |
||
| if (p.isAbsolute()) { | ||
| Path root = workspaceManager.getWorkspace(); | ||
| if (p.startsWith(root)) { | ||
| return root.relativize(p).toString(); | ||
| } | ||
| } | ||
| return path.startsWith("/") ? path.substring(1) : path; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] No regression test is included for the bug being fixed. The existing
MemoryConsolidatorFilesystemTestexercises the Remote/InMemoryStore path but never covers the local ROOTED (non-sandboxed, non-namespaced) case whereFileInfo.path()is a real absolute filesystem path. Consider adding a unit test that creates a localWorkspaceManagerwith a@TempDir, seeds amemory/directory, and asserts thatconsolidate()reads daily ledgers correctly — or at minimum a package-private test that directly invokestoRelative()with all three path shapes (SANDBOXED/memory/x.md, ROOTED absolute/tmp/ws/memory/x.md, namespace-relativens/memory/x.md).