From 8d8e61fd1383215f8603ace09dfab45d6d63d7fd Mon Sep 17 00:00:00 2001 From: Waleed Mahamid <120018496+WaleedMahamid@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:45:12 +0200 Subject: [PATCH] Keep report URLs on one line in narrow consoles Without a terminal (CI logs such as Jenkins) rich falls back to an 80-column console and wraps the report URL. EU report URLs are 83 characters long, so the last three characters of the aggregation ID moved to the next line and the link shown in the log returned 404. Print report URLs with soft_wrap so they are never wrapped, and cover the single and multiple URL cases with an 80-column console. Co-Authored-By: Claude Fable 5.2 --- cycode/cli/printers/text_printer.py | 4 ++-- tests/cli/printers/test_text_printer.py | 27 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cycode/cli/printers/text_printer.py b/cycode/cli/printers/text_printer.py index 7a88739f..6fa8247c 100644 --- a/cycode/cli/printers/text_printer.py +++ b/cycode/cli/printers/text_printer.py @@ -118,10 +118,10 @@ def print_report_urls(self, report_urls: list[str], aggregation_report_url: str single_url = report_urls[0] if len(report_urls) == 1 else None single_url = aggregation_report_url or single_url if single_url: - self.console.print(f'[b]Report URL:[/] {single_url}') + self.console.print(f'[b]Report URL:[/] {single_url}', soft_wrap=True) return # If there are multiple report URLs, print them all self.console.print('[b]Report URLs:[/]') for report_url in report_urls: - self.console.print(f'- {report_url}') + self.console.print(f'- {report_url}', soft_wrap=True) diff --git a/tests/cli/printers/test_text_printer.py b/tests/cli/printers/test_text_printer.py index 05a98382..8715dd01 100644 --- a/tests/cli/printers/test_text_printer.py +++ b/tests/cli/printers/test_text_printer.py @@ -146,3 +146,30 @@ def test_malicious_package_prints_the_advisory_and_the_removal_instruction( assert 'Advisory: MAL-2024-1234' in result assert 'Remediation: Remove this package from your dependencies.' in result + + +_LONG_REPORT_URL = 'https://app.eu.cycode.com/cli-logs-aggregation/01234567-89ab-cdef-0123-456789abcdef' + + +@pytest.fixture +def narrow_printer(output: io.StringIO) -> TextPrinter: + ctx = MagicMock() + ctx.obj = {'scan_type': 'sast', 'show_secret': False} + ctx.info_name = 'path' + return TextPrinter(ctx, Console(file=output, width=80), Console(stderr=True)) + + +def test_report_url_is_not_wrapped_on_a_narrow_console(narrow_printer: TextPrinter, output: io.StringIO) -> None: + narrow_printer.print_report_urls([], aggregation_report_url=_LONG_REPORT_URL) + + assert output.getvalue().splitlines() == [f'Report URL: {_LONG_REPORT_URL}'] + + +def test_multiple_report_urls_are_not_wrapped_on_a_narrow_console( + narrow_printer: TextPrinter, output: io.StringIO +) -> None: + report_urls = [_LONG_REPORT_URL, _LONG_REPORT_URL.replace('abcdef', 'fedcba')] + + narrow_printer.print_report_urls(report_urls) + + assert output.getvalue().splitlines() == ['Report URLs:', *(f'- {url}' for url in report_urls)]