From 3fd9fbb9833a0cac6ce17acd560e2678b7648640 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Thu, 9 Jul 2026 11:02:00 +0100 Subject: [PATCH 1/2] fix(variable:create): resolve "-e ." default-environment placeholder 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) --- integration-tests/variable_write_test.go | 18 ++++++++++++++++++ .../Command/Variable/VariableCreateCommand.php | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/integration-tests/variable_write_test.go b/integration-tests/variable_write_test.go index b3f5be3b..5064d047 100644 --- a/integration-tests/variable_write_test.go +++ b/integration-tests/variable_write_test.go @@ -98,6 +98,24 @@ func TestVariableCreate(t *testing.T) { assertTrimmed(t, "false", f.Run("var:get", "-p", p, "env:TEST", "-l", "p", "-P", "visible_runtime")) } +func TestVariableCreateDefaultEnvironment(t *testing.T) { + // Regression test for CLI-164: using "-e ." (the default-environment code) + // must not fail form validation of the --environment option. + s := setupVariableTest(t) + s.apiHandler.SetEnvironments([]*mockapi.Environment{s.mainEnv}) + + f, p := s.factory, s.projectID + + //nolint:lll + _, stdErr, err := f.RunCombinedOutput("var:create", "-p", p, "-e", ".", "-l", "e", "env:FOOBAR", "--value", "bar foo") + assert.NoError(t, err) + assert.Contains(t, stdErr, "Selecting default environment") + assert.Contains(t, stdErr, "Creating variable env:FOOBAR on the environment main") + assert.NotContains(t, stdErr, "is not one of") + + assertTrimmed(t, "bar foo", f.Run("var:get", "-p", p, "-e", "main", "env:FOOBAR", "-P", "value")) +} + func TestVariableCreateWithAppScope(t *testing.T) { s := setupVariableTest(t) diff --git a/legacy/src/Command/Variable/VariableCreateCommand.php b/legacy/src/Command/Variable/VariableCreateCommand.php index 2e2ce2b5..aa425cdb 100644 --- a/legacy/src/Command/Variable/VariableCreateCommand.php +++ b/legacy/src/Command/Variable/VariableCreateCommand.php @@ -64,6 +64,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int $selection = $this->selector->getSelection($input, new SelectorConfig(envRequired: false)); $this->selection = $selection; + // The 'environment' form field validates the --environment option + // against the list of environment IDs. Replace the default-environment + // placeholder ('.') with the resolved environment ID so validation + // succeeds. See CLI-164. + if ($selection->hasEnvironment() && $input->getOption('environment') === Selector::DEFAULT_ENVIRONMENT_CODE) { + $input->setOption('environment', $selection->getEnvironment()->id); + } + // Merge the 'name' argument with the --name option. if ($input->getArgument('name')) { if ($input->getOption('name')) { From abf79a8eee64da6f1099a5df57759b2388ca4e94 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Thu, 9 Jul 2026 11:05:02 +0100 Subject: [PATCH 2/2] fix(test): remove unused //nolint:lll directive 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) --- integration-tests/variable_write_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integration-tests/variable_write_test.go b/integration-tests/variable_write_test.go index 5064d047..2a4be8c0 100644 --- a/integration-tests/variable_write_test.go +++ b/integration-tests/variable_write_test.go @@ -106,7 +106,6 @@ func TestVariableCreateDefaultEnvironment(t *testing.T) { f, p := s.factory, s.projectID - //nolint:lll _, stdErr, err := f.RunCombinedOutput("var:create", "-p", p, "-e", ".", "-l", "e", "env:FOOBAR", "--value", "bar foo") assert.NoError(t, err) assert.Contains(t, stdErr, "Selecting default environment")