fix(issue-45): restore stays off when python3 has no tomllib
The shim runs a bare python3. Before 3.11 the module failed to import and the server started with restore on; now it gets the key alone, with a warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
feceddf49f
commit
eedcebcc12
2 files changed
+16
-1
No files matched your search
@@ -32,7 +32,6 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import tomllib
|
|
||||||
from typing import List, Mapping, Optional, Tuple
|
from typing import List, Mapping, Optional, Tuple
|
||||||
|
|
||||||
MARKER = "# generated by multi-agent-mux (Issue #45) - do not edit"
|
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"
|
KEY = "resume_agents_on_restore"
|
||||||
MINIMAL = f"[session]\n{KEY} = false\n"
|
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*(#.*)?$")
|
_SESSION_HEADER = re.compile(r"^\s*\[\s*session\s*\]\s*(#.*)?$")
|
||||||
_ANY_HEADER = re.compile(r"^\s*\[")
|
_ANY_HEADER = re.compile(r"^\s*\[")
|
||||||
_KEY_LINE = re.compile(rf"^\s*{KEY}\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."""
|
always has session.resume_agents_on_restore = false."""
|
||||||
if not user_text or not user_text.strip():
|
if not user_text or not user_text.strip():
|
||||||
return MINIMAL, []
|
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:
|
try:
|
||||||
user = tomllib.loads(user_text)
|
user = tomllib.loads(user_text)
|
||||||
except tomllib.TOMLDecodeError as e:
|
except tomllib.TOMLDecodeError as e:
|
||||||
|
|||||||
@@ -71,6 +71,14 @@ def test_a_bad_value_type_falls_back_to_minimal():
|
|||||||
assert warnings == []
|
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):
|
def _env(tmp_path, **kw):
|
||||||
env = {"HOME": str(tmp_path / "home")}
|
env = {"HOME": str(tmp_path / "home")}
|
||||||
env.update(kw)
|
env.update(kw)
|
||||||
|
|||||||
Reference in new issue
Block a user