gen-keybinds: a C locale lost every section header — match the dash as a literal #55

Merged
dank merged 1 commits from fix/gen-keybinds-locale-safe-sections into main 2026-10-20 22:21:29 -07:00
Owner

Found while adding a rule to agent/APPEND_SYSTEM.md: the suite is red in any C-locale shell, and the cause is a silent data loss in the keybinds generator.

Measured

Old (origin/main) script against the live ~/.config/niri/cfg/keybinds.kdl:

shell sections rows exit
UTF-8 12 120 0
LC_ALL=C 0 120 0

A third of the page vanishes and the caller still gets a green status. Cron, systemd user units and agent shells all run LC_ALL=C, so every automated regeneration has been writing the section-less sheet; Frank's terminal is UTF-8, which is why it was never seen.

Cause

/^[[:space:]]*\/\/[[:space:]]*─+ (.+) ─+[[:space:]]*$/ puts a quantifier on a multibyte character. LANG=en_US.UTF-8 does not save it — LC_ALL overrides everything — and gawk then matches byte-wise, so ─+ means "the last byte of U+2500, repeated", a sequence that never occurs in the file.

Fix

Match and strip the dash as a literal (gsub(/─/, "", s)), byte-safe in every locale. A comment still has to be dash-decorated on both sides to open a section, so plain comments stay ignored. No locale is pinned: pinning en_US.UTF-8 would have been the other wrong answer — this box ships only C.utf8.

Verification

  • New black-box test drives the generator through env LC_ALL=C and asserts the headers are there — the box's own UTF-8 terminal could never have caught this.
  • LC_ALL=C bats tests/ = 110 ok, 0 failures; the file is also 8/8 under C.utf8.
  • omp-docs/tools/niri/keybindings.md is unaffected (12 headers, 120 rows — generated from a UTF-8 shell), and output is now identical in both locales, so no regeneration is needed.

cwd: /home/blank/.omp/wt/wt-20261019-125509-7c8a99d · session: 01a155bb-6474-7366-be9d-629f74af0e05 (built in the worktree ~/.omp/wt/wt-keybinds-locale)

Found while adding a rule to `agent/APPEND_SYSTEM.md`: the suite is red in any C-locale shell, and the cause is a silent data loss in the keybinds generator. ## Measured Old (`origin/main`) script against the live `~/.config/niri/cfg/keybinds.kdl`: | shell | sections | rows | exit | |---|---|---|---| | UTF-8 | 12 | 120 | 0 | | `LC_ALL=C` | **0** | 120 | 0 | A third of the page vanishes and the caller still gets a green status. Cron, systemd user units and agent shells all run `LC_ALL=C`, so every automated regeneration has been writing the section-less sheet; Frank's terminal is UTF-8, which is why it was never seen. ## Cause `/^[[:space:]]*\/\/[[:space:]]*─+ (.+) ─+[[:space:]]*$/` puts a quantifier on a multibyte character. `LANG=en_US.UTF-8` does not save it — `LC_ALL` overrides everything — and gawk then matches byte-wise, so `─+` means "the last byte of U+2500, repeated", a sequence that never occurs in the file. ## Fix Match and strip the dash as a literal (`gsub(/─/, "", s)`), byte-safe in every locale. A comment still has to be dash-decorated on both sides to open a section, so plain comments stay ignored. No locale is pinned: pinning `en_US.UTF-8` would have been the other wrong answer — this box ships only `C.utf8`. ## Verification - New black-box test drives the generator through `env LC_ALL=C` and asserts the headers are there — the box's own UTF-8 terminal could never have caught this. - `LC_ALL=C bats tests/` = **110 ok, 0 failures**; the file is also 8/8 under `C.utf8`. - `omp-docs/tools/niri/keybindings.md` is unaffected (12 headers, 120 rows — generated from a UTF-8 shell), and output is now identical in both locales, so no regeneration is needed. --- cwd: /home/blank/.omp/wt/wt-20261019-125509-7c8a99d · session: 01a155bb-6474-7366-be9d-629f74af0e05 (built in the worktree `~/.omp/wt/wt-keybinds-locale`)
dank added 1 commit 2026-10-20 21:27:46 -07:00
The section rule was `/^[[:space:]]*\/\/[[:space:]]*─+ (.+) ─+…$/`, a quantifier on a
multibyte character. Under LC_ALL=C — which is what cron, systemd user units and agent
shells get, regardless of LANG — gawk matches byte-wise, so `─+` means "the last byte of
U+2500, repeated" and never matches. Measured on the live keybinds.kdl: the old script
emitted 0 section headers instead of 12, all 120 binding rows intact, exit status 0. A
silent one-third-of-the-page loss, invisible to any caller that only checks the status.

The dash is now matched and stripped as a literal (`gsub(/─/, "")`), which is byte-safe
in every locale, and a comment must be dash-decorated on both sides to open a section, so
plain comments are still ignored. A test pins the C-locale case explicitly, because the
box's own terminal has always been UTF-8 and could never have caught this.

The committed artifact omp-docs/tools/niri/keybindings.md is unaffected (12 headers,
120 rows — it was generated from a UTF-8 shell); output is now identical either way.
dank merged commit 1cc4b76479 into main 2026-10-20 22:21:29 -07:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dank/command-center#55