fix: sync Grok empty-group preservation
This commit is contained in:
1 parent
3de6f8823a
commit
eac8220dbe
2 files changed
+13
-5
No files matched your search
@@ -215,6 +215,7 @@ def _remove_managed(
|
||||
continue
|
||||
handlers = group["hooks"]
|
||||
kept: List[JsonObject] = []
|
||||
group_changed = False
|
||||
for handler in handlers:
|
||||
managed_id = _managed_agent_id(handler, script_name)
|
||||
remove = managed_id is not None and (
|
||||
@@ -222,10 +223,13 @@ def _remove_managed(
|
||||
)
|
||||
if remove:
|
||||
changed = True
|
||||
group_changed = True
|
||||
else:
|
||||
kept.append(handler)
|
||||
if kept:
|
||||
result.append(group if len(kept) == len(handlers) else {**group, "hooks": kept})
|
||||
if not group_changed:
|
||||
result.append(group)
|
||||
elif kept:
|
||||
result.append({**group, "hooks": kept})
|
||||
return result, changed
|
||||
|
||||
|
||||
|
||||
@@ -341,7 +341,7 @@ def test_install_replaces_stale_handlers_for_every_agent(
|
||||
assert len(current["hooks"]["PostToolUse"]) == 1
|
||||
|
||||
|
||||
def test_uninstall_preserves_untouched_empty_native_event(
|
||||
def test_uninstall_preserves_untouched_empty_native_group(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
fixture = prepare_fixture(
|
||||
@@ -349,13 +349,17 @@ def test_uninstall_preserves_untouched_empty_native_event(
|
||||
)
|
||||
fixture.plugin.install(fixture.config)
|
||||
settings = json.loads(fixture.config_path.read_text(encoding="utf-8"))
|
||||
settings["hooks"]["PreToolUse"] = []
|
||||
settings["hooks"]["PreToolUse"].insert(
|
||||
0, {"hooks": [], "label": "keep empty group"}
|
||||
)
|
||||
fixture.config_path.write_text(json.dumps(settings), encoding="utf-8")
|
||||
|
||||
fixture.plugin.uninstall(AGENT_ID)
|
||||
|
||||
remaining = json.loads(fixture.config_path.read_text(encoding="utf-8"))
|
||||
assert remaining["hooks"]["PreToolUse"] == []
|
||||
assert remaining["hooks"]["PreToolUse"] == [
|
||||
{"hooks": [], "label": "keep empty group"}
|
||||
]
|
||||
assert "PostToolUse" not in remaining["hooks"]
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user