From 8d61ec6b3f020056108006b4b406b39a6eaf7dd9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 1 Jul 2026 14:59:05 +0000 Subject: [PATCH] test: improve SanitizePublicChallengeSummary testing coverage Co-authored-by: matdev83 <211248003+matdev83@users.noreply.github.com> --- pkg/lipsdk/auth/sanitize_test.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/lipsdk/auth/sanitize_test.go b/pkg/lipsdk/auth/sanitize_test.go index f1ce873b..ecfc5811 100644 --- a/pkg/lipsdk/auth/sanitize_test.go +++ b/pkg/lipsdk/auth/sanitize_test.go @@ -9,25 +9,28 @@ func TestSanitizePublicChallengeSummary(t *testing.T) { t.Parallel() fb := "fallback-msg" cases := []struct { - name string - in string - want string + name string + in string + maxRunes int + want string }{ - {"empty uses fallback", "", fb}, - {"whitespace uses fallback", " \t ", fb}, - {"plain short unchanged", "Sign in to continue.", "Sign in to continue."}, - {"collapses internal space", "a \tb", "a b"}, - {"strips controls", "line1\x00line2", "line1 line2"}, - {"bearer triggers fallback", "Please use Bearer sk-abc", fb}, - {"access_token triggers fallback", "Open https://x?access_token=secret", fb}, - {"long truncates", strings.Repeat("x", 400), strings.Repeat("x", 254) + "…"}, + {"empty uses fallback", "", 255, fb}, + {"whitespace uses fallback", " \t ", 255, fb}, + {"plain short unchanged", "Sign in to continue.", 255, "Sign in to continue."}, + {"collapses internal space", "a \tb", 255, "a b"}, + {"strips controls", "line1\x00line2", 255, "line1 line2"}, + {"bearer triggers fallback", "Please use Bearer sk-abc", 255, fb}, + {"access_token triggers fallback", "Open https://x?access_token=secret", 255, fb}, + {"long truncates", strings.Repeat("x", 400), 255, strings.Repeat("x", 254) + "…"}, + {"zero maxRunes defaults to 256", strings.Repeat("x", 400), 0, strings.Repeat("x", 255) + "…"}, + {"negative maxRunes defaults to 256", strings.Repeat("x", 400), -1, strings.Repeat("x", 255) + "…"}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { t.Parallel() - got := SanitizePublicChallengeSummary(tc.in, fb, 255) + got := SanitizePublicChallengeSummary(tc.in, fb, tc.maxRunes) if got != tc.want { - t.Fatalf("SanitizePublicChallengeSummary(%q) = %q, want %q", tc.in, got, tc.want) + t.Fatalf("SanitizePublicChallengeSummary(%q, %d) = %q, want %q", tc.in, tc.maxRunes, got, tc.want) } }) }