main.py (5146 lines, 106 routes) becomes an assembly only: one package per domain — core, files, settings, dashboards, conversations, diff, notifications, forms, runs, accounts, workers, models, cron, agents, projects, services, goals, memories, plans, templates — each exposing an APIRouter; the flat domain modules move into their package behind a barrel that keeps the old `import conversations` / `import projects` spellings. The shared singletons (store, meta_store, hub, indexer, …) are built once by core.state.build_state() and attached to app.state.ai; routes take them as the `deps: State` dependency and helpers as an explicit `deps: AppState`. conversations/pricing.py carries the per-model rates out of the parser. Verified: route table and OpenAPI byte-identical; 90 read endpoints golden-diffed against the monolith on a copy of the live data (identical); write routes smoke-tested; 66 backend tests pass. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
86 lines
3.1 KiB
Python
86 lines
3.1 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_cwd_rule(self):
|
|
self.assertEqual(accounts.resolve({"cwd": self.ORUS}, {}), "work")
|
|
|
|
def test_source_beats_cwd(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_and_cwd(self):
|
|
self.assertEqual(accounts.resolve({"cwd": self.ORUS},
|
|
{"account": "personal",
|
|
"accountSource": "work"}),
|
|
"personal")
|
|
|
|
def test_unknown_stamp_ignored(self):
|
|
self.assertEqual(accounts.resolve({"cwd": self.ORUS},
|
|
{"account": "nope"}), "work")
|
|
|
|
|
|
class CwdRule(unittest.TestCase):
|
|
def test_repo_and_subdir(self):
|
|
for cwd in ("/home/u/projects/orus-monorepo",
|
|
"/home/u/projects/orus-monorepo/apps/web",
|
|
"/home/u/projects/orus-monorepo/"):
|
|
self.assertEqual(accounts.account_for_cwd(cwd), "work", cwd)
|
|
|
|
def test_worktrees(self):
|
|
self.assertEqual(
|
|
accounts.account_for_cwd("/home/u/worktrees/orus-monorepo-fix-bug"),
|
|
"work")
|
|
self.assertEqual(
|
|
accounts.account_for_cwd("/home/u/worktrees/orus-monorepo-a/pkg"),
|
|
"work")
|
|
|
|
def test_non_matches(self):
|
|
for cwd in ("/home/u/homelab", "/home/u/projects/ai-agent",
|
|
"/home/u/projects/orus-monorepo-notes",
|
|
"/home/u/worktrees/homelab-orus-monorepo",
|
|
"", None):
|
|
self.assertIsNone(accounts.account_for_cwd(cwd), cwd)
|
|
|
|
|
|
class Projects(unittest.TestCase):
|
|
def test_routing(self):
|
|
self.assertEqual(accounts.account_for_projects(["orus-monorepo"]), "work")
|
|
self.assertEqual(
|
|
accounts.account_for_projects(["homelab", "project:orus-monorepo"]),
|
|
"work")
|
|
self.assertIsNone(accounts.account_for_projects(["ai-agent"]))
|
|
self.assertIsNone(accounts.account_for_projects(None))
|
|
|
|
|
|
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"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|