Skip to content

The agent that grows with you

refactor(config-remote): backend.py uses diff.py's path helpers instead of its own copies

Ben Barclay5da4eeb03cb2
diff --git a/plugins/config_backends/remote/backend.py b/plugins/config_backends/remote/backend.py
index cc6542dc825..a7fdaefae8e 100644
--- a/plugins/config_backends/remote/backend.py
+++ b/plugins/config_backends/remote/backend.py
@@ -27,7 +27,8 @@ from hermes_cli.config_backend import (
from . import client
from .credentials import PLANE_CREDENTIAL_ENV_NAMES, PlaneCredentialError
-from .diff import _get_path, apply_intent, diff, encode_changes, intent_diff, json_equal, strip_locked, write_check
+from .diff import (_get_path, _pop_path, _set_path, apply_intent, diff, encode_changes, intent_diff, json_equal,
+ strip_locked, write_check)
from .paths import Path as KeyPath
from .paths import PathError, covers, decode, encode, from_dotted
from .values import secret_literal_path, to_wire
@@ -851,19 +852,3 @@ def _first_change(path: KeyPath, sent: Any, found: bool, got: Any) -> Optional[K
except ConfigValueError:
return path
-
-def _set_path(doc: dict[str, Any], path: KeyPath, value: Any) -> None:
- node = doc
- for seg in path[:-1]:
- if not isinstance(node.get(seg), dict):
- node[seg] = {}
- node = node[seg]
- node[path[-1]] = value
-
-
-def _pop_path(doc: dict[str, Any], path: KeyPath) -> None:
- node: Any = doc
- for seg in path[:-1]:
- node = node.get(seg) if isinstance(node, dict) else None
- if isinstance(node, dict):
- node.pop(path[-1], None)
diff --git a/tests/plugins/config_backends/test_remote_backend.py b/tests/plugins/config_backends/test_remote_backend.py
index f57b1040bf9..8a7fd4927f8 100644
--- a/tests/plugins/config_backends/test_remote_backend.py
+++ b/tests/plugins/config_backends/test_remote_backend.py
@@ -375,6 +375,17 @@ def test_poll_interval_is_a_constant_no_env_tunes(monkeypatch):
assert not any("POLL" in n for n in names)
+def test_backend_edits_paths_with_the_diff_helpers():
+ # teknium1 P2-3: one _set_path/_pop_path pair (diff.py's), not a second copy in backend.py.
+ from plugins.config_backends.remote import diff as diff_mod
+ assert backend_mod._set_path is diff_mod._set_path
+ assert backend_mod._pop_path is diff_mod._pop_path
+ doc = {"a": {"b": 1}}
+ assert backend_mod._pop_path(doc, ("a", "b")) is True and doc == {"a": {}}
+ assert backend_mod._pop_path(doc, ("a", "b")) is False
+ assert backend_mod._pop_path(doc, ("x", "y")) is False
+
+
def test_named_profile_fetches_its_own_layer(plane):
from hermes_constants import reset_hermes_home_override, set_hermes_home_override