diff --git a/atomic-cli/README.md b/atomic-cli/README.md index 6517fece..4eea14e0 100644 --- a/atomic-cli/README.md +++ b/atomic-cli/README.md @@ -772,8 +772,7 @@ atomic apply preview feature --to-stack main |--------|-------------| | `--to-stack ` | Target stack (default: current) | | `--from-stack ` | Source stack | -| `--deps` | Automatically apply dependencies (default: true) | -| `--allow-conflicts` | Proceed even if conflicts arise | +| `--allow-conflicts` | Proceed even if conflicts arise (not available for `pick`) | --- diff --git a/atomic-cli/src/commands/change/command.rs b/atomic-cli/src/commands/change/command.rs index 157b5087..402297a4 100644 --- a/atomic-cli/src/commands/change/command.rs +++ b/atomic-cli/src/commands/change/command.rs @@ -60,12 +60,6 @@ pub struct ChangeCmd { #[arg(long = "show-deps")] pub show_deps: bool, - /// Show graph_op details. - /// - /// When enabled, shows detailed information about each graph_op. - #[arg(long = "show-hunks")] - pub show_hunks: bool, - /// Show full hashes instead of abbreviated. #[arg(long = "full-hash")] pub full_hash: bool, @@ -94,7 +88,6 @@ impl ChangeCmd { view: None, format: ChangeFormat::Default, show_deps: false, - show_hunks: false, full_hash: false, show_attest: false, show_provenance: false, @@ -125,12 +118,6 @@ impl ChangeCmd { self } - /// Builder: set show-hunks flag. - pub fn with_show_hunks(mut self, show_hunks: bool) -> Self { - self.show_hunks = show_hunks; - self - } - /// Builder: set full-hash flag. pub fn with_full_hash(mut self, full_hash: bool) -> Self { self.full_hash = full_hash; diff --git a/atomic-cli/src/commands/change/mod.rs b/atomic-cli/src/commands/change/mod.rs index 8941d513..80e11632 100644 --- a/atomic-cli/src/commands/change/mod.rs +++ b/atomic-cli/src/commands/change/mod.rs @@ -17,7 +17,6 @@ //! --view View to use for sequence lookup (default: current) //! -f, --format Output format (default, short, json) //! --show-deps Show dependency details -//! --show-hunks Show graph_op details //! -h, --help Print help information //! ``` //! diff --git a/atomic-cli/src/commands/change/tests.rs b/atomic-cli/src/commands/change/tests.rs index e3184489..59ef44f1 100644 --- a/atomic-cli/src/commands/change/tests.rs +++ b/atomic-cli/src/commands/change/tests.rs @@ -199,7 +199,6 @@ mod tests { assert!(cmd.view.is_none()); assert_eq!(cmd.format, ChangeFormat::Default); assert!(!cmd.show_deps); - assert!(!cmd.show_hunks); assert!(!cmd.full_hash); } @@ -240,12 +239,6 @@ mod tests { assert!(cmd.show_deps); } - #[test] - fn test_change_cmd_with_show_hunks() { - let cmd = ChangeCmd::new().with_show_hunks(true); - assert!(cmd.show_hunks); - } - #[test] fn test_change_cmd_with_full_hash() { let cmd = ChangeCmd::new().with_full_hash(true); @@ -259,14 +252,12 @@ mod tests { .with_view("main") .with_format(ChangeFormat::Short) .with_show_deps(true) - .with_show_hunks(true) .with_full_hash(true); assert_eq!(cmd.identifier, Some("ABC123".to_string())); assert_eq!(cmd.view, Some("main".to_string())); assert_eq!(cmd.format, ChangeFormat::Short); assert!(cmd.show_deps); - assert!(cmd.show_hunks); assert!(cmd.full_hash); } @@ -644,20 +635,6 @@ mod tests { assert!(result.is_err()); } - #[test] - #[serial] - fn test_change_run_with_show_hunks() { - let _guard = TestGuard::new(); - - let _repo = Repository::init(".").unwrap(); - - let cmd = ChangeCmd::new().with_show_hunks(true); - let result = cmd.run(); - - // Will fail (no changes) but shouldn't panic - assert!(result.is_err()); - } - // Debug and Clone Tests #[test] diff --git a/atomic-cli/src/commands/diff/command.rs b/atomic-cli/src/commands/diff/command.rs index 531b207d..3932c71c 100644 --- a/atomic-cli/src/commands/diff/command.rs +++ b/atomic-cli/src/commands/diff/command.rs @@ -63,14 +63,6 @@ pub struct Diff { #[arg(long)] pub untracked: bool, - /// Show staged changes (reserved for future use). - #[arg(long, hide = true)] - pub cached: bool, - - /// View to compare against. - #[arg(long)] - pub view: Option, - /// Enable token-level diff highlighting (CRDT-powered). /// /// Shows exactly which tokens changed within a line, not just @@ -93,8 +85,6 @@ impl Diff { name_status: false, short: false, untracked: false, - cached: false, - view: None, word_diff: false, } } @@ -151,12 +141,6 @@ impl Diff { self } - /// Builder: set the view to compare against. - pub fn with_view(mut self, view: impl Into) -> Self { - self.view = Some(view.into()); - self - } - /// Builder: set the word-diff flag. pub fn with_word_diff(mut self, word_diff: bool) -> Self { self.word_diff = word_diff; diff --git a/atomic-cli/src/commands/diff/mod.rs b/atomic-cli/src/commands/diff/mod.rs index 36460e0f..ce2a149c 100644 --- a/atomic-cli/src/commands/diff/mod.rs +++ b/atomic-cli/src/commands/diff/mod.rs @@ -40,7 +40,6 @@ //! --stat Show diffstat summary only //! --no-color Disable colored output //! --word-diff Enable token-level diff highlighting -//! --cached Show staged changes (not yet implemented) //! --name-only Show only names of changed files //! --name-status Show names and status of changed files //! -h, --help Print help information diff --git a/atomic-cli/src/commands/diff/tests.rs b/atomic-cli/src/commands/diff/tests.rs index 5da10752..98e26190 100644 --- a/atomic-cli/src/commands/diff/tests.rs +++ b/atomic-cli/src/commands/diff/tests.rs @@ -596,8 +596,6 @@ mod tests { assert!(!diff.no_color); assert!(!diff.name_only); assert!(!diff.name_status); - assert!(!diff.cached); - assert!(diff.view.is_none()); } #[test] @@ -934,12 +932,6 @@ mod tests { assert!(diff.name_status); } - #[test] - fn test_diff_with_view() { - let diff = Diff::new().with_view("feature"); - assert_eq!(diff.view, Some("feature".to_string())); - } - #[test] fn test_diff_builder_chain() { let diff = Diff::new() diff --git a/atomic-cli/src/commands/identity/mod.rs b/atomic-cli/src/commands/identity/mod.rs index ba3110b2..d508065c 100644 --- a/atomic-cli/src/commands/identity/mod.rs +++ b/atomic-cli/src/commands/identity/mod.rs @@ -270,14 +270,17 @@ pub struct Default { #[arg(long, short = 'u')] pub usage: Option, - /// Clear the default identity instead of setting one. - #[arg(long, conflicts_with = "name")] + /// Clear the global default identity instead of setting one. + /// + /// Clearing a usage-specific default is not supported, so --clear + /// cannot be combined with --usage. + #[arg(long, conflicts_with_all = ["name", "usage"])] pub clear: bool, } impl Command for Default { fn run(&self) -> CliResult<()> { - use crate::output::{print_success, print_warning}; + use crate::output::print_success; use atomic_identity::{IdentityStore, IdentityUsage}; let mut store = IdentityStore::open_default().map_err(|e| { @@ -288,25 +291,11 @@ impl Command for Default { })?; if self.clear { - // Clear the default - if let Some(usage_str) = &self.usage { - let usage = IdentityUsage::parse(usage_str); - // Clear usage-specific default by setting global default - // Note: The store doesn't have a clear_default_for_usage method yet - // For now, we just inform the user - print_warning(&format!( - "Clearing default for usage '{}' is not yet supported", - usage - )); - } else { - store.clear_default().map_err(|e| { - crate::error::CliError::Internal(anyhow::anyhow!( - "Failed to clear default: {}", - e - )) - })?; - print_success("Cleared default identity"); - } + // Clear the global default (--clear conflicts with --usage in clap) + store.clear_default().map_err(|e| { + crate::error::CliError::Internal(anyhow::anyhow!("Failed to clear default: {}", e)) + })?; + print_success("Cleared default identity"); } else if let Some(name) = &self.name { // Load the identity by name let identity = store diff --git a/atomic-cli/src/commands/insert.rs b/atomic-cli/src/commands/insert.rs index ce2cf179..26ce4c48 100644 --- a/atomic-cli/src/commands/insert.rs +++ b/atomic-cli/src/commands/insert.rs @@ -41,10 +41,6 @@ pub struct Insert { #[arg(long)] view: Option, - /// Insert dependencies automatically. - #[arg(long, default_value = "true")] - deps: bool, - /// Allow conflicts during insert. #[arg(long)] allow_conflicts: bool, @@ -85,10 +81,6 @@ pub struct FromViewArgs { #[arg(long)] to_view: Option, - /// Insert dependencies automatically. - #[arg(long, default_value = "true")] - deps: bool, - /// Allow conflicts during insert. #[arg(long)] allow_conflicts: bool, @@ -113,10 +105,6 @@ pub struct TagArgs { #[arg(long)] to_view: Option, - /// Insert dependencies automatically. - #[arg(long, default_value = "true")] - deps: bool, - /// Allow conflicts during insert. #[arg(long)] allow_conflicts: bool, @@ -136,14 +124,6 @@ pub struct PickArgs { /// Target view to insert changes into (default: current view). #[arg(long)] to_view: Option, - - /// Insert dependencies automatically. - #[arg(long, default_value = "true")] - deps: bool, - - /// Allow conflicts during insert. - #[arg(long)] - allow_conflicts: bool, } /// Arguments for previewing what would be inserted. @@ -196,7 +176,7 @@ fn run_single_insert(repo: &Repository, change_str: &str, args: &Insert) -> CliR let is_current_view = args.view.is_none() || args.view.as_deref() == Some(repo.current_view()); let options = InsertOptions::default() - .apply_deps(args.deps) + .apply_deps(true) .allow_conflict(args.allow_conflicts); let options = if let Some(ref view) = args.view { @@ -207,14 +187,11 @@ fn run_single_insert(repo: &Repository, change_str: &str, args: &Insert) -> CliR output::print_info(&format!("Inserting change {}...", format_hash(&hash, true))); - let outcome = if args.deps { - repo.insert_change_rec(&hash, options) - } else { - repo.insert_change(&hash, options) - } - .map_err(|e| CliError::Conflict { - description: e.to_string(), - })?; + let outcome = repo + .insert_change_rec(&hash, options) + .map_err(|e| CliError::Conflict { + description: e.to_string(), + })?; print_insert_outcome( &outcome.stats.applied_hashes, @@ -250,7 +227,7 @@ fn run_from_view(repo: &Repository, args: &FromViewArgs) -> CliResult<()> { )); let options = CrossViewInsertOptions::new(&args.from_view, &to_view) - .with_dependencies(args.deps) + .with_dependencies(true) .allow_conflicts(args.allow_conflicts) .dry_run(args.dry_run); @@ -323,7 +300,7 @@ fn run_tag(repo: &Repository, args: &TagArgs) -> CliResult<()> { let options = CrossViewInsertOptions::new(&from_view, &to_view) .up_to_tag(&args.tag_name) - .with_dependencies(args.deps) + .with_dependencies(true) .allow_conflicts(args.allow_conflicts) .dry_run(args.dry_run); @@ -587,7 +564,6 @@ mod tests { let _ = InsertSubcommand::FromView(FromViewArgs { from_view: "feature".to_string(), to_view: Some("main".to_string()), - deps: true, allow_conflicts: false, dry_run: false, }); @@ -596,7 +572,6 @@ mod tests { tag_name: "v1.0.0".to_string(), from_view: Some("feature".to_string()), to_view: Some("main".to_string()), - deps: true, allow_conflicts: false, dry_run: false, }); @@ -604,8 +579,6 @@ mod tests { let _ = InsertSubcommand::Pick(PickArgs { changes: vec!["abc123".to_string()], to_view: None, - deps: true, - allow_conflicts: false, }); let _ = InsertSubcommand::Preview(PreviewArgs { @@ -620,14 +593,12 @@ mod tests { let args = FromViewArgs { from_view: "feature".to_string(), to_view: None, - deps: true, allow_conflicts: false, dry_run: false, }; assert_eq!(args.from_view, "feature"); assert!(args.to_view.is_none()); - assert!(args.deps); assert!(!args.allow_conflicts); assert!(!args.dry_run); } @@ -638,7 +609,6 @@ mod tests { tag_name: "v1.0.0".to_string(), from_view: Some("feature".to_string()), to_view: Some("main".to_string()), - deps: false, allow_conflicts: true, dry_run: true, }; @@ -646,7 +616,6 @@ mod tests { assert_eq!(args.tag_name, "v1.0.0"); assert_eq!(args.from_view, Some("feature".to_string())); assert_eq!(args.to_view, Some("main".to_string())); - assert!(!args.deps); assert!(args.allow_conflicts); assert!(args.dry_run); } @@ -660,8 +629,6 @@ mod tests { "ghi789".to_string(), ], to_view: Some("main".to_string()), - deps: true, - allow_conflicts: false, }; assert_eq!(args.changes.len(), 3); diff --git a/atomic-cli/src/commands/intent/mod.rs b/atomic-cli/src/commands/intent/mod.rs index a0ddfa58..4179c704 100644 --- a/atomic-cli/src/commands/intent/mod.rs +++ b/atomic-cli/src/commands/intent/mod.rs @@ -1,11 +1,17 @@ //! `atomic intent` — the canonical "record the why" engine surface. //! //! This is a NEW top-level command, a sibling of `atomic vault` (see -//! [`crate::commands::vault`]). It is distinct from the existing vault-scoped -//! `atomic vault intent ...` tree ([`crate::commands::vault::intent`]): that -//! tree manages the raw vault entries (create/list/show/update/delete/link), -//! while this one drives the `atomic-canonical` engine — lifting a stored intent -//! into a canonical JSON-LD node, gating it, attesting it, and rendering it. +//! [`crate::commands::vault`]). It is distinct from the vault-scoped +//! `atomic vault intent ...` tree, which still ships and is marked +//! DEPRECATED: that tree manages the raw vault entries +//! (create/list/show/update/delete/link), while this one drives the +//! `atomic-canonical` engine — lifting a stored intent into a canonical +//! JSON-LD node, gating it, attesting it, and rendering it. +//! +//! The two are not yet output-compatible (`atomic intent list --json` omits +//! titles, `atomic intent new` has no `--priority`/`--json`), so the +//! deprecated tree cannot be removed until a migration lands that also +//! updates the vault skills embedded in `vault_defaults.rs`. //! //! # Verbs //! diff --git a/atomic-cli/src/commands/intent/show.rs b/atomic-cli/src/commands/intent/show.rs index cc220879..a41df42a 100644 --- a/atomic-cli/src/commands/intent/show.rs +++ b/atomic-cli/src/commands/intent/show.rs @@ -11,7 +11,7 @@ use crate::error::{CliError, CliResult}; /// Show an intent as a rendered read-time projection. /// -/// Distinct from [`crate::commands::vault::intent::IntentShow`], which dumps the +/// Distinct from the deprecated `atomic vault intent show`, which dumps the /// raw stored body. This projects the lifted canonical node. #[derive(Parser, Debug)] #[command(name = "show")] diff --git a/atomic-cli/src/commands/log/command.rs b/atomic-cli/src/commands/log/command.rs index 7c64a05c..72db5b41 100644 --- a/atomic-cli/src/commands/log/command.rs +++ b/atomic-cli/src/commands/log/command.rs @@ -51,13 +51,6 @@ pub struct Log { #[arg(long = "tags-only")] pub tags_only: bool, - /// Filter to changes affecting a specific path. - /// - /// Shows only changes that modified the given file or directory. - /// Note: This requires loading change content for filtering. - #[arg(long = "path", value_name = "PATH")] - pub path: Option, - /// Output format. /// /// Controls how changes are displayed: @@ -116,7 +109,6 @@ impl Log { count: None, view: None, tags_only: false, - path: None, format: LogFormat::Default, reverse: false, from: None, @@ -143,12 +135,6 @@ impl Log { self } - /// Builder: set path filter. - pub fn with_path(mut self, path: impl Into) -> Self { - self.path = Some(path.into()); - self - } - /// Builder: set the output format. pub fn with_format(mut self, format: LogFormat) -> Self { self.format = format; @@ -517,18 +503,6 @@ impl Command for Log { return Ok(()); } - // Filter by path if specified (requires loading change content) - // Note: Path filtering is a placeholder - full implementation would - // require inspecting each change's hunks for the affected paths - if let Some(ref _path) = self.path { - // Path filtering would be implemented here - // For now, we show a warning and continue with unfiltered results - eprintln!( - "{}", - warning("Note: Path filtering is not yet fully implemented") - ); - } - // Draft views now filter inherited changes by default (the // repository layer compares against ancestor VIEW_CHANGES). // Use `--all` to see the full log including inherited entries. diff --git a/atomic-cli/src/commands/log/mod.rs b/atomic-cli/src/commands/log/mod.rs index 9b80009e..57178c34 100644 --- a/atomic-cli/src/commands/log/mod.rs +++ b/atomic-cli/src/commands/log/mod.rs @@ -14,7 +14,6 @@ //! --all Show all views' history //! --view Show history for specific view //! --tags-only Only show tagged changes -//! --path Show only changes affecting this path //! -f, --format Output format (default, short, oneline, json) //! --reverse Show in reverse order (oldest first) //! --from Start from sequence number diff --git a/atomic-cli/src/commands/log/tests.rs b/atomic-cli/src/commands/log/tests.rs index d71a2bfa..5393982b 100644 --- a/atomic-cli/src/commands/log/tests.rs +++ b/atomic-cli/src/commands/log/tests.rs @@ -186,7 +186,6 @@ mod tests { assert!(log.count.is_none()); assert!(log.view.is_none()); assert!(!log.tags_only); - assert!(log.path.is_none()); assert_eq!(log.format, LogFormat::Default); assert!(!log.reverse); assert!(log.from.is_none()); @@ -224,12 +223,6 @@ mod tests { assert!(log.tags_only); } - #[test] - fn test_log_with_path() { - let log = Log::new().with_path("src/lib.rs"); - assert_eq!(log.path, Some("src/lib.rs".to_string())); - } - #[test] fn test_log_with_format() { let log = Log::new().with_format(LogFormat::Oneline); @@ -260,7 +253,6 @@ mod tests { .with_count(20) .with_view("release") .with_tags_only(true) - .with_path("docs/") .with_format(LogFormat::Json) .with_reverse(true) .with_from(50) @@ -269,7 +261,6 @@ mod tests { assert_eq!(log.count, Some(20)); assert_eq!(log.view, Some("release".to_string())); assert!(log.tags_only); - assert_eq!(log.path, Some("docs/".to_string())); assert_eq!(log.format, LogFormat::Json); assert!(log.reverse); assert_eq!(log.from, Some(50)); diff --git a/atomic-cli/src/commands/memory/new.rs b/atomic-cli/src/commands/memory/new.rs index edc5f135..cf2a49f4 100644 --- a/atomic-cli/src/commands/memory/new.rs +++ b/atomic-cli/src/commands/memory/new.rs @@ -105,6 +105,19 @@ impl Command for MemoryNew { let id = self.id.clone().unwrap_or_else(generate_ulid_lowercased); let vault_path = bridge::normalize_memory_path(&id); + // Do not overwrite a memory or invalidate its attestation. + if repo + .vault_retrieve(&vault_path) + .map_err(CliError::Repository)? + .is_some() + { + return Err(CliError::InvalidArgument { + message: format!( + "memory '{id}' already exists at .vault/{vault_path}; choose a different --id" + ), + }); + } + // Build the frontmatter SPINE as FLAT SCALAR/array fields only (so it // survives yaml_frontmatter_to_json round-trip). Do NOT write // attributedTo/proof/contentHash — attest fills those. createdAt is @@ -304,4 +317,61 @@ mod tests { assert_eq!(node.derived_from[0], "urn:atomic:intent:demo-1"); assert!(node.text.contains("health-check timeout")); } + + #[test] + #[serial_test::serial] + fn test_new_refuses_duplicate_id() { + struct DirGuard { + original: std::path::PathBuf, + } + impl DirGuard { + fn new() -> Self { + Self { + original: std::env::current_dir() + .unwrap_or_else(|_| std::path::PathBuf::from("/")), + } + } + } + impl Drop for DirGuard { + fn drop(&mut self) { + let _ = std::env::set_current_dir(&self.original); + } + } + + let _guard = DirGuard::new(); + let dir = tempdir().unwrap(); + { + let repo = Repository::init(dir.path()).unwrap(); + repo.init_vault().unwrap(); + } + std::env::set_current_dir(dir.path()).unwrap(); + + let first = MemoryNew { + kind: "constraint".into(), + about: vec![], + derived_from: vec![], + text: Some("original fact".into()), + id: Some("dup01".into()), + status: "active".into(), + }; + first.run().expect("first create succeeds"); + + let overwrite = MemoryNew { + kind: "preference".into(), + about: vec![], + derived_from: vec![], + text: Some("REPLACED".into()), + id: Some("dup01".into()), + status: "active".into(), + }; + let err = overwrite.run().expect_err("duplicate id must be rejected"); + assert!( + err.to_string().contains("already exists"), + "unexpected error: {err}" + ); + + let on_disk = std::fs::read_to_string(dir.path().join(".vault/memory/dup01.md")).unwrap(); + assert!(on_disk.contains("original fact")); + assert!(!on_disk.contains("REPLACED")); + } } diff --git a/atomic-cli/src/commands/mv.rs b/atomic-cli/src/commands/mv.rs index a403b995..d0ba480e 100644 --- a/atomic-cli/src/commands/mv.rs +++ b/atomic-cli/src/commands/mv.rs @@ -15,7 +15,6 @@ //! //! Options: //! -n, --dry-run Show what would be moved without doing it -//! -f, --force Force move even if destination exists //! -h, --help Print help information //! ``` //! @@ -75,7 +74,6 @@ use crate::output::{print_hint, print_success, print_warning}; /// # Options /// /// - `--dry-run` / `-n`: Preview what would be moved -/// - `--force` / `-f`: Force move even if destination exists (overwrite tracking) #[derive(Parser, Debug, Clone)] #[command(name = "move")] #[derive(Default)] @@ -98,14 +96,6 @@ pub struct Move { /// modify the repository or filesystem. #[arg(short = 'n', long = "dry-run")] pub dry_run: bool, - - /// Force move even if destination tracking exists. - /// - /// This will overwrite the destination's tracking entry if it exists. - /// The destination file on disk is NOT overwritten unless you explicitly - /// remove it first. - #[arg(short = 'f', long = "force")] - pub force: bool, } impl Move { @@ -115,7 +105,6 @@ impl Move { source: source.into(), destination: destination.into(), dry_run: false, - force: false, } } @@ -125,12 +114,6 @@ impl Move { self } - /// Builder: set the force flag. - pub fn with_force(mut self, force: bool) -> Self { - self.force = force; - self - } - /// Normalize a path relative to the repository root. fn normalize_path(&self, repo_root: &Path, path: &str) -> CliResult { let p = Path::new(path); @@ -217,17 +200,30 @@ impl Command for Move { return Err(CliError::FileNotFound { path: source_path }); } - // Check if destination is already tracked (unless force) - if !self.force - && repo - .is_tracked(&destination) - .map_err(CliError::Repository)? + // The repository cannot move onto an already tracked path. + if repo + .is_tracked(&destination) + .map_err(CliError::Repository)? { return Err(CliError::FileAlreadyTracked { path: PathBuf::from(&destination), }); } + // `rename` overwrites existing files, so reject any destination entry. + // `symlink_metadata` also detects dangling symlinks. + let destination_disk = repo_root.join(&destination); + if std::fs::symlink_metadata(&destination_disk).is_ok() + && !is_same_file(&source_path, &destination_disk) + { + return Err(CliError::InvalidArgument { + message: format!( + "destination '{}' already exists on disk; move it away or choose another name", + destination + ), + }); + } + // Dry run mode if self.dry_run { println!("Would move: {} → {}", source, destination); @@ -272,6 +268,19 @@ impl Command for Move { } } +/// Returns true when both paths resolve to the same entry. +/// +/// This allows case-only renames. Errors return false so moves fail safely. +fn is_same_file(source: &Path, destination: &Path) -> bool { + match ( + std::fs::canonicalize(source), + std::fs::canonicalize(destination), + ) { + (Ok(source), Ok(destination)) => source == destination, + _ => false, + } +} + // Tests #[cfg(test)] @@ -286,7 +295,6 @@ mod tests { assert_eq!(cmd.source, "old.rs"); assert_eq!(cmd.destination, "new.rs"); assert!(!cmd.dry_run); - assert!(!cmd.force); } #[test] @@ -295,7 +303,6 @@ mod tests { assert!(cmd.source.is_empty()); assert!(cmd.destination.is_empty()); assert!(!cmd.dry_run); - assert!(!cmd.force); } #[test] @@ -304,22 +311,13 @@ mod tests { assert!(cmd.dry_run); } - #[test] - fn test_move_with_force() { - let cmd = Move::new("old.rs", "new.rs").with_force(true); - assert!(cmd.force); - } - #[test] fn test_move_builder_chain() { - let cmd = Move::new("src/old.rs", "src/new.rs") - .with_dry_run(true) - .with_force(true); + let cmd = Move::new("src/old.rs", "src/new.rs").with_dry_run(true); assert_eq!(cmd.source, "src/old.rs"); assert_eq!(cmd.destination, "src/new.rs"); assert!(cmd.dry_run); - assert!(cmd.force); } // Path Resolution Tests @@ -370,15 +368,12 @@ mod tests { #[test] fn test_move_clone() { - let cmd = Move::new("old.rs", "new.rs") - .with_dry_run(true) - .with_force(true); + let cmd = Move::new("old.rs", "new.rs").with_dry_run(true); let cloned = cmd.clone(); assert_eq!(cloned.source, cmd.source); assert_eq!(cloned.destination, cmd.destination); assert_eq!(cloned.dry_run, cmd.dry_run); - assert_eq!(cloned.force, cmd.force); } // Normalize Path Tests @@ -409,4 +404,142 @@ mod tests { let result = cmd.normalize_path(temp.path(), "/completely/different/path.rs"); assert!(result.is_err()); } + + // Run-level Data-Safety Tests + + struct DirGuard { + original: PathBuf, + } + + impl DirGuard { + fn new() -> Self { + Self { + original: std::env::current_dir().unwrap_or_else(|_| PathBuf::from("/")), + } + } + } + + impl Drop for DirGuard { + fn drop(&mut self) { + let _ = std::env::set_current_dir(&self.original); + } + } + + fn init_repo_with_tracked(files: &[(&str, &str)]) -> tempfile::TempDir { + let temp = tempfile::tempdir().unwrap(); + { + let _repo = atomic_repository::Repository::init(temp.path()).unwrap(); + } + for (name, content) in files { + std::fs::write(temp.path().join(name), content).unwrap(); + } + std::env::set_current_dir(temp.path()).unwrap(); + let add = crate::commands::add::Add::new() + .with_files(files.iter().map(|(n, _)| n.to_string()).collect::>()); + add.run().unwrap(); + temp + } + + #[test] + #[serial_test::serial] + fn test_move_refuses_existing_untracked_destination() { + let _guard = DirGuard::new(); + let temp = init_repo_with_tracked(&[("src.txt", "SOURCE")]); + std::fs::write(temp.path().join("dest.txt"), "PRECIOUS-UNTRACKED").unwrap(); + + let result = Move::new("src.txt", "dest.txt").run(); + + assert!(result.is_err(), "move onto an existing file must fail"); + let dest = std::fs::read_to_string(temp.path().join("dest.txt")).unwrap(); + assert_eq!(dest, "PRECIOUS-UNTRACKED", "destination must be untouched"); + let src = std::fs::read_to_string(temp.path().join("src.txt")).unwrap(); + assert_eq!(src, "SOURCE", "source must still exist"); + } + + #[test] + #[serial_test::serial] + fn test_move_refuses_tracked_destination() { + let _guard = DirGuard::new(); + let temp = init_repo_with_tracked(&[("a.txt", "A"), ("b.txt", "TRACKED-B")]); + + let result = Move::new("a.txt", "b.txt").run(); + + assert!(result.is_err(), "move onto a tracked file must fail"); + assert_eq!( + std::fs::read_to_string(temp.path().join("b.txt")).unwrap(), + "TRACKED-B" + ); + assert_eq!( + std::fs::read_to_string(temp.path().join("a.txt")).unwrap(), + "A" + ); + } + + #[test] + #[serial_test::serial] + fn test_move_into_existing_directory_works() { + let _guard = DirGuard::new(); + let temp = init_repo_with_tracked(&[("file.txt", "CONTENT")]); + std::fs::create_dir(temp.path().join("sub")).unwrap(); + + let result = Move::new("file.txt", "sub").run(); + + assert!( + result.is_ok(), + "move into a directory failed: {:?}", + result.err() + ); + assert_eq!( + std::fs::read_to_string(temp.path().join("sub/file.txt")).unwrap(), + "CONTENT" + ); + assert!(!temp.path().join("file.txt").exists()); + } + + #[test] + #[serial_test::serial] + fn test_move_allows_case_only_rename() { + let _guard = DirGuard::new(); + let temp = init_repo_with_tracked(&[("File.txt", "CONTENT")]); + + // The destination is the source on case-insensitive filesystems. + let result = Move::new("File.txt", "file.txt").run(); + + assert!( + result.is_ok(), + "case-only rename must be allowed: {:?}", + result.err() + ); + assert_eq!( + std::fs::read_to_string(temp.path().join("file.txt")).unwrap(), + "CONTENT" + ); + } + + #[test] + #[serial_test::serial] + #[cfg(unix)] + fn test_move_refuses_dangling_symlink_destination() { + let _guard = DirGuard::new(); + let temp = init_repo_with_tracked(&[("src.txt", "SOURCE")]); + let dangling = temp.path().join("dangling.txt"); + std::os::unix::fs::symlink(temp.path().join("no-such-target"), &dangling).unwrap(); + + let result = Move::new("src.txt", "dangling.txt").run(); + + assert!( + result.is_err(), + "move onto a dangling symlink must fail — Path::exists() reports \ + false for it, which let rename destroy the link" + ); + assert!( + std::fs::symlink_metadata(&dangling).unwrap().is_symlink(), + "the symlink must survive" + ); + assert_eq!( + std::fs::read_to_string(temp.path().join("src.txt")).unwrap(), + "SOURCE", + "source must still exist" + ); + } } diff --git a/atomic-cli/src/commands/stash.rs b/atomic-cli/src/commands/stash.rs index 35bfe071..ff55e2aa 100644 --- a/atomic-cli/src/commands/stash.rs +++ b/atomic-cli/src/commands/stash.rs @@ -83,7 +83,7 @@ use atomic_repository::Repository; use crate::commands::{find_repository_root, format_timestamp_relative, Command}; use crate::error::{CliError, CliResult}; -use crate::output::{print_blank, print_hint, print_success, print_warning, view as style_view}; +use crate::output::{print_hint, print_success, print_warning, view as style_view}; // Constants @@ -113,10 +113,6 @@ pub struct Stash { #[arg(short, long, global = true)] pub message: Option, - /// Include untracked files in the stash. - #[arg(short = 'u', long, global = true)] - pub include_untracked: bool, - /// Keep the changes in the working copy after stashing. /// /// By default, stash restores the working copy to clean state. @@ -135,10 +131,6 @@ pub enum StashSubcommand { #[arg(short, long)] message: Option, - /// Include untracked files in the stash. - #[arg(short = 'u', long)] - include_untracked: bool, - /// Keep the changes in the working copy after stashing. #[arg(short, long)] keep: bool, @@ -172,10 +164,6 @@ pub enum StashSubcommand { /// Stash to show (e.g., "stash@{0}" or "0"). Defaults to most recent. #[arg(value_name = "STASH")] stash: Option, - - /// Show full diff output. - #[arg(short, long)] - patch: bool, }, /// Delete a stash without applying. @@ -244,7 +232,6 @@ impl Stash { Self { command: None, message: None, - include_untracked: false, keep: false, } } @@ -255,24 +242,12 @@ impl Stash { self } - /// Builder: set the include-untracked flag. - pub fn with_include_untracked(mut self, include: bool) -> Self { - self.include_untracked = include; - self - } - /// Builder: set the keep flag. pub fn with_keep(mut self, keep: bool) -> Self { self.keep = keep; self } - /// Builder: set the --all subcommand behavior (alias for include_untracked). - pub fn with_all(mut self, all: bool) -> Self { - self.include_untracked = all; - self - } - /// Builder: set the subcommand to apply with dependencies. pub fn with_dependencies(mut self, _deps: bool) -> Self { // Dependencies flag is handled at the subcommand level; @@ -389,10 +364,9 @@ impl Stash { &self, repo: &mut Repository, message: Option, - include_untracked: bool, keep: bool, ) -> CliResult<()> { - self.run_push(repo, message, include_untracked, keep) + self.run_push(repo, message, keep) } /// Execute stash push (save changes). @@ -400,7 +374,6 @@ impl Stash { &self, repo: &mut Repository, message: Option, - include_untracked: bool, keep: bool, ) -> CliResult<()> { // Check for uncommitted changes @@ -488,23 +461,6 @@ impl Stash { } } - if include_untracked || self.include_untracked { - for entry in status.untracked() { - let p = entry.path().to_string_lossy().to_string(); - let abs = repo.root().join(&p); - if abs.is_file() { - let rel_dir = stash_dir.join( - std::path::Path::new(&p) - .parent() - .unwrap_or(std::path::Path::new("")), - ); - let _ = std::fs::create_dir_all(&rel_dir); - let _ = std::fs::copy(&abs, stash_dir.join(&p)); - stashed_paths.push(p); - } - } - } - // Write a manifest so we know which files were stashed let manifest_path = stash_dir.join("MANIFEST"); let manifest_content = stashed_paths.join("\n"); @@ -632,7 +588,7 @@ impl Stash { } /// Execute stash show. - fn run_show(&self, repo: &Repository, stash_ref: Option<&str>, patch: bool) -> CliResult<()> { + fn run_show(&self, repo: &Repository, stash_ref: Option<&str>) -> CliResult<()> { let stash = self.parse_stash_ref(repo, stash_ref)?; println!("{}", stash.reference()); @@ -650,12 +606,6 @@ impl Stash { println!(" Changes: {}", info.change_count); - if patch { - // TODO: Implement full diff output - print_blank(); - print_hint("Full diff output not yet implemented"); - } - Ok(()) } @@ -730,19 +680,15 @@ impl Command for Stash { match &self.command { None => { // Default action: push - self.run_push(&mut repo, None, self.include_untracked, self.keep) + self.run_push(&mut repo, None, self.keep) + } + Some(StashSubcommand::Push { message, keep }) => { + self.run_push(&mut repo, message.clone(), *keep) } - Some(StashSubcommand::Push { - message, - include_untracked, - keep, - }) => self.run_push(&mut repo, message.clone(), *include_untracked, *keep), Some(StashSubcommand::Pop { stash }) => self.run_pop(&mut repo, stash.as_deref()), Some(StashSubcommand::Apply { stash }) => self.run_apply(&mut repo, stash.as_deref()), Some(StashSubcommand::List) => self.run_list(&repo), - Some(StashSubcommand::Show { stash, patch }) => { - self.run_show(&repo, stash.as_deref(), *patch) - } + Some(StashSubcommand::Show { stash }) => self.run_show(&repo, stash.as_deref()), Some(StashSubcommand::Drop { stash }) => self.run_drop(&mut repo, stash.as_deref()), Some(StashSubcommand::Clear { force }) => self.run_clear(&mut repo, *force), } @@ -762,7 +708,6 @@ mod tests { let cmd = Stash::new(); assert!(cmd.command.is_none()); assert!(cmd.message.is_none()); - assert!(!cmd.include_untracked); assert!(!cmd.keep); } @@ -779,12 +724,6 @@ mod tests { assert_eq!(cmd.message, Some("WIP auth".to_string())); } - #[test] - fn test_stash_with_include_untracked() { - let cmd = Stash::new().with_include_untracked(true); - assert!(cmd.include_untracked); - } - #[test] fn test_stash_with_keep() { let cmd = Stash::new().with_keep(true); @@ -793,13 +732,9 @@ mod tests { #[test] fn test_stash_builder_chain() { - let cmd = Stash::new() - .with_message("test") - .with_include_untracked(true) - .with_keep(true); + let cmd = Stash::new().with_message("test").with_keep(true); assert_eq!(cmd.message, Some("test".to_string())); - assert!(cmd.include_untracked); assert!(cmd.keep); } @@ -863,14 +798,11 @@ mod tests { #[test] fn test_stash_clone() { - let cmd = Stash::new() - .with_message("test") - .with_include_untracked(true); + let cmd = Stash::new().with_message("test"); let cloned = cmd.clone(); assert_eq!(cloned.message, cmd.message); - assert_eq!(cloned.include_untracked, cmd.include_untracked); assert_eq!(cloned.keep, cmd.keep); } @@ -880,18 +812,12 @@ mod tests { fn test_subcommand_push() { let subcmd = StashSubcommand::Push { message: Some("test".to_string()), - include_untracked: true, keep: false, }; match subcmd { - StashSubcommand::Push { - message, - include_untracked, - keep, - } => { + StashSubcommand::Push { message, keep } => { assert_eq!(message, Some("test".to_string())); - assert!(include_untracked); assert!(!keep); } _ => panic!("Expected Push"), diff --git a/atomic-cli/src/commands/tag/create.rs b/atomic-cli/src/commands/tag/create.rs index b26e5a4b..3e4fcfe7 100644 --- a/atomic-cli/src/commands/tag/create.rs +++ b/atomic-cli/src/commands/tag/create.rs @@ -14,8 +14,6 @@ //! //! Options: //! -m, --message Message for an annotated tag -//! -a, --author Author for an annotated tag (format: "Name ") -//! -s, --view View to tag (default: current view) //! -f, --force Overwrite existing tag //! -h, --help Print help information //! ``` @@ -45,35 +43,6 @@ use crate::output::{emphasis, print_success}; #[cfg(test)] use std::path::PathBuf; -// Author Parsing - -/// Parse an author string in the format `"Name "` or just `"Name"`. -/// -/// # Arguments -/// -/// * `s` - The author string to parse -/// -/// # Returns -/// -/// A tuple of (name, optional_email). -fn parse_author(s: &str) -> (String, Option) { - let s = s.trim(); - - // Try to match "Name " format - if let Some(start) = s.find('<') { - if let Some(end) = s.find('>') { - if start < end { - let name = s[..start].trim().to_string(); - let email = s[start + 1..end].trim().to_string(); - return (name, Some(email)); - } - } - } - - // Just a name - (s.to_string(), None) -} - // Create Command /// Create a new tag. @@ -96,19 +65,6 @@ pub struct Create { #[arg(long, short = 'm', value_name = "MESSAGE")] pub message: Option, - /// Author for an annotated tag. - /// - /// Format: `"Name "` or just `"Name"`. - /// If not provided, uses the default identity. - #[arg(long, short = 'a', value_name = "AUTHOR")] - pub author: Option, - - /// View to tag. - /// - /// If not provided, uses the current view. - #[arg(long, short = 's', value_name = "VIEW")] - pub view: Option, - /// Overwrite existing tag. /// /// If a tag with this name already exists, overwrite it. @@ -122,8 +78,6 @@ impl Create { Self { name: None, message: None, - author: None, - view: None, force: false, } } @@ -133,8 +87,6 @@ impl Create { Self { name: Some(name.into()), message: None, - author: None, - view: None, force: false, } } @@ -145,18 +97,6 @@ impl Create { self } - /// Builder: set the author. - pub fn with_author(mut self, author: impl Into) -> Self { - self.author = Some(author.into()); - self - } - - /// Builder: set the view. - pub fn with_view(mut self, view: impl Into) -> Self { - self.view = Some(view.into()); - self - } - /// Builder: set the force flag. pub fn with_force(mut self, force: bool) -> Self { self.force = force; @@ -235,38 +175,6 @@ mod tests { use super::*; use serial_test::serial; - // ------------------------------------------------------------------------- - // Author Parsing Tests - // ------------------------------------------------------------------------- - - #[test] - fn test_parse_author_with_email() { - let (name, email) = parse_author("Alice "); - assert_eq!(name, "Alice"); - assert_eq!(email, Some("alice@example.com".to_string())); - } - - #[test] - fn test_parse_author_without_email() { - let (name, email) = parse_author("Bob"); - assert_eq!(name, "Bob"); - assert_eq!(email, None); - } - - #[test] - fn test_parse_author_with_spaces() { - let (name, email) = parse_author(" Alice Smith "); - assert_eq!(name, "Alice Smith"); - assert_eq!(email, Some("alice@example.com".to_string())); - } - - #[test] - fn test_parse_author_empty_email() { - let (name, email) = parse_author("Alice <>"); - assert_eq!(name, "Alice"); - assert_eq!(email, Some("".to_string())); - } - // ------------------------------------------------------------------------- // Command Builder Tests // ------------------------------------------------------------------------- @@ -276,7 +184,6 @@ mod tests { let cmd = Create::with_name("v1.0.0"); assert_eq!(cmd.name, Some("v1.0.0".to_string())); assert!(cmd.message.is_none()); - assert!(cmd.author.is_none()); assert!(!cmd.force); } @@ -287,18 +194,6 @@ mod tests { assert_eq!(cmd.message, Some("Release 1.0".to_string())); } - #[test] - fn test_create_with_author() { - let cmd = Create::with_name("v1.0.0").with_author("Alice "); - assert_eq!(cmd.author, Some("Alice ".to_string())); - } - - #[test] - fn test_create_with_view() { - let cmd = Create::with_name("v1.0.0").with_view("release"); - assert_eq!(cmd.view, Some("release".to_string())); - } - #[test] fn test_create_with_force() { let cmd = Create::with_name("v1.0.0").with_force(true); @@ -310,8 +205,6 @@ mod tests { let cmd = Create::default(); assert!(cmd.name.is_none()); assert!(cmd.message.is_none()); - assert!(cmd.author.is_none()); - assert!(cmd.view.is_none()); assert!(!cmd.force); } @@ -404,9 +297,7 @@ mod tests { // Change to the repo directory std::env::set_current_dir(repo_path).unwrap(); - let cmd = Create::with_name("v1.0.0") - .with_message("Release version 1.0.0") - .with_author("Alice "); + let cmd = Create::with_name("v1.0.0").with_message("Release version 1.0.0"); let result = cmd.run(); assert!(result.is_ok()); diff --git a/atomic-cli/src/commands/tag/mod.rs b/atomic-cli/src/commands/tag/mod.rs index 9b8c3c5b..e82d1ad6 100644 --- a/atomic-cli/src/commands/tag/mod.rs +++ b/atomic-cli/src/commands/tag/mod.rs @@ -37,9 +37,6 @@ //! $ atomic tag create v1.0.0 -m "Release version 1.0.0" //! Created annotated tag: v1.0.0 //! -//! # Create a tag with author information -//! $ atomic tag create v1.0.0 -m "Release" --author "Alice " -//! Created annotated tag: v1.0.0 //! ``` //! //! ## Listing Tags diff --git a/atomic-cli/src/commands/unrecord.rs b/atomic-cli/src/commands/unrecord.rs index 42e0f691..e53732a5 100644 --- a/atomic-cli/src/commands/unrecord.rs +++ b/atomic-cli/src/commands/unrecord.rs @@ -1,17 +1,13 @@ //! The `unrecord` command for removing changes from a view. //! //! This module implements the `atomic unrecord` command, which removes -//! the most recent change (or a specific change) from the current view's -//! change log. The change itself is NOT deleted from the change store — +//! the most recent change from the current view's change log. The change itself is NOT deleted from the change store — //! it can be re-inserted later via `atomic insert`. //! //! # Usage //! //! ```text -//! atomic unrecord [OPTIONS] [CHANGE] -//! -//! Arguments: -//! [CHANGE] Hash or prefix of the change to unrecord (default: last change) +//! atomic unrecord [OPTIONS] //! //! Options: //! -n, --dry-run Preview what would be unrecorded @@ -26,12 +22,6 @@ //! Unrecorded: ABCDEF12 "Add feature file" //! ``` //! -//! Unrecord a specific change by hash prefix: -//! ```text -//! $ atomic unrecord ABCDEF -//! Unrecorded: ABCDEF12 "Add feature file" -//! ``` -//! //! Preview without actually unrecording: //! ```text //! $ atomic unrecord --dry-run @@ -68,13 +58,6 @@ use crate::output::{print_success, print_warning}; #[derive(Parser, Debug, Default)] #[command(name = "unrecord")] pub struct Unrecord { - /// Hash or prefix of the change to unrecord. - /// - /// If not specified, the most recent change on the current view - /// is unrecorded. Provide a hash prefix to unrecord a specific change. - #[arg(value_name = "CHANGE")] - pub change: Option, - /// Preview what would be unrecorded without doing it. #[arg(short = 'n', long = "dry-run")] pub dry_run: bool, @@ -96,27 +79,17 @@ impl Command for Unrecord { UnrecordOptions::new() }; - let outcome = if let Some(ref _prefix) = self.change { - // TODO: support unrecording a specific change by hash prefix - // once hash_from_prefix is available on the transaction trait. - return Err(CliError::InvalidArgument { - message: "Unrecording a specific change by hash is not yet supported. \ - Use `atomic unrecord` (no argument) to unrecord the last change." - .to_string(), - }); - } else { - // Unrecord the most recent change - repo.unrecord_last(options).map_err(|e| match e { - atomic_repository::RepositoryError::Unrecord(msg) - if msg.contains("empty") || msg.contains("Empty") => - { - CliError::InvalidArgument { - message: "View is empty — nothing to unrecord".to_string(), - } + // Unrecord the most recent change + let outcome = repo.unrecord_last(options).map_err(|e| match e { + atomic_repository::RepositoryError::Unrecord(msg) + if msg.contains("empty") || msg.contains("Empty") => + { + CliError::InvalidArgument { + message: "View is empty — nothing to unrecord".to_string(), } - other => CliError::Repository(other), - })? - }; + } + other => CliError::Repository(other), + })?; if outcome.was_dry_run { for hash in &outcome.unrecorded { @@ -139,7 +112,6 @@ mod tests { #[test] fn test_default() { let cmd = Unrecord::default(); - assert!(cmd.change.is_none()); assert!(!cmd.dry_run); } } diff --git a/atomic-cli/src/commands/vault/summaries.rs b/atomic-cli/src/commands/vault/summaries.rs index 2688ba56..325276ba 100644 --- a/atomic-cli/src/commands/vault/summaries.rs +++ b/atomic-cli/src/commands/vault/summaries.rs @@ -11,10 +11,11 @@ //! //! Options: //! --goal Goal name to get summaries for -//! --json Output as JSON (default for this command) //! -h, --help Print help information //! ``` //! +//! Output is always JSON. +//! //! # Examples //! //! ```text @@ -52,10 +53,6 @@ pub struct Summaries { /// are returned. #[arg(long)] pub goal: Option, - - /// Output as JSON (this is the default for summaries). - #[arg(long)] - pub json: bool, } impl Command for Summaries { diff --git a/atomic-cli/src/commands/view/switch.rs b/atomic-cli/src/commands/view/switch.rs index 925fff0d..a8a8f3df 100644 --- a/atomic-cli/src/commands/view/switch.rs +++ b/atomic-cli/src/commands/view/switch.rs @@ -134,7 +134,7 @@ impl Command for Switch { // Auto-stash: save changes before switching let stash_cmd = crate::commands::stash::Stash::new() .with_message(format!("Auto-stash before switching to {}", name)); - stash_cmd.run_push_on(&mut repo, None, false, false)?; + stash_cmd.run_push_on(&mut repo, None, false)?; } else { let dirty: Vec = status .entries() diff --git a/atomic-cli/src/main.rs b/atomic-cli/src/main.rs index 72278400..47e5c84b 100644 --- a/atomic-cli/src/main.rs +++ b/atomic-cli/src/main.rs @@ -693,7 +693,7 @@ enum Commands { /// atomic vault session start /// /// # Create an intent - /// atomic vault intent create --title "Fix auth" + /// atomic intent new "Fix auth" /// ``` Vault(Vault), diff --git a/tests/harness/06_tags_and_stash.sh b/tests/harness/06_tags_and_stash.sh index 0ae94538..8f8d2a86 100755 --- a/tests/harness/06_tags_and_stash.sh +++ b/tests/harness/06_tags_and_stash.sh @@ -554,8 +554,12 @@ else fi # ═══════════════════════════════════════════════════════════════════════════ -begin_section "Stash: Stash with new untracked files (--include-untracked)" +begin_section "Stash: Untracked files are left in place" # ═══════════════════════════════════════════════════════════════════════════ +# +# The --include-untracked flag was removed: it copied untracked files into +# the stash sidecar but never cleaned them from the working copy, while +# still printing "clean". Untracked files now simply stay untouched. make_temp_repo "stash-untracked" init_repo @@ -568,20 +572,19 @@ record_change "base" >/dev/null 2>&1 || true create_file "newfile.txt" "I am new" overwrite_file "tracked.txt" "modified tracked" -# Stash with --include-untracked -stash_iu="$(atomic stash push --include-untracked 2>&1)" -if echo "$stash_iu" | grep -qiE "saved|stash"; then - _pass "stash with --include-untracked succeeds" -else - _pass "stash with --include-untracked completed" -fi +# The removed flag must stay removed +assert_failure "stash rejects removed --include-untracked flag" \ + atomic stash push --include-untracked -# tracked.txt should be restored +# Plain stash: tracked change saved, untracked file left alone +assert_success "stash saves tracked changes" atomic stash push assert_file_content "tracked.txt restored" "tracked.txt" "tracked" +assert_file_exists "untracked file left in working copy" "newfile.txt" # Pop and verify atomic stash pop >/dev/null 2>&1 || true assert_file_content "tracked.txt modified after pop" "tracked.txt" "modified tracked" +assert_file_content "untracked file untouched by pop" "newfile.txt" "I am new" # ═══════════════════════════════════════════════════════════════════════════ begin_section "Stash: Stash with custom message" diff --git a/tests/harness/14_vault_kg.sh b/tests/harness/14_vault_kg.sh index ff8f0d38..4744ebe0 100755 --- a/tests/harness/14_vault_kg.sh +++ b/tests/harness/14_vault_kg.sh @@ -120,20 +120,20 @@ make_temp_repo "vault-intents" init_repo --vault # 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]+" +run_cmd atomic intent new "Fix authentication" +assert_ran "intent new 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 -run_cmd atomic vault intent list --json -assert_ran "intent appears in list with title" "fix authentication" +# List intents — canonical list JSON carries id/status, not the title +run_cmd atomic intent list --json +assert_ran "intent appears in list by ID" "\"id\": \"$first_id\"" # Create a second intent -run_cmd atomic vault intent create --title "Add logging" -assert_ran "second intent create succeeds" "Created intent:" +run_cmd atomic intent new "Add logging" +assert_ran "second intent new succeeds" "Created intent:" -run_cmd atomic vault intent list --json +run_cmd atomic 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)" @@ -143,10 +143,10 @@ fi # Show the first intent by ID if [[ -n "$first_id" ]]; then - run_cmd atomic vault intent show "$first_id" --json + run_cmd atomic intent show "$first_id" --json assert_ran "intent show returns detail for $first_id" "fix authentication" - run_cmd atomic vault intent update "$first_id" --status in-progress + run_cmd atomic intent update "$first_id" --status in-progress assert_ran "intent update sets status" "Updated intent: $first_id" else _fail "intent show" "could not extract intent ID from create output" @@ -158,12 +158,38 @@ run_cmd atomic vault goal start --name intent-goal assert_ran "goal for linking created" "Started goal: intent-goal" if [[ -n "$first_id" ]]; then - run_cmd atomic vault intent link "$first_id" --goal intent-goal + run_cmd atomic intent link --goal intent-goal "$first_id" assert_ran "intent linked to goal" "link|intent-goal" else _fail "intent link" "could not extract intent ID from create output" fi +# The deprecated vault intent family remains a supported compatibility path +# while embedded skills still invoke it. Keep one end-to-end lifecycle test so +# future cleanup cannot silently break that path before the migration finishes. +run_cmd atomic vault intent create --title "Legacy compatibility" +assert_ran "deprecated vault intent create remains functional" "Created intent: [A-Za-z0-9-]+-[0-9]+" + +legacy_id="$(echo "$OUT" | sed -n 's/.*Created intent: \([A-Za-z0-9-]*\).*/\1/p' | head -1)" + +run_cmd atomic vault intent list --json +assert_ran "deprecated vault intent list remains functional" "legacy compatibility" + +if [[ -n "$legacy_id" ]]; then + run_cmd atomic vault intent show "$legacy_id" --json + assert_ran "deprecated vault intent show remains functional" "legacy compatibility" + + run_cmd atomic vault intent update "$legacy_id" --status in-progress + assert_ran "deprecated vault intent update remains functional" "Updated intent: $legacy_id" + + run_cmd atomic vault intent link "$legacy_id" --goal intent-goal + assert_ran "deprecated vault intent link remains functional" "Linked goal 'intent-goal'" +else + _fail "deprecated vault intent show" "could not extract intent ID from create output" + _fail "deprecated vault intent update" "could not extract intent ID from create output" + _fail "deprecated vault intent link" "could not extract intent ID from create output" +fi + # ════════════════════════════════════════════════════════════════════════════ # Section 4: Record + Vault Integration # ════════════════════════════════════════════════════════════════════════════ diff --git a/tests/harness/16_vault_pull_bootstrap.sh b/tests/harness/16_vault_pull_bootstrap.sh index 9c31bd69..5fead859 100755 --- a/tests/harness/16_vault_pull_bootstrap.sh +++ b/tests/harness/16_vault_pull_bootstrap.sh @@ -132,11 +132,11 @@ else fi # Creating an intent should work -out="$(atomic vault intent create --title "User B task" 2>&1)" || true +out="$(atomic intent new "User B task" 2>&1)" || true if echo "$out" | grep -qE "[A-Za-z]+-[0-9]+|Created"; then - _pass "User B: intent create works after bootstrap" + _pass "User B: intent new works after bootstrap" else - _fail "User B: intent create" "$out" + _fail "User B: intent new" "$out" fi # ════════════════════════════════════════════════════════════════════════════ @@ -158,9 +158,8 @@ switch_view "agent-session-1" >/dev/null 2>&1 # intents/manual///intent.md # With an agent session it would be: # intents////intent.md -out="$(atomic vault intent create --title "Draft intent 1" --json 2>&1)" || true -intent_file_1="$(echo "$out" | grep -o '"intent_file"[[:space:]]*:[[:space:]]*"[^"]*"' \ - | sed 's/.*"intent_file"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')" || true +out="$(atomic intent new "Draft intent 1" 2>&1)" || true +intent_file_1="$(echo "$out" | sed -n 's/.*file: \(.*intent\.md\).*/\1/p' | head -1)" || true # The path should be scoped (either under view name or manual/) if echo "$intent_file_1" | grep -qE "intents/(agent-session-1|manual)/"; then @@ -197,9 +196,8 @@ new_view "agent-session-2" --draft --parent dev >/dev/null 2>&1 || \ switch_view "agent-session-2" >/dev/null 2>&1 # Create an intent on the second view -out2="$(atomic vault intent create --title "Draft intent 2" --json 2>&1)" || true -intent_file_2="$(echo "$out2" | grep -o '"intent_file"[[:space:]]*:[[:space:]]*"[^"]*"' \ - | sed 's/.*"intent_file"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')" || true +out2="$(atomic intent new "Draft intent 2" 2>&1)" || true +intent_file_2="$(echo "$out2" | sed -n 's/.*file: \(.*intent\.md\).*/\1/p' | head -1)" || true # The two intent files should be different paths. # Without agent sessions, both land in manual// but with @@ -222,11 +220,11 @@ fi # Each view should only see its own intents switch_view "agent-session-1" >/dev/null 2>&1 -list1="$(atomic vault intent list --json 2>/dev/null)" || true +list1="$(atomic intent list --json 2>/dev/null)" || true count1="$(echo "$list1" | grep -c '"id"' || true)" switch_view "agent-session-2" >/dev/null 2>&1 -list2="$(atomic vault intent list --json 2>/dev/null)" || true +list2="$(atomic intent list --json 2>/dev/null)" || true count2="$(echo "$list2" | grep -c '"id"' || true)" # Note: the manifest is shared (local redb), so both intents may appear. @@ -246,7 +244,7 @@ first_id="$(echo "$list1" | grep -oE '"id"\s*:\s*"[^"]+"' | head -1 \ if [[ -n "$first_id" ]]; then # Show should work - show_out="$(atomic vault intent show "$first_id" --json 2>/dev/null)" || true + show_out="$(atomic intent show "$first_id" --json 2>/dev/null)" || true if echo "$show_out" | grep -qi "draft intent"; then _pass "Intent show works on view-scoped path" else @@ -254,7 +252,7 @@ if [[ -n "$first_id" ]]; then fi # Update should work - update_out="$(atomic vault intent update "$first_id" --status in-progress 2>&1)" || true + update_out="$(atomic intent update "$first_id" --status in-progress 2>&1)" || true if echo "$update_out" | grep -qiE "updated|in-progress"; then _pass "Intent update works on view-scoped path" else