Skip to content

Separate ingestion of environment from fmf keys and CLI options#4968

Draft
happz wants to merge 2 commits into
mainfrom
plan-cli-environment
Draft

Separate ingestion of environment from fmf keys and CLI options#4968
happz wants to merge 2 commits into
mainfrom
plan-cli-environment

Conversation

@happz

@happz happz commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
  • they will have different position in the list of sources ordered by precedence,
  • the CLI input is used twice, both from run and from plan, while it will be owned by the run only.

Pull Request Checklist

  • implement the feature

* they will have different position in the list of sources ordered by
  precedence,
* the CLI input is used twice, both from run and from plan, while it
  will be owned by the run only.
@happz happz added this to planning Jun 8, 2026
@happz happz added area | environment Environment variables handling ci | full test Pull request is ready for the full test execution labels Jun 8, 2026
@github-project-automation github-project-automation Bot moved this to backlog in planning Jun 8, 2026
@happz happz moved this from backlog to implement in planning Jun 8, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors environment variable extraction by replacing the unified Environment.from_inputs method with dedicated from_fmf_keys and from_cli_options methods, alongside updating type annotations in tmt/utils/__init__.py. In tmt/base/plan.py, casting environment-file directly to list[str] can cause runtime bugs if a single string is provided. Normalize environment-file using tmt.utils.normalize_string_list and validate that environment is a dictionary before passing them to from_fmf_keys.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tmt/base/plan.py
Comment on lines +490 to 496
return Environment.from_fmf_keys(
raw_fmf_environment_files=cast(Optional[list[str]], self.node.get("environment-file"))
or [],
raw_fmf_environment=cast(Optional[dict[str, Any]], self.node.get('environment')) or {},
file_root=Path(self.node.root) if self.node.root else None, # pyright: ignore[reportUnknownVariableType, reportUnknownArgumentType]
key_address=self.node.name, # pyright: ignore[reportUnknownVariableType, reportUnknownArgumentType]
logger=self._logger,
)

@property
def _environment_from_cli(self) -> Environment:
"""
Environment variables from ``--environment`` and ``--environment-file`` options.
"""

return Environment.from_inputs(
raw_cli_environment_files=self.opt('environment-file') or [],
raw_cli_environment=self.opt('environment'),
file_root=Path(self.node.root) if self.node.root else None, # pyright: ignore[reportUnknownVariableType, reportUnknownArgumentType]
key_address=self.node.name, # pyright: ignore[reportUnknownVariableType, reportUnknownArgumentType]
logger=self._logger,
)

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.

critical

Normalize environment-file using tmt.utils.normalize_string_list and validate environment is a dictionary. Casting a string to list[str] causes runtime bugs as from_files will iterate over characters of the filename string.

        raw_fmf_environment_files = tmt.utils.normalize_string_list(
            f'{self.node.name}:environment-file',
            self.node.get("environment-file"),
            self._logger,
        )
        raw_fmf_environment = self.node.get('environment')
        if raw_fmf_environment is None:
            raw_fmf_environment = {}
        elif not isinstance(raw_fmf_environment, dict):
            raise tmt.utils.NormalizationError(
                f'{self.node.name}:environment',
                raw_fmf_environment,
                'unset or a dictionary',
            )

        return Environment.from_fmf_keys(
            raw_fmf_environment_files=raw_fmf_environment_files,
            raw_fmf_environment=raw_fmf_environment,
            file_root=Path(self.node.root) if self.node.root else None,  # pyright: ignore[reportUnknownVariableType, reportUnknownArgumentType]
            logger=self._logger,
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area | environment Environment variables handling ci | full test Pull request is ready for the full test execution

Projects

Status: implement

Development

Successfully merging this pull request may close these issues.

1 participant