Skip to content

fix(audit-engine): record not-evaluated page checks so carried pages score as in a full audit #2099 - #2170

Merged
nc9 merged 3 commits into
mainfrom
fix/carried-not-evaluated-2099
Nov 21, 2026
Merged

nc9 merged 3 commits into
mainfrom
fix/carried-not-evaluated-2099

Conversation

@nc9

@nc9 nc9 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2099 (option C, AC2 as reworded).

What changes

  • SitePageRecord.notEvaluated?: string[] | null (core-contracts): per page, the ruleId|checkName checks the run that last crawled it could not evaluate there (e.g. perf/ttfb with no timing data). Absent, null or empty reads as today.
  • Write (merge-core): each crawled page records the checks this run did not evaluate on it (collector evidence plus the unsampled signal, matched by the page's hash). The record is disjoint from the page's rows by construction: a check with a fresh finding on the page is left out, and a check the merge carries a prior row for (merge: a not-evaluated page's prior still resolves when the resolution signal is over budget, and on complete-store and local merges #508) is dropped as it is carried. Rule-wide (ruleId|*) entries are not recorded.
  • Read: countCarriedNotEvaluated(priorPages, carriedPageUrls) gives per rule the recorded (carried page, check) pairs. Because the record never overlaps rows, both the materialized path (buildScoringResultsFromMerged) and the chunked complete-store fold (cleanCarriedPasses) subtract that same count from the carried passes (rule total clamped at 0), using stored page rows alone. No further contract change.
  • The sampled-store estimator is unchanged: it rewrites the union's tallies, which already carry the subtraction.

Acceptance criteria

  • AC1 cause: confirmed in the issue thread.
  • AC2 (reworded): ttfb tallies exact on both paths: tests/capped-rescore.test.ts "a 3-page re-run tallies perf/ttfb exactly as the full audit, as one POST and chunked" (single POST and both chunked drivers equal the full audit's tally, 45 passes) and the existing "a chunked publish stores every failing page..." now asserts ttfbTally(afterChunked) equals the full audit's. Overall score tolerance stays at 1 with a comment naming info-only rules (pub#2167).
  • Record disjoint from rows: "the page row records the skipped check, and only where the page holds no row for it" (one POST and chunked, plus a run 3 carrying them).
  • Back-compat: "a store written before the record (no notEvaluated) scores as it did: the skipped pages pass".
  • Fail-before on origin/main: the exact ttfb assertions fail (expected 45 passes, received 50) in 3 tests; the back-compat test passes on main, as it should.

Gates

  • packages/audit-engine and packages/core-contracts: bun run typecheck clean (packages have no format/lint scripts; root format:check and lint exit 0).
  • bun run scripts/test-suites.ts --check: OK.
  • tests/capped-rescore.test.ts: 35 pass, 0 fail.
  • bun run scripts/test-suites.ts --run audit-engine: 2368 pass, 3 skip, 0 fail (247 files).
  • bun run scripts/test-suites.ts --run rules: 12504 pass, 24 todo, 0 fail.
  • bun scripts/changelog.ts check: OK.

Notes

  • Storage: 34 bytes per row in JSON with one entry, 17 per extra entry; rows with nothing skipped are byte-identical.
  • Private side (later, migration number from planning): cloud site_pages needs a nullable column written by upsertSitePages and read by getSitePages; an upsert without the field writes NULL. Until then the cloud store drops the field and scores as today. CLI local sqlite is unchanged (follows the canonical precedent).
  • Agent skill: no change needed.
  • Hold-list (storage contract): Nik decides the merge.

Local sqlite store (a12e0c4)

The CLI's local smart re-audit (runSmartAudits) now persists and reads the record too, so it scores carried pages exactly like the cloud.

  • Migration: site_pages.not_evaluated TEXT, nullable JSON, migration 49 (SCHEMA_VERSION 48 to 49) via MIGRATIONS and runMigrations in packages/crawler/src/storage/sqlite.ts. Also listed in SITE_PAGES_ALTER_COLUMNS, so reconcileColumns re-adds it on a version-collided DB. Duplicate-column errors are swallowed, so it is idempotent.
  • Write: upsertSitePages writes the JSON array, or NULL when absent (a full re-crawl clears an old record).
  • Read: getSitePages selects named columns. NULL, malformed JSON or a non-string-array cell all read as nothing recorded, never a throw.
  • Scoring: runSmartAudits reads the prior pages before the merge and passes countCarriedNotEvaluated(priorPages, carriedPageUrls) to buildScoringResultsFromMerged.
  • Tests: apps/cli/tests/audit/smart-audits-not-evaluated-2099.test.ts (6) covers:
    • a 60-page fixture's perf/ttfb re-run tallies 45 = 45 (fails before: 50 with the store fix and no scorer wiring; all 6 fail without the change);
    • a re-crawl clears the record;
    • NULL and malformed cells read as nothing recorded;
    • a v48 DB opens, migrates idempotently and scores as before (2 + 57);
    • a version-collided DB self-heals;
    • the older CLI's named-column INSERT and SELECT * by-name read work on a migrated DB.
  • A drift-guard case for site_pages in pages-alter-columns-guard.test.ts.
  • Gates: format:check, lint and typecheck (root and per workspace) pass. test-suites.ts --check passes, as do both changelog checks. Suites: --run crawler 1177 pass, 0 fail; --run audit-engine 2369 pass, 0 fail; --run cli 4579 pass, 0 fail.
  • Merged origin/main (fix(rules): one finding per leaking endpoint, deduped after the site pass (#2082) #2164) with a sign-off. Agent skill: no change needed.

nc9 added 3 commits November 21, 2026 10:41
…carried pages score as in a full audit #2099

Signed-off-by: Nik Cubrilovic <[email protected]>
…ore so CLI smart re-audits score carried pages as a full audit #2099

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/carried-not-evaluated-2099 branch from d6696fc to d4f8508 Compare November 21, 2026 11:16
@nc9
nc9 merged commit 3af70a9 into main Nov 21, 2026
8 of 15 checks passed
@nc9
nc9 deleted the fix/carried-not-evaluated-2099 branch November 21, 2026 11:52
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.

engine: carried pages earn ttfb passes a full audit skips (capped re-audit scores 1 point high)

1 participant