From 425fafb683bee42ab7024e04ed21840d14074909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeffry=20W=C3=BCrmli?= Date: Thu, 12 Nov 2026 13:28:05 +0100 Subject: [PATCH] test: cover truncation of very long Command lines in text and JSON output --- internal/render/detail_test.go | 44 +++++++++++++++++++ .../text_detail_overlong_command.golden | 14 ++++++ 2 files changed, 58 insertions(+) create mode 100644 internal/render/testdata/text_detail_overlong_command.golden diff --git a/internal/render/detail_test.go b/internal/render/detail_test.go index d9d449a..0d0e1d0 100644 --- a/internal/render/detail_test.go +++ b/internal/render/detail_test.go @@ -230,3 +230,47 @@ func TestText_DetailLongHeadlineAndProcessNameFitTheWidth(t *testing.T) { } } } + +func overlongCommandReport(command string) report.PortReport { + r := processReport() + r.Findings[0].Explanation.Details[0].Value = command + return r +} + +func TestText_DetailOverlongCommandGolden(t *testing.T) { + r := overlongCommandReport("java -cp " + strings.Repeat("/opt/app/lib/dependency-with-a-long-name.jar:", 12) + " com.example.Main") + var buf strings.Builder + if err := Text(&buf, []report.PortReport{r}, Options{Width: 80}); err != nil { + t.Fatal(err) + } + + golden(t, "text_detail_overlong_command.golden", []byte(buf.String())) +} + +func TestText_DetailTruncatedCommandKeepsMultibyteRunesWhole(t *testing.T) { + r := overlongCommandReport(strings.Repeat("größe-日本語-", 40)) + var buf strings.Builder + if err := Text(&buf, []report.PortReport{r}, Options{Width: 80}); err != nil { + t.Fatal(err) + } + + out := buf.String() + if !utf8.ValidString(out) { + t.Errorf("truncation split a UTF-8 character:\n%q", out) + } + if !strings.Contains(out, "…") { + t.Errorf("an over-long command should end in an ellipsis:\n%s", out) + } +} + +func TestJSON_DetailKeepsFullCommand(t *testing.T) { + command := strings.Repeat("--flag=value ", 60) + var buf strings.Builder + if err := JSON(&buf, []report.PortReport{overlongCommandReport(command)}); err != nil { + t.Fatal(err) + } + + if !strings.Contains(buf.String(), command) { + t.Errorf("JSON must carry the full command:\n%s", buf.String()) + } +} diff --git a/internal/render/testdata/text_detail_overlong_command.golden b/internal/render/testdata/text_detail_overlong_command.golden new file mode 100644 index 0000000..ca0d083 --- /dev/null +++ b/internal/render/testdata/text_detail_overlong_command.golden @@ -0,0 +1,14 @@ +──────────────────────── :3000 · Antigravity (PID 3983) ──────────────────────── + + ℹ tcp 127.0.0.1 + + User jeffry + Uptime 6d 1h + Started by Antigravity ← launchd + Command java -cp + /opt/app/lib/dependency-with-a-long-name.jar:/opt/app/lib/depe… + com.example.Main + Directory /Users/jeffry/Projects/some/deeply/nested/project/directory + + → Stop kill 3983 +