Skip to content

Add var-access + edge-case + SSH tests; fix extra_vars leak and ignore_errors bug#5

Merged
wangxin merged 1 commit into
mainfrom
tests-and-extravars-fix
Jun 12, 2026
Merged

Add var-access + edge-case + SSH tests; fix extra_vars leak and ignore_errors bug#5
wangxin merged 1 commit into
mainfrom
tests-and-extravars-fix

Conversation

@wangxin

@wangxin wangxin commented Jun 12, 2026

Copy link
Copy Markdown
Owner

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_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 legacy module_ignore_errors used == True, which wrongly accepted 1/1.0 (since 1 == True in Python), contradicting its own comment. Changed to is 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, legacy module_ignore_errors, string-args guidance, gather_facts.
  • test_ssh_integration.py (ssh marker) — Ansible's real SSH transport via a throwaway containerized sshd in tests/ssh/; auto-skips when no target is configured, so the default run stays green.

CI / docs

  • New test-ssh CI job that builds the container and runs the ssh tier.
  • Registered the ssh pytest marker; added .gitattributes (LF for *.sh).
  • README: documented the variable-access API and the two test tiers.

Validation

Ran the full suite and the Docker-backed SSH tier on two boxes:

Ubuntu 22 Ubuntu 24
Python / ansible-core 3.10 / 2.17.14 3.12 / 2.19.10
Full suite 79 ✓ 79 ✓
SSH tier 6 ✓ 6 ✓

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

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>
@wangxin wangxin merged commit 61f51eb into main Jun 12, 2026
18 checks passed
@wangxin wangxin deleted the tests-and-extravars-fix branch June 12, 2026 06:26
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.

1 participant