Skip to content

fix(audit): score empty successful pages - #1330

Closed
WilliamK112 wants to merge 4 commits into
squirrelscan:mainfrom
WilliamK112:codex/empty-body-pages-1314
Closed

WilliamK112 wants to merge 4 commits into
squirrelscan:mainfrom
WilliamK112:codex/empty-body-pages-1314

Conversation

@WilliamK112

Copy link
Copy Markdown
Contributor

Summary

  • preserve captured zero-byte HTML responses instead of treating them as absent bodies
  • include empty successful HTML pages in both audit adapters and the scored page universe
  • add a real crawl/report regression test plus documentation and changelog coverage

Closes #1314

Verification

  • bun test ./apps/cli/tests/audit/empty-body-page-1314.test.ts ./apps/cli/tests/squirrel-home-guard.test.ts ./packages/audit-engine/tests/page-features-noindex-golden.test.ts — 17 passed
  • bun test ./packages/crawler/tests/pages-without-bodies-2343.test.ts ./packages/crawler/tests/evicted-bodies-2342.test.ts — 9 passed
  • bun run scripts/test-suites.ts --run audit-engine — 1,597 passed, 3 skipped
  • bun run typecheck in apps/cli, packages/audit-engine, and packages/crawler
  • bun run docs:check
  • bun run format:check and bun run lint in apps/cli
  • detect-secrets 1.5.0 hook against .secrets.baseline
  • Full CLI suite: 3,255 passed and 1 skipped; the store-scripts failure passed on isolated rerun, while the unrelated checkReachability timeout reproduced on isolated rerun.

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

Docs: updated docs/cli/audit.mdx. Skill: none.

@nc9 nc9 added bug Something isn't working cli labels Oct 30, 2026
@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Reviewed head: 749e8cd

Thanks @WilliamK112. The storage change is correct: sqlite.ts keeps an evicted body (null) separate from a captured empty one (""), with no schema change, and both adapters now test html === null the same way. The new golden test only adds a case, and sites without empty pages score exactly as before. Because this changes which pages get scored, a few things need tightening first.

Must fix

  1. No status gate. isAuditablePage (packages/audit-engine/src/page-features.ts, the html === null check) and getParsedPages (packages/audit-engine/src/adapter.ts ~484, apps/cli/src/audit/adapter.ts ~291) don't check the status. An empty text/html response with a 3xx, 4xx, 5xx or 204 status is now parsed and audited, and gets missing-title and missing-H1 findings. Previously it was dropped, or appended as a bare empty page for 4xx, which the new !pageDataMap.has guard now prevents. The CHANGELOG and docs say "successful", so please gate on 2xx where pages enter the audited set (and decide on 204: it is 2xx, but by definition it has no content). Add 404, 410 and 204 empty-body tests.
  2. A render failure may become a scored empty page. packages/audit-engine/src/cloud-fetcher.ts (~242) maps a render item with no HTML to body: item.html ?? "" and fills in text/html headers when none came back. Before this PR that was dropped; now it becomes an audited empty 200 with false findings. Please check whether a no-HTML render item can reach the crawler as a success, and if so, keep it null ("no body") at that point.

Should fix

  1. Rule coverage on "". The new test only includes core/meta-title and core/h1. Please run the full rule set against an empty-body fixture and show that nothing throws and nothing misleading is reported, for example thin content, canonical, hreflang and schema rules. parser: a page body without <html> (empty, text, JSON) makes document.head throw; every DOM rule reports a bogus 'Rule error' fail #1270 covered markup-free bodies, not empty ones.

  2. Leftover truthiness checks still drop an empty page, so a report rebuilt from a stored crawl would disagree with the live audit:

    • apps/cli/src/reports/reconstruct.ts:502 (withBody?.html ? … : null);
    • apps/cli/src/audit/adapter.ts ~331 (if (record.html)).

    packages/audit-engine/src/batch-sizing.ts:208,222 is probably harmless since it only affects sizing, but please confirm.

Low

  1. The new docs paragraph in docs/cli/audit.mdx splits "The audit command manages crawl sessions intelligently:" from the table it introduces. It fits better with the page-count and coverage docs.
  2. Tests to add: evicted (null) vs captured "" at the storage level, and an empty response with no content type. Please also confirm the fixture's new Response(null, …) is stored as "", so the test passes for the right reason.

The CHANGELOG entry, DCO and lack of new dependencies are all fine.

Verdict: needs changes (1 and 2 required; 3 and 4 strongly suggested).

nc9 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: 749e8cd

Thanks @WilliamK112, this is a focused fix for #1314. Verdict: pending maintainer review (no blocking problems found, but CLI tests had not finished when I looked).

Findings, most severe first:

  1. Medium: other !page.html truthiness checks remain. The PR switches the adapter, isAuditablePage and the SQLite content-store fallback to html === null, but a few sibling checks still drop an empty string: apps/cli/src/audit/cloud.ts:620, packages/audit-engine/src/batch-sizing.ts:208 and :222, and packages/waf-detect/src/challenge.ts:84. Please confirm each is intentionally unchanged (an empty body has nothing to size or classify) or align them, so a zero-byte page behaves the same locally and in cloud runs.
  2. Low: docs paragraph is misplaced. In docs/cli/audit.mdx the new paragraph sits between "The audit command manages crawl sessions intelligently:" and the table it introduces, which breaks that sentence. Move it above that line or into its own subsection.
  3. Low: CHANGELOG. The entry is under the unreleased section with a ### Fixed heading and references audit: a 200 page with an empty body is dropped silently before the rules run #1314, which is right. Please check the heading level matches the other unreleased entries.
  4. Info: tests. The adapter-level test and the end-to-end runAudit test against a local zero-byte /empty page cover the behaviour well, and the engine golden test covers isAuditablePage.

Conventions: DCO sign-off present, no new runtime dependency, docs and CHANGELOG updated. CI: format, lint, typecheck, engine golden tests, docs build and CodeQL pass; "CLI tests" has no conclusion yet.

@WilliamK112

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. I pushed 1a63336 with the follow-ups:\n\n- Empty bodies are now auditable only for content-bearing 2xx statuses. Empty 404, 410, 204, 205, missing-content-type, and uncaptured responses stay outside page-rule evaluation.\n- The full rule set now runs against the zero-byte 200 fixture, with assertions for title, H1, word count, canonical, hreflang, and schema findings.\n- Render results without HTML are explicitly narrowed out of the mapper and fall back to plain fetch; a bodyless rendered 200 regression test covers this.\n- reconstructReport, pageRecordToPage, page feature extraction, and stream batch sizing now preserve the null-versus-empty distinction.\n- Storage coverage proves an empty string round-trips separately from null.\n- The documentation is now under Crawl behavior.\n\nThe remaining truthy checks are intentional: technology sampling skips a zero-byte sample because there are no bytes to fingerprint, and WAF detection sees an empty body the same as no challenge markers.\n\nValidation: 98 focused tests passed; audit-engine suite passed 1601 tests; CLI format, lint, type checks, crawler/audit-engine type checks, docs checks, and secret scan passed. The full CLI suite reached 3256 passing tests; its unrelated stalled-body deadline test timed out, while the separate store-scripts retry passed all 10 tests.

@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Reviewed head: 1a63336

Thanks @WilliamK112, thorough follow-up. Both must-fix items and both should-fix items are in:

  • 2xx gate: isAuditableEmptyBodyStatus (200-299, excluding 204 and 205) and hasAuditableHtmlBody are used in both adapters, buildSiteContext, getParsedPages, pageRecordToPage, reconstructReport and isAuditablePage. Empty 3xx/4xx/5xx/204/205 and headerless responses stay out, the streaming and v1 paths agree, and the end-to-end fixture proves it.
  • Render without HTML: mapRenderItemToResponse now only takes items with HTML, and a no-HTML item takes the existing fallback-to-fetch branch, claimed once, so there's no double fetch. A genuinely empty render ("") still maps to an empty 200.
  • Full rule set on "": ruleInclude: ["*"], with word count, canonical, hreflang and JSON-LD asserted.
  • Leftover truthiness: reconstruct.ts, pageRecordToPage and batch sizing are fixed. The remaining checks (tech detection and sampling) are harmless on an empty body.
  • Storage: "" and null now round-trip separately.

Two small things, neither blocking:

  1. Docs placement: the new ### Empty successful pages subsection was inserted before "The audit command manages crawl sessions intelligently:", so that sentence and its scenario table now sit under the new heading. Please move the subsection after the table, or restore a heading before the sentence.
  2. Test: the all-rules test checks result.ok but not that no rule reported an error on the empty page. An explicit assertion would lock that in.

Verdict: good to merge after the docs placement fix. A docs-only push needs no further review round.

@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@WilliamK112 one timing note: a change to the same empty-document handling (parseHTML no longer throwing on empty or rootless documents) is about to land on main in our next release batch. It touches the same lines as this PR, so a rebase now would mean resolving the same conflicts twice. Please hold off: I'll ping you here once it has merged. Then a single push with the rebase and the docs placement fix gets this merged.

@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@WilliamK112 the overlapping change is now on main (released in v0.0.142), so this is a good time to rebase. When you do, please include the docs fix in the same push:

  • Rebase: main now has parseHTML returning an empty shell for empty or rootless documents (commits 73780351 and 8541a8c3). They touch the same three places as this PR: packages/audit-engine/src/adapter.ts, apps/cli/src/audit/adapter.ts and isAuditablePage in page-features.ts. Main still drops empty-string bodies at those sites, so your 2xx gate replaces that behaviour. Expect conflicts there.
  • Docs: the "Empty successful pages" subsection currently sits between "The audit command manages crawl sessions intelligently:" and its scenario table. Moving it after the table fixes that.

Once the rebased head is up and CI is green, I'll review the change against the version I last reviewed, and it can go into the next release batch.

@WilliamK112
WilliamK112 force-pushed the codex/empty-body-pages-1314 branch from 1a63336 to 2002d4b Compare October 30, 2026 07:05
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Rebased onto upstream main at dbede75 and pushed the updated head 2002d4b. The overlapping adapter and page-feature changes keep the 2xx empty-body gate while using the new empty-shell parser behavior from v0.0.142. I also moved the Empty successful pages subsection below the crawl-session table as requested.\n\nLocal validation after the rebase: 98 focused tests passed, CLI and audit-engine type checks passed, docs checks passed, and the secret scan passed. CI is running on the rebased head.

@WilliamK112

Copy link
Copy Markdown
Contributor Author

Follow-up pushed in d90f67a: the rebase had placed the #1314 bullet inside the newly released v0.0.142 section, so the immutable changelog guard correctly failed. The bullet is now under Unreleased / Fixed. The released-section guard passes locally, and the new CI run is starting.

nc9 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: d90f67a

Thanks @WilliamK112, the rebase is clean and the earlier requests are all still in place. Verdict: pending maintainer review, with one blocker (CI) below.

Findings, most severe first:

  1. Blocker: Changelog guard is red on this head. The diff of CHANGELOG.md removes the blank line that ends the v0.0.142 section, just above ## v0.0.141 (hunk at @@ -35,7 +39,6 @@). That is an edit inside a released section, which the guard rejects. Please restore that blank line so the only change to the file is the new ### Fixed bullet under [Unreleased]. The bullet itself is in the right place.
  2. Resolved from the last review: the docs subsection now sits after the crawl-session table (docs/cli/audit.mdx), and the 2xx gate (isAuditableEmptyBodyStatus, hasAuditableHtmlBody) is shared by both adapters, isAuditablePage and getParsedPages. The "" and null storage round-trip is covered in evicted-bodies-2342.test.ts.
  3. Still open, small: the all-rules test in empty-body-page-1314.test.ts does not assert that no rule errored on the empty page. One explicit assertion would lock that in.
  4. Checks: CLI tests, audit engine golden tests, typecheck, lint, docs, secret scan and DCO sign-offs pass. No new runtime dependency, and no input-driven regexes or loops were added.

Once the changelog blank line is restored and CI is green this is ready for a maintainer merge decision.

nik

@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Reviewed head: d90f67a

Thanks for the rebase and the docs move, William. Checked against the version we approved: the three empty-body sites resolve correctly against #1290, the 2xx gate is kept (404, 410, 204 and responses with no content type behave as before), the docs subsection now sits after the scenario table, and the tests pass locally.

One thing left, and it is ours to fix: the PR removes the blank line between the last v0.0.142 bullet and the ## v0.0.141 heading in CHANGELOG.md, so the Changelog guard sees a changed released section. We will carry the blank line when this lands in the next release batch, with your authorship preserved. No action needed from you.

nik

@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Landed in v0.0.144 as af4d291c 54be2fcf 522a6606 via #1356. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.144. Thank you William, this fixed a real gap: a successful page with an empty body is now audited and scored instead of dropped, and you are credited in the release notes. Closing this original.

nik

@nc9 nc9 closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cli

Projects

None yet

Development

Successfully merging this pull request may close these issues.

audit: a 200 page with an empty body is dropped silently before the rules run

2 participants