11"""Tests for Rust hook engine registration (AMPLIHACK_HOOK_ENGINE=rust).
22
33Covers:
4- - find_rust_hook_binary(): PATH lookup, ~/.amplihack/bin, ~/.cargo/bin
4+ - find_rust_hook_binary(): PATH lookup, ~/.amplihack/.claude/bin, legacy ~/.amplihack/ bin, ~/.cargo/bin
55- get_hook_engine(): env var parsing
66- update_hook_paths() with hook_engine="rust": uses Rust binary, errors when missing
77- stage_hooks() with AMPLIHACK_HOOK_ENGINE=rust: generates Rust wrapper scripts
@@ -81,17 +81,31 @@ def test_finds_on_path(self, tmp_path):
8181 assert result is not None
8282 assert result .endswith ("amplihack-hooks" )
8383
84- def test_finds_in_amplihack_bin (self , tmp_path ):
84+ def test_finds_in_staged_claude_bin (self , tmp_path ):
85+ bin_dir = tmp_path / ".amplihack" / ".claude" / "bin"
86+ bin_dir .mkdir (parents = True )
87+ binary = bin_dir / "amplihack-hooks"
88+ binary .write_text ("#!/bin/sh\n echo test" )
89+ binary .chmod (0o755 )
90+
91+ with patch ("shutil.which" , return_value = None ):
92+ with patch ("os.path.expanduser" , side_effect = lambda p : str (tmp_path / p .lstrip ("~/" ))):
93+ result = find_rust_hook_binary ()
94+ assert result is not None
95+ assert ".claude/bin" in result
96+
97+ def test_finds_in_legacy_amplihack_bin (self , tmp_path ):
8598 bin_dir = tmp_path / ".amplihack" / "bin"
8699 bin_dir .mkdir (parents = True )
87100 binary = bin_dir / "amplihack-hooks"
88101 binary .write_text ("#!/bin/sh\n echo test" )
89102 binary .chmod (0o755 )
90103
91104 with patch ("shutil.which" , return_value = None ):
92- with patch ("os.path.expanduser" , side_effect = lambda p : str (tmp_path / p .lstrip ("~/" ))) :
105+ with patch ("os.path.expanduser" , side_effect = lambda p : str (tmp_path / p .lstrip ("~/" ))):
93106 result = find_rust_hook_binary ()
94107 assert result is not None
108+ assert "/.amplihack/bin/" in result
95109
96110 def test_finds_in_cargo_bin (self , tmp_path ):
97111 cargo_dir = tmp_path / ".cargo" / "bin"
@@ -105,13 +119,19 @@ def test_finds_in_cargo_bin(self, tmp_path):
105119 result = find_rust_hook_binary ()
106120 assert result is not None
107121
108- def test_amplihack_bin_takes_priority_over_cargo_bin (self , tmp_path ):
109- """~/.amplihack/bin should win over ~/.cargo/bin."""
110- amplihack_dir = tmp_path / ".amplihack" / "bin"
111- amplihack_dir .mkdir (parents = True )
112- amplihack_binary = amplihack_dir / "amplihack-hooks"
113- amplihack_binary .write_text ("#!/bin/sh\n echo amplihack" )
114- amplihack_binary .chmod (0o755 )
122+ def test_staged_bin_takes_priority_over_legacy_and_cargo_bin (self , tmp_path ):
123+ """~/.amplihack/.claude/bin should win over legacy ~/.amplihack/bin and ~/.cargo/bin."""
124+ staged_dir = tmp_path / ".amplihack" / ".claude" / "bin"
125+ staged_dir .mkdir (parents = True )
126+ staged_binary = staged_dir / "amplihack-hooks"
127+ staged_binary .write_text ("#!/bin/sh\n echo staged" )
128+ staged_binary .chmod (0o755 )
129+
130+ legacy_dir = tmp_path / ".amplihack" / "bin"
131+ legacy_dir .mkdir (parents = True )
132+ legacy_binary = legacy_dir / "amplihack-hooks"
133+ legacy_binary .write_text ("#!/bin/sh\n echo legacy" )
134+ legacy_binary .chmod (0o755 )
115135
116136 cargo_dir = tmp_path / ".cargo" / "bin"
117137 cargo_dir .mkdir (parents = True )
@@ -123,12 +143,12 @@ def test_amplihack_bin_takes_priority_over_cargo_bin(self, tmp_path):
123143 with patch ("os.path.expanduser" , side_effect = lambda p : str (tmp_path / p .lstrip ("~/" ))):
124144 result = find_rust_hook_binary ()
125145 assert result is not None
126- assert ".amplihack" in result
146+ assert ".amplihack/.claude/bin " in result
127147 assert ".cargo" not in result
128148
129149 def test_non_executable_file_skipped (self , tmp_path ):
130- """A non-executable file at ~/.amplihack/bin/amplihack-hooks should be skipped."""
131- bin_dir = tmp_path / ".amplihack" / "bin"
150+ """A non-executable file at ~/.amplihack/.claude/ bin/amplihack-hooks should be skipped."""
151+ bin_dir = tmp_path / ".amplihack" / ".claude" / " bin"
132152 bin_dir .mkdir (parents = True )
133153 binary = bin_dir / "amplihack-hooks"
134154 binary .write_text ("#!/bin/sh\n echo test" )
0 commit comments