@@ -141,6 +141,96 @@ func TestIsDangerousOperation(t *testing.T) {
141141 }
142142}
143143
144+ func TestStripHeavyFields (t * testing.T ) {
145+ tests := []struct {
146+ name string
147+ output string
148+ command string
149+ args []string
150+ check func (t * testing.T , result string )
151+ }{
152+ {
153+ name : "strips versions from service list JSON" ,
154+ command : "service" ,
155+ args : []string {"list" },
156+ output : `[{"id":"svc1","name":"my-service","versions":[{"number":1},{"number":2},{"number":3}]},{"id":"svc2","name":"other","versions":[{"number":1}]}]` ,
157+ check : func (t * testing.T , result string ) {
158+ if strings .Contains (result , "versions" ) {
159+ t .Error ("Expected versions to be stripped" )
160+ }
161+ if ! strings .Contains (result , "svc1" ) || ! strings .Contains (result , "svc2" ) {
162+ t .Error ("Expected service IDs to be preserved" )
163+ }
164+ if ! strings .Contains (result , "my-service" ) {
165+ t .Error ("Expected service names to be preserved" )
166+ }
167+ },
168+ },
169+ {
170+ name : "does not strip for non-service commands" ,
171+ command : "backend" ,
172+ args : []string {"list" },
173+ output : `[{"id":"b1","versions":[1,2,3]}]` ,
174+ check : func (t * testing.T , result string ) {
175+ if ! strings .Contains (result , "versions" ) {
176+ t .Error ("Expected versions to remain for non-service commands" )
177+ }
178+ },
179+ },
180+ {
181+ name : "does not strip for service describe" ,
182+ command : "service" ,
183+ args : []string {"describe" },
184+ output : `{"id":"svc1","versions":[{"number":1}]}` ,
185+ check : func (t * testing.T , result string ) {
186+ if ! strings .Contains (result , "versions" ) {
187+ t .Error ("Expected versions to remain for service describe" )
188+ }
189+ },
190+ },
191+ {
192+ name : "handles non-JSON output" ,
193+ command : "service" ,
194+ args : []string {"list" },
195+ output : "NAME ID\n my-service svc1\n " ,
196+ check : func (t * testing.T , result string ) {
197+ if result != "NAME ID\n my-service svc1\n " {
198+ t .Error ("Expected non-JSON output to be unchanged" )
199+ }
200+ },
201+ },
202+ {
203+ name : "handles empty output" ,
204+ command : "service" ,
205+ args : []string {"list" },
206+ output : "" ,
207+ check : func (t * testing.T , result string ) {
208+ if result != "" {
209+ t .Error ("Expected empty output to be unchanged" )
210+ }
211+ },
212+ },
213+ {
214+ name : "handles empty args" ,
215+ command : "service" ,
216+ args : []string {},
217+ output : `[{"id":"svc1","versions":[1]}]` ,
218+ check : func (t * testing.T , result string ) {
219+ if ! strings .Contains (result , "versions" ) {
220+ t .Error ("Expected versions to remain when args are empty" )
221+ }
222+ },
223+ },
224+ }
225+
226+ for _ , tt := range tests {
227+ t .Run (tt .name , func (t * testing.T ) {
228+ result := StripHeavyFields (tt .output , tt .command , tt .args )
229+ tt .check (t , result )
230+ })
231+ }
232+ }
233+
144234func TestTruncateOutput (t * testing.T ) {
145235 tests := []struct {
146236 name string
0 commit comments