Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Add integration tests for config and state commands (#219)

Maximilian Roosaae2b6574c6a
diff --git a/tests/integration_tests/config_init.rs b/tests/integration_tests/config_init.rs
index af8746590..987b88628 100644
--- a/tests/integration_tests/config_init.rs
+++ b/tests/integration_tests/config_init.rs
@@ -1,4 +1,7 @@
-use crate::common::{set_temp_home_env, setup_home_snapshot_settings, temp_home, wt_command};
+use crate::common::{
+ TestRepo, make_snapshot_cmd, repo, set_temp_home_env, setup_home_snapshot_settings,
+ setup_snapshot_settings, temp_home, wt_command,
+};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
use std::fs;
@@ -65,3 +68,60 @@ fn test_config_init_creates_file(temp_home: TempDir) {
let config_path = global_config_dir.join("config.toml");
assert!(config_path.exists(), "Config file should be created");
}
+
+/// Test `wt config create --project` creates project config file
+#[rstest]
+fn test_config_create_project_creates_file(repo: TestRepo) {
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "config", &["create", "--project"], None);
+ assert_cmd_snapshot!(cmd, @r"
+ success: true
+ exit_code: 0
+ ----- stdout -----
+
+ ----- stderr -----
+ βœ… Created project config: [REPO]/.config/wt.toml
+
+ πŸ’‘ Edit this file to configure hooks for this repository
+ πŸ’‘ See https://worktrunk.dev/hooks/ for hook documentation
+ ");
+ });
+
+ // Verify file was actually created
+ let config_path = repo.root_path().join(".config/wt.toml");
+ assert!(
+ config_path.exists(),
+ "Project config file should be created"
+ );
+}
+
+/// Test `wt config create --project` when project config already exists
+#[rstest]
+fn test_config_create_project_already_exists(repo: TestRepo) {
+ // Create project config file
+ let config_dir = repo.root_path().join(".config");
+ fs::create_dir_all(&config_dir).unwrap();
+ fs::write(
+ config_dir.join("wt.toml"),
+ r#"[[project.post-create]]
+run = "echo hello"
+"#,
+ )
+ .unwrap();
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "config", &["create", "--project"], None);
+ assert_cmd_snapshot!(cmd, @r"
+ success: true
+ exit_code: 0
+ ----- stdout -----
+
+ ----- stderr -----
+ βšͺ Project config already exists: [REPO]/.config/wt.toml
+
+ πŸ’‘ Use wt config show to view, or wt config create --help for format reference
+ ");
+ });
+}
diff --git a/tests/integration_tests/config_state.rs b/tests/integration_tests/config_state.rs
index af8aeac2f..b8cf3d527 100644
--- a/tests/integration_tests/config_state.rs
+++ b/tests/integration_tests/config_state.rs
@@ -413,6 +413,30 @@ fn test_state_get_logs_empty(repo: TestRepo) {
assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No logs");
}
+#[rstest]
+fn test_state_get_logs_with_files(repo: TestRepo) {
+ // Create wt-logs directory with some log files
+ let git_dir = repo.root_path().join(".git");
+ let log_dir = git_dir.join("wt-logs");
+ std::fs::create_dir_all(&log_dir).unwrap();
+ std::fs::write(
+ log_dir.join("feature-post-start-npm.log"),
+ "npm output here",
+ )
+ .unwrap();
+ std::fs::write(log_dir.join("bugfix-remove.log"), "remove output").unwrap();
+
+ let output = wt_state_cmd(&repo, "logs", "get", &[]).output().unwrap();
+ assert!(output.status.success());
+ // Verify we get a table with file info
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(stderr.contains("File"));
+ assert!(stderr.contains("Size"));
+ assert!(stderr.contains("Age"));
+ assert!(stderr.contains("feature-post-start-npm.log"));
+ assert!(stderr.contains("bugfix-remove.log"));
+}
+
#[rstest]
fn test_state_clear_logs_empty(repo: TestRepo) {
let output = wt_state_cmd(&repo, "logs", "clear", &[]).output().unwrap();