# שלמות ניהול החשבון

> תיעוד היסטורי. מקור: docs/platform/production-integrity-release.md · 6a466bf.

## Scope

This release covers account management, vehicles, fleets, provider selection and
station discovery. Charger commands and payment collection remain disabled until
their provider integrations are separately implemented and verified. Existing
layouts, styling, approved images and plan capacities are preserved.

## Changes

- Vehicle plate/catalog writes use a server-only RPC after a fresh government
  registration lookup. The transaction checks the authenticated actor's active
  membership, tenant status, vehicle revision and plan capacity. Browser clients
  retain only RLS-constrained metadata updates. Existing vehicle data is preserved;
  the migration does not retroactively certify historical catalog snapshots.
- Owners can revoke an invitation, immediately invalidating its acceptance token.
  Acceptance and revocation serialize on the tenant/invitation so only one wins.
- Driver identity can be linked in either order: driver before membership or
  membership before driver. Only a server-verified Clerk email belonging to an
  active account member supplies identity evidence. Display names and caller
  input cannot establish identity. Removed verified addresses become noncurrent;
  existing driver links are never silently reassigned.
- Favorites, support drafts and notification-read state are stored by mode,
  account and user. This is browser persistence, not cloud synchronization. Unknown
  owners of legacy shared favorites/drafts are preserved unassigned and are not
  imported into a connected account automatically.
- Export/reset covers every demo workspace on the device, including profiles,
  providers and private demo data. Connected-account data, device preferences and
  ambiguous legacy data are preserved. Reset clears a remembered demo destination
  and exits a deleted demo account.
- Browser-state updates synchronize across components and tabs, including the
  analytics-consent setting. No analytics provider is enabled by this release.
- API origin checks use the actual validated Host header, so a production server
  bound to `0.0.0.0` accepts the browser's legitimate host. Missing, malformed,
  cross-origin and internal-bind-origin requests are rejected. Forwarded headers
  cannot select a trusted host or scheme. The same guard protects vehicle lookup.

## Required server configuration

The product Vercel project requires its existing Clerk and Supabase public
configuration plus **SUPABASE_SERVICE_ROLE_KEY**, stored as a server-only sensitive
environment variable. It is used only for narrowly scoped trusted vehicle and
verified-email operations. It must never be prefixed with NEXT_PUBLIC, sent to
browser code, committed, printed in logs or included in test artifacts.

Native Clerk-to-Supabase third-party trust remains required for all normal
RLS-scoped reads and metadata writes. Verify the configured project reference is
`dxeijkkmueuhvynvsgch` and the product target is
`linknodes-energy-product` before releasing. Do not apply this release to the
unrelated dealership database or legal-platform Vercel project.

Vercel's trusted `VERCEL=1` environment signal selects HTTPS for origin checks.
Verify that system environment variables are exposed in the staged deployment.
Plain `next start` uses HTTP. A TLS reverse proxy outside Vercel must preserve the
browser's Host header and set server-only `APP_ORIGIN` to its exact canonical
public origin; forwarded headers alone are deliberately insufficient.

## Release gates

The GitHub workflow has three required release checks:

1. Locked dependencies, generated-system consistency, TypeScript, lint, all unit
   tests and production build.
2. All versioned migrations on a fresh PostgreSQL 17 service, followed by tenant,
   provider, workspace-profile, plan-capacity, verified-vehicle and invitation
   lifecycle regressions. Tests include real concurrent transactions and verify
   cleanup. The runner refuses a remote or nonempty database.
3. Production-build Chromium tests for workspace navigation, onboarding,
   vehicle capacity, provider persistence, fail-closed APIs, private browser data
   isolation, tab synchronization and all-demo export/reset.

Browser tests use synthetic data and no live credentials. They do not replace an
authenticated production smoke test against Clerk and Supabase. Passing a build
alone is not permission to declare the connected product verified.

Successful pull-request builds publish a private `vehicle-assets` artifact with
one-day retention. This preserves the exact tracked PNG files for source-file
deployments; no environment files, credentials or browser state are included.
Verify extracted paths, byte lengths and Git blob SHA against the release tree.

## Compatible rollout order

1. Record the current production deployment and current main commit. Verify the
   exact release commit has passed all three GitHub checks and the server key is
   configured for the production target.
2. Apply `20261109190535_verified_vehicle_writes.sql` (additive revision/RPC) and
   `20261109190551_invitation_driver_lifecycle.sql` (identity and invitations).
   Keep historical migration versions intact; cloud apply timestamps can differ
   from source filenames, so record both the migration name and source checksum.
3. Build and stage the exact release commit using production configuration without
   assigning production domains. Preserve all existing assets. Verify the build
   and connected smoke checks, then promote that staged deployment.
4. Immediately apply `20261109191257_enforce_verified_vehicle_writes.sql`. This
   final migration removes browser INSERT and broad UPDATE grants, retaining
   metadata-column UPDATE. Verify direct protected writes fail and the trusted
   server path still works. The final restriction must not precede the new app.
5. Verify record counts and existing vehicle data, tenant isolation, owner invite
   revocation, both driver-link orders, account capacities and server health.

If server configuration, database tests, browser tests or connected smoke checks
are unavailable or fail, keep the current production deployment active. Do not
apply the final grant restriction and do not claim completion of production QA.

## Rollback considerations

Additive migrations can remain in place if the new deployment is rejected before
promotion. Keep the existing application active and investigate the failing gate.
After enforcement, an old deployment cannot write vehicle identities directly.
Prefer rolling forward with a narrow repair; do not silently restore the broad
grants that this release removes. Do not drop verified-identity evidence or rewrite
customer records as a rollback shortcut. Record any emergency change explicitly.
