Skip to content

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

test: remove obsolete prompt, config, and mcp test modules

Steven Enamakel2010cb302ffd
diff --git a/crates/openhuman-core/src/agent/prompts/mod_tests.rs b/crates/openhuman-core/src/agent/prompts/mod_tests.rs
index 82e7646166..b30d303618 100644
--- a/crates/openhuman-core/src/agent/prompts/mod_tests.rs
+++ b/crates/openhuman-core/src/agent/prompts/mod_tests.rs
@@ -87,8 +87,6 @@ mod grounding_spec_check_tests;
mod subagent_render_tests;
#[path = "mod_tests_tools_sections_tests.rs"]
mod tools_sections_tests;
-#[path = "mod_tests_user_files_reflections_tests.rs"]
-mod user_files_reflections_tests;
#[test]
fn tool_call_format_maps_to_the_dialect_and_harness_vocabulary() {
diff --git a/crates/openhuman-core/src/agent/prompts/mod_tests_user_files_reflections_tests.rs b/crates/openhuman-core/src/agent/prompts/mod_tests_user_files_reflections_tests.rs
deleted file mode 100644
index dc71356f86..0000000000
--- a/crates/openhuman-core/src/agent/prompts/mod_tests_user_files_reflections_tests.rs
+++ /dev/null
@@ -1,375 +0,0 @@
-use super::*;
-
-#[test]
-fn profile_md_and_memory_md_are_capped_at_user_file_max_chars() {
- // Both PROFILE.md and MEMORY.md are user-specific files that can
- // grow over time. Injection caps them at USER_FILE_MAX_CHARS
- // (~1000 tokens each) so the system prompt footprint stays
- // bounded. Test both files at once to pin the shared budget.
- let workspace = std::env::temp_dir().join(format!(
- "openhuman_prompt_user_cap_{}",
- uuid::Uuid::new_v4()
- ));
- std::fs::create_dir_all(&workspace).unwrap();
- let big = "x".repeat(USER_FILE_MAX_CHARS + 500);
- std::fs::write(workspace.join("PROFILE.md"), &big).unwrap();
- std::fs::write(workspace.join("MEMORY.md"), &big).unwrap();
-
- let tools: Vec<Box<dyn Tool>> = vec![Box::new(TestTool)];
- let rendered = render_subagent_system_prompt(
- &workspace,
- "test-model",
- &[0],
- &tools,
- &[],
- "You are the orchestrator.",
- SubagentRenderOptions {
- include_identity: false,
- include_safety_preamble: false,
- include_profile: true,
- include_memory_md: true,
- },
- ToolCallFormat::PFormat,
- &[],
- );
-
- assert!(rendered.contains("### PROFILE.md"));
- assert!(rendered.contains("### MEMORY.md"));
- // Each file gets its own truncation marker mentioning the cap.
- let marker = format!("[... truncated at {USER_FILE_MAX_CHARS} chars");
- assert_eq!(
- rendered.matches(marker.as_str()).count(),
- 2,
- "both PROFILE.md and MEMORY.md must emit the truncation marker at \
- USER_FILE_MAX_CHARS — found:\n{rendered}"
- );
- // Sanity-check the cap is genuinely tighter than the bootstrap cap.
- const {
- assert!(USER_FILE_MAX_CHARS < BOOTSTRAP_MAX_CHARS);
- }
-
- let _ = std::fs::remove_dir_all(workspace);
-}
-
-#[test]
-fn for_subagent_builder_injects_user_files_even_when_identity_omitted() {
- // Regression pin for the review finding: the runtime Tauri chat
- // path spins welcome/trigger_* via `OpenHumanSessionHost::from_config_for_agent`
- // → `SystemPromptBuilder::for_subagent(body, omit_identity=true, …)`,
- // which deliberately drops `IdentitySection`. Before
- // `UserFilesSection` existed, our PROFILE/MEMORY injection lived
- // inside `IdentitySection::build` and got dropped along with it,
- // so the first Tauri turn never saw the user's onboarding output
- // even though the subagent-host path and the debug dumper did.
- //
- // This test exercises the exact builder call-site the runtime
- // uses for welcome (`omit_identity = true`, both user-file flags
- // opted in via PromptContext) and pins that the rendered prompt
- // contains both files.
- let workspace = std::env::temp_dir().join(format!(
- "openhuman_prompt_for_subagent_user_files_{}",
- uuid::Uuid::new_v4()
- ));
- std::fs::create_dir_all(&workspace).unwrap();
- std::fs::write(
- workspace.join("PROFILE.md"),
- "# User Profile\nJane Doe — crypto trader in PST.",
- )
- .unwrap();
- std::fs::write(
- workspace.join("MEMORY.md"),
- "# Long-term memory\nShipped v1 last sprint; prefers terse Rust.",
- )
- .unwrap();
-
- let tools: Vec<Box<dyn Tool>> = vec![];
- let prompt_tools = PromptTool::from_tools(&tools);
- let ctx = PromptContext {
- workspace_dir: &workspace,
- model_name: "test-model",
- agent_id: "",
- tools: &prompt_tools,
- workflows: &[],
- dispatcher_instructions: "",
- learned: LearnedContextData::default(),
- visible_tool_names: &NO_FILTER,
- tool_call_format: ToolCallFormat::PFormat,
- connected_integrations: &[],
- connected_identities_md: String::new(),
- include_profile: true,
- include_memory_md: true,
- curated_snapshot: None,
- user_identity: None,
- personality_roster: vec![],
- agents_md_global: None,
- agents_md_local: None,
- };
-
- // Test a narrow-agent runtime path:
- // `SystemPromptBuilder::for_subagent(body, omit_identity=true, …)`.
- let builder = SystemPromptBuilder::for_subagent(
- "You are a specialist agent.".into(),
- true, // omit_identity — drops SOUL/IDENTITY preamble
- true, // omit_safety_preamble
- );
- let rendered = builder.build(&ctx).unwrap();
-
- assert!(
- !rendered.contains("## Project Context"),
- "identity preamble must still be suppressed when omit_identity=true"
- );
- assert!(
- rendered.contains("### PROFILE.md") && rendered.contains("Jane Doe"),
- "narrow runtime path must inject PROFILE.md despite omit_identity=true, got:\n{rendered}"
- );
- assert!(
- rendered.contains("### MEMORY.md") && rendered.contains("terse Rust"),
- "narrow runtime path must inject MEMORY.md despite omit_identity=true, got:\n{rendered}"
- );
-
- // Mirror the narrow-specialist runtime path (code_executor,
- // critic, …): both flags off → user files must stay out.
- let ctx_narrow = PromptContext {
- workspace_dir: &workspace,
- model_name: "test-model",
- agent_id: "",
- tools: &prompt_tools,
- workflows: &[],
- dispatcher_instructions: "",
- learned: LearnedContextData::default(),
- visible_tool_names: &NO_FILTER,
- tool_call_format: ToolCallFormat::PFormat,
- connected_integrations: &[],
- connected_identities_md: String::new(),
- include_profile: false,
- include_memory_md: false,
- curated_snapshot: None,
- user_identity: None,
- personality_roster: vec![],
- agents_md_global: None,
- agents_md_local: None,
- };
- let narrow = builder.build(&ctx_narrow).unwrap();
- assert!(
- !narrow.contains("### PROFILE.md") && !narrow.contains("### MEMORY.md"),
- "narrow specialist runtime path must NOT leak user files, got:\n{narrow}"
- );
-
- let _ = std::fs::remove_dir_all(workspace);
-}
-
-#[test]
-fn memory_md_injection_is_framed_as_background_not_prior_chat() {
- // GH-4745 regression: MEMORY.md is durable cross-session memory. Without
- // a frame, a relevant curated observation reads to the model as prior
- // *in-thread* conversation, so on a brand-new thread it opens with
- // "already covered this in a previous chat" and shortcuts its answer.
- // Pin that the rendered prompt frames the block as background memory and
- // that the guardrail precedes the injected `### MEMORY.md` heading.
- //
- // `tempfile::tempdir()` cleans up via `Drop` even when an assertion
- // below panics — a bare `remove_dir_all` at the tail would leak the
- // dir exactly on the failing run we most want to inspect.
- let workspace = tempfile::tempdir().unwrap();
- std::fs::write(
- workspace.path().join("MEMORY.md"),
- "# Long-term memory\nReviewed `def f(x)` last week; user prefers terse notes.",
- )
- .unwrap();
-
- let tools: Vec<Box<dyn Tool>> = vec![];
- let prompt_tools = PromptTool::from_tools(&tools);
- let ctx = memory_framing_ctx(workspace.path(), &prompt_tools);
-
- let rendered = UserFilesSection.build(&ctx).unwrap();
-
- assert!(
- rendered.contains("### MEMORY.md") && rendered.contains("terse notes"),
- "MEMORY.md must still be injected, got:\n{rendered}"
- );
- assert!(
- rendered.contains("background — not this conversation"),
- "MEMORY.md must be framed as durable background memory, got:\n{rendered}"
- );
- assert!(
- rendered.contains("already covered this in a previous chat"),
- "framing must explicitly forbid asserting prior-chat continuity, got:\n{rendered}"
- );
- let frame_at = rendered.find("background — not this conversation").unwrap();
- let heading_at = rendered.find("### MEMORY.md").unwrap();
- assert!(
- frame_at < heading_at,
- "the guardrail note must precede the MEMORY.md block, got:\n{rendered}"
- );
-}
-
-#[test]
-fn memory_md_framing_absent_when_no_memory_content() {
- // The frame must never appear on its own: when MEMORY.md is missing/empty
- // (a genuinely fresh workspace) there is nothing to scope, so emitting a
- // dangling "background memory" note would itself imply phantom history.
- let workspace = tempfile::tempdir().unwrap();
-
- let tools: Vec<Box<dyn Tool>> = vec![];
- let prompt_tools = PromptTool::from_tools(&tools);
- let ctx = memory_framing_ctx(workspace.path(), &prompt_tools);
-
- let rendered = UserFilesSection.build(&ctx).unwrap();
- assert!(
- !rendered.contains("background — not this conversation"),
- "no MEMORY.md content → no dangling framing note, got:\n{rendered}"
- );
-}
-
-#[test]
-fn prompt_tool_constructors_and_user_memory_skip_empty_bodies() {
- let plain = PromptTool::new("shell", "run commands");
- assert_eq!(plain.name, "shell");
- assert!(plain.parameters_schema.is_none());
-
- let with_schema =
- PromptTool::with_schema("http_request", "fetch data", "{\"type\":\"object\"}".into());
- assert_eq!(
- with_schema.parameters_schema.as_deref(),
- Some("{\"type\":\"object\"}")
- );
-
- let ctx = PromptContext {
- workspace_dir: Path::new("/tmp"),
- model_name: "model",
- agent_id: "",
- tools: &[],
- workflows: &[],
- dispatcher_instructions: "",
- learned: LearnedContextData {
- tree_root_summaries: vec![ns_summary("user", "kept"), ns_summary("empty", " ")],
- ..Default::default()
- },
- visible_tool_names: &NO_FILTER,
- tool_call_format: ToolCallFormat::PFormat,
- connected_integrations: &[],
- connected_identities_md: String::new(),
- include_profile: false,
- include_memory_md: false,
- curated_snapshot: None,
- user_identity: None,
- personality_roster: vec![],
- agents_md_global: None,
- agents_md_local: None,
- };
- let rendered = UserMemorySection.build(&ctx).unwrap();
- assert!(rendered.contains("### user"));
- assert!(!rendered.contains("### empty"));
- assert_eq!(default_workspace_file_content("missing"), "");
-}
-
-#[test]
-fn user_reflections_section_renders_bullets_with_priority_preamble() {
- let ctx = ctx_with_learned(LearnedContextData {
- reflections: vec![
- "Going forward I want concise replies".into(),
- "I realized I prefer Rust over TypeScript".into(),
- ],
- ..Default::default()
- });
- let rendered = UserReflectionsSection.build(&ctx).unwrap();
- assert!(rendered.starts_with("## User Reflections\n\n"));
- assert!(
- rendered.contains("higher-priority"),
- "preamble must signal that reflections outrank generic memory"
- );
- assert!(rendered.contains("- Going forward I want concise replies"));
- assert!(rendered.contains("- I realized I prefer Rust over TypeScript"));
-}
-
-#[test]
-fn user_reflections_section_returns_empty_without_entries() {
- let ctx = ctx_with_learned(LearnedContextData::default());
- assert!(UserReflectionsSection.build(&ctx).unwrap().is_empty());
-}
-
-#[test]
-fn user_reflections_section_skips_blank_entries() {
- let ctx = ctx_with_learned(LearnedContextData {
- reflections: vec![" ".into(), "Real reflection".into(), "".into()],
- ..Default::default()
- });
- let rendered = UserReflectionsSection.build(&ctx).unwrap();
- assert!(rendered.contains("- Real reflection"));
- // Bullet count should match the non-blank entry count.
- assert_eq!(rendered.matches("\n- ").count(), 1);
-}
-
-#[test]
-fn render_user_reflections_helper_matches_section_output() {
- let ctx = ctx_with_learned(LearnedContextData {
- reflections: vec!["x".into()],
- ..Default::default()
- });
- let via_section = UserReflectionsSection.build(&ctx).unwrap();
- let via_helper = render_user_reflections(&ctx).unwrap();
- assert_eq!(via_section, via_helper);
-}
-
-#[test]
-fn insert_section_before_places_section_ahead_of_named_target() {
- // Reflections must rank ahead of generic memory in builders that
- // already include `UserMemorySection` (the `with_defaults` chain).
- // Verify the helper inserts at the correct index instead of
- // tail-appending.
- let builder = SystemPromptBuilder::with_defaults()
- .insert_section_before("user_memory", Box::new(UserReflectionsSection));
- let names: Vec<&str> = builder.sections.iter().map(|s| s.name()).collect();
- let r_idx = names
- .iter()
- .position(|n| *n == "user_reflections")
- .expect("user_reflections section");
- let m_idx = names
- .iter()
- .position(|n| *n == "user_memory")
- .expect("user_memory section");
- assert!(
- r_idx < m_idx,
- "insert_section_before should place the new section ahead of its target, got order {names:?}"
- );
-}
-
-#[test]
-fn insert_section_before_falls_back_to_append_when_target_missing() {
- // Dynamic / sub-agent builders do not include a `user_memory`
- // section. The helper should still land the new section so the
- // caller's wiring stays loop-free, just at the tail.
- let builder = SystemPromptBuilder::default()
- .add_section(Box::new(SafetySection))
- .insert_section_before("user_memory", Box::new(UserReflectionsSection));
- let names: Vec<&str> = builder.sections.iter().map(|s| s.name()).collect();
- assert_eq!(names.last(), Some(&"user_reflections"));
- assert_eq!(names.len(), 2);
-}
-
-#[test]
-fn user_reflections_render_above_user_memory_when_both_present() {
- // Acceptance criterion: reflections rank above generic
- // tree summaries — verify by composing the same way the runtime
- // does (UserReflectionsSection appended ahead of any
- // UserMemorySection content).
- let ctx = ctx_with_learned(LearnedContextData {
- reflections: vec!["I want terse answers".into()],
- tree_root_summaries: vec![ns_summary("user", "Generic summary")],
- ..Default::default()
- });
- let reflections = UserReflectionsSection.build(&ctx).unwrap();
- let memory = UserMemorySection.build(&ctx).unwrap();
- let combined = format!("{reflections}{memory}");
- let r_idx = combined
- .find("## User Reflections")
- .expect("reflections heading");
- let m_idx = combined.find("## User Memory").expect("memory heading");
- assert!(
- r_idx < m_idx,
- "reflections must render before user-memory block"
- );
-}
-
-// ─── ToolsSection native-skip tests ──────────────────────────────────────────
-
diff --git a/crates/openhuman-core/src/config/schema/load_env_overlay_runtime_tests.rs b/crates/openhuman-core/src/config/schema/load_env_overlay_runtime_tests.rs
deleted file mode 100644
index 0f35f94515..0000000000
--- a/crates/openhuman-core/src/config/schema/load_env_overlay_runtime_tests.rs
+++ /dev/null
@@ -1,82 +0,0 @@
-use super::*;
-
-#[test]
-fn env_overlay_subsystems_memory_driver_and_hooks_apply() {
- let mut cfg = Config::default();
- // The shared schema retains the persisted legacy id; binding normalizes it
- // to the built-in `tinymemory` module id.
- assert_eq!(cfg.subsystems.memory.driver, "tinycortex");
- assert!(cfg.subsystems.memory.hooks.auto_recall);
- assert!(cfg.subsystems.memory.hooks.auto_capture);
- assert_eq!(cfg.subsystems.memory.hooks.max_context_tokens, 2000);
- assert_eq!(cfg.subsystems.memory.hooks.recall_max_chars, 1000);
- assert_eq!(cfg.subsystems.memory.hooks.capture_max_chars, 500);
-
- cfg.apply_env_overlay_with(
- &HashMapEnv::new()
- .with("OPENHUMAN_MEMORY_DRIVER", "supermemory")
- .with("OPENHUMAN_MEMORY_HOOKS_AUTO_RECALL", "off")
- .with("OPENHUMAN_MEMORY_HOOKS_AUTO_CAPTURE", "false")
- .with("OPENHUMAN_MEMORY_HOOKS_MAX_CONTEXT_TOKENS", "4000")
- .with("OPENHUMAN_MEMORY_HOOKS_RECALL_MAX_CHARS", "2000")
- .with("OPENHUMAN_MEMORY_HOOKS_CAPTURE_MAX_CHARS", "900"),
- );
-
- assert_eq!(cfg.subsystems.memory.driver, "supermemory");
- assert!(!cfg.subsystems.memory.hooks.auto_recall);
- assert!(!cfg.subsystems.memory.hooks.auto_capture);
- assert_eq!(cfg.subsystems.memory.hooks.max_context_tokens, 4000);
- assert_eq!(cfg.subsystems.memory.hooks.recall_max_chars, 2000);
- assert_eq!(cfg.subsystems.memory.hooks.capture_max_chars, 900);
-
- // A blank driver value is ignored, leaving the previous override intact.
- cfg.apply_env_overlay_with(&HashMapEnv::new().with("OPENHUMAN_MEMORY_DRIVER", " "));
- assert_eq!(cfg.subsystems.memory.driver, "supermemory");
-
- // A non-numeric budget value is ignored, leaving the previous value intact.
- cfg.apply_env_overlay_with(
- &HashMapEnv::new().with("OPENHUMAN_MEMORY_HOOKS_MAX_CONTEXT_TOKENS", "nope"),
- );
- assert_eq!(cfg.subsystems.memory.hooks.max_context_tokens, 4000);
-}
-
-#[test]
-fn env_overlay_learning_source_values_and_invalid_ignored() {
- let mut cfg = Config::default();
- cfg.apply_env_overlay_with(
- &HashMapEnv::new().with("OPENHUMAN_LEARNING_REFLECTION_SOURCE", "local"),
- );
- assert_eq!(
- cfg.learning.reflection_source,
- crate::config::ReflectionSource::Local
- );
-
- cfg.apply_env_overlay_with(
- &HashMapEnv::new().with("OPENHUMAN_LEARNING_REFLECTION_SOURCE", "cloud"),
- );
- assert_eq!(
- cfg.learning.reflection_source,
- crate::config::ReflectionSource::Cloud
- );
-
- // Unknown — ignored, retains cloud from previous step.
- cfg.apply_env_overlay_with(
- &HashMapEnv::new().with("OPENHUMAN_LEARNING_REFLECTION_SOURCE", "bogus"),
- );
- assert_eq!(
- cfg.learning.reflection_source,
- crate::config::ReflectionSource::Cloud
- );
-}
-
-#[test]
-fn env_overlay_learning_numeric_values_parse() {
- let mut cfg = Config::default();
- cfg.apply_env_overlay_with(
- &HashMapEnv::new()
- .with("OPENHUMAN_LEARNING_MAX_REFLECTIONS_PER_SESSION", "8")
- .with("OPENHUMAN_LEARNING_MIN_TURN_COMPLEXITY", "2"),
- );
- assert_eq!(cfg.learning.max_reflections_per_session, 8);
- assert_eq!(cfg.learning.min_turn_complexity, 2);
-}
diff --git a/crates/openhuman-core/src/config/schema/load_tests.rs b/crates/openhuman-core/src/config/schema/load_tests.rs
index 86b4aa8b01..5457972453 100644
--- a/crates/openhuman-core/src/config/schema/load_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load_tests.rs
@@ -108,8 +108,6 @@ mod backup_tests;
mod corruption_recovery_tests;
#[path = "load_env_overlay_context_tests.rs"]
mod env_overlay_context_tests;
-#[path = "load_env_overlay_runtime_tests.rs"]
-mod env_overlay_runtime_tests;
#[path = "load_env_overlay_tests.rs"]
mod env_overlay_tests;
#[path = "load_migration_tests.rs"]
diff --git a/crates/openhuman-core/src/mcp/server/tools_tests.rs b/crates/openhuman-core/src/mcp/server/tools_tests.rs
index 26a3914f2b..e562c48404 100644
--- a/crates/openhuman-core/src/mcp/server/tools_tests.rs
+++ b/crates/openhuman-core/src/mcp/server/tools_tests.rs
@@ -15,5 +15,3 @@ fn list_tools_result_for_config(config: &crate::config::Config) -> Value {
mod dispatch_tests;
#[path = "tools_tests_params_and_specs_tests.rs"]
mod params_and_specs_tests;
-#[path = "tools_tests_tag_and_dispatch_tests.rs"]
-mod tag_and_dispatch_tests;
diff --git a/crates/openhuman-core/src/mcp/server/tools_tests_tag_and_dispatch_tests.rs b/crates/openhuman-core/src/mcp/server/tools_tests_tag_and_dispatch_tests.rs
deleted file mode 100644
index 664fb63b36..0000000000
--- a/crates/openhuman-core/src/mcp/server/tools_tests_tag_and_dispatch_tests.rs
+++ /dev/null
@@ -1,214 +0,0 @@
-use super::*;
-
-#[test]
-fn tree_tag_rejects_all_blank_tags() {
- // After blank-trim the list is empty — same failure mode as `[]`.
- let err = build_rpc_params(
- "tree.tag",
- json!({ "chunk_id": "abc", "tags": [" ", ""] }),
- )
- .expect_err("must reject");
- assert!(
- err.message().contains("at least one non-empty string"),
- "got: {}",
- err.message()
- );
-}
-
-#[test]
-fn tree_tag_rejects_non_string_tags() {
- // Numeric entries inside `tags` get caught by the string-array helper.
- let err = build_rpc_params("tree.tag", json!({ "chunk_id": "abc", "tags": ["ok", 42] }))
- .expect_err("must reject");
- assert!(
- err.message()
- .contains("argument `tags` must contain only strings"),
- "got: {}",
- err.message()
- );
-}
-
-#[test]
-fn tree_tag_builds_tag_record_document() {
- let params = build_rpc_params(
- "tree.tag",
- json!({ "chunk_id": "chunk-42", "tags": ["todo", "q3-planning"] }),
- )
- .expect("params");
-
- // Document key is deterministic on chunk_id only → re-tagging
- // the same chunk upserts.
- assert_eq!(params["namespace"], "mcp");
- assert_eq!(params["key"], "mcp-tag-chunk-42");
- assert_eq!(params["source_type"], "mcp");
-
- // Title surfaces the target chunk for human-readable recall.
- assert!(
- params["title"]
- .as_str()
- .expect("title is a string")
- .contains("chunk-42"),
- "title was: {}",
- params["title"]
- );
-
- // Top-level `tags` flows to the document tag index (queryable
- // via `doc_list` / search filters) — this is the key differentiator
- // from `memory.note` whose payload is opaque free-form text.
- assert_eq!(params["tags"], json!(["todo", "q3-planning"]));
-
- // Metadata carries the back-reference plus a mirrored tag list,
- // so consumers reading the metadata view don't need to also
- // join against the top-level `tags` field.
- let metadata = params["metadata"]
- .as_object()
- .expect("metadata is an object");
- assert_eq!(metadata["tags_for_chunk_id"], "chunk-42");
- assert_eq!(metadata["applied_tags"], json!(["todo", "q3-planning"]));
-}
-
-#[test]
-fn tree_tag_trims_blanks_but_keeps_real_tags() {
- // Mixed list — blanks are silently dropped (matches existing
- // `optional_string_array` behaviour) but the resulting set is
- // still non-empty so the call succeeds.
- let params = build_rpc_params(
- "tree.tag",
- json!({ "chunk_id": "chunk-7", "tags": [" important ", "", " ", "todo"] }),
- )
- .expect("params");
-
- assert_eq!(params["tags"], json!(["important", "todo"]));
-}
-
-#[test]
-fn tree_tag_rejects_empty_chunk_id() {
- let err = build_rpc_params("tree.tag", json!({ "chunk_id": "", "tags": ["todo"] }))
- .expect_err("must reject");
- assert!(
- err.message()
- .contains("argument `chunk_id` must not be empty"),
- "got: {}",
- err.message()
- );
-}
-
-#[test]
-fn tree_tag_rejects_unknown_argument() {
- let err = build_rpc_params(
- "tree.tag",
- json!({ "chunk_id": "abc", "tags": ["t"], "priority": "high" }),
- )
- .expect_err("must reject");
- assert!(
- err.message().contains("unexpected argument `priority`"),
- "got: {}",
- err.message()
- );
-}
-
-#[test]
-fn tree_tag_rejects_oversize_tag_array() {
- // Per-graycyrus #2316 review: cap the tag-array length so a
- // misbehaving client can't flood a chunk's tag-record document
- // with hundreds of categorical labels. Builds an over-cap
- // array and asserts the dedicated rejection message.
- let oversize: Vec<String> = (0..(TREE_TAG_MAX_TAGS + 1))
- .map(|i| format!("tag-{i}"))
- .collect();
- let err = build_rpc_params("tree.tag", json!({ "chunk_id": "abc", "tags": oversize }))
- .expect_err("must reject");
- assert!(
- err.message().contains("accepts at most"),
- "got: {}",
- err.message()
- );
-}
-
-#[test]
-fn tree_tag_rejects_oversize_individual_tag() {
- // Per-graycyrus #2316 review: a single oversize tag is almost
- // certainly free-form text that should be `memory.note` instead
- // of going through the categorical tag surface — reject up-front
- // so the misuse is visible rather than silently writing a giant
- // token into the queryable `tags` index.
- let oversize_tag = "a".repeat(TREE_TAG_MAX_TAG_LENGTH + 1);
- let err = build_rpc_params(
- "tree.tag",
- json!({ "chunk_id": "abc", "tags": [oversize_tag] }),
- )
- .expect_err("must reject");
- assert!(err.message().contains("exceeds"), "got: {}", err.message());
-}
-
-#[test]
-fn tree_tag_accepts_max_size_tags() {
- // Boundary: exactly TREE_TAG_MAX_TAGS entries (the cap is
- // "at most N", not "fewer than N") with each entry at exactly
- // TREE_TAG_MAX_TAG_LENGTH chars must succeed. Locks the
- // inclusive-vs-exclusive bound so a future off-by-one
- // refactor breaks the test, not user calls.
- let max_tags: Vec<String> = (0..TREE_TAG_MAX_TAGS)
- .map(|i| format!("tag-{i:0width$}", width = TREE_TAG_MAX_TAG_LENGTH - 4))
- .collect();
- // Sanity: each entry is == TREE_TAG_MAX_TAG_LENGTH chars.
- assert!(max_tags.iter().all(|t| t.len() == TREE_TAG_MAX_TAG_LENGTH));
- let params = build_rpc_params("tree.tag", json!({ "chunk_id": "abc", "tags": max_tags }))
- .expect("at the cap must succeed");
- // The built params should preserve all TREE_TAG_MAX_TAGS entries.
- assert_eq!(
- params["tags"].as_array().expect("tags is array").len(),
- TREE_TAG_MAX_TAGS
- );
-}
-
-// ── slug_from ─────────────────────────────────────────────────────
-
-#[test]
-fn slug_from_produces_clean_slug() {
- assert_eq!(slug_from("Hello World!"), "hello-world");
- assert_eq!(slug_from(" spaces "), "spaces");
- assert_eq!(slug_from("CamelCase123"), "camelcase123");
- assert_eq!(slug_from("a--b"), "a-b");
-}
-
-#[test]
-fn slug_from_truncates_long_titles() {
- let long = "a".repeat(100);
- let slug = slug_from(&long);
- assert!(slug.len() <= 64);
-}
-
-#[test]
-fn slug_from_returns_hash_fallback_for_non_alphanumeric_titles() {
- // Non-alphanumeric titles should produce "untitled-<hash>" with a
- // stable, deterministic hash suffix.
- let slug_bang = slug_from("!!!");
- let slug_at = slug_from("@@@");
- assert!(slug_bang.starts_with("untitled-"), "got: {slug_bang}");
- assert!(slug_at.starts_with("untitled-"), "got: {slug_at}");
- // Different inputs → different slugs
- assert_ne!(slug_bang, slug_at);
- // Empty title also gets a fallback
- assert!(slug_from("").starts_with("untitled-"));
- // Stable across calls
- assert_eq!(slug_from("!!!"), slug_bang);
-}
-
-#[test]
-fn slug_from_unicode_only_titles_are_unique_and_stable() {
- let chinese = slug_from("会议记录");
- let russian = slug_from("Протокол");
- let emoji = slug_from("🦀🚀");
- // All produce hash-based fallbacks
- assert!(chinese.starts_with("untitled-"), "got: {chinese}");
- assert!(russian.starts_with("untitled-"), "got: {russian}");
- assert!(emoji.starts_with("untitled-"), "got: {emoji}");
- // All distinct
- assert_ne!(chinese, russian);
- assert_ne!(chinese, emoji);
- assert_ne!(russian, emoji);
- // Stable
- assert_eq!(slug_from("会议记录"), chinese);
- assert_eq!(slug_from("Протокол"), russian);
-}