-
Notifications
You must be signed in to change notification settings - Fork 0
fix(public): guard the live site against footer tap-target drift (closes footer backlog item) #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { readFileSync } from "node:fs" | ||
| import { fileURLToPath } from "node:url" | ||
| import { dirname, join } from "node:path" | ||
|
|
||
| const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..") | ||
| const read = (p) => readFileSync(join(ROOT, p), "utf8") | ||
|
|
||
| let failures = 0 | ||
| let checks = 0 | ||
| const ok = (cond, msg) => { | ||
| checks++ | ||
| if (cond) console.log(` ok ${msg}`) | ||
| else { | ||
| failures++ | ||
| console.error(` FAIL ${msg}`) | ||
| } | ||
| } | ||
|
|
||
| // The deployed stylesheet must keep the footer link rule at the WCAG 2.2 | ||
| // (SC 2.5.8) 24px minimum. The local suite (test-public-link-targets.mjs) | ||
| // asserts the same rule against public/styles.css; this guard re-asserts it | ||
| // against the stylesheet the live site actually serves, so a stale or | ||
| // drifted deployment fails loudly instead of silently re-opening the footer | ||
| // tap-target backlog item. | ||
| // | ||
| // The footer backlog item re-opened because the live site was serving the | ||
| // pre-fix stylesheet: PR #22 gave .footer-links a "inline-block; | ||
| // min-height: 24px; padding: 4px 0" in public/styles.css, but the deployed | ||
| // stylesheet still rendered footer links as ~17px plain-inline glyph boxes | ||
| // on every tinystudio.in page at mobile widths. | ||
| const LIVE_CSS_URL = process.env.LIVE_CSS_URL ?? "https://tinystudio.in/styles.css" | ||
| const FETCH_TIMEOUT_MS = 10_000 | ||
|
|
||
| // The one selector test-public-link-targets.mjs requires of the local sheet. | ||
| const FOOTER_SELECTOR = ".footer-links a" | ||
|
|
||
| const targetRuleOf = (css, selector) => { | ||
| const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") | ||
| const pattern = selector | ||
| .split(",") | ||
| .map((s) => esc(s.trim())) | ||
| .join("\\s*,\\s*") | ||
| const match = css.match(new RegExp(`${pattern}\\s*\\{([^}]*)\\}`)) | ||
| return match ? match[1] : null | ||
| } | ||
|
|
||
| console.log("test-public-live-footer-targets: the deployed tinystudio.in stylesheet keeps the footer link rule at the WCAG 2.2 24px minimum") | ||
|
|
||
| let css = null | ||
| try { | ||
| const res = await fetch(LIVE_CSS_URL, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) }) | ||
| if (!res.ok) { | ||
| console.log(` ok skipped: ${LIVE_CSS_URL} answered ${res.status}, deployment not reachable - no footer tap-target assertions run`) | ||
| } else { | ||
| css = await res.text() | ||
| } | ||
| } catch (err) { | ||
| console.log(` ok skipped: ${LIVE_CSS_URL} unreachable (${err?.cause?.code ?? err?.name ?? "network error"}) - no footer tap-target assertions run`) | ||
| } | ||
|
|
||
| if (css !== null) { | ||
| console.log(`A. the footer link rule in the served ${LIVE_CSS_URL} enforces the 24px minimum`) | ||
| const rule = targetRuleOf(css, FOOTER_SELECTOR) | ||
| ok(rule !== null, `live styles.css has a ${FOOTER_SELECTOR} rule`) | ||
| if (rule) { | ||
| ok(/display:\s*(inline-block|inline-flex|block)/.test(rule), `live ${FOOTER_SELECTOR} links are block-level boxes (hit area covers the line box)`) | ||
| ok(!/display:\s*inline\s*;/.test(rule), `live ${FOOTER_SELECTOR} links are not plain inline boxes`) | ||
| ok(/min-height:\s*24px/.test(rule), `live ${FOOTER_SELECTOR} links declare min-height: 24px`) | ||
| const paddingMatch = rule.match(/padding:\s*([^;]+)/) | ||
| ok(paddingMatch !== null, `live ${FOOTER_SELECTOR} links declare vertical padding`) | ||
| if (paddingMatch) { | ||
| const vertical = parseFloat(paddingMatch[1].trim().split(/\s+/)[0]) | ||
| ok(vertical >= 4, `live ${FOOTER_SELECTOR} vertical padding is at least 4px (${vertical}px), so 16px text + padding >= 24px`) | ||
| } | ||
| } | ||
| if (failures === 0) { | ||
| console.log(" the deployed stylesheet carries the footer tap-target rule from public/styles.css") | ||
| } else { | ||
| console.log(" the deployed stylesheet is stale: it misses the footer tap-target rule that public/styles.css already has (see FAIL lines above). Refresh the live deployment from origin/main.") | ||
| } | ||
| } | ||
|
|
||
| console.log("B. npm test/ci wiring") | ||
| const pkg = JSON.parse(read("package.json")) | ||
| ok( | ||
| pkg.scripts.test.includes("test-public-live-footer-targets.mjs"), | ||
| "npm test runs the public live footer-target guard" | ||
| ) | ||
| ok( | ||
| pkg.scripts.ci.includes("test-public-live-footer-targets.mjs"), | ||
| "npm run ci runs the public live footer-target guard" | ||
| ) | ||
|
|
||
| console.log(`\n${checks} checks, ${failures} failures`) | ||
| process.exit(failures === 0 ? 0 : 1) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the live deployment returns a non-2xx response—such as a 404 because
styles.csswas omitted or a 500 from the server—fetchsucceeds, this branch merely reports a skip, and the new guard exits successfully after its wiring checks. That lets CI pass while every public page may be loading no stylesheet at all; reserve skipping for transport-level unreachability and record an assertion failure for HTTP error responses.Useful? React with 👍 / 👎.