personal memory agent
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

support: return 403/500 on badge-count instead of fake zero

Respond 403 "Support is not enabled" when disabled and 500 with the
error envelope on client exceptions, matching the Wave 0 registerTask
contract so the UI can distinguish disabled from failing from empty.
Add unit coverage for the three paths.

+65 -5
+4 -5
apps/support/routes.py
··· 257 257 def badge_count() -> Any: 258 258 """Return count of tickets with new responses (for app badge).""" 259 259 if not _enabled(): 260 - return jsonify({"count": 0}) 260 + return error_response("Support is not enabled", 403) 261 261 262 262 try: 263 263 client = _get_client() 264 264 tickets = client.list_tickets(status="open") 265 - # Count tickets that have been updated since creation 266 - # (a simple heuristic for "has new response") 267 265 count = sum( 268 266 1 for t in tickets if t.get("updated_at", "") > t.get("created_at", "") 269 267 ) 270 268 return jsonify({"count": count}) 271 - except Exception: 272 - return jsonify({"count": 0}) 269 + except Exception as exc: 270 + logger.exception("Failed to fetch badge count") 271 + return error_response(str(exc), 500)
+61
tests/test_app_support.py
··· 1 + # SPDX-License-Identifier: AGPL-3.0-only 2 + # Copyright (c) 2026 sol pbc 3 + 4 + """Tests for support app routes.""" 5 + 6 + import pytest 7 + 8 + 9 + @pytest.fixture 10 + def support_client(): 11 + """Create a Flask test client with support blueprint.""" 12 + from flask import Flask 13 + 14 + from apps.support.routes import support_bp 15 + 16 + app = Flask(__name__) 17 + app.register_blueprint(support_bp) 18 + yield app.test_client() 19 + 20 + 21 + class _TicketsClient: 22 + def __init__(self, tickets=None, error: Exception | None = None): 23 + self.tickets = tickets or [] 24 + self.error = error 25 + 26 + def list_tickets(self, *, status=None): 27 + if self.error: 28 + raise self.error 29 + return self.tickets 30 + 31 + 32 + def test_badge_count_enabled_empty(support_client, monkeypatch): 33 + monkeypatch.setattr("apps.support.routes._enabled", lambda: True) 34 + monkeypatch.setattr("apps.support.routes._get_client", lambda: _TicketsClient()) 35 + 36 + resp = support_client.get("/app/support/api/badge-count") 37 + 38 + assert resp.status_code == 200 39 + assert resp.get_json() == {"count": 0} 40 + 41 + 42 + def test_badge_count_disabled_returns_403(support_client, monkeypatch): 43 + monkeypatch.setattr("apps.support.routes._enabled", lambda: False) 44 + 45 + resp = support_client.get("/app/support/api/badge-count") 46 + 47 + assert resp.status_code == 403 48 + assert resp.get_json() == {"error": "Support is not enabled"} 49 + 50 + 51 + def test_badge_count_error_returns_500(support_client, monkeypatch): 52 + monkeypatch.setattr("apps.support.routes._enabled", lambda: True) 53 + monkeypatch.setattr( 54 + "apps.support.routes._get_client", 55 + lambda: _TicketsClient(error=RuntimeError("simulated")), 56 + ) 57 + 58 + resp = support_client.get("/app/support/api/badge-count") 59 + 60 + assert resp.status_code == 500 61 + assert "error" in resp.get_json()