use crate::agents::AgentRegistry;
use crate::checkpoint::execution_history::ExecutionHistory;
use crate::checkpoint::RunContext;
use crate::config::Config;
use crate::executor::MockProcessExecutor;
use crate::logger::{Colors, Logger};
use crate::pipeline::Timer;
use crate::prompts::template_context::TemplateContext;
use crate::workspace::{MemoryWorkspace, Workspace};
use std::path::PathBuf;
use std::sync::Arc;
pub(super) struct TestFixture {
pub config: Config,
pub registry: AgentRegistry,
pub colors: Colors,
pub logger: Logger,
pub timer: Timer,
pub template_context: TemplateContext,
pub executor: Arc<MockProcessExecutor>,
pub workspace: MemoryWorkspace,
pub workspace_arc: Arc<dyn crate::workspace::Workspace>,
pub repo_root: PathBuf,
pub run_log_context: crate::logging::RunLogContext,
pub cloud: crate::config::types::CloudConfig,
pub git_env: crate::runtime::environment::mock::MockGitEnvironment,
}
impl TestFixture {
pub fn new() -> Self {
Self::with_workspace(MemoryWorkspace::new_test())
}
pub fn with_workspace(workspace: MemoryWorkspace) -> Self {
let workspace_arc = Arc::new(workspace.clone()) as Arc<dyn crate::workspace::Workspace>;
let colors = Colors { enabled: false };
let logger = Logger::new(colors);
let run_log_context = crate::logging::RunLogContext::new(&workspace).unwrap();
Self {
config: Config::default(),
registry: AgentRegistry::new().unwrap(),
colors,
logger,
timer: Timer::new(),
template_context: TemplateContext::default(),
executor: Arc::new(MockProcessExecutor::new()),
workspace,
workspace_arc,
repo_root: PathBuf::from("/mock/repo"),
run_log_context,
cloud: crate::config::types::CloudConfig::disabled(),
git_env: crate::runtime::environment::mock::MockGitEnvironment::new(),
}
}
pub fn ctx_with_workspace<'a>(
&'a mut self,
workspace: &'a dyn crate::workspace::Workspace,
) -> crate::phases::PhaseContext<'a> {
crate::phases::PhaseContext {
config: &self.config,
registry: &self.registry,
logger: &self.logger,
colors: &self.colors,
timer: &mut self.timer,
developer_agent: "dev",
reviewer_agent: "rev",
review_guidelines: None,
template_context: &self.template_context,
run_context: RunContext::new(),
execution_history: ExecutionHistory::new(),
executor: self.executor.as_ref(),
executor_arc: Arc::clone(&self.executor) as Arc<dyn crate::executor::ProcessExecutor>,
repo_root: self.repo_root.as_path(),
workspace,
workspace_arc: Arc::clone(&self.workspace_arc),
run_log_context: &self.run_log_context,
cloud_reporter: None,
cloud: &self.cloud,
env: &self.git_env,
}
}
pub fn ctx(&mut self) -> crate::phases::PhaseContext<'_> {
crate::phases::PhaseContext {
config: &self.config,
registry: &self.registry,
logger: &self.logger,
colors: &self.colors,
timer: &mut self.timer,
developer_agent: "dev",
reviewer_agent: "rev",
review_guidelines: None,
template_context: &self.template_context,
run_context: RunContext::new(),
execution_history: ExecutionHistory::new(),
executor: self.executor.as_ref(),
executor_arc: Arc::clone(&self.executor) as Arc<dyn crate::executor::ProcessExecutor>,
repo_root: self.repo_root.as_path(),
workspace: &self.workspace,
workspace_arc: Arc::clone(&self.workspace_arc),
run_log_context: &self.run_log_context,
cloud_reporter: None,
cloud: &self.cloud,
env: &self.git_env,
}
}
}
#[test]
fn test_fixture_produces_valid_context() {
let mut fixture = TestFixture::new();
assert_eq!(fixture.workspace.root(), std::path::Path::new("/test/repo"));
let ctx = fixture.ctx();
assert_eq!(ctx.developer_agent, "dev");
assert_eq!(ctx.reviewer_agent, "rev");
assert!(ctx.review_guidelines.is_none());
assert!(ctx.cloud_reporter.is_none());
}