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