Commit Graph

38 Commits

Author SHA1 Message Date
starmen1265 ee0fc74378 fix(download): return author name instead of mid in _extract_author
PR Test / lint (pull_request) Successful in 1s
- Fix download processor to return actual author name (e.g. "HOLA小测佬")
  instead of B站用户ID (mid, e.g. "406636263")
- Add 5 test cases for author extraction logic
- Resolves report display issue where UP主名称 showed numeric ID

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 13:50:02 +08:00
starmen1265 fae4ff2f28 fix(06-03): update test import to use new package structure
- Remove sys.path manipulation from test file
- Use standard package import from kb_workflow.metadata
- Test file now follows the same import pattern as production code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 00:35:31 +08:00
starmen1265 c9ca1b538d refactor(06-02): update CLI and test imports to kb_workflow.pipeline
- Remove sys.path manipulation from kb_workflow.py
- Update CLI imports to use kb_workflow.pipeline prefix
- Update all test file imports and patch paths

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 00:17:10 +08:00
starmen1265 766283366e refactor(06-01): delete original metadata directories and update tests
- Remove kb-bilibili-metadata/ and kb-zhihu-metadata/ directories
- Create kb_workflow/__init__.py to export main and process_command
- Update test_cli/test_process_command.py imports for new package structure

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 00:06:01 +08:00
starmen1265 ccfa201250 fix(05-03): fix pre-existing test issues blocking verification
- Fix test_workflow_skips_completed_steps to mock _ask_rerun_step
- Fix test_fetch_video_metadata_success to use AsyncMock
- Document other pre-existing test issues in deferred-items.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 23:28:27 +08:00
starmen1265 360aee200f test(05-03): add Pipeline archive integration tests
- Test pipeline includes archive step
- Test archive uses platform directory structure
- Test no date-based subdirectories in archive
- Update default steps assertion to include archive

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 23:26:14 +08:00
starmen1265 be783f97fa test(05-03): add ArchiveProcessor unit tests
- Test archive copies to correct platform directory
- Test filename format {YYYYMMDD}_{content_id}_analysis.md
- Test skip when step already completed
- Test detect existing archive by content_id
- Test handle missing analysis file with error

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 23:24:17 +08:00
starmen1265 f05c93d2b1 fix(zhihu): remove noscript tags to prevent duplicate images
PR Test / lint (pull_request) Successful in 1s
Zhihu HTML structure includes noscript fallback images:
<figure><img data-actualsrc=...><noscript><img src=...></noscript></figure>

After fixing lazy-load (replacing src with data-actualsrc), both imgs
have real URLs, causing duplicates. The fix removes noscript tags before
processing img elements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 15:08:08 +08:00
starmen1265 8ad64a4d1b fix(asr): use content_dir for subtitle output instead of video_path
PR Test / lint (pull_request) Successful in 2s
- Add content_dir field to ASRInput schema
- Pass content_dir from pipeline when creating ASRInput
- Modify _try_official_subtitle to use content_dir for output
- Modify _run_whisper_basic to use content_dir for output
- Add validation for empty video_path in Whisper fallback

Root cause: DownloadProcessor sets content_file="" for video types,
causing Path("").parent to resolve to current directory instead of
content directory. Subtitle files were written to wrong location.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 22:59:24 +08:00
starmen1265 b6ff7c81aa fix(zhihu): handle lazy-load images in markdown conversion
知乎使用图片懒加载机制,`<img>` 标签的 `src` 属性包含 SVG 占位符,
真实图片 URL 在 `data-actualsrc` 或 `data-original` 属性中。
`markdownify` 只读取 `src`,导致转换后得到无效占位符。

修复:在转换前预处理 HTML,将真实图片 URL 替换到 `src` 属性。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 22:59:24 +08:00
starmen1265 377794b5b3 test(04-05): add end-to-end integration tests
- Test full workflow execution from URL to analysis
- Test workflow error handling
- Test state persistence
- Test workflow resumability (skip completed steps)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:46:46 +08:00
starmen1265 76aefa23e1 test(04-05): add failing tests for CLI process subcommand
- Test process --help shows usage
- Test process <url> calls Pipeline.run()
- Test invalid URL returns error
- Test --output-dir flag
- Test --no-skip flag

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:43:06 +08:00
starmen1265 5d4cb93f8b test(04-04): add schema validation tests for PipelineInput/Output/Config
- Test PipelineInput validates url field (required)
- Test PipelineOutput contains results dict
- Test PipelineConfig has default steps list
- Test PipelineConfig allows custom output_dir

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:37:28 +08:00
starmen1265 0b7d8707bf feat(04-03): implement AnalyzeProcessor with DeepAnalyzer integration
- AnalyzeProcessor wraps existing DeepAnalyzer for pipeline integration
- Loads metadata and content from JSON files
- Generates analysis reports as Markdown with frontmatter
- Records state on success and failure
- Supports both video and article content types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:32:31 +08:00
starmen1265 87d64b57c0 test(04-03): add failing tests for AnalyzeInput/AnalyzeOutput schemas
- Test schema validation for AnalyzeInput (metadata_file, content_file, content_type, output_file)
- Test schema validation for AnalyzeOutput (analysis_file, summary, main_topics, key_insights, tags, stats)
- Test AnalyzeProcessor integration with DeepAnalyzer
- Test state recording on success and failure

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:27:59 +08:00
starmen1265 ec268f7d17 feat(04-02): add content downloading and module export for DownloadProcessor
TDD GREEN phase:
- DownloadProcessor downloads article/answer/zhuanlan content
- Video content is skipped (handled by ASR in Phase 3)
- Content files saved with correct naming convention
- DownloadProcessor exported from kb_pipeline.processors
- All 17 tests pass

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:24:00 +08:00
starmen1265 fc6fba76b2 feat(04-02): implement DownloadProcessor with metadata fetching
TDD GREEN phase:
- DownloadProcessor inherits from BaseProcessor
- Fetches metadata from Bilibili and Zhihu adapters
- Saves metadata to content_dir as JSON
- Records state on success/failure
- Skips step if already completed (idempotency)
- All metadata tests pass

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:22:48 +08:00
starmen1265 567bd32c94 test(04-02): add failing tests for DownloadProcessor metadata fetching
TDD RED phase:
- Test DownloadProcessor fetches Bilibili video metadata correctly
- Test DownloadProcessor fetches Zhihu answer metadata correctly
- Test DownloadProcessor records state on success
- Test DownloadProcessor records state on failure

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:19:21 +08:00
starmen1265 9d5c3ffc48 test(04-02): add failing tests for DownloadInput/DownloadOutput schemas
TDD RED phase:
- Test DownloadInput validates required fields (content_dir, content_type)
- Test DownloadOutput validates required fields (metadata_file, content_file, title, author)
- Test DownloadOutput handles both video and article content types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:17:54 +08:00
starmen1265 06d36fc440 feat(04-01): implement ParseProcessor and update module exports
- ParseProcessor wraps LinkParser for URL parsing
- Returns ParseOutput with platform, content_type, content_id
- Records state when state_manager is provided
- Handles unknown URLs with success=False
- Export BaseProcessor, ParseProcessor, ASRProcessor from __init__.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:14:32 +08:00
starmen1265 efddef98d3 feat(04-01): add ParseInput and ParseOutput schemas
- ParseInput extends StepInput with url field
- ParseOutput extends StepOutput with platform, content_type, content_id, resolved_url, original_url
- Tests for schema validation and inheritance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:11:44 +08:00
starmen1265 3ad2576aed test(04-01): add failing tests for BaseProcessor abstract class
- Test BaseProcessor cannot be instantiated directly
- Test subclass must implement process() method
- Test state_manager attribute is provided
- Test STEP_NAME class attribute requirement

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:10:52 +08:00
starmen1265 6b3fae3543 test(03-01): fix state recording test mock behavior
- Fix test_state_recording_failure to use correct mock pattern
- _try_official_subtitle returning None triggers _Whisper` fallback
- Ensure proper exception propagation for accurate failure recording

- All 22 tests passing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 19:27:21 +08:00
starmen1265 b2330c32c8 test(03-01): add ASRInput and ASROutput schemas
- Add ASRInput schema with video_path and content_type fields
- Add ASROutput schema with tool/has_subtitle/output_files/segments/text/duration_seconds/speakers
- Create test_processors directory with conftest fixtures
- Add comprehensive schema tests (8 test cases)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 19:20:17 +08:00
starmen1265 a6f4d34625 test(02-03): add failing tests for ZhihuAdapter
- Test answer content extraction
- Test zhuanlan (article) content extraction
- Test cookie-based authentication
- Test login page detection
- Test AuthError handling for missing/expired cookies

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 18:24:37 +08:00
starmen1265 d17fbd8118 test(02-02): add article content tests with YAML frontmatter
- Add test for article content returning Markdown format
- Add test for YAML frontmatter with required fields
- Add test for video content returning empty (ASR handling)
- Add test for unsupported content type error

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 18:24:17 +08:00
starmen1265 b74f6a0c73 feat(02-02): implement BilibiliAdapter for video and article metadata
- Implement PlatformAdapter interface for Bilibili platform
- Add video metadata extraction (BV号)
- Add article metadata extraction (CV号)
- Add automatic retry on network errors (3 attempts)
- Add state recording for failed steps
- Add content type identification from URL
- Add output filename generation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 18:23:11 +08:00
starmen1265 3f42bfaf0d test(02-02): add failing tests for PlatformAdapter base class
- Add test for abstract class instantiation prevention
- Add test for incomplete implementation detection
- Add test for complete implementation instantiation
- Add test for async method signatures
- Add shared fixtures for platform tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 18:19:24 +08:00
starmen1265 bd29425d28 feat(02-01): add IdempotencyChecker for file existence checking
- Create IdempotencyChecker class with check_exists method
- Check for metadata JSON and content Markdown files
- Return tuple of (all_exist, existing_files)
- Follow naming convention: {platform}_{content_id}_{type}.{ext}
- Add get_expected_files helper method
- Add 8 unit tests covering all scenarios

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 18:13:35 +08:00
starmen1265 dd94f068e7 feat(02-01): add LinkParser and ParsedLink for unified URL parsing
- Create ParsedLink dataclass with platform, content_type, content_id fields
- Implement LinkParser class with regex-based URL parsing
- Support Bilibili video/article URLs (with/without www)
- Support Zhihu answer/zhuanlan URLs
- Support b23.tv short link resolution with requests.head
- Return None for unrecognized URLs (no exceptions)
- Add 15 unit tests covering all supported URL types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 18:12:16 +08:00
starmen1265 c87dd8b803 test(01-03): add failing tests for retry mechanism
- Test retry on NetworkError (up to 3 times)
- Test no retry on non-NetworkError (ValidationError)
- Test reraise after max attempts
- Test preserved return value on success
- Test exponential backoff configuration
- Test cause exception preservation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 17:17:51 +08:00
starmen1265 44b5d18113 feat(01-03): implement configuration management with pydantic-settings
- KBSettings class loading from ~/.kb_env file
- Required fields: base_path, archive_path
- Optional fields: git_root, git_user, git_email
- Secret fields: hf_token, zhihu_cookie (SecretStr)
- get_settings() singleton with lru_cache
- env_prefix "KB_" for environment variables
- Tests adjusted for proper env isolation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 17:17:10 +08:00
starmen1265 624cd76538 feat(01-01): implement WorkflowStateManager with atomic write
GREEN phase: Implement state management with:
- Atomic write pattern (temp file + os.replace)
- Backup rotation (workflow_state.json -> .bak)
- Backup fallback on corruption
- get_or_create idempotent creation

Fix test to properly create backup before corruption test.

All 20 tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 17:16:30 +08:00
starmen1265 e789d81230 test(01-03): add failing tests for configuration management
- Test KBSettings required fields (base_path, archive_path)
- Test KBSettings optional fields with defaults
- Test secret fields (hf_token, zhihu_cookie) as SecretStr
- Test missing required fields raises ValidationError
- Test get_settings returns singleton via lru_cache
- Test env vars with KB_ prefix are read

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 17:15:35 +08:00
starmen1265 246e4038b4 test(01-01): add failing tests for WorkflowStateManager
RED phase: 20 test cases for:
- WorkflowState.is_step_completed (5 tests)
- WorkflowState.mark_step_* methods (4 tests)
- WorkflowStateManager atomic write (4 tests)
- WorkflowStateManager backup fallback (4 tests)
- WorkflowStateManager.get_or_create (3 tests)

11 tests fail due to missing kb_pipeline.state module.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 17:15:02 +08:00
starmen1265 840559075a test(01-03): add failing tests for error handling
- Test ErrorType enum (NETWORK, VALIDATION, SYSTEM, AUTH)
- Test KBError base class with to_dict method
- Test NetworkError with status_code and auto-suggestion
- Test ValidationError with validation_errors list
- Test SystemError with system_message
- Test AuthError with auth_type
- Test error class hierarchy

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 17:13:50 +08:00
starmen1265 7ffaafd615 refactor(01-02): add comprehensive tests for full coverage
- Add tests for WorkflowState methods (mark_step_started, mark_step_completed, mark_step_failed)
- Add tests for StepResult schema
- Add tests for StepDefinition schema with dependencies
- Achieve 100% test coverage on kb_pipeline/schemas.py
- Total 37 tests passing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 17:08:51 +08:00
starmen1265 85413bc1c6 test(01-02): add failing tests for core pipeline schemas
- Create kb_pipeline package structure
- Add test fixtures in conftest.py
- Add 28 test cases for StepInput, StepOutput, StepStatus, StepRecord, WorkflowState
- Add JSON serialization/deserialization tests
- TDD RED phase: tests fail because schemas.py not yet implemented

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