Skip to content

Add Tier-1 integration tests; fix bugs; inline result collector#1

Merged
wangxin merged 4 commits into
mainfrom
tier1-tests-and-callback-refactor
Jun 11, 2026
Merged

Add Tier-1 integration tests; fix bugs; inline result collector#1
wangxin merged 4 commits into
mainfrom
tier1-tests-and-callback-refactor

Conversation

@wangxin

@wangxin wangxin commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

Make the library testable end-to-end without SSH or Docker, fix three bugs the new tests uncovered, and rewrite the README Quickstart to be copy-paste runnable.

Bug fixes

  1. Bundle the result-collecting callback inline (it previously referenced a json_results plugin that only existed in sonic-mgmt).
  2. tqm._stdout_callback was removed in ansible-core 2.19+; append the collector to tqm._callback_plugins directly instead.
  3. json.dumps in _check_failed_results crashed on non-serializable Task instances on ansible-core 2.19+; added default=str.

Tests

30 Tier-1 integration tests using Ansible's local connection — hermetic, no SSH, no Docker. Covers basic execution, dynamic dispatch, batch modes, no_log, forks, multi-host fan-out, the AnsibleHosts container protocol, and per-host failure aggregation.

README

Rewrote the Quickstart so the first snippet actually runs (uses AnsibleLocalhost), added a result-shape matrix, documented failure semantics, and fixed a stale ansible-core<2.20 cap.

Validation

All 17 CI jobs green (lint + Python 3.10–3.13 × ansible-core 2.16–2.21 matrix).

wangxin and others added 4 commits June 11, 2026 14:16
Adds a Tier-1 test suite (30 tests) that exercises the full execution
path (build_task -> TaskQueueManager -> result parsing -> failure
handling) via Ansible's local connection plugin, with no SSH or external
host required.

Fixes three bugs uncovered by the new tests:

1. The 'json_results' stdout callback referenced by _run() was not
   bundled in the standalone package. Replaced with an inline
   _JsonResultsCallback constructed directly (no plugin loader).

2. tqm._stdout_callback was removed in ansible-core 2.19+. The callback
   instance is now appended to tqm._callback_plugins directly, and the
   default 'minimal' stdout callback is evicted after load_callbacks()
   so it does not print to the terminal.

3. json.dumps in _check_failed_results crashed on non-serializable Task
   instances in _task_fields on ansible-core 2.19+. Added default=str.

Test coverage groups:
- Basic execution and dynamic dispatch via __getattr__
- load_module / run_loaded_modules and with-block batch mode
- no_log censoring (with negative control)
- forks fan-out across a 4-host local-connection inventory
- AnsibleHosts container protocol (len, getitem int/str/bad, iter)
- Pattern matching (subset, empty -> NoAnsibleHostError)
- _make_single_host fast-path regression
- Per-host failure aggregation (failures do not drop hosts from results)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xin Wang <wangxin.wang@gmail.com>
The previous negative control asserted SECRET appears in result['invocation'],
which depends on Ansible's interpreter-discovery state and was empty on
Python 3.12/3.13 in CI. Assert SECRET appears anywhere in the serialized
result instead (stdout from echo always has it).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xin Wang <wangxin.wang@gmail.com>
- Lead with AnsibleLocalhost: zero setup (no inventory, no SSH) so
  the first snippet a reader copies actually runs.
- Add inline inventory.ini example for the AnsibleHost path.
- Document the result-shape matrix (single/multi host x single/batch).
- Document AnsibleModuleFailed + ignore_errors failure semantics.
- Expand task_directives coverage (ignore_errors, no_log, when,
  failed_when, changed_when, become).
- Show AnsibleHosts container protocol (len, getitem, iter).
- Link to tests/test_local_integration.py as runnable examples.
- Fix stale ansible-core version cap: <2.20 -> <2.22.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xin Wang <wangxin.wang@gmail.com>
Adds a short note pointing out that `with host:` is lexically scoped, and
that `load_module` + `run_loaded_modules` is the explicit form for
assembling a batch across multiple functions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xin Wang <wangxin.wang@gmail.com>
@wangxin wangxin merged commit e469194 into main Jun 11, 2026
17 checks passed
@wangxin wangxin deleted the tier1-tests-and-callback-refactor branch June 11, 2026 06:46
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