Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(cli): correct _read_output_line_count for trailing newlines (#1328)
Felix-Ayushdff4c03f23a1
diff --git a/packages/cli/src/repowise/cli/commands/augment_cmd/read_state.py b/packages/cli/src/repowise/cli/commands/augment_cmd/read_state.pyindex 274a671de..552c7f356 100644--- a/packages/cli/src/repowise/cli/commands/augment_cmd/read_state.py+++ b/packages/cli/src/repowise/cli/commands/augment_cmd/read_state.py@@ -714,6 +714,6 @@ def _read_output_line_count(tool_output: object) -> int:return ncontent = file_block.get("content")if isinstance(content, str):- return content.count("\n") + 1+ return len(content.splitlines()) if content else 0text = _extract_output_text(tool_output)- return (text.count("\n") + 1) if text.strip() else 0+ return len(text.splitlines()) if text.strip() else 0diff --git a/tests/unit/cli/test_read_state_line_count.py b/tests/unit/cli/test_read_state_line_count.pynew file mode 100644index 000000000..2f11725b5--- /dev/null+++ b/tests/unit/cli/test_read_state_line_count.py@@ -0,0 +1,31 @@+"""Regression tests for _read_output_line_count edge cases."""+from __future__ import annotations++from repowise.cli.commands.augment_cmd.read_state import _read_output_line_count+++def test_line_count_no_trailing_newline():+ assert _read_output_line_count({"file": {"content": "a\nb"}}) == 2+++def test_line_count_trailing_newline():+ """Trailing newline must not inflate the line count."""+ assert _read_output_line_count({"file": {"content": "a\nb\n"}}) == 2+++def test_line_count_single_line_trailing_newline():+ assert _read_output_line_count({"file": {"content": "hello\n"}}) == 1+++def test_line_count_empty_content():+ assert _read_output_line_count({"file": {"content": ""}}) == 0+++def test_line_count_fallback_text():+ """The text fallback path must also handle trailing newlines correctly."""+ assert _read_output_line_count({"output": "a\nb\n"}) == 2+++def test_line_count_fallback_whitespace_only():+ """Whitespace-only text fallback must count as zero lines."""+ assert _read_output_line_count({"output": " "}) == 0