Full read-only audit of all 13 mini-apps against README's problem-mapping table + each module's own doc comments. 6 COHERENT (lightclock, fairdraw, healthpost, theclimb, sky, mentor), 7 GAP-FOUND and fixed in prior commits (fairshare, waterwatch, tunnelsafety, housing, assembly, findfamily, farms).
10 KiB
Sky mini-app coherence audit (ambient clock-schedule + presence counter)
Scope: src/lib/sky.ts, src/lib/skyPresence.ts, src/miniapps/sky/useSkyPresence.ts,
src/miniapps/sky/SkyScreen.tsx. Memory wall / morale-pulse sync coherence is out of
scope (already fixed and verified this session) - this audit covers only the ambient
clock-schedule and the presence counter.
1. Is the ambient clock-schedule a genuine, coherent simulated clock?
Yes. computeSkyState(clock, schedule) in src/lib/sky.ts:163-179 is a pure function:
export function computeSkyState(
clock: Clock,
schedule: readonly SkyScheduleSegment[] = DEFAULT_SKY_SCHEDULE,
): SkyState {
const timestamp = clock.now();
if (!isValidTimestamp(timestamp)) return { ...FALLBACK_SKY_STATE, timestamp };
const cycleHour = computeCycleHour(timestamp);
const { segment, progress } = resolveSegment(schedule, cycleHour);
return { phase: segment.phase, brightness: segment.brightness, skyColor: segment.skyColor,
horizonColor: segment.horizonColor, cycleHour, progress, timestamp };
}
- Cycle length is an explicit, named constant:
HOURS_PER_CYCLE = 24(sky.ts:63), withMS_PER_HOUR = 3_600_000(sky.ts:61) - a stated, documented 24-hour UTC cycle ("A Hollow 'day' is a plain 24-hour UTC cycle",sky.ts:62). computeCycleHour(timestampMs)(sky.ts:98-102) maps epoch ms to[0, 24)via((timestampMs % msPerCycle) + msPerCycle) % msPerCycle, i.e. deterministic modular arithmetic on real elapsed time - not a random/visual effect.resolveSegment(sky.ts:113-141) walks the fiveDEFAULT_SKY_SCHEDULEsegments (night/dawn/day/dusk/night,sky.ts:67-73) sorted bystartHour, and computesprogressthrough the active segment aselapsedHours / segmentLengthHours, so phase transitions and in-between brightness interpolation points are both genuine functions of elapsed wall-clock time, not arbitrary.- Determinism is independently verified by
src/lib/sky.test.ts: two independentFixedClockinstances at the same timestamp producetoEqualoutput ("produces identical output from two independent clock instances at the same timestamp"), and every declared schedule segment'sstartHouris checked to resolve to its own declared phase/brightness ("is consistent across the whole default schedule's declared phases"). - Invalid timestamps (NaN/Infinity/negative) return a defined
FALLBACK_SKY_STATE(sky.ts:88-96,isValidTimestampatsky.ts:98-100) rather than fabricating a phase - also test-verified ("never fabricates a schedule-derived phase for an invalid timestamp").
Verdict: genuine, coherent 24-hour deterministic clock. No gap.
2. Is the presence counter driven by a real WebRTC/Yjs Awareness roster, or fabricated?
Real roster, never fabricated. Chain of evidence:
useSkyPresence.ts:144-172(useSkyPresence): in production (no injected testawareness), whenhasRealtimeTransport()is true (typeof RTCPeerConnection !== "undefined",useSkyPresence.ts:23-25) it callsconnectAssemblySync(createAssemblyDoc(), room)and usessync.provider.awareness- the same real WebRTC-backed Yjs awareness provider Assembly already uses (src/lib/assemblySync.ts), not a bespoke/fake channel.checkIn(awareness, handle)announces this device's own ephemeral per-session handle (skyPresence.ts:99-108,generateEphemeralHandleatskyPresence.ts:62-67) - never the real account id, so the roster can't leak a stable identity, but it also can't be spoofed to multiply the count artificially.presenceCount(awareness)(skyPresence.ts:134-139) isawareness.getStates().size- a direct read of the number of distinct connected YjsAwarenessclient entries. No arithmetic, random number, or placeholder is involved anywhere in this path.- Cohort scoping (
presenceRoomForCohort,skyPresence.ts:38-44; cohort code caching,useSkyPresence.ts:49-66) means two devices only ever share a room (and therefore a count) if they deliberately share a cohort code - ruling out a single global room that would count unrelated strangers. - Test environments are explicitly walled off from the real network:
hasRealtimeTransport()returns false under vitest/happy-dom (noRTCPeerConnection), in which case the hook falls back to a local, no-transportAwareness(new Y.Doc())(useSkyPresence.ts:160-163)- so automated tests exercise the real counting logic against a real (if offline)
Awarenessinstance, never a mocked/fabricated number.useSkyPresence.test.tsxandskyPresence.test.ts(not re-read line-by-line here, but referenced by the module's own docstrings) back this with assertions that a solo session counts to exactly 1, never 0 or a placeholder, until checkout.
- so automated tests exercise the real counting logic against a real (if offline)
-
- The initial React state (`useState(() => injectedAwareness ? presenceCount(injectedAwareness)
- 1)
,useSkyPresence.ts:136-137) is the honest pre-connection default of "just me" (1), not an invented number - and is immediately replaced by the real roster-derived count viasubscribePresenceCount` once the awareness connection exists.
Verdict: the presence count can only ever reflect genuinely-connected peers via a real Yjs Awareness roster riding real WebRTC in production. No fabrication found. No gap.
3. Is SystemClock (real wall-clock) cleanly separated from an injectable test clock?
Yes, cleanly separated via a shared Clock interface.
Clockinterface (sky.ts:17-20):{ now(): number }.SystemClock(sky.ts:36-40):now() { return Date.now(); }- the only production implementation, used unconditionally unless an explicit override is supplied.FixedClock(sky.ts:26-34): constructor-pinned timestamp, used only bysky.test.tsand bycomputeSkyStateAt(timestampMs, schedule)(sky.ts:184-189), a convenience wrapper explicitly documented as wrapping aFixedClockfor one-shot timestamp-to-state conversion (also test-only call sites).- Production wiring in
SkyScreen.tsx:51:const activeClock = useMemo(() => clock ?? new SystemClock(), [clock])- theclockprop exists purely as a test seam (SkyScreenProps.clock?: Clock,SkyScreen.tsx:44); when omitted (the real app's route render, with no caller ever passing a clock),SystemClockis instantiated and used. There is no code path in which production can silently receive aFixedClock- that would require a caller explicitly constructing and threading one in, whichAppRoutes.tsx/miniappComponents.tsxdo not do.
Verdict: clean separation. Production always gets real time; only sky.test.ts and
SkyScreen.test.tsx (via the clock prop) ever supply a FixedClock. No gap.
4. Any real device-API angle beyond what's already used (and is restraint appropriate)?
Checked for an obvious candidate: a real ambient-light sensor or ambient ("devicelight") API would in principle let "brightness" reflect the user's actual surroundings instead of a simulated schedule. In practice:
- The
AmbientLightSensor/devicelightWeb APIs are not implemented in any shipping browser engine today (Chromium shippedAmbientLightSensorbehind a flag and later removed it; Firefox/Safari never shipped it) - wiring to it would be dead code in every real browser this PWA targets, which is exactly the "claimed-but-unwired" anti-pattern this audit is hunting for, not a fix for it. - The feature is explicitly framed, in both the README and the module's own doc-comment ("a culture/morale mini-app, not a utility" / "ambient sky-view engine"), as a shared, synchronized atmospheric backdrop - its entire value is that every device, anywhere, computes the same phase from the same UTC instant (verified above in Q1/Q3). A real per-device light sensor would break that invariant (two devices in different rooms would show different brightness for the same "sky"), directly contradicting the stated concept.
- Geolocation-based real sunrise/sunset (vs. the stylized fixed 24h schedule) was also considered: also rejected as scope-inflation - the module's docstring already commits to "a stylized day/night cycle," and real geolocation would require a permission prompt and per-device divergence inappropriate for a shared ambient view.
Verdict: restraint is appropriate. No real device API is mischaracterized as used, and none should be added without contradicting the feature's own "shared ambient backdrop, not a utility" framing. No gap.
5. Any claimed-but-unwired UI/feature?
Checked SkyScreen.tsx end to end against sky.ts/skyMemoryWall.ts/skyMorale.ts/
useSkyPresence.ts:
- Phase label + brightness (
data-testid="sky-phase"/"sky-brightness") read directly fromskyState.phase/skyState.brightness, refreshed everytickIntervalMs(default 30s,SkyScreen.tsx:22) viasetInterval(() => setSkyState(computeSkyState(activeClock)), tickIntervalMs)- wired, not static. - Presence badge (
data-testid="sky-presence-count") readsuseSkyPresence(...)'s live return value - wired (Q2 above). - Memory wall form/list and morale pulse form/counts all call real
postMemoryWallEntry/postMoralePulse/extractMemoryWallEntries/extractMoralePulses/aggregateMoraleCountsand render their real return values - all wired (and already fixed/verified for sync coherence this session, per the task's own note). trySyncWithBackend()fire-and-forget on mount (SkyScreen.tsx:72-75) matches its documented best-effort, non-blocking, throw-free contract insrc/lib/sync.ts.
Verdict: no claimed-but-unwired feature found in the clock-schedule/presence surface.
Overall verdict
COHERENT. The ambient clock-schedule is a genuine, deterministic, cycle-length-named
(HOURS_PER_CYCLE = 24) pure function of elapsed UTC time (computeSkyState /
computeCycleHour / resolveSegment in src/lib/sky.ts), verified by schedule-consistency
and cross-instance-determinism tests. The presence counter is a direct read of a real Yjs
Awareness.getStates().size roster riding a real WebRTC transport in production
(useSkyPresence.ts + skyPresence.ts), cohort-scoped, test-isolated via a
RTCPeerConnection feature check, and never fabricates a count. SystemClock vs.
FixedClock are cleanly separated behind a shared Clock interface with production
defaulting to SystemClock unconditionally. No further device-API wiring is warranted given
the feature's own "shared ambient backdrop, not a utility" framing. No claimed-but-unwired
UI was found. No gap to fix.