@@ -2,7 +2,11 @@ import fs from "node:fs";
22import * as os from "node:os" ;
33import path from "node:path" ;
44import { describe , expect , it } from "vitest" ;
5- import { appendSessionToolTruncationWarning , shortenPath } from "./render-utils.js" ;
5+ import {
6+ appendSessionToolTruncationWarning ,
7+ shortenPath ,
8+ trimTrailingEmptyLines ,
9+ } from "./render-utils.js" ;
610
711const theme = {
812 fg : ( color : string , text : string ) => `<${ color } >${ text } </${ color } >` ,
@@ -26,6 +30,38 @@ describe("appendSessionToolTruncationWarning", () => {
2630 } ) ;
2731} ) ;
2832
33+ describe ( "trimTrailingEmptyLines" , ( ) => {
34+ it . each ( [
35+ {
36+ name : "removes multiple trailing empty lines" ,
37+ lines : [ "first" , "second" , "" , "" ] ,
38+ expected : [ "first" , "second" ] ,
39+ } ,
40+ { name : "removes all-empty input" , lines : [ "" , "" ] , expected : [ ] } ,
41+ {
42+ name : "keeps leading and interior empty lines" ,
43+ lines : [ "" , "first" , "" , "second" , "" ] ,
44+ expected : [ "" , "first" , "" , "second" ] ,
45+ } ,
46+ {
47+ name : "keeps whitespace-only trailing lines" ,
48+ lines : [ "first" , " " , "\t" ] ,
49+ expected : [ "first" , " " , "\t" ] ,
50+ } ,
51+ ] ) ( "$name" , ( { lines, expected } ) => {
52+ expect ( trimTrailingEmptyLines ( lines ) ) . toEqual ( expected ) ;
53+ } ) ;
54+
55+ it ( "does not mutate the caller-owned lines" , ( ) => {
56+ const lines = [ "first" , "" , "" ] ;
57+ const original = [ ...lines ] ;
58+
59+ trimTrailingEmptyLines ( lines ) ;
60+
61+ expect ( lines ) . toEqual ( original ) ;
62+ } ) ;
63+ } ) ;
64+
2965describe ( "shortenPath" , ( ) => {
3066 const home = os . homedir ( ) ;
3167
0 commit comments