@@ -222,4 +222,60 @@ func TestLocalComposeRun(t *testing.T) {
222
222
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/run-test/compose.yaml" , "run" , "build" , "echo" , "hello world" )
223
223
res .Assert (t , icmd.Expected {Out : "hello world" })
224
224
})
225
+
226
+ t .Run ("compose run with piped input detection" , func (t * testing.T ) {
227
+ if composeStandaloneMode {
228
+ t .Skip ("Skipping test compose with piped input detection in standalone mode" )
229
+ }
230
+ // Test that piped input is properly detected and TTY is automatically disabled
231
+ // This tests the logic added in run.go that checks dockerCli.In().IsTerminal()
232
+ cmd := c .NewCmd ("sh" , "-c" , "echo 'piped-content' | docker compose -f ./fixtures/run-test/piped-test.yaml run --rm piped-test" )
233
+ res := icmd .RunCmd (cmd )
234
+
235
+ res .Assert (t , icmd.Expected {Out : "piped-content" })
236
+ res .Assert (t , icmd .Success )
237
+ })
238
+
239
+ t .Run ("compose run piped input should not allocate TTY" , func (t * testing.T ) {
240
+ if composeStandaloneMode {
241
+ t .Skip ("Skipping test compose with piped input detection in standalone mode" )
242
+ }
243
+ // Test that when stdin is piped, the container correctly detects no TTY
244
+ // This verifies that the automatic noTty=true setting works correctly
245
+ cmd := c .NewCmd ("sh" , "-c" , "echo '' | docker compose -f ./fixtures/run-test/piped-test.yaml run --rm tty-test" )
246
+ res := icmd .RunCmd (cmd )
247
+
248
+ res .Assert (t , icmd.Expected {Out : "No TTY detected" })
249
+ res .Assert (t , icmd .Success )
250
+ })
251
+
252
+ t .Run ("compose run piped input with explicit --tty should fail" , func (t * testing.T ) {
253
+ if composeStandaloneMode {
254
+ t .Skip ("Skipping test compose with piped input detection in standalone mode" )
255
+ }
256
+ // Test that explicitly requesting TTY with piped input fails with proper error message
257
+ // This should trigger the "input device is not a TTY" error
258
+ cmd := c .NewCmd ("sh" , "-c" , "echo 'test' | docker compose -f ./fixtures/run-test/piped-test.yaml run --rm --tty piped-test" )
259
+ res := icmd .RunCmd (cmd )
260
+
261
+ res .Assert (t , icmd.Expected {
262
+ ExitCode : 1 ,
263
+ Err : "the input device is not a TTY" ,
264
+ })
265
+ })
266
+
267
+ t .Run ("compose run piped input with --no-TTY=false should fail" , func (t * testing.T ) {
268
+ if composeStandaloneMode {
269
+ t .Skip ("Skipping test compose with piped input detection in standalone mode" )
270
+ }
271
+ // Test that explicitly disabling --no-TTY (i.e., requesting TTY) with piped input fails
272
+ // This should also trigger the "input device is not a TTY" error
273
+ cmd := c .NewCmd ("sh" , "-c" , "echo 'test' | docker compose -f ./fixtures/run-test/piped-test.yaml run --rm --no-TTY=false piped-test" )
274
+ res := icmd .RunCmd (cmd )
275
+
276
+ res .Assert (t , icmd.Expected {
277
+ ExitCode : 1 ,
278
+ Err : "the input device is not a TTY" ,
279
+ })
280
+ })
225
281
}
0 commit comments