Skip to content

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

test(flows): add test module for flow registration

Steven Enamakelb4534ecad35e
diff --git a/crates/openhuman-core/src/flows/registration.rs b/crates/openhuman-core/src/flows/registration.rs
index 8fbdfdfae4..3f5cb48084 100644
--- a/crates/openhuman-core/src/flows/registration.rs
+++ b/crates/openhuman-core/src/flows/registration.rs
@@ -117,3 +117,7 @@ pub(crate) fn tools(config: Arc<Config>, security: &Arc<SecurityPolicy>) -> Vec<
Box::new(FlowMemoryRememberTool::new(security.clone())),
]
}
+
+#[cfg(test)]
+#[path = "registration_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/flows/registration_tests.rs b/crates/openhuman-core/src/flows/registration_tests.rs
new file mode 100644
index 0000000000..d0037eee6e
--- /dev/null
+++ b/crates/openhuman-core/src/flows/registration_tests.rs
@@ -0,0 +1,42 @@
+use super::*;
+use serde_json::{json, Value};
+
+/// The persisted catalogue is recorded in session transcripts
+/// (`session_host/recorded_tools.rs`), so every tool's name, description,
+/// parameter schema, permission and external-effect flag must stay
+/// byte-identical across moves of the code behind it. Regenerate the snapshot
+/// deliberately with `UPDATE_FLOW_TOOL_SNAPSHOT=1`.
+fn catalogue() -> Value {
+ let config = Arc::new(Config::default());
+ let security = Arc::new(SecurityPolicy::default());
+ Value::Array(
+ tools(config, &security)
+ .iter()
+ .map(|t| {
+ json!({
+ "name": t.name(),
+ "description": t.description(),
+ "parameters": t.parameters_schema(),
+ "permission": format!("{:?}", t.permission_level()),
+ "external_effect": t.external_effect(),
+ })
+ })
+ .collect(),
+ )
+}
+
+#[test]
+fn flow_tool_catalogue_matches_recorded_snapshot() {
+ let actual = catalogue();
+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
+ .join("src/flows/registration_tests/flow_tools.snap.json");
+ if std::env::var_os("UPDATE_FLOW_TOOL_SNAPSHOT").is_some() {
+ std::fs::create_dir_all(path.parent().unwrap()).unwrap();
+ std::fs::write(&path, serde_json::to_string_pretty(&actual).unwrap() + "\n").unwrap();
+ }
+ let expected: Value = serde_json::from_str(&std::fs::read_to_string(&path).unwrap()).unwrap();
+ assert_eq!(
+ actual, expected,
+ "flow tool catalogue drifted from registration_tests/flow_tools.snap.json"
+ );
+}