@@ -114,7 +114,7 @@ def test_git_commit_with_gates_disabled(self, monkeypatch, capsys):
114114 assert result is None
115115
116116 def test_git_commit_with_gates_enabled_returns_context (self , monkeypatch , capsys ):
117- """When qualityGates.enabled is True, should return additionalContext."""
117+ """When qualityGates.enabled is True, should return compact additionalContext."""
118118 config = {"qualityGates" : {"enabled" : True }}
119119 result = _run_hook (
120120 {"tool_name" : "Bash" , "tool_input" : {"command" : "git commit -m 'feat: test'" }},
@@ -123,8 +123,12 @@ def test_git_commit_with_gates_enabled_returns_context(self, monkeypatch, capsys
123123 assert result is not None
124124 assert "hookSpecificOutput" in result
125125 hook_output = result ["hookSpecificOutput" ]
126- # Should have additionalContext with quality gate reminder
126+ # Should have compact additionalContext with quality gate reminder (#1039)
127127 assert "additionalContext" in hook_output
128+ ctx = hook_output ["additionalContext" ]
129+ assert "[Quality Gate]" in ctx
130+ # Compact: single line, no bullet points
131+ assert ctx .count ("\n " ) == 0
128132
129133 def test_git_commit_amend_with_gates (self , monkeypatch , capsys ):
130134 """git commit --amend should also trigger quality gates."""
@@ -160,7 +164,7 @@ class TestPreToolUseSmartTestRunner:
160164 """Tests for SmartTestRunner integration in pre-tool-use hook."""
161165
162166 def test_git_commit_injects_test_suggestion (self , monkeypatch , capsys , tmp_path ):
163- """git commit should inject related test suggestion into additionalContext."""
167+ """git commit should inject compact test count into additionalContext (#1039) ."""
164168 # Create a fake staged file list
165169 monkeypatch .setattr (
166170 "subprocess.check_output" ,
@@ -173,8 +177,9 @@ def test_git_commit_injects_test_suggestion(self, monkeypatch, capsys, tmp_path)
173177 )
174178 assert result is not None
175179 ctx = result ["hookSpecificOutput" ]["additionalContext" ]
176- assert "Consider running" in ctx
177- assert "foo.spec.ts" in ctx
180+ # Collapsed format: count only, no individual file listing
181+ assert "related test(s) found" in ctx
182+ assert "foo.spec.ts" not in ctx
178183
179184 def test_git_commit_no_staged_files_no_suggestion (self , monkeypatch , capsys ):
180185 """git commit with no staged files should not inject suggestion."""
@@ -203,7 +208,7 @@ def test_git_commit_config_files_only_no_suggestion(self, monkeypatch, capsys):
203208 assert result is None
204209
205210 def test_git_commit_combines_quality_gate_and_test_suggestion (self , monkeypatch , capsys ):
206- """When both quality gates and test suggestion active, both in context."""
211+ """When both quality gates and test suggestion active, both in compact context (#1039) ."""
207212 monkeypatch .setattr (
208213 "subprocess.check_output" ,
209214 lambda * a , ** kw : b"src/bar.ts\n " ,
@@ -215,7 +220,7 @@ def test_git_commit_combines_quality_gate_and_test_suggestion(self, monkeypatch,
215220 )
216221 assert result is not None
217222 ctx = result ["hookSpecificOutput" ]["additionalContext" ]
218- assert "Consider running " in ctx
223+ assert "related test(s) found " in ctx
219224 assert "Quality Gate" in ctx
220225
221226 def test_non_git_commit_no_test_suggestion (self , monkeypatch , capsys ):
@@ -241,6 +246,77 @@ def _raise(*a, **kw):
241246 assert result is None
242247
243248
249+ class TestPreToolUseCompactOutput :
250+ """Tests for compact output format (#1039)."""
251+
252+ def test_checklist_collapsed_to_domain_counts (self , monkeypatch , capsys ):
253+ """Checklist should show domain counts, not individual items (#1039)."""
254+ monkeypatch .setattr (
255+ "subprocess.check_output" ,
256+ lambda * a , ** kw : b"src/auth/login.ts\n " ,
257+ )
258+ config = {"qualityGates" : {"enabled" : False }}
259+ result = _run_hook (
260+ {"tool_name" : "Bash" , "tool_input" : {"command" : "git commit -m 'feat: auth'" }},
261+ monkeypatch , capsys , config = config ,
262+ )
263+ assert result is not None
264+ ctx = result ["hookSpecificOutput" ]["additionalContext" ]
265+ # Collapsed: "[Checklist] security(5)" not individual items
266+ assert "[Checklist]" in ctx
267+ assert "security(" in ctx
268+ # Should NOT contain individual checklist items
269+ assert "Validate and sanitize" not in ctx
270+
271+ def test_quality_gate_compact_single_line (self , monkeypatch , capsys ):
272+ """Quality gate should be a single line (#1039)."""
273+ config = {"qualityGates" : {"enabled" : True }}
274+ result = _run_hook (
275+ {"tool_name" : "Bash" , "tool_input" : {"command" : "git commit -m 'test'" }},
276+ monkeypatch , capsys , config = config ,
277+ )
278+ assert result is not None
279+ ctx = result ["hookSpecificOutput" ]["additionalContext" ]
280+ # Quality gate alone: single line, no newlines
281+ assert "[Quality Gate]" in ctx
282+ assert ctx .count ("\n " ) == 0
283+
284+ def test_full_commit_output_max_5_lines (self , monkeypatch , capsys ):
285+ """Combined output (gate + tests + checklist) should be max 5 lines (#1039)."""
286+ monkeypatch .setattr (
287+ "subprocess.check_output" ,
288+ lambda * a , ** kw : b"src/auth/login.ts\n src/api/users.ts\n " ,
289+ )
290+ config = {"qualityGates" : {"enabled" : True }}
291+ result = _run_hook (
292+ {"tool_name" : "Bash" , "tool_input" : {"command" : "git commit -m 'feat: all'" }},
293+ monkeypatch , capsys , config = config ,
294+ )
295+ assert result is not None
296+ ctx = result ["hookSpecificOutput" ]["additionalContext" ]
297+ line_count = ctx .count ("\n " ) + 1
298+ assert line_count <= 5 , f"Output has { line_count } lines, max is 5:\n { ctx } "
299+
300+ def test_test_suggestion_shows_count_not_files (self , monkeypatch , capsys ):
301+ """Test suggestion should show count, not individual file paths (#1039)."""
302+ monkeypatch .setattr (
303+ "subprocess.check_output" ,
304+ lambda * a , ** kw : b"src/foo.ts\n src/bar.ts\n src/baz.ts\n " ,
305+ )
306+ config = {"qualityGates" : {"enabled" : False }}
307+ result = _run_hook (
308+ {"tool_name" : "Bash" , "tool_input" : {"command" : "git commit -m 'feat: multi'" }},
309+ monkeypatch , capsys , config = config ,
310+ )
311+ assert result is not None
312+ ctx = result ["hookSpecificOutput" ]["additionalContext" ]
313+ # Should show count (3 files * ~5 candidates each = many, but deduplicated)
314+ assert "related test(s) found" in ctx
315+ # Should NOT list individual test files
316+ assert ".spec.ts" not in ctx
317+ assert ".test.ts" not in ctx
318+
319+
244320class TestPreToolUseStatusMessage :
245321 """Tests for agent statusMessage in hook output (#974)."""
246322
@@ -325,4 +401,4 @@ def test_status_combined_with_quality_gate(self, monkeypatch, capsys, tmp_path):
325401 hook_out = result ["hookSpecificOutput" ]
326402 assert "statusMessage" in hook_out
327403 assert "additionalContext" in hook_out
328- assert "Quality Gate" in hook_out ["additionalContext" ]
404+ assert "[ Quality Gate] " in hook_out ["additionalContext" ]
0 commit comments