From c2512cb9b9f25485ca6cc95652360dd378e882b7 Mon Sep 17 00:00:00 2001
From: Talal Alqahs <153442159+TFQ0@users.noreply.github.com>
Date: Thu, 8 Oct 2026 08:30:40 +0300
Subject: [PATCH] 3.1.0
---
README.md | 31 +++
docs/report-validation.md | 107 ++++++++
tests/test_app.py | 60 +++++
tests/test_cli.py | 9 +
tests/test_exporters.py | 67 ++++-
tests/test_rule_reports.py | 12 +-
tests/wheel_smoke.py | 3 +-
tfq0seo/cli.py | 7 +
tfq0seo/core/app.py | 56 +++-
tfq0seo/core/crawler.py | 4 +
tfq0seo/exporters/base.py | 68 ++++-
tfq0seo/templates/audit_summary.html | 67 +++++
tfq0seo/templates/enhanced_report.html | 18 +-
tfq0seo/templates/optimized_report.html | 325 ++----------------------
tfq0seo/templates/page_inventory.html | 172 +++++++++++++
tfq0seo/templates/report.html | 16 +-
16 files changed, 671 insertions(+), 351 deletions(-)
create mode 100644 docs/report-validation.md
create mode 100644 tfq0seo/templates/audit_summary.html
create mode 100644 tfq0seo/templates/page_inventory.html
diff --git a/README.md b/README.md
index 6025f4b..918e29e 100644
--- a/README.md
+++ b/README.md
@@ -385,6 +385,37 @@ and browse 20 findings per page. Details expose complete evidence on demand.
This view runs locally in the report and requires JavaScript, without Chart.js
or network access. JSON retains every finding as well.
+All three HTML templates include **Crawl coverage & timing** and a **Pages &
+response times** inventory. They distinguish the configured page limit from
+recorded URLs and complete/partial/failed/skipped outcomes. Search by URL,
+title, description, or error; filter outcomes; sort by fetch time, score, or
+finding count; and paginate every record. Expand **Page details** for metadata,
+word/link counts, headings, canonical/robots observations, category scores,
+findings, recommendations, and individual timing measurements. The optimized
+template's performance charts work offline without external scripts.
+
+`summary.analysis_duration` uses a monotonic clock and covers discovery, pacing,
+fetching, and analysis, excluding report assembly/export. `crawl_stats` records
+HTTP requests by kind (including retries), applied robots crawl delays, and
+analysis cache hits. Its page throughput counts analyzed HTML pages, excluding
+failed/skipped URLs. Imported reports without run context keep these measurements
+unavailable. Per-page `load_time` is network time; `timings.total_seconds` also
+includes fetch waiting/pacing, while headers and download timings describe the
+final response. Concurrent timings overlap and should not be added to estimate
+total elapsed time.
+
+A fast command exit is not evidence of a completed crawl. For example, this
+command must include the URL; omitting it produces a usage error (exit code 2)
+without creating a report:
+
+```bash
+tfq0seo crawl https://example.com --depth 5 --max-pages 500 --concurrent 5 --format json --output audit.json
+```
+
+`--max-pages 500` sets a ceiling; fewer discoverable pages can produce a smaller
+report. Inspect the actual counts, discovery gaps, and completion reason. See
+[the live-site verification](docs/report-validation.md) for a measured example.
+
JSON, HTML, CSV, and XLSX exports write a temporary file beside the destination,
close it successfully, and then atomically replace the destination. Rendering,
serialization, write, and replacement failures preserve an existing report and
diff --git a/docs/report-validation.md b/docs/report-validation.md
new file mode 100644
index 0000000..63657fd
--- /dev/null
+++ b/docs/report-validation.md
@@ -0,0 +1,107 @@
+# HTML reporting and crawl-speed verification
+
+Measured on 25 September 2026 using the local source checkout, Python 3.14.6,
+Windows, and the owner's authorized site `https://siwar.ksaa.gov.sa/`.
+These observations describe this run and environment, not a capacity guarantee.
+
+## Reproducing the reported fast exit
+
+The supplied command omitted the required URL:
+
+```sh
+tfq0seo crawl --depth 5 --max-pages 500 --concurrent 5 --format json --output audit.json
+```
+
+Invoking it through `python -m tfq0seo.cli` exited with code **2** after **1.56
+seconds**, with `Error: Missing argument 'URL'.` No crawl or report write occurs
+in that case. This explains the command as supplied; it does not establish what
+happened in a different invocation that included a URL.
+
+## Live-site observations
+
+Two real, unauthenticated crawls respected robots.txt and disabled analysis
+caching. The first used a 110-page ceiling, concurrency 3, and a 120-second
+crawl deadline. It completed 18 pages in 110.76 seconds; report assembly took
+0.44 seconds and JSON/HTML exports 0.84 seconds (112.04 seconds overall).
+
+The second used the supplied depth, page ceiling, and concurrency with the URL
+added:
+
+```sh
+python -m tfq0seo.cli crawl https://siwar.ksaa.gov.sa/ --depth 5 --max-pages 500 --concurrent 5 --config reports/siwar-validation/live-config.yaml --format json --output reports/siwar-validation/audit.json
+python -m tfq0seo.cli export --input reports/siwar-validation/audit.json --format html --output reports/siwar-validation/audit.html
+```
+
+The local verification configuration limited requests to 15 seconds (10 seconds
+for connecting), one retry, and a 180-second crawl deadline, with caching off.
+No robots or TLS safeguards were disabled.
+
+To reproduce it, save this as `reports/siwar-validation/live-config.yaml`:
+
+```yaml
+crawler:
+ max_crawl_time: 180
+ timeout: 15
+ connect_timeout: 10
+ read_timeout: 15
+ max_retries: 1
+ cache_enabled: false
+```
+
+| Observation | Second run |
+| --- | ---: |
+| Configured page ceiling | 500 |
+| Recorded URLs / analyzed HTML pages | 18 / 18 |
+| Complete / partial / failed / skipped pages | 18 / 0 / 0 / 0 |
+| HTTP requests | 23: 18 pages, 4 sitemap requests, 1 robots request |
+| Analysis cache hits | 0 |
+| Distinct recorded text hashes | 14 |
+| Crawl + analysis elapsed | 110.67 s |
+| Applied robots crawl delay | 5 s |
+| Mean / median HTML network time | 0.100 / 0.064 s |
+| Minimum / maximum HTML network time | 0.035 / 0.444 s |
+| HTML export from saved JSON | 0.41 s |
+
+The five-second delay came from the site's robots.txt. Fast HTTP responses do
+not imply a two-second audit: pacing, discovery, and analysis are separate work.
+The page ceiling is not an inventory of the website, and static crawling does
+not render JavaScript or enumerate every dictionary/search result.
+
+Both runs recorded discovery gaps: an excluded `/login` sitemap entry and
+document-type parse errors at the three guessed sitemap locations
+`/sitemap_index.xml`, `/sitemap-index.xml`, and `/sitemaps/sitemap.xml`. The report
+therefore remains **partial**, despite all 18 fetched HTML pages completing
+analysis. No claim of complete site coverage is made.
+
+The second crawl saved its JSON successfully. The surrounding measurement
+script then failed while decoding UTF-8 console output with Windows cp1252, so
+its total CLI wall time was not retained. The HTML was subsequently exported
+from that saved JSON without recrawling; elapsed crawl time above is the tool's
+monotonic measurement. Local artifacts are in `reports/siwar-validation/`
+(ignored by Git), including `audit.html`, `audit.json`, `measurements.json`,
+`before-measurements.json`, and the observed `robots.txt`.
+
+## Regression checks
+
+- A 110-page loopback crawl compares every reported request with the HTTP
+ server log, verifies URL retention, and includes a failed response and a
+ skipped non-HTML response. Neither inflates analyzed-page throughput.
+- Separate sitemap discovery and page-fetch sessions contribute to request
+ totals. Imported report records inherit neither stale timings nor budgets.
+- HTML checks preserve all 506 records in a large report across all three
+ templates, retain missing measurements, and escape untrusted page content.
+- Browser checks exercise 45-record pagination (20/20/5), search, outcome
+ filtering, numeric sorting, empty results, and expanded page details.
+ Injected HTML remains text and unsafe URL schemes are not clickable.
+
+```sh
+python -m pytest tests/test_app.py tests/test_exporters.py tests/test_cli.py
+```
+
+The complete suite passed **921 tests** in 239.04 seconds on Python 3.14.6.
+Wheel and source builds passed Twine validation; the installed wheel passed
+the isolated smoke test, including all report templates and shared partials.
+Packaged Python/HTML files matched the working tree byte-for-byte. Modified
+Python modules also passed Python 3.8 grammar parsing (not a Python 3.8 runtime
+test). Interactive browser checks used a loopback HTTP preview; a direct
+`file://` preview was blocked by the browser tool's URL policy.
diff --git a/tests/test_app.py b/tests/test_app.py
index d176a5e..146fc0e 100644
--- a/tests/test_app.py
+++ b/tests/test_app.py
@@ -126,6 +126,66 @@ def test_http_statuses_and_even_median_are_preserved():
assert metrics['load_time_stats']['median'] == 2
+def test_over_100_page_run_counts_real_requests_and_excludes_failures_from_speed(http_site):
+ import time
+ base, routes, requests = http_site
+ count = 110
+ routes['/robots.txt'] = (200, {'Content-Type': 'text/plain'}, 'User-agent: *\nAllow: /')
+ routes['/'] = (200, {'Content-Type': 'text/html'}, '
Start
Start
' +
+ ''.join(f'Page {i}' for i in range(1, count)) + '')
+ for i in range(1, count):
+ routes[f'/page/{i}'] = (200, {'Content-Type': 'text/html'}, f'Page {i}
--max-pages is an upper limit, not the number of pages found on the site.
+ Counts cover the URLs discovered or supplied for this run. JavaScript-generated routes and content are not rendered.
+
+
HTTP requests (including discovery / retries)
{{ audit.requests|number }}
+
Analyzed HTML pages / second
{{ audit.throughput|number(2) }}
+
Analysis cache hits
{{ audit.cache_hits|number }}
+
Distinct recorded text hashes
{{ audit.unique_content|number }}
+ {% for kind, count in audit.requests_by_kind.items() %}
{{ kind|title }} HTTP requests
{{ count }}
{% endfor %}
+ {% for origin, delay in audit.robots_delays.items() %}
Completion:
+ {% if audit.completion_reason == 'queue_exhausted' %}No more eligible URLs remained in the discovered queue. This does not prove that every page on the website was found.
+ {% elif audit.completion_reason == 'input_processed' %}The supplied URL list was processed.
+ {% elif audit.completion_reason == 'limits_reached' %}A configured limit stopped coverage.
+ {% elif audit.completion_reason == 'discovery_errors' %}The discovered queue finished with discovery gaps; review the details below.
+ {% else %}The crawl completion reason was not recorded in this report.{% endif %}
+
+ {% if audit.failed or audit.skipped or audit.partial or audit.limits or audit.discovery_errors %}
+
+ Coverage needs review. Failed, skipped, partial, and undiscovered pages are not successful full analyses.
+ {% if audit.limits %}
Elapsed time includes fetching, robots pacing, discovery, and analysis; it excludes report assembly and export.
+ Parallel requests overlap, so adding per-page timings does not give the run's elapsed time.
HTML fetch is recorded network time for the HTML request, including redirects/retries, excluding pacing and analysis.
+ Details separate final-response headers and body download from total fetch elapsed time (which includes waiting).
+ These are HTTP observations, not browser load time, TTFB, or Core Web Vitals. Missing timings remain “Not measured”.