Files
computer-playbook/tests/unit/cli/deploy/dedicated/test_command_passthrough.py
T
kevinveenbirkenbach ea63818216 refactor(cli): simplify dedicated deploy wrapper and add ansible passthrough support
- Remove unused cli_root and logs handling from dedicated deploy wrapper
- Add parse_known_args() to forward native ansible-playbook flags
- Append passthrough args at the end for proper override behavior
- Clean up MODE_LOGS usage
- Update runner signature and cleanup phase logic
- Adapt unit tests to new wrapper contract
- Add unit test for ansible flag passthrough in command.main()

https://chatgpt.com/share/69694ad5-453c-800f-8047-cf210f60460f
2026-01-15 21:15:06 +01:00

73 lines
2.6 KiB
Python

from __future__ import annotations
import unittest
from unittest import mock
from cli.deploy.dedicated import command as dedicated_command
class TestDedicatedCommandPassthrough(unittest.TestCase):
@mock.patch("cli.deploy.dedicated.command.validate_application_ids")
@mock.patch("cli.deploy.dedicated.command.run_ansible_playbook")
@mock.patch("cli.deploy.dedicated.command.load_modes_from_yaml")
@mock.patch("cli.deploy.dedicated.command.add_dynamic_mode_args")
@mock.patch("cli.deploy.dedicated.command.build_modes_from_args")
def test_main_passes_unknown_ansible_args_through(
self,
mock_build_modes_from_args,
mock_add_dynamic_mode_args,
mock_load_modes_from_yaml,
mock_run_ansible_playbook,
mock_validate_application_ids,
):
# Make dynamic modes a no-op for this test
mock_load_modes_from_yaml.return_value = []
mock_add_dynamic_mode_args.return_value = {}
mock_build_modes_from_args.return_value = {}
argv = [
"/etc/inventories/github-ci/servers.yml",
"--host-type",
"workstation",
"--diff",
# passthrough args (unknown to wrapper parser)
"--tags",
"deploy",
"--check",
"-e",
"FOO=bar",
]
rc = dedicated_command.main(argv)
self.assertEqual(rc, 0)
# validate_application_ids should be called with inventory + ids (empty list here)
mock_validate_application_ids.assert_called_once()
called_inventory, called_ids = mock_validate_application_ids.call_args.args
self.assertEqual(called_inventory, "/etc/inventories/github-ci/servers.yml")
self.assertEqual(called_ids, [])
# run_ansible_playbook must be called once with ansible_args passthrough
mock_run_ansible_playbook.assert_called_once()
kwargs = mock_run_ansible_playbook.call_args.kwargs
self.assertEqual(kwargs["inventory"], "/etc/inventories/github-ci/servers.yml")
self.assertTrue(kwargs["diff"])
# host_type must be forwarded via modes
self.assertIn("modes", kwargs)
self.assertEqual(kwargs["modes"].get("host_type"), "workstation")
# Ensure old MODE_LOGS is not reintroduced
self.assertNotIn("MODE_LOGS", kwargs["modes"])
# Passthrough args must be preserved in order
self.assertEqual(
kwargs["ansible_args"],
["--tags", "deploy", "--check", "-e", "FOO=bar"],
)
if __name__ == "__main__":
unittest.main()