diff --git a/scripts/docs-i18n/translator.go b/scripts/docs-i18n/translator.go index 932499d1ce7..f97767d58a3 100644 --- a/scripts/docs-i18n/translator.go +++ b/scripts/docs-i18n/translator.go @@ -315,11 +315,16 @@ func previewCommandOutput(stdout, stderr string) string { return "no output" } combined = strings.Join(strings.Fields(combined), " ") - const limit = 500 + const ( + limit = 1200 + headLength = 300 + tailLength = 800 + ) if len(combined) <= limit { return combined } - return combined[:limit] + "..." + // Codex prints API failures after its header and prompt, so the tail carries the actionable error. + return combined[:headLength] + " ... [truncated] ... " + combined[len(combined)-tailLength:] } func sleepWithContext(ctx context.Context, delay time.Duration) error { diff --git a/scripts/docs-i18n/translator_test.go b/scripts/docs-i18n/translator_test.go index 5d5d48a427d..c45b511090b 100644 --- a/scripts/docs-i18n/translator_test.go +++ b/scripts/docs-i18n/translator_test.go @@ -336,7 +336,7 @@ sleep 10 } func TestPreviewCommandOutputFlattensAndTruncates(t *testing.T) { - input := "line one\n\nline two\tline three " + strings.Repeat("x", 600) + input := "line one\n\nline two\tline three " + strings.Repeat("x", 1200) + " final api error 429" preview := previewCommandOutput(input, "") if strings.Contains(preview, "\n") { t.Fatalf("expected flattened whitespace, got %q", preview) @@ -344,7 +344,22 @@ func TestPreviewCommandOutputFlattensAndTruncates(t *testing.T) { if !strings.HasPrefix(preview, "line one line two line three ") { t.Fatalf("unexpected preview prefix: %q", preview) } - if !strings.HasSuffix(preview, "...") { - t.Fatalf("expected truncation suffix, got %q", preview) + if !strings.Contains(preview, "... [truncated] ...") { + t.Fatalf("expected truncation marker, got %q", preview) + } + if !strings.HasSuffix(preview, "final api error 429") { + t.Fatalf("expected retained error tail, got %q", preview) + } +} + +func TestPreviewCommandOutputRetainsStderrTail(t *testing.T) { + stdout := "startup banner " + strings.Repeat("x", 1200) + stderr := "provider api error 429" + preview := previewCommandOutput(stdout, stderr) + if !strings.HasPrefix(preview, "startup banner ") { + t.Fatalf("unexpected preview prefix: %q", preview) + } + if !strings.HasSuffix(preview, stderr) { + t.Fatalf("expected retained stderr tail, got %q", preview) } }