refactor(g3-cli): eliminate code-path aliasing in config and project content loading
Consolidate duplicated logic into canonical shared functions: - Extract load_config_with_cli_overrides() to utils.rs - Was duplicated in lib.rs and accumulative.rs with subtle differences - lib.rs version had Chrome diagnostics + provider validation - accumulative.rs version was missing both - Now all callers use the complete canonical implementation - Extract combine_project_content() to project_files.rs - Was duplicated inline in lib.rs and agent_mode.rs - Simplified implementation using iterator flatten - Added unit tests for all cases This eliminates drift risk where the duplicated implementations could diverge over time (accumulative.rs was already missing Chrome diagnostics and provider validation). Agent: fowler
This commit is contained in:
@@ -82,6 +82,26 @@ pub fn read_project_memory(workspace_dir: &Path) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Combine AGENTS.md, README, and memory content into a single string.
|
||||
///
|
||||
/// Returns None if all inputs are None, otherwise joins non-None parts with double newlines.
|
||||
pub fn combine_project_content(
|
||||
agents_content: Option<String>,
|
||||
readme_content: Option<String>,
|
||||
memory_content: Option<String>,
|
||||
) -> Option<String> {
|
||||
let parts: Vec<String> = [agents_content, readme_content, memory_content]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
if parts.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(parts.join("\n\n"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Format a byte size for display.
|
||||
fn format_size(len: usize) -> String {
|
||||
if len < 1000 {
|
||||
@@ -178,4 +198,26 @@ mod tests {
|
||||
assert!(truncated.ends_with("..."));
|
||||
assert_eq!(truncated.len(), 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_combine_project_content_all_some() {
|
||||
let result = combine_project_content(
|
||||
Some("agents".to_string()),
|
||||
Some("readme".to_string()),
|
||||
Some("memory".to_string()),
|
||||
);
|
||||
assert_eq!(result, Some("agents\n\nreadme\n\nmemory".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_combine_project_content_partial() {
|
||||
let result = combine_project_content(None, Some("readme".to_string()), None);
|
||||
assert_eq!(result, Some("readme".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_combine_project_content_all_none() {
|
||||
let result = combine_project_content(None, None, None);
|
||||
assert_eq!(result, None);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user