mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-07 03:15:56 +00:00
Module moves (with imports, paths, argv literals, scripts, docs, and
parents[N] formulas updated in lockstep):
- cli/deploy -> cli/administration/deploy
- cli/validate/inventory -> cli/administration/inventory/validate
- cli/vault -> cli/administration/secrets/vault
- cli/administration/inventory/encrypt -> cli/administration/secrets/seal
- cli/mirror -> cli/contributing/mirror
The new cli/administration/secrets cluster collocates the whole-file
ansible-vault wrapper next to the inventory-aware per-field sealer.
The user-facing CLI subcommand paths follow the package layout, e.g.
"infinito administration deploy dedicated <inv>" and
"infinito administration inventory validate <inv>".
Help system redesign in cli/core/{discovery,help,app}.py:
- Discovery now distinguishes runnable commands (directories with
__main__.py) from category folders (directories that only group
further commands). Empty support packages are filtered out.
- Each category folder MAY carry a README.md; its H1 heading is used
as the title and its first paragraph as the one-line description in
the help output.
- "infinito" / "infinito --help" prints only the top-level entries
(one level deep). "infinito <category>" navigates into a folder and
shows its sub-folders and commands one level deep, with the README
title as the page heading and the invocation as a dim subtitle.
- New "--tree [N]" flag walks the tree under the (optional) path
prefix recursively. N caps the depth (1-based); omit N for an
unbounded walk. The output uses Unicode tree connectors, an emoji
per entry (folder for categories, gear for commands), a globally
aligned description column, and multi-line wrapped descriptions
with tree-continuity bars on continuation lines.
- Category and command listings use the full invocation
("infinito meta callorder") rather than the bare leaf name, so the
output is copy-pasteable.
Convention doc + 17 CLI READMEs:
- New docs/contributing/artefact/files/cli/readme_md.md describes the
H1+paragraph layout the help system reads, and how it differs from
role/docs READMEs.
- README.md added for cli/{administration, build, contributing, meta}
and their immediate sub-folders, plus cli/meta/roles/applications
and its resolution sub-folder. Each follows the "title with trailing
emoji + single descriptive paragraph" convention.
Mirror resolver/sync description strings (the help system reads them
from argparse --help output) added so they no longer surface as
"options:" in the global index. cli/mirror/cleanup already had a
description and is unchanged.
Fixes uncovered by the move:
- import unittest.mock added to four dedicated-deploy tests so
unittest.mock.patch resolves under stdlib unittest discovery
(Python 3.13 no longer surfaces unittest.mock through "import
unittest" alone).
- parents[N] index in the new
cli/administration/inventory/validate/__init__.py corrected from
3 to 4 to match the deeper layout.
- test_paths.INVENTORY_VALIDATOR_PATH assertion and test_runner
substring assertions updated to match the new validator path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
141 lines
4.8 KiB
Python
141 lines
4.8 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from cli.administration.deploy.dedicated import modes
|
|
|
|
|
|
class TestParseBoolLiteral(unittest.TestCase):
|
|
def test_true_values(self):
|
|
self.assertTrue(modes._parse_bool_literal("true"))
|
|
self.assertTrue(modes._parse_bool_literal("True"))
|
|
self.assertTrue(modes._parse_bool_literal(" yes "))
|
|
self.assertTrue(modes._parse_bool_literal("ON"))
|
|
|
|
def test_false_values(self):
|
|
self.assertFalse(modes._parse_bool_literal("false"))
|
|
self.assertFalse(modes._parse_bool_literal("False"))
|
|
self.assertFalse(modes._parse_bool_literal(" no "))
|
|
self.assertFalse(modes._parse_bool_literal("off"))
|
|
|
|
def test_unknown_value(self):
|
|
self.assertIsNone(modes._parse_bool_literal("maybe"))
|
|
self.assertIsNone(modes._parse_bool_literal(""))
|
|
self.assertIsNone(modes._parse_bool_literal(" "))
|
|
|
|
|
|
class TestLoadModesFromYaml(unittest.TestCase):
|
|
def test_load_modes_basic(self):
|
|
content = """\
|
|
MODE_CLEANUP: true # cleanup before deploy
|
|
MODE_DEBUG: false # debug output
|
|
MODE_ASSERT: null # inventory assertion
|
|
OTHER_KEY: true # should be ignored (no MODE_ prefix)
|
|
"""
|
|
|
|
with tempfile.NamedTemporaryFile("w+", delete=False, encoding="utf-8") as f:
|
|
path = f.name
|
|
f.write(content)
|
|
f.flush()
|
|
|
|
try:
|
|
parsed = modes.load_modes_from_yaml(path)
|
|
finally:
|
|
Path(path).unlink()
|
|
|
|
self.assertEqual(len(parsed), 3)
|
|
by_name = {m["name"]: m for m in parsed}
|
|
|
|
self.assertIn("MODE_CLEANUP", by_name)
|
|
self.assertIn("MODE_DEBUG", by_name)
|
|
self.assertIn("MODE_ASSERT", by_name)
|
|
|
|
self.assertEqual(by_name["MODE_CLEANUP"]["default"], True)
|
|
self.assertEqual(by_name["MODE_DEBUG"]["default"], False)
|
|
self.assertIsNone(by_name["MODE_ASSERT"]["default"])
|
|
self.assertEqual(by_name["MODE_CLEANUP"]["help"], "cleanup before deploy")
|
|
|
|
def test_load_modes_ignores_non_mode_keys(self):
|
|
content = """\
|
|
FOO: true
|
|
BAR: false
|
|
MODE_FOO: true
|
|
"""
|
|
|
|
with tempfile.NamedTemporaryFile("w+", delete=False, encoding="utf-8") as f:
|
|
path = f.name
|
|
f.write(content)
|
|
f.flush()
|
|
|
|
try:
|
|
parsed = modes.load_modes_from_yaml(path)
|
|
finally:
|
|
Path(path).unlink()
|
|
|
|
self.assertEqual(len(parsed), 1)
|
|
self.assertEqual(parsed[0]["name"], "MODE_FOO")
|
|
|
|
|
|
class TestDynamicModes(unittest.TestCase):
|
|
def setUp(self):
|
|
self.modes_meta = [
|
|
{"name": "MODE_CLEANUP", "default": True, "help": "Cleanup before run"},
|
|
{"name": "MODE_DEBUG", "default": False, "help": "Debug output"},
|
|
{"name": "MODE_ASSERT", "default": None, "help": "Inventory assertion"},
|
|
]
|
|
|
|
def test_add_dynamic_mode_args_and_build_modes_defaults(self):
|
|
from argparse import ArgumentParser
|
|
|
|
parser = ArgumentParser()
|
|
spec = modes.add_dynamic_mode_args(parser, self.modes_meta)
|
|
|
|
self.assertIn("MODE_CLEANUP", spec)
|
|
self.assertIn("MODE_DEBUG", spec)
|
|
self.assertIn("MODE_ASSERT", spec)
|
|
|
|
# No flags passed → defaults apply
|
|
args = parser.parse_args([])
|
|
resolved = modes.build_modes_from_args(spec, args)
|
|
|
|
self.assertTrue(resolved["MODE_CLEANUP"]) # default True
|
|
self.assertFalse(resolved["MODE_DEBUG"]) # default False
|
|
self.assertNotIn("MODE_ASSERT", resolved) # explicit, not set
|
|
|
|
def test_add_dynamic_mode_args_and_build_modes_flags_true(self):
|
|
from argparse import ArgumentParser
|
|
|
|
parser = ArgumentParser()
|
|
spec = modes.add_dynamic_mode_args(parser, self.modes_meta)
|
|
|
|
# MODE_CLEANUP: true → --skip-cleanup sets it to False
|
|
# MODE_DEBUG: false → --debug sets it to True
|
|
# MODE_ASSERT: None → --assert true sets it to True
|
|
args = parser.parse_args(["--skip-cleanup", "--debug", "--assert", "true"])
|
|
resolved = modes.build_modes_from_args(spec, args)
|
|
|
|
self.assertFalse(resolved["MODE_CLEANUP"])
|
|
self.assertTrue(resolved["MODE_DEBUG"])
|
|
self.assertTrue(resolved["MODE_ASSERT"])
|
|
|
|
def test_add_dynamic_mode_args_and_build_modes_flags_false_explicit(self):
|
|
from argparse import ArgumentParser
|
|
|
|
parser = ArgumentParser()
|
|
spec = modes.add_dynamic_mode_args(parser, self.modes_meta)
|
|
|
|
# explicit false for MODE_ASSERT
|
|
args = parser.parse_args(["--assert", "false"])
|
|
resolved = modes.build_modes_from_args(spec, args)
|
|
|
|
self.assertTrue(resolved["MODE_CLEANUP"]) # still default True
|
|
self.assertFalse(resolved["MODE_DEBUG"]) # still default False
|
|
self.assertIn("MODE_ASSERT", resolved)
|
|
self.assertFalse(resolved["MODE_ASSERT"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|