Commit Graph

8 Commits

Author SHA1 Message Date
starmen1265 d9861aa6c3 feat(07-03): implement login CLI subcommand
- Add login_command function with QR code login, cookie import, and status check
- Add login subcommand with --import-cookie and --status options
- Update CLI help text with login examples
- Fix mock paths in tests to match actual import locations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 18:10:43 +08:00
starmen1265 94c85baac9 test(07-03): add failing tests for login CLI subcommand
- Test login_default_mode - default QR code login flow
- Test login_import_cookie - --import-cookie JSON import
- Test login_status - --status cookie validation
- Test login_integration - successful login saves cookie
- Test login_error_handling - exception handling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 18:01:53 +08:00
starmen1265 32bb22008b test(07-03): add failing tests for cookie validation
- Test validate_cookie_valid - valid cookie returns user info
- Test validate_cookie_expired - expired cookie returns False
- Test validate_cookie_empty - empty cookie returns False
- Test validate_cookie_malformed - network error handling
- Test validate_cookie_other_status_code - non-200/401 handling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:59:28 +08:00
starmen1265 072d83da35 feat(07-01): implement ZhihuLogin QR code login class
TDD GREEN phase - implementation passes all 8 tests:

- ZhihuLoginResult: Pydantic model for login results
- ZhihuLogin: Main class with QR code login flow
  - LOGIN_URL: https://www.zhihu.com/signin
  - CANVAS_SELECTORS: Multiple fallback selectors for QR canvas
  - _find_qrcode_canvas(): Find canvas with fallback selectors
  - _save_qrcode_image(): Save QR code to intermediate directory
  - check_login_cookie(): Detect z_c0 cookie for login state
  - get_cookies_str(): Extract cookie string from context
  - _wait_for_login(): Poll with configurable timeout (tenacity)
  - login_by_qrcode(): Main entry point for login flow

Key design decisions:
- Uses tenacity Retrying for configurable timeout
- QR code saved to intermediate_path with timestamp
- Multiple canvas selectors for robustness
- Proper browser lifecycle management

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:54:06 +08:00
starmen1265 fb9bc2d1ed test(07-01): add failing tests for ZhihuLogin QR code login
TDD RED phase - tests expect ZhihuLogin class that doesn't exist yet:

- test_login_page_access: verify correct login URL
- test_qrcode_screenshot: verify QR code capture and save
- test_cookie_detection_with_z_c0: verify login detection
- test_cookie_detection_without_z_c0: verify no login when missing z_c0
- test_cookie_extraction: verify cookie string format
- test_login_timeout: verify timeout after 60s polling
- test_result_model_success: verify success result model
- test_result_model_failure: verify failure result model

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:50:26 +08:00
starmen1265 19c377ef65 test(07-02): add failing tests for Cookie persistence
- Test save_cookie creates env file
- Test save_cookie updates existing line
- Test save_cookie appends new line
- Test save_cookie preserves other lines
- Test save_cookie sets file permissions to 600
- Test load_cookie returns saved value
- Test load_cookie returns empty if file not exists

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:49:47 +08:00
starmen1265 f90de6b8a6 test(07-01): add auth test fixtures
- Create tests/test_auth/conftest.py with pytest fixtures
- mock_browser: Mock PlaywrightBrowser for unit testing
- mock_canvas: Mock canvas element for QR code screenshot
- sample_cookies: Test cookie data with z_c0 login cookie
- sample_cookies_no_login: Test cookies without login state
- mock_env_file: Temporary .kb_env file fixture
- intermediate_path: Temporary intermediate directory fixture

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:49:22 +08:00
starmen1265 af3536aa92 test(07-02): add failing tests for Cookie JSON parsing
- Test parse_json_cookies for Chrome Cookie Editor format
- Test domain filtering for zhihu.com
- Test empty array handling
- Test malformed JSON error handling
- Test file not found error handling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:48:23 +08:00