Skip to content

fix(a11y): keep per_page fixed to prevent pagination offset regression - #296

Merged
gfargo-horizon-agent[bot] merged 2 commits into
mainfrom
agent/localpress-1357-localpress-264-b-06-a11y-pagination-offs
Aug 2, 2026
Merged

fix(a11y): keep per_page fixed to prevent pagination offset regression#296
gfargo-horizon-agent[bot] merged 2 commits into
mainfrom
agent/localpress-1357-localpress-264-b-06-a11y-pagination-offs

Conversation

@gfargo-horizon-agent

@gfargo-horizon-agent gfargo-horizon-agent Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

What

Fix runA11yScan pagination so every post within --limit is analyzed exactly once, regardless of whether the limit is a multiple of the page size (20).

The root cause was perPage = Math.min(20, limit - postsChecked) on line 120 of a11y.ts. When postsChecked approached limit on a final partial page, per_page shrank (e.g. to 10) while page kept incrementing. Since the WordPress REST API computes its offset as (page - 1) * per_page, a smaller per_page moved the window backwards, causing records from an earlier page to be re-fetched. With limit=50 over 100 posts, posts 21–30 were analyzed twice and posts 41–50 were never reached.

Why

Closes #264
Plane: OSS-1357

How

  • Replace Math.min(20, limit - postsChecked) with a fixed const PER_PAGE = 20 so per_page never changes between requests, keeping the server-side offset stable.
  • Add a if (postsChecked >= limit) break guard inside the post-analysis loop to truncate the final page client-side rather than sending a smaller per_page to the server.
  • Add a regression test: mock API honors per_page/page strictly (returns slice((page-1)*perPage, page*perPage) with accurate X-WP-TotalPages). Asserts that with limit: 50 over 100 posts, postsChecked === 50 and the exact set of analyzed IDs is {1…50} — no duplicates, no posts from 51–100.

Testing

  • build passes (bun run typecheck — clean)
  • tests pass (bun test test/unit/a11y.test.ts — 8/8 pass, including new regression test)
  • lint clean (biome check . — no issues)
  • CI: pending

🤖 Generated by the harbor agent loop. Reviewed by a human before merge.

Closes #264

When per_page shrank on the final iteration (Math.min(20, limit - postsChecked)),
the server-side offset (page-1)*per_page moved backwards into already-scanned
records. With limit=50 over 100 posts this caused posts 21-30 to be analyzed
twice and posts 41-50 to never be analyzed.

Fix: use a fixed PER_PAGE=20 constant for all requests. Client-side, break the
inner post loop early once postsChecked reaches the limit, so the final page is
correctly truncated without ever changing the per_page sent to the server.

Regression test: mock API that honours per_page/page strictly, verifies that
with limit=50 exactly 50 distinct post IDs (1-50) are analyzed and no ID
from 51-100 appears in findings.

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🔎 Agent review (kiro · sonnet) — LGTM

REVIEW: LGTM
RESOLVES: full

The fix correctly pins per_page to a constant 20 and caps analysis client-side before postsChecked is incremented, eliminating both the backwards-window and the over-count bugs. The regression test's second sub-run (result2) provides solid coverage of the exact-IDs-1–50 invariant.

2 nits — 2 inline on the diff

Comment thread test/unit/a11y.test.ts Outdated
Comment thread test/unit/a11y.test.ts Outdated

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🔎 Agent re-review (sonnet, delta) — LGTM

REVIEW: LGTM
RESOLVES: full

The fix correctly pins per_page at 20 and truncates the final page client-side via the new inner-loop break, resolving the offset-shift bug described in OSS-1357. The added regression test validates exact-once coverage for a non-multiple-of-20 limit and all tests pass.

@gfargo-horizon-agent
gfargo-horizon-agent Bot merged commit 521cb8d into main Aug 2, 2026
6 checks passed
@gfargo-horizon-agent
gfargo-horizon-agent Bot deleted the agent/localpress-1357-localpress-264-b-06-a11y-pagination-offs branch August 2, 2026 15:51
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.

B-06: a11y pagination offset breaks for any --limit not a multiple of 20

0 participants