Files
ai-agent/backend/test_notify_log_account.py
Gabriel Vidal df2b6001e8 feat(backend): notification feeds carry the Claude account
/api/notifications now returns each conversation's resolved `account`, and
/api/notify-log stamps an entry's `account` when its session's sidecar
records one (`account` / `accountSource`) — never guessed, so an
unattributed hub-only entry stays account-less. What the PWA's global
Perso / Work switch scopes the notification feed and pending asks by.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 22:19:29 +02:00

45 lines
1.4 KiB
Python

"""The account stamp on /api/notify-log entries — what the PWA's Perso / Work
switch scopes a hub-only entry by (``python3 -m unittest test_notify_log_account``
from ``backend/``, inside the service image)."""
import unittest
from types import SimpleNamespace
from notifications.routes import _with_account
class _Meta:
def __init__(self, by_sid):
self.by_sid = by_sid
def peek(self, sid):
return self.by_sid.get(sid, {})
def _deps(by_sid):
return SimpleNamespace(meta_store=_Meta(by_sid))
class WithAccount(unittest.TestCase):
def test_spawn_stamp(self):
e = {"id": "n1", "sessionId": "s1"}
out = _with_account(_deps({"s1": {"account": "work"}}), e)
self.assertEqual(out["account"], "work")
self.assertNotIn("account", e) # the stored entry is never mutated
def test_import_source(self):
out = _with_account(_deps({"s1": {"accountSource": "work"}}),
{"sessionId": "s1"})
self.assertEqual(out["account"], "work")
def test_unknown_stays_unstamped(self):
# no sidecar stamp: never guessed onto the default account
for deps, e in ((_deps({}), {"sessionId": "s1"}),
(_deps({"s1": {"account": "nope"}}), {"sessionId": "s1"}),
(_deps({}), {"id": "n1"})):
self.assertNotIn("account", _with_account(deps, e))
if __name__ == "__main__":
unittest.main()