Skip to content

fix(reports): show the Site Audit score in points, compared with the same page's audit before - #2133

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/report-audit-score
Nov 5, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/report-audit-score

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

The Site Audit Score section of a report (Reports › a report, and its PDF) showed the wrong number. site_audits.total_score is stored on a 0–1 scale, and Site Audit shows it as 0–100 points (audit-report.tsx multiplies by 100). The report's snapshot (getAuditSnapshot in web/src/lib/actions/reports.ts) only rounded it to one decimal. So a page that scores 64 in Site Audit read 0.6 in the report.

The same section had two more problems:

  • The change compared different pages. The previous score was the brand's audit just before, whatever page that was. A report could set the home page's 64 against a product page's 81.
  • The change had a % sign. It used the report's percentage Delta, so a 10-point change read "+0.1%".

The AI executive summary got the same snapshot. It saw "totalScore": 0.6, with no note on what the field means.

Found while building #2131 (open point 6 there).

What changes

  • The snapshot now stores three things:
    • the score in points, rounded as Site Audit rounds it;
    • the score of the same page's audit before;
    • scale: 100, to mark the new shape.
  • "The same page" means what it means on the Pages list: the final URL after a redirect, the host without www, and the path without a trailing slash. auditPageKey follows the same rule as pageKey in server/src/lib/audit/history.js.
  • Finding the audit before: the snapshot reads the brand's latest 100 complete, non-partial audits up to the report's end date, newest first. Before, it read 2.
    • If the page's audit before isn't among them, or this is the page's first audit, the report shows no change.
    • An audit without a score is never used as the one before, as in findPreviousCompletedAudit.
  • The report and the PDF show the score ("64") and the change in points ("+4", "-5"), with no % sign. Delta/DeltaText take unit="" for this; every other change keeps its %.
  • Reports saved before this fix: a saved report never changes, so old payloads keep their 0.6. They now read "~60", because the old value had only one decimal, so the true score was somewhere from 55 to 65. They show no change, because their previous score may be another page's.
  • The AI summary's prompt (server/src/routes/reports.js) says that auditScore is one page's score in 0–100 points, written without a % sign. It also says that previousScore is that page's audit before, not the previous period.

Code

  • New web/src/lib/reports/audit-score.ts, with pure functions tested on their own:
    • auditPageKey;
    • auditSnapshotFrom(rows), which builds the snapshot;
    • auditScoreView(auditScore), which gives what the page and the PDF show, for new and old payloads.
  • ReportAuditScore gains scale?: 100. Its comments say which scale each payload uses.

Help: help/reports/visibility-reports.md › Read a report gets one sentence. Site Audit Score is the exception to "compared with the previous period". It shows the latest audit of one page, scored 0 to 100, with the change since that page's audit before. approved-articles.json is regenerated.

No migration. No new strings: the section's existing reports.auditScore and auditedOn are kept.

Related issue

None. Found while building #2131 (Site Audit score range).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Audit one page of a brand twice, with an audit of another page in between.
  2. Generate a report with Audit Score checked, and check the section:
    • The score matches the latest audit's score in Site Audit, for example "64", not "0.6".
    • The change is the difference from that page's audit before, in points, for example "+4". It has no % sign.
    • The other page's audit in between is ignored.
  3. Download the PDF. The section shows the same score and change.
  4. Open a report generated before this change that has an Audit Score. It reads "~60", with no change.
  5. Run cd web && npx vitest run src/lib/reports "src/app/[locale]/(dashboard)/dashboard/reports/[id]" src/lib/help.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change) — see help/README.md

Full checks on this branch (d57f2be), built on main 8be573d. The branch still merges into main cleanly.

  • Web: format:check and typecheck pass. lint has 0 errors; its 7 warnings are old ones in files this PR doesn't touch. yarn test passes 975 files (10,411 tests, 1 skipped). yarn build passes with CI's placeholder env.
  • Server: format:check and lint pass. npm test passes 415 files (5,707 tests, 4 skipped).

Generated by Claude Code

…same page's audit before

A report's Site Audit Score section printed site_audits.total_score on its
0-1 scale rounded to one decimal, so a page Site Audit scores 64 read 0.6.
Its change compared the brand's audit before, whichever page that was, and
carried a % sign.

The snapshot now stores the score in 0-100 points as Site Audit rounds it,
the score of the same page's audit before (the Pages list's page key), and
scale: 100. The page and PDF show the change in points. Reports saved
before keep their payload and now read "~60", with no change. The summary
prompt says what auditScore is. Help: one sentence in Read a report.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@gkhngyk
gkhngyk merged commit 3d53dff into ansvisor:main Nov 5, 2026
13 checks passed
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.

3 participants