fix(issue-45): MAM herdr servers start with restore-on-restart off; resume closes its own restored empty shell (v4.8.5) #48
No files matched your search
@@ -32,7 +32,6 @@ import os
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
import tomllib
|
||||
from typing import List, Mapping, Optional, Tuple
|
||||
|
||||
MARKER = "# generated by multi-agent-mux (Issue #45) - do not edit"
|
||||
@@ -42,6 +41,11 @@ FALLBACK_NAME = "herdr-server-config.toml"
|
||||
KEY = "resume_agents_on_restore"
|
||||
MINIMAL = f"[session]\n{KEY} = false\n"
|
||||
|
||||
try:
|
||||
import tomllib
|
||||
except ImportError: # Python < 3.11: no parser to check a merge with
|
||||
tomllib = None
|
||||
|
||||
_SESSION_HEADER = re.compile(r"^\s*\[\s*session\s*\]\s*(#.*)?$")
|
||||
_ANY_HEADER = re.compile(r"^\s*\[")
|
||||
_KEY_LINE = re.compile(rf"^\s*{KEY}\s*=")
|
||||
@@ -107,6 +111,9 @@ def server_config_text(user_text: Optional[str]) -> Tuple[str, List[str]]:
|
||||
always has session.resume_agents_on_restore = false."""
|
||||
if not user_text or not user_text.strip():
|
||||
return MINIMAL, []
|
||||
if tomllib is None:
|
||||
return MINIMAL, [f"this Python has no tomllib (3.11+); the MAM server uses only {KEY} = false, "
|
||||
"without the rest of your settings"]
|
||||
try:
|
||||
user = tomllib.loads(user_text)
|
||||
except tomllib.TOMLDecodeError as e:
|
||||
|
||||
@@ -71,6 +71,14 @@ def test_a_bad_value_type_falls_back_to_minimal():
|
||||
assert warnings == []
|
||||
|
||||
|
||||
def test_without_tomllib_restore_is_still_off(monkeypatch):
|
||||
# The shim runs a bare `python3`; on one older than 3.11 an import error
|
||||
# would leave the server with restore on. Off wins over the user's settings.
|
||||
monkeypatch.setattr(hc, "tomllib", None)
|
||||
text, warnings = hc.server_config_text("[ui]\nconfirm_close = false\n")
|
||||
assert text == hc.MINIMAL and "no tomllib" in warnings[0]
|
||||
|
||||
|
||||
def _env(tmp_path, **kw):
|
||||
env = {"HOME": str(tmp_path / "home")}
|
||||
env.update(kw)
|
||||
|
||||
Reference in new issue
Block a user