Skip to content

feat(updates): add beta channel opt-in and safe restart guard - #506

Merged
khaira777 merged 2 commits into
mainfrom
fm/flocafe-beta-update-ui
Aug 24, 2026
Merged

khaira777 merged 2 commits into
mainfrom
fm/flocafe-beta-update-ui

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Implement the in-app update UX for FloCafe's beta channel and safe restarts (epic #463, policy decision #503).

  1. Restart-to-install confirmation guard: before quitAndInstall() runs, require manager or owner PIN approval reusing the app's existing master-PIN mechanism (authorizeMasterPin in main/services/master-pin.ts) - do not invent a parallel credential store. The confirmation dialog must show a prominent RED warning stating: all systems (POS, KDS, printing, reports) go down while the update installs; service comes back automatically once the app restarts; and this should not be done during business hours. If PIN approval fails or is cancelled, do not restart - there must be no UI path to restart-to-install without approval. This builds on the honest update-state model from App-side update state model: stop masking 404s as up-to-date #467 (main/index.ts restart-and-install handler, frontend settings updates panel); the guard is a gate before quitAndInstall, not a new update status.

  2. Beta channel opt-in toggle in Settings > Updates: calls the IPC contract owned by the sibling flocafe-beta-release-channel workstream: updates:set-beta-channel(enabled: boolean) and updates:get-beta-channel(): boolean. That crew owns main-process + preload implementation of those channels, so this PR must NOT implement them and must feature-detect: if window.electronAPI lacks these methods (getBetaChannel/setBetaChannel), render the toggle visibly disabled with a short explanation so the PR stays correct whether or not the sibling PR has landed. Persisted state lives on the main-process side; the renderer only reflects what get-beta-channel returns and optimistically updates after a successful set.

Acceptance criteria: restart-to-install without manager/owner PIN approval is impossible from any UI path; red warning copy present and readable with explicit confirm required (cannot be dismissed into a restart by accident); toggle renders per feature-detection rules; new UI strings go through i18n (en/es/pt/fa json files, npm run i18n:check passes); unit tests for new guard/toggle logic following existing node:test patterns (tests/update-ui.test.ts, npm run test:update-ui); lint and builds pass. Constraints: no changes to release workflows or electron-builder config (sibling crew owns those); no changes to the beta-channel IPC main/preload implementation itself.

Environment notes for pipeline agents: the pipeline worktree starts WITHOUT node_modules - run npm ci at repo root before running any test/build/lint step. Evidence must be assertion/log-based only - do NOT attempt browser screenshot capture.

What Changed

  • Added Settings > Updates beta-channel opt-in with IPC feature detection, disabled-state guidance, persisted-state loading, optimistic updates, and localized strings.
  • Added manager/owner PIN-gated restart-to-install confirmation with a prominent red downtime warning before quitAndInstall() can run.
  • Wired update behavior through the Electron bridge, documented the beta release process, and added focused update UI tests.

Risk Assessment

✅ Low: The change is bounded and correctly enforces the PIN gate before quitAndInstall while safely feature-detecting the sibling beta-channel API.

Testing

Validated renderer guard and beta-channel logic, update-state readiness, preload contract, Master PIN authorization, translations across en/es/pt/fa, and the main-process restart gate. Missing or wrong PINs did not call quitAndInstall; approved PIN did. Evidence was assertion/log-based per the explicit environment requirement; no screenshots were attempted.

Evidence: Main guard evidence

Main IPC guard exercised actual handler and authorizeMasterPin: missing PIN denied, wrong PIN denied, approved PIN restarted once.

[Log] Log files location: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flocafe-update-handler-q1hw4s/
[Flo] Initializing...
[Flo] Initializing database...
[Flo] Starting local server...
[Flo] Starting KDS server on port 3002...
[Flo] Starting Server App on port 3003...
[Flo] Initializing WhatsApp service...
[Flo] Starting mDNS advertisement...
[mDNS] Advertising flo.local:3001  (IP fallback: http://127.0.0.1:3001)
[mDNS] KDS available at http://flo.local:3002  (IP fallback: http://127.0.0.1:3002)
[mDNS] Server App available at http://flo.local:3003  (IP fallback: http://127.0.0.1:3003)
[Flo] Initializing printer...
[Flo] Registering IPC handlers...
[Flo] Creating window...
[Flo] Ready!
Main IPC guard: missing PIN denied; wrong PIN denied; approved Master PIN restarted once.
Main IPC guard exercised actual main/index handler and actual authorizeMasterPin().
Evidence: Focused update UI tests

> [email protected] test:update-ui
> ts-node --transpile-only -P tests/tsconfig.json tests/update-ui.test.ts

✔ normalizeRestartInstallResult: guarded success payload resolves ok (1.516959ms)
✔ normalizeRestartInstallResult: denial keeps the dialog open with the error (0.092459ms)
✔ normalizeRestartInstallResult: legacy void resolution still counts as accepted (0.067583ms)
✔ normalizeRestartInstallResult: malformed payloads never count as success (0.075875ms)
✔ isValidManagerPinInput accepts exactly four digits (0.114583ms)
✔ canSubmitRestartInstall requires an explicit valid confirmation (0.062875ms)
✔ betaChannelApiSupported is false when the sibling preload API is absent (0.069875ms)
✔ betaChannelApiSupported is true only when both contract methods exist (0.05225ms)
✔ normalizeBetaChannelValue passes booleans through and rejects junk (0.077834ms)
✔ normalizeBetaChannelValue unwraps { enabled } envelopes (0.109ms)
✔ normalizeBetaChannelValue treats error envelopes as unknown state (0.058958ms)
✔ normalizeBetaChannelWriteResult: confirmed success adopts reported state (0.090334ms)
✔ normalizeBetaChannelWriteResult: legacy void assumes the requested value landed (0.05275ms)
✔ normalizeBetaChannelWriteResult: failure keeps the previously rendered value (0.046625ms)
✔ readBetaChannelState reports unsupported when the contract is missing (0.081958ms)
✔ readBetaChannelState round-trips the persisted boolean when present (0.0755ms)
✔ readBetaChannelState degrades to unsupported on a rejected get (0.100208ms)
✔ writeBetaChannelState refuses to call a missing setBetaChannel (0.078125ms)
✔ writeBetaChannelState returns the new state after a successful set (0.110125ms)
ℹ tests 19
ℹ suites 0
ℹ pass 19
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 12.438916
Evidence: Translation integrity tests

> [email protected] test:translations
> ts-node --transpile-only -P tests/tsconfig.json tests/translations.test.ts

Translation integrity: en <-> es <-> pt <-> fa
  ✓ registry ↔ files consistent (4 languages, 4 files)
  en.json: 2214 leaf keys
  es.json: 2214 leaf keys
  pt.json: 2214 leaf keys
  fa.json: 2214 leaf keys
  ✓ no duplicate keys within translation files
  ✓ exact leaf key parity with en.json (no missing, no orphan keys)
  ✓ all leaves are non-empty strings (no empty objects/arrays/null/booleans/numbers)
  ✓ no malformed values
  ✓ all messages parse as valid ICU (plurals, selects, brackets)
  ✓ placeholder arguments and plural/select selectors match en.json in all locales
  ✓ rich-text tags match en.json in all locales
  ✓ no undefined keys (1828 literal t() calls covered)
  ✓ no unsafe template-literal t() calls (all dynamic keys exhaustively cast)
  ✓ no active frontend consumers import the legacy i18n bridge
  ✓ messages.d.ts AppConfig augmentation present (compile-time key checks active)
  ✓ no untranslated fa.json values (31 intentional shared values)

✅ All translation integrity checks passed.

Negative tests (fixture-based):
  ✓ all negative fixtures detected by their validators

✅ All translation integrity checks + negative tests passed.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • npm ci
  • npm run test:update-ui
  • npm run test:update-state
  • npm run test:master-pin
  • npm run test:electron-api-contract
  • npm run test:translations
  • Disposable mocked-Electron execution of the actual main/index.ts restart handler with actual authorizeMasterPin()
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…le (#463)

Restart-to-install guard:
- main process authorizes manager/owner PIN via authorizeMasterPin inside
  the 'restart-and-install' handler before quitAndInstall, returning
  {success,error} instead of restarting on denial
- new UpdateInstallGuardDialog shows a prominent red warning (all systems
  down during install, automatic return after restart, avoid business
  hours) and requires an explicit 4-digit PIN confirm; cancelling or an
  invalid PIN can never trigger a restart
- UpdateBadge 'restart now' now opens the dialog instead of restarting
  directly; useUpdateStatus.restartAndInstall forwards the PIN

Beta channel opt-in (#503 contract):
- Settings > Updates gains a beta/pre-release toggle that feature-detects
  updates:get/set-beta-channel on electronAPI and renders visibly disabled
  with an explanation when absent
- persisted state stays in the main process; renderer reflects get result
  and optimistically updates only after a successful set

i18n keys added under update.* in en/es/pt/fa; new unit tests in
tests/update-ui.test.ts (npm run test:update-ui).
@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a backend-authoritative Master PIN gate and explicit downtime warning before installing a downloaded update. It also adds a feature-detected beta-channel toggle that remains visibly disabled until the sibling IPC implementation is available.

  • Routes the update badge’s restart action through a localized PIN confirmation dialog.
  • Validates the Master PIN in the main process before calling quitAndInstall().
  • Adds beta-channel state normalization, optional Electron API types, and focused tests.
  • Documents the beta opt-in and guarded restart behavior.

Confidence Score: 5/5

The PR appears safe to merge, with the restart authorization enforced in the main process and the unavailable beta IPC contract handled through explicit feature detection.

The changed restart path checks both update readiness and the existing Master PIN authorization before reaching quitAndInstall, while failed or cancelled approval leaves the application running; the beta toggle remains disabled when its sibling bridge is absent.

Important Files Changed

Filename Overview
main/index.ts Adds the authoritative update-readiness and Master PIN checks before invoking quitAndInstall().
frontend/src/components/updates/UpdateInstallGuardDialog.tsx Adds an explicit PIN confirmation dialog with prominent localized downtime warnings and safe cancellation behavior.
frontend/src/components/layout/UpdateBadge.tsx Replaces the direct restart action with the guarded installation dialog.
frontend/src/components/settings/BetaChannelToggle.tsx Adds a feature-detected beta-channel control with disabled guidance and persisted-state loading.
frontend/src/lib/updates/beta-channel.ts Adds defensive normalization and orchestration helpers for the sibling-owned optional beta-channel API.
frontend/src/lib/updates/restart-install.ts Adds strict four-digit PIN submission checks and guarded IPC-result normalization.
main/preload.ts Updates the existing restart bridge to forward the approval PIN without implementing the sibling beta-channel contract.
tests/update-ui.test.ts Covers restart-result normalization, PIN submission rules, beta API feature detection, and beta read/write normalization.

Sequence Diagram

sequenceDiagram
    actor Operator
    participant Badge as Update Badge
    participant Guard as Install Guard Dialog
    participant Preload as Electron Preload
    participant Main as Main Process
    participant Auth as Master PIN Service
    participant Updater as electron-updater

    Operator->>Badge: Select Restart Now
    Badge->>Guard: Open downtime warning and PIN prompt
    Operator->>Guard: Enter PIN and explicitly confirm
    Guard->>Preload: restartAndInstall(pin)
    Preload->>Main: invoke restart-and-install
    Main->>Main: Verify update is ready
    Main->>Auth: authorizeMasterPin(pin)
    alt Approval denied
        Auth-->>Main: Error
        Main-->>Guard: success: false
        Guard-->>Operator: Keep dialog open and show error
    else Approval granted
        Auth-->>Main: Approved
        Main->>Updater: quitAndInstall()
    end
Loading

Reviews (1): Last reviewed commit: "no-mistakes(document): Updated release d..." | Re-trigger Greptile

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