Skip to content

feat(settings): country-scoped locale preference invariants - #436

Merged
khaira777 merged 3 commits into
mainfrom
feat/issue-390-locale-preference-invariants
Aug 21, 2026
Merged

khaira777 merged 3 commits into
mainfrom
feat/issue-390-locale-preference-invariants

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Validate and deliver the country-scoped locale preference invariants while preserving existing UI locale and tenant regional settings boundaries

What Changed

  • Backend settings endpoints (PUT /api/settings/business, PUT /api/settings/:key) now validate currency_display, number_digits, and calendar against the active country's declared localeOptions; unsupported values return HTTP 400 with a country-specific error message, and stale legacy values are normalized to neutral defaults on read and write.
  • Changing the country triggers automatic normalization of previously stored locale display preferences that are not supported by the new country, resetting them to their neutral defaults (rial, locale, locale).
  • The frontend country-select handler mirrors the same normalization logic, keeping supported values and resetting unsupported ones when the user switches countries.
  • Documentation and i18n boundary docs updated to reflect that calendar mode, digit representation, and currency display are now constrained by the active country's localeOptions rather than being fully tenant-authoritative.

Risk Assessment

✅ Low: Well-scoped change with correct locale preference normalization on both read (businessShape) and write (PUT handlers), properly restored timezone preservation, and comprehensive behavioral test coverage.

Testing

Ran the dedicated issue-390 integration test which exercises the backend settings API across 5 scenarios: US rejection of unsupported preferences, IR acceptance of toman/latin/persian, IR→US stale value normalization, US→IR re-acceptance, and legacy DB cleanse on both GET businessShape and PUT save. All assertions passed. Verified no regressions in the adjacent issue-389 timezone test. Confirmed frontend TypeScript compiles without errors. Worktree is clean.

Evidence: Issue-390 test output (filtered)
Issue #390: country-scoped regional preference invariants
============================================================
[MIGRATION v23] normalized: 0, unparseable: 0
[MIGRATION v23] merged 0 duplicate customer(s)
[MIGRATION v23] verification: 0 customers, 0 still non-E.164
[MIGRATION v24] normalized: 0, unparseable: 0
[MIGRATION v25] backfilled addons for 0 order items (0 unparseable, skipped)
[MIGRATION v30] backfilled 0 order_item(s) still missing a normalized addons snapshot
[MIGRATION v30] Dropped order_items.addons — order_item_addons is now the only place selected addons live.

✅ Issue #390 locale-preference invariant checks passed
Evidence: Full test run evidence
Issue #390: country-scoped regional preference invariants
============================================================
✅ Issue #390 locale-preference invariant checks passed

Test scenarios verified:
1. US country rejects unsupported locale preferences (persian calendar, toman display, latin digits) → HTTP 400
2. IR country accepts supported preferences (toman, toman_short, latin, persian, gregorian) → HTTP 200, canonical IRR storage preserved
3. IR → US transition normalizes stale preferences to neutral defaults (rial, locale) → HTTP 200
4. US → IR transition re-accepts Iran-specific preferences → HTTP 200
5. Legacy non-IR DB with stale Iran values normalizes on GET (businessShape) and PUT (save)

Frontend typecheck: clean (no errors)
Related test (issue-389 timezone override): passed

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 3 issues found → auto-fixed ✅
  • ⚠️ frontend/src/app/(dashboard)/settings/page.tsx - merge conflict rebasing onto origin/main
  • ⚠️ main/routes/settings.ts - merge conflict rebasing onto origin/main
  • ⚠️ package.json - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ frontend/src/app/(dashboard)/settings/page.tsx:2273 - Timezone preservation logic was removed from the country-change handler. The old code checked timezoneWasDefault and only replaced the timezone if the user hadn't explicitly chosen a different one from the previous country's default. The new code unconditionally overwrites with country?.timezone || p.timezone. This is a behavioral regression unrelated to the locale preference invariants in issue fix(settings): enforce country-scoped regional preference invariants #390 — the explicit comment "The country profile timezone is only a suggestion. Only replace it when the user has not explicitly chosen a different timezone for the previous country" was also removed.

🔧 Fix: Restore timezoneWasDefault guard in country-change handler
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • node tests/run-electron-node-test.cjs tests/issue-390-locale-preference-invariants.test.ts
  • node tests/run-electron-node-test.cjs tests/issue-389-timezone-override.test.ts
  • npx tsc --noEmit --project frontend/tsconfig.json
  • git status --short (clean worktree)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR constrains locale display preferences to each active country’s declared options while preserving tenant-selected timezone behavior.

  • Adds country-aware backend validation and normalization for currency display, digits, and calendar preferences.
  • Mirrors normalization in the settings UI when changing countries.
  • Documents the revised locale boundaries and adds integration coverage for supported, unsupported, and legacy values.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported timezone-preservation regression is corrected by comparing the current timezone with the previous country’s default before applying the new country’s default.

Important Files Changed

Filename Overview
main/routes/settings.ts Adds shared country-scoped locale preference validation and normalization across business reads and settings writes.
frontend/src/app/(dashboard)/settings/page.tsx Normalizes locale preferences when countries change while retaining the restored explicit-timezone preservation behavior.
tests/issue-390-locale-preference-invariants.test.ts Exercises rejection, acceptance, country transitions, and legacy-value normalization through the backend settings API.
docs/API.md Documents country-aware locale preference validation, defaults, and normalization behavior.
docs/i18n.md Clarifies the boundary between tenant-authoritative timezone selection and country-constrained locale display preferences.
package.json Registers the locale-preference invariant integration test in the repository test scripts.

Reviews (2): Last reviewed commit: "no-mistakes(document): Updated API.md an..." | Re-trigger Greptile

Scope currency_display/number_digits/calendar validation and
normalization to the active country locale options instead of a global
option union. Explicit unsupported values now return HTTP 400; stale
values from IR to other country transitions are silently normalized to
neutral defaults. The settings page resets locale preference state on
country change. Adds integration coverage for the IR/US transition
matrix and legacy non-IR databases.
@khaira777
khaira777 force-pushed the feat/issue-390-locale-preference-invariants branch from c128f8c to 466ad7e Compare August 21, 2026 00:16
@khaira777
khaira777 enabled auto-merge (squash) August 21, 2026 00:19
@khaira777
khaira777 merged commit 079edba into main Aug 21, 2026
13 checks passed
@khaira777
khaira777 deleted the feat/issue-390-locale-preference-invariants branch August 21, 2026 00:20
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