test(moa): trim to two invariants; map teo-nex attribution

Replace the CLI-subprocess parametrization (6 hermes processes per run) with a
direct normalizer invariant: non-finite cadence -> default cadence, non-finite
temperatures -> None while finite values (0, 0.75) survive.
This commit is contained in:
teknium1
2026-09-14 17:51:12 -07:00
committed by Teknium
parent 0c492361fa
commit c810bc771f

View File

@@ -1,56 +1,34 @@
"""Malformed numeric MoA settings must degrade to defaults, not break the CLI or JSON."""
import json
import os
from pathlib import Path
import subprocess
import sys
import math
import pytest
import yaml
from hermes_cli.moa_config import normalize_moa_config
@pytest.mark.parametrize("fanout", [
{"mode": "every_n", "n": float("inf")},
{"mode": "every_n", "n": float("-inf")},
{"mode": "every_n", "n": "inf"},
{"mode": "every_n", "n": "-inf"},
"every_n:inf",
"every_n:-inf",
"every_n:nan",
])
def test_moa_list_tolerates_nonfinite_fanout(tmp_path, fanout):
home = tmp_path / "profile"
home.mkdir()
(home / "config.yaml").write_text(yaml.safe_dump({"moa": {"fanout": fanout}}))
env = {**os.environ, "HERMES_HOME": str(home)}
result = subprocess.run(
[sys.executable, "-m", "hermes_cli.main", "moa", "list"],
cwd=Path(__file__).resolve().parents[2],
env=env, capture_output=True, text=True, timeout=45,
)
assert result.returncode == 0, result.stdout + result.stderr
normalized = normalize_moa_config({"fanout": fanout})
assert normalized["fanout"] == normalize_moa_config({})["fanout"]
def test_nonfinite_fanout_falls_back_to_default_cadence(fanout):
assert normalize_moa_config({"fanout": fanout})["fanout"] == normalize_moa_config({})["fanout"]
assert normalize_moa_config({"fanout": {"mode": "every_n", "n": "3.0"}})["fanout"] == "every_n:3"
@pytest.mark.parametrize("temperature", [float("nan"), float("inf"), float("-inf"), "NaN", "inf", "-inf"])
@pytest.mark.parametrize("temperature", [float("nan"), float("inf"), "-inf", "NaN"])
def test_nonfinite_temperatures_do_not_escape_into_json(temperature):
raw = {
normalized = normalize_moa_config({
"reference_temperature": temperature,
"aggregator_temperature": temperature,
}
normalized = normalize_moa_config(raw)
})
assert normalized["reference_temperature"] is None
assert normalized["aggregator_temperature"] is None
json.dumps(normalized, allow_nan=False)
finite = normalize_moa_config({
"reference_temperature": 0,
"aggregator_temperature": "0.75",
"fanout": {"mode": "every_n", "n": "3.0"},
})
assert finite["reference_temperature"] == 0
finite = normalize_moa_config({"reference_temperature": 0, "aggregator_temperature": "0.75"})
assert finite["reference_temperature"] == 0 and math.isfinite(finite["reference_temperature"])
assert finite["aggregator_temperature"] == 0.75
assert finite["fanout"] == "every_n:3"