Spaces:
Paused
Paused
fix: unify standby relogin and skip Google auto reuse
Browse filesFiles changed (4)
72 unmodified lines737475767778736 unmodified lines815816817818819820821822823824825826827828829830831832833834835836642 unmodified lines147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667131 unmodified lines17991800180118021803180418051 unmodified line1807180818091810181118127 unmodified lines18201821182218231824182518261827182818291830183118324 unmodified lines18371838183918401841184218433 unmodified lines18471848184918501851185218537 unmodified lines18611862186318641865186618673 unmodified lines18711872187318741875187618771 unmodified line18791880188118821883188418853 unmodified lines1889189018911892189318941895189618971898311 unmodified lines22102211221222132214221572 unmodified linesreturn bool(_normalized_email(email)) and _normalized_email(email) == _normalized_email(get_admin_email())def sync_account_states(chatgpt_api=None):"""根据 Team 实际成员列表同步本地账号状态"""account_id = get_chatgpt_account_id()736 unmodified linesreturn exhausted_infodef _submit_reinvite_primary_step(page, field, labels, step_name, wait_seconds=0):"""只点击当前表单的主按钮,避免误点 Google / Apple / Microsoft 登录入口。"""if not _click_primary_auth_button(page, field, labels):logger.warning("[轮转] %s 时未找到主提交按钮 | URL: %s | body=%s", step_name, page.url, _page_excerpt(page))return Falseif wait_seconds:time.sleep(wait_seconds)if _is_google_redirect(page):logger.warning("[轮转] %s 后误跳转到 Google 登录: %s", step_name, page.url)return Falsereturn Truedef _first_visible_editable_locator(page, selectors, timeout=800):try:locator = page.locator(selectors).first642 unmodified linesdef reinvite_account(chatgpt_api, mail_client, acc):"""恢复 standby 账号 — 直接登录(域名自动加入 workspace,不需要邀请)。登录后自动回到 workspace,然后刷新 Codex token。"""from playwright.sync_api import sync_playwrightfrom autoteam.invite import screenshotemail = acc["email"]password = acc.get("password", "")logger.info("[轮转] 恢复旧账号: %s(直接登录)", email)# 关闭 ChatGPT API 浏览器避免冲突if chatgpt_api and chatgpt_api.browser:chatgpt_api.stop()with sync_playwright() as p:browser = p.chromium.launch(**get_playwright_launch_options())context = browser.new_context(viewport={"width": 1280, "height": 800},user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",)page = context.new_page()restore_failed = False# 直接去登录页page.goto("https://chatgpt.com/auth/login", wait_until="domcontentloaded", timeout=60000)time.sleep(5)# Cloudflarefor _i in range(12):html = page.content()[:2000].lower()if "verify you are human" not in html and "challenge" not in page.url:breaktime.sleep(5)# 点登录try:login_btn = page.locator('button:has-text("登录"), button:has-text("Log in")').firstif login_btn.is_visible(timeout=5000):login_btn.click()time.sleep(3)except Exception:pass# 输入邮箱email_input = page.locator('input[name="email"], input[type="email"]').firsttry:if email_input.is_visible(timeout=5000):email_input.fill(email)time.sleep(0.5)if not _submit_reinvite_primary_step(page, email_input, ["Continue", "继续"], "提交邮箱", wait_seconds=3):restore_failed = Trueexcept Exception:pass# 输入密码 / 点击一次性验证码登录pwd_input = page.locator('input[type="password"]').firsttry:if not restore_failed and _is_google_redirect(page):restore_failed = Trueif not restore_failed and pwd_input.is_visible(timeout=5000):if password:pwd_input.fill(password)time.sleep(0.5)if not _submit_reinvite_primary_step(page,pwd_input,["Continue", "继续", "Log in", "登录"],"提交密码",wait_seconds=8,):restore_failed = Trueelse:otp_btn = page.locator('button:has-text("一次性验证码"), button:has-text("one-time"), button:has-text("email login")').firstif otp_btn.is_visible(timeout=3000):logger.info("[轮转] 无密码,点击一次性验证码登录")otp_btn.click()time.sleep(8)if _is_google_redirect(page):logger.warning("[轮转] 切换一次性验证码登录后误跳转到 Google 登录: %s", page.url)restore_failed = Trueelse:if not _submit_reinvite_primary_step(page,pwd_input,["Continue", "继续", "Log in", "登录"],"提交登录步骤",wait_seconds=8,):restore_failed = Trueexcept Exception:pass# 可能需要邮箱验证码code_input = Nonetry:code_input = page.locator('input[name="code"], input[placeholder*="验证码"]').firstif not code_input.is_visible(timeout=5000):code_input = Noneexcept Exception:code_input = Noneif not restore_failed and code_input and mail_client:import relogger.info("[轮转] 等待登录验证码...")otp = Nonestart_t = time.time()while time.time() - start_t < 120:emails = mail_client.search_emails_by_recipient(email, size=10)for em in emails:subj = em.get("subject", "").lower()if "invited" in subj:continuetext = em.get("text", "") or em.get("content", "")match = re.search(r"\b(\d{6})\b", text)if match:otp = match.group(1)breakif otp:breaktime.sleep(3)if otp:logger.info("[轮转] 输入验证码: %s", otp)code_input.fill(otp)time.sleep(0.5)if not _submit_reinvite_primary_step(page,code_input,["Continue", "继续", "Verify", "验证"],"提交邮箱验证码",wait_seconds=5,):restore_failed = Truescreenshot(page, "reinvite_final.png")logger.info("[轮转] 当前 URL: %s", page.url)if not restore_failed and _is_google_redirect(page):logger.warning("[轮转] 登录流程误跳转到 Google 登录: %s", page.url)restore_failed = Truebrowser.close()if restore_failed:logger.warning("[轮转] 旧账号恢复流程失败,保持 standby: %s", email)update_account(email, status=STATUS_STANDBY)return Falseif not _is_email_in_team(email):logger.warning("[轮转] 旧账号登录后仍未进入 Team,恢复失败: %s", email)update_account(email, status=STATUS_STANDBY)return False# 更新状态update_account(email, status=STATUS_ACTIVE, last_active_at=time.time())# 刷新 Codex tokenbundle = login_codex_via_browser(email, password, mail_client=mail_client)if bundle:auth_file = save_auth_file(bundle)update_account(email, auth_file=auth_file)logger.info("[轮转] 旧账号已恢复: %s", email)else:# 尝试用已有的 refresh_tokenauth_file = acc.get("auth_file")if auth_file and Path(auth_file).exists():auth_data = json.loads(read_text(Path(auth_file)))rt = auth_data.get("refresh_token")if rt:new_tokens = refresh_access_token(rt)if new_tokens:auth_data["access_token"] = new_tokens["access_token"]auth_data["refresh_token"] = new_tokens.get("refresh_token", rt)auth_data["last_refresh"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())write_text(Path(auth_file), json.dumps(auth_data, indent=2))logger.info("[轮转] 旧账号已恢复(token 已刷新): %s", email)return Truelogger.warning("[轮转] 旧账号已登录但 Codex token 刷新失败: %s", email)return True131 unmodified lines# 优先复用旧账号(先验证额度是否真的恢复了)filled = 0standby_list = [a for a in get_standby_accounts() if not _is_main_account_email(a.get("email"))]skipped = []for acc in standby_list:if filled >= vacancies:1 unmodified lineemail = acc["email"]auth_file = acc.get("auth_file")# 验证额度是否真的恢复了quota_ok = Falseif auth_file and Path(auth_file).exists():7 unmodified linesif quota_info:update_account(email, last_quota=quota_info)logger.info("[4/5] 跳过 %s(额度未恢复)", email)skipped.append(acc)continueif status_str == "ok" and isinstance(info, dict):p_remain = 100 - info.get("primary_pct", 0)if p_remain < threshold:logger.info("[4/5] 跳过 %s(剩余 %d%% < %d%%)", email, p_remain, threshold)skipped.append(acc)continuequota_ok = True# auth_error: token 失效,用 last_quota 判断(但重置时间已过的不算)4 unmodified linesif exhausted_info:window_label = _quota_window_label(exhausted_info.get("window"))logger.info("[4/5] 跳过 %s(%s额度未恢复)", email, window_label)skipped.append(acc)continuep_resets = lq.get("primary_resets_at", 0)if p_resets and time.time() >= p_resets:3 unmodified linesp_remain = 100 - lq.get("primary_pct", 0)if p_remain < threshold:logger.info("[4/5] 跳过 %s(上次额度 %d%% < %d%%)", email, p_remain, threshold)skipped.append(acc)continuequota_ok = Trueexcept Exception:7 unmodified linesif exhausted_info:window_label = _quota_window_label(exhausted_info.get("window"))logger.info("[4/5] 跳过 %s(%s额度未恢复)", email, window_label)skipped.append(acc)continuep_resets = lq.get("primary_resets_at", 0)if p_resets and time.time() >= p_resets:3 unmodified linesp_remain = 100 - lq.get("primary_pct", 0)if p_remain < threshold:logger.info("[4/5] 跳过 %s(历史额度 %d%% < %d%%)", email, p_remain, threshold)skipped.append(acc)continueelse:# 没有 last_quota,看 quota_resets_at 是否已过1 unmodified lineif resets_at and time.time() < resets_at:mins = max(0, int((resets_at - time.time()) / 60))logger.info("[4/5] 跳过 %s(%d 分钟后恢复)", email, mins)skipped.append(acc)continuelogger.info("[4/5] 复用: %s", email)3 unmodified linesfilled += 1current_count += 1else:skipped.append(acc)if skipped:logger.info("[4/5] 跳过 %d 个额度未恢复的旧号", len(skipped))remaining = TARGET - current_countif remaining <= 0:311 unmodified linesreusable = standby_list[standby_index]standby_index += 1email = reusable["email"]logger.info("[填充] 复用旧账号: %s", email)# 确保 chatgpt 浏览器可用if not chatgpt.browser:72 unmodified lines737475767778798081828384858687888990919293949596979899100101102736 unmodified lines839840841842843844642 unmodified lines148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519131 unmodified lines165116521653165416551656165716581 unmodified line1660166116621663166416651666166716681669167016717 unmodified lines16791680168116821683168416851686168716881689169016914 unmodified lines16961697169816991700170117023 unmodified lines17061707170817091710171117127 unmodified lines17201721172217231724172517263 unmodified lines17301731173217331734173517361 unmodified line17381739174017411742174317443 unmodified lines174817491750175117521753175417551756175717581759311 unmodified lines207120722073207420752076207720782079208072 unmodified linesreturn bool(_normalized_email(email)) and _normalized_email(email) == _normalized_email(get_admin_email())_GOOGLE_AUTO_REUSE_DOMAINS = {"gmail.com", "googlemail.com"}def _get_account_login_provider(acc: dict | None) -> str:acc = acc or {}for key in ("login_provider", "auth_provider", "oauth_provider"):provider = (acc.get(key) or "").strip().lower()if provider:return provideremail = _normalized_email(acc.get("email"))if "@" in email and email.rsplit("@", 1)[-1] in _GOOGLE_AUTO_REUSE_DOMAINS:return "google"return ""def _auto_reuse_skip_reason(acc: dict | None) -> str | None:provider = _get_account_login_provider(acc)if provider == "google":return "Google 登录账号暂不支持自动复用"return Nonedef sync_account_states(chatgpt_api=None):"""根据 Team 实际成员列表同步本地账号状态"""account_id = get_chatgpt_account_id()736 unmodified linesreturn exhausted_infodef _first_visible_editable_locator(page, selectors, timeout=800):try:locator = page.locator(selectors).first642 unmodified linesdef reinvite_account(chatgpt_api, mail_client, acc):"""恢复 standby 账号 — 复用统一的 Codex OAuth 登录流程。只有拿到 team plan 的认证结果,才视为恢复成功。"""email = acc["email"]password = acc.get("password", "")logger.info("[轮转] 恢复旧账号: %s(统一 OAuth 登录)", email)# 关闭 ChatGPT API 浏览器避免冲突if chatgpt_api and chatgpt_api.browser:chatgpt_api.stop()bundle = login_codex_via_browser(email, password, mail_client=mail_client)if not bundle:logger.warning("[轮转] 旧账号 OAuth 登录失败,保持 standby: %s", email)update_account(email, status=STATUS_STANDBY)return Falseplan_type = (bundle.get("plan_type") or "").lower()if plan_type != "team":logger.warning("[轮转] 旧账号登录后 plan=%s,不是 team,恢复失败: %s", plan_type or "unknown", email)update_account(email, status=STATUS_STANDBY)return Falseauth_file = save_auth_file(bundle)update_account(email, status=STATUS_ACTIVE, last_active_at=time.time(), auth_file=auth_file)logger.info("[轮转] 旧账号已恢复: %s", email)return True131 unmodified lines# 优先复用旧账号(先验证额度是否真的恢复了)filled = 0standby_list = [a for a in get_standby_accounts() if not _is_main_account_email(a.get("email"))]quota_skipped = []auto_reuse_skipped = []for acc in standby_list:if filled >= vacancies:1 unmodified lineemail = acc["email"]auth_file = acc.get("auth_file")skip_reason = _auto_reuse_skip_reason(acc)if skip_reason:logger.info("[4/5] 跳过 %s(%s)", email, skip_reason)auto_reuse_skipped.append(acc)continue# 验证额度是否真的恢复了quota_ok = Falseif auth_file and Path(auth_file).exists():7 unmodified linesif quota_info:update_account(email, last_quota=quota_info)logger.info("[4/5] 跳过 %s(额度未恢复)", email)quota_skipped.append(acc)continueif status_str == "ok" and isinstance(info, dict):p_remain = 100 - info.get("primary_pct", 0)if p_remain < threshold:logger.info("[4/5] 跳过 %s(剩余 %d%% < %d%%)", email, p_remain, threshold)quota_skipped.append(acc)continuequota_ok = True# auth_error: token 失效,用 last_quota 判断(但重置时间已过的不算)4 unmodified linesif exhausted_info:window_label = _quota_window_label(exhausted_info.get("window"))logger.info("[4/5] 跳过 %s(%s额度未恢复)", email, window_label)quota_skipped.append(acc)continuep_resets = lq.get("primary_resets_at", 0)if p_resets and time.time() >= p_resets:3 unmodified linesp_remain = 100 - lq.get("primary_pct", 0)if p_remain < threshold:logger.info("[4/5] 跳过 %s(上次额度 %d%% < %d%%)", email, p_remain, threshold)quota_skipped.append(acc)continuequota_ok = Trueexcept Exception:7 unmodified linesif exhausted_info:window_label = _quota_window_label(exhausted_info.get("window"))logger.info("[4/5] 跳过 %s(%s额度未恢复)", email, window_label)quota_skipped.append(acc)continuep_resets = lq.get("primary_resets_at", 0)if p_resets and time.time() >= p_resets:3 unmodified linesp_remain = 100 - lq.get("primary_pct", 0)if p_remain < threshold:logger.info("[4/5] 跳过 %s(历史额度 %d%% < %d%%)", email, p_remain, threshold)quota_skipped.append(acc)continueelse:# 没有 last_quota,看 quota_resets_at 是否已过1 unmodified lineif resets_at and time.time() < resets_at:mins = max(0, int((resets_at - time.time()) / 60))logger.info("[4/5] 跳过 %s(%d 分钟后恢复)", email, mins)quota_skipped.append(acc)continuelogger.info("[4/5] 复用: %s", email)3 unmodified linesfilled += 1current_count += 1else:quota_skipped.append(acc)if quota_skipped:logger.info("[4/5] 跳过 %d 个额度未恢复或复用失败的旧号", len(quota_skipped))if auto_reuse_skipped:logger.info("[4/5] 跳过 %d 个暂不支持自动复用的旧号", len(auto_reuse_skipped))remaining = TARGET - current_countif remaining <= 0:311 unmodified linesreusable = standby_list[standby_index]standby_index += 1email = reusable["email"]skip_reason = _auto_reuse_skip_reason(reusable)if skip_reason:logger.info("[填充] 跳过旧账号: %s(%s)", email, skip_reason)continuelogger.info("[填充] 复用旧账号: %s", email)# 确保 chatgpt 浏览器可用if not chatgpt.browser:
59 unmodified lines60616259 unmodified lines("status", None),]assert chatgpt.stopped == 159 unmodified lines6061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011159 unmodified lines("status", None),]assert chatgpt.stopped == 1def test_cmd_fill_skips_google_accounts_during_auto_reuse(monkeypatch):chatgpt = _FakeChatGPT()count_values = iter([4, 5])events = []monkeypatch.setattr(manager, "ChatGPTTeamAPI", lambda: chatgpt)monkeypatch.setattr(manager, "CloudMailClient", lambda: _FakeMailClient())monkeypatch.setattr(manager, "get_team_member_count", lambda _chatgpt: next(count_values))monkeypatch.setattr(manager,"get_standby_accounts",lambda: [{"email": "bubblehuntr@gmail.com", "_quota_recovered": True},{"email": "old-2@example.com", "_quota_recovered": True},],)def fake_reinvite(_chatgpt, _mail, acc):events.append(("reinvite", acc["email"]))return Truemonkeypatch.setattr(manager, "reinvite_account", fake_reinvite)monkeypatch.setattr(manager,"create_new_account",lambda _chatgpt, _mail: events.append(("create", None)) or True,)monkeypatch.setattr(manager, "sync_to_cpa", lambda: events.append(("sync", None)))monkeypatch.setattr(manager, "cmd_status", lambda: events.append(("status", None)))manager.cmd_fill(target=5)assert events == [("reinvite", "old-2@example.com"),("sync", None),("status", None),]assert chatgpt.stopped == 1def test_auto_reuse_skip_reason_detects_google_provider_and_gmail():assert manager._auto_reuse_skip_reason({"email": "bubblehuntr@gmail.com"}) == "Google 登录账号暂不支持自动复用"assert (manager._auto_reuse_skip_reason({"email": "user@example.com", "login_provider": "google"})== "Google 登录账号暂不支持自动复用")assert manager._auto_reuse_skip_reason({"email": "user@example.com"}) is None
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101112 unmodified lines114115116117118119120121122123124125126127128129130import sysimport typesfrom autoteam import accounts, managerclass _FakeLocator:def __init__(self, visible=False):self._visible = visibleself.value = Noneself.clicked = False@propertydef first(self):return selfdef is_visible(self, timeout=None):return self._visibledef fill(self, value):self.value = valuedef click(self):self.clicked = Trueclass _FakePage:def __init__(self):self.url = ""self.email_input = _FakeLocator(visible=True)self.password_input = _FakeLocator(visible=False)self.code_input = _FakeLocator(visible=False)self.login_button = _FakeLocator(visible=False)def goto(self, url, **kwargs):self.url = urldef content(self):return "<html></html>"def locator(self, selector):if selector == 'button:has-text("登录"), button:has-text("Log in")':return self.login_buttonif selector == 'input[name="email"], input[type="email"]':return self.email_inputif selector == 'input[type="password"]':return self.password_inputif selector == 'input[name="code"], input[placeholder*="验证码"]':return self.code_inputreturn _FakeLocator(visible=False)class _FakeContext:def __init__(self, page):self._page = pagedef new_page(self):return self._pageclass _FakeBrowser:def __init__(self, page):self._page = pageself.closed = Falsedef new_context(self, **kwargs):return _FakeContext(self._page)def close(self):self.closed = Trueclass _FakePlaywright:def __init__(self, page):self.chromium = types.SimpleNamespace(launch=lambda **kwargs: _FakeBrowser(page))class _FakeSyncPlaywright:def __init__(self, page):self._playwright = _FakePlaywright(page)def __enter__(self):return self._playwrightdef __exit__(self, exc_type, exc, tb):return Falsedef test_reinvite_account_stops_when_primary_submit_redirects_to_google(monkeypatch):page = _FakePage()updates = []click_labels = []fake_invite_module = types.ModuleType("autoteam.invite")fake_invite_module.screenshot = lambda page_obj, name: Nonemonkeypatch.setitem(sys.modules, "autoteam.invite", fake_invite_module)monkeypatch.setattr("playwright.sync_api.sync_playwright", lambda: _FakeSyncPlaywright(page))monkeypatch.setattr(manager.time, "sleep", lambda *_args, **_kwargs: None)def fake_click_primary(page_obj, field, labels):click_labels.append(tuple(labels))page_obj.url = "https://accounts.google.com/v3/signin/identifier"return Truemonkeypatch.setattr(manager, "_click_primary_auth_button", fake_click_primary)monkeypatch.setattr(manager, "_is_email_in_team", lambda email: (_ for _ in ()).throw(AssertionError("should not check team")))monkeypatch.setattr(manager,2 unmodified lines)monkeypatch.setattr(manager,"login_codex_via_browser",lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("should not refresh codex")),)result = manager.reinvite_account(types.SimpleNamespace(browser=None),None,{"email": "tmp-user@example.com", "password": "secret"},)assert result is Falseassert page.email_input.value == "tmp-user@example.com"assert click_labels == [("Continue", "继续")]assert updates == [("tmp-user@example.com", {"status": accounts.STATUS_STANDBY})]12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364652 unmodified lines686970717273747576777879808182import typesfrom autoteam import accounts, managerdef test_reinvite_account_uses_unified_oauth_login_and_marks_active(monkeypatch):updates = []monkeypatch.setattr(manager,"login_codex_via_browser",lambda email, password, mail_client=None: {"email": email,"access_token": "token-1","refresh_token": "refresh-1","plan_type": "team",},)monkeypatch.setattr(manager, "save_auth_file", lambda bundle: f"/tmp/{bundle['email']}.json")monkeypatch.setattr(manager,"update_account",lambda email, **kwargs: updates.append((email, kwargs)),)monkeypatch.setattr(manager.time, "time", lambda: 1234567890)monkeypatch.setattr(manager,"_is_email_in_team",lambda email: (_ for _ in ()).throw(AssertionError("should not check team membership separately")),)result = manager.reinvite_account(types.SimpleNamespace(browser=False),None,{"email": "tmp-user@example.com", "password": "secret"},)assert result is Trueassert updates == [("tmp-user@example.com",{"status": accounts.STATUS_ACTIVE,"last_active_at": 1234567890,"auth_file": "/tmp/tmp-user@example.com.json",},)]def test_reinvite_account_marks_standby_when_oauth_login_returns_non_team(monkeypatch):updates = []monkeypatch.setattr(manager,"login_codex_via_browser",lambda email, password, mail_client=None: {"email": email,"access_token": "token-1","refresh_token": "refresh-1","plan_type": "free",},)monkeypatch.setattr(manager,2 unmodified lines)monkeypatch.setattr(manager,"_is_email_in_team",lambda email: (_ for _ in ()).throw(AssertionError("should not check team membership separately")),)result = manager.reinvite_account(types.SimpleNamespace(browser=False),None,{"email": "tmp-user@example.com", "password": ""},)assert result is Falseassert updates == [("tmp-user@example.com", {"status": accounts.STATUS_STANDBY})]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263from autoteam import manager
class _FakeChatGPT: def __init__(self): self.browser = True self.started = 0 self.stopped = 0
def start(self): self.browser = True self.started += 1
def stop(self): self.browser = False self.stopped += 1
class _FakeMailClient: def login(self): return None
def test_cmd_rotate_skips_google_accounts_during_auto_reuse(monkeypatch): chatgpt = _FakeChatGPT() count_values = iter([4, 5]) events = []
monkeypatch.setattr(manager, "sync_account_states", lambda: events.append(("sync_account_states", None))) monkeypatch.setattr(manager, "cmd_check", lambda: events.append(("cmd_check", None))) monkeypatch.setattr(manager, "ChatGPTTeamAPI", lambda: chatgpt) monkeypatch.setattr(manager, "CloudMailClient", lambda: _FakeMailClient()) monkeypatch.setattr(manager, "load_accounts", lambda: []) monkeypatch.setattr(manager, "get_team_member_count", lambda _chatgpt: next(count_values)) monkeypatch.setattr( manager, "get_standby_accounts", lambda: [ {"email": "bubblehuntr@gmail.com"}, {"email": "old-2@example.com"}, ], ) monkeypatch.setattr( manager, "reinvite_account", lambda _chatgpt, _mail, acc: events.append(("reinvite", acc["email"])) or True, ) monkeypatch.setattr( manager, "create_new_account", lambda _chatgpt, _mail: events.append(("create", None)) or True, ) monkeypatch.setattr(manager, "sync_to_cpa", lambda: events.append(("sync_to_cpa", None)))
manager.cmd_rotate(target_seats=5)
assert events == [ ("sync_account_states", None), ("cmd_check", None), ("reinvite", "old-2@example.com"), ("sync_to_cpa", None), ] assert chatgpt.stopped == 1src/autoteam/manager.py+60-195
tests/unit/test_manager_fill.py+49
tests/unit/test_manager_reinvite.py+53-101
tests/unit/test_manager_rotate.pyAdded+63