Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): null-safe CityXpBadge CTA, shared now clock, badge tests
[._.]/ Adam Eivye0793cb6c107
diff --git a/client/src/components/city/CityXpBadge.jsx b/client/src/components/city/CityXpBadge.jsxindex 0095171093..756533cee8 100644--- a/client/src/components/city/CityXpBadge.jsx+++ b/client/src/components/city/CityXpBadge.jsx@@ -54,9 +54,13 @@ export default function CityXpBadge({ character }) {// the birth-date field lives). The CTA distinguishes a genuinely unset date ("set") from a// present-but-unusable one ("fix" — invalid/future/unreadable), so we never tell the user to// set a date they already entered (#2757).+ // birthDateCta returns null for 'ok' (a real level exists). It's non-null whenever hasBirthDate+ // is false under the server's status⟺level invariant, but read every cta.* through `?.`/`??`+ // anyway so a hypothetical invariant break degrades to the SET prompt instead of crashing the+ // whole HUD — the same defensive gate CharacterSheet and CityHudCompact use (#2757, claude review).const cta = view.hasBirthDate ? null : birthDateCta(view.birthDateStatus);- const levelLabel = view.hasBirthDate ? `LV ${view.level}` : cta.badgeLabel;- const target = view.hasBirthDate ? '/character' : cta.path;+ const levelLabel = view.hasBirthDate ? `LV ${view.level}` : (cta?.badgeLabel ?? 'LV —');+ const target = view.hasBirthDate ? '/character' : (cta?.path ?? '/meatspace/age');// A present-but-unusable date (invalid/future/unreadable) renders in the warning color, matching// the CharacterSheet "fix" prompt and the changelog's promise (#2757). Never true while leveling.const fixState = cta?.kind === 'fix';@@ -66,7 +70,7 @@ export default function CityXpBadge({ character }) {<buttontype="button"onClick={() => navigate(target)}- title={view.hasBirthDate ? 'Open character sheet' : cta.title}+ title={view.hasBirthDate ? 'Open character sheet' : (cta?.title ?? 'Set your birth date')}className={`relative block w-40 sm:w-48 bg-black/85 backdrop-blur-sm border rounded-lg px-3 py-2.5 overflow-hidden text-left transition-all duration-300 hover:bg-cyan-500/10 ${leveling? 'border-amber-400/70 shadow-[0_0_16px_rgba(245,158,11,0.5)]'@@ -124,7 +128,7 @@ export default function CityXpBadge({ character }) {<div className="relative flex items-center justify-between mt-1"><span className="font-pixel text-[8px] text-gray-500 tracking-wider">- {view.hasBirthDate ? `${pct}% TO NEXT` : cta.badgeCaption}+ {view.hasBirthDate ? `${pct}% TO NEXT` : (cta?.badgeCaption ?? 'SET BIRTH DATE')}</span>{view.hp != null && view.maxHp != null && (<spandiff --git a/client/src/components/city/CityXpBadge.test.jsx b/client/src/components/city/CityXpBadge.test.jsxnew file mode 100644index 0000000000..f419b61f3f--- /dev/null+++ b/client/src/components/city/CityXpBadge.test.jsx@@ -0,0 +1,45 @@+import { describe, it, expect } from 'vitest';+import { render, screen } from '@testing-library/react';+import { MemoryRouter } from 'react-router-dom';+import CityXpBadge from './CityXpBadge';++const renderBadge = (character) =>+ render(+ <MemoryRouter initialEntries={['/city']}>+ <CityXpBadge character={character} />+ </MemoryRouter>,+ );++describe('CityXpBadge birth-date CTA (#2757)', () => {+ it('shows the numeric level and % caption when a level exists', () => {+ renderBadge({ level: 7, ageYears: 7.5, birthDateStatus: 'ok' });+ expect(screen.getByText('LV 7')).toBeInTheDocument();+ expect(screen.queryByText('LV —')).not.toBeInTheDocument();+ expect(screen.queryByText('LV !')).not.toBeInTheDocument();+ });++ it('shows the SET prompt (LV —) for a genuinely unset date', () => {+ renderBadge({ level: null, ageYears: null, birthDateStatus: 'unset' });+ expect(screen.getByText('LV —')).toBeInTheDocument();+ expect(screen.getByText('SET BIRTH DATE')).toBeInTheDocument();+ expect(screen.getByTitle('Set your birth date')).toBeInTheDocument();+ });++ it('shows the FIX prompt (LV !) in the warning style for a present-but-unusable date', () => {+ for (const status of ['invalid', 'future', 'unreadable']) {+ const { unmount } = renderBadge({ level: null, ageYears: null, birthDateStatus: status });+ expect(screen.getByText('LV !')).toBeInTheDocument();+ expect(screen.getByText('FIX BIRTH DATE')).toBeInTheDocument();+ // Warning-colored, not the normal cyan accent (changelog promise).+ expect(screen.getByText('LV !').className).toMatch(/text-port-warning/);+ unmount();+ }+ });++ it('degrades to the SET prompt instead of crashing if status is "ok" with no level (invariant break)', () => {+ // birthDateCta('ok') is null; the badge must not throw on cta.badgeLabel — it falls back to+ // the SET prompt (claude review defensive gate). Rendering without throwing is the assertion.+ renderBadge({ level: null, ageYears: null, birthDateStatus: 'ok' });+ expect(screen.getByText('LV —')).toBeInTheDocument();+ });+});diff --git a/server/services/character.js b/server/services/character.jsindex 0dd67cff23..af97f14400 100644--- a/server/services/character.js+++ b/server/services/character.js@@ -207,10 +207,14 @@ async function enrichCharacter(raw, { withSkills = true, withMetrics = true } =withSkills ? getCharacterSkills(read) : Promise.resolve(undefined),withMetrics ? getCharacterMetrics(read) : Promise.resolve(undefined),]);- const ageYears = ageYearsFromBirthDate(birthDate);+ // One shared `now` for both derivations so status and level can't disagree at the future+ // boundary (a birthDate a millisecond apart from two separate `new Date()` clocks) — the+ // invariant CityXpBadge/CityHudCompact rely on (#2757, claude review).+ const now = new Date();+ const ageYears = ageYearsFromBirthDate(birthDate, now);// birthDateStatus (#2757) lets the CTA branch "set" (unset) vs "fix" (invalid/future/unreadable)// instead of conflating every null-level case. Derived + stripped like the other DERIVED_FIELDS.- const birthDateStatus = birthDateStatusFrom(birthDate, readable);+ const birthDateStatus = birthDateStatusFrom(birthDate, readable, now);const enriched = { ...raw, ageYears, level: levelFromAge(ageYears), birthDateStatus };// Drop any stale persisted key when a registry wasn't computed, so a hand-edited// character.json can't pass its own `skills`/`metrics` off as freshly derived.