huskies: merge 629_refactor_migrate_commanddispatch_and_commandcontext_to_services_bundle
This commit is contained in:
@@ -34,8 +34,8 @@ pub(super) fn handle_coverage(ctx: &CommandContext) -> Option<String> {
|
||||
let args = ctx.args.trim();
|
||||
|
||||
match args {
|
||||
"run" => Some(run_coverage(ctx.project_root)),
|
||||
"" => Some(read_cached_coverage(ctx.project_root)),
|
||||
"run" => Some(run_coverage(ctx.effective_root())),
|
||||
"" => Some(read_cached_coverage(ctx.effective_root())),
|
||||
other => Some(format!(
|
||||
"Usage: `coverage` (cached) or `coverage run` (fresh)\n\nUnknown argument: `{other}`"
|
||||
)),
|
||||
@@ -262,32 +262,13 @@ fn extract_summary_field(output: &str, label: &str) -> Option<String> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::agents::AgentPool;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
fn make_ctx<'a>(
|
||||
agents: &'a Arc<AgentPool>,
|
||||
ambient_rooms: &'a Arc<Mutex<HashSet<String>>>,
|
||||
services: &'a crate::services::Services,
|
||||
project_root: &'a std::path::Path,
|
||||
args: &'a str,
|
||||
) -> super::super::CommandContext<'a> {
|
||||
super::super::CommandContext {
|
||||
bot_name: "Timmy",
|
||||
args,
|
||||
project_root,
|
||||
agents,
|
||||
ambient_rooms,
|
||||
room_id: "!test:example.com",
|
||||
}
|
||||
}
|
||||
|
||||
fn test_agents() -> Arc<AgentPool> {
|
||||
Arc::new(AgentPool::new_test(3000))
|
||||
}
|
||||
|
||||
fn test_ambient() -> Arc<Mutex<HashSet<String>>> {
|
||||
Arc::new(Mutex::new(HashSet::new()))
|
||||
super::super::CommandContext::new_test(services, args, "!test:example.com", project_root)
|
||||
}
|
||||
|
||||
fn sample_coverage_report(overall: f64, threshold: f64, files: Vec<(&str, f64)>) -> String {
|
||||
@@ -336,9 +317,9 @@ mod tests {
|
||||
);
|
||||
std::fs::write(dir.path().join(".coverage_report.json"), &report).unwrap();
|
||||
|
||||
let agents = test_agents();
|
||||
let ambient = test_ambient();
|
||||
let ctx = make_ctx(&agents, &ambient, dir.path(), "");
|
||||
let services =
|
||||
crate::services::Services::new_test(dir.path().to_path_buf(), "Timmy".to_string());
|
||||
let ctx = make_ctx(&services, dir.path(), "");
|
||||
let output = handle_coverage(&ctx).unwrap();
|
||||
|
||||
assert!(output.contains("72.5"), "should include overall: {output}");
|
||||
@@ -371,9 +352,9 @@ mod tests {
|
||||
let report = sample_coverage_report(40.0, 30.0, files);
|
||||
std::fs::write(dir.path().join(".coverage_report.json"), &report).unwrap();
|
||||
|
||||
let agents = test_agents();
|
||||
let ambient = test_ambient();
|
||||
let ctx = make_ctx(&agents, &ambient, dir.path(), "");
|
||||
let services =
|
||||
crate::services::Services::new_test(dir.path().to_path_buf(), "Timmy".to_string());
|
||||
let ctx = make_ctx(&services, dir.path(), "");
|
||||
let output = handle_coverage(&ctx).unwrap();
|
||||
|
||||
assert!(output.contains("a.rs"), "should show lowest file: {output}");
|
||||
@@ -396,9 +377,9 @@ mod tests {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
std::fs::write(dir.path().join(".coverage_baseline"), "72.5\n").unwrap();
|
||||
|
||||
let agents = test_agents();
|
||||
let ambient = test_ambient();
|
||||
let ctx = make_ctx(&agents, &ambient, dir.path(), "");
|
||||
let services =
|
||||
crate::services::Services::new_test(dir.path().to_path_buf(), "Timmy".to_string());
|
||||
let ctx = make_ctx(&services, dir.path(), "");
|
||||
let output = handle_coverage(&ctx).unwrap();
|
||||
|
||||
assert!(
|
||||
@@ -416,9 +397,9 @@ mod tests {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
std::fs::write(dir.path().join(".coverage_baseline"), "60.00\n65.21\n").unwrap();
|
||||
|
||||
let agents = test_agents();
|
||||
let ambient = test_ambient();
|
||||
let ctx = make_ctx(&agents, &ambient, dir.path(), "");
|
||||
let services =
|
||||
crate::services::Services::new_test(dir.path().to_path_buf(), "Timmy".to_string());
|
||||
let ctx = make_ctx(&services, dir.path(), "");
|
||||
let output = handle_coverage(&ctx).unwrap();
|
||||
|
||||
assert!(
|
||||
@@ -435,9 +416,9 @@ mod tests {
|
||||
fn coverage_missing_both_files_reports_clearly() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
|
||||
let agents = test_agents();
|
||||
let ambient = test_ambient();
|
||||
let ctx = make_ctx(&agents, &ambient, dir.path(), "");
|
||||
let services =
|
||||
crate::services::Services::new_test(dir.path().to_path_buf(), "Timmy".to_string());
|
||||
let ctx = make_ctx(&services, dir.path(), "");
|
||||
let output = handle_coverage(&ctx).unwrap();
|
||||
|
||||
assert!(
|
||||
@@ -450,9 +431,9 @@ mod tests {
|
||||
fn coverage_run_missing_script_reports_error() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
|
||||
let agents = test_agents();
|
||||
let ambient = test_ambient();
|
||||
let ctx = make_ctx(&agents, &ambient, dir.path(), "run");
|
||||
let services =
|
||||
crate::services::Services::new_test(dir.path().to_path_buf(), "Timmy".to_string());
|
||||
let ctx = make_ctx(&services, dir.path(), "run");
|
||||
let output = handle_coverage(&ctx).unwrap();
|
||||
|
||||
assert!(
|
||||
@@ -464,9 +445,9 @@ mod tests {
|
||||
#[test]
|
||||
fn coverage_unknown_arg_returns_usage() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let agents = test_agents();
|
||||
let ambient = test_ambient();
|
||||
let ctx = make_ctx(&agents, &ambient, dir.path(), "blah");
|
||||
let services =
|
||||
crate::services::Services::new_test(dir.path().to_path_buf(), "Timmy".to_string());
|
||||
let ctx = make_ctx(&services, dir.path(), "blah");
|
||||
let output = handle_coverage(&ctx).unwrap();
|
||||
assert!(
|
||||
output.contains("Usage"),
|
||||
@@ -480,15 +461,13 @@ mod tests {
|
||||
let report = sample_coverage_report(55.0, 50.0, vec![]);
|
||||
std::fs::write(dir.path().join(".coverage_report.json"), &report).unwrap();
|
||||
|
||||
let agents = test_agents();
|
||||
let ambient = test_ambient();
|
||||
let services =
|
||||
crate::services::Services::new_test(dir.path().to_path_buf(), "Timmy".to_string());
|
||||
let room_id = "!test:example.com".to_string();
|
||||
let dispatch = super::super::CommandDispatch {
|
||||
bot_name: "Timmy",
|
||||
services: &services,
|
||||
project_root: &services.project_root,
|
||||
bot_user_id: "@timmy:homeserver.local",
|
||||
project_root: dir.path(),
|
||||
agents: &agents,
|
||||
ambient_rooms: &ambient,
|
||||
room_id: &room_id,
|
||||
};
|
||||
let result = super::super::try_handle_command(&dispatch, "@timmy coverage");
|
||||
|
||||
Reference in New Issue
Block a user