Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
sanity: merge origin/main; Halloween theme takes main's readable danger red
aashu68349512efc7
diff --cc .ai/lessons.mdindex bea0832b83,7530f807d4..5e0b85c954--- a/.ai/lessons.md+++ b/.ai/lessons.md@@@ -4050,22 -4069,83 +4069,103 @@@ The write was then removed (nothing rea**Applies to:** every table in `fieldMappings` (`apps/erp/app/modules/shared/imports.models.ts`) whose importer has a fallback for a blank cell.+## A temporary override lives in the thing it overrides, not in its callers++**Context:** Halloween had to be the theme for everyone while in season (2026-10). The first cut replaced the cookie read in all three apps' `getTheme` (`services/theme.server.ts`) with `resolveTheme(halloweenTheme.name)`.++**Problem:** Undoing it meant rewriting three deleted cookie reads from memory, and nothing pointed at them: deleting `halloween-theme.ts` would just break the imports. The mesh colors in `MeshGradientBackground.tsx` (a `Record<string, …>`, so no compile error) and a test that imported the theme directly had the same shape. The removal checklist went stale twice as pieces were added.++**Rule:** Put a seasonal or temporary behaviour on the removable unit itself (its `available` window and `mesh` on the `SeasonalTheme`, read by the shared resolver) and keep callers generic, so deleting the unit turns the behaviour off. Test the mechanism on a fixture, not on the instance. Keep ONE removal checklist, next to the code, and make every other comment point to it.++**Applies to:** `packages/utils/src/themes.ts` seasonal themes, `packages/react/src/Halloween/`, any feature flag, promo or seasonal UI.++## The theme a page renders is not the theme the user picked++**Context:** A seasonal theme made `getTheme` (`services/theme.server.ts`) return the seasonal name for everyone in season (2026-10).++**Problem:** The ERP's onboarding theme step and `x+/account+/theme.tsx` also read `getTheme` to seed and post back the user's own pick. In season they posted the seasonal name, `themeColorValidator` refused it, and onboarding could not get past the theme step. The theme pickers meanwhile painted a chosen theme onto `<body>` while the server kept rendering the seasonal one.++**Rule:** Keep "what to render" (`getTheme` → `resolveTheme`) and "what the user chose" (`getStoredTheme` → `storedTheme`) as two reads, and decide the season once, in the root loader (`Document` renders the name with `themeByName`). A picker that cannot take effect is disabled and says why (`useSeasonalTheme`, `SeasonalThemeNotice`).++**Applies to:** `packages/utils/src/themes.ts`, every app's `services/theme.server.ts` and `root.tsx`, every theme picker.+++ ## Registering on `load` from entry.client never registers in dev++ **Context:** The ERP and MES service workers were registered from `entry.client.tsx` with `window.addEventListener("load", register)`, the pattern most guides show (2026-10-22).++ **Problem:** On the dev server React Router imports `entry.client` late: by the time the module runs, the page has already fired `load` (`document.readyState === "complete"`), so the listener never ran and no worker was registered. The offline page never appeared and nothing logged an error.++ **Rule:** Register immediately when `document.readyState === "complete"`, and on `load` otherwise. Check `navigator.serviceWorker.getRegistrations()` in the browser after any change to how a worker is registered.++ **Applies to:** `apps/erp/app/entry.client.tsx`, `apps/mes/app/entry.client.tsx`; any code in an entry module that waits for `load`.++ ## A service worker's install-time cache can come out empty and stay empty++ **Context:** The ERP worker saves `offline.html` when it installs, and installs anyway when the save fails, so push never depends on it (2026-10-22).++ **Problem:** A user toggled offline while an updated worker was installing. The save failed, the new worker activated and deleted the previous cache, and every later offline page load got the browser's "This site can't be reached": the worker had nothing to answer with, and it only reinstalls when its own file changes.++ **Rule:** Never trust that install filled a cache. Re-check it from the fetch handler after a page load that reached the network (`ensureOfflinePage`), and give the worker a built-in last-resort response (`fallbackOfflinePage`) so a cache miss never surfaces as the browser's error.++ **Applies to:** `apps/{erp,mes}/public/service-worker.js`; any worker that precaches on install.++ ## Changing a precached file without bumping the cache name changes nothing++ **Context:** `offline.html` was edited several times (the game, the text wrapping), and each time existing browsers kept showing the old page (2026-10-22).++ **Problem:** A worker saves the file only when it installs, and it reinstalls only when `service-worker.js` itself changes. Editing `offline.html` alone leaves every browser that already has the worker on the old copy, and the self-heal only fills a missing entry, it never replaces one.++ **Rule:** Every change to `offline.html` bumps the offline cache in both workers (ERP `OFFLINE_CACHE`, MES `SHELL_CACHE`). `offline-page.test.ts` in each app pins the page's hash to the cache name, so a change that skips the bump fails.++ **Applies to:** `apps/{erp,mes}/public/offline.html` and `service-worker.js`.++ ## Chrome on macOS drops an installed app's Dock badge when its window closes++ **Context:** The app icon badge is set by the open tab and by each push (`setAppBadge` in the worker), so it should keep counting while the installed app is closed (2026-10-22).++ **Problem:** In Chrome on macOS the badge shows while the app's window is open and disappears when it closes; a push that arrives later, and `setAppBadge` run from the worker's own console, both resolve and draw nothing. Chrome's installed app is a helper process that quits with its window, and the badge belongs to it. The badge also needs macOS notification permission with "Badge app icon" on (System Settings → Notifications → the app).++ **Rule:** Do not promise a closed-app badge on macOS Chrome. Test the badge with the app hidden (⌘H), not closed, and test the closed case on a platform meant to keep it (an iPhone Home Screen app) before calling it broken.++ **Applies to:** `apps/erp/app/hooks/useAppBadge.ts`, `apps/erp/public/service-worker.js`, the `send-push` badge count.++ ## A scheduler decision is only stored when every write-back guard agrees++ **Context:** The scheduler balances an operation that has not started onto any work center of its process (F10, 2026-10-26).++ **Problem:** Two separate "never overwrite a stored work center" guards sat between the decision and the database: one in `applyWorkCenterSelections`, one in the engine's `buildWrites`. Fixing the first one alone changed nothing in the database. The `capacityReservation` row named the chosen station while `jobOperation.workCenterId` kept the old one, and every unit test still passed.++ **Rule:** When you change what the scheduler decides, trace the value to the write (`placementWrites`, `run-overlay.ts`). Test the decision and the write together, then remove the write fix and confirm a test goes red.++ **Applies to:** `packages/planning/src/scheduling/` — `apply-work-center-selections.ts`, `run-overlay.ts`, `scheduling-engine.ts`.++ ## An SQL test that inserts an employee needs the company's root group first++ **Context:** Seeding employees in a `supabase/tests/*.test.sql` file (`rpc-privileges.test.sql`, 2026-10-26).++ **Problem:** The `employee` insert fires the employee-type group interceptor, which needs the company's "All Employees" root group. A test company made by hand has no root group, so the insert fails. `SET session_replication_role` is not permitted there.++ **Rule:** Insert the root group first, with the id `getGroupId` builds: `'00000000-0000-' || substr(c,1,4) || '-' || substr(c,5,4) || '-' || substr(c,9,12)` for company id `c`. Then insert the employee type and the employee.++ **Applies to:** SQL tests under `packages/database/supabase/tests/` that create employees.++ ## `setGenericQueryFilters` erases a query's row type++ **Context:** Inventory → Receiving read a view through `setGenericQueryFilters` and its route annotated the rows with a hand-written type (2026-10-26).++ **Problem:** The helper's signature is typed loosely (it carries `@ts-expect-error`), so whatever it returns awaits to rows of type `any`. An annotation on those rows is an unchecked cast: renaming a column in the select string, or dropping it from the view, compiles clean and renders blank. Types in `types.ts` derived through `ReturnType<typeof getX>` are `any` the same way.++ **Rule:** Keep the typed builder. Assign the helper's result back to the query variable (`query = setGenericQueryFilters(query, { filters })`), which keeps the variable's declared type, then apply the sort and `.range()` on it directly. Derive the row type from that function in `types.ts`, and narrow a view's never-null keys once at the loader boundary rather than guarding them in components.++ **Applies to:** list reads in `apps/erp/app/modules/*/*.service.ts` that call `setGenericQueryFilters`, and the `types.ts` row types derived from them.+++ ## OCCT keeps every document it opened by path, and refuses to open it again++ **Context:** The optimize ingest gained a PMI pass (`read_pmi`, `crates/occt-bridge/src/pmi.cc`) that reads the same `.xbf` the optimiser had just tessellated with `read_xbf` (2026-10-26).++ **Problem:** `TDocStd_Application::Open(path, doc)` registers the document with the application until `Close(doc)`. `read_xbf` never closes it, so the second open of the same path failed with `PCDM_RS_AlreadyRetrieved` ("could not open XBF document"). The hermetic converter test passed, because it opened the `.xbf` only once; only the assembler's ingest test, which runs both passes, showed it.++ **Rule:** A second reader of an `.xbf` opens it from a stream (`Open(std::istream&, doc)`), which skips the path check, and calls `xcaf_app()->Close(doc)` when done. Test any new pass over the ingest's xbf through `run_ingest`, not only through the converter.++ **Applies to:** `crates/occt-bridge/src/*.cc` (any function that opens a BinXCAF document), `apps/assembler/src/actions/optimize.rs` (`run_ingest`).diff --cc packages/locale/locales/de/mes.poindex d657d65b29,c1c19fab4e..0bf88a13f4--- a/packages/locale/locales/de/mes.po+++ b/packages/locale/locales/de/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "Instandhaltungseinsatz anzeigenmsgid "View or open"msgstr "Anzeigen oder Öffnen"+msgid "Wash"+msgstr "Waschen"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "Wir haben Ihnen einen Magic Link zur Anmeldung an Ihrem Konto gesendet."+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "{translatedTerm} ist was?"diff --cc packages/locale/locales/en/mes.poindex a5705a09e8,ce2fdc0949..0ca0efe48d--- a/packages/locale/locales/en/mes.po+++ b/packages/locale/locales/en/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "View maintenance dispatchmsgid "View or open"msgstr "View or open"+msgid "Wash"+msgstr "Wash"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "We've sent you a magic link to sign in to your account."+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."msgid "What is {translatedTerm}?"msgstr "What is {translatedTerm}?"diff --cc packages/locale/locales/es/mes.poindex 75b3f2ea2c,b9a695e6e4..1aad5df50e--- a/packages/locale/locales/es/mes.po+++ b/packages/locale/locales/es/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "Ver orden de mantenimientomsgid "View or open"msgstr "Ver o abrir"+msgid "Wash"+msgstr "Lavar"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "Le hemos enviado un enlace mágico para iniciar sesión en su cuenta."+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "¿Qué es {translatedTerm}?"diff --cc packages/locale/locales/fr/mes.poindex bf56ed5eb4,ee0a4a204c..43341b3d58--- a/packages/locale/locales/fr/mes.po+++ b/packages/locale/locales/fr/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "Voir l'intervention de maintenamsgid "View or open"msgstr "Afficher ou ouvrir"+msgid "Wash"+msgstr "Laver"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "Nous vous avons envoyé un lien magique pour vous connecter à votre compte."+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "Qu'est-ce que {translatedTerm} ?"diff --cc packages/locale/locales/hi/mes.poindex 22d2446938,0771708de4..e7ffc43c31--- a/packages/locale/locales/hi/mes.po+++ b/packages/locale/locales/hi/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "रखरखाव कार्msgid "View or open"msgstr "देखें या खोलें"+msgid "Wash"+msgstr "धुलाई"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "हमने आपके खाते में साइन इन करने के लिए आपको एक जादुई लिंक भेजा है।"+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "{translatedTerm} क्या है?"diff --cc packages/locale/locales/it/mes.poindex c58c3dff25,be5e47dcb7..f01846b373--- a/packages/locale/locales/it/mes.po+++ b/packages/locale/locales/it/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "Visualizza intervento di manutemsgid "View or open"msgstr "Visualizza o apri"+msgid "Wash"+msgstr "Lavaggio"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "Ti abbiamo inviato un link di accesso al tuo account."+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "Cos'è {translatedTerm}?"diff --cc packages/locale/locales/ja/mes.poindex b325f09797,345a10f6c9..457b4d7a78--- a/packages/locale/locales/ja/mes.po+++ b/packages/locale/locales/ja/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "保全指示を表示msgid "View or open"msgstr "表示または開く"+msgid "Wash"+msgstr "洗浄"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "アカウントにサインインするためのマジックリンクをお送りしました。"+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "{translatedTerm}とは何ですか?"diff --cc packages/locale/locales/ko/mes.poindex f862ddc2b0,7d6883977b..cf57870f44--- a/packages/locale/locales/ko/mes.po+++ b/packages/locale/locales/ko/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "유지보수 지시 보기msgid "View or open"msgstr "보기 또는 열기"+msgid "Wash"+msgstr "세척"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "계정에 로그인할 수 있는 매직 링크를 보내드렸습니다."+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "{translatedTerm}란 무엇인가요?"diff --cc packages/locale/locales/pl/mes.poindex 719d635cd7,ad48f307bb..a6e999810b--- a/packages/locale/locales/pl/mes.po+++ b/packages/locale/locales/pl/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "Wyświetl zlecenie utrzymania rmsgid "View or open"msgstr "Wyświetl lub otwórz"+msgid "Wash"+msgstr "Mycie"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "Wysłaliśmy Ci link do logowania na Twoje konto."+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "Co to jest {translatedTerm}?"diff --cc packages/locale/locales/pt/mes.poindex 33dc067037,c27c53a1e3..d5a4e9bc9d--- a/packages/locale/locales/pt/mes.po+++ b/packages/locale/locales/pt/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "Visualizar ordem de manutençãmsgid "View or open"msgstr "Visualizar ou abrir"+msgid "Wash"+msgstr "Lavagem"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "Enviamos um link mágico para você entrar na sua conta."+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "O que é {translatedTerm}?"diff --cc packages/locale/locales/ru/mes.poindex b3d6333432,68f5c8381a..9bc5238d35--- a/packages/locale/locales/ru/mes.po+++ b/packages/locale/locales/ru/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "Просмотреть заявmsgid "View or open"msgstr "Просмотр или открытие"+msgid "Wash"+msgstr "Мойка"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "Мы отправили вам ссылку для входа в ваш аккаунт."+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "Что такое {translatedTerm}?"diff --cc packages/locale/locales/tr/mes.poindex 0dbec3ec74,b4d2bd28b5..ee977bcfb6--- a/packages/locale/locales/tr/mes.po+++ b/packages/locale/locales/tr/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "Bakım emrini Görüntülemsgid "View or open"msgstr "Görüntüle veya aç"+msgid "Wash"+msgstr "Yıkama"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "Hesabınıza giriş yapmak için size bir sihirli bağlantı gönderdik."+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "{translatedTerm} nedir?"diff --cc packages/locale/locales/zh/mes.poindex 598353b98d,c84203d247..a2dc43c4ab--- a/packages/locale/locales/zh/mes.po+++ b/packages/locale/locales/zh/mes.po@@@ -2260,11 -2245,8 +2275,11 @@@ msgstr "查看维护工单msgid "View or open"msgstr "查看或打开"+msgid "Wash"+msgstr "清洗"+- msgid "We've sent you a magic link to sign in to your account."- msgstr "我们已向您发送了登录链接,请查收。"+ msgid "We've emailed you a sign-in link and a 6-digit code. Follow the link, or enter the code here."+ msgstr ""msgid "What is {translatedTerm}?"msgstr "{translatedTerm}是什么?"diff --cc packages/utils/src/halloween-theme.tsindex a5477625c6,0000000000..959657582fmode 100644,000000..100644--- a/packages/utils/src/halloween-theme.ts+++ b/packages/utils/src/halloween-theme.ts@@@ -1,80 -1,0 +1,80 @@@+// SPDX-License-Identifier: AGPL-3.0-only+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,+// including ports, remain AGPLv3; serving them over a network requires releasing their source.++import type { SeasonalTheme } from "./themes";++// Seasonal theme: on October 31 it replaces every theme, for everyone, and+// the sign-in page's Night Shift and the app decorations come with it+// (packages/react/src/Halloween/). Nobody can pick it. To change the day or+// widen it to a few, edit `available`; nothing else is needed. The removal+// checklist is at the top of packages/react/src/Halloween/HalloweenLayer.tsx.++export const halloweenTheme = {+ name: "halloween",+ label: "Halloween",+ available: {+ from: { month: 10, day: 31 },+ to: { month: 10, day: 31 }+ },+ mesh: {+ light: ["#fdf0e4", "#f6f0fa", "#fffaf5", "#fbefe6"],+ dark: ["#2d1205", "#14081f", "#0D0D0D", "#050505"]+ },+ activeColor: {+ light: "25 95% 50%",+ dark: "25 95% 53%"+ },+ cssVars: {+ light: {+ background: "30 30% 95%",+ foreground: "270 30% 8%",+ card: "0 0% 100%",+ "card-foreground": "270 30% 8%",+ popover: "0 0% 100%",+ "popover-foreground": "270 30% 8%",+ primary: "25 95% 50%",+ "primary-foreground": "270 30% 6%",+ active: "270 40% 92%",+ "active-foreground": "270 60% 40%",+ secondary: "30 20% 92%",+ "secondary-foreground": "270 30% 10%",+ muted: "30 15% 90%",+ "muted-foreground": "270 8% 42%",+ accent: "30 20% 92%",+ "accent-foreground": "270 30% 10%",- destructive: "0 84.2% 60.2%",++ destructive: "0 74% 42%",+ "destructive-foreground": "0 0% 98%",+ border: "30 15% 86%",+ input: "30 15% 86%",+ ring: "25 95% 50%",+ success: "142 70% 45%",+ "success-foreground": "0 0% 98%"+ },+ dark: {+ background: "270 20% 6%",+ foreground: "30 20% 96%",+ card: "270 25% 3%",+ "card-foreground": "30 20% 96%",+ popover: "270 20% 9%",+ "popover-foreground": "30 20% 96%",+ primary: "25 95% 53%",+ "primary-foreground": "270 30% 6%",+ active: "270 35% 18%",+ "active-foreground": "270 80% 78%",+ secondary: "270 15% 14%",+ "secondary-foreground": "30 20% 96%",+ muted: "270 15% 10%",+ "muted-foreground": "270 8% 64%",+ accent: "270 15% 14%",+ "accent-foreground": "30 20% 96%",- destructive: "0 72.2% 50.6%",- "destructive-foreground": "0 0% 98%",++ destructive: "0 100% 64%",++ "destructive-foreground": "0 0% 0%",+ border: "270 15% 15%",+ input: "270 15% 15%",+ ring: "25 95% 53%",+ success: "142 70% 45%",+ "success-foreground": "0 0% 98%"+ }+ }+} as const satisfies SeasonalTheme;diff --cc packages/utils/src/themes.test.tsindex 413022dd81,5d28e6ed87..f3c4bcd5a2--- a/packages/utils/src/themes.test.ts+++ b/packages/utils/src/themes.test.ts@@@ -2,127 -2,69 +2,194 @@@// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,// including ports, remain AGPLv3; serving them over a network requires releasing their source.-import { describe, expect, it } from "vitest";-import { themes } from "./themes";+// The season is tested on a fixture, and the registry on whatever seasonal+// themes exist, so removing one (Halloween) leaves this file as it is.++import { CalendarDate } from "@internationalized/date";+import { afterEach, describe, expect, it, vi } from "vitest";+import {+ DEFAULT_THEME_NAME,+ isInSeason,+ isSeasonalTheme,+ resolveTheme,+ type SeasonalTheme,+ seasonalThemes,+ storedTheme,+ type ThemeWindow,+ themeByName,+ themes+} from "./themes";+import { themeColorValidator } from "./types";++// Typed by what a seasonal theme may declare, so it compiles when empty.+const seasonal: readonly SeasonalTheme[] = seasonalThemes;++const spooky: { available: ThemeWindow } = {+ available: { from: { month: 10, day: 20 }, to: { month: 11, day: 1 } }+};+ // WCAG 2.1 contrast ratio between two theme values written as "H S% L%".+ function contrast(a: string, b: string) {+ const la = relativeLuminance(a);+ const lb = relativeLuminance(b);+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);+ }++ function relativeLuminance(value: string) {+ const match = value.match(/^([\d.]+)\s+([\d.]+)%?\s+([\d.]+)%$/);+ if (!match) throw new Error(`Not an HSL theme value: ${value}`);+ const h = Number(match[1]);+ const s = Number(match[2]) / 100;+ const l = Number(match[3]) / 100;+ const k = (n: number) => (n + h / 30) % 12;+ const a = s * Math.min(l, 1 - l);+ const linear = (n: number) => {+ const c = l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1));+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;+ };+ return 0.2126 * linear(0) + 0.7152 * linear(8) + 0.0722 * linear(4);+ }++ const TEXT = 4.5;+ const SURFACES = ["card", "background", "muted", "popover"] as const;+++// Seasonal themes replace every theme while in season, so they meet it too.++const everyTheme = [...themes, ...seasonalThemes];+++ describe("destructive colour contrast", () => {+ it.each(- themes.flatMap((theme) =>++ everyTheme.flatMap((theme) =>+ (["light", "dark"] as const).map((mode) => [theme.name, mode] as const)+ )+ )("%s %s: destructive-foreground on destructive", (name, mode) => {- const vars = themes.find((t) => t.name === name)!.cssVars[mode];++ const vars = everyTheme.find((t) => t.name === name)!.cssVars[mode];+ expect(+ contrast(vars.destructive, vars["destructive-foreground"])+ ).toBeGreaterThanOrEqual(TEXT);+ });+- it.each(themes.map((theme) => theme.name))(++ it.each(everyTheme.map((theme) => theme.name))(+ "%s light: destructive text on every surface",+ (name) => {- const vars = themes.find((t) => t.name === name)!.cssVars.light;++ const vars = everyTheme.find((t) => t.name === name)!.cssVars.light;+ for (const surface of SURFACES) {+ expect(+ contrast(vars.destructive, vars[surface]),+ surface+ ).toBeGreaterThanOrEqual(TEXT);+ }+ }+ );+- it.each(themes.map((theme) => theme.name))(++ it.each(everyTheme.map((theme) => theme.name))(+ "%s dark: destructive text on every surface",+ (name) => {- const vars = themes.find((t) => t.name === name)!.cssVars.dark;++ const vars = everyTheme.find((t) => t.name === name)!.cssVars.dark;+ for (const surface of SURFACES) {+ expect(+ contrast(vars.destructive, vars[surface]),+ surface+ ).toBeGreaterThanOrEqual(TEXT);+ }+ }+ );+ });+++describe("isInSeason", () => {+ it("is on inside the window, both ends included", () => {+ expect(isInSeason(spooky, new CalendarDate(2026, 10, 20))).toBe(true);+ expect(isInSeason(spooky, new CalendarDate(2026, 10, 31))).toBe(true);+ expect(isInSeason(spooky, new CalendarDate(2026, 11, 1))).toBe(true);+ });++ it("is off outside it", () => {+ expect(isInSeason(spooky, new CalendarDate(2026, 10, 19))).toBe(false);+ expect(isInSeason(spooky, new CalendarDate(2026, 11, 2))).toBe(false);+ });+});++describe("isInSeason with no date", () => {+ afterEach(() => {+ vi.useRealTimers();+ });++ const onAt = (instant: string) => {+ vi.useFakeTimers();+ vi.setSystemTime(instant);+ return isInSeason(spooky);+ };++ it("turns on once the first time zone reaches the first day", () => {+ // Oct 19 in UTC, Oct 20 in India and on Kiritimati (UTC+14).+ expect(onAt("2026-10-19T23:03:00Z")).toBe(true);+ // Still Oct 19 everywhere, Kiritimati included.+ expect(onAt("2026-10-19T09:00:00Z")).toBe(false);+ });++ it("turns off once the last time zone leaves the last day", () => {+ // Nov 2 in UTC, still Nov 1 at UTC-12.+ expect(onAt("2026-11-02T11:00:00Z")).toBe(true);+ // Nov 2 everywhere.+ expect(onAt("2026-11-02T13:00:00Z")).toBe(false);+ });+});++// A day no seasonal theme is on.+const ordinaryDay = new CalendarDate(2026, 3, 15);++describe("resolveTheme on an ordinary day", () => {+ it("is a day with no theme in season", () => {+ for (const theme of seasonal) {+ expect(isInSeason(theme, ordinaryDay)).toBe(false);+ }+ });++ it("returns the stored theme", () => {+ expect(resolveTheme("violet", ordinaryDay).name).toBe("violet");+ expect(storedTheme("violet").name).toBe("violet");+ expect(themeByName("violet").name).toBe("violet");+ expect(isSeasonalTheme("violet")).toBe(false);+ });++ it("falls back to the default for a removed or missing theme", () => {+ expect(resolveTheme("pumpkin-spice", ordinaryDay).name).toBe(+ DEFAULT_THEME_NAME+ );+ expect(resolveTheme(undefined, ordinaryDay).name).toBe(DEFAULT_THEME_NAME);+ expect(resolveTheme(null, ordinaryDay).name).toBe(DEFAULT_THEME_NAME);+ });+});++for (const theme of seasonal) {+ const { from, to } = theme.available;+ const firstDay = new CalendarDate(2026, from.month, from.day);+ const lastDay = new CalendarDate(2026, to.month, to.day);+ const dayAfter = lastDay.add({ days: 1 });++ describe(`seasonal theme "${theme.name}"`, () => {+ it("is in no picker", () => {+ expect(themes.map((t) => t.name)).not.toContain(theme.name);+ expect(themeColorValidator.safeParse({ theme: theme.name }).success).toBe(+ false+ );+ });++ it("replaces every theme for everyone while in season", () => {+ for (const day of [firstDay, lastDay]) {+ expect(resolveTheme("violet", day).name).toBe(theme.name);+ expect(resolveTheme(undefined, day).name).toBe(theme.name);+ }+ });++ it("hands everyone back their own theme after its season", () => {+ expect(resolveTheme("violet", dayAfter).name).toBe("violet");+ expect(resolveTheme(theme.name, dayAfter).name).toBe(DEFAULT_THEME_NAME);+ });++ it("is never a stored pick, but renders by name", () => {+ expect(isSeasonalTheme(theme.name)).toBe(true);+ expect(storedTheme(theme.name).name).toBe(DEFAULT_THEME_NAME);+ expect(themeByName(theme.name).name).toBe(theme.name);+ });+ });+}