diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f04c330..7f934491 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,6 +57,11 @@ jobs: - name: Run tests run: cargo test --workspace + - name: Run CLI semantic diff harness + if: matrix.os == 'ubuntu-latest' + shell: bash + run: ATOMIC_BIN="$PWD/target/debug/atomic" bash tests/harness/run_all.sh 09 + fmt: name: Format runs-on: ubuntu-latest diff --git a/atomic-cli/README.md b/atomic-cli/README.md index ccabd05e..6517fece 100644 --- a/atomic-cli/README.md +++ b/atomic-cli/README.md @@ -860,6 +860,13 @@ Global identity configuration is stored in `~/.config/atomic/` (or platform equi # Run all CLI tests cargo test -p atomic-cli +# Validate that every public command path renders help +cargo test -p atomic-cli --test cli_surface_integration_test + +# Run the black-box CLI harness against a freshly built binary +cargo build -p atomic-cli +ATOMIC_BIN="$PWD/target/debug/atomic" bash tests/harness/run_all.sh + # Run tests serially (required for integration tests that change cwd) cargo test -p atomic-cli -- --test-threads=1 @@ -883,4 +890,4 @@ cargo test -p atomic-cli -- --nocapture ## License -Dual-licensed under MIT and Apache 2.0. \ No newline at end of file +Dual-licensed under MIT and Apache 2.0. diff --git a/atomic-cli/src/commands/agent/disable.rs b/atomic-cli/src/commands/agent/disable.rs index 154802f8..1452958a 100644 --- a/atomic-cli/src/commands/agent/disable.rs +++ b/atomic-cli/src/commands/agent/disable.rs @@ -210,10 +210,12 @@ impl Disable { /// - `claude-code` → `~/.claude/settings.json` /// - `gemini-cli` → `~/.gemini/settings.json` /// - `agy` → `~/.gemini/config/plugins/atomic/` (plugin) + /// - `codex` → `~/.codex/hooks.json` /// - No `--agent` flag → removes from all agents that have global hooks fn run_global(&self) -> CliResult<()> { use atomic_agent::hooks::agy::AgyHook; use atomic_agent::hooks::claude_code::ClaudeCodeHook; + use atomic_agent::hooks::codex::CodexHook; use atomic_agent::hooks::gemini_cli::GeminiCliHook; let agents: Vec<&str> = if let Some(ref name) = self.agent { @@ -230,6 +232,9 @@ impl Disable { if AgyHook::new().is_installed_global() { found.push("agy"); } + if CodexHook::new().is_installed_global() { + found.push("codex"); + } found }; @@ -295,6 +300,21 @@ impl Disable { } } } + "codex" => { + let hook = CodexHook::new(); + if !hook.is_installed_global() { + continue; + } + match hook.uninstall_global() { + Ok(()) => { + print_success("Removed global hooks from ~/.codex/hooks.json"); + total_removed += 1; + } + Err(e) => { + print_error(&format!("Failed to remove Codex global hooks: {}", e)); + } + } + } "kiro" => { print_success("Kiro hooks are configured through the IDE panel."); println!( @@ -309,7 +329,7 @@ impl Disable { } other => { print_warning(&format!( - "Global disable is not supported for '{}'. Supported agents: claude-code, gemini-cli, agy, kilo, kiro", + "Global disable is not supported for '{}'. Supported agents: claude-code, gemini-cli, agy, codex, kilo, kiro", other )); } diff --git a/atomic-cli/src/commands/agent/enable.rs b/atomic-cli/src/commands/agent/enable.rs index a85c4ca0..a72b07b6 100644 --- a/atomic-cli/src/commands/agent/enable.rs +++ b/atomic-cli/src/commands/agent/enable.rs @@ -128,12 +128,18 @@ impl Command for Enable { // Install for all detected agents let detected = registry.detect(&repo_root); if detected.is_empty() { - // If none detected, try all registered agents - print_warning("No agents detected — installing hooks for all registered agents."); - registry.list() - } else { - detected + // Do not install hooks when no agent is detected. + print_error( + "No agents detected in this repository — nothing to enable with --all.", + ); + print_warning( + "Create a .claude/, .gemini/, or .agents/ directory first, or use --agent .", + ); + return Err(crate::error::CliError::InvalidArgument { + message: "no agents detected for --all".to_string(), + }); } + detected } else if let Some(ref name) = self.agent { // Specific agent requested — validate it exists registry diff --git a/atomic-cli/src/commands/clone/command.rs b/atomic-cli/src/commands/clone/command.rs index 766e2e3e..a604cbd1 100644 --- a/atomic-cli/src/commands/clone/command.rs +++ b/atomic-cli/src/commands/clone/command.rs @@ -529,6 +529,7 @@ impl Clone { } // Apply downloaded changes to the local view + let mut apply_errors = Vec::new(); if stats.changes_downloaded > 0 { print_blank(); progress.phase = ClonePhase::Applying; @@ -536,7 +537,6 @@ impl Clone { // Insert each downloaded change in order to build the graph let insert_options = atomic_repository::InsertOptions::default(); - let mut apply_errors = Vec::new(); for entry in &remote_entries { let hash = match atomic_core::types::Hash::from_base32(entry.hash.as_bytes()) { @@ -657,21 +657,39 @@ impl Clone { progress.phase = ClonePhase::Complete; - // Final summary + // Keep partial output, but return failure when any step failed. print_blank(); - if stats.has_failures() { + if stats.has_failures() || !apply_errors.is_empty() { print_warning(&format!( - "Clone completed with errors: {} downloaded, {} failed", - stats.changes_downloaded, stats.changes_failed - )); - } else { - print_success(&format!( - "Clone complete: {} downloaded into {}/", - format_count(stats.changes_downloaded, "change"), - target_path.display() + "Clone completed with errors: {} downloaded, {} failed to download, {} failed to apply", + stats.changes_downloaded, + stats.changes_failed, + apply_errors.len(), )); + + if self.into_existing { + print_hint( + "Next: run 'atomic git import --incremental' to import the Git checkout.", + ); + } + + // Preserve the partial clone before returning the error. + if let Some(guard) = guard { + guard.disable(); + } + return Err(CliError::Internal(anyhow::anyhow!( + "clone completed with errors ({} download, {} apply)", + stats.changes_failed, + apply_errors.len(), + ))); } + print_success(&format!( + "Clone complete: {} downloaded into {}/", + format_count(stats.changes_downloaded, "change"), + target_path.display() + )); + if self.into_existing { print_hint("Next: run 'atomic git import --incremental' to import the Git checkout."); } diff --git a/atomic-cli/src/commands/git/push.rs b/atomic-cli/src/commands/git/push.rs index 507cffe8..43d5cbc9 100644 --- a/atomic-cli/src/commands/git/push.rs +++ b/atomic-cli/src/commands/git/push.rs @@ -160,10 +160,9 @@ impl Command for Push { print_success(&format!("Pushed to {}/{}", self.remote, current_view)); } Err(e) => { - print_warning(&format!( - "Commit created but push failed: {}. Run 'git push' manually.", - e - )); + // Keep the local commit, but report the failed push. + print_warning("Commit created locally. Run 'git push' manually to retry."); + return Err(e); } } } diff --git a/atomic-cli/src/commands/intent/delete.rs b/atomic-cli/src/commands/intent/delete.rs index a4a03843..6acad684 100644 --- a/atomic-cli/src/commands/intent/delete.rs +++ b/atomic-cli/src/commands/intent/delete.rs @@ -38,6 +38,10 @@ impl Command for IntentDelete { let repo = Repository::open(&root).map_err(CliError::Repository)?; if !self.force { + // Check that the intent exists before prompting. + repo.vault_intent_show(&self.id) + .map_err(CliError::Repository)?; + let prompt = format!( "Discard intent '{}'? This removes the unstarted draft from the vault.", self.id diff --git a/atomic-cli/src/commands/org/delete.rs b/atomic-cli/src/commands/org/delete.rs index 7de0669c..f9a19863 100644 --- a/atomic-cli/src/commands/org/delete.rs +++ b/atomic-cli/src/commands/org/delete.rs @@ -83,8 +83,18 @@ impl Command for OrgDelete { impl OrgDelete { async fn execute(&self) -> CliResult<()> { - // Prompt for confirmation unless --force is set. + let client = build_client(self.org.as_deref(), None).await?; + + // `--force` skips both the precheck and confirmation. if !self.force { + // Check that the organization exists before prompting. + atomic_teams::org::get_org(&client, &self.slug) + .await + .map_err(|e| CliError::RemoteError { + message: e.to_string(), + url: None, + })?; + print_warning(&format!( "This will permanently delete organization '{}' and all its data.", self.slug @@ -103,8 +113,6 @@ impl OrgDelete { } } - let client = build_client(self.org.as_deref(), None).await?; - atomic_teams::org::delete_org(&client, &self.slug) .await .map_err(|e| CliError::RemoteError { diff --git a/atomic-cli/src/commands/pull/command.rs b/atomic-cli/src/commands/pull/command.rs index 0ea83e18..17f6e3c6 100644 --- a/atomic-cli/src/commands/pull/command.rs +++ b/atomic-cli/src/commands/pull/command.rs @@ -105,9 +105,10 @@ pub struct Pull { /// Remote name or URL to pull from. /// /// Can be a configured remote name (like "origin") or a full URL. - /// If not specified, uses the default remote "origin". - #[arg(default_value = DEFAULT_REMOTE)] - pub remote: String, + /// + /// Defaults to the configured remote, then `origin`. + #[arg()] + pub remote: Option, /// Local view to pull into. /// @@ -174,12 +175,12 @@ impl Pull { /// use atomic::commands::pull::Pull; /// /// let pull = Pull::new(); - /// assert_eq!(pull.remote, "origin"); + /// assert!(pull.remote.is_none()); /// assert!(!pull.dry_run); /// ``` pub fn new() -> Self { Self { - remote: DEFAULT_REMOTE.to_string(), + remote: None, to_view: None, from_view: None, dry_run: false, @@ -193,7 +194,7 @@ impl Pull { /// Builder: set the remote name or URL. pub fn with_remote(mut self, remote: impl Into) -> Self { - self.remote = remote.into(); + self.remote = Some(remote.into()); self } @@ -247,24 +248,31 @@ impl Pull { // Internal Helper Methods - /// Resolve the remote URL and any identity hint from the `--identity` flag. - /// - /// Returns `(url, identity_hint)` where `identity_hint` comes solely from - /// the `--identity` CLI flag. If absent, `attach_identity` falls back to - /// URL-subdomain inference. - fn resolve_remote_url(&self, repo: &Repository) -> CliResult<(String, Option)> { + /// Use the explicit remote first, then the repository default. + fn resolve_remote_name(&self, repo: &Repository) -> String { + match &self.remote { + Some(name) => name.clone(), + None => repo + .get_default_remote() + .map(|(name, _entry)| name) + .unwrap_or_else(|_| DEFAULT_REMOTE.to_string()), + } + } + + /// Resolve the remote and optional identity override. + fn resolve_remote_url(&self, repo: &Repository) -> CliResult<(String, String, Option)> { + let remote_name = self.resolve_remote_name(repo); + // If it looks like a URL, use it directly - if self.remote.contains("://") { - return Ok((self.remote.clone(), self.identity.clone())); + if remote_name.contains("://") { + return Ok((remote_name.clone(), remote_name, self.identity.clone())); } // Look up named remote in repository configuration - match repo.get_remote(&self.remote) { - Ok(entry) => Ok((entry.url, self.identity.clone())), + match repo.get_remote(&remote_name) { + Ok(entry) => Ok((remote_name, entry.url, self.identity.clone())), Err(atomic_repository::RepositoryError::RemoteNotFound { .. }) => { - Err(CliError::RemoteNotFound { - name: self.remote.clone(), - }) + Err(CliError::RemoteNotFound { name: remote_name }) } Err(e) => Err(CliError::Repository(e)), } @@ -309,6 +317,7 @@ impl Pull { /// Shows what changes would be pulled without actually pulling them. fn display_dry_run( &self, + remote_name: &str, remote_url: &str, remote_view: &str, to_download: &[PullChange], @@ -321,7 +330,7 @@ impl Pull { println!( "Would pull {} from {} (view: {}):", format_count(to_download.len(), "change"), - self.remote, + remote_name, remote_view ); print_blank(); @@ -373,8 +382,8 @@ impl Pull { let repo_root = find_repository_root()?; let repo = Repository::open(&repo_root).map_err(CliError::Repository)?; - // Resolve remote URL and identity hint - let (remote_url, identity_hint) = self.resolve_remote_url(&repo)?; + // Resolve remote name, URL, and identity hint + let (remote_name, remote_url, identity_hint) = self.resolve_remote_url(&repo)?; // Determine views let local_view = self.get_local_view(&repo); @@ -383,7 +392,7 @@ impl Pull { // Print header println!( "Pulling from {} ({})", - style_view(&self.remote), + style_view(&remote_name), hint(&remote_url) ); @@ -453,7 +462,7 @@ impl Pull { // Handle dry run if self.dry_run { - return self.display_dry_run(&remote_url, &remote_view, &to_download); + return self.display_dry_run(&remote_name, &remote_url, &remote_view, &to_download); } // Check for nothing to pull @@ -594,6 +603,7 @@ impl Pull { } // Materialize the working copy so on-disk files reflect the new state + let mut materialize_failed = false; if stats.has_applied() { let mat_spinner = create_spinner("Updating working copy..."); match repo.materialize() { @@ -604,6 +614,7 @@ impl Pull { ); } Err(e) => { + materialize_failed = true; finish_error(&mat_spinner, "Failed to update working copy"); print_warning(&format!( "Applied {} but failed to update working copy: {}", @@ -703,21 +714,33 @@ impl Pull { } } - // Final summary + // Keep partial output, but return failure when any step failed. print_blank(); - if stats.has_failures() { + if stats.has_failures() || !apply_errors.is_empty() || materialize_failed { print_warning(&format!( - "Pull completed with errors: {} downloaded, {} failed", - stats.changes_downloaded, stats.changes_failed - )); - } else { - print_success(&format!( - "Pull complete: {} downloaded and applied to {}", - format_count(stats.changes_downloaded, "change"), - local_view + "Pull completed with errors: {} downloaded, {} failed to download, {} failed to apply", + stats.changes_downloaded, + stats.changes_failed, + apply_errors.len(), )); + return Err(CliError::Internal(anyhow::anyhow!( + "pull completed with errors ({} download, {} apply{})", + stats.changes_failed, + apply_errors.len(), + if materialize_failed { + ", working copy not updated" + } else { + "" + }, + ))); } + print_success(&format!( + "Pull complete: {} downloaded and applied to {}", + format_count(stats.changes_downloaded, "change"), + local_view + )); + Ok(()) } } @@ -765,7 +788,7 @@ mod tests { fn test_pull_new() { let pull = Pull::new(); - assert_eq!(pull.remote, DEFAULT_REMOTE); + assert!(pull.remote.is_none()); assert!(pull.to_view.is_none()); assert!(pull.from_view.is_none()); assert!(!pull.dry_run); @@ -779,21 +802,21 @@ mod tests { #[test] fn test_pull_default() { let pull: Pull = Default::default(); - assert_eq!(pull.remote, DEFAULT_REMOTE); + assert!(pull.remote.is_none()); } /// Test with_remote builder method. #[test] fn test_pull_with_remote() { let pull = Pull::new().with_remote("upstream"); - assert_eq!(pull.remote, "upstream"); + assert_eq!(pull.remote.as_deref(), Some("upstream")); } /// Test with_remote with URL. #[test] fn test_pull_with_remote_url() { let pull = Pull::new().with_remote("https://example.com/repo"); - assert_eq!(pull.remote, "https://example.com/repo"); + assert_eq!(pull.remote.as_deref(), Some("https://example.com/repo")); } /// Test with_to_view builder method. @@ -861,7 +884,7 @@ mod tests { .with_timeout(120) .with_download_only(true); - assert_eq!(pull.remote, "upstream"); + assert_eq!(pull.remote.as_deref(), Some("upstream")); assert_eq!(pull.to_view, Some("feature".to_string())); assert_eq!(pull.from_view, Some("main".to_string())); assert!(pull.dry_run); @@ -878,7 +901,7 @@ mod tests { let cloned = original.clone(); - assert_eq!(cloned.remote, "test"); + assert_eq!(cloned.remote.as_deref(), Some("test")); assert!(cloned.dry_run); } diff --git a/atomic-cli/src/commands/pull/mod.rs b/atomic-cli/src/commands/pull/mod.rs index a19a9055..1509586e 100644 --- a/atomic-cli/src/commands/pull/mod.rs +++ b/atomic-cli/src/commands/pull/mod.rs @@ -32,7 +32,7 @@ //! atomic pull [OPTIONS] [REMOTE] //! //! Arguments: -//! [REMOTE] Remote name or URL (default: "origin") +//! [REMOTE] Remote name or URL (default: the configured default remote, or "origin") //! //! Options: //! --to-channel Local channel to pull into (default: current) @@ -183,7 +183,7 @@ mod tests { #[test] fn test_pull_reexported() { let pull = Pull::new(); - assert_eq!(pull.remote, DEFAULT_REMOTE); + assert!(pull.remote.is_none()); } /// Verify that PullChange is properly re-exported. diff --git a/atomic-cli/src/commands/push/command.rs b/atomic-cli/src/commands/push/command.rs index d2c177f6..48841f77 100644 --- a/atomic-cli/src/commands/push/command.rs +++ b/atomic-cli/src/commands/push/command.rs @@ -78,9 +78,10 @@ pub struct Push { /// Remote name or URL to push to. /// /// Can be a configured remote name (like "origin") or a full URL. - /// If not specified, uses the default remote "origin". - #[arg(default_value = DEFAULT_REMOTE)] - pub remote: String, + /// + /// Defaults to the configured remote, then `origin`. + #[arg()] + pub remote: Option, /// Remote view to push to. /// @@ -142,12 +143,12 @@ impl Push { /// use atomic::commands::push::Push; /// /// let push = Push::new(); - /// assert_eq!(push.remote, "origin"); + /// assert!(push.remote.is_none()); /// assert!(!push.dry_run); /// ``` pub fn new() -> Self { Self { - remote: DEFAULT_REMOTE.to_string(), + remote: None, to_view: None, from_view: None, dry_run: false, @@ -161,7 +162,7 @@ impl Push { /// Builder: set the remote name or URL. pub fn with_remote(mut self, remote: impl Into) -> Self { - self.remote = remote.into(); + self.remote = Some(remote.into()); self } @@ -177,6 +178,17 @@ impl Push { self } + /// Use the explicit remote first, then the repository default. + fn resolve_remote_name(&self, repo: &Repository) -> String { + match &self.remote { + Some(name) => name.clone(), + None => repo + .get_default_remote() + .map(|(name, _entry)| name) + .unwrap_or_else(|_| DEFAULT_REMOTE.to_string()), + } + } + /// Builder: set the dry-run flag. pub fn with_dry_run(mut self, dry_run: bool) -> Self { self.dry_run = dry_run; @@ -213,24 +225,20 @@ impl Push { self } - /// Resolve the remote URL and any identity hint from the `--identity` flag. - /// - /// Returns `(url, identity_hint)` where `identity_hint` comes solely from - /// the `--identity` CLI flag. If absent, `attach_identity` falls back to - /// URL-subdomain inference. - fn resolve_remote_url(&self, repo: &Repository) -> CliResult<(String, Option)> { + /// Resolve the remote and optional identity override. + fn resolve_remote_url(&self, repo: &Repository) -> CliResult<(String, String, Option)> { + let remote_name = self.resolve_remote_name(repo); + // If it looks like a URL, use it directly - if self.remote.contains("://") { - return Ok((self.remote.clone(), self.identity.clone())); + if remote_name.contains("://") { + return Ok((remote_name.clone(), remote_name, self.identity.clone())); } // Look up named remote in repository configuration - match repo.get_remote(&self.remote) { - Ok(entry) => Ok((entry.url, self.identity.clone())), + match repo.get_remote(&remote_name) { + Ok(entry) => Ok((remote_name, entry.url, self.identity.clone())), Err(atomic_repository::RepositoryError::RemoteNotFound { .. }) => { - Err(CliError::RemoteNotFound { - name: self.remote.clone(), - }) + Err(CliError::RemoteNotFound { name: remote_name }) } Err(e) => Err(CliError::Repository(e)), } @@ -273,6 +281,7 @@ impl Push { /// Display the dry run preview. fn display_dry_run( &self, + remote_name: &str, remote_url: &str, remote_view: &str, to_upload: &[PushChange], @@ -285,7 +294,7 @@ impl Push { println!( "Would push {} to {} (view: {}):", format_count(to_upload.len(), "change"), - self.remote, + remote_name, remote_view ); print_blank(); @@ -308,8 +317,8 @@ impl Push { let repo_root = find_repository_root()?; let repo = Repository::open(&repo_root).map_err(CliError::Repository)?; - // Resolve remote URL and identity hint - let (remote_url, identity_hint) = self.resolve_remote_url(&repo)?; + // Resolve remote name, URL, and identity hint + let (remote_name, remote_url, identity_hint) = self.resolve_remote_url(&repo)?; // Determine views let local_view = self.get_local_view(&repo); @@ -319,7 +328,7 @@ impl Push { // Print header println!( "Pushing to {} ({})", - style_view(&self.remote), + style_view(&remote_name), hint(&remote_url) ); @@ -427,7 +436,7 @@ impl Push { // Handle dry run if self.dry_run { - return self.display_dry_run(&remote_url, &remote_view, &to_upload); + return self.display_dry_run(&remote_name, &remote_url, &remote_view, &to_upload); } // Check for nothing to push @@ -484,7 +493,7 @@ impl Push { print_blank(); print_success(&format!( "Push complete: {} view created on {}", - remote_view, self.remote + remote_view, remote_name )); return Ok(()); } @@ -805,7 +814,7 @@ mod tests { #[test] fn test_push_new() { let push = Push::new(); - assert_eq!(push.remote, "origin"); + assert!(push.remote.is_none()); assert!(push.to_view.is_none()); assert!(push.from_view.is_none()); assert!(!push.dry_run); @@ -818,19 +827,19 @@ mod tests { #[test] fn test_push_default() { let push = Push::default(); - assert_eq!(push.remote, "origin"); + assert!(push.remote.is_none()); } #[test] fn test_push_with_remote() { let push = Push::new().with_remote("upstream"); - assert_eq!(push.remote, "upstream"); + assert_eq!(push.remote.as_deref(), Some("upstream")); } #[test] fn test_push_with_remote_url() { let push = Push::new().with_remote("https://example.com/repo"); - assert_eq!(push.remote, "https://example.com/repo"); + assert_eq!(push.remote.as_deref(), Some("https://example.com/repo")); } #[test] @@ -890,7 +899,7 @@ mod tests { .with_insecure(true) .with_timeout(120); - assert_eq!(push.remote, "upstream"); + assert_eq!(push.remote.as_deref(), Some("upstream")); assert_eq!(push.to_view, Some("main".to_string())); assert_eq!(push.from_view, Some("feature".to_string())); assert!(push.dry_run); @@ -911,7 +920,7 @@ mod tests { #[test] fn test_push_debug() { - let push = Push::new(); + let push = Push::new().with_remote("origin"); let debug_str = format!("{:?}", push); assert!(debug_str.contains("Push")); diff --git a/atomic-cli/src/commands/push/mod.rs b/atomic-cli/src/commands/push/mod.rs index a2dbf970..b3748446 100644 --- a/atomic-cli/src/commands/push/mod.rs +++ b/atomic-cli/src/commands/push/mod.rs @@ -31,7 +31,7 @@ //! atomic push [OPTIONS] [REMOTE] //! //! Arguments: -//! [REMOTE] Remote name or URL (default: "origin") +//! [REMOTE] Remote name or URL (default: the configured default remote, or "origin") //! //! Options: //! --to-channel Remote channel to push to (default: same as local) @@ -147,7 +147,7 @@ mod tests { #[test] fn test_push_reexported() { let push = Push::new(); - assert_eq!(push.remote, DEFAULT_REMOTE); + assert!(push.remote.is_none()); } #[test] diff --git a/atomic-cli/src/commands/query/mod.rs b/atomic-cli/src/commands/query/mod.rs index 0221664d..c4455fd1 100644 --- a/atomic-cli/src/commands/query/mod.rs +++ b/atomic-cli/src/commands/query/mod.rs @@ -1027,6 +1027,16 @@ fn emit_html(query: &str, nodes: &[KgNode], edges: &[KgEdge]) -> String { ) } +/// Truncate display text on character boundaries and append `...`. +fn truncate_display(s: &str, max_chars: usize) -> String { + if s.chars().count() <= max_chars { + s.to_string() + } else { + let kept: String = s.chars().take(max_chars.saturating_sub(3)).collect(); + format!("{}...", kept) + } +} + /// Search the knowledge graph. #[derive(Parser, Debug)] pub struct QueryNodes { @@ -1099,12 +1109,7 @@ impl Command for QueryNodes { let summary_display = if summary.is_empty() { String::new() } else { - let truncated = if summary.len() > 60 { - format!("{}...", &summary[..57]) - } else { - summary.to_string() - }; - format!(" {}", truncated) + format!(" {}", truncate_display(summary, 60)) }; println!(" [{}] {}{}", node.kind, node.id, summary_display); } @@ -1150,12 +1155,7 @@ impl Command for QueryNeighbors { let summary_display = if summary.is_empty() { String::new() } else { - let truncated = if summary.len() > 50 { - format!("{}...", &summary[..47]) - } else { - summary.to_string() - }; - format!(" {}", truncated) + format!(" {}", truncate_display(summary, 50)) }; println!(" [{}] {}{}", node.kind, node.id, summary_display); } @@ -1811,7 +1811,8 @@ impl Command for PlanExec { for node in &result.nodes { print!(" [{}] {}", node.kind, node.label); if let Some(ref s) = node.summary { - let short = if s.len() > 60 { &s[..60] } else { s }; + // Truncate safely for Unicode text. + let short: String = s.chars().take(60).collect(); print!(": {}", short); } println!(); @@ -1831,7 +1832,8 @@ impl Command for PlanExec { if !result.content.is_empty() { println!("\nContent ({} entries):", result.content.len()); for (path, text) in &result.content { - let preview = if text.len() > 100 { &text[..100] } else { text }; + // Truncate safely for Unicode text. + let preview: String = text.chars().take(100).collect(); println!(" {}: {}...", path, preview.replace('\n', " ")); } } @@ -1965,3 +1967,55 @@ impl Command for QueryAsk { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::truncate_display; + + #[test] + fn test_truncate_display_short_ascii_unchanged() { + assert_eq!(truncate_display("hello", 60), "hello"); + } + + #[test] + fn test_truncate_display_long_ascii_truncated() { + let s = "a".repeat(80); + let out = truncate_display(&s, 60); + assert_eq!(out, format!("{}...", "a".repeat(57))); + } + + #[test] + fn test_truncate_display_exact_limit_unchanged() { + let s = "b".repeat(60); + assert_eq!(truncate_display(&s, 60), s); + } + + #[test] + fn test_truncate_display_three_byte_chars_no_panic() { + // Regression test for three-byte characters. + let s = format!("x{}", "\u{20ac}".repeat(40)); + assert!(s.len() > 60); // byte length exceeds the old byte-based check + assert_eq!(truncate_display(&s, 60), s); // 41 chars: no truncation + } + + #[test] + fn test_truncate_display_three_byte_chars_truncated() { + let s = format!("x{}", "\u{20ac}".repeat(80)); // 81 chars, 241 bytes + let out = truncate_display(&s, 60); + assert_eq!(out, format!("x{}...", "\u{20ac}".repeat(56))); + } + + #[test] + fn test_truncate_display_four_byte_chars_within_limit_unchanged() { + // Regression test for four-byte characters. + let s = "\u{1f680}".repeat(40); + assert_eq!(truncate_display(&s, 50), s); + } + + #[test] + fn test_truncate_display_four_byte_chars_truncated() { + let s = "\u{1f680}".repeat(80); + let out = truncate_display(&s, 50); + assert_eq!(out, format!("{}...", "\u{1f680}".repeat(47))); + } +} diff --git a/atomic-cli/src/commands/revise.rs b/atomic-cli/src/commands/revise.rs index 577fe467..e4bf8373 100644 --- a/atomic-cli/src/commands/revise.rs +++ b/atomic-cli/src/commands/revise.rs @@ -228,10 +228,6 @@ pub struct Revise { #[arg(long)] pub dry_run: bool, - /// Include all untracked files in the revision. - #[arg(short, long)] - pub all: bool, - /// Specific files to include in the revision. #[arg(last = true)] pub files: Vec, @@ -247,7 +243,6 @@ impl Revise { no_edit: false, author: None, dry_run: false, - all: false, files: Vec::new(), } } diff --git a/atomic-cli/src/commands/team/delete.rs b/atomic-cli/src/commands/team/delete.rs index c5521df2..3cb21528 100644 --- a/atomic-cli/src/commands/team/delete.rs +++ b/atomic-cli/src/commands/team/delete.rs @@ -85,8 +85,19 @@ impl Command for TeamDelete { impl TeamDelete { async fn execute(&self) -> CliResult<()> { - // Prompt for confirmation unless --force is set. + let client = build_client(self.org.as_deref(), None).await?; + let org_slug = client.org_slug().to_string(); + + // `--force` skips both the precheck and confirmation. if !self.force { + // Check that the team exists before prompting. + atomic_teams::team::get_team(&client, &org_slug, &self.slug) + .await + .map_err(|e| CliError::RemoteError { + message: e.to_string(), + url: None, + })?; + print_warning(&format!( "This will permanently delete team '{}' and all its memberships and grants.", self.slug @@ -105,9 +116,6 @@ impl TeamDelete { } } - let client = build_client(self.org.as_deref(), None).await?; - let org_slug = client.org_slug().to_string(); - atomic_teams::team::delete_team(&client, &org_slug, &self.slug) .await .map_err(|e| CliError::RemoteError { diff --git a/atomic-cli/src/commands/workspace/delete.rs b/atomic-cli/src/commands/workspace/delete.rs index 4e829fa4..41e91c59 100644 --- a/atomic-cli/src/commands/workspace/delete.rs +++ b/atomic-cli/src/commands/workspace/delete.rs @@ -71,8 +71,13 @@ impl Command for WorkspaceDelete { .map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?; rt.block_on(async { - // Confirm unless --force is set. + let (client, org_slug) = build_client_with_org(self.org.as_deref(), None).await?; + + // `--force` skips both the precheck and confirmation. if !self.force { + // Check that the workspace exists before prompting. + client.get_workspace(&self.slug).await.map_err(remote_err)?; + print_warning(&format!( "This will permanently delete workspace '{}' and all its projects.", self.slug @@ -90,8 +95,6 @@ impl Command for WorkspaceDelete { } } - let (client, org_slug) = build_client_with_org(self.org.as_deref(), None).await?; - client .delete_workspace(&self.slug) .await diff --git a/atomic-cli/src/main.rs b/atomic-cli/src/main.rs index 88317857..72278400 100644 --- a/atomic-cli/src/main.rs +++ b/atomic-cli/src/main.rs @@ -908,3 +908,14 @@ fn main() { std::process::exit(err.exit_code()); } } + +#[cfg(test)] +mod cli_definition_tests { + use super::Cli; + use clap::CommandFactory; + + #[test] + fn clap_command_definition_is_valid() { + Cli::command().debug_assert(); + } +} diff --git a/atomic-cli/tests/cli_surface_integration_test.rs b/atomic-cli/tests/cli_surface_integration_test.rs new file mode 100644 index 00000000..927acf0a --- /dev/null +++ b/atomic-cli/tests/cli_surface_integration_test.rs @@ -0,0 +1,169 @@ +//! End-to-end smoke tests for every public Atomic CLI command. +//! +//! The test discovers subcommands from the binary's own Clap help output, then +//! recursively invokes `--help` for every discovered command path. This keeps +//! the test in sync as commands are added or removed and catches parser +//! conflicts that command-level unit tests do not exercise. + +use std::collections::{HashSet, VecDeque}; +use std::process::{Command, Output}; + +fn run_help(path: &[String]) -> Output { + Command::new(env!("CARGO_BIN_EXE_atomic")) + .args(path) + .arg("--no-color") + .arg("--help") + .output() + .unwrap_or_else(|error| { + panic!( + "failed to execute `atomic{} --help`: {error}", + display_path(path) + ) + }) +} + +fn display_path(path: &[String]) -> String { + if path.is_empty() { + String::new() + } else { + format!(" {}", path.join(" ")) + } +} + +/// Extract the first column from Clap's `Commands:` section. +/// +/// Command rows have exactly two leading spaces. Wrapped descriptions are +/// indented further, so they are ignored. +fn visible_subcommands(help: &str) -> Vec { + let mut in_commands = false; + let mut commands = Vec::new(); + + for raw_line in help.lines() { + let line = raw_line.trim_end_matches('\r'); + + if line == "Commands:" { + in_commands = true; + continue; + } + + if !in_commands { + continue; + } + + if line.is_empty() { + if !commands.is_empty() { + break; + } + continue; + } + + let Some(row) = line.strip_prefix(" ") else { + break; + }; + + if row.starts_with(char::is_whitespace) { + continue; + } + + let Some(name) = row.split_whitespace().next() else { + continue; + }; + + // Clap adds this standard dispatcher automatically. Its child paths + // duplicate the commands already traversed from their canonical path. + if name == "help" { + continue; + } + + commands.push(name.to_string()); + } + + commands +} + +#[test] +fn every_public_command_renders_help() { + let mut pending = VecDeque::from([Vec::::new()]); + let mut visited = HashSet::new(); + let mut leaf_count = 0usize; + + while let Some(path) = pending.pop_front() { + assert!( + visited.insert(path.clone()), + "CLI command tree contains a duplicate path: atomic{}", + display_path(&path) + ); + + let output = run_help(&path); + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + + assert!( + output.status.success(), + "`atomic{} --help` failed with {}\nstdout:\n{}\nstderr:\n{}", + display_path(&path), + output.status, + stdout, + stderr + ); + assert!( + stdout.contains("Usage:"), + "`atomic{} --help` did not render a Usage section\nstdout:\n{}\nstderr:\n{}", + display_path(&path), + stdout, + stderr + ); + + let children = visible_subcommands(&stdout); + if children.is_empty() { + leaf_count += 1; + } + + for child in children { + let mut child_path = path.clone(); + child_path.push(child); + pending.push_back(child_path); + } + } + + // These sentinels prove discovery descended through one-, two-, and + // three-level command families rather than only checking root help. + for expected in [ + ["agent", "enable"].as_slice(), + ["project", "delete"].as_slice(), + ["vault", "intent", "create"].as_slice(), + ] { + let expected = expected + .iter() + .map(|part| (*part).to_string()) + .collect::>(); + assert!( + visited.contains(&expected), + "CLI help discovery missed `atomic{}`", + display_path(&expected) + ); + } + + assert!(leaf_count > 0, "CLI help discovery found no leaf commands"); + eprintln!( + "validated help for {} public command paths ({} leaves)", + visited.len(), + leaf_count + ); +} + +#[test] +fn command_section_parser_ignores_wrapped_descriptions_and_help_dispatcher() { + let help = "\ +Commands: + alpha First command + with a wrapped description + beta Second command + help Print this message or the help of the given subcommand(s) + +Options: + -h, --help Print help +"; + + assert_eq!(visible_subcommands(help), ["alpha", "beta"]); +} diff --git a/docs/git-import-harness-plan.md b/docs/git-import-harness-plan.md index 136182b4..7790c9fb 100644 --- a/docs/git-import-harness-plan.md +++ b/docs/git-import-harness-plan.md @@ -62,19 +62,26 @@ The following git-specific helpers will be added to `helpers.sh`: ```bash # ── Git Helpers ───────────────────────────────────────────────────────────── +# Exit code recognized by run_all.sh as a suite-level skip. +HARNESS_SKIP_EXIT="${HARNESS_SKIP_EXIT:-77}" + +skip_suite() { + local reason="$1" + echo "${YELLOW}SKIPPING: $reason${RESET}" + exit "$HARNESS_SKIP_EXIT" +} + # Check if git is available require_git() { if ! command -v git &>/dev/null; then - echo "${YELLOW}SKIPPING: git not installed${RESET}" - exit 0 + skip_suite "git not installed" fi } # Check if network is available require_network() { if ! curl --silent --head --max-time 5 https://github.com &>/dev/null; then - echo "${YELLOW}SKIPPING: network unavailable${RESET}" - exit 0 + skip_suite "network unavailable" fi } @@ -86,9 +93,13 @@ clone_git_repo() { local ref="${2:-HEAD}" GIT_REPO_DIR="$(mktemp -d "${TMPDIR:-/tmp}/atomic-git-test-XXXXXX")" _HARNESS_TMPDIRS+=("$GIT_REPO_DIR") - git clone --quiet "$url" "$GIT_REPO_DIR" 2>/dev/null + if ! git clone --quiet "$url" "$GIT_REPO_DIR" 2>/dev/null; then + skip_suite "failed to clone git repo '$url'" + fi if [[ "$ref" != "HEAD" ]]; then - (cd "$GIT_REPO_DIR" && git checkout --quiet "$ref") + if ! (cd "$GIT_REPO_DIR" && git checkout --quiet "$ref"); then + skip_suite "failed to checkout ref '$ref' in git repo '$url'" + fi fi } @@ -668,7 +679,9 @@ git clone https://github.com/holman/spark.git git clone https://github.com/sharkdp/hyperfine.git ``` -Tests gracefully skip if network is unavailable using the `require_network` helper. +Tests gracefully skip if network is unavailable using the `require_network` +helper. The top-level runner reports exit code 77 as an explicitly skipped +suite rather than counting the missing prerequisite as a pass. --- diff --git a/tests/harness/09_semantic_diff_pairing.sh b/tests/harness/09_semantic_diff_pairing.sh index 0dce6437..b9d92c69 100644 --- a/tests/harness/09_semantic_diff_pairing.sh +++ b/tests/harness/09_semantic_diff_pairing.sh @@ -119,6 +119,18 @@ assert_paired_diff() { fi } +# Return only actual +/- change lines from Atomic's unified diff output. +# Context lines are intentionally rendered around changes and must not be +# mistaken for modified content. +# +# Filters out only the `+++ b/…` / `--- a/…` file headers. Requiring a +# non-+/- second character instead would drop real change lines whose +# content starts with '+' or '-' (rendered as `++…`/`--…`) and added or +# deleted blank lines (a bare `+` or `-`). +extract_atomic_change_lines() { + grep -E '^[+-]' | grep -vE '^\+\+\+ b/|^--- a/' || true +} + # ═══════════════════════════════════════════════════════════════════════════ begin_section "Pairing: Single modified line among additions" # ═══════════════════════════════════════════════════════════════════════════ @@ -299,6 +311,7 @@ record_change "Production config" >/dev/null 2>&1 HASH="$(get_last_change_hash)" DIFF_OUT="$(atomic diff --no-color -c "$HASH" 2>&1)" +CHANGE_LINES="$(printf '%s\n' "$DIFF_OUT" | extract_atomic_change_lines)" assert_paired_diff \ "Multi mod: HOST localhost→0.0.0.0 paired" \ @@ -322,12 +335,12 @@ assert_paired_diff \ assert_output_not_contains \ "Multi mod: unchanged DB_PORT not in diff" \ "DB_PORT = 5432" \ - echo "$DIFF_OUT" + echo "$CHANGE_LINES" assert_output_not_contains \ "Multi mod: unchanged DB_NAME not in diff" \ 'DB_NAME = "myapp"' \ - echo "$DIFF_OUT" + echo "$CHANGE_LINES" # ═══════════════════════════════════════════════════════════════════════════ begin_section "Pairing: Modification buried in large insertion block" @@ -562,6 +575,7 @@ record_change "Update even constants, add comments" >/dev/null 2>&1 HASH="$(get_last_change_hash)" DIFF_OUT="$(atomic diff --no-color -c "$HASH" 2>&1)" +CHANGE_LINES="$(printf '%s\n' "$DIFF_OUT" | extract_atomic_change_lines)" # Check that each modified line is paired PAIR_SUCCESS=0 @@ -604,14 +618,19 @@ else "Only $PAIR_SUCCESS/10 modifications paired ($PAIR_FAIL failed). Expected ≥8." fi -# Verify unchanged lines are NOT in the diff +# Verify unchanged lines are NOT among the +/- change lines. They may appear +# as legitimate context around a nearby modification. +UNCHANGED_FOUND=0 for i in 1 3 5 7 9; do - if echo "$DIFF_OUT" | grep -qF "VALUE_${i} = \"original_${i}\""; then + if echo "$CHANGE_LINES" | grep -qF "VALUE_${i} = \"original_${i}\""; then _fail "Scale: unchanged VALUE_${i} should not be in diff" \ "VALUE_${i} appeared in diff but was not modified" + UNCHANGED_FOUND=1 fi done -_pass "Scale: unchanged odd constants not in diff" +if [[ "$UNCHANGED_FOUND" -eq 0 ]]; then + _pass "Scale: unchanged odd constants not in diff" +fi # ═══════════════════════════════════════════════════════════════════════════ begin_section "Pairing: Mixed adds, deletes, and modifications" diff --git a/tests/harness/12_full_repo_diff_parity.sh b/tests/harness/12_full_repo_diff_parity.sh index 318e7523..7e0ec9af 100755 --- a/tests/harness/12_full_repo_diff_parity.sh +++ b/tests/harness/12_full_repo_diff_parity.sh @@ -191,11 +191,8 @@ WORK="$REPO_DIR" CLONE_DIR="$WORK/repo" # Clone -git clone --quiet "$REPO_URL" "$CLONE_DIR" 2>/dev/null -if [[ $? -ne 0 ]]; then - _skip "clone failed (no network?): $REPO_URL" - print_summary - exit 0 +if ! git clone --quiet "$REPO_URL" "$CLONE_DIR" 2>/dev/null; then + skip_suite "failed to clone $REPO_URL (network unavailable?)" fi _pass "cloned $REPO_URL" diff --git a/tests/harness/14_vault_kg.sh b/tests/harness/14_vault_kg.sh index db76d6e2..ff8f0d38 100755 --- a/tests/harness/14_vault_kg.sh +++ b/tests/harness/14_vault_kg.sh @@ -5,10 +5,16 @@ # 1. Vault initialization and default content # 2. Goal lifecycle (start, stop, resume) # 3. Intent lifecycle (create, update, link) -# 4. Memory storage and retrieval +# 4. Record + vault integration # 5. KG enrichment from VCS data -# 6. KG queries (search, neighbors) +# 6. Vault show and query # 7. Git import → KG enrichment → queries +# 8. Memory and materialize +# 9. Vault behavior in a repo initialized without --vault +# +# Every assertion checks both the exit code and the expected output shape. +# A branch that would pass regardless of the command's outcome is a bug in +# this suite, not a feature: the point of the harness is trustworthy greens. HARNESS_DIR="$(cd "$(dirname "$0")" && pwd)" source "$HARNESS_DIR/helpers.sh" @@ -18,12 +24,35 @@ echo "${BOLD}══════════════════════ echo "${BOLD} Suite: 14_vault_kg${RESET}" echo "${BOLD}══════════════════════════════════════════════════════════════${RESET}" -# ── Local helper ──────────────────────────────────────────────────────────── +# ── Local helpers ─────────────────────────────────────────────────────────── # Like require_network but returns true/false instead of exiting the script. _network_available() { curl --silent --head --max-time 5 https://github.com &>/dev/null } +# Run a command, capturing combined output and exit code into OUT/RC. +# The `|| RC=$?` guard keeps a failing command from aborting the suite +# under `set -e` — failures are asserted on, not fatal. +# Usage: run_cmd atomic vault list --json +run_cmd() { + RC=0 + OUT="$("$@" 2>&1)" || RC=$? +} + +# Assert the last run_cmd exited 0 AND its output matches an ERE pattern. +# Usage: assert_ran "desc" "pattern" +assert_ran() { + local desc="$1" + local pattern="$2" + if [[ $RC -ne 0 ]]; then + _fail "$desc" "exit $RC: $(echo "$OUT" | head -2 | tr '\n' ' ')" + elif ! echo "$OUT" | grep -qiE "$pattern"; then + _fail "$desc" "output missing /$pattern/: $(echo "$OUT" | head -2 | tr '\n' ' ')" + else + _pass "$desc" + fi +} + # ════════════════════════════════════════════════════════════════════════════ # Section 1: Vault Initialization # ════════════════════════════════════════════════════════════════════════════ @@ -47,12 +76,8 @@ assert_file_exists "code intelligence skill installed" ".vault/skills/code-intel assert_file_exists "memory index installed" ".vault/memory/MEMORY.md" # Vault list should show default entries -out="$(atomic vault list --json 2>/dev/null)" || true -if echo "$out" | grep -q "skills/atomic-vault.md"; then - _pass "vault list shows default skill" -else - _fail "vault list shows default skill" "output: $(echo "$out" | head -3)" -fi +run_cmd atomic vault list --json +assert_ran "vault list shows default skill" "skills/atomic-vault\.md" # ════════════════════════════════════════════════════════════════════════════ # Section 2: Goal Lifecycle @@ -64,40 +89,26 @@ make_temp_repo "vault-goals" init_repo --vault # Start a goal with a custom name -out="$(atomic vault goal start --name test-goal --developer "alice" 2>&1)" -if echo "$out" | grep -q "test-goal"; then - _pass "goal start succeeds with custom name" -else - _fail "goal start succeeds" "$out" -fi +run_cmd atomic vault goal start --name test-goal --developer "alice" +assert_ran "goal start succeeds with custom name" "Started goal: test-goal" # Goal should appear in list -out="$(atomic vault goal list --json 2>/dev/null)" || true -if echo "$out" | grep -q "test-goal"; then - _pass "goal appears in list" -else - _fail "goal appears in list" "$out" -fi +run_cmd atomic vault goal list --json +assert_ran "goal appears in list" "test-goal" # Goal file should exist on disk assert_file_exists "goal file materialized" ".vault/goals/test-goal/_goal.md" # Stop with promote -out="$(atomic vault goal stop --promote test-goal 2>&1)" -if echo "$out" | grep -qiE "completed|promoted|stopped"; then - _pass "goal stop --promote succeeds" -else - _pass "goal stop completes" # Accept any successful completion -fi +run_cmd atomic vault goal stop --promote test-goal +assert_ran "goal stop --promote succeeds" "Completed goal: test-goal" # Start another goal, then discard -atomic vault goal start --name discard-me >/dev/null 2>&1 -out="$(atomic vault goal stop --discard discard-me 2>&1)" -if echo "$out" | grep -qiE "discard"; then - _pass "goal stop --discard succeeds" -else - _pass "goal discard completes" -fi +run_cmd atomic vault goal start --name discard-me +assert_ran "second goal start succeeds" "Started goal: discard-me" + +run_cmd atomic vault goal stop --discard discard-me +assert_ran "goal stop --discard succeeds" "Discarded goal: discard-me" # ════════════════════════════════════════════════════════════════════════════ # Section 3: Intent Lifecycle @@ -108,70 +119,49 @@ begin_section "Vault: Intent Lifecycle" make_temp_repo "vault-intents" init_repo --vault -# Create an intent -out="$(atomic vault intent create --title "Fix authentication" --priority high 2>&1)" -if echo "$out" | grep -qE "[A-Za-z]+-[0-9]+"; then - _pass "intent create returns an ID" -else - # Accept any non-error output as success - if [[ $? -eq 0 ]] || [[ -n "$out" ]]; then - _pass "intent create succeeds" - else - _fail "intent create" "$out" - fi -fi +# Create an intent — must print the assigned ID +run_cmd atomic vault intent create --title "Fix authentication" --priority high +assert_ran "intent create returns an ID" "Created intent: [A-Za-z0-9-]+-[0-9]+" + +first_id="$(echo "$OUT" | sed -n 's/.*Created intent: \([A-Za-z0-9-]*\).*/\1/p' | head -1)" # List intents -out="$(atomic vault intent list --json 2>/dev/null)" || true -if echo "$out" | grep -qi "fix authentication"; then - _pass "intent appears in list with title" -else - _fail "intent appears in list" "output: $(echo "$out" | head -5)" -fi +run_cmd atomic vault intent list --json +assert_ran "intent appears in list with title" "fix authentication" # Create a second intent -atomic vault intent create --title "Add logging" >/dev/null 2>&1 +run_cmd atomic vault intent create --title "Add logging" +assert_ran "second intent create succeeds" "Created intent:" -out="$(atomic vault intent list --json 2>/dev/null)" || true -intent_count="$(echo "$out" | grep -c '"id"' || true)" -if [[ "$intent_count" -ge 2 ]]; then +run_cmd atomic vault intent list --json +intent_count="$(echo "$OUT" | grep -c '"id"' || true)" +if [[ $RC -eq 0 && "$intent_count" -ge 2 ]]; then _pass "multiple intents created (count: $intent_count)" else - _fail "multiple intents" "expected >= 2, got $intent_count" + _fail "multiple intents" "exit $RC, expected >= 2 ids, got $intent_count" fi -# Show a specific intent (grab the first ID from the list) -first_id="$(echo "$out" | grep -oE '"id"\s*:\s*"[^"]+"' | head -1 | sed 's/.*"id"\s*:\s*"\([^"]*\)".*/\1/')" || true +# Show the first intent by ID if [[ -n "$first_id" ]]; then - show_out="$(atomic vault intent show "$first_id" --json 2>/dev/null)" || true - if echo "$show_out" | grep -qi "fix authentication\|add logging"; then - _pass "intent show returns detail for $first_id" - else - _pass "intent show completes for $first_id" - fi -else - _skip "intent show" "could not extract intent ID from list" -fi + run_cmd atomic vault intent show "$first_id" --json + assert_ran "intent show returns detail for $first_id" "fix authentication" -# Update intent status -if [[ -n "$first_id" ]]; then - update_out="$(atomic vault intent update "$first_id" --status in-progress 2>&1)" || true - _pass "intent update status completes" + run_cmd atomic vault intent update "$first_id" --status in-progress + assert_ran "intent update sets status" "Updated intent: $first_id" else - _skip "intent update" "no intent ID available" + _fail "intent show" "could not extract intent ID from create output" + _fail "intent update" "could not extract intent ID from create output" fi -# Link intent to a goal -atomic vault goal start --name intent-goal >/dev/null 2>&1 || true +# Link intent to a goal (the goal must exist first) +run_cmd atomic vault goal start --name intent-goal +assert_ran "goal for linking created" "Started goal: intent-goal" + if [[ -n "$first_id" ]]; then - link_out="$(atomic vault intent link "$first_id" --goal intent-goal 2>&1)" || true - if echo "$link_out" | grep -qiE "link|goal|intent"; then - _pass "intent linked to goal" - else - _pass "intent link completes" - fi + run_cmd atomic vault intent link "$first_id" --goal intent-goal + assert_ran "intent linked to goal" "link|intent-goal" else - _skip "intent link" "no intent ID available" + _fail "intent link" "could not extract intent ID from create output" fi # ════════════════════════════════════════════════════════════════════════════ @@ -187,18 +177,19 @@ init_repo --vault create_file "src/main.rs" 'fn main() { println!("hello"); }' add_files "src/main.rs" -# Record should succeed (and auto-enrich KG) -record_change "Add main.rs" >/dev/null 2>&1 -_pass "record succeeds with vault enabled" - -# Verify KG was enriched -out="$(atomic vault query search "main" --json 2>/dev/null)" || true -if echo "$out" | grep -qi "main\|change"; then - _pass "KG search finds recorded content" +# Record should succeed (and auto-enrich the KG) +rc=0 +record_change "Add main.rs" >/dev/null 2>&1 || rc=$? +if [[ $rc -eq 0 ]]; then + _pass "record succeeds with vault enabled" else - _pass "KG search runs without error" + _fail "record succeeds with vault enabled" "exit $rc" fi +# Record auto-enriches: search must surface the recorded change or file +run_cmd atomic vault query search "main" --json +assert_ran "KG search finds recorded content" "change:|file:src/main\.rs" + # ════════════════════════════════════════════════════════════════════════════ # Section 5: KG Enrichment # ════════════════════════════════════════════════════════════════════════════ @@ -212,39 +203,23 @@ init_repo --vault create_file "src/auth.rs" "pub fn authenticate() { }\npub fn verify() { }" create_file "src/main.rs" "fn main() { authenticate(); }" add_files "src/auth.rs" "src/main.rs" -record_change "Add auth module" >/dev/null 2>&1 +record_change "Add auth module" >/dev/null 2>&1 || true -# Run explicit KG enrichment -out="$(atomic vault query enrich 2>&1)" -if echo "$out" | grep -qiE "enrich|views|files|changes|complete"; then - _pass "KG enrich from VCS data" -else - _pass "KG enrich completes" -fi +# Run explicit KG enrichment — reports what was enriched +run_cmd atomic vault query enrich +assert_ran "KG enrich from VCS data" "Enriched: .*views.*files.*changes" # Search for entities -out="$(atomic vault query search "auth" --json 2>/dev/null)" || true -if echo "$out" | grep -qi "auth"; then - _pass "KG search finds 'auth' content" -else - _pass "KG search completes without error" -fi +run_cmd atomic vault query search "auth" --json +assert_ran "KG search finds 'auth' content" "auth" -# Query neighbors of a view node -out="$(atomic vault query neighbors "view:dev" --json 2>/dev/null)" || true -if echo "$out" | grep -qi "view\|node\|edge"; then - _pass "KG neighbors query for view node" -else - _pass "KG neighbors query completes" -fi +# Query neighbors of a view node — returns a node/edge graph +run_cmd atomic vault query neighbors "view:dev" --json +assert_ran "KG neighbors query for view node" '"nodes"' # Reindex -out="$(atomic vault query reindex 2>&1)" -if echo "$out" | grep -qiE "index|reindex|complete"; then - _pass "KG reindex succeeds" -else - _pass "KG reindex completes" -fi +run_cmd atomic vault query reindex +assert_ran "KG reindex succeeds" "Indexed [0-9]+ nodes" # ════════════════════════════════════════════════════════════════════════════ # Section 6: Vault Show and Query @@ -254,24 +229,23 @@ begin_section "Vault: Show and Query" # Reuse vault-kg repo from Section 5 (still in REPO_DIR) -# Show a vault path -out="$(atomic vault show ".vault/skills/atomic-vault.md" --json 2>/dev/null)" || true -if echo "$out" | grep -qiE "skill\|vault\|content\|path"; then - _pass "vault show returns skill content" +# Show a vault entry (keys are vault-relative, without the .vault/ prefix) +run_cmd atomic vault show "skills/atomic-vault.md" --json +assert_ran "vault show returns skill content" "Atomic Vault" + +# Embed — the default hash-embed provider needs no external config +run_cmd atomic vault query embed +assert_ran "vault query embed runs the embedding provider" "Embedded [0-9]+ total chunks" + +# Ask requires an LLM API key: accept either a real answer (exit 0) or the +# explicit no-key error (non-zero) — anything else is a failure. +run_cmd atomic vault query ask "What files are in this repo?" --json +if [[ $RC -eq 0 ]]; then + _pass "vault query ask answers with API key configured" +elif echo "$OUT" | grep -qi "API key"; then + _pass "vault query ask fails cleanly without API key" else - _pass "vault show completes" -fi - -# Embed (may be a no-op without an embedding provider configured) -out="$(atomic vault query embed 2>&1)" || true -_pass "vault query embed completes" - -# Ask a question (may require LLM config — accept graceful error) -out="$(atomic vault query ask "What files are in this repo?" --json 2>/dev/null)" || true -if echo "$out" | grep -qiE "file\|answer\|result\|error\|not configured"; then - _pass "vault query ask returns response or config notice" -else - _pass "vault query ask completes" + _fail "vault query ask" "exit $RC: $(echo "$OUT" | head -2 | tr '\n' ' ')" fi # ════════════════════════════════════════════════════════════════════════════ @@ -280,7 +254,8 @@ fi begin_section "Vault: Git Import → KG" -# Skip if no network or no git +# Skip only this section (not the whole suite — earlier sections already ran) +# when git or the network is unavailable. if ! command -v git &>/dev/null; then _skip "git import KG tests" "git not installed" elif ! _network_available; then @@ -289,44 +264,42 @@ else make_temp_repo "vault-git-kg" echo " Cloning hashicorp/go-uuid..." - clone_git_repo "https://github.com/hashicorp/go-uuid.git" - cd "$GIT_REPO_DIR" - - # Import with vault - atomic init --vault >/dev/null 2>&1 || true - atomic git import >/dev/null 2>&1 || true - _pass "git import completes with vault" - - # Enrich KG from imported data - out="$(atomic vault query enrich 2>&1)" - if echo "$out" | grep -qiE "enrich|view|file|change|complete"; then - _pass "KG enrichment after git import" - else - _pass "KG enrichment completes" - fi - - # Search should find content from the imported repo - out="$(atomic vault query search "uuid" --json 2>/dev/null)" || true - if echo "$out" | grep -qi "uuid\|node"; then - _pass "KG search finds imported content" - else - _pass "KG search runs after import" - fi - - # Neighbors query after import - out="$(atomic vault query neighbors "view:main" --json 2>/dev/null)" || true - if echo "$out" | grep -qi "view\|node\|edge\|change"; then - _pass "KG neighbors query after import" - else - _pass "KG neighbors query runs after import" - fi - - # Reindex vault entries - out="$(atomic vault query reindex 2>&1)" - if echo "$out" | grep -qiE "index|complete"; then - _pass "vault reindex after import" + GIT_KG_DIR="$(mktemp -d "${TMPDIR:-/tmp}/atomic-git-kg-XXXXXX")" + _HARNESS_TMPDIRS+=("$GIT_KG_DIR") + if ! git clone --quiet "https://github.com/hashicorp/go-uuid.git" "$GIT_KG_DIR" 2>/dev/null; then + _skip "git import KG tests" "clone failed (transient network?)" else - _pass "reindex completes" + cd "$GIT_KG_DIR" + + run_cmd atomic init --vault + if [[ $RC -eq 0 ]]; then + _pass "init --vault in git checkout" + else + _fail "init --vault in git checkout" "exit $RC: $(echo "$OUT" | head -2 | tr '\n' ' ')" + fi + + run_cmd atomic git import + if [[ $RC -eq 0 ]]; then + _pass "git import completes with vault" + else + _fail "git import completes with vault" "exit $RC: $(echo "$OUT" | tail -2 | tr '\n' ' ')" + fi + + # Enrich KG from imported data + run_cmd atomic vault query enrich + assert_ran "KG enrichment after git import" "Enriched: .*views.*files.*changes" + + # Search should find content from the imported repo + run_cmd atomic vault query search "uuid" --json + assert_ran "KG search finds imported content" "uuid" + + # Neighbors query for the imported default view + run_cmd atomic vault query neighbors "view:main" --json + assert_ran "KG neighbors query after import" '"nodes"' + + # Reindex vault entries + run_cmd atomic vault query reindex + assert_ran "vault reindex after import" "Indexed [0-9]+ nodes" fi fi @@ -340,61 +313,39 @@ make_temp_repo "vault-memory" init_repo --vault # Memory list should show the default MEMORY.md -out="$(atomic vault memory list --json 2>/dev/null)" || true -if echo "$out" | grep -qi "MEMORY\|memory"; then - _pass "memory list shows default index" -else - _pass "memory list runs" -fi +run_cmd atomic vault memory list --json +assert_ran "memory list shows default index" "memory/MEMORY\.md" # Materialize all vault entries -out="$(atomic vault materialize 2>&1)" -if echo "$out" | grep -qiE "material|complete|written"; then - _pass "vault materialize all" -else - _pass "materialize completes" -fi +run_cmd atomic vault materialize +assert_ran "vault materialize all" "Materialized [0-9]+ vault entries" # Sync (deflate markdown → redb) -out="$(atomic vault sync 2>&1)" -if echo "$out" | grep -qiE "sync|up to date|complete"; then - _pass "vault sync (no changes)" -else - _pass "vault sync completes" -fi +run_cmd atomic vault sync +assert_ran "vault sync reports status" "Synced [0-9]+ vault files|up to date" # Materialize then sync round-trip — vault state should be stable -out2="$(atomic vault sync 2>&1)" -if echo "$out2" | grep -qiE "sync|up to date|complete|no changes"; then - _pass "vault sync idempotent after materialize" -else - _pass "second sync completes" -fi +run_cmd atomic vault sync +assert_ran "vault sync idempotent after materialize" "up to date" # ════════════════════════════════════════════════════════════════════════════ -# Section 9: Vault in Non-Vault Repo (Negative Tests) +# Section 9: Vault in a Repo Initialized Without --vault # ════════════════════════════════════════════════════════════════════════════ -begin_section "Vault: Negative Tests" +begin_section "Vault: Init Without --vault" make_temp_repo "vault-negative" init_repo # no --vault -# Vault commands should fail gracefully on a non-vault repo -out="$(atomic vault list --json 2>&1)" || true -if echo "$out" | grep -qiE "not.*vault\|no vault\|error\|not initialized"; then - _pass "vault list fails gracefully on non-vault repo" -else - # If it returned empty or succeeded with nothing, that's also acceptable - _pass "vault list on non-vault repo returns empty or error" -fi +# `atomic init` always provisions a minimal vault (memory index), so vault +# commands are expected to WORK here — pin that behavior rather than +# accepting anything. +run_cmd atomic vault list --json +assert_ran "vault list works after plain init" "memory/MEMORY\.md" -out="$(atomic vault goal list --json 2>&1)" || true -if echo "$out" | grep -qiE "not.*vault\|no vault\|error\|not initialized"; then - _pass "vault goal list fails gracefully on non-vault repo" -else - _pass "vault goal list on non-vault repo handled" -fi +# No goals were created, so the list is an empty JSON array +run_cmd atomic vault goal list --json +assert_ran "goal list is empty after plain init" '^\[\]$' # ════════════════════════════════════════════════════════════════════════════ # Summary diff --git a/tests/harness/15_storage_api.sh b/tests/harness/15_storage_api.sh index 0ed0fab1..ec1ffda8 100755 --- a/tests/harness/15_storage_api.sh +++ b/tests/harness/15_storage_api.sh @@ -79,11 +79,7 @@ check_server() { } if ! check_server; then - echo "" - echo "${YELLOW}SKIPPING: atomic-storage server not reachable at ${SERVER_URL}${RESET}" - echo "${YELLOW} Start the server first, or set ATOMIC_SERVER_URL to point to a running instance.${RESET}" - echo "" - exit 0 + skip_suite "atomic-storage server not reachable at ${SERVER_URL}; start it or set ATOMIC_SERVER_URL" fi echo "" diff --git a/tests/harness/helpers.sh b/tests/harness/helpers.sh index 7beb9121..0d4aaeb6 100755 --- a/tests/harness/helpers.sh +++ b/tests/harness/helpers.sh @@ -35,6 +35,10 @@ TESTS_FAILED=0 TESTS_SKIPPED=0 FAIL_MESSAGES=() +# Exit code used when an entire suite cannot run because a prerequisite is +# unavailable. The top-level runner recognizes 77 as SKIPPED, not PASSED. +HARNESS_SKIP_EXIT="${HARNESS_SKIP_EXIT:-77}" + # ── Binary discovery ──────────────────────────────────────────────────────── # Allow overriding via $ATOMIC_BIN; otherwise discover the best available binary. @@ -215,6 +219,20 @@ _skip() { echo " ${YELLOW}⊘${RESET} $name ${YELLOW}(skipped${reason:+: $reason})${RESET}" } +# Mark the entire suite as skipped and stop it immediately. +# If assertions have already failed, the suite FAILS instead — a skip must +# never mask earlier failures as "skipped" in the runner's summary. +# Usage: skip_suite "reason" +skip_suite() { + local reason="$1" + if [[ ${TESTS_FAILED:-0} -gt 0 ]]; then + echo "${RED}NOT skipping ($reason): $TESTS_FAILED assertion(s) already failed${RESET}" + exit 1 + fi + echo "${YELLOW}SKIPPING: $reason${RESET}" + exit "$HARNESS_SKIP_EXIT" +} + # Assert that the last command succeeded (exit 0). # Usage: assert_success "description" command args... assert_success() { @@ -465,16 +483,14 @@ assert_log_count() { # Check if git is available require_git() { if ! command -v git &>/dev/null; then - echo "${YELLOW}SKIPPING: git not installed${RESET}" - exit 0 + skip_suite "git not installed" fi } # Check if network is available (can reach github.com) require_network() { if ! curl --silent --head --max-time 5 https://github.com &>/dev/null; then - echo "${YELLOW}SKIPPING: network unavailable${RESET}" - exit 0 + skip_suite "network unavailable" fi } @@ -494,13 +510,11 @@ clone_git_repo() { GIT_REPO_DIR="$(mktemp -d "${TMPDIR:-/tmp}/atomic-git-test-XXXXXX")" _HARNESS_TMPDIRS+=("$GIT_REPO_DIR") if ! git clone --quiet "$url" "$GIT_REPO_DIR"; then - echo "${YELLOW}SKIPPING: failed to clone git repo '$url'${RESET}" - exit 0 + skip_suite "failed to clone git repo '$url'" fi if [[ "$ref" != "HEAD" ]]; then if ! (cd "$GIT_REPO_DIR" && git checkout --quiet "$ref"); then - echo "${YELLOW}SKIPPING: failed to checkout ref '$ref' in git repo '$url'${RESET}" - exit 0 + skip_suite "failed to checkout ref '$ref' in git repo '$url'" fi fi } diff --git a/tests/harness/run_all.sh b/tests/harness/run_all.sh index 04614677..5c0a04f5 100755 --- a/tests/harness/run_all.sh +++ b/tests/harness/run_all.sh @@ -17,6 +17,8 @@ set -euo pipefail HARNESS_DIR="$(cd "$(dirname "$0")" && pwd)" REPO_ROOT="$(cd "$HARNESS_DIR/../.." && pwd)" +HARNESS_SKIP_EXIT=77 +export HARNESS_SKIP_EXIT # ── Colours ───────────────────────────────────────────────────────────────── @@ -109,7 +111,9 @@ echo "" TOTAL_SUITES=0 PASSED_SUITES=0 +SKIPPED_SUITES=0 FAILED_SUITES=0 +SKIPPED_SUITE_NAMES=() FAILED_SUITE_NAMES=() TOTAL_TESTS=0 @@ -142,6 +146,10 @@ for suite in "${SELECTED_SUITES[@]}"; do if [[ $suite_exit -eq 0 ]]; then PASSED_SUITES=$((PASSED_SUITES + 1)) echo " ${GREEN}Suite PASSED${RESET}" + elif [[ $suite_exit -eq $HARNESS_SKIP_EXIT ]]; then + SKIPPED_SUITES=$((SKIPPED_SUITES + 1)) + SKIPPED_SUITE_NAMES+=("$suite_name") + echo " ${YELLOW}Suite SKIPPED${RESET}" else FAILED_SUITES=$((FAILED_SUITES + 1)) FAILED_SUITE_NAMES+=("$suite_name") @@ -164,9 +172,17 @@ echo "${BOLD}╔═════════════════════ echo "${BOLD}║ Combined Results ║${RESET}" echo "${BOLD}╠═══════════════════════════════════════════════════════════╣${RESET}" echo "${BOLD}║${RESET} ${BOLD}║${RESET}" -echo "${BOLD}║${RESET} Suites: ${GREEN}${PASSED_SUITES} passed${RESET} ${RED}${FAILED_SUITES} failed${RESET} / ${TOTAL_SUITES} total ${BOLD}║${RESET}" +echo "${BOLD}║${RESET} Suites: ${GREEN}${PASSED_SUITES} passed${RESET} ${YELLOW}${SKIPPED_SUITES} skipped${RESET} ${RED}${FAILED_SUITES} failed${RESET} / ${TOTAL_SUITES} total ${BOLD}║${RESET}" echo "${BOLD}║${RESET} ${BOLD}║${RESET}" +if [[ ${#SKIPPED_SUITE_NAMES[@]} -gt 0 ]]; then + echo "${BOLD}║${RESET} ${YELLOW}Skipped suites:${RESET} ${BOLD}║${RESET}" + for name in "${SKIPPED_SUITE_NAMES[@]}"; do + printf "${BOLD}║${RESET} ${YELLOW}• %-51s${RESET} ${BOLD}║${RESET}\n" "$name" + done + echo "${BOLD}║${RESET} ${BOLD}║${RESET}" +fi + if [[ ${#FAILED_SUITE_NAMES[@]} -gt 0 ]]; then echo "${BOLD}║${RESET} ${RED}Failed suites:${RESET} ${BOLD}║${RESET}" for name in "${FAILED_SUITE_NAMES[@]}"; do