fix(review): keep tests non-interactive by default · Entire

fix(review): keep tests non-interactive by default

114562a→main·

dipree·3d ago·2 files·+42 added/-3 removed

Sessions

01KXGSRY52644B5B6A7CKHQV4BView transcript

[?
Fix Review Interactive Setup and DefaultsPi·GPT-5.6-sol·1 step](/content/gh/entireio/cli/session/019f60f0-7ee7-73b0-b787-4c8cbc646802#timeline-01KXGSRY52644B5B6A7CKHQV4B/index.html)

Changes

2

276 unmodified lines

277
278
279
280
281
282
280
281
282
283
284
285
286
287
1 unmodified line

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304

276 unmodified lines

// Bubble Tea to accept keypresses. A controlling /dev/tty alone is insufficient
// because the command may still have piped stdin.
func reviewCommandIsInteractive(cmd *cobra.Command) bool {
    testTTY := os.Getenv(interactive.EnvTestTTY)
    ci := os.Getenv("CI")
    hardDisabled := (testTTY != "" && testTTY != "1") || (ci != "" && ci != "false")
    hardDisabled := reviewInteractivityHardDisabled(
        os.Getenv(interactive.EnvTestTTY),
        os.Getenv("CI"),
        interactive.UnderTest(),
    )
    return reviewTTYIsInteractive(
        interactive.IsTerminalReader(cmd.InOrStdin()),
        interactive.IsTerminalWriter(cmd.OutOrStdout()),
    1 unmodified line

)
}

func reviewInteractivityHardDisabled(testTTY, ci string, underTest bool) bool {
    // Match CanPromptInteractively's precedence: ENTIRE_TEST_TTY=1 may opt an
    // in-process test into interaction, while tests without that explicit
    // override must never read from a developer's real terminal.
    if testTTY != "" {
        return testTTY != "1"
    }
    return underTest || (ci != "" && ci != "false")
}

func reviewTTYIsInteractive(stdinTTY, stdoutTTY, hardDisabled bool) bool {
    return !hardDisabled && stdinTTY && stdoutTTY
}

Mcmd/entire/cli/review/cmd.go+15/-3

87 unmodified lines

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

87 unmodified lines

}
}

func TestReviewInteractivityHardDisabled(t *testing.T) {
    t.Parallel()

tests := []struct {
        name      string
        testTTY   string
        ci        string
        underTest bool
        want      bool
    }{
        {name: "go test defaults off", underTest: true, want: true},
        {name: "test override enables", testTTY: "1", ci: "true", underTest: true, want: false},
        {name: "test override disables", testTTY: "0", want: true},
        {name: "CI disables", ci: "true", want: true},
        {name: "CI false does not disable", ci: "false", want: false},
        {name: "normal process", want: false},
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            t.Parallel()
            if got := reviewInteractivityHardDisabled(tt.testTTY, tt.ci, tt.underTest); got != tt.want {
                t.Fatalf("reviewInteractivityHardDisabled(%q, %q, %v) = %v, want %v", tt.testTTY, tt.ci, tt.underTest, got, tt.want)
            }
        })
    }
}

func TestReviewTTYIsInteractive(t *testing.T) {
    t.Parallel()