From 2c46a1ffc152695a50bac0a50f82a93bff13db82 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Mon, 9 Nov 2026 18:45:02 -0600 Subject: [PATCH] Fix inventory and heal validation fixtures --- tests/jeannie-unit | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/jeannie-unit b/tests/jeannie-unit index 8c976c5..57cdd52 100755 --- a/tests/jeannie-unit +++ b/tests/jeannie-unit @@ -330,12 +330,14 @@ test_inventory_validator_rejects_ip_drift() { local inventory="${TMP_DIR}/invalid-homelab.yml" python3 - "${REPO_ROOT}/homelab.yml" "${inventory}" <<'PY' import sys +import yaml source, target = sys.argv[1:3] -text = open(source, encoding="utf-8").read() -text = text.replace("lan_ip: 192.168.100.73", "lan_ip: not-an-ip", 1) +with open(source, encoding="utf-8") as handle: + inventory = yaml.safe_load(handle) +inventory["hosts"]["debian"]["lan_ip"] = "not-an-ip" with open(target, "w", encoding="utf-8") as handle: - handle.write(text) + yaml.safe_dump(inventory, handle, sort_keys=False) PY assert_command_failure_contains "inventory validator rejects invalid Debian LAN IP" "hosts.debian.lan_ip is not a valid IP" "${REPO_ROOT}/scripts/validate-homelab-inventory" "${inventory}" } @@ -343,6 +345,7 @@ PY test_heal_cooldown_escalates_to_diagnostics() { local status_json="${TMP_DIR}/heal-status.json" local state_json="${TMP_DIR}/heal-state.json" + local fixture_root="${TMP_DIR}/heal-fixture" local output cat >"${status_json}" <<'EOF' @@ -364,6 +367,27 @@ test_heal_cooldown_escalates_to_diagnostics() { ] } EOF + mkdir -p "${fixture_root}/clusters/pimox" + printf '{"kube_system_uid":"test-cluster-uid"}\n' >"${fixture_root}/clusters/pimox/identity.json" + python3 - "${status_json}" "${REPO_ROOT}/homelab.yml" <<'PY' +import json +import os +import sys +import yaml + +status_path, inventory_path = sys.argv[1:] +with open(inventory_path, encoding="utf-8") as handle: + inventory = yaml.safe_load(handle) +with open(status_path, encoding="utf-8") as handle: + status = json.load(handle) +status["cluster"] = { + "profile": "pimox", + "kubeconfig": os.path.expanduser(inventory["cluster"]["profiles"]["pimox"]["control_plane"]["kubeconfig"]), + "uid": "test-cluster-uid", +} +with open(status_path, "w", encoding="utf-8") as handle: + json.dump(status, handle) +PY python3 - "${state_json}" <<'PY' import json import sys @@ -384,7 +408,9 @@ with open(sys.argv[1], "w", encoding="utf-8") as handle: PY output="$( - LAB_HEAL_STATE_FILE="${state_json}" LAB_HEAL_COOLDOWN_SECONDS=3600 \ + HOMELAB_STATE_DIR="${fixture_root}" HOMELAB_INVENTORY_FILE="${REPO_ROOT}/homelab.yml" \ + LAB_CLUSTER_PROFILE=pimox JEANNIE_CLUSTER_PROFILE_PIN=pimox \ + LAB_HEAL_STATE_FILE="${state_json}" LAB_HEAL_COOLDOWN_SECONDS=3600 \ "${REPO_ROOT}/scripts/heal" plan --status-json "${status_json}" )" assert_contains "heal cooldown removes auto target" "Next heal target: none" "${output}"