Files
ai-agent/backend/test_accounts.py
Gabriel VidalandClaude Opus 5.5 f337facdd0 feat(profiles): Settings → Profiles drive the scope and new-prompt defaults
A profile (Personal, Work) groups the Claude accounts, workers and projects
used together, and replaces the hard-coded orus-monorepo → work link (account
projects/cwd, project-tag routing, the cwd attribution rule).

- backend/profiles: /data/profiles.json store (seeded from the workers' old
  autoRoute flags), GET/PATCH /api/profiles, SSE 'profiles'. Each account and
  project sits in one profile; workers are derived from their login; a
  default runner (worker or lab) and a lab start directory per profile.
- Routing: a new run bills the profile's account and goes to its default
  runner while online; project costs and project-less conversations follow
  the profile's projects. ?account= takes a comma list.
- Settings → Profiles (ItemCard list): colour (moved off Claude accounts),
  icon, accounts, default runner, lab start dir, projects.
- The home toggle, the dashboards' switch and the app colour follow the
  profile; the History drawer header carries the switch on conversation
  pages (the open conversation stays open).
- Composer: account, runner and projects preselected from the profile; the
  profile's projects stay out of a worker run's location block.
- Cards drop the account / worker / project pills the profile on screen
  already says; an All view shows one profile pill. The offline-worker
  banner only warns about the scoped profile's workers.
- Workers page switch = the profile's default runner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 18:26:01 +02:00

65 lines
2.3 KiB
Python

"""Unit tests for the account profiles (``python3 -m unittest test_accounts``
from ``backend/`` — stdlib only, no app import)."""
import unittest
import accounts
class ResolveOrder(unittest.TestCase):
ORUS = "/home/u/projects/orus-monorepo"
def test_default(self):
self.assertEqual(accounts.resolve({"cwd": "/home/u/homelab"}, {}),
"personal")
self.assertEqual(accounts.resolve(None, None), "personal")
def test_no_cwd_rule(self):
# The orus-monorepo → work link is a profile's business now: the cwd
# alone never makes a conversation a work one.
self.assertEqual(accounts.resolve({"cwd": self.ORUS}, {}), "personal")
def test_source(self):
# a work-account session started from a terminal in the homelab
self.assertEqual(accounts.resolve({"cwd": "/home/u/homelab"},
{"accountSource": "work"}), "work")
def test_explicit_beats_source(self):
self.assertEqual(accounts.resolve({"cwd": self.ORUS},
{"account": "personal",
"accountSource": "work"}),
"personal")
def test_unknown_stamp_ignored(self):
self.assertEqual(accounts.resolve({}, {"account": "nope",
"accountSource": "work"}),
"work")
def test_no_hardcoded_projects(self):
for a in accounts.public():
self.assertNotIn("projects", a)
class Selector(unittest.TestCase):
def test_totals_default_excludes_work(self):
sel = accounts.selector(None)
self.assertTrue(sel("personal"))
self.assertFalse(sel("work"))
self.assertTrue(sel(None)) # unresolved ⇒ default account
def test_all_and_one(self):
self.assertTrue(accounts.selector("all")("work"))
self.assertTrue(accounts.selector("work")("work"))
self.assertFalse(accounts.selector("work")("personal"))
self.assertFalse(accounts.selector("bogus")("personal"))
def test_a_profiles_accounts(self):
sel = accounts.selector("personal,work")
self.assertTrue(sel("work") and sel("personal") and sel(None))
self.assertFalse(accounts.selector("work,bogus")("personal"))
if __name__ == "__main__":
unittest.main()