Skip to content

fix(variable:create): resolve "-e ." default-environment placeholder#125

Open
pjcdawkins wants to merge 2 commits into
mainfrom
cli-164-using-e-for-variablecreate-throws-exception
Open

fix(variable:create): resolve "-e ." default-environment placeholder#125
pjcdawkins wants to merge 2 commits into
mainfrom
cli-164-using-e-for-variablecreate-throws-exception

Conversation

@pjcdawkins

Copy link
Copy Markdown
Contributor

Problem

Creating a variable with -e . selected the default environment correctly, then crashed:

Selecting default environment (indicated by .)
Selected environment: main (type: production)

In Field.php line 252:

  . is not one of: dev1, dirauthtest, main, production

Cause

variable:create builds a ConsoleForm whose environment field is an OptionsField. During resolveOptions() the form re-reads the raw --environment option value (.) and validates it against the list of real environment IDs, before normalization. The selector had already resolved . to the default environment, but the form validated the literal placeholder and threw.

variable:update is not affected — it unsets the environment field from its form.

Fix

After the selector resolves the selection, replace the default-environment placeholder (.) in the --environment option with the resolved environment ID, so the form validates a real ID. Guarded on the value being exactly the placeholder, so explicit environment names and the no--e case are untouched.

Added an integration test (TestVariableCreateDefaultEnvironment) that reproduces the crash and confirms the variable is created on the default environment.

🤖 Generated with Claude Code

Creating a variable with `-e .` selected the default environment
correctly, then crashed with `In Field.php line 252: . is not one of:
...`.

The command builds a ConsoleForm whose `environment` field validates the
`--environment` option against the list of real environment IDs before
normalization. The selector had already resolved `.` to the default
environment, but the form validated the literal placeholder.

Replace the default-environment placeholder in the `--environment` option
with the resolved environment ID after selection, so the form validates a
real ID.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 9, 2026 10:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in variable:create when users select the default environment via -e . by normalizing the placeholder value (.) to the resolved environment ID before ConsoleForm option validation runs.

Changes:

  • Normalize --environment from the default-environment placeholder (.) to the resolved environment ID after selection, preventing OptionsField validation from rejecting ..
  • Add an integration regression test covering var:create -e . and verifying the variable is created on the default environment.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
legacy/src/Command/Variable/VariableCreateCommand.php Rewrites --environment from . to the resolved environment ID after selector resolution so form validation uses a real environment ID.
integration-tests/variable_write_test.go Adds a regression test ensuring var:create -e . does not fail validation and creates the variable on the default environment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The command line is within the length limit, so the directive was flagged
as unused by nolintlint.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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