fix(console): 콘솔 없는 실행에서 확인 프롬프트가 무한 대기하던 문제 수정

Symfony 는 posix_isatty 로 비대화 실행을 감지해 isInteractive 를 false 로
내리는데, Windows PHP 에는 posix 확장이 없어 그 분기가 실행되지 않는다. 그래서
--no-interaction 없이 CI·스케줄러·에이전트에서 부르면 isInteractive 가 true 로
남고 ask 가 오지 않을 응답을 무한히 기다린다. 프롬프트 출력마저 버퍼에 갇혀
예외도 로그도 없이 "커맨드가 느리다" 로만 관측된다.

posix 없이도 동작하는 stream_isatty 로 한 번 더 판정한다. 판단 재료가 없으면
질문하는 쪽으로 떨어진다 — 물어볼 수 있는데 안 묻는 것이 더 위험하기 때문이다.

이 트레이트를 공유하는 13개 커맨드의 기본값을 전수 확인했다. 파괴적 확인은
모두 false(중단)이고 true 는 search:index --repair 하나뿐이라, 확인 없이
파괴적 동작이 수행되는 경로는 생기지 않는다.

문서는 이미 "비TTY → default 즉시 반환" 을 계약으로 명시하고 있었다 —
구현이 그 계약을 Windows 에서 지키지 못한 것이다.
This commit is contained in:
HeuJung committed 2026-08-12 10:53:04 +09:00
1 parent 7765695339
commit b44f2befd7
4 files changed
+104 -6

No files matched your search

@@ -134,19 +134,64 @@ class HasUnifiedConfirmTest extends TestCase
$this->assertStringContainsString('진행할까요? (yes/no) [yes]:', $display);
}
private function makeTester(bool $default): CommandTester
/**
* 응답을 받을 수 없는 실행에서는 질문하지 않고 기본값을 돌려준다.
*
* Symfony 는 `posix_isatty()` 로 비대화 실행을 자동 감지하는데 Windows PHP 에는
* posix 확장이 없어 그 분기가 실행되지 않는다. 그래서 `--no-interaction` 없이
* 에이전트·CI·스케줄러에서 부르면 `isInteractive()` 가 true 로 남아 `ask()` 가
* 응답을 기다리며 무한 대기한다. 출력도 남지 않아 "명령이 느리다" 로만 보인다.
*/
public function test_returns_default_without_asking_when_prompt_cannot_be_answered(): void
{
$command = new class($default) extends Command
$tester = $this->makeTester(true, canPrompt: false);
$tester->execute([]);
$display = $tester->getDisplay();
$this->assertSame('true', trim($display));
$this->assertStringNotContainsString('진행할까요?', $display);
}
/**
* 기본값이 false 인 파괴적 확인은 응답을 받을 수 없을 때 중단으로 떨어져야 한다.
*/
public function test_returns_false_default_without_asking_when_prompt_cannot_be_answered(): void
{
$tester = $this->makeTester(false, canPrompt: false);
$tester->execute([]);
$display = $tester->getDisplay();
$this->assertSame('false', trim($display));
$this->assertStringNotContainsString('진행할까요?', $display);
}
/**
* @param bool $default 프롬프트 기본값
* @param bool|null $canPrompt 응답 가능 여부 강제 (null 이면 실제 판정 사용)
*/
private function makeTester(bool $default, ?bool $canPrompt = null): CommandTester
{
$command = new class($default, $canPrompt) extends Command
{
use HasUnifiedConfirm;
// 트레이트 메서드는 parent:: 로 부를 수 없어 별칭으로 원 구현을 남긴다
use HasUnifiedConfirm {
canPromptForAnswer as private traitCanPromptForAnswer;
}
protected $signature = 'test:unified-confirm';
public function __construct(private bool $defaultValue)
public function __construct(private bool $defaultValue, private ?bool $canPrompt = null)
{
parent::__construct();
}
protected function canPromptForAnswer(): bool
{
return $this->canPrompt ?? $this->traitCanPromptForAnswer();
}
public function handle(): int
{
$result = $this->unifiedConfirm('진행할까요?', $this->defaultValue);