Skip to content

Commit 516106c

Browse files
committed
Changed: Extract test helpers from task.rs into shared module
- Move agent/allow_tools/pattern_task/deny_task into test_helpers.rs - Import helpers with glob in task.rs tests
1 parent d111e61 commit 516106c

3 files changed

Lines changed: 85 additions & 46 deletions

File tree

src/reloaded-code-agents/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ mod loader;
66
mod parser;
77
mod path;
88
mod runtime;
9+
#[cfg(test)]
10+
mod test_helpers;
911
mod types;
1012

1113
pub use catalog::AgentCatalog;

src/reloaded-code-agents/src/runtime/task.rs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,8 @@ fn collect_allowed_tools(
193193
#[cfg(test)]
194194
mod tests {
195195
use super::*;
196-
use crate::types::PermissionRule;
197-
use crate::{AgentConfig, AgentMode, AgentRuntimeBuilder, AgentToolSettings};
198-
use ahash::AHashMap;
196+
use crate::test_helpers::*;
197+
use crate::AgentRuntimeBuilder;
199198
use indexmap::IndexMap;
200199
use reloaded_code_core::permissions::{ExpandError, PermissionAction};
201200
use reloaded_code_core::tool_metadata::{
@@ -204,49 +203,6 @@ mod tests {
204203

205204
type TestResult = Result<(), ExpandError>;
206205

207-
fn agent(
208-
name: &str,
209-
mode: AgentMode,
210-
description: &str,
211-
permission: IndexMap<String, PermissionRule>,
212-
) -> AgentConfig {
213-
AgentConfig {
214-
name: name.into(),
215-
mode,
216-
description: description.into(),
217-
model: None,
218-
hidden: false,
219-
temperature: None,
220-
top_p: None,
221-
permission,
222-
options: AHashMap::new(),
223-
tool_settings: AgentToolSettings::default(),
224-
prompt: Default::default(),
225-
}
226-
}
227-
228-
fn allow_tools(names: &[&str]) -> IndexMap<String, PermissionRule> {
229-
names
230-
.iter()
231-
.map(|n| ((*n).into(), PermissionRule::Action(PermissionAction::Allow)))
232-
.collect()
233-
}
234-
235-
fn pattern_task(patterns: &[(&str, PermissionAction)]) -> IndexMap<String, PermissionRule> {
236-
let mut map = IndexMap::new();
237-
for (pattern, action) in patterns {
238-
map.insert(pattern.to_string(), *action);
239-
}
240-
IndexMap::from([(task_meta::NAME.into(), PermissionRule::Pattern(map))])
241-
}
242-
243-
fn deny_task() -> IndexMap<String, PermissionRule> {
244-
IndexMap::from([(
245-
task_meta::NAME.into(),
246-
PermissionRule::Action(PermissionAction::Deny),
247-
)])
248-
}
249-
250206
/// Unknown callers yield no targets.
251207
#[test]
252208
fn callable_targets_returns_empty_for_unknown_caller() -> TestResult {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use crate::types::PermissionRule;
2+
use crate::{AgentConfig, AgentMode, AgentToolSettings};
3+
use ahash::AHashMap;
4+
use indexmap::IndexMap;
5+
use reloaded_code_core::permissions::PermissionAction;
6+
use reloaded_code_core::tool_metadata::task as task_meta;
7+
8+
/// Build an [`AgentConfig`] for tests.
9+
///
10+
/// # Parameters
11+
/// - `name` - agent name
12+
/// - `mode` - agent operating mode
13+
/// - `description` - agent description
14+
/// - `permission` - initial permission rules
15+
///
16+
/// # Returns
17+
/// A populated [`AgentConfig`] with all other fields set to defaults.
18+
pub(crate) fn agent(
19+
name: &str,
20+
mode: AgentMode,
21+
description: &str,
22+
permission: IndexMap<String, PermissionRule>,
23+
) -> AgentConfig {
24+
AgentConfig {
25+
name: name.into(),
26+
mode,
27+
description: description.into(),
28+
model: None,
29+
hidden: false,
30+
temperature: None,
31+
top_p: None,
32+
permission,
33+
options: AHashMap::new(),
34+
tool_settings: AgentToolSettings::default(),
35+
prompt: Default::default(),
36+
}
37+
}
38+
39+
/// Map tool names to `Allow` permission rules.
40+
///
41+
/// # Parameters
42+
/// - `names` - tool names that should be allowed.
43+
///
44+
/// # Returns
45+
/// An ordered map of name → `PermissionRule::Action(Allow)`.
46+
pub(crate) fn allow_tools(names: &[&str]) -> IndexMap<String, PermissionRule> {
47+
names
48+
.iter()
49+
.map(|n| ((*n).into(), PermissionRule::Action(PermissionAction::Allow)))
50+
.collect()
51+
}
52+
53+
/// Build task-scoped pattern permissions.
54+
///
55+
/// Patterns are wrapped under the task metadata name so they apply to task execution.
56+
///
57+
/// # Parameters
58+
/// - `patterns` - ordered pattern/action pairs.
59+
///
60+
/// # Returns
61+
/// A single-entry map keyed by [`task_meta::NAME`] containing [`PermissionRule::Pattern`].
62+
pub(crate) fn pattern_task(
63+
patterns: &[(&str, PermissionAction)],
64+
) -> IndexMap<String, PermissionRule> {
65+
let mut map = IndexMap::new();
66+
for (pattern, action) in patterns {
67+
map.insert(pattern.to_string(), *action);
68+
}
69+
IndexMap::from([(task_meta::NAME.into(), PermissionRule::Pattern(map))])
70+
}
71+
72+
/// Return a deny-all rule for task execution.
73+
///
74+
/// # Returns
75+
/// A single-entry map keyed by [`task_meta::NAME`] with `PermissionRule::Action(Deny)`.
76+
pub(crate) fn deny_task() -> IndexMap<String, PermissionRule> {
77+
IndexMap::from([(
78+
task_meta::NAME.into(),
79+
PermissionRule::Action(PermissionAction::Deny),
80+
)])
81+
}

0 commit comments

Comments
 (0)