Skip to content

Commit 2d56dfd

Browse files
jawwad-aliclaude
andauthored
fix(integrations): cline hook note collapses onto instruction at EOF (#3263)
The hook-note injection regex matches the line terminator via (\r\n|\n|$), so the captured eol group is empty when the instruction is the final line of a file with no trailing newline. The cline integration emitted the note with that empty eol, mashing the note text and the instruction onto a single line. Default eol to '\n', matching the agy integration twin which already guards this case. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 810d6fc commit 2d56dfd

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/specify_cli/integrations/cline/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ def _inject_hook_command_note(content: str) -> str:
9696
def repl(m: re.Match[str]) -> str:
9797
indent = m.group(1)
9898
instruction = m.group(2)
99-
eol = m.group(3)
99+
# ``eol`` is empty when the regex matched via ``$`` because the
100+
# instruction was the final line of a file with no trailing
101+
# newline. Default to ``\n`` so the note never collapses onto
102+
# the same line as the instruction.
103+
eol = m.group(3) or "\n"
100104
return (
101105
indent
102106
+ _HOOK_COMMAND_NOTE.rstrip("\n")

tests/integrations/test_integration_cline.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ def test_cline_hook_instruction_injection(self):
9090
assert "replace dots (`.`) with hyphens (`-`)" in injected
9191
assert "- For each executable hook, output the following:" in injected
9292

93+
def test_cline_hook_instruction_injection_no_trailing_newline(self):
94+
"""Note must not collapse onto the instruction line when the
95+
instruction is the final line with no trailing newline.
96+
97+
The injection regex matches the end-of-line via ``(\\r\\n|\\n|$)``, so
98+
the captured ``eol`` is empty on a file's last line that lacks a
99+
trailing newline. Without an ``or "\\n"`` fallback the note text and
100+
the instruction are emitted on the same line.
101+
"""
102+
cline = get_integration("cline")
103+
content = "- For each executable hook, output the following:" # no trailing \n
104+
injected = cline._inject_hook_command_note(content)
105+
assert "replace dots (`.`) with hyphens (`-`)" in injected
106+
# Instruction stays on its own line rather than being mashed onto the note.
107+
assert "\n- For each executable hook, output the following:" in injected
108+
93109
# -- Overrides for MarkdownIntegrationTests ---------------------------
94110

95111
def test_setup_creates_files(self, tmp_path):

0 commit comments

Comments
 (0)