From 2a6fc783a74d1f8181f69c901873b7289a327155 Mon Sep 17 00:00:00 2001 From: Lafnaps <177272356+Lafnaps@users.noreply.github.com> Date: Sat, 1 Aug 2026 15:37:59 +0300 Subject: [PATCH] fix(rules): report proposal resolution failures instead of pretending success --- app.py | 15 +++-- static/index.html | 2 +- static/rules-panel.js | 18 +++++- tests/test_rule_proposals.py | 104 +++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 tests/test_rule_proposals.py diff --git a/app.py b/app.py index 60a6434e..8ce739cf 100644 --- a/app.py +++ b/app.py @@ -1778,13 +1778,19 @@ async def resolve_rule_proposal(msg_id: int, request: Request): rule_id = meta.get("rule_id") if action == "activate" and rule_id is not None: - rules.activate(int(rule_id)) + if not rules.activate(int(rule_id)): + return JSONResponse( + {"error": "could not activate rule (active limit reached or rule not found)"}, + status_code=409, + ) meta["status"] = "activated" elif action == "draft" and rule_id is not None: - rules.make_draft(int(rule_id)) + if not rules.make_draft(int(rule_id)): + return JSONResponse({"error": "rule not found"}, status_code=409) meta["status"] = "drafted" elif action == "dismiss" and rule_id is not None: - rules.delete(int(rule_id)) + if not rules.delete(int(rule_id)): + return JSONResponse({"error": "rule not found"}, status_code=409) meta["status"] = "dismissed" else: return JSONResponse({"error": "invalid action"}, status_code=400) @@ -1814,7 +1820,8 @@ async def demote_rule_proposal(msg_id: int): meta = msg.get("metadata", {}) rule_id = meta.get("rule_id") if rule_id is not None: - rules.delete(int(rule_id)) + if not rules.delete(int(rule_id)): + return JSONResponse({"error": "rule not found"}, status_code=409) text = meta.get("text", msg.get("text", "")) updated = store.update_message(msg_id, { "type": "chat", diff --git a/static/index.html b/static/index.html index f015bf49..6a57ad61 100644 --- a/static/index.html +++ b/static/index.html @@ -344,7 +344,7 @@