@@ -37,6 +37,37 @@ func TestSessionCurrent_NoSessionsPrintsHint(t *testing.T) {
3737 }
3838}
3939
40+ // Machine-readable modes must keep stdout parseable: with --json and no
41+ // active session, the hint text goes to stderr and the command exits
42+ // non-zero, instead of printing prose to stdout with exit 0 (which crashed
43+ // downstream JSON parsers in the review runner sandboxes).
44+ func TestSessionCurrent_JSONNoSessionErrorsWithCleanStdout (t * testing.T ) {
45+ // t.Chdir cannot coexist with t.Parallel; this test mutates process CWD.
46+ dir := t .TempDir ()
47+ testutil .InitRepo (t , dir )
48+ t .Chdir (dir )
49+
50+ for _ , flag := range []string {"--json" , "--transcript" } {
51+ cmd := newSessionCurrentCmd ()
52+ var stdout , stderr bytes.Buffer
53+ cmd .SetOut (& stdout )
54+ cmd .SetErr (& stderr )
55+ cmd .SetContext (context .Background ())
56+ cmd .SetArgs ([]string {flag })
57+
58+ err := cmd .Execute ()
59+ if err == nil {
60+ t .Errorf ("%s: expected non-zero exit when no session exists" , flag )
61+ }
62+ if stdout .Len () != 0 {
63+ t .Errorf ("%s: stdout must stay clean for parsers, got: %q" , flag , stdout .String ())
64+ }
65+ if ! strings .Contains (stderr .String (), "No active session" ) {
66+ t .Errorf ("%s: expected 'No active session' on stderr, got: %q" , flag , stderr .String ())
67+ }
68+ }
69+ }
70+
4071func TestSessionCurrent_JSONPrintsCurrentSessionInfo (t * testing.T ) {
4172 // t.Chdir cannot coexist with t.Parallel; this test mutates process CWD.
4273 dir := t .TempDir ()
0 commit comments