@@ -68,7 +68,7 @@ def test_color_enum_total_count(self):
6868 self .assertEqual (len (Color ), 14 , f"Expected 14 colors, got { len (Color )} " )
6969
7070 def test_color_values_are_ansi_codes (self ):
71- """Color values should be ANSI escape sequences."""
71+ """Color values should be ANSI escape sequences (16-color or true color) ."""
7272 from hatch .cli .cli_utils import Color
7373
7474 for color in Color :
@@ -80,6 +80,27 @@ def test_color_values_are_ansi_codes(self):
8080 color .value .endswith ('m' ),
8181 f"{ color .name } value should end with 'm': { repr (color .value )} "
8282 )
83+ # Verify it's either 16-color or true color format
84+ is_16_color = color .value .startswith ('\033 [' ) and not color .value .startswith ('\033 [38;2;' )
85+ is_true_color = color .value .startswith ('\033 [38;2;' )
86+ self .assertTrue (
87+ is_16_color or is_true_color or color .name == 'RESET' ,
88+ f"{ color .name } should be 16-color or true color format: { repr (color .value )} "
89+ )
90+
91+ def test_amber_color_exists (self ):
92+ """Color.AMBER should exist for entity highlighting."""
93+ from hatch .cli .cli_utils import Color
94+
95+ self .assertTrue (
96+ hasattr (Color , 'AMBER' ),
97+ "Color enum missing AMBER for entity highlighting"
98+ )
99+ # AMBER should have a valid ANSI value
100+ self .assertTrue (
101+ Color .AMBER .value .startswith ('\033 [' ),
102+ f"AMBER value should be ANSI escape: { repr (Color .AMBER .value )} "
103+ )
83104
84105 def test_reset_clears_formatting (self ):
85106 """RESET should be the standard ANSI reset code."""
@@ -139,6 +160,54 @@ def test_truecolor_detection_fallback_false(self):
139160 self .assertFalse (_supports_truecolor ())
140161
141162
163+ class TestHighlightFunction (unittest .TestCase ):
164+ """Tests for highlight() utility function.
165+
166+ Reference: R12 §3.3 (12-enhancing_colors_v0.md) - Bold modifier
167+ """
168+
169+ def test_highlight_with_colors_enabled (self ):
170+ """highlight() should apply bold + amber when colors enabled."""
171+ from hatch .cli .cli_utils import highlight , Color
172+
173+ env_without_no_color = {k : v for k , v in os .environ .items () if k != 'NO_COLOR' }
174+ with patch .dict (os .environ , env_without_no_color , clear = True ):
175+ with patch .object (sys .stdout , 'isatty' , return_value = True ):
176+ result = highlight ('test-entity' )
177+
178+ # Should contain bold escape
179+ self .assertIn ('\033 [1m' , result )
180+ # Should contain amber color
181+ self .assertIn (Color .AMBER .value , result )
182+ # Should contain reset
183+ self .assertIn (Color .RESET .value , result )
184+ # Should contain the text
185+ self .assertIn ('test-entity' , result )
186+
187+ def test_highlight_with_colors_disabled (self ):
188+ """highlight() should return plain text when colors disabled."""
189+ from hatch .cli .cli_utils import highlight
190+
191+ with patch .dict (os .environ , {'NO_COLOR' : '1' }):
192+ result = highlight ('test-entity' )
193+
194+ # Should be plain text without ANSI codes
195+ self .assertEqual (result , 'test-entity' )
196+ self .assertNotIn ('\033 [' , result )
197+
198+ def test_highlight_non_tty (self ):
199+ """highlight() should return plain text in non-TTY mode."""
200+ from hatch .cli .cli_utils import highlight
201+
202+ env_without_no_color = {k : v for k , v in os .environ .items () if k != 'NO_COLOR' }
203+ with patch .dict (os .environ , env_without_no_color , clear = True ):
204+ with patch .object (sys .stdout , 'isatty' , return_value = False ):
205+ result = highlight ('test-entity' )
206+
207+ # Should be plain text
208+ self .assertEqual (result , 'test-entity' )
209+
210+
142211class TestColorsEnabled (unittest .TestCase ):
143212 """Tests for color enable/disable decision logic.
144213
0 commit comments