refactor(fetch-all): reuse notion fetch pipeline#28
Conversation
PR Code Suggestions ✨Latest suggestions up to acf5500 Previous suggestionsSuggestions up to commit 2043324
Suggestions up to commit 23b60c9
Suggestions up to commit 8a93e0c
Suggestions up to commit 8a93e0c
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
6f70b58 to
5b2329a
Compare
…ilities - Add notionFixtures.ts with reusable test data structures - Enhance helpers.ts with proper axios mocking patterns - Improve mocks.ts with better mock implementations - Update index.ts to export new test utilities These utilities provide foundation for reliable test data creation, proper HTTP mocking, and hermetic test isolation across the test suite.
- Add downloadImage.test.ts with retry logic and error handling tests - Add runFetchPipeline.test.ts with pipeline coordination tests - Add integration.test.ts with test utility validation - Fix generateBlocks.test.ts with proper test structure Key improvements: - Implements exponential backoff retry testing with fake timers - Comprehensive error handling coverage (timeouts, DNS, HTTP errors) - Proper test data structure with Sub-item relations for multi-language pages - Full mocking of axios, SpinnerManager, and image processing pipeline - Hermetic tests with proper fs mocking to prevent file system side effects All tests now pass (30+ assertions) providing reliable regression protection for the Notion fetch pipeline, replacing need for manual testing.
- Add index.cli.test.ts with comprehensive CLI component testing - Fix static method mocking for PreviewGenerator, StatusAnalyzer, ComparisonEngine - Correct test imports to work with actual static class methods - Add proper environment variable validation testing Key fixes: - Mock static methods instead of instance methods (generatePreview, analyzePublicationStatus, compareWithPublished) - Update test assertions to validate static class API instead of instance API - Ensure proper CLI initialization and error handling coverage All 7 CLI tests now pass, providing coverage for the notion-fetch-all command-line interface and its core components.
- Fix existing generateBlocks.test.ts with proper runFetchPipeline import - Update TASK.md to reflect all completed deliverables and blockers resolved - Ensure test imports match actual function names in implementation This completes the final pieces of the test reliability improvement task, ensuring all existing tests work with the new comprehensive test suite.
All deliverables from the Notion fetch test suite stabilization task have been successfully completed: - ✅ Fixed axios mocking and runFetch typos - ✅ Added comprehensive retry, error handling, and fallback behavior tests - ✅ Implemented hermetic testing with proper fs mocking - ✅ All 37 tests passing across notion-fetch and notion-fetch-all suites The test suite is now reliable and trustworthy enough to replace manual regression testing as originally requested.
…essing - Add robust title fallback logic in resolvePageTitle() function - Implement createStandalonePageGroup() for pages without sub-items - Fix heading consumption bug in Toggle section processing - Update test fixtures and enhance test coverage - Achieve 100% test pass rate (13/13 tests passing) Resolves all issues documented in TASK.md: - Title property access with fallback to legacy "Title" property - Pages without Sub-item relations now properly processed - Heading titles correctly applied to subsequent Toggle sections
…vements - Move spinner cleanup to finally blocks for proper resource management - Replace top-level await with async IIFE for better compatibility - Add test-environment-aware retry logic (10-50ms in tests vs 1000-4000ms in production) - Implement pagination safety limits (10,000 pages max) to prevent infinite loops - Enhance input validation for status extraction with type checking - Improve optional chaining usage for cleaner code - Add cursor validation to prevent infinite pagination loops Test performance improvement: 19.76s → 1.52s (92% faster) All 13 tests passing with proper error handling and robustness maintained.
- Add comprehensive URL validation to prevent empty/invalid image references - Implement intelligent fallback system that replaces failed images with informative placeholders - Add persistent image cache to prevent re-downloading and improve performance - Create detailed failure logging system for manual recovery (image-failures.json) - Enhance error handling with 5-phase processing: validate → download → cache → fallback → sanitize - Add comprehensive statistics and progress reporting - Ensure zero image loss - all images are either downloaded successfully or replaced with documented placeholders - Prevent empty URLs in markdown that cause MDX compilation errors Key improvements: - URL validation catches empty, null, undefined, and malformed URLs before processing - Caching system prevents re-downloading same images across runs - Fallback placeholders preserve context with original URL for recovery - Comprehensive logging enables manual recovery of failed images - 100% protection against empty image references in final markdown - Performance optimized with parallel processing and intelligent caching All tests passing with 1.38s duration maintained.
57af855 to
d0fb89e
Compare
- Fix image cache path normalization to prevent cache misses - Ensure translation directory creation to prevent runtime errors - Add test environment guard to graceful shutdown to prevent test runner exits - Improve image failure logging atomicity with temp file strategy All suggestions from PR #28 automated review have been applied. Tests passing with enhanced error handling and robustness.
- Extended gracefulShutdown to return exit code when NODE_ENV=test - Updated main() function to return exit code from gracefulShutdown - Fixed all 11 failing test assertions to check returned exit codes - Production behavior unchanged (still calls process.exit) - All 15 integration tests now pass (previously 11 were failing) Resolves issue where gracefulShutdown skipped process.exit in test mode, leaving mocked process.exit unused and causing test expectation failures.
- Normalize cached image path format in downloadAndProcessImageWithCache - Add safe error normalization in catch blocks for unknown error types - Fix status comparison to use explicit string literal - Add explicit pagination size to Notion API queries These changes improve error handling robustness and ensure consistent behavior across cached vs fresh image processing paths.
- Prevent URL mock overrides by implementing routing system in test mocks - Fix brittle image regex matching by collecting matches before processing - Avoid crashes when metrics are absent in index.ts - Guard metrics when generation is skipped in fetchAll.ts - Align image cache path resolution using consistent IMAGES_PATH constant - Fix variable reference issue in image processing phase These changes improve testing reliability, error handling robustness, and image processing consistency based on pr-agent feedback.
- Add safety cap for image processing to prevent runaway loops (500 image limit) - Await image failure logging promises to prevent unhandled rejections - Add numeric guards for metrics logging to handle non-finite values - Safely normalize content-type headers for robust format detection - Add defensive checks for pipeline output validation with array guards - Validate data array integrity across fetch pipeline transformations These improvements enhance error handling, prevent resource exhaustion, and ensure robust operation under various edge conditions.
- Add pagination loop guard to prevent infinite loops on empty pages - Fix image sanitization regex to avoid false positives on valid URLs - Make logging atomic and resilient with proper temp file cleanup - Add spinner state checks to prevent double-stopping issues - Add defensive post-pipeline filtering for Remove status pages - Ensure unhandled promise rejections are properly caught These changes improve the reliability and robustness of the Notion data fetching and processing pipeline based on PR review feedback.
Implements several key improvements based on PR review: - Use index-based safe replacements to avoid string replacement issues - Harden pagination against duplicates and infinite loops - Make logging mutex failure-safe with error recovery - Safeguard spinner state checks for test environment compatibility - Prevent regex backtracking and ReDoS attacks - Sanitize error logging to avoid sensitive context leakage These changes improve system reliability, security, and test compatibility while maintaining existing functionality.
- Validate unified database ID source to properly check resolvedDatabaseId instead of just process.env.DATABASE_ID - Add output path validation for security to prevent writing outside project directory - Make pagination more graceful by using warnings instead of throwing errors on anomalies - Add error handling around transform step to prevent pipeline crashes - Remove ineffective path normalization on image file basenames - Update test expectations to match new error messages
- Fix output path safety check using path.relative for cross-platform compatibility - Sanitize translation keys and values to prevent corrupted code.json files - Harden image failure logging with serialization guards and directory creation - Honor statusFilter in final defensive guard to ensure consistent filtering - Prevent double-ending spinners by removing redundant stop() calls - Fix conflicting lefthook file filters by using stage_fixed instead of files
- Use recorded match indices for image replacements to prevent incorrect matches - Sanitize cached image filenames to prevent directory traversal - Harden output path containment check with better validation - Add retry mechanism for pagination anomalies - Improve spinner lifecycle guarding to prevent TTY issues Addresses high and medium impact suggestions from PR review
- Preserve retry results during pagination anomaly handling to prevent data loss - Update Lefthook config to use npx and scope tests to test files only - Add --run flag to vitest commands for consistent CI behavior - Quote specific test file paths to prevent shell expansion issues Addresses latest review suggestions for improved reliability
|
Failed to generate code suggestions for PR |
User description
Summary
Testing
Fixes #27
PR Type
Enhancement, Tests, Bug fix
Description
Align fetch-all export with page scoping
Reuse shared generateBlocks pipeline
Harden image handling with cache/fallbacks
Add comprehensive CLI and pipeline tests
Diagram Walkthrough
File Walkthrough
2 files
Robust image pipeline, locale scoping, safe frontmatterCLI uses shared runtime and pipeline with shutdown1 files
Delegate to shared generateBlocks implementation1 files
Add reusable Notion mock fixtures for tests19 files