Add var-access + edge-case + SSH tests; fix extra_vars leak and ignore_errors bug#5
Merged
Merged
Conversation
Expand test coverage from 88% to 92% and add a real-SSH integration tier, fixing two genuine defects surfaced by the new tests. Bug fixes (src/ansible_host/__init__.py): - extra_vars leaked across instances: Ansible's load_extra_vars() memoizes its dict and VariableManager holds it by reference, so update_extra_vars / the hostvars= constructor path mutated process-global state visible to every other instance. Each instance now copies its own extra_vars. - build_task used `== True` for the legacy module_ignore_errors kwarg, which wrongly accepted 1/1.0 (since 1 == True). Changed to `is True`. Tests: - test_host_vars.py: full variable-access API (get_host_var/get_visible_var, host_vars/visible_vars, extra_vars/update_extra_vars) incl. precedence, template rendering, and cross-instance leak regressions. - test_execution_edge_cases.py: cardinality/inventory errors, multi-task and multi-host failure aggregation, unreachable hosts, NoTasksError, legacy module_ignore_errors, string-args guidance, gather_facts. - test_ssh_integration.py (ssh marker): real SSH transport via a throwaway containerized sshd (tests/ssh/), auto-skipping when no target is configured. CI/docs: - New test-ssh CI job that builds the container and runs the ssh tier. - Register the `ssh` pytest marker; add .gitattributes (LF for *.sh). - README: document the variable-access API and the two test tiers. Validated on Ubuntu 22 (py3.10/ansible-core 2.17) and Ubuntu 24 (py3.12/ansible-core 2.19): full suite + SSH tier green on both. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Xin Wang <xiwang5@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Expands test coverage (88% → 92%) and adds a real-SSH integration tier, fixing two genuine bugs that the new tests surfaced.
Bug fixes
extra_varsleaked across instances. Ansible'sload_extra_vars()memoizes its dict andVariableManagerholds it by reference, soupdate_extra_vars/ thehostvars=constructor path mutated process-global state visible to every other instance. Each instance now copies its ownextra_vars.build_tasklegacymodule_ignore_errorsused== True, which wrongly accepted1/1.0(since1 == Truein Python), contradicting its own comment. Changed tois True.Tests added
test_host_vars.py— full variable-access API (get_host_var/get_visible_var,host_vars/visible_vars,extra_vars/update_extra_vars): host-vs-visible scope, host>group>extra precedence, template rendering, and cross-instance leak regressions.test_execution_edge_cases.py— cardinality/inventory errors, multi-task and multi-host failure aggregation, unreachable hosts,NoTasksError, legacymodule_ignore_errors, string-args guidance,gather_facts.test_ssh_integration.py(sshmarker) — Ansible's real SSH transport via a throwaway containerized sshd intests/ssh/; auto-skips when no target is configured, so the default run stays green.CI / docs
test-sshCI job that builds the container and runs thesshtier.sshpytest marker; added.gitattributes(LF for*.sh).Validation
Ran the full suite and the Docker-backed SSH tier on two boxes:
The version spread also caught two over-specified test assumptions (template native-type, error type), now made version-robust — exactly what the CI matrix protects against.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com