Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(prompts): move the workspace-file upgrade test beside its module

M3gA-Mindd1c0ee7e2a48
diff --git a/crates/openhuman-core/src/agent/prompts/mod_tests_tools_sections_tests.rs b/crates/openhuman-core/src/agent/prompts/mod_tests_tools_sections_tests.rs
index 26f927f540..260806fdea 100644
--- a/crates/openhuman-core/src/agent/prompts/mod_tests_tools_sections_tests.rs
+++ b/crates/openhuman-core/src/agent/prompts/mod_tests_tools_sections_tests.rs
@@ -85,48 +85,6 @@ fn sync_workspace_file_updates_hash_and_inject_workspace_file_truncates() {
let _ = std::fs::remove_dir_all(workspace);
}
-#[test]
-fn a_new_builtin_replaces_an_untouched_file_and_keeps_an_edited_one() {
- // A release changes the bundled SOUL.md. A workspace whose copy still
- // matches the previous built-in gets the new one; a workspace where the
- // user edited it keeps the edit. Both record the new built-in's hash.
- fn hash(content: &str) -> String {
- use std::hash::{Hash, Hasher};
- let mut hasher = std::collections::hash_map::DefaultHasher::new();
- content.hash(&mut hasher);
- format!("{:016x}", hasher.finish())
- }
- let fresh = tempfile::tempdir().unwrap();
- sync_workspace_file(fresh.path(), "SOUL.md");
- let current = std::fs::read_to_string(fresh.path().join("SOUL.md")).unwrap();
- let current_hash = std::fs::read_to_string(fresh.path().join(".SOUL.md.builtin-hash")).unwrap();
-
- for (on_disk, expected) in [
- ("previous built-in SOUL.md", current.as_str()),
- ("the user's own SOUL.md", "the user's own SOUL.md"),
- ] {
- let workspace = tempfile::tempdir().unwrap();
- std::fs::write(workspace.path().join("SOUL.md"), on_disk).unwrap();
- std::fs::write(
- workspace.path().join(".SOUL.md.builtin-hash"),
- hash("previous built-in SOUL.md"),
- )
- .unwrap();
-
- sync_workspace_file(workspace.path(), "SOUL.md");
-
- assert_eq!(
- std::fs::read_to_string(workspace.path().join("SOUL.md")).unwrap(),
- expected,
- "on disk before the upgrade: {on_disk:?}"
- );
- assert_eq!(
- std::fs::read_to_string(workspace.path().join(".SOUL.md.builtin-hash")).unwrap(),
- current_hash
- );
- }
-}
-
#[test]
fn prompt_tool_constructors_and_unknown_default_file() {
let plain = PromptTool::new("shell", "run commands");
diff --git a/crates/openhuman-core/src/prompts/workspace_files.rs b/crates/openhuman-core/src/prompts/workspace_files.rs
index 8c8bb28810..077cdef8e1 100644
--- a/crates/openhuman-core/src/prompts/workspace_files.rs
+++ b/crates/openhuman-core/src/prompts/workspace_files.rs
@@ -258,3 +258,7 @@ pub fn default_workspace_file_content(filename: &str) -> &'static str {
_ => "",
}
}
+
+#[cfg(test)]
+#[path = "workspace_files_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/prompts/workspace_files_tests.rs b/crates/openhuman-core/src/prompts/workspace_files_tests.rs
new file mode 100644
index 0000000000..377234c19b
--- /dev/null
+++ b/crates/openhuman-core/src/prompts/workspace_files_tests.rs
@@ -0,0 +1,43 @@
+use super::*;
+
+#[test]
+fn a_new_builtin_replaces_an_untouched_file_and_keeps_an_edited_one() {
+ // A release changes the bundled SOUL.md. A workspace whose copy still
+ // matches the previous built-in gets the new one; a workspace where the
+ // user edited it keeps the edit. Both record the new built-in's hash.
+ fn hash(content: &str) -> String {
+ use std::hash::{Hash, Hasher};
+ let mut hasher = std::collections::hash_map::DefaultHasher::new();
+ content.hash(&mut hasher);
+ format!("{:016x}", hasher.finish())
+ }
+ let fresh = tempfile::tempdir().unwrap();
+ sync_workspace_file(fresh.path(), "SOUL.md");
+ let current = std::fs::read_to_string(fresh.path().join("SOUL.md")).unwrap();
+ let current_hash = std::fs::read_to_string(fresh.path().join(".SOUL.md.builtin-hash")).unwrap();
+
+ for (on_disk, expected) in [
+ ("previous built-in SOUL.md", current.as_str()),
+ ("the user's own SOUL.md", "the user's own SOUL.md"),
+ ] {
+ let workspace = tempfile::tempdir().unwrap();
+ std::fs::write(workspace.path().join("SOUL.md"), on_disk).unwrap();
+ std::fs::write(
+ workspace.path().join(".SOUL.md.builtin-hash"),
+ hash("previous built-in SOUL.md"),
+ )
+ .unwrap();
+
+ sync_workspace_file(workspace.path(), "SOUL.md");
+
+ assert_eq!(
+ std::fs::read_to_string(workspace.path().join("SOUL.md")).unwrap(),
+ expected,
+ "on disk before the upgrade: {on_disk:?}"
+ );
+ assert_eq!(
+ std::fs::read_to_string(workspace.path().join(".SOUL.md.builtin-hash")).unwrap(),
+ current_hash
+ );
+ }
+}