Skip to content

fix(desktop): validate locale:set input against supported locales#97

Merged
hqhq1025 merged 1 commit intomainfrom
wt/loop-fix-locale-ipc-validate
Apr 19, 2026
Merged

fix(desktop): validate locale:set input against supported locales#97
hqhq1025 merged 1 commit intomainfrom
wt/loop-fix-locale-ipc-validate

Conversation

@hqhq1025
Copy link
Copy Markdown
Collaborator

Summary

  • locale:set IPC accepted any non-empty string and persisted it to ~/.config/open-codesign/locale.json. normalizeLocale then silently rewrote bad values to en at read time, masking the underlying bug and stranding users on the wrong language until they cleared the file.
  • Reject unsupported tags up-front, canonicalize known aliases (zh-Hans-CNzh-CN) before persisting, and add tests for rejection, canonicalization, and bad input shapes.

Constraint check (PRINCIPLES §5b)

  • Compatibility: green — accepted tags unchanged; only previously-broken inputs now error.
  • Upgradeability: green — file format {schemaVersion: 1, locale} unchanged; we just stop writing garbage into locale.
  • No bloat: green — uses existing @open-codesign/i18n exports; no new deps.
  • Elegance: green — small, contained validation at the IPC boundary.

Test plan

  • pnpm --filter @open-codesign/desktop test -- src/main/locale-ipc.test.ts (4/4 pass)
  • pnpm --filter @open-codesign/desktop typecheck
  • pnpm exec biome check apps/desktop/src/main/locale-ipc.ts apps/desktop/src/main/locale-ipc.test.ts

`locale:set` previously accepted any non-empty string and persisted it to
~/.config/open-codesign/locale.json. A bad write (whether from a renderer
bug or third-party caller) was silently rewritten to "en" at read time by
normalizeLocale, masking the underlying problem and leaving users on the
wrong language until they manually cleared the file.

Reject unsupported tags up-front, canonicalize aliases (zh-Hans-CN → zh-CN)
before persisting, and cover the new behavior with tests for rejection,
canonicalization, and bad input shapes.
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Findings

  • No issues found in added/modified lines with high confidence.

Summary

  • Review mode: initial
  • No blocker/major/minor/nit findings in the latest diff.
  • docs/VISION.md and docs/PRINCIPLES.md: Not found in repo/docs in this checkout, so that context could not be revalidated here.
  • Residual risk: no test in this diff verifies renderer/UI error surfacing when locale:set rejects invalid locales.

Testing

  • Not run (automation)

open-codesign Bot

@hqhq1025 hqhq1025 merged commit af193e1 into main Apr 19, 2026
5 of 6 checks passed
@hqhq1025 hqhq1025 deleted the wt/loop-fix-locale-ipc-validate branch April 19, 2026 08:00
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.

1 participant