Skip to content

feat: improve cookie expired detection and initialization UX#186

Merged
QuBenhao merged 2 commits intomasterfrom
fix/cookie-expired-prompt
Apr 19, 2026
Merged

feat: improve cookie expired detection and initialization UX#186
QuBenhao merged 2 commits intomasterfrom
fix/cookie-expired-prompt

Conversation

@QuBenhao
Copy link
Copy Markdown
Owner

Summary

  • Add distinct prompts for "cookie not found in browser" vs "browser cookie expired"
  • Verify browser cookie immediately after detection, prompt re-login if expired
  • Add "skip remaining config" option to use existing settings from .env
  • Fix missing separator line when config not saved
  • leetcode_cookie_updater.py now validates cookie expiry before returning

Test plan

  • Test initialization with expired browser cookie - should prompt re-login
  • Test initialization with no browser cookie - should show "not found" message
  • Test "skip remaining config" option - should use existing .env values
  • Test choosing not to save config - should show warning with separator

🤖 Generated with Claude Code

- Add distinct prompts for "cookie not found" vs "cookie expired"
- Verify browser cookie immediately after detection, prompt re-login if expired
- Add "skip remaining config" option to use existing settings
- Fix missing separator line when config not saved
- leetcode_cookie_updater.py now validates cookie expiry

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@QuBenhao
Copy link
Copy Markdown
Owner Author

代码审查

✅ 优点

  1. 用户体验改进

    • 区分了「浏览器未找到 Cookie」和「Cookie 已过期」两种场景,提示更加精准
    • 新增「跳过剩余配置」选项,避免重复配置流程
    • 立即验证浏览器 Cookie,发现问题可以当场重试
  2. 代码结构

    • 将 Cookie 验证提前到检测后立即执行,逻辑更清晰
    • 添加了缺失的分割线,输出更整齐
  3. 国际化

    • 中英文提示同步更新,保持一致

⚠️ 建议改进

1. leetcode.py 第 117-121 行

if env_file.exists():
    try:
        load_dotenv(dotenv_path=env_file.as_posix())
    except Exception:
        pass

建议:捕获异常后应该打印警告,否则如果 load_dotenv 失败,用户不知道发生了什么。

if env_file.exists():
    try:
        load_dotenv(dotenv_path=env_file.as_posix())
    except Exception as e:
        print(f"⚠️  加载现有配置失败: {e}")

2. leetcode.py 第 85-95 行 - 重试登录流程

当前逻辑:

if retry != "n":
    print(t("init_waiting_login"))
    input()  # Wait for user
    continue  # 重新获取浏览器 cookie

问题:如果用户多次登录失败,没有退出机制,会无限循环。

建议添加最大重试次数或退出选项:

max_retries = 3
retry_count = 0
while retry_count < max_retries:
    # ... existing logic ...
    if retry != "n":
        retry_count += 1
        # ...
    else:
        break

3. leetcode_cookie_updater.py 第 47 行

from python.utils import check_cookie_expired

这个导入依赖于 sys.path.insert,如果项目结构变化可能失效。

建议:考虑使用相对导入或确保 PYTHONPATH 正确设置。


🔍 其他观察

  1. 测试计划未完成 - PR body 中的 test plan 都是未勾选状态,建议完成测试后再合并

  2. CHANGELOG - 如果这是一个用户可见的功能改进,考虑更新 CHANGELOG


📝 总结

这是一个很好的用户体验改进 PR!主要建议:

  1. 异常处理增加日志
  2. 重试逻辑增加上限
  3. 完成测试计划

审批意见:Approve with suggestions 🎉

- Add warning when load_dotenv fails instead of silently passing
- Add max retry limit (3) for browser cookie re-login flow
- Add i18n keys for new warnings

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@QuBenhao QuBenhao merged commit 0c3a034 into master Apr 19, 2026
@QuBenhao QuBenhao deleted the fix/cookie-expired-prompt branch April 19, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant