From f5f98688ddc8f432d9ec455d237e5e74c3e6ecc5 Mon Sep 17 00:00:00 2001 From: wuyang6 Date: Tue, 7 Jul 2026 21:21:19 +0800 Subject: [PATCH] Fix compact summary regex replacement --- src/compact.py | 2 +- tests/test_compact.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compact.py b/src/compact.py index 0d75012..ece71a1 100644 --- a/src/compact.py +++ b/src/compact.py @@ -238,7 +238,7 @@ def format_compact_summary(summary: str) -> str: content = match.group(1).strip() formatted = re.sub( r'[\s\S]*?', - f'Summary:\n{content}', + lambda _: f'Summary:\n{content}', formatted, ) diff --git a/tests/test_compact.py b/tests/test_compact.py index 66709ca..b35d963 100644 --- a/tests/test_compact.py +++ b/tests/test_compact.py @@ -112,6 +112,12 @@ class TestFormatCompactSummary(unittest.TestCase): self.assertNotIn('Line 1', formatted) self.assertIn('Final summary', formatted) + def test_summary_content_keeps_regex_backslashes_literal(self) -> None: + raw = r'Regex examples: \s+ and \1 should stay literal.' + formatted = format_compact_summary(raw) + self.assertIn(r'\s+', formatted) + self.assertIn(r'\1', formatted) + class TestGetCompactUserSummaryMessage(unittest.TestCase): """Tests for the post-compact user message builder."""