mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 16:17:09 +01:00
THE DEFECT, FOUND BY MEASURING RATHER THAN READING. `SectionNav` carries a
full mobile treatment — `sticky top-0 z-20`, a translucent background, a
backdrop blur, a bottom border — for a state that could never occur. Scrolled
to 2500px on `/de/method` at 375px wide, the rail sat at `top: -1489`: it had
scrolled away like any static block.
A sticky element can only travel inside its containing block, and
`SectionNavLayout` wrapped the rail in a grid-item div exactly as tall as the
rail itself. Zero room to travel, so `position: sticky` did nothing and every
style written for the stuck state was decoration. `display: contents` below
`lg` takes the wrapper out of layout, the nav becomes the grid item, and it
inherits the grid's full height.
And it had pinned to `top: 0`, which is where the 69px site header already is
with a higher z-index — so had it ever stuck, it would have stuck underneath
the header.
WHILE FIXING IT, THE ROW GOT HONEST ABOUT SIZE. Seven sections wrapped to four
rows: 153px, a fifth of an 800px phone screen, held permanently to show a table
of contents nobody asked to keep looking at. It is now one row that scrolls
sideways — 57px — which is what documentation sites converged on for the same
reason. Measured after: pinned at exactly 69px, links clickable, and the
document still 375px wide in a 375px viewport.
ONE HEADER HEIGHT, REPLACING FOUR GUESSES. The header had no height; 69px
emerged from `min-h-11` plus `py-3` plus a border. Headings meanwhile carried
`scroll-mt-20`, `scroll-mt-24` AND `scroll-mt-28` — 2, 15 and 7 of them — three
answers to "how far below the top does an anchor land", each clearing 69px by
luck. `--header-height` in globals.css is now the single value: the header is
given it, the rail pins below it, and one `scroll-mt-anchor` utility (which
also accounts for the rail on phones) replaced all 24 occurrences.
TWO MORE DUPLICATIONS, EACH WITH A COPY THAT HAD DRIFTED:
- `lib/text/words.ts` replaces FIVE whole-word matchers. `saysWord`,
`says` and `demonstrates` were byte-identical under three names; `check.ts`
and `text.ts` each kept a private `escape`. `display.ts` says in its own
comment that it is copying the variety gate — the author knew they were
writing the second one, because there was nowhere to put it. `text.ts` opens
by arguing these operations belong "in one place" while holding a fifth copy.
Eight tests pin the cases the five copies each half-knew.
- `lib/i18n/dates.ts` replaces THREE date formatters whose comments all said
"the reader's own date format, never a hardcoded one" and which then
disagreed about the month and the fallback. The tag was resolved at three
different layers: not at all, at the caller, and at the use site — so
`SavedWords` declared `locale: string` and was handed a pre-resolved
`de-CH`. Now the formatter owns it and the prop is `Locale`. A test asserts
the chat workspace's date is byte-identical in all seven locales, because a
refactor that changes a glyph is not one. Also ends `essays/[slug]`
importing a helper out of another page module.
THE AUDIT LEARNED TWO THINGS, BOTH PROVEN BY MUTATION:
- Its two checks disagreed about scrollers. `clipped` exempts a deliberate
`overflow-x: auto` ("a real scroller is a deliberate choice"); the horizontal
`over` check did not, and reported four findings against a correct page whose
document did not overflow. They now agree. Mutation-tested: widened the rail
to 900px and `OVER` still fires, on the nav itself.
- It now fails if the header's CONTENT outgrows the token height. The first
version compared the header to the token and could never fail — the header
IS the token — which is worse than no check. Mutation-tested at `2rem`:
"the header contains 68px of content in a 32px bar".
Note that lint and type-check both passed while globals.css was unparseable
(`@utility` cannot nest inside `@media`); neither compiles CSS. The dev server
was what said so.
Verified: verify exit 0 — 852 tests, 72 suites; audit:language 20 pages / 0
English; audit:responsive 116 renders across de/fr/ru, 320–375px, light and
dark — 0 overflow, 0 header drift; `/de/method` screenshotted at 390px
scrolled to 2200, rail pinned under the header.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
59 lines
2.7 KiB
TypeScript
59 lines
2.7 KiB
TypeScript
import { test, describe } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { escapeLiteral, saysWord, wordPattern, replaceWord } from "./words.ts";
|
|
|
|
/**
|
|
* Each case here is a bug one of the five former copies was written to avoid.
|
|
* Keeping them together is the point: the reason the copies drifted is that
|
|
* each one knew about some of these and none knew about all of them.
|
|
*/
|
|
describe("whole-word matching", () => {
|
|
test("a word is not found inside a longer word", () => {
|
|
// The `si` / `isch` case, named in three of the five original comments.
|
|
assert.equal(saysWord("Das isch guet", "si"), false);
|
|
assert.equal(saysWord("Si händ gseit", "si"), true);
|
|
});
|
|
|
|
test("an umlaut is a letter, so the boundary is not `\\w`", () => {
|
|
// With `\w` the boundary falls after "gr", and "grüezi" matches "gr".
|
|
assert.equal(saysWord("grüezi mitenand", "gr"), false);
|
|
assert.equal(saysWord("grüezi mitenand", "grüezi"), true);
|
|
});
|
|
|
|
test("case is folded, because a sentence-initial word is the same word", () => {
|
|
// The shipped bug: located case-insensitively, blanked case-sensitively,
|
|
// so the exercise printed its own answer.
|
|
assert.equal(saysWord("Mir händ es gseh", "mir"), true);
|
|
assert.equal(replaceWord("Mir händ es gseh", "mir", "____"), "____ händ es gseh");
|
|
});
|
|
|
|
test("a literal form with regex punctuation matches itself and nothing else", () => {
|
|
assert.equal(escapeLiteral("z'spöt"), "z'spöt");
|
|
assert.equal(saysWord("es isch z.spöt", "z.spöt"), true);
|
|
// Unescaped, `.` would match the apostrophe and report a false positive.
|
|
assert.equal(saysWord("es isch z'spöt", "z.spöt"), false);
|
|
});
|
|
|
|
test("a form containing a bracket does not throw", () => {
|
|
// Pack and vocabulary data is typed by contributors, not generated.
|
|
assert.doesNotThrow(() => saysWord("was auch immer", "(chunnt"));
|
|
assert.equal(saysWord("was auch immer", "(chunnt"), false);
|
|
});
|
|
|
|
test("`i` and `u` cannot be switched off by a caller", () => {
|
|
const p = wordPattern("mir", "g");
|
|
assert.ok(p.flags.includes("i"), "case-insensitivity is not the caller's to drop");
|
|
assert.ok(p.flags.includes("u"), "unicode is not the caller's to drop");
|
|
assert.ok(p.flags.includes("g"), "the caller's own flag survives");
|
|
});
|
|
|
|
test("a duplicated flag does not produce an invalid pattern", () => {
|
|
assert.doesNotThrow(() => wordPattern("mir", "gi"));
|
|
assert.equal(wordPattern("mir", "giu").flags.split("").length, new Set(wordPattern("mir", "giu").flags).size);
|
|
});
|
|
|
|
test("replacement hits every occurrence, not just the first", () => {
|
|
assert.equal(replaceWord("mir und mir", "mir", "x"), "x und x");
|
|
});
|
|
});
|