use assert_fs::TempDir; #[cfg(feature = "test-utils")] use jj_cz::{Body, BreakingChange, CommitType, Description, MockJjExecutor, MockPrompts, Scope}; use jj_cz::{CommitWorkflow, Error, JjLib}; #[cfg(feature = "test-utils")] #[tokio::test] async fn test_happy_path_integration() { // T037: Happy path integration test let mock_executor = MockJjExecutor::new(); let mock_prompts = MockPrompts::new() .with_commit_type(CommitType::Feat) .with_scope(Scope::empty()) .with_description(Description::parse("add new feature").unwrap()) .with_breaking_change(BreakingChange::No) .with_body(Body::default()) .with_confirm(true); let workflow = CommitWorkflow::with_prompts(mock_executor, mock_prompts); let result = workflow.run_for_revset("@").await; assert!( result.is_ok(), "Workflow should complete successfully: {:?}", result ); } #[tokio::test] async fn test_not_in_repo() { // T038: Not-in-repo integration test - with_working_dir itself returns the error let temp_dir = TempDir::new().unwrap(); let result = JjLib::with_working_dir(temp_dir.path()).await; assert!(matches!(result, Err(Error::NotARepository))); } #[cfg(feature = "test-utils")] #[tokio::test] async fn test_cancellation() { // T039: Cancellation integration test // This is tricky to test directly without a TTY // We'll test the error handling path instead // Create a mock executor that simulates cancellation struct CancelMock; #[async_trait::async_trait(?Send)] impl jj_cz::JjExecutor for CancelMock { async fn is_repository(&self) -> Result { Ok(true) } async fn describe(&self, _revset: &str, _message: &str) -> Result<(), Error> { Err(Error::Cancelled) } async fn get_description(&self, _revset: &str) -> Result { Ok(String::new()) } } let executor = CancelMock; let mock_prompts = MockPrompts::new() .with_commit_type(CommitType::Feat) .with_scope(Scope::empty()) .with_description(Description::parse("test").unwrap()) .with_breaking_change(BreakingChange::No) .with_body(Body::default()) .with_confirm(true); let workflow = CommitWorkflow::with_prompts(executor, mock_prompts); let result = workflow.run_for_revset("@").await; // Should fail with Cancelled error assert!(matches!(result, Err(Error::Cancelled))); }