Skip to content

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

refactor: extract inline test modules into separate test files

Steven Enamakel50c72b376c11
diff --git a/src/openhuman/agent/debug/prompt_size.rs b/src/openhuman/agent/debug/prompt_size.rs
index 0293b7ed81..17481c1c5d 100644
--- a/src/openhuman/agent/debug/prompt_size.rs
+++ b/src/openhuman/agent/debug/prompt_size.rs
@@ -285,78 +285,5 @@ pub fn render_text(report: &PromptSizeReport, section_limit: usize, tool_limit:
}
#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn sections_sum_to_the_whole_prompt() {
- let text = "preamble line\n# Title\nbody\n## Sub\nmore body\n### Deep\ntail\n";
- let sections = split_sections(text);
- let total: usize = sections.iter().map(|s| s.bytes).sum();
- assert_eq!(
- total,
- text.len(),
- "section bytes must account for every byte of the prompt; \
- a table that does not sum is worse than no table"
- );
- }
-
- #[test]
- fn preamble_is_kept_when_text_starts_before_the_first_heading() {
- let sections = split_sections("loose text\n# Title\nbody\n");
- assert_eq!(sections[0].heading, "(preamble)");
- assert_eq!(sections[0].bytes, "loose text\n".len());
- }
-
- #[test]
- fn no_preamble_entry_when_the_prompt_opens_on_a_heading() {
- let sections = split_sections("# Title\nbody\n");
- assert_eq!(sections.len(), 1);
- assert_eq!(sections[0].heading, "# Title");
- }
-
- #[test]
- fn deeper_headings_do_not_split() {
- // `####` is body text as far as this report is concerned.
- let sections = split_sections("## Sub\na\n#### Deeper\nb\n");
- assert_eq!(sections.len(), 1);
- }
-
- #[test]
- fn a_bare_hash_is_not_a_heading() {
- // No trailing space: a shell comment in an example block, not a section.
- assert!(!is_heading("#!/usr/bin/env bash\n"));
- assert!(!is_heading("#hashtag\n"));
- assert!(is_heading("## Real\n"));
- }
-
- #[test]
- fn tools_are_ranked_by_cost_not_registration_order() {
- let dumped = DumpedPrompt {
- agent_id: "t".into(),
- toolkit: None,
- mode: "session",
- model: "m".into(),
- workspace_dir: std::path::PathBuf::from("/tmp"),
- text: "# A\nbody\n".into(),
- tool_names: vec!["small".into(), "big".into()],
- skill_tool_count: 0,
- tool_specs: vec![
- serde_json::json!({"name": "small", "description": "s", "parameters": {}}),
- serde_json::json!({
- "name": "big",
- "description": "a much longer description than the other one",
- "parameters": {"type": "object", "properties": {"a": {"type": "string"}}}
- }),
- ],
- };
- let report = PromptSizeReport::from_dump(&dumped);
- assert_eq!(report.tools[0].name, "big");
- assert_eq!(report.tool_count, 2);
- assert_eq!(
- report.fixed_prefix_bytes,
- report.prompt_bytes + report.tool_bytes
- );
- assert!(report.tools[1].parameters_bytes > 0, "`{{}}` is two bytes");
- }
-}
+#[path = "prompt_size_tests.rs"]
+mod tests;
diff --git a/src/openhuman/agent/debug/prompt_size_tests.rs b/src/openhuman/agent/debug/prompt_size_tests.rs
new file mode 100644
index 0000000000..ab2c2e8ecb
--- /dev/null
+++ b/src/openhuman/agent/debug/prompt_size_tests.rs
@@ -0,0 +1,74 @@
+use super::*;
+
+ #[test]
+ fn sections_sum_to_the_whole_prompt() {
+ let text = "preamble line\n# Title\nbody\n## Sub\nmore body\n### Deep\ntail\n";
+ let sections = split_sections(text);
+ let total: usize = sections.iter().map(|s| s.bytes).sum();
+ assert_eq!(
+ total,
+ text.len(),
+ "section bytes must account for every byte of the prompt; \
+ a table that does not sum is worse than no table"
+ );
+ }
+
+ #[test]
+ fn preamble_is_kept_when_text_starts_before_the_first_heading() {
+ let sections = split_sections("loose text\n# Title\nbody\n");
+ assert_eq!(sections[0].heading, "(preamble)");
+ assert_eq!(sections[0].bytes, "loose text\n".len());
+ }
+
+ #[test]
+ fn no_preamble_entry_when_the_prompt_opens_on_a_heading() {
+ let sections = split_sections("# Title\nbody\n");
+ assert_eq!(sections.len(), 1);
+ assert_eq!(sections[0].heading, "# Title");
+ }
+
+ #[test]
+ fn deeper_headings_do_not_split() {
+ // `####` is body text as far as this report is concerned.
+ let sections = split_sections("## Sub\na\n#### Deeper\nb\n");
+ assert_eq!(sections.len(), 1);
+ }
+
+ #[test]
+ fn a_bare_hash_is_not_a_heading() {
+ // No trailing space: a shell comment in an example block, not a section.
+ assert!(!is_heading("#!/usr/bin/env bash\n"));
+ assert!(!is_heading("#hashtag\n"));
+ assert!(is_heading("## Real\n"));
+ }
+
+ #[test]
+ fn tools_are_ranked_by_cost_not_registration_order() {
+ let dumped = DumpedPrompt {
+ agent_id: "t".into(),
+ toolkit: None,
+ mode: "session",
+ model: "m".into(),
+ workspace_dir: std::path::PathBuf::from("/tmp"),
+ text: "# A\nbody\n".into(),
+ tool_names: vec!["small".into(), "big".into()],
+ skill_tool_count: 0,
+ tool_specs: vec![
+ serde_json::json!({"name": "small", "description": "s", "parameters": {}}),
+ serde_json::json!({
+ "name": "big",
+ "description": "a much longer description than the other one",
+ "parameters": {"type": "object", "properties": {"a": {"type": "string"}}}
+ }),
+ ],
+ };
+ let report = PromptSizeReport::from_dump(&dumped);
+ assert_eq!(report.tools[0].name, "big");
+ assert_eq!(report.tool_count, 2);
+ assert_eq!(
+ report.fixed_prefix_bytes,
+ report.prompt_bytes + report.tool_bytes
+ );
+ assert!(report.tools[1].parameters_bytes > 0, "`{{}}` is two bytes");
+ }
+
diff --git a/src/openhuman/cron/tools/collapsed.rs b/src/openhuman/cron/tools/collapsed.rs
index bf818dfafa..ccd86e1d83 100644
--- a/src/openhuman/cron/tools/collapsed.rs
+++ b/src/openhuman/cron/tools/collapsed.rs
@@ -188,97 +188,5 @@ impl Tool for CronTool {
}
#[cfg(test)]
-mod tests {
- use super::*;
-
- fn tool() -> CronTool {
- CronTool::new(
- Arc::new(Config::default()),
- Arc::new(SecurityPolicy::default()),
- )
- }
-
- #[test]
- fn the_schema_advertises_every_action() {
- let schema = tool().parameters_schema();
- let actions = schema["properties"]["action"]["enum"]
- .as_array()
- .expect("enum")
- .iter()
- .map(|v| v.as_str().unwrap_or_default().to_string())
- .collect::<Vec<_>>();
- assert_eq!(
- actions,
- vec!["list", "add", "update", "remove", "run", "runs"]
- );
- }
-
- #[test]
- fn the_schema_carries_the_members_parameters() {
- // `job_id` comes from four members and `patch` only from `update`.
- // Their presence is what proves the merge read the members rather than
- // a hand-written union that could drift from them.
- let schema = tool().parameters_schema();
- let props = schema["properties"].as_object().expect("properties");
- assert!(props.contains_key("job_id"));
- assert!(props.contains_key("patch"));
- }
-
- #[test]
- fn a_read_only_action_is_not_reported_as_execute() {
- // The whole point of `permission_level_with_args`: collapsing must not
- // silently promote `list` to the privilege `add` needs.
- let tool = tool();
- let listing = serde_json::json!({"action": "list"});
- assert!(
- tool.permission_level_with_args(&listing) < tool.permission_level(),
- "list must resolve below the family's strictest level"
- );
- }
-
- #[test]
- fn an_unknown_action_falls_back_to_the_strictest_level() {
- let tool = tool();
- let nonsense = serde_json::json!({"action": "definitely_not_an_action"});
- assert_eq!(
- tool.permission_level_with_args(&nonsense),
- tool.permission_level()
- );
- }
-
- #[test]
- fn a_missing_action_falls_back_to_the_strictest_level() {
- let tool = tool();
- assert_eq!(
- tool.permission_level_with_args(&serde_json::json!({})),
- tool.permission_level()
- );
- }
-
- #[tokio::test]
- async fn an_unknown_action_is_an_error_result_naming_the_valid_ones() {
- let result = tool()
- .execute(serde_json::json!({"action": "nope"}))
- .await
- .expect("dispatch does not fail the call");
- assert!(result.is_error);
- let text = format!("{result:?}");
- assert!(text.contains("nope"), "names what was passed: {text}");
- assert!(text.contains("list|add"), "names the valid actions: {text}");
- }
-
- #[test]
- fn every_member_is_hidden_so_the_collapse_actually_saves_something() {
- // The load-bearing assertion. Adding an action to the table while
- // leaving its member `Direct` would ship both surfaces and save
- // nothing, and nothing else in the build would notice.
- for entry in tool().actions() {
- assert_eq!(
- entry.tool.exposure(),
- ToolExposure::Hidden,
- "`{}` is still advertised alongside the collapsed `cron` tool",
- entry.tool.name()
- );
- }
- }
-}
+#[path = "collapsed_tests.rs"]
+mod tests;
diff --git a/src/openhuman/cron/tools/collapsed_tests.rs b/src/openhuman/cron/tools/collapsed_tests.rs
new file mode 100644
index 0000000000..3f75ed640a
--- /dev/null
+++ b/src/openhuman/cron/tools/collapsed_tests.rs
@@ -0,0 +1,93 @@
+use super::*;
+
+ fn tool() -> CronTool {
+ CronTool::new(
+ Arc::new(Config::default()),
+ Arc::new(SecurityPolicy::default()),
+ )
+ }
+
+ #[test]
+ fn the_schema_advertises_every_action() {
+ let schema = tool().parameters_schema();
+ let actions = schema["properties"]["action"]["enum"]
+ .as_array()
+ .expect("enum")
+ .iter()
+ .map(|v| v.as_str().unwrap_or_default().to_string())
+ .collect::<Vec<_>>();
+ assert_eq!(
+ actions,
+ vec!["list", "add", "update", "remove", "run", "runs"]
+ );
+ }
+
+ #[test]
+ fn the_schema_carries_the_members_parameters() {
+ // `job_id` comes from four members and `patch` only from `update`.
+ // Their presence is what proves the merge read the members rather than
+ // a hand-written union that could drift from them.
+ let schema = tool().parameters_schema();
+ let props = schema["properties"].as_object().expect("properties");
+ assert!(props.contains_key("job_id"));
+ assert!(props.contains_key("patch"));
+ }
+
+ #[test]
+ fn a_read_only_action_is_not_reported_as_execute() {
+ // The whole point of `permission_level_with_args`: collapsing must not
+ // silently promote `list` to the privilege `add` needs.
+ let tool = tool();
+ let listing = serde_json::json!({"action": "list"});
+ assert!(
+ tool.permission_level_with_args(&listing) < tool.permission_level(),
+ "list must resolve below the family's strictest level"
+ );
+ }
+
+ #[test]
+ fn an_unknown_action_falls_back_to_the_strictest_level() {
+ let tool = tool();
+ let nonsense = serde_json::json!({"action": "definitely_not_an_action"});
+ assert_eq!(
+ tool.permission_level_with_args(&nonsense),
+ tool.permission_level()
+ );
+ }
+
+ #[test]
+ fn a_missing_action_falls_back_to_the_strictest_level() {
+ let tool = tool();
+ assert_eq!(
+ tool.permission_level_with_args(&serde_json::json!({})),
+ tool.permission_level()
+ );
+ }
+
+ #[tokio::test]
+ async fn an_unknown_action_is_an_error_result_naming_the_valid_ones() {
+ let result = tool()
+ .execute(serde_json::json!({"action": "nope"}))
+ .await
+ .expect("dispatch does not fail the call");
+ assert!(result.is_error);
+ let text = format!("{result:?}");
+ assert!(text.contains("nope"), "names what was passed: {text}");
+ assert!(text.contains("list|add"), "names the valid actions: {text}");
+ }
+
+ #[test]
+ fn every_member_is_hidden_so_the_collapse_actually_saves_something() {
+ // The load-bearing assertion. Adding an action to the table while
+ // leaving its member `Direct` would ship both surfaces and save
+ // nothing, and nothing else in the build would notice.
+ for entry in tool().actions() {
+ assert_eq!(
+ entry.tool.exposure(),
+ ToolExposure::Hidden,
+ "`{}` is still advertised alongside the collapsed `cron` tool",
+ entry.tool.name()
+ );
+ }
+ }
+
diff --git a/src/openhuman/flows/skills/mod.rs b/src/openhuman/flows/skills/mod.rs
index 0a39cd4016..d65cf5e036 100644
--- a/src/openhuman/flows/skills/mod.rs
+++ b/src/openhuman/flows/skills/mod.rs
@@ -63,140 +63,5 @@ pub const FLOW_AUTHORING: BundledSkill = BundledSkill {
};
#[cfg(test)]
-mod tests {
- use super::*;
-
- fn skill_dir() -> std::path::PathBuf {
- std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
- .join("src/openhuman/flows/skills/flow-authoring")
- }
-
- #[test]
- fn bundled_skill_matches_the_directory_on_disk() {
- // A page added to the directory but not to `FLOW_AUTHORING` is not a
- // compile error and not a test failure anywhere else — it simply never
- // ships, and the prompt's pointer table sends the model to a file that
- // does not exist. This is that check.
- let root = skill_dir();
- let mut on_disk = Vec::new();
- for entry in walkdir(&root) {
- let rel = entry
- .strip_prefix(&root)
- .expect("under root")
- .to_string_lossy()
- .replace('\\', "/");
- on_disk.push(rel);
- }
- on_disk.sort();
-
- let mut listed: Vec<String> = FLOW_AUTHORING
- .files
- .iter()
- .map(|f| f.path.to_string())
- .collect();
- listed.sort();
-
- assert_eq!(
- listed, on_disk,
- "FLOW_AUTHORING's file list and the on-disk bundle have diverged"
- );
- }
-
- fn walkdir(root: &std::path::Path) -> Vec<std::path::PathBuf> {
- let mut out = Vec::new();
- let mut stack = vec![root.to_path_buf()];
- while let Some(dir) = stack.pop() {
- for entry in std::fs::read_dir(&dir).expect("read_dir").flatten() {
- let path = entry.path();
- if path.is_dir() {
- stack.push(path);
- } else {
- out.push(path);
- }
- }
- }
- out
- }
-
- #[test]
- fn every_page_the_manifest_advertises_exists() {
- // The WORKFLOW.md table is what the model reads to choose a page. A
- // row naming a file that does not ship is a dead end the model cannot
- // diagnose — it just gets an error and gives up on the manual.
- let manifest = FLOW_AUTHORING
- .files
- .iter()
- .find(|f| f.path == "WORKFLOW.md")
- .expect("manifest")
- .contents;
- for file in FLOW_AUTHORING.files {
- if file.path == "WORKFLOW.md" {
- continue;
- }
- assert!(
- manifest.contains(file.path),
- "`{}` ships but the manifest's table never names it",
- file.path
- );
- }
- for line in manifest.lines() {
- for token in line.split('`') {
- if token.starts_with("references/") {
- assert!(
- FLOW_AUTHORING.files.iter().any(|f| f.path == token),
- "the manifest points at `{token}`, which does not ship"
- );
- }
- }
- }
- }
-
- #[test]
- fn the_frontmatter_description_does_not_advertise_a_dropped_page() {
- // The description is what the model reads in the `## Installed Skills`
- // catalogue to decide whether to open the skill at all, and it is prose
- // rather than a path — so the `references/` token check below cannot
- // see it. It went stale the first time a page moved back into the
- // standing prompt: the description still promised graph sizing after
- // `graph-shape.md` was deleted.
- let manifest = FLOW_AUTHORING
- .files
- .iter()
- .find(|f| f.path == "WORKFLOW.md")
- .expect("manifest")
- .contents;
- let description = manifest
- .lines()
- .find(|l| l.starts_with("description:"))
- .expect("frontmatter description");
- for dropped in ["how large a graph", "graph should be", "graph-shape"] {
- assert!(
- !description.contains(dropped),
- "the description still advertises `{dropped}`, which no longer ships"
- );
- }
- }
-
- #[test]
- fn the_builder_prompt_points_at_pages_that_ship() {
- // Same check from the other side. The prompt carries its own copy of
- // the table (the model needs to know the manual exists before it has
- // read the manual), so the two can drift independently.
- const PROMPT: &str = include_str!("../agents/workflow_builder/prompt.md");
- assert!(
- PROMPT.contains("flow-authoring"),
- "the builder prompt must name the skill that holds its reference manual"
- );
- let mut pointed = 0;
- for token in PROMPT.split('`') {
- if token.starts_with("references/") {
- pointed += 1;
- assert!(
- FLOW_AUTHORING.files.iter().any(|f| f.path == token),
- "the builder prompt points at `{token}`, which does not ship"
- );
- }
- }
- assert!(pointed >= 3, "the prompt's pointer table lost its rows");
- }
-}
+#[path = "skills_tests.rs"]
+mod tests;
diff --git a/src/openhuman/flows/skills/skills_tests.rs b/src/openhuman/flows/skills/skills_tests.rs
new file mode 100644
index 0000000000..6f322e6854
--- /dev/null
+++ b/src/openhuman/flows/skills/skills_tests.rs
@@ -0,0 +1,136 @@
+use super::*;
+
+ fn skill_dir() -> std::path::PathBuf {
+ std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
+ .join("src/openhuman/flows/skills/flow-authoring")
+ }
+
+ #[test]
+ fn bundled_skill_matches_the_directory_on_disk() {
+ // A page added to the directory but not to `FLOW_AUTHORING` is not a
+ // compile error and not a test failure anywhere else — it simply never
+ // ships, and the prompt's pointer table sends the model to a file that
+ // does not exist. This is that check.
+ let root = skill_dir();
+ let mut on_disk = Vec::new();
+ for entry in walkdir(&root) {
+ let rel = entry
+ .strip_prefix(&root)
+ .expect("under root")
+ .to_string_lossy()
+ .replace('\\', "/");
+ on_disk.push(rel);
+ }
+ on_disk.sort();
+
+ let mut listed: Vec<String> = FLOW_AUTHORING
+ .files
+ .iter()
+ .map(|f| f.path.to_string())
+ .collect();
+ listed.sort();
+
+ assert_eq!(
+ listed, on_disk,
+ "FLOW_AUTHORING's file list and the on-disk bundle have diverged"
+ );
+ }
+
+ fn walkdir(root: &std::path::Path) -> Vec<std::path::PathBuf> {
+ let mut out = Vec::new();
+ let mut stack = vec![root.to_path_buf()];
+ while let Some(dir) = stack.pop() {
+ for entry in std::fs::read_dir(&dir).expect("read_dir").flatten() {
+ let path = entry.path();
+ if path.is_dir() {
+ stack.push(path);
+ } else {
+ out.push(path);
+ }
+ }
+ }
+ out
+ }
+
+ #[test]
+ fn every_page_the_manifest_advertises_exists() {
+ // The WORKFLOW.md table is what the model reads to choose a page. A
+ // row naming a file that does not ship is a dead end the model cannot
+ // diagnose — it just gets an error and gives up on the manual.
+ let manifest = FLOW_AUTHORING
+ .files
+ .iter()
+ .find(|f| f.path == "WORKFLOW.md")
+ .expect("manifest")
+ .contents;
+ for file in FLOW_AUTHORING.files {
+ if file.path == "WORKFLOW.md" {
+ continue;
+ }
+ assert!(
+ manifest.contains(file.path),
+ "`{}` ships but the manifest's table never names it",
+ file.path
+ );
+ }
+ for line in manifest.lines() {
+ for token in line.split('`') {
+ if token.starts_with("references/") {
+ assert!(
+ FLOW_AUTHORING.files.iter().any(|f| f.path == token),
+ "the manifest points at `{token}`, which does not ship"
+ );
+ }
+ }
+ }
+ }
+
+ #[test]
+ fn the_frontmatter_description_does_not_advertise_a_dropped_page() {
+ // The description is what the model reads in the `## Installed Skills`
+ // catalogue to decide whether to open the skill at all, and it is prose
+ // rather than a path — so the `references/` token check below cannot
+ // see it. It went stale the first time a page moved back into the
+ // standing prompt: the description still promised graph sizing after
+ // `graph-shape.md` was deleted.
+ let manifest = FLOW_AUTHORING
+ .files
+ .iter()
+ .find(|f| f.path == "WORKFLOW.md")
+ .expect("manifest")
+ .contents;
+ let description = manifest
+ .lines()
+ .find(|l| l.starts_with("description:"))
+ .expect("frontmatter description");
+ for dropped in ["how large a graph", "graph should be", "graph-shape"] {
+ assert!(
+ !description.contains(dropped),
+ "the description still advertises `{dropped}`, which no longer ships"
+ );
+ }
+ }
+
+ #[test]
+ fn the_builder_prompt_points_at_pages_that_ship() {
+ // Same check from the other side. The prompt carries its own copy of
+ // the table (the model needs to know the manual exists before it has
+ // read the manual), so the two can drift independently.
+ const PROMPT: &str = include_str!("../agents/workflow_builder/prompt.md");
+ assert!(
+ PROMPT.contains("flow-authoring"),
+ "the builder prompt must name the skill that holds its reference manual"
+ );
+ let mut pointed = 0;
+ for token in PROMPT.split('`') {
+ if token.starts_with("references/") {
+ pointed += 1;
+ assert!(
+ FLOW_AUTHORING.files.iter().any(|f| f.path == token),
+ "the builder prompt points at `{token}`, which does not ship"
+ );
+ }
+ }
+ assert!(pointed >= 3, "the prompt's pointer table lost its rows");
+ }
+
diff --git a/src/openhuman/flows/types.rs b/src/openhuman/flows/types.rs
index 489a09f7a3..6891a375bb 100644
--- a/src/openhuman/flows/types.rs
+++ b/src/openhuman/flows/types.rs
@@ -489,165 +489,5 @@ pub struct FlowSuggestion {
}
#[cfg(test)]
-mod tests {
- use super::*;
- use tinyflows::model::{Node, NodeKind};
-
- fn sample_graph() -> WorkflowGraph {
- WorkflowGraph {
- nodes: vec![Node {
- id: "t".to_string(),
- kind: NodeKind::Trigger,
- type_version: 1,
- name: "Trigger".to_string(),
- config: serde_json::Value::Null,
- ports: Vec::new(),
- position: None,
- }],
- ..Default::default()
- }
- }
-
- #[test]
- fn flow_round_trips_through_json() {
- let flow = Flow {
- id: "flow_1".to_string(),
- name: "demo".to_string(),
- description: "Round-trips through JSON.".to_string(),
- enabled: true,
- graph: sample_graph(),
- created_at: "2026-01-01T00:00:00Z".to_string(),
- updated_at: "2026-01-01T00:00:00Z".to_string(),
- last_run_at: None,
- last_status: None,
- require_approval: false,
- };
- let json = serde_json::to_string(&flow).expect("serialize");
- let back: Flow = serde_json::from_str(&json).expect("deserialize");
- assert_eq!(back.id, flow.id);
- assert_eq!(back.graph, flow.graph);
- assert!(back.last_run_at.is_none());
- assert!(!back.require_approval);
- }
-
- #[test]
- fn flow_require_approval_defaults_false_when_omitted_from_json() {
- // Legacy/serialized JSON authored before the field existed must still
- // deserialize (SQLite rows are migrated via `add_column_if_missing`,
- // but any bare JSON fixture should also default safely).
- let json = serde_json::json!({
- "id": "flow_1",
- "name": "demo",
- "enabled": true,
- "graph": sample_graph(),
- "created_at": "2026-01-01T00:00:00Z",
- "updated_at": "2026-01-01T00:00:00Z",
- });
- let flow: Flow = serde_json::from_value(json).expect("deserialize");
- assert!(!flow.require_approval);
- }
-
- #[test]
- fn flow_run_round_trips_through_json() {
- let run = FlowRun {
- id: "flow:flow_1:run-uuid".to_string(),
- flow_id: "flow_1".to_string(),
- thread_id: "flow:flow_1:run-uuid".to_string(),
- status: "completed".to_string(),
- started_at: "2026-01-01T00:00:00Z".to_string(),
- finished_at: Some("2026-01-01T00:00:01Z".to_string()),
- steps: vec![FlowRunStep {
- node_id: "t".to_string(),
- output: serde_json::json!([{"json": {"hello": "world"}}]),
- port: None,
- ..Default::default()
- }],
- pending_approvals: Vec::new(),
- error: None,
- graph_hash: None,
- };
- let json = serde_json::to_string(&run).expect("serialize");
- let back: FlowRun = serde_json::from_str(&json).expect("deserialize");
- assert_eq!(back.id, run.id);
- assert_eq!(back.steps.len(), 1);
- assert_eq!(back.steps[0].node_id, "t");
- assert!(back.steps[0].port.is_none());
- }
-
- #[test]
- fn flow_run_step_omits_port_when_none() {
- let step = FlowRunStep {
- node_id: "n".to_string(),
- output: serde_json::Value::Null,
- port: None,
- ..Default::default()
- };
- let v = serde_json::to_value(&step).unwrap();
- assert!(v.get("port").is_none());
- }
-
- #[test]
- fn suggestion_status_token_round_trips() {
- for st in [
- SuggestionStatus::New,
- SuggestionStatus::Dismissed,
- SuggestionStatus::Built,
- ] {
- assert_eq!(SuggestionStatus::from_str_lossy(st.as_str()), st);
- }
- // Unknown tokens fall back to New rather than erroring.
- assert_eq!(
- SuggestionStatus::from_str_lossy("something_new"),
- SuggestionStatus::New
- );
- assert_eq!(SuggestionStatus::default(), SuggestionStatus::New);
- }
-
- #[test]
- fn flow_suggestion_round_trips_through_json() {
- let s = FlowSuggestion {
- id: "sug_abc".to_string(),
- title: "Auto-file email receipts".to_string(),
- one_liner: "When a Gmail receipt arrives, add a row to your expenses sheet."
- .to_string(),
- rationale: "You forward receipts to yourself most weeks.".to_string(),
- trigger_hint: Some("app_event".to_string()),
- steps_outline: vec![
- "Watch Gmail for receipts".to_string(),
- "Extract amount + vendor".to_string(),
- ],
- suggested_connections: vec!["composio:gmail:conn_1".to_string()],
- suggested_slugs: vec!["GMAIL_NEW_GMAIL_MESSAGE".to_string()],
- build_prompt: "Build a workflow that…".to_string(),
- confidence: 0.82,
- status: SuggestionStatus::New,
- created_at: "2026-07-05T00:00:00Z".to_string(),
- source_run_id: Some("run-1".to_string()),
- };
- let json = serde_json::to_string(&s).expect("serialize");
- let back: FlowSuggestion = serde_json::from_str(&json).expect("deserialize");
- assert_eq!(back, s);
- }
-
- #[test]
- fn flow_suggestion_defaults_optional_fields() {
- // A minimal pitch (no trigger/steps/connections/slugs/status/run) must
- // deserialize with safe defaults.
- let json = serde_json::json!({
- "id": "sug_min",
- "title": "Daily digest",
- "one_liner": "Summarize your unread mail each morning.",
- "rationale": "You check mail first thing.",
- "build_prompt": "Build a scheduled digest…",
- "created_at": "2026-07-05T00:00:00Z",
- });
- let s: FlowSuggestion = serde_json::from_value(json).expect("deserialize");
- assert!(s.trigger_hint.is_none());
- assert!(s.steps_outline.is_empty());
- assert!(s.suggested_connections.is_empty());
- assert!(s.suggested_slugs.is_empty());
- assert_eq!(s.confidence, 0.0);
- assert_eq!(s.status, SuggestionStatus::New);
- assert!(s.source_run_id.is_none());
- }
-}
+#[path = "types_tests.rs"]
+mod tests;
diff --git a/src/openhuman/flows/types_tests.rs b/src/openhuman/flows/types_tests.rs
new file mode 100644
index 0000000000..0fe8cdb33d
--- /dev/null
+++ b/src/openhuman/flows/types_tests.rs
@@ -0,0 +1,161 @@
+use super::*;
+ use tinyflows::model::{Node, NodeKind};
+
+ fn sample_graph() -> WorkflowGraph {
+ WorkflowGraph {
+ nodes: vec![Node {
+ id: "t".to_string(),
+ kind: NodeKind::Trigger,
+ type_version: 1,
+ name: "Trigger".to_string(),
+ config: serde_json::Value::Null,
+ ports: Vec::new(),
+ position: None,
+ }],
+ ..Default::default()
+ }
+ }
+
+ #[test]
+ fn flow_round_trips_through_json() {
+ let flow = Flow {
+ id: "flow_1".to_string(),
+ name: "demo".to_string(),
+ description: "Round-trips through JSON.".to_string(),
+ enabled: true,
+ graph: sample_graph(),
+ created_at: "2026-01-01T00:00:00Z".to_string(),
+ updated_at: "2026-01-01T00:00:00Z".to_string(),
+ last_run_at: None,
+ last_status: None,
+ require_approval: false,
+ };
+ let json = serde_json::to_string(&flow).expect("serialize");
+ let back: Flow = serde_json::from_str(&json).expect("deserialize");
+ assert_eq!(back.id, flow.id);
+ assert_eq!(back.graph, flow.graph);
+ assert!(back.last_run_at.is_none());
+ assert!(!back.require_approval);
+ }
+
+ #[test]
+ fn flow_require_approval_defaults_false_when_omitted_from_json() {
+ // Legacy/serialized JSON authored before the field existed must still
+ // deserialize (SQLite rows are migrated via `add_column_if_missing`,
+ // but any bare JSON fixture should also default safely).
+ let json = serde_json::json!({
+ "id": "flow_1",
+ "name": "demo",
+ "enabled": true,
+ "graph": sample_graph(),
+ "created_at": "2026-01-01T00:00:00Z",
+ "updated_at": "2026-01-01T00:00:00Z",
+ });
+ let flow: Flow = serde_json::from_value(json).expect("deserialize");
+ assert!(!flow.require_approval);
+ }
+
+ #[test]
+ fn flow_run_round_trips_through_json() {
+ let run = FlowRun {
+ id: "flow:flow_1:run-uuid".to_string(),
+ flow_id: "flow_1".to_string(),
+ thread_id: "flow:flow_1:run-uuid".to_string(),
+ status: "completed".to_string(),
+ started_at: "2026-01-01T00:00:00Z".to_string(),
+ finished_at: Some("2026-01-01T00:00:01Z".to_string()),
+ steps: vec![FlowRunStep {
+ node_id: "t".to_string(),
+ output: serde_json::json!([{"json": {"hello": "world"}}]),
+ port: None,
+ ..Default::default()
+ }],
+ pending_approvals: Vec::new(),
+ error: None,
+ graph_hash: None,
+ };
+ let json = serde_json::to_string(&run).expect("serialize");
+ let back: FlowRun = serde_json::from_str(&json).expect("deserialize");
+ assert_eq!(back.id, run.id);
+ assert_eq!(back.steps.len(), 1);
+ assert_eq!(back.steps[0].node_id, "t");
+ assert!(back.steps[0].port.is_none());
+ }
+
+ #[test]
+ fn flow_run_step_omits_port_when_none() {
+ let step = FlowRunStep {
+ node_id: "n".to_string(),
+ output: serde_json::Value::Null,
+ port: None,
+ ..Default::default()
+ };
+ let v = serde_json::to_value(&step).unwrap();
+ assert!(v.get("port").is_none());
+ }
+
+ #[test]
+ fn suggestion_status_token_round_trips() {
+ for st in [
+ SuggestionStatus::New,
+ SuggestionStatus::Dismissed,
+ SuggestionStatus::Built,
+ ] {
+ assert_eq!(SuggestionStatus::from_str_lossy(st.as_str()), st);
+ }
+ // Unknown tokens fall back to New rather than erroring.
+ assert_eq!(
+ SuggestionStatus::from_str_lossy("something_new"),
+ SuggestionStatus::New
+ );
+ assert_eq!(SuggestionStatus::default(), SuggestionStatus::New);
+ }
+
+ #[test]
+ fn flow_suggestion_round_trips_through_json() {
+ let s = FlowSuggestion {
+ id: "sug_abc".to_string(),
+ title: "Auto-file email receipts".to_string(),
+ one_liner: "When a Gmail receipt arrives, add a row to your expenses sheet."
+ .to_string(),
+ rationale: "You forward receipts to yourself most weeks.".to_string(),
+ trigger_hint: Some("app_event".to_string()),
+ steps_outline: vec![
+ "Watch Gmail for receipts".to_string(),
+ "Extract amount + vendor".to_string(),
+ ],
+ suggested_connections: vec!["composio:gmail:conn_1".to_string()],
+ suggested_slugs: vec!["GMAIL_NEW_GMAIL_MESSAGE".to_string()],
+ build_prompt: "Build a workflow that…".to_string(),
+ confidence: 0.82,
+ status: SuggestionStatus::New,
+ created_at: "2026-07-05T00:00:00Z".to_string(),
+ source_run_id: Some("run-1".to_string()),
+ };
+ let json = serde_json::to_string(&s).expect("serialize");
+ let back: FlowSuggestion = serde_json::from_str(&json).expect("deserialize");
+ assert_eq!(back, s);
+ }
+
+ #[test]
+ fn flow_suggestion_defaults_optional_fields() {
+ // A minimal pitch (no trigger/steps/connections/slugs/status/run) must
+ // deserialize with safe defaults.
+ let json = serde_json::json!({
+ "id": "sug_min",
+ "title": "Daily digest",
+ "one_liner": "Summarize your unread mail each morning.",
+ "rationale": "You check mail first thing.",
+ "build_prompt": "Build a scheduled digest…",
+ "created_at": "2026-07-05T00:00:00Z",
+ });
+ let s: FlowSuggestion = serde_json::from_value(json).expect("deserialize");
+ assert!(s.trigger_hint.is_none());
+ assert!(s.steps_outline.is_empty());
+ assert!(s.suggested_connections.is_empty());
+ assert!(s.suggested_slugs.is_empty());
+ assert_eq!(s.confidence, 0.0);
+ assert_eq!(s.status, SuggestionStatus::New);
+ assert!(s.source_run_id.is_none());
+ }
+
diff --git a/src/openhuman/memory/tools/collapsed.rs b/src/openhuman/memory/tools/collapsed.rs
index 83cd00debc..526968d95d 100644
--- a/src/openhuman/memory/tools/collapsed.rs
+++ b/src/openhuman/memory/tools/collapsed.rs
@@ -240,112 +240,5 @@ impl Tool for MemoryTool {
}
#[cfg(test)]
-mod tests {
- use super::*;
-
- fn tool() -> MemoryTool {
- MemoryTool::new(
- Arc::new(Config::default()),
- Arc::new(SecurityPolicy::default()),
- )
- }
-
- #[test]
- fn every_member_is_hidden_so_the_collapse_actually_saves_something() {
- // `all_actions`, not `actions`: capability filtering could hide a
- // still-advertised member from this check in some environments, and
- // the property being pinned holds regardless of capabilities.
- for entry in tool().all_actions() {
- assert_eq!(
- entry.tool.exposure(),
- ToolExposure::Hidden,
- "`{}` is still advertised alongside the collapsed `memory` tool",
- entry.tool.name()
- );
- }
- }
-
- #[test]
- fn the_schema_advertises_every_action() {
- let schema = tool().parameters_schema();
- let listed = schema["properties"]["action"]["enum"]
- .as_array()
- .expect("enum")
- .len();
- assert_eq!(listed, 11);
- }
-
- #[test]
- fn each_action_resolves_to_exactly_its_members_level() {
- // The real contract, and the one that keeps collapsing honest: whatever
- // a member declares, the collapsed tool reports for that action.
- //
- // Note this family currently declares one level between them (see the
- // module docs): `memory_store` and `memory_forget` never override
- // `permission_level`, so they inherit the `ReadOnly` default. That is
- // pre-existing and deliberately not changed here — raising them is a
- // behaviour change to the approval gate, not a token optimisation. An
- // inequality assertion would therefore be asserting a bug.
- let tool = tool();
- for entry in tool.actions() {
- let args = serde_json::json!({"action": entry.action});
- assert_eq!(
- tool.permission_level_with_args(&args),
- entry.tool.permission_level_with_args(&args),
- "action `{}` must report what `{}` reports",
- entry.action,
- entry.tool.name()
- );
- }
- }
-
- #[test]
- fn collapsing_never_lowers_the_argument_free_level() {
- // The safety property that does not depend on what the members happen
- // to declare today: a caller that cannot pass arguments is never told
- // a level below any member's.
- let tool = tool();
- let floor = tool.permission_level();
- for entry in tool.actions() {
- assert!(
- entry.tool.permission_level() <= floor,
- "`{}` requires more than the collapsed tool advertises",
- entry.tool.name()
- );
- }
- }
-
- #[test]
- fn an_unknown_action_falls_back_to_the_strictest_level() {
- let tool = tool();
- assert_eq!(
- tool.permission_level_with_args(&serde_json::json!({"action": "nope"})),
- tool.permission_level()
- );
- }
-
- #[tokio::test]
- async fn an_unknown_action_is_an_error_result_naming_the_valid_ones() {
- let result = tool()
- .execute(serde_json::json!({"action": "recal"}))
- .await
- .expect("dispatch does not fail the call");
- assert!(result.is_error);
- let text = format!("{result:?}");
- assert!(text.contains("recal"));
- assert!(text.contains("recall|store|forget"));
- }
-
- #[test]
- fn the_memory_tree_tool_is_not_a_member() {
- // Pinning the decision in the module docs: `memory_tree` dispatches on
- // its own `mode`, and folding it in would make this two-level.
- assert!(
- !tool()
- .all_actions()
- .iter()
- .any(|e| e.tool.name() == "memory_tree"),
- "memory_tree stays a separate tool"
- );
- }
-}
+#[path = "collapsed_tests.rs"]
+mod tests;
diff --git a/src/openhuman/memory/tools/collapsed_tests.rs b/src/openhuman/memory/tools/collapsed_tests.rs
new file mode 100644
index 0000000000..e0c8dd8085
--- /dev/null
+++ b/src/openhuman/memory/tools/collapsed_tests.rs
@@ -0,0 +1,108 @@
+use super::*;
+
+ fn tool() -> MemoryTool {
+ MemoryTool::new(
+ Arc::new(Config::default()),
+ Arc::new(SecurityPolicy::default()),
+ )
+ }
+
+ #[test]
+ fn every_member_is_hidden_so_the_collapse_actually_saves_something() {
+ // `all_actions`, not `actions`: capability filtering could hide a
+ // still-advertised member from this check in some environments, and
+ // the property being pinned holds regardless of capabilities.
+ for entry in tool().all_actions() {
+ assert_eq!(
+ entry.tool.exposure(),
+ ToolExposure::Hidden,
+ "`{}` is still advertised alongside the collapsed `memory` tool",
+ entry.tool.name()
+ );
+ }
+ }
+
+ #[test]
+ fn the_schema_advertises_every_action() {
+ let schema = tool().parameters_schema();
+ let listed = schema["properties"]["action"]["enum"]
+ .as_array()
+ .expect("enum")
+ .len();
+ assert_eq!(listed, 11);
+ }
+
+ #[test]
+ fn each_action_resolves_to_exactly_its_members_level() {
+ // The real contract, and the one that keeps collapsing honest: whatever
+ // a member declares, the collapsed tool reports for that action.
+ //
+ // Note this family currently declares one level between them (see the
+ // module docs): `memory_store` and `memory_forget` never override
+ // `permission_level`, so they inherit the `ReadOnly` default. That is
+ // pre-existing and deliberately not changed here — raising them is a
+ // behaviour change to the approval gate, not a token optimisation. An
+ // inequality assertion would therefore be asserting a bug.
+ let tool = tool();
+ for entry in tool.actions() {
+ let args = serde_json::json!({"action": entry.action});
+ assert_eq!(
+ tool.permission_level_with_args(&args),
+ entry.tool.permission_level_with_args(&args),
+ "action `{}` must report what `{}` reports",
+ entry.action,
+ entry.tool.name()
+ );
+ }
+ }
+
+ #[test]
+ fn collapsing_never_lowers_the_argument_free_level() {
+ // The safety property that does not depend on what the members happen
+ // to declare today: a caller that cannot pass arguments is never told
+ // a level below any member's.
+ let tool = tool();
+ let floor = tool.permission_level();
+ for entry in tool.actions() {
+ assert!(
+ entry.tool.permission_level() <= floor,
+ "`{}` requires more than the collapsed tool advertises",
+ entry.tool.name()
+ );
+ }
+ }
+
+ #[test]
+ fn an_unknown_action_falls_back_to_the_strictest_level() {
+ let tool = tool();
+ assert_eq!(
+ tool.permission_level_with_args(&serde_json::json!({"action": "nope"})),
+ tool.permission_level()
+ );
+ }
+
+ #[tokio::test]
+ async fn an_unknown_action_is_an_error_result_naming_the_valid_ones() {
+ let result = tool()
+ .execute(serde_json::json!({"action": "recal"}))
+ .await
+ .expect("dispatch does not fail the call");
+ assert!(result.is_error);
+ let text = format!("{result:?}");
+ assert!(text.contains("recal"));
+ assert!(text.contains("recall|store|forget"));
+ }
+
+ #[test]
+ fn the_memory_tree_tool_is_not_a_member() {
+ // Pinning the decision in the module docs: `memory_tree` dispatches on
+ // its own `mode`, and folding it in would make this two-level.
+ assert!(
+ !tool()
+ .all_actions()
+ .iter()
+ .any(|e| e.tool.name() == "memory_tree"),
+ "memory_tree stays a separate tool"
+ );
+ }
+