use pretty_assertions::assert_eq;
use rho_protocol as wire;
use super::{available_commands, skill_commands};
use crate::{
agent::AgentRuntimeSpec,
app::session_commands::{test_support::Fixture, BuiltInCommand, CommandSet, Hosting},
skills::{Skill, SkillSource},
};
#[test]
fn a_menu_leaves_out_built_ins_and_kinds_its_host_does_not_run() {
let fixture = Fixture::new();
let commands = CommandSet {
built_ins: &[BuiltInCommand::Init],
workflows: Hosting::Refused,
agents: Hosting::Refused,
sessions_label: "test sessions",
};
let listed = available_commands(&fixture.scope(), commands)
.into_iter()
.map(|command| (command.name, command.kind, command.input_hint))
.collect::<Vec<_>>();
let slash = |name: &str, hint: Option<&str>| {
(
name.to_string(),
wire::CommandKind::Slash,
hint.map(str::to_string),
)
};
let skill = |name: &str| (name.to_string(), wire::CommandKind::Skill, None);
assert_eq!(
listed,
[
slash("init", None),
slash("prompt:review", Some("[$1]")),
slash("mcp:docs:search", Some("<query>")),
skill("demo"),
skill("rho-agent-creator"),
skill("rho-config"),
skill("rho-init"),
skill("rho-workflow-authoring"),
]
);
}
#[test]
fn agent_commands_are_listed_for_orchestration_tools_alone() {
let fixture = Fixture::new();
let commands = CommandSet {
built_ins: &[BuiltInCommand::Init],
workflows: Hosting::Runs,
agents: Hosting::Runs,
sessions_label: "test sessions",
};
let scope = fixture.scope();
let rho_agents = scope
.files
.agent_catalog()
.unwrap()
.iter()
.filter(|entry| matches!(entry.definition.runtime, AgentRuntimeSpec::Rho { .. }))
.map(|entry| format!("agent:{}", entry.definition.id))
.collect::<Vec<_>>();
let (orchestration, everyone): (Vec<_>, Vec<_>) = available_commands(&scope, commands)
.into_iter()
.partition(|command| command.audience == wire::CommandAudience::Orchestration);
let orchestration = orchestration
.into_iter()
.map(|command| command.name)
.collect::<Vec<_>>();
let not_everyones = everyone
.into_iter()
.filter(|command| command.audience != wire::CommandAudience::Everyone)
.collect::<Vec<_>>();
assert_eq!(
(
orchestration,
not_everyones,
rho_agents.contains(&"agent:child-rho".to_string())
),
(rho_agents, Vec::new(), true)
);
}
fn skill(name: &str) -> Skill {
Skill {
name: name.into(),
description: format!("{name} description"),
disable_model_invocation: false,
source: SkillSource::BuiltIn,
contents: String::new(),
}
}
#[test]
fn skill_commands_skip_names_composers_read_as_amounts() {
let skills = [
skill("review"),
skill("2fa"),
skill("20k"),
skill("1e6"),
skill("42"),
];
let names = skill_commands(&skills)
.into_iter()
.map(|command| command.name)
.collect::<Vec<_>>();
assert_eq!(names, ["review", "2fa"]);
}