Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions internal/render/detail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,50 @@ 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())
}
}

// hiddenOwnerReport builds a PID 0 report the way the real pipeline does: the
// title comes from the generic detector and the advice from the advise package.
func hiddenOwnerReport(t *testing.T) report.PortReport {
Expand Down
14 changes: 14 additions & 0 deletions internal/render/testdata/text_detail_overlong_command.golden
Original file line number Diff line number Diff line change
@@ -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

Loading