fix(8816): a hold rule holds the first write to a file its own path trigger names
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 10s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / Python tests (push) Successful in 1m51s
CI & Build / integration (push) Successful in 2m24s
CI & Build / Build & push image (push) Successful in 24s
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 10s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / Python tests (push) Successful in 1m51s
CI & Build / integration (push) Successful in 2m24s
CI & Build / Build & push image (push) Successful in 24s
A rule set to hold never held a file edit, so rule 198 (services run on the orchestrator's defaults), even at hold, could only sit beside the compose-file edit that broke it. The trigger board now names the rules whose path trigger matched the act, and a write is held only for those: a mount or a keyword alone still lets a write through. Tool descriptions and the using-grimoire skill say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -563,23 +563,45 @@ async def test_an_inform_rule_and_a_preference_never_stop_the_act():
|
||||
assert (await _arm(pairs)).decision == {}
|
||||
|
||||
|
||||
async def _deliver_for(tool, decision):
|
||||
async def _deliver_for(tool, decision, board=None):
|
||||
from grimoire.services import moment_actions as ma
|
||||
|
||||
with patch.object(ma, "moments_for", AsyncMock(return_value=PUSH)), \
|
||||
patch.object(md, "_board", AsyncMock(return_value=None)), \
|
||||
patch.object(md, "_board", AsyncMock(return_value=board)), \
|
||||
patch.object(md, "deliver_moments",
|
||||
AsyncMock(return_value=rp.RuleResult(decision=dict(decision)))):
|
||||
_reached, result = await _REAL_DELIVER(1, tool, {})
|
||||
return result.decision
|
||||
|
||||
|
||||
async def test_a_write_is_refused_by_an_enforced_rule_but_never_held():
|
||||
async def test_a_write_is_refused_by_an_enforced_rule_and_held_only_through_a_path_trigger():
|
||||
from grimoire.services.rule_triggers import Board
|
||||
|
||||
hold = {"kind": "hold", "rule_ids": [7], "reason": "read it"}
|
||||
enforce = {"kind": "enforce", "rule_ids": [6], "reason": "not run"}
|
||||
assert await _deliver_for("Edit", hold) == {}
|
||||
assert await _deliver_for("Bash", hold) == hold
|
||||
assert await _deliver_for("Write", enforce) == enforce
|
||||
# Rule 7's own path trigger names the file: the write waits for one read.
|
||||
assert await _deliver_for("Edit", hold, Board(path_hits={7})) == hold
|
||||
# Another rule's path trigger matched; rule 7 reached the write otherwise.
|
||||
assert await _deliver_for("Write", hold, Board(path_hits={8})) == {}
|
||||
|
||||
|
||||
async def test_the_board_names_the_rules_a_path_trigger_matched(monkeypatch):
|
||||
from grimoire.services import rule_triggers as rt
|
||||
|
||||
compose = fake_rule(id=198, title="defaults")
|
||||
keyword = fake_rule(id=5, title="keyword only")
|
||||
monkeypatch.setattr(rt, "_in_scope", AsyncMock(return_value=[
|
||||
(compose, [rt.Trigger("keyword", "update_config"), rt.Trigger("path", "**/compose*.yml")]),
|
||||
(keyword, [rt.Trigger("keyword", "update_config")]),
|
||||
]))
|
||||
edit = {"file_path": "/repo/deploy/compose.deploy.yml", "new_string": "update_config:"}
|
||||
board = await rt.board(1, 2, tool="Edit", tool_input=edit)
|
||||
assert board.path_hits == {198}
|
||||
other = await rt.board(1, 2, tool="Edit", tool_input={**edit, "file_path": "/repo/README.md"})
|
||||
assert other.path_hits == set()
|
||||
|
||||
|
||||
def _decided(tmp_path, decision, session="s-decide"):
|
||||
|
||||
Reference in New Issue
Block a user