Fix cheating integration tests - #8
Conversation
Tests were "cheating" by reimplementing logic instead of testing actual code: - Created src/lib.rs to expose WebFetch as a library for testing - Made generate_filename public for test access - Fixed test_filename_generation_with_extension to call real WebFetch::generate_filename - Fixed test_http_404_error to match actual error format (removed "The server returned an error response.") - Updated snapshot for http_404_error test Out of scope (would require full MCP server infrastructure): - test_fetch_grugbrain, test_fetch_creates_directory, test_file_path_is_relative
Pull Request Review: Fix cheating integration testsSummaryThis PR successfully addresses the issue of tests reimplementing logic instead of testing actual code. The refactoring creates a proper library structure that enables genuine integration testing. Positive ChangesCode Organization ✓
Test Improvements ✓
Code Quality ✓
Areas for ConsiderationTest Coverage GapsThe PR correctly identifies tests that still need work (marked as "out of scope"):
Recommendation: Consider filing a follow-up issue to address these remaining tests once the MCP server infrastructure for testing is available. Minor Suggestions1. Cargo.toml Library ConfigurationConsider adding a [lib]
name = "webfetch2"
path = "src/lib.rs"This makes the library structure explicit (though Cargo will infer it correctly). 2. DocumentationThe /// Generates a deterministic filename from a URL using a hash of the full URL.
///
/// The filename format is `{hash}.{extension}` where:
/// - `hash` is a hexadecimal hash of the full URL string
/// - `extension` is extracted from the URL path, defaulting to "html"
///
/// # Example
/// ```
/// use url::Url;
/// let url = Url::parse("https://example.com/file.json").unwrap();
/// let filename = WebFetch::generate_filename(&url);
/// assert!(filename.ends_with(".json"));
/// ```
pub fn generate_filename(url: &url::Url) -> String {3. Test AssertionsIn test_filename_generation_with_extension:149, the assertion message is excellent and descriptive. This is good practice throughout. Security Review ✓
Performance Review ✓
Potential IssuesNone CriticalNo bugs or critical issues identified. The changes are clean and focused. Testing RecommendationsTo verify the changes work correctly: # Run tests to ensure everything passes
cargo test
# Check that the binary still works
cargo build --release
./target/release/webfetch2 --help
# Verify library can be imported (create a simple test crate)
cargo new --bin test_import
# Add webfetch2 = { path = "../webfetch2" } to Cargo.toml
# Try importing: use webfetch2::WebFetch;ConclusionRecommendation: Approve with minor suggestions This is a well-executed refactoring that addresses the core issue described in the PR. The separation of library and binary concerns is a Rust best practice, and the test fixes ensure they're testing actual implementation code. The remaining test improvements are correctly scoped out and don't diminish the value of this PR. The code quality is solid, follows Rust conventions, and maintains backward compatibility. Great work on improving test integrity! Review performed by Claude Code |
|
|
Claude finished @hibukki's task —— View job Tasks Completed ✓What I Did:
Changes committed and pushed to branch
|
- Fixed test_file_path_is_relative to use PathBuf consistently and verify directory exists before writing - Added explicit [lib] section to Cargo.toml - Enhanced TODO comments on out-of-scope tests to clarify they require MCP infrastructure - Updated line number references in TODO comments Co-authored-by: Yonatan Cale <hibukki@users.noreply.github.com>
Pull Request Review: Fix cheating integration testsSummaryThis PR addresses a significant testing anti-pattern where tests were reimplementing production logic instead of calling the actual code under test. The refactoring extracts the core logic into a library crate ( Positives
Code Quality and Best PracticesMinor: Cargo.toml:4 sets Visibility: src/lib.rs:116 makes Potential BugsCritical: Hash instability for filenames (src/lib.rs:117-122)
Recommendation: Use a stable hash algorithm like sha256, or sanitize the URL into a valid filename. Minor: Unsafe file extension parsing (src/lib.rs:125-135) Edge cases not handled:
Performance ConsiderationsURL cloning: In Security ConcernsPath traversal risk (Low severity): src/lib.rs:60-61 Currently safe because No size limit on downloads: src/lib.rs:94 The code reads entire responses into memory ( Test CoverageImproved but still limited Now properly tested:
Still cheating (acknowledged in TODOs):
Missing test coverage:
Recommendation: Consider adding unit tests for Summary and RecommendationsPriority Fixes:
Nice-to-haves: Verdict: This PR is a significant step forward in test quality. The architectural refactoring is sound. After fixing the edition and hash stability issues, this should be good to merge. The remaining test limitations are well-documented and can be addressed in future work. |
Tests were "cheating" by reimplementing logic instead of testing actual code:
Out of scope (would require full MCP server infrastructure):