use super::*;
fn canonical_root(temp: &TempWorkspace) -> PathBuf {
fs::canonicalize(temp.path()).expect("workspace root should canonicalize")
}
fn sibling_of(root: &Path, suffix: &str) -> PathBuf {
let name = root
.file_name()
.expect("workspace root should have a file name")
.to_string_lossy();
root.parent()
.expect("workspace root should have a parent")
.join(format!("{name}{suffix}"))
}
#[test]
fn read_file_absolute_resource_path_is_not_shadowed_by_a_workspace_file() {
let temp = TempWorkspace::new("path-resource-anchor");
let tools = tools_for(temp.path());
let root = canonical_root(&temp);
let resource = sibling_of(&root, "-resource");
temp.write_text("demo/SKILL.md", "workspace copy\n");
fs::create_dir_all(resource.join("demo")).expect("resource directory should be creatable");
fs::write(resource.join("demo/SKILL.md"), "resource copy\n")
.expect("resource file should be writable");
let absolute = resource.join("demo/SKILL.md");
let absolute_text = absolute.to_str().expect("resource path should be utf8");
let outcome = read_outcome(&tools, absolute_text);
assert_eq!(outcome.status(), ToolCallResultStatus::Succeeded);
assert_eq!(
json_content(&outcome)["content"],
"resource copy\n",
"an absolute path must name the file it was written for, not a same-named file below another root"
);
assert_eq!(
json_content(&outcome)["path"],
absolute_text,
"a file outside the workspace root keeps its absolute spelling"
);
fs::remove_dir_all(&resource).expect("resource tree should be removable");
}
#[test]
fn apply_patch_absolute_path_edits_outside_file_and_not_the_workspace_copy() {
let temp = TempWorkspace::new("path-absolute-anchor");
let tools = tools_for(temp.path());
let root = canonical_root(&temp);
let outside = sibling_of(&root, "-outside.txt");
temp.write_text("note.txt", "alpha\nold\nomega\n");
fs::write(&outside, "alpha\nold\nomega\n").expect("outside file should be writable");
let outside_text = outside.to_str().expect("outside path should be utf8");
let outcome = patch_text_outcome(&tools, &update_patch(outside_text, "old", "new"));
assert_eq!(outcome.status(), ToolCallResultStatus::Succeeded);
assert_eq!(read_text(&outside), "alpha\nnew\nomega\n");
assert_eq!(
read_text(&temp.path().join("note.txt")),
"alpha\nold\nomega\n",
"a same-named workspace file must not receive the outside write"
);
fs::remove_file(&outside).expect("outside file should be removable");
}
#[test]
fn read_file_accepts_absolute_path_inside_the_workspace() {
let temp = TempWorkspace::new("path-absolute-read");
temp.write_text("dir/note.txt", "one\ntwo\n");
let tools = tools_for(temp.path());
let absolute = canonical_root(&temp).join("dir/note.txt");
let outcome = read_outcome(
&tools,
absolute.to_str().expect("absolute path should be utf8"),
);
assert_eq!(outcome.status(), ToolCallResultStatus::Succeeded);
assert_eq!(
json_content(&outcome)["path"],
"dir/note.txt",
"an absolute argument must be reported as a workspace-relative path"
);
assert!(
!outcome
.content()
.as_str()
.contains(canonical_root(&temp).to_str().expect("root utf8")),
"tool output must not include absolute host roots"
);
}
#[test]
fn apply_patch_accepts_absolute_path_inside_the_workspace() {
let temp = TempWorkspace::new("path-absolute-patch");
temp.write_text("dir/note.txt", "alpha\nold\nomega\n");
let tools = tools_for(temp.path());
let absolute = canonical_root(&temp).join("dir/note.txt");
let patch = update_patch(
absolute.to_str().expect("absolute path should be utf8"),
"old",
"new",
);
let outcome = patch_text_outcome(&tools, &patch);
assert_eq!(outcome.status(), ToolCallResultStatus::Succeeded);
assert_eq!(
json_content(&outcome)["changes"][0]["path"],
"dir/note.txt",
"the change must be reported relative to the workspace root"
);
assert_eq!(
read_text(&temp.path().join("dir/note.txt")),
"alpha\nnew\nomega\n"
);
}
#[test]
fn read_file_reads_absolute_path_outside_the_workspace() {
let temp = TempWorkspace::new("path-absolute-outside");
let tools = tools_for(temp.path());
let root = canonical_root(&temp);
let outside = sibling_of(&root, "-outside.txt");
fs::write(&outside, "outside\n").expect("outside file should be writable");
let outside_text = outside.to_str().expect("outside path should be utf8");
let outcome = read_outcome(&tools, outside_text);
assert_eq!(
outcome.status(),
ToolCallResultStatus::Succeeded,
"an absolute path outside the workspace is the caller's own reference, not a tool denial"
);
assert_eq!(json_content(&outcome)["content"], "outside\n");
assert_eq!(
json_content(&outcome)["path"],
outside_text,
"a target outside the workspace root has no workspace-relative spelling to report"
);
fs::remove_file(&outside).expect("outside file should be removable");
}
#[test]
fn apply_patch_edits_files_outside_the_workspace() {
let temp = TempWorkspace::new("path-absolute-patch-outside");
let tools = tools_for(temp.path());
let root = canonical_root(&temp);
let outside_dir = sibling_of(&root, "-outside");
fs::create_dir_all(&outside_dir).expect("outside directory should be creatable");
let existing = outside_dir.join("note.txt");
fs::write(&existing, "alpha\nold\nomega\n").expect("outside file should be writable");
let existing_text = existing.to_str().expect("outside path should be utf8");
let update = patch_text_outcome(&tools, &update_patch(existing_text, "old", "new"));
assert_eq!(update.status(), ToolCallResultStatus::Succeeded);
assert_eq!(read_text(&existing), "alpha\nnew\nomega\n");
let created = outside_dir.join("dir/created.txt");
let created_text = created.to_str().expect("outside path should be utf8");
let add = patch_text_outcome(&tools, &add_patch(created_text, &["one", "two"]));
assert_eq!(add.status(), ToolCallResultStatus::Succeeded);
assert_eq!(read_text(&created), "one\ntwo\n");
let delete = patch_text_outcome(&tools, &delete_patch(existing_text));
assert_eq!(delete.status(), ToolCallResultStatus::Succeeded);
assert!(
!existing.exists(),
"a delete section must remove the file it names"
);
fs::remove_dir_all(&outside_dir).expect("outside directory should be removable");
}
#[test]
fn child_write_scope_denies_absolute_paths_outside_the_workspace() {
let temp = TempWorkspace::new("path-child-write-scope");
let scoped = WorkspaceTools::new(
WorkspaceToolsConfig::new(temp.path().to_path_buf())
.with_patch_write_scope(Some(vec![PathBuf::from("allowed")])),
)
.expect("workspace tools should construct");
let unscoped = tools_for(temp.path());
let root = canonical_root(&temp);
let outside = sibling_of(&root, "-outside.txt");
fs::write(&outside, "alpha\nold\nomega\n").expect("outside file should be writable");
let outside_text = outside.to_str().expect("outside path should be utf8");
let allowed = patch_text_outcome(&unscoped, &update_patch(outside_text, "old", "new"));
assert_eq!(allowed.status(), ToolCallResultStatus::Succeeded);
assert_eq!(read_text(&outside), "alpha\nnew\nomega\n");
fs::write(&outside, "alpha\nold\nomega\n").expect("outside file should be restored");
let denied = patch_text_outcome(&scoped, &update_patch(outside_text, "old", "new"));
assert_eq!(denied.status(), ToolCallResultStatus::Failed);
assert_eq!(
denied.diagnostic().expect("diagnostic").code(),
ERROR_PATH_DENIED
);
assert!(
json_content(&denied)["error"]["message"]
.as_str()
.expect("message should be text")
.contains("outside the configured write scope"),
"a child agent must not leave its write scope by naming an absolute path"
);
assert_eq!(read_text(&outside), "alpha\nold\nomega\n");
fs::remove_file(&outside).expect("outside file should be removable");
}
#[derive(Debug)]
struct TestExternalTreePolicy {
root: PathBuf,
read_paths: std::sync::Mutex<Vec<PathBuf>>,
committed_paths: std::sync::Mutex<Vec<PathBuf>>,
}
impl TestExternalTreePolicy {
fn new(root: PathBuf) -> Self {
Self {
root,
read_paths: std::sync::Mutex::new(Vec::new()),
committed_paths: std::sync::Mutex::new(Vec::new()),
}
}
}
impl crate::ExternalTreePolicy for TestExternalTreePolicy {
fn root(&self) -> &Path {
&self.root
}
fn governs_path(&self, path: &Path) -> bool {
path.starts_with(&self.root)
}
fn on_text_read(&self, path: &Path) -> Result<(), String> {
if self.governs_path(path) {
self.read_paths
.lock()
.expect("read lock")
.push(path.to_path_buf());
}
Ok(())
}
fn authorize_write(
&self,
kind: crate::ExternalWriteKind,
path: &Path,
_byte_len: usize,
) -> Result<(), String> {
if !self.governs_path(path) {
return Ok(());
}
if matches!(
kind,
crate::ExternalWriteKind::Update | crate::ExternalWriteKind::Delete
) && !self
.read_paths
.lock()
.expect("read lock")
.iter()
.any(|seen| seen == path)
{
return Err("external tree requires reading a file before updating it".to_owned());
}
Ok(())
}
fn on_writes_committed(&self, paths: &[PathBuf]) -> Result<(), String> {
self.committed_paths
.lock()
.expect("committed lock")
.extend(paths.iter().cloned());
Ok(())
}
}
#[test]
fn read_only_write_scope_still_allows_governed_external_tree_writes() {
let temp = TempWorkspace::new("path-memory-write-scope");
let root = canonical_root(&temp);
let external_root = sibling_of(&root, "-memory");
fs::create_dir_all(&external_root).expect("external root should be created");
let external_root = fs::canonicalize(&external_root).expect("canonical external root");
let tree_policy = std::sync::Arc::new(TestExternalTreePolicy::new(external_root.clone()));
let note = external_root.join("observations/_inbox/note.md");
let tools = WorkspaceTools::new(
WorkspaceToolsConfig::new(temp.path().to_path_buf())
.with_patch_write_scope(Some(Vec::new()))
.with_external_tree_policy(tree_policy.clone()),
)
.expect("workspace tools should construct");
let note_text = note.to_str().expect("external note path should be utf8");
let created = patch_text_outcome(&tools, &add_patch(note_text, &["# Note", "", "A fact."]));
assert_eq!(created.status(), ToolCallResultStatus::Succeeded);
assert_eq!(read_text(¬e), "# Note\n\nA fact.\n");
assert_eq!(
tree_policy.committed_paths.lock().expect("committed").len(),
1
);
let outside = sibling_of(&root, "-nope.txt");
let outside_text = outside.to_str().expect("outside path should be utf8");
let denied = patch_text_outcome(&tools, &add_patch(outside_text, &["no"]));
assert_eq!(denied.status(), ToolCallResultStatus::Failed);
assert!(
json_content(&denied)["error"]["message"]
.as_str()
.expect("message should be text")
.contains("this write scope allows no workspace files")
);
assert!(
!outside.exists(),
"a read-only scope must not create workspace files"
);
fs::remove_dir_all(&external_root).expect("external root should be removable");
}
#[test]
fn write_forbidden_paths_block_patches_without_blocking_reads() {
let temp = TempWorkspace::new("path-write-forbidden");
temp.write_text(".git/config", "[core]\n");
let tools = WorkspaceTools::new(
WorkspaceToolsConfig::new(temp.path().to_path_buf())
.with_write_forbidden_paths(vec![PathBuf::from(".git")]),
)
.expect("workspace tools should construct");
let read = read_outcome(&tools, ".git/config");
assert_eq!(read.status(), ToolCallResultStatus::Succeeded);
let patch = patch_text_outcome(&tools, &update_patch(".git/config", "[core]", "[changed]"));
assert_eq!(patch.status(), ToolCallResultStatus::Failed);
assert_eq!(
patch.diagnostic().expect("diagnostic").code(),
ERROR_PATH_DENIED
);
}
#[cfg(unix)]
#[test]
fn read_file_follows_platform_symlinks_outside_the_workspace() {
let temp = TempWorkspace::new("path-outside-symlink");
let tools = tools_for(temp.path());
let root = canonical_root(&temp);
let target_dir = sibling_of(&root, "-linked");
let link_dir = sibling_of(&root, "-link");
fs::create_dir_all(&target_dir).expect("linked directory should be creatable");
fs::write(target_dir.join("note.txt"), "linked\n").expect("linked file should be writable");
symlink(&target_dir, &link_dir).expect("directory symlink should be created");
let linked = link_dir.join("note.txt");
let outcome = read_outcome(&tools, linked.to_str().expect("linked path should be utf8"));
assert_eq!(outcome.status(), ToolCallResultStatus::Succeeded);
assert_eq!(json_content(&outcome)["content"], "linked\n");
fs::remove_file(link_dir.as_path()).expect("directory symlink should be removable");
fs::remove_dir_all(&target_dir).expect("linked directory should be removable");
}
#[test]
fn workspace_path_normalizes_dot_segments_and_resolves_escapes() {
let temp = TempWorkspace::new("path-dot-segments");
temp.write_text("dir/note.txt", "one\ntwo\n");
let tools = tools_for(temp.path());
let root = canonical_root(&temp);
let inside = read_outcome(&tools, "./dir/../dir/note.txt");
assert_eq!(
inside.status(),
ToolCallResultStatus::Succeeded,
"redundant dot segments name the same file and must not be rejected"
);
assert_eq!(json_content(&inside)["path"], "dir/note.txt");
let sibling = sibling_of(&root, "-climbed.txt");
fs::write(&sibling, "climbed\n").expect("sibling file should be writable");
let named = sibling
.strip_prefix(root.parent().expect("root parent"))
.expect("sibling is below the shared parent");
let climbed = read_outcome(&tools, &format!("../{}", named.display()));
assert_eq!(
climbed.status(),
ToolCallResultStatus::Succeeded,
"a relative path that climbs above the root names a real file"
);
assert_eq!(json_content(&climbed)["content"], "climbed\n");
assert_eq!(
json_content(&climbed)["path"],
format!("../{}", named.display()),
"the reported path keeps the escape visible"
);
fs::remove_file(&sibling).expect("sibling file should be removable");
}
#[test]
fn workspace_path_denies_the_root_itself_and_reads_prefix_lookalikes() {
let temp = TempWorkspace::new("path-root-lookalike");
temp.write_text("dir/note.txt", "one\ntwo\n");
let tools = tools_for(temp.path());
let root = canonical_root(&temp);
let root_text = root.to_str().expect("root path should be utf8");
let as_root = read_outcome(&tools, root_text);
assert_failed_json(&as_root, ERROR_PATH_DENIED, None, root.as_path());
assert!(
json_content(&as_root)["error"]["message"]
.as_str()
.expect("message should be text")
.contains("not the root itself"),
"the root is a directory to browse, never a file to read"
);
let lookalike_dir = sibling_of(&root, "-lookalike");
fs::create_dir_all(lookalike_dir.join("dir")).expect("lookalike tree should be creatable");
fs::write(lookalike_dir.join("dir/note.txt"), "sibling\n")
.expect("lookalike file should be writable");
let lookalike = lookalike_dir.join("dir/note.txt");
let lookalike_text = lookalike.to_str().expect("lookalike path should be utf8");
let sibling = read_outcome(&tools, lookalike_text);
assert_eq!(
sibling.status(),
ToolCallResultStatus::Succeeded,
"a sibling that shares the root's name prefix is its own target"
);
assert_eq!(json_content(&sibling)["content"], "sibling\n");
assert_eq!(
json_content(&sibling)["path"],
lookalike_text,
"the sibling is not inside the workspace root, so it is reported absolute"
);
fs::remove_dir_all(&lookalike_dir).expect("lookalike tree should be removable");
}
#[test]
fn workspace_path_reads_hidden_components_after_normalization() {
let temp = TempWorkspace::new("path-hidden-after-normalization");
temp.write_text(".git/config", "[core]\n");
let tools = tools_for(temp.path());
let outcome = read_outcome(&tools, "dir/../.git/config");
assert_eq!(
outcome.status(),
ToolCallResultStatus::Succeeded,
"a leading dot is ordinary spelling and must survive normalization"
);
assert_eq!(
json_content(&outcome)["path"],
".git/config",
"the reported path is the normalized workspace-relative form"
);
assert_eq!(json_content(&outcome)["content"], "[core]\n");
}
#[test]
fn host_path_policy_blocks_credentials_and_allows_readonly_state_dir() {
let temp = TempWorkspace::new("path-denied-absolute");
let root = canonical_root(&temp);
let state_dir = sibling_of(&root, "-private-state");
let providers_dir = sibling_of(&root, "-providers");
let trust_file = state_dir.join("workspace-trust.json");
let input_history_file = state_dir.join("input-history/workspace.jsonl");
let log_file = state_dir.join("logs/merry.jsonl");
let journal_file = state_dir.join("sessions/sess-1/journal.jsonl");
let secret_file = providers_dir.join("secrets/openai.key");
let nested_secret = state_dir.join("external.key");
fs::create_dir_all(journal_file.parent().expect("journal parent"))
.expect("journal dir should be created");
fs::create_dir_all(input_history_file.parent().expect("input history parent"))
.expect("input history dir should be created");
fs::create_dir_all(log_file.parent().expect("log parent")).expect("log dir should be created");
fs::create_dir_all(secret_file.parent().expect("secret parent"))
.expect("providers dir should be created");
fs::write(&trust_file, "{}\n").expect("trust file should write");
fs::write(&input_history_file, "\"hello\"\n").expect("input history should write");
fs::write(&log_file, "{\"level\":\"INFO\"}\n").expect("log file should write");
fs::write(&journal_file, "{\"event\":\"started\"}\n").expect("journal file should write");
fs::write(&secret_file, "sk-top-secret\n").expect("secret file should write");
fs::write(&nested_secret, "sk-nested-secret\n").expect("nested secret should write");
let allowed_dir = sibling_of(&root, "-config-dir");
let allowed_file = allowed_dir.join("config.toml");
fs::create_dir_all(&allowed_dir).expect("allowed dir should be created");
fs::write(&allowed_file, "profile = 'coding'\n").expect("allowed file should write");
let policy =
merry_core::HostPathPolicy::from_merry_dirs(state_dir.clone(), providers_dir.clone())
.extend_denied([nested_secret.clone()]);
let tools = WorkspaceTools::new(
WorkspaceToolsConfig::new(temp.path().to_path_buf()).with_host_path_policy(policy),
)
.expect("workspace tools should construct");
let secret_text = secret_file.to_str().expect("secret path should be utf8");
let read_denied = read_outcome(&tools, secret_text);
assert_eq!(read_denied.status(), ToolCallResultStatus::Failed);
assert_eq!(
read_denied.diagnostic().expect("diagnostic").code(),
ERROR_PATH_DENIED
);
let nested_secret_text = nested_secret
.to_str()
.expect("nested secret path should be utf8");
let nested_secret_read_denied = read_outcome(&tools, nested_secret_text);
assert_eq!(
nested_secret_read_denied.status(),
ToolCallResultStatus::Failed
);
assert_eq!(
nested_secret_read_denied
.diagnostic()
.expect("diagnostic")
.code(),
ERROR_PATH_DENIED
);
let climbed = format!(
"../{}/secrets/openai.key",
providers_dir
.file_name()
.expect("providers dir name")
.to_str()
.expect("utf8")
);
let climbed_read_denied = read_outcome(&tools, &climbed);
assert_eq!(climbed_read_denied.status(), ToolCallResultStatus::Failed);
assert_eq!(
climbed_read_denied.diagnostic().expect("diagnostic").code(),
ERROR_PATH_DENIED
);
let update_denied = patch_text_outcome(
&tools,
&update_patch(secret_text, "sk-top-secret", "sk-tampered"),
);
assert_eq!(update_denied.status(), ToolCallResultStatus::Failed);
assert_eq!(
update_denied.diagnostic().expect("diagnostic").code(),
ERROR_PATH_DENIED
);
let added_secret = providers_dir.join("secrets/new.key");
let add_denied = patch_text_outcome(
&tools,
&add_patch(added_secret.to_str().expect("utf8"), &["sk-new"]),
);
assert_eq!(add_denied.status(), ToolCallResultStatus::Failed);
assert_eq!(
add_denied.diagnostic().expect("diagnostic").code(),
ERROR_PATH_DENIED
);
assert!(!added_secret.exists());
let delete_denied = patch_text_outcome(&tools, &delete_patch(secret_text));
assert_eq!(delete_denied.status(), ToolCallResultStatus::Failed);
assert_eq!(
delete_denied.diagnostic().expect("diagnostic").code(),
ERROR_PATH_DENIED
);
assert_eq!(read_text(&secret_file), "sk-top-secret\n");
for (path, expected) in [
(&journal_file, "{\"event\":\"started\"}\n"),
(&input_history_file, "\"hello\"\n"),
(&log_file, "{\"level\":\"INFO\"}\n"),
(&trust_file, "{}\n"),
] {
let path_text = path.to_str().expect("state path should be utf8");
let read = read_outcome(&tools, path_text);
assert_eq!(read.status(), ToolCallResultStatus::Succeeded);
assert_eq!(json_content(&read)["content"], expected);
}
let journal_text = journal_file.to_str().expect("journal path should be utf8");
let journal_update_denied = patch_text_outcome(
&tools,
&update_patch(
journal_text,
"{\"event\":\"started\"}",
"{\"event\":\"tampered\"}",
),
);
assert_eq!(journal_update_denied.status(), ToolCallResultStatus::Failed);
assert_eq!(
journal_update_denied
.diagnostic()
.expect("diagnostic")
.code(),
ERROR_PATH_DENIED
);
let trust_text = trust_file.to_str().expect("trust path should be utf8");
let trust_update_denied =
patch_text_outcome(&tools, &update_patch(trust_text, "{}", "{\"t\":1}"));
assert_eq!(trust_update_denied.status(), ToolCallResultStatus::Failed);
assert_eq!(
trust_update_denied.diagnostic().expect("diagnostic").code(),
ERROR_PATH_DENIED
);
let journal_delete_denied = patch_text_outcome(&tools, &delete_patch(journal_text));
assert_eq!(journal_delete_denied.status(), ToolCallResultStatus::Failed);
assert_eq!(
journal_delete_denied
.diagnostic()
.expect("diagnostic")
.code(),
ERROR_PATH_DENIED
);
assert_eq!(read_text(&journal_file), "{\"event\":\"started\"}\n");
assert_eq!(read_text(&trust_file), "{}\n");
let allowed_text = allowed_file.to_str().expect("allowed path should be utf8");
let read_allowed = read_outcome(&tools, allowed_text);
assert_eq!(read_allowed.status(), ToolCallResultStatus::Succeeded);
let update_allowed = patch_text_outcome(
&tools,
&update_patch(allowed_text, "profile = 'coding'", "profile = 'updated'"),
);
assert_eq!(update_allowed.status(), ToolCallResultStatus::Succeeded);
assert_eq!(read_text(&allowed_file), "profile = 'updated'\n");
fs::remove_dir_all(&state_dir).expect("state dir should be removable");
fs::remove_dir_all(&providers_dir).expect("providers dir should be removable");
fs::remove_dir_all(&allowed_dir).expect("allowed dir should be removable");
}
#[test]
fn host_path_policy_allows_nested_memory_writes_and_denies_nested_providers_under_state_dir() {
let temp = TempWorkspace::new("path-shared-state-data");
let root = canonical_root(&temp);
let shared_merry_dir = sibling_of(&root, "-localappdata-merry");
let providers_dir = shared_merry_dir.join("providers");
let memory_root = shared_merry_dir.join("memory");
let journal_file = shared_merry_dir.join("sessions/s1/journal.jsonl");
let secret_file = providers_dir.join("secrets/openai.key");
fs::create_dir_all(journal_file.parent().expect("journal parent")).expect("journal dir");
fs::create_dir_all(secret_file.parent().expect("secret parent")).expect("providers dir");
fs::create_dir_all(&memory_root).expect("memory dir");
fs::write(&journal_file, "{\"event\":\"ok\"}\n").expect("journal write");
fs::write(&secret_file, "sk-shared-secret\n").expect("secret write");
let memory_root = fs::canonicalize(&memory_root).expect("canonical memory dir");
let tree_policy = std::sync::Arc::new(TestExternalTreePolicy::new(memory_root.clone()));
let memory_note = memory_root.join("topics/sandbox.md");
fs::create_dir_all(memory_note.parent().expect("topics dir")).expect("topics dir");
fs::write(&memory_note, "# Sandbox\n\nOld note.\n").expect("memory note write");
let policy = merry_core::HostPathPolicy::from_merry_dirs(
shared_merry_dir.clone(),
providers_dir.clone(),
)
.with_durable_memory_root(Some(memory_root));
let tools = WorkspaceTools::new(
WorkspaceToolsConfig::new(temp.path().to_path_buf())
.with_host_path_policy(policy)
.with_external_tree_policy(tree_policy),
)
.expect("workspace tools should construct");
let journal_text = journal_file.to_str().expect("utf8 journal");
let read_journal = read_outcome(&tools, journal_text);
assert_eq!(read_journal.status(), ToolCallResultStatus::Succeeded);
let patch_journal = patch_text_outcome(
&tools,
&update_patch(journal_text, "{\"event\":\"ok\"}", "{\"event\":\"bad\"}"),
);
assert_eq!(patch_journal.status(), ToolCallResultStatus::Failed);
assert_eq!(
patch_journal.diagnostic().expect("diagnostic").code(),
ERROR_PATH_DENIED
);
let secret_text = secret_file.to_str().expect("utf8 secret");
let read_secret = read_outcome(&tools, secret_text);
assert_eq!(read_secret.status(), ToolCallResultStatus::Failed);
assert_eq!(
read_secret.diagnostic().expect("diagnostic").code(),
ERROR_PATH_DENIED
);
let note_text = memory_note.to_str().expect("utf8 note");
let read_note = read_outcome(&tools, note_text);
assert_eq!(read_note.status(), ToolCallResultStatus::Succeeded);
let patch_note = patch_text_outcome(&tools, &update_patch(note_text, "Old note.", "New note."));
assert_eq!(patch_note.status(), ToolCallResultStatus::Succeeded);
assert_eq!(read_text(&memory_note), "# Sandbox\n\nNew note.\n");
fs::remove_dir_all(&shared_merry_dir).expect("shared dir should be removable");
}