Skip to content

feat(audit): list audited pages one row per URL with their history - #1133

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/audit-pages
Oct 17, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/audit-pages

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Site Audit lists audited pages one row per URL, with each page's history underneath, and its dates no longer follow the browser's locale. This is SA-002 of the Site Audit v2 spec.

Two problems this fixes:

  • Repeated rows (F6): Recent Audits listed every run, so a page audited several times appeared several times (e.g. /ai-search/citation-monitoring twice on the same day).
  • Mixed date formats (F9): dates followed the browser's locale, so a Turkish browser showed "16.10.2026" and "14 Eki" in the English UI.

Server: GET /api/audits/pages?brandId=…&limit&offset

  • One row per page: audits are grouped by page.
    • The page key is the host without www. and the path without a trailing slash, from the final URL after redirects.
    • Query string and fragment are ignored, so /pricing, www…/pricing/ and /pricing?utm_source=… are one page.
  • Order: the most recently audited page comes first.
  • Each page carries:
    • its latest completed score, and the one before it;
    • a status: Good from 70, Improving below 70 when at least a point above the previous audit, Needs work otherwise, Running while a re-audit runs, Failed when no audit of the page ever completed;
    • its trend (up to the last 10 completed scores);
    • its open issues: failed and warning signals in the latest completed audit;
    • its runs (up to 50, with the full count).
  • Reads:
    • The brand's audits are read past PostgREST's 1000-row page (readAllRpcRows), and a row repeated at a slice boundary counts once.
    • Issues are counted only for the rows sent, in chunks of 20 audits (under 1000 signal rows each).
  • Response extras: total (the number of pages) for paging, and the brand's primaryHost.
  • Untouched: the existing GET /api/audits list and the MCP site-audit tools.

Web: the hub's Pages table (audit/_pages-table.tsx)

  • Replaces Recent Audits: Pages · N, with columns Page, Score (with a small trend line), Issues, Status and Last audit.
  • Labels: pages on the brand's primary domain show their path; other sites show host and path. Long URLs truncate.
  • Navigation:
    • The row opens the page's latest report.
    • The arrow lists its earlier audits: date and time, score or status, a report link, and delete.
    • Deleting re-reads the list in place, so open histories stay open.
  • Dates: fixed English formats via new formatMonthDay and formatDateTime in lib/format.ts, used on the Score over time axis, the table and the history.
  • Removed: getAudits and its types; the hub was their only user.

Out of scope (later Site Audit tasks)

  • Bulk selection and Re-audit: SA-003.
  • Send to Action Center: SA-013.
  • Group by template: SA-007.
  • The Opportunities tab: SA-004.
  • Citations / AI visits columns: SA-011 / SA-004.

Known limits

  • Reads: each request reads all of the brand's audits to group them. That is fine at today's volumes; a SQL grouping function can replace it if a brand's history grows large.
  • Stuck runs: an audit left running by a crashed job keeps its page at Running until that run is deleted. The old list showed it the same way.

Related issue

None. Site Audit v2 spec, task SA-002.

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 the same page a few times, using different spellings (https://www.example.com/pricing/, …/pricing?utm_source=x). Also audit one page on another site, and one URL that fails.
  2. Open Site Audit.
    • Pages · N lists each page once, own-domain pages by path, the other site with its host.
    • The latest score shows with a trend line; Improving appears when it rose since the previous audit.
    • A page that never completed reads Failed with "—".
  3. Click a row: its latest report opens.
  4. Click the arrow:
    • Earlier audits list with date and time.
    • Delete one: the table updates and the history stays open.
  5. With the browser set to Turkish, the dates still read "Oct 14, 2026" and the chart axis "Oct 14".

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): no errors; the 7 warnings are in files this PR does not touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • server: npm run format, npm run lint and npm test (1450) pass.
    • history.test.js:
      • pageKey spellings, root, case and hosts;
      • pageStatus rules;
      • buildAuditPages: grouping, redirects, running and failed runs, the trend, and repeats at a read boundary.
    • routes/audits-pages.test.js:
      • rows, issues, total and primary host;
      • paging over pages;
      • reading past 1000 audits;
      • issue counts in chunks;
      • a missing brand.
  • web: yarn test (1256) and yarn build pass.
    • _pages-table.test.tsx: rows, row click vs arrow, history, the "older audits not shown" note, failed/running pages, Load more, pageLabel.
    • format.test.ts: English dates under a simulated Turkish browser locale.
  • Browser: this branch's server (port 8081) and web, with 11 sample audits on the demo brand.
    • The sample: four spellings of /pricing plus a failed run, a competitor page, a never-completed page and others.
    • Checked at 1440px and 1024px, in light and dark; the 1024px check led to the truncation fix.
    • Delete was tried from a history.
    • The sample audits were deleted afterwards.

🤖 Generated with Claude Code

Site Audit's Recent Audits listed every run, so a page audited several
times appeared as several rows (F6), with dates in the browser's locale
("16.10.2026", "14 Eki") in an English UI (F9). This is SA-002 of the
Site Audit v2 spec.

- GET /api/audits/pages groups the brand's audits by page (host without
  www. and path without a trailing slash; query and fragment ignored, final
  URL after redirects), most recently audited first. Each page has its
  latest completed score, the previous one, a status (Good from 70,
  Improving when a point or more up, Needs work, Running, Failed), its
  trend, open issues (failed + warning signals) and its runs. Audits are
  read past the 1000-row page, and issues are counted for the rows sent.
- The hub's Pages table replaces Recent Audits: Page, Score with a small
  trend line, Issues, Status and Last audit. The row opens the latest
  report; the arrow lists earlier audits with their reports and delete.
  Own-domain pages show their path, other sites host and path.
- Dates use fixed English formats (formatMonthDay, formatDateTime) on the
  chart axis, the table and the history.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk This is SA-002 from the Site Audit v2 spec: the hub lists audited pages one row per URL (status, trend, issues, history), and its dates no longer follow the browser's locale. It's independent of #1132 (SA-001); the two touch routes/audits.js and en.json in different places and merge cleanly in either order. Thanks for reviewing!

@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.

Rebuilt on main: the history, audits-pages route, Pages table and format tests, typecheck, lint and format pass, and CI is green.

/pages reads every audit of the brand past the 1000-row page and counts issues only for the page of rows sent, in chunks of 20 audits that stay under the row cap. Production has 105 audits in all, so the read is small today.

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.

2 participants