Skip to content

feat(frontend): bootstrap print locales before first print - #624

Merged
khaira777 merged 7 commits into
mainfrom
fm/flocafe-locale-policy-bootstrap-r1
Sep 3, 2026
Merged

khaira777 merged 7 commits into
mainfrom
fm/flocafe-locale-policy-bootstrap-r1

Conversation

@khaira777

@khaira777 khaira777 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Implement Phase 6 of the FloCafe internationalization and printing remediation plan: make locale and print-policy loading deterministic before the first print. Synchronize print-language policies at authentication/bootstrap time instead of only after visiting Settings. Surface browser locale-bundle failures instead of silently labeling English output as another locale. Add all-registered-locale browser and WebUSB loading tests. The selected print language must be available at authentication/bootstrap time and before the first print. Browser locale-bundle loading failures must be visible and actionable, never silently treated as another locale English output. Browser and WebUSB loading tests must cover every registered locale. Existing active UI-language behavior, print semantics, timezone behavior, financial values, and thermal safety must remain unchanged. Keep this as a deterministic locale-loading and print-policy bootstrap change. Do not change translation wording or setup/demo seed quality, country defaults, timezone behavior, currency precision, tax or service-charge policy, country-pack templates, printer capability architecture, raster output, broad routing, or unrelated UI. Start from the current FloCafe default branch after merged PR #620. Phase 5A country-pack charge-row parity remains separately deferred until its output-contract compatibility decision is settled. Use the full no-mistakes delivery path; after this phase lands, continue only with the next planned phase and preserve the one-worker-at-a-time sequence.

What Changed

  • Bootstrap authenticated tenant print policies and preload selected receipt/KOT locale bundles during login, session restore, and tenant selection before the dashboard is released.
  • Surface failed print-locale loads as actionable warnings, including browser/WebUSB print paths, and prevent HTML downloads when required bundles fail.
  • Add Phase 6 coverage for authentication races and browser/WebUSB receipt loading across every registered locale.

Risk Assessment

✅ Low: The change is bounded to deterministic print-policy/locale bootstrap and warning propagation, with stale-auth operation guards and coverage for the selected browser/WebUSB locale paths; no concrete source risk was substantiated.

Testing

After installing the locked dependencies, focused bootstrap, race, browser/WebUSB locale, KOT, printer, compatibility, build, and packaged locale-chunk checks completed without actionable failures. The simulated bundle failure produced a visible reload instruction. Receipt HTML/PNG evidence was captured; the toast failure path used a synthetic browser harness rather than a screenshot because the dashboard was not rendered. No linters or static analysis were run per the assigned test-phase boundary.

Evidence: All locale loading evidence
Phase 6 locale loading: 8 registered locales
Browser and WebUSB receipt loading covered every registered locale.
Evidence: Locale failure visibility evidence
{"failedLanguages":["de"],"operatorToast":"Print language bundle(s) \"de\" could not be loaded. Check the locale bundle and reload the app to retry."}
  • Evidence: Rendered Persian receipt (local file: ~/.no-mistakes/evidence/01M1K152VD2H33T9003Q4478X8/01_persian_receipt_rial_persian_digits.png)
Evidence: Rendered receipt HTML
<!DOCTYPE html>
<html lang="fa-IR" dir="rtl">
<head>
  <meta charset="utf-8">
  <title>رسید # BILL-IR-0089</title>
  <style>
    
    * { box-sizing: border-box; margin: 0; padding: 0; }
    body { font-family: -apple-system, 'Segoe UI', Tahoma, 'Noto Naskh Arabic', 'Helvetica Neue', Arial, sans-serif; font-size: 12px; line-height: 1.4; color: #333; }
    .bill-container { max-width: 100%; margin: 0 auto; }
    .reprint-banner { text-align: center; font-size: 22px; font-weight: bold; letter-spacing: 2px; color: #c00; border: 3px solid #c00; padding: 6px; margin-bottom: 15px; }
    .online-order-banner { text-align: center; font-size: 18px; font-weight: bold; letter-spacing: 1px; border: 2px solid #333; padding: 6px; margin-bottom: 15px; }
    .online-order-banner .online-order-detail { font-size: 13px; font-weight: normal; letter-spacing: normal; margin-top: 2px; }
    .header { text-align: center; margin-bottom: 20px; padding-bottom: 10px; border-bottom: 1px solid #ccc; }
    .header h1 { font-size: 24px; margin-bottom: 5px; }
    .bill-details { margin-bottom: 15px; }
    .bill-details table { width: 100%; }
    .items-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; }
    .items-table th, .items-table td { padding: 8px; border-bottom: 1px solid #eee; text-align: start; }
    .items-table th { background: #f5f5f5; font-weight: bold; }
    .tax-table, .payments-table { width: 50%; margin-inline-start: 50%; border-collapse: collapse; margin-bottom: 15px; }
    .tax-table th, .tax-table td, .payments-table th, .payments-table td { padding: 6px 8px; }
    .tax-table th, .payments-table th { background: #f9f9f9; text-align: start; }
    .totals-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; }
    .totals-table td { padding: 6px 8px; }
    .total-row { border-top: 2px solid #333; font-size: 16px; }
    .footer { text-align: center; margin-top: 30px; padding-top: 15px; border-top: 1px solid #ccc; }
    .powered-by { font-size: 10px; margin-top: 8px; color: #555; }
    .text-end { text-align: end !important; }
    .num { unicode-bidi: isolate; white-space: nowrap; }
    .ltr { direction: ltr; unicode-bidi: isolate; }
    .text-muted { color: #666; }
    .text-italic { font-style: italic; color: #888; }
  
        .bill-container { padding: 10px; max-width: 80mm; font-size: 11px; }
        .header h1 { font-size: 16px; }
      
    @media print {
      .no-print { display: none !important; }
      body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    }
  </style>
</head>
<body>
  <div class="bill-container">
    
    
    <!-- Header -->
    <div class="header">
      <h1>کافه کتاب تهران (Tehran Book Cafe)</h1>
      <p>تهران، خیابان انقلاب، پلاک ۱۲</p>
      <p>تلفن: <span class="ltr" dir="ltr">+98 21 6644 1234</span></p>
      <p>کد اقتصادی: <span class="ltr" dir="ltr">411123456789</span></p>
    </div>

    <!-- Bill Details -->
    <div class="bill-details">
      <table>
        <tr>
          <td><strong>رسید #</strong> <span class="ltr" dir="ltr">BILL-IR-0089</span></td>
          <td class="text-end"><strong>تاریخ</strong> ۲۶ مرداد ۱۴۰۵، ۱۸:۰۰</td>
        </tr>
        <tr><td><strong>میز</strong> میز ۱۲ (Table 12)</td><td></td></tr>
        <tr><td><strong>مشتری</strong> رضا حسینی (Reza Hosseini)</td><td></td></tr>
        <tr><td><strong>شماره مشتری</strong> <span class="ltr" dir="ltr">+98 912 345 6789</span></td><td></td></tr>
      </table>
    </div>

    <!-- Items Table -->
    <table class="items-table">
      <thead>
        <tr>
          <th>اقلام</th>
          <th class="text-end">تعداد</th>
          <th class="text-end">نرخ</th>
          <th class="text-end">مبلغ</th>
        </tr>
      </thead>
      <tbody>
        
          <tr>
            <td>
              چای زعفرانی (Saffron Tea)
              <br><small class="text-muted">+ هل اضافه</small>
              <br><small class="text-italic">کم شیرین</small>
            </td>
            <td class="text-end num">۲</td>
            <td class="text-end num">‎ریال ۳۰۰٬۰۰۰</td>
            <td class="text-end num">‎ریال ۶۶۰٬۰۰۰</td>
          </tr>
        
          <tr>
            <td>
              باقلوا یزدی (Baklava)
              
              
            </td>
            <td class="text-end num">۱</td>
            <td class="text-end num">‎ریال ۳۰۰٬۰۰۰</td>
            <td class="text-end num">‎ریال ۳۳۰٬۰۰۰</td>
          </tr>
        
      </tbody>
    </table>

    <!-- Tax Breakdown -->
    
    <table class="tax-table">
      <thead>
        <tr><th colspan="2">جزئیات مالیات</th></tr>
      </thead>
      <tbody>
        
          <tr><td>ارزش افزوده (VAT) @10%</td><td class="text-end num">‎ریال ۹۰٬۰۰۰</td></tr>
        
      </tbody>
    </table>
    

    <!-- Totals -->
    <table class="totals-table">
      
      
      <tr><td>جمع جزء</td><td class="text-end num">‎ریال ۹۰۰٬۰۰۰</td></tr>
      
      
      
      
      
      <tr class="total-row"><td><strong>جمع کل</strong></td><td class="text-end num"><strong>‎ریال ۹۹۰٬۰۰۰</strong></td></tr>
      
      
      
    </table>

    <!-- Payments -->
    
    <table class="payments-table">
      <thead>
        <tr><th colspan="2">پرداخت‌ها</th></tr>
      </thead>
      <tbody>
        
          <tr><td>کارت</td><td class="text-end num">‎ریال ۹۹۰٬۰۰۰</td></tr>
        
      </tbody>
    </table>
    

    <!-- Footer -->
    <div class="footer">
      <p>از بازدید شما سپاسگزاریم!</p>
      <p>مالیات در صورت اعمال، شامل شده است</p>
      <p class="powered-by">Powered by FloPOS<br>https://flopos.com</p>
    </div>
  </div>

  <div class="no-print" style="text-align:center;margin-top:20px;">
    <button onclick="window.print()" style="padding:10px 20px;font-size:16px;cursor:pointer;">چاپ رسید</button>
  </div>
</body>
</html>
  

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ frontend/src/lib/printer/web-print.ts:160 - Locale-load warnings omit kind, so showPrintWarningsToast treats them as skipped receipt lines. Browser/KOT failures therefore show misleading text such as “1 line was not printed” and unsupported-character guidance, despite printing English labels. Add a distinct warning classification and render the locale-load message separately.

🔧 Fix: Classified locale warnings and routed them to actionable toasts
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • npm ci --ignore-scripts
  • frontend: npm ci --ignore-scripts
  • npm run test:phase6-locale-loading
  • npm run test:auth-print-bootstrap-race
  • npm run test:browser-receipts with required evidence directory
  • npm run test:kot-locale-cold-start
  • npm run test:printer
  • npm run build:frontend
  • npm run test:locale-chunks
  • npm run test:print-labels
  • npm run test:auth-ui-deterministic
  • Synthetic browser locale-bundle failure check with captured actionable toast text
  • Visual inspection of the generated Persian receipt screenshot
  • Final clean-worktree and transient-artifact cleanup check
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ Configured backend and frontend ESLint checks could not run because the worktree has no installed eslint executable (eslint: command not found).

🔧 Fix: Lint and static analysis clean
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR deterministically synchronizes tenant print-language policies and preloads selected locale bundles before authenticated bootstrap completes.

  • Adds stale-auth-operation protection around asynchronous print-policy application.
  • Surfaces locale-load failures through explicit print warnings and actionable operator notifications.
  • Extends browser, WebUSB, authentication-race, and all-registered-locale coverage.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported stale-bootstrap overwrite is prevented by checking operation identity after locale loading and before applying either print policy.

Important Files Changed

Filename Overview
frontend/src/store/auth.ts Coordinates login, restoration, and tenant selection with operation identities so stale asynchronous bootstrap work cannot overwrite current print policies.
frontend/src/lib/print-policy-bootstrap.ts Resolves stored receipt and KOT policies, warms their selected locale bundles, and applies policies only while the originating auth operation remains current.
frontend/src/components/layout/AuthGuard.tsx Surfaces print-locale bootstrap failures after restoration while retaining the existing authenticated routing behavior.
frontend/src/lib/printer/web-print.ts Reports explicit locale-fallback warnings from browser receipt generation and printing.
frontend/src/lib/printer/warnings-toast.ts Separates actionable locale-load notifications from skipped-content and financial print warnings.
tests/auth-print-bootstrap-race.test.ts Verifies that a stale session restoration cannot replace a newer tenant selection or its receipt and KOT policies.
tests/phase6-locale-loading.test.ts Covers policy bootstrap and browser/WebUSB receipt locale loading across all registered languages.

Sequence Diagram

sequenceDiagram
  participant User
  participant Auth as Auth Store
  participant API
  participant Bootstrap as Print Policy Bootstrap
  participant Locale as Locale Loader
  participant Dashboard

  User->>Auth: Login, restore session, or select tenant
  Auth->>Auth: Increment operation identity
  Auth->>API: Load tenant/session data
  API-->>Auth: Tenant and print policies
  Auth->>Bootstrap: Synchronize policies with identity guard
  Bootstrap->>Locale: Load receipt and KOT locales
  Locale-->>Bootstrap: Loaded locales or failures
  Bootstrap->>Bootstrap: Verify operation is still current
  alt Current operation
    Bootstrap-->>Auth: Apply policies and report failures
    Auth-->>Dashboard: Release authenticated state
  else Stale operation
    Bootstrap-->>Auth: Skip policy mutation
  end
Loading

Reviews (2): Last reviewed commit: "no-mistakes(document): Documented print-..." | Re-trigger Greptile

Comment thread frontend/src/store/auth.ts Resolved
@khaira777
khaira777 merged commit 6538e0b into main Sep 3, 2026
15 checks passed
@khaira777
khaira777 deleted the fm/flocafe-locale-policy-bootstrap-r1 branch September 3, 2026 07:38
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