fix(default-plugins): the ensure child answers once
Review: the child checked whether the waiting ensure had read its early answer, then wrote a final result; the ensure could read and remove the answer between the two, leaving a result file nobody reads. Once the early answer is sent it is the run's only result; the platform installs after it are logged.
This commit is contained in:
@@ -100,7 +100,8 @@ def _read_child_result(root: Path, run_id: str) -> Optional[dict]:
|
||||
class _StartReady:
|
||||
"""The ensure child's early answer: once the defaults a start waits for are settled (installed or owed),
|
||||
the waiting ``ensure`` gets the outcome so far plus the platform defaults this child goes on installing
|
||||
(``background``). Written at most once; with nothing left for later, the final result is the answer."""
|
||||
(``background``). The run's only answer once sent (the platform installs after it are logged); with
|
||||
nothing left for later, the final result is the answer."""
|
||||
|
||||
def __init__(self, root: Path, run_id: str) -> None:
|
||||
self.root, self.run_id, self.sent = root, run_id, False
|
||||
@@ -115,12 +116,6 @@ class _StartReady:
|
||||
logger.info("default plugins: the start goes on; %s install in the background (a running gateway "
|
||||
"serves each platform as it lands)", ", ".join(background))
|
||||
|
||||
def consumed(self) -> bool:
|
||||
"""The waiting ensure read the early answer: nobody is left to read a final one."""
|
||||
from hermes_cli import default_plugins as _dp
|
||||
|
||||
return self.sent and not _dp._result_path(self.root, self.run_id).exists()
|
||||
|
||||
|
||||
def _install_subset_and_record(
|
||||
target_homes: list[Path],
|
||||
@@ -189,7 +184,7 @@ def _ensure_child_work(run_id: str, home: Optional[Path], *, say: Callable[[str]
|
||||
logger.exception("default plugin install failed")
|
||||
_note_failure(root, _dp._BACKOFF)
|
||||
outcome = {"installed": [], "owed": [f"error: {exc}"]}
|
||||
if not start_ready.consumed(): # not on a BaseException: no result reads as owed
|
||||
if not start_ready.sent: # one answer per run; not on a BaseException: no result reads as owed
|
||||
_dp._write_child_result(root, run_id, outcome)
|
||||
return 1 if outcome["owed"] else 0
|
||||
|
||||
|
||||
@@ -748,3 +748,15 @@ def test_start_waits_for_a_provider_default_but_not_for_a_platform_default(tmp_p
|
||||
assert (home / "plugins" / "chatplat").is_dir()
|
||||
assert default_plugins._recorded(home) == {"chatplat", "memprov"}
|
||||
assert not list((home / "cache").glob("default-plugins.result-*.json")), "a result nobody reads was left"
|
||||
|
||||
|
||||
def test_the_ensure_child_answers_once_when_platform_defaults_go_on_installing(tmp_path, monkeypatch):
|
||||
"""Its early answer is the run's only result: a final write after it would land beside an ensure that
|
||||
may already have read and removed the answer, a file nobody reads."""
|
||||
platform = entry_from_mapping({**_entry_dict("chatplat"), "category": "platform"}, "chatplat")
|
||||
home = _setup_env(tmp_path, monkeypatch, [platform], [{"entries": [_entry_dict("chatplat")]}])
|
||||
monkeypatch.setattr(lcm_migrate, "_install_into", _fake_install_into([]))
|
||||
assert default_plugins._ensure_child_work("run-once", None, say=lambda _m: None) == 0
|
||||
result = json.loads(default_plugins._result_path(home, "run-once").read_text(encoding="utf-8"))
|
||||
assert result == {"run_id": "run-once", "installed": [], "owed": [], "background": ["chatplat"]}
|
||||
assert default_plugins._recorded(home) == {"chatplat"}
|
||||
|
||||
Reference in New Issue
Block a user