feat: track imported accounts per upstream key across platforms

Add upstream_key_account_links table mapping generated keys to remote
accounts per website/platform, surface imported_accounts on key
responses, and update website sync/routers to manage the links.
This commit is contained in:
liujing
2026-07-23 17:52:58 +08:00
parent ee89cd6119
commit df7e400e7b
17 changed files with 1081 additions and 537 deletions
+26 -3
View File
@@ -137,9 +137,17 @@ def test_create_binding_runs_initial_sync(monkeypatch, db_session):
assert log.new_rate == "2.20"
def test_create_binding_skips_write_when_website_auto_sync_disabled(db_session):
def test_create_binding_skips_write_when_website_auto_sync_disabled(monkeypatch, db_session):
website, upstream = seed_rows(db_session, auto_sync_enabled=False)
class FakeClient:
def __init__(self, **kwargs): pass
def __enter__(self): return self
def __exit__(self, *args): pass
def get_groups(self, endpoint):
return [{"id": "target", "name": "Target group", "platform": "openai"}]
monkeypatch.setattr(websites_router, "Sub2ApiWebsiteClient", FakeClient)
result = websites_router.create_binding(
make_body(website.id, upstream.id),
db_session,
@@ -155,9 +163,17 @@ def test_create_binding_skips_write_when_website_auto_sync_disabled(db_session):
assert log.new_rate == "2.20"
def test_create_binding_skips_write_when_binding_disabled(db_session):
def test_create_binding_skips_write_when_binding_disabled(monkeypatch, db_session):
website, upstream = seed_rows(db_session)
class FakeClient:
def __init__(self, **kwargs): pass
def __enter__(self): return self
def __exit__(self, *args): pass
def get_groups(self, endpoint):
return [{"id": "target", "name": "Target group", "platform": "openai"}]
monkeypatch.setattr(websites_router, "Sub2ApiWebsiteClient", FakeClient)
result = websites_router.create_binding(
make_body(website.id, upstream.id, enabled=False),
db_session,
@@ -171,8 +187,15 @@ def test_create_binding_skips_write_when_binding_disabled(db_session):
assert log.new_rate == "2.20"
def test_create_binding_keeps_binding_when_initial_sync_calculation_fails(db_session):
def test_create_binding_keeps_binding_when_initial_sync_calculation_fails(monkeypatch, db_session):
website, upstream = seed_rows(db_session)
class FakeClient:
def __init__(self, **kwargs): pass
def __enter__(self): return self
def __exit__(self, *args): pass
def get_groups(self, endpoint):
return [{"id": "target", "name": "Target group", "platform": "openai"}]
monkeypatch.setattr(websites_router, "Sub2ApiWebsiteClient", FakeClient)
db_session.query(UpstreamRateSnapshot).delete()
db_session.commit()