Skip to content

fix: unify is_html heuristic, fix content sniffing, add tests#24

Merged
GeiserX merged 3 commits into
mainfrom
fix/unify-is-html-heuristic
May 4, 2026
Merged

fix: unify is_html heuristic, fix content sniffing, add tests#24
GeiserX merged 3 commits into
mainfrom
fix/unify-is-html-heuristic

Conversation

@GeiserX
Copy link
Copy Markdown
Owner

@GeiserX GeiserX commented May 4, 2026

Summary

Addresses all review comments from PR #6 (bare-host URL detection):

  • Unified _is_html_url() method: Extracted shared static method replacing two independent inline heuristics in download_file() and download() that could drift independently
  • Fixed content sniffing: Added .lstrip() before signature checks so BOM, leading whitespace, or Wayback-injected scripts before <html> don't cause false negatives. Also added <!doctype lowercase detection (consistent with download_file() line 543)
  • Regression tests: 4 new tests covering bare-host/root URLs, HTML extensions, extensionless paths, and asset extension classification

Test plan

  • All 19 tests pass locally
  • CI passes on 3.9/3.10/3.11

Summary by CodeRabbit

Release Notes

  • Version Update

    • Version 1.4.1 released
  • Improvements

    • Enhanced URL detection to more accurately identify HTML web pages and distinguish them from static assets (stylesheets, scripts, images, fonts)
  • Tests

    • Added comprehensive unit test coverage for URL classification validation

GeiserX added 2 commits May 4, 2026 10:06
Address all review comments from PR #6:

- Extract shared _is_html_url() static method used by both
  download_file() and download(), preventing heuristic drift
- Fix content sniffing to .lstrip() before checking signatures,
  handling BOM/whitespace/Wayback-injected scripts before <html>
- Add <!doctype lowercase to content signature detection
- Add regression tests for bare-host, root, extension, and
  extensionless URL classification
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

Warning

Rate limit exceeded

@GeiserX has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fbcf82c3-1cd9-4e6f-b043-b5b67e70f147

📥 Commits

Reviewing files that changed from the base of the PR and between 038aae6 and 7cec6e0.

📒 Files selected for processing (2)
  • tests/test_downloader.py
  • wayback_archive/downloader.py
📝 Walkthrough

Walkthrough

This PR refactors HTML-URL detection in the downloader by introducing a centralized _is_html_url() helper method, replacing inline heuristics in two locations. The package version is bumped to 1.4.1, supporting documentation is renamed, and new unit tests validate the helper's classification logic.

Changes

HTML Detection Refactoring

Layer / File(s) Summary
Core Helper
wayback_archive/downloader.py
New _is_html_url(url, parsed=None) static method classifies URLs as HTML based on root/empty paths, .html/.htm suffixes, or absence of non-HTML asset extensions.
Integration & Refactoring
wayback_archive/downloader.py
download_file() and download() methods replaced inline is_html_page conditions with calls to _is_html_url(); content signature detection simplified via content_stripped = content.lstrip().
Tests
tests/test_downloader.py
Four new test methods exercise _is_html_url() for bare hosts/roots, .html/.htm extensions, extensionless paths, and asset/document format exclusions.
Version & Documentation
wayback_archive/__init__.py, CLAUDE.md, .coderabbit.yaml
Version incremented to 1.4.1; document title changed to CLAUDE.md; config pattern updated to CLAUDE.md (resulting in duplicate entry).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: unifying the is_html heuristic, fixing content sniffing, and adding tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/unify-is-html-heuristic

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 54 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@GeiserX
Copy link
Copy Markdown
Owner Author

GeiserX commented May 4, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.69%. Comparing base (e07676c) to head (7cec6e0).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #24      +/-   ##
==========================================
+ Coverage   90.59%   90.69%   +0.09%     
==========================================
  Files           5        5              
  Lines        1425     1440      +15     
==========================================
+ Hits         1291     1306      +15     
  Misses        134      134              
Flag Coverage Δ
unittests 90.69% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
wayback_archive/__init__.py 100.00% <100.00%> (ø)
wayback_archive/downloader.py 90.39% <100.00%> (+0.10%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@GeiserX
Copy link
Copy Markdown
Owner Author

GeiserX commented May 4, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@GeiserX
Copy link
Copy Markdown
Owner Author

GeiserX commented May 4, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
wayback_archive/downloader.py (1)

156-162: 💤 Low value

Dead code: non_html set is never used.

The logic at line 157-158 returns False for any URL with an extension. Lines 159-162 are unreachable:

  • If ext is truthy → returns False at line 158
  • If ext is falsy → path cannot end with .css, .js, etc., so the non_html check always returns True
♻️ Suggested simplification
     ext = os.path.splitext(path_lower)[1]
-    if ext:
-        return False
-    non_html = {'.css', '.js', '.jpg', '.jpeg', '.png', '.gif', '.svg',
-                '.woff', '.woff2', '.ttf', '.eot', '.otf', '.ico',
-                '.json', '.xml', '.txt', '.pdf'}
-    return not any(path_lower.endswith(e) for e in non_html)
+    # Any extension means not HTML; no extension means likely HTML
+    return not ext
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@wayback_archive/downloader.py` around lines 156 - 162, The current logic
declares non_html but never uses it because the early "if ext: return False"
makes the later check unreachable; change the logic to use ext against the
non_html set instead: compute ext = os.path.splitext(path_lower)[1], then if
ext: return ext not in non_html (where non_html = {'.css', '.js', ...}), else
return True (no extension => treat as HTML). Update references to path_lower,
ext and non_html accordingly and remove the unreachable code path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.coderabbit.yaml:
- Around line 43-45: Remove the duplicate entry in the filePatterns array so
"CLAUDE.md" only appears once; locate the filePatterns block in .coderabbit.yaml
and delete the redundant "CLAUDE.md" line (the duplicate entries under
filePatterns) so the array contains a single "CLAUDE.md" entry.

---

Nitpick comments:
In `@wayback_archive/downloader.py`:
- Around line 156-162: The current logic declares non_html but never uses it
because the early "if ext: return False" makes the later check unreachable;
change the logic to use ext against the non_html set instead: compute ext =
os.path.splitext(path_lower)[1], then if ext: return ext not in non_html (where
non_html = {'.css', '.js', ...}), else return True (no extension => treat as
HTML). Update references to path_lower, ext and non_html accordingly and remove
the unreachable code path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b0f67133-1cc9-4fc0-a660-cff3c98a6dc0

📥 Commits

Reviewing files that changed from the base of the PR and between e07676c and 038aae6.

📒 Files selected for processing (5)
  • .coderabbit.yaml
  • CLAUDE.md
  • tests/test_downloader.py
  • wayback_archive/__init__.py
  • wayback_archive/downloader.py

Comment thread .coderabbit.yaml
Comment on lines 43 to 45
filePatterns:
- "AGENTS.md"
- "CLAUDE.md"
- "CLAUDE.md"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Duplicate "CLAUDE.md" entry in filePatterns.

Lines 44 and 45 are identical. The rename of AGENTS.mdCLAUDE.md landed on top of an already-existing CLAUDE.md entry.

🛠️ Proposed fix
     filePatterns:
-      - "CLAUDE.md"
       - "CLAUDE.md"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.coderabbit.yaml around lines 43 - 45, Remove the duplicate entry in the
filePatterns array so "CLAUDE.md" only appears once; locate the filePatterns
block in .coderabbit.yaml and delete the redundant "CLAUDE.md" line (the
duplicate entries under filePatterns) so the array contains a single "CLAUDE.md"
entry.

@GeiserX GeiserX merged commit acd06f9 into main May 4, 2026
7 checks passed
@GeiserX GeiserX deleted the fix/unify-is-html-heuristic branch May 4, 2026 08:35
@GeiserX GeiserX mentioned this pull request May 4, 2026
3 tasks
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