import os import sys PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, PROJECT_ROOT) from config import load_dispatcher_config, load_worker_inventory def test_load_dispatcher_config_accepts_yaml_path(tmp_path): config_path = tmp_path / "dispatcher.yaml" config_path.write_text( """ CONFIG_ENV: test INSTANCE_NAME: test-dispatcher REDIS_PORT: 6380 FEATURE_FLAGS: yaml_config: true """.lstrip(), encoding="utf-8", ) config = load_dispatcher_config(config_path=str(config_path)) assert config["CONFIG_ENV"] == "test" assert config["INSTANCE_NAME"] == "test-dispatcher" assert config["REDIS_PORT"] == 6380 assert config["FEATURE_FLAGS"]["yaml_config"] is True def test_load_worker_inventory_accepts_yaml_config_object(tmp_path): inventory_path = tmp_path / "inventory.yaml" inventory_path.write_text( """ WORKER_INVENTORY: - worker_id: 192.168.1.20 ssh_target: 192.168.1.20 repo_dir: D:/autool python_exe: python tags: - test """.lstrip(), encoding="utf-8", ) inventory = load_worker_inventory(path=str(inventory_path), env_name="test") assert len(inventory) == 1 assert inventory[0]["worker_id"] == "192.168.1.20" assert inventory[0]["ssh_host"] == "192.168.1.20" assert inventory[0]["repo_dir"] == "D:/autool" def test_load_worker_inventory_accepts_standalone_yaml_list(tmp_path): inventory_path = tmp_path / "workers.yml" inventory_path.write_text( """ - worker_id: 192.168.1.21 ssh_target: 192.168.1.21 repo_dir: D:/autool python_exe: python tags: [] """.lstrip(), encoding="utf-8", ) inventory = load_worker_inventory(path=str(inventory_path), env_name="prod") assert len(inventory) == 1 assert inventory[0]["worker_id"] == "192.168.1.21"