Skip to content

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

test(hooks): exercise the pre-create alias direction post-revert (#2877)

Maximilian Roos9131aa6644eb
diff --git a/src/cli/hook.rs b/src/cli/hook.rs
index 500a4bb48..d115bd393 100644
--- a/src/cli/hook.rs
+++ b/src/cli/hook.rs
@@ -459,12 +459,22 @@ mod tests {
#[test]
fn test_parse_hook_type_aliases() {
- // `pre-start`/`post-start` are deprecated aliases for
- // `pre-create`/`post-create`.
- let opts = parse(&["pre-start"]).unwrap();
- assert_eq!(opts.hook_type, HookType::PreCreate);
- let opts = parse(&["post-start"]).unwrap();
- assert_eq!(opts.hook_type, HookType::PostCreate);
+ // `pre-create`/`post-create` are deprecated aliases for the canonical
+ // `pre-start`/`post-start`; both forms parse to the same `HookType`.
+ for name in ["pre-start", "pre-create"] {
+ assert_eq!(
+ parse(&[name]).unwrap().hook_type,
+ HookType::PreCreate,
+ "{name}"
+ );
+ }
+ for name in ["post-start", "post-create"] {
+ assert_eq!(
+ parse(&[name]).unwrap().hook_type,
+ HookType::PostCreate,
+ "{name}"
+ );
+ }
}
#[test]
diff --git a/src/commands/hook_commands.rs b/src/commands/hook_commands.rs
index 1ed70bdd5..453e32baa 100644
--- a/src/commands/hook_commands.rs
+++ b/src/commands/hook_commands.rs
@@ -382,7 +382,7 @@ pub fn handle_hook_show(
let project_id = repo.project_identifier().ok();
// Parse hook type filter if provided. clap's value parser already
- // validated the string (canonical name or deprecated `-start` alias);
+ // validated the string (canonical name or deprecated `-create` alias);
// `parse_hook_type` maps both to the canonical `HookType`.
let filter: Option<HookType> = hook_type_filter
.map(crate::cli::parse_hook_type)
diff --git a/src/config/deprecation.rs b/src/config/deprecation.rs
index 4ad33c7bc..fb726adaa 100644
--- a/src/config/deprecation.rs
+++ b/src/config/deprecation.rs
@@ -475,10 +475,6 @@ pub struct Deprecations {
pub approved_commands: bool,
/// Has `[select]` section (moved to `[switch.picker]`)
pub select: bool,
- /// Reserved for future hook-name deprecation tracking; always false.
- pub pre_start: bool,
- /// Reserved for future hook-name deprecation tracking; always false.
- pub post_start: bool,
/// Has `[ci]` section (moved to `[forge]`)
pub ci_section: bool,
/// Has `no-ff` in `[merge]` section (use `ff` instead)
@@ -498,8 +494,6 @@ impl Deprecations {
&& self.commit_gen.is_empty()
&& !self.approved_commands
&& !self.select
- && !self.pre_start
- && !self.post_start
&& !self.ci_section
&& !self.no_ff
&& !self.no_cd
@@ -533,8 +527,6 @@ fn detect_deprecations_from_doc(
commit_gen: find_commit_generation_from_doc(doc),
approved_commands: find_approved_commands_from_doc(doc),
select: find_select_from_doc(doc),
- pre_start: false,
- post_start: false,
ci_section: find_ci_section_from_doc(doc),
no_ff: find_negated_bool_from_doc(doc, "merge", "no-ff", "ff"),
no_cd: find_negated_bool_from_doc(doc, "switch", "no-cd", "cd"),
@@ -1569,7 +1561,7 @@ pub fn check_and_migrate(
// For non-config-show commands, emit per-kind warnings but skip the diff.
// The diff is reserved for `wt config show`, where the user has opted into details.
//
- // Some deprecations migrate silently (e.g. the `-start` → `-create` hook
+ // Some deprecations migrate silently (e.g. the `-create` → `-start` hook
// rename): `format_deprecation_warnings` emits nothing for them. The hint is
// gated on the warning text being non-empty so a silently-migrated config
// produces no stray "run wt config show" line with nothing above it.
@@ -3453,8 +3445,6 @@ approved-commands = ["npm install"]
commit_gen: CommitGenerationDeprecations::default(),
approved_commands: true,
select: false,
- pre_start: false,
- post_start: false,
ci_section: false,
no_ff: false,
no_cd: false,
@@ -3855,8 +3845,6 @@ pager = "delta --paging=never"
commit_gen: CommitGenerationDeprecations::default(),
approved_commands: false,
select: true,
- pre_start: false,
- post_start: false,
ci_section: false,
no_ff: false,
no_cd: false,
@@ -3895,6 +3883,92 @@ pager = "delta --paging=never"
);
}
+ fn migrate_create_hooks(content: &str) -> String {
+ let Ok(mut doc) = content.parse::<toml_edit::DocumentMut>() else {
+ return content.to_string();
+ };
+ if migrate_create_hooks_doc(&mut doc) {
+ doc.to_string()
+ } else {
+ content.to_string()
+ }
+ }
+
+ /// `migrate_create_hooks_doc` renames the deprecated `pre-create`/`post-create`
+ /// keys to canonical `pre-start`/`post-start`, preserving the value shape
+ /// (string, `[table]`, `[[array-of-tables]]`) at both the top level and
+ /// inside `[projects."..."]`.
+ #[test]
+ fn test_migrate_create_hooks_renames_every_shape() {
+ let content = r#"pre-create = "npm install"
+
+[[post-create]]
+lint = "cargo clippy"
+
+[projects."my-project"]
+pre-create = "cargo build"
+
+[projects."my-project".post-create]
+server = "npm run dev"
+"#;
+ let result = migrate_create_hooks(content);
+ assert!(
+ !result.contains("pre-create") && !result.contains("post-create"),
+ "no deprecated key may remain; got:\n{result}"
+ );
+ assert!(
+ result.contains(r#"pre-start = "npm install""#),
+ "top-level string renamed; got:\n{result}"
+ );
+ assert!(
+ result.contains("[[post-start]]"),
+ "top-level array-of-tables renamed; got:\n{result}"
+ );
+ assert!(
+ result.contains(r#"pre-start = "cargo build""#),
+ "per-project string renamed; got:\n{result}"
+ );
+ assert!(
+ result.contains(r#"[projects."my-project".post-start]"#),
+ "per-project table renamed; got:\n{result}"
+ );
+ }
+
+ /// When the canonical `-start` key already exists, the migrator leaves the
+ /// deprecated `-create` key alone rather than clobbering the user's value.
+ #[test]
+ fn test_migrate_create_hooks_skips_when_start_exists() {
+ let content = r#"pre-create = "old"
+pre-start = "new"
+
+[projects."my-project"]
+post-create = "old"
+post-start = "new"
+"#;
+ assert_eq!(
+ migrate_create_hooks(content),
+ content,
+ "must not clobber an existing canonical key"
+ );
+ }
+
+ #[test]
+ fn test_migrate_create_hooks_invalid_toml() {
+ let content = "this is { not valid toml";
+ assert_eq!(migrate_create_hooks(content), content);
+ }
+
+ #[test]
+ fn snapshot_migrate_create_to_start() {
+ let content = r#"pre-create = "npm install"
+
+[post-create]
+server = "npm run dev"
+"#;
+ let migrated = compute_migrated_content(content);
+ insta::assert_snapshot!(migration_diff(content, &migrated));
+ }
+
fn migrate_switch_picker_timeout(content: &str) -> String {
let Ok(mut doc) = content.parse::<toml_edit::DocumentMut>() else {
return content.to_string();
@@ -4039,8 +4113,6 @@ pager = "delta"
commit_gen: CommitGenerationDeprecations::default(),
approved_commands: false,
select: false,
- pre_start: false,
- post_start: false,
ci_section: false,
no_ff: true,
no_cd: true,
diff --git a/src/config/snapshots/worktrunk__config__deprecation__tests__snapshot_migrate_create_to_start.snap b/src/config/snapshots/worktrunk__config__deprecation__tests__snapshot_migrate_create_to_start.snap
new file mode 100644
index 000000000..c2b416983
--- /dev/null
+++ b/src/config/snapshots/worktrunk__config__deprecation__tests__snapshot_migrate_create_to_start.snap
@@ -0,0 +1,10 @@
+---
+source: src/config/deprecation.rs
+expression: "migration_diff(content, &migrated)"
+---
+-pre-create = "npm install"
++pre-start = "npm install"
+
+-[post-create]
++[post-start]
+ server = "npm run dev"
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index 34ec72fef..172ae3ae1 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -362,33 +362,34 @@ my-lint = "my-lint-tool"
);
}
-/// A current-worktree `.config/wt.toml` that still uses the deprecated
-/// `pre-start`/`post-start` hook keys keeps working through `wt hook show`:
-/// `ProjectConfig::load` migrates the keys to `pre-start`/`post-start`
-/// before deserializing, the value parser accepts both the canonical type
-/// argument and the deprecated alias, and Phase 1 of the rename (issue #2838)
-/// migrates silently — no deprecation warning.
+/// A current-worktree `.config/wt.toml` that uses the deprecated
+/// `pre-create`/`post-create` hook keys keeps working through `wt hook show`:
+/// `ProjectConfig::load` migrates the keys to canonical `pre-start`/`post-start`
+/// before deserializing, and the type-argument value parser accepts both the
+/// canonical name and the deprecated alias. The rename is paused at Phase 1
+/// (issue #2838), so the migration is silent — no deprecation warning.
#[rstest]
-fn test_hook_show_accepts_deprecated_start_hooks(repo: TestRepo) {
+fn test_hook_show_accepts_deprecated_create_hooks(repo: TestRepo) {
// Single-token commands so the bash highlighter doesn't split them with
// ANSI codes (same shape as the deep-merge `hook show` tests above).
repo.write_project_config(
- r#"[pre-start]
-deps = "pre-start-tool"
+ r#"[pre-create]
+deps = "pre-create-tool"
-[post-start]
-deps = "post-start-tool"
+[post-create]
+deps = "post-create-tool"
"#,
);
- // The `-create` arg exercises the load-time migration (the `[*-start]` key
- // must deserialize into the `*_create` field); the `-start` arg additionally
- // exercises the value parser accepting the deprecated alias.
+ // The `-start` arg passes the canonical type name; the `-create` arg
+ // exercises the value parser accepting the deprecated alias. Both resolve
+ // to the same hook because `ProjectConfig::load` migrates the `[*-create]`
+ // config keys to canonical `[*-start]` before deserializing.
let cases = [
- ("pre-start", "pre-start-tool"),
- ("pre-start", "pre-start-tool"),
- ("post-start", "post-start-tool"),
- ("post-start", "post-start-tool"),
+ ("pre-start", "pre-create-tool"),
+ ("pre-create", "pre-create-tool"),
+ ("post-start", "post-create-tool"),
+ ("post-create", "post-create-tool"),
];
for (type_arg, expected) in cases {
let mut cmd = repo.wt_command();
@@ -652,7 +653,7 @@ fn test_system_config_deprecations_pass_through_gate(repo: TestRepo) {
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(
&system_config_path,
- r#"post-start = "npm install"
+ r#"post-create = "npm install"
[select]
pager = "delta --paging=never"
@@ -680,7 +681,7 @@ pager = "delta --paging=never"
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
stdout.contains("npm install"),
- "post-start in system config should migrate to post-start and stay active, got: {stdout}"
+ "deprecated post-create key should migrate to post-start and stay active, got: {stdout}"
);
}
@@ -3448,31 +3449,6 @@ pager = "delta --paging=never"
});
}
-/// `wt config show` reveals the silent `-start` → `-create` hook migration as a
-/// diff. Phase 1 stays warning-free (see issue #2838), so the output carries no
-/// "is deprecated" line — only the proposed diff and the apply hint.
-#[rstest]
-fn test_config_show_displays_start_hook_migration(mut repo: TestRepo, temp_home: TempDir) {
- repo.setup_mock_ci_tools_unauthenticated();
-
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
- let config_path = global_config_dir.join("config.toml");
- fs::write(&config_path, "pre-start = \"npm install\"\n").unwrap();
-
- let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
- settings.bind(|| {
- let mut cmd = wt_command();
- repo.configure_wt_cmd(&mut cmd);
- repo.configure_mock_commands(&mut cmd);
- cmd.arg("config").arg("show").current_dir(repo.root_path());
- set_temp_home_env(&mut cmd, temp_home.path());
- set_xdg_config_path(&mut cmd, temp_home.path());
-
- assert_cmd_snapshot!(cmd);
- });
-}
-
/// `wt config show` displays deprecation details for `[merge] no-ff` → `ff` (inverted).
#[rstest]
fn test_config_show_displays_no_ff_deprecation(mut repo: TestRepo, temp_home: TempDir) {
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index a9322d6a3..e764fe197 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -60,13 +60,13 @@ approved-commands = ["echo 'Setup complete'"]
snapshot_switch("post_start_single_command", &repo, &["--create", "feature"]);
}
-/// A config that still uses the deprecated `pre-start` hook key loads and runs:
-/// the key is silently migrated to `pre-start`. Phase 1 of the rename emits no
-/// warning (see https://github.com/max-sixty/worktrunk/issues/2838).
+/// A config that uses the deprecated `pre-create` hook key loads and runs: the
+/// key is silently migrated to canonical `pre-start`. Phase 1 of the rename
+/// emits no warning (see https://github.com/max-sixty/worktrunk/issues/2838).
#[rstest]
-fn test_deprecated_start_hook_key_runs_silently(repo: TestRepo) {
- repo.write_project_config(r#"pre-start = "echo ran > marker.txt""#);
- repo.commit("Add deprecated pre-start hook");
+fn test_deprecated_create_hook_key_runs_silently(repo: TestRepo) {
+ repo.write_project_config(r#"pre-create = "echo ran > marker.txt""#);
+ repo.commit("Add deprecated pre-create hook");
repo.write_test_approvals(
r#"[projects."../origin"]
approved-commands = ["echo ran > marker.txt"]
@@ -82,15 +82,15 @@ approved-commands = ["echo ran > marker.txt"]
assert!(
output.status.success(),
- "switch with a deprecated pre-start hook should succeed, stderr: {}",
+ "switch with a deprecated pre-create hook should succeed, stderr: {}",
String::from_utf8_lossy(&output.stderr)
);
- // The hook ran — the `pre-start` key was migrated to `pre-start`.
+ // The hook ran — the `pre-create` key was migrated to canonical `pre-start`.
let worktree_path = repo.root_path().parent().unwrap().join("repo.feature");
assert!(
worktree_path.join("marker.txt").exists(),
- "deprecated pre-start hook should have run"
+ "deprecated pre-create hook should have run"
);
// Phase 1 migrates silently: no deprecation warning, and no stray
@@ -142,7 +142,7 @@ approved-commands = ["exit 1"]
"#,
);
- // Failing pre-start hook (via deprecated pre-start name) aborts with FailFast
+ // A failing pre-start hook aborts with FailFast
snapshot_switch(
"post_start_failing_command",
&repo,
diff --git a/tests/integration_tests/user_hooks.rs b/tests/integration_tests/user_hooks.rs
index 18e6e323c..ad73e7c4f 100644
--- a/tests/integration_tests/user_hooks.rs
+++ b/tests/integration_tests/user_hooks.rs
@@ -166,9 +166,8 @@ failing = "exit 1"
"#,
);
- // Failing pre-start hook (via deprecated pre-start name) aborts with FailFast.
- // The worktree is already created before pre-start runs (it was renamed from
- // pre-start), so the worktree exists but the command exits non-zero.
+ // A failing pre-start hook aborts with FailFast. The worktree is created
+ // before pre-start runs, so it exists even though the command exits non-zero.
snapshot_switch("user_post_start_failure", &repo, &["--create", "feature"]);
// Worktree exists (created before pre-start ran) but the command failed
@@ -1592,20 +1591,21 @@ fn test_standalone_hook_pre_start(repo: TestRepo) {
}
#[rstest]
-fn test_standalone_hook_start_alias_runs_silently(repo: TestRepo) {
- // `wt hook pre-start` is a deprecated alias for `wt hook pre-start`. It
- // still runs, and Phase 1 of the rename emits no warning (issue #2838).
- repo.write_project_config(r#"pre-start = "echo 'START_ALIAS' > hook_ran.txt""#);
+fn test_standalone_hook_create_alias_runs_silently(repo: TestRepo) {
+ // `wt hook pre-create` is a deprecated alias for `wt hook pre-start`. It
+ // still runs the canonical `pre-start` hook, and Phase 1 of the rename
+ // emits no warning (issue #2838).
+ repo.write_project_config(r#"pre-start = "echo 'CREATE_ALIAS' > hook_ran.txt""#);
let mut cmd = crate::common::wt_command();
cmd.current_dir(repo.root_path());
cmd.env("WORKTRUNK_CONFIG_PATH", repo.test_config_path());
- cmd.args(["hook", "pre-start", "--yes"]);
+ cmd.args(["hook", "pre-create", "--yes"]);
let output = cmd.output().unwrap();
assert!(
output.status.success(),
- "wt hook pre-start should succeed (alias for pre-start)"
+ "wt hook pre-create should succeed (alias for pre-start)"
);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
@@ -1617,7 +1617,7 @@ fn test_standalone_hook_start_alias_runs_silently(repo: TestRepo) {
let marker = repo.root_path().join("hook_ran.txt");
crate::common::wait_for_file_content(&marker);
let content = fs::read_to_string(&marker).unwrap();
- assert!(content.contains("START_ALIAS"));
+ assert!(content.contains("CREATE_ALIAS"));
}
#[rstest]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_displays_start_hook_migration.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_displays_start_hook_migration.snap
deleted file mode 100644
index 27cf55819..000000000
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_displays_start_hook_migration.snap
+++ /dev/null
@@ -1,75 +0,0 @@
----
-source: tests/integration_tests/config_show.rs
-info:
- program: wt
- args:
- - config
- - show
- env:
- APPDATA: "[TEST_CONFIG_HOME]"
- CLICOLOR_FORCE: "1"
- COLUMNS: "500"
- GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
- GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
- GIT_COMMON_DIR: ""
- GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
- GIT_CONFIG_SYSTEM: /dev/null
- GIT_DIR: ""
- GIT_EDITOR: ""
- GIT_INDEX_FILE: ""
- GIT_OBJECT_DIRECTORY: ""
- GIT_TERMINAL_PROMPT: "0"
- GIT_WORK_TREE: ""
- HOME: "[TEST_HOME]"
- LANG: C
- LC_ALL: C
- LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
- MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
- NO_COLOR: ""
- OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
- PATH: "[PATH]"
- PSModulePath: ""
- RUST_LOG: warn
- SHELL: ""
- TERM: alacritty
- USERPROFILE: "[TEST_HOME]"
- WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
- WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
- WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
- WORKTRUNK_TEST_BASH_INSTALLED: "0"
- WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
- WORKTRUNK_TEST_CODEX_INSTALLED: "0"
- WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
- WORKTRUNK_TEST_EPOCH: "1735776000"
- WORKTRUNK_TEST_FISH_INSTALLED: "0"
- WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
- WORKTRUNK_TEST_NUSHELL_ENV: "0"
- WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
- WORKTRUNK_TEST_POWERSHELL_ENV: "0"
- WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
- WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
- WORKTRUNK_TEST_ZSH_INSTALLED: "0"
- XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
----
-success: true
-exit_code: 0
------ stdout -----
-USER CONFIG @ ~/.config/worktrunk/config.toml
-  pre-start = "npm install"
-↳ Optional system config not found @ /etc/xdg/worktrunk/config.toml
-
-PROJECT CONFIG @ _REPO_/.config/wt.toml
-○ Identifier: ../origin
-↳ Not found
-
-SHELL INTEGRATION
-▲ Shell integration not configured
-↳ To configure, run wt config shell install
-  Invoked as: [PROJECT_ROOT]/target/[BUILD_MODE]/wt
-
-OTHER
-○ wt: [VERSION]
-○ git: [VERSION]
-○ Hyperlinks: inactive
-
------ stderr -----