@@ -261,3 +261,116 @@ func TestCmdSearchSessions_NoMatch(t *testing.T) {
261261 t .Error ("expected handled" )
262262 }
263263}
264+
265+ // ── /trim ─────────────────────────────────────────────────────────────────────
266+
267+ func TestCmdTrim_NoAgent (t * testing.T ) {
268+ ctx := Context {Parts : []string {"/trim" , "3" }}
269+ result := cmdTrim (ctx )
270+ if ! result .Handled {
271+ t .Error ("expected handled" )
272+ }
273+ }
274+
275+ func TestCmdTrim_EmptyContext (t * testing.T ) {
276+ ag := & iteragent.Agent {}
277+ ctx := Context {
278+ Parts : []string {"/trim" , "3" },
279+ Agent : ag ,
280+ }
281+ result := cmdTrim (ctx )
282+ if ! result .Handled {
283+ t .Error ("expected handled" )
284+ }
285+ }
286+
287+ func TestCmdTrim_KeepsLastTurns (t * testing.T ) {
288+ ag := & iteragent.Agent {}
289+ // 8 messages = 4 turns
290+ for i := 0 ; i < 4 ; i ++ {
291+ ag .Messages = append (ag .Messages ,
292+ iteragent.Message {Role : "user" , Content : "q" },
293+ iteragent.Message {Role : "assistant" , Content : "a" },
294+ )
295+ }
296+ ctx := Context {
297+ Parts : []string {"/trim" , "2" },
298+ Agent : ag ,
299+ }
300+ result := cmdTrim (ctx )
301+ if ! result .Handled {
302+ t .Error ("expected handled" )
303+ }
304+ if len (ag .Messages ) > 4 {
305+ t .Errorf ("expected ≤4 messages after trim(2 turns), got %d" , len (ag .Messages ))
306+ }
307+ }
308+
309+ func TestCmdTrim_AlreadySmall (t * testing.T ) {
310+ ag := & iteragent.Agent {}
311+ ag .Messages = []iteragent.Message {
312+ {Role : "user" , Content : "hello" },
313+ {Role : "assistant" , Content : "hi" },
314+ }
315+ ctx := Context {
316+ Parts : []string {"/trim" , "10" },
317+ Agent : ag ,
318+ }
319+ result := cmdTrim (ctx )
320+ if ! result .Handled {
321+ t .Error ("expected handled" )
322+ }
323+ // Messages should be unchanged.
324+ if len (ag .Messages ) != 2 {
325+ t .Errorf ("expected 2 messages, got %d" , len (ag .Messages ))
326+ }
327+ }
328+
329+ // ── /multi nil-context fix ────────────────────────────────────────────────────
330+
331+ func TestCmdMulti_NoReadMultiLine (t * testing.T ) {
332+ ctx := Context {
333+ Parts : []string {"/multi" },
334+ Agent : & iteragent.Agent {},
335+ REPL : REPLCallbacks {},
336+ }
337+ result := cmdMulti (ctx )
338+ if ! result .Handled {
339+ t .Error ("expected handled" )
340+ }
341+ }
342+
343+ func TestCmdMulti_CancelledInput (t * testing.T ) {
344+ ctx := Context {
345+ Parts : []string {"/multi" },
346+ Agent : & iteragent.Agent {},
347+ REPL : REPLCallbacks {
348+ ReadMultiLine : func () (string , bool ) { return "" , false },
349+ },
350+ }
351+ result := cmdMulti (ctx )
352+ if ! result .Handled {
353+ t .Error ("expected handled" )
354+ }
355+ }
356+
357+ func TestCmdMulti_SendsPrompt (t * testing.T ) {
358+ var got string
359+ ctx := Context {
360+ Parts : []string {"/multi" },
361+ Agent : & iteragent.Agent {},
362+ REPL : REPLCallbacks {
363+ ReadMultiLine : func () (string , bool ) { return "line one\n line two" , true },
364+ StreamAndPrint : func (_ context.Context , _ * iteragent.Agent , prompt , _ string ) {
365+ got = prompt
366+ },
367+ },
368+ }
369+ result := cmdMulti (ctx )
370+ if ! result .Handled {
371+ t .Error ("expected handled" )
372+ }
373+ if got != "line one\n line two" {
374+ t .Errorf ("expected prompt forwarded, got %q" , got )
375+ }
376+ }
0 commit comments