-
Notifications
You must be signed in to change notification settings - Fork 0
Inject base-directory seam for workspace resolution and migrate last EnvLock users off CWD mutation (#493) #581
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 |
|---|---|---|
|
|
@@ -11,13 +11,23 @@ use cap_std::{ambient_authority, fs_utf8::Dir}; | |
| use std::{env, path::Path}; | ||
|
|
||
| /// Resolve a potentially relative manifest parent path to an absolute UTF-8 workspace root. | ||
| fn resolve_absolute_workspace_root(utf8_parent: &Utf8Path) -> Result<Utf8PathBuf> { | ||
| /// | ||
| /// An injected `base` directory anchors relative parents for tests; `None` | ||
| /// falls back to the process current directory so production behaviour is | ||
| /// unchanged. | ||
| fn resolve_absolute_workspace_root( | ||
| utf8_parent: &Utf8Path, | ||
| base: Option<&Path>, | ||
| ) -> Result<Utf8PathBuf> { | ||
| let workspace_base = if utf8_parent.is_absolute() { | ||
| utf8_parent.to_path_buf().into_std_path_buf() | ||
| } else { | ||
| env::current_dir() | ||
| .context(localization::message(keys::MANIFEST_RESOLVE_WORKSPACE_ROOT))? | ||
| .join(utf8_parent.as_std_path()) | ||
| let anchor = match base { | ||
| Some(dir) => dir.to_path_buf(), | ||
| None => env::current_dir() | ||
| .context(localization::message(keys::MANIFEST_RESOLVE_WORKSPACE_ROOT))?, | ||
| }; | ||
| anchor.join(utf8_parent.as_std_path()) | ||
| }; | ||
| Utf8PathBuf::from_path_buf(workspace_base).map_err(|invalid| { | ||
| anyhow!( | ||
|
|
@@ -40,7 +50,13 @@ pub(super) struct ManifestWorkspace { | |
| } | ||
|
|
||
| /// Open the directory containing `path` as a capability-scoped workspace. | ||
| pub(super) fn open_manifest_workspace(path: &Path) -> Result<ManifestWorkspace> { | ||
| /// | ||
| /// `base` anchors relative manifest paths for tests; `None` keeps the ambient | ||
| /// current-directory resolution used by production callers. | ||
| pub(super) fn open_manifest_workspace( | ||
| path: &Path, | ||
| base: Option<&Path>, | ||
|
Comment on lines
+54
to
+58
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.
This introduces a new injection seam, but the commit does not update any architecture, design, or developer documentation to define its ownership, permitted call sites, and composition rules. The inline statement that it is “for tests” does not establish whether production callers may reuse it or how it relates to the repository's existing environment-seam taxonomy; document that policy in the appropriate indexed guide as required. AGENTS.md reference: AGENTS.md:L111-L119 Useful? React with 👍 / 👎. |
||
| ) -> Result<ManifestWorkspace> { | ||
| let parent = match path.parent() { | ||
| Some(parent) if !parent.as_os_str().is_empty() => parent, | ||
| _ => Path::new("."), | ||
|
|
@@ -70,7 +86,7 @@ pub(super) fn open_manifest_workspace(path: &Path) -> Result<ManifestWorkspace> | |
| .with_arg("path", path.display().to_string()) | ||
| ) | ||
| })?; | ||
| let root = resolve_absolute_workspace_root(utf8_parent)?; | ||
| let root = resolve_absolute_workspace_root(utf8_parent, base)?; | ||
| tracing::debug!(workspace = %root, manifest = %manifest_file, "opening manifest workspace directory"); | ||
| let dir = Dir::open_ambient_dir(root.as_path(), ambient_authority()) | ||
| .inspect_err(|err| { | ||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: leynos/netsuke
Length of output: 50373
🏁 Script executed:
Repository: leynos/netsuke
Length of output: 2659
🏁 Script executed:
Repository: leynos/netsuke
Length of output: 28175
🏁 Script executed:
Repository: leynos/netsuke
Length of output: 293
🏁 Script executed:
Repository: leynos/netsuke
Length of output: 487
Resolve relative
basepaths before joining.When
baseis relative, anchor it toenv::current_dir()before joiningutf8_parent. Otherwise,workspace.rootremains relative, andDir::open_ambient_dirresolves it against the process current directory. Add a test withSome(Path::new("."))that assertsworkspace.root.is_absolute().🤖 Prompt for AI Agents