You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.5 KiB
67 lines
2.5 KiB
import json
|
|
|
|
from mulit_agent_app.config import AgentConfig
|
|
|
|
|
|
def test_controller_url_requires_secure_scheme(tmp_path):
|
|
config = AgentConfig(tmp_path, tmp_path / "settings.json", tmp_path / "agent.sqlite3", tmp_path / "agent.log")
|
|
|
|
try:
|
|
config.save_controller_url("http://127.0.0.1:8443")
|
|
except ValueError:
|
|
pass
|
|
else:
|
|
raise AssertionError("An insecure controller URL must be rejected.")
|
|
|
|
|
|
def test_portable_config_is_loaded_and_updated(monkeypatch, tmp_path):
|
|
config_dir = tmp_path / "config"
|
|
config_dir.mkdir()
|
|
config_path = config_dir / "agent-config.json"
|
|
config_path.write_text(
|
|
json.dumps({"controller_url": "wss://10.0.0.8:8443", "agent_name": "build-agent"}),
|
|
encoding="utf-8",
|
|
)
|
|
monkeypatch.setenv("MULTI_AGENT_CONFIG_DIR", str(config_dir))
|
|
|
|
config = AgentConfig.load()
|
|
config.save_controller_url("wss://10.0.0.9:8443")
|
|
|
|
assert config.controller_url == "wss://10.0.0.8:8443"
|
|
assert json.loads(config_path.read_text(encoding="utf-8"))["controller_url"] == "wss://10.0.0.9:8443"
|
|
|
|
|
|
def test_agent_name_is_saved_in_portable_config(tmp_path):
|
|
config_path = tmp_path / "agent-config.json"
|
|
config = AgentConfig(tmp_path, config_path, tmp_path / "agent.sqlite3", tmp_path / "agent.log")
|
|
|
|
assert config.save_agent_name(" 设计部 Agent ") == "设计部 Agent"
|
|
assert json.loads(config_path.read_text(encoding="utf-8"))["agent_name"] == "设计部 Agent"
|
|
|
|
|
|
def test_persistent_settings_are_mirrored_to_the_portable_config(tmp_path):
|
|
persistent_path = tmp_path / "app-data" / "agent-settings.json"
|
|
portable_path = tmp_path / "release" / "config" / "agent-config.json"
|
|
config = AgentConfig(
|
|
tmp_path / "app-data",
|
|
persistent_path,
|
|
tmp_path / "app-data" / "agent.sqlite3",
|
|
tmp_path / "app-data" / "agent.log",
|
|
mirror_settings_path=portable_path,
|
|
)
|
|
|
|
config.save_agent_name("长期保存的 Agent")
|
|
reloaded = AgentConfig(
|
|
tmp_path / "app-data",
|
|
persistent_path,
|
|
tmp_path / "app-data" / "agent.sqlite3",
|
|
tmp_path / "app-data" / "agent.log",
|
|
agent_name="长期保存的 Agent",
|
|
mirror_settings_path=portable_path,
|
|
)
|
|
reloaded.save_controller_url("wss://10.0.0.9:8443")
|
|
|
|
expected = {"agent_name": "长期保存的 Agent", "controller_url": "wss://10.0.0.9:8443"}
|
|
for path in (persistent_path, portable_path):
|
|
saved = json.loads(path.read_text(encoding="utf-8"))
|
|
assert {key: saved[key] for key in expected} == expected
|
|
|