Skip to content

Exit env-kit.edit cleanly when there is no terminal - #26

Merged
imanimanyara merged 1 commit into
mainfrom
fix/edit-command-fails-fast-without-tty
Oct 13, 2026
Merged

imanimanyara merged 1 commit into
mainfrom
fix/edit-command-fails-fast-without-tty

Conversation

@imanimanyara

Copy link
Copy Markdown
Member

Summary

When laranail::env-kit.edit runs with no terminal (cron, a CI step, a pipe), it fails with an uncaught Laravel\Prompts\Exceptions\NonInteractiveValidationException: Required. and a stack trace. Without a TTY, laravel/prompts returns each prompt's default instead of asking. The editor's first select() has no default, so its required validation throws.

  • EditCommand::handle() now checks canPrompt() first. Input must be interactive, which rules out --no-interaction and covers Symfony's own no-TTY detection. Prompts must also be able to ask: either Laravel's question-helper fallback is active (Windows, the test harness) or stdin is a terminal, which is the same check laravel/prompts makes.
  • When it cannot prompt, the command writes laranail::env-kit.edit needs an interactive terminal. To change keys without one, use laranail::env-kit.set, laranail::env-kit.unset or laranail::env-kit.rename., changes nothing, and exits 2 (EXIT_USAGE, from the documented exit-code contract). The editor has no --key/--value flags; those three commands are the non-interactive path.
  • The interactive path is unchanged. All existing TUI tests pass as before, including the --force-production one.
  • CHANGELOG [Unreleased] has a Fixed entry. docs/tools/tui.md has a new "Without a terminal" section.

Tests (tests/Feature/TuiTest.php)

  • --no-interaction via artisan(): asserts the full message, exit code 2, no "Closed EnvKit editor.", and the file is unchanged.
  • Real no-TTY run: a worker process boots a testbench app in the local environment, so Laravel does not answer prompts for the user. It runs the command through Kernel::handle() with stdin set to /dev/null. The test asserts the message, that Required. is absent, exit status 2, and that the file is unchanged. It is skipped without POSIX/proc_open, the same as ConcurrencyTest.

Fail-first, against the old EditCommand:

  • the subprocess output was NonInteractiveValidationException ... Required.;
  • the -n case tried to prompt (askQuestion(), but no expectations were specified);
  • the 8 existing tests passed.

Local: pest 541 passed, phpstan clean, and pint clean against package-tools' pint.json. Rector is not configured in this repository (no rector.php, and not in CI), so it was not run.

With stdin not a terminal, laravel/prompts returns each prompt's
default, and the editor's menu has none, so the first select() threw
NonInteractiveValidationException: Required. Check up front instead:
under --no-interaction or with no terminal, name the set, unset and
rename commands, change nothing, and exit 2.
Copilot AI balanced review requested due to automatic review settings October 13, 2026 13:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@imanimanyara
imanimanyara merged commit ab1b5e2 into main Oct 13, 2026
5 checks passed
@imanimanyara
imanimanyara deleted the fix/edit-command-fails-fast-without-tty branch November 1, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants