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): prove the row guard against synthetic rows, not the shipped table
[._.]/ Adam Eivy2e4246413946
diff --git a/server/services/sprites/animationTargets.test.js b/server/services/sprites/animationTargets.test.jsindex e5be7a50eb..85a1ba5011 100644--- a/server/services/sprites/animationTargets.test.js+++ b/server/services/sprites/animationTargets.test.js@@ -110,8 +110,12 @@ describe('resolveAnimationTarget precedence', () => {},}));const { resolveAnimationTarget: resolveWithNullFps } = await import('./animationTargets.js');+ // The literal `null` key is what makes this DISCRIMINATING: without the+ // guard the code would evaluate `runtimeContract[null]`, which coerces to+ // the string key "null" — so a contract carrying that key would resolve+ // fps: 24 / fpsLocked: true. With the guard the rung is skipped entirely.expect(resolveWithNullFps({- runtimeContract: { walkFrameCount: 16, walkFps: 24 },+ runtimeContract: { walkFrameCount: 16, walkFps: 24, null: 24 },})).toMatchObject({ frameCount: 16, fps: 10, source: 'app', fpsLocked: false });vi.doUnmock('./animationTracks.js');vi.resetModules();diff --git a/server/services/sprites/animationTracks.js b/server/services/sprites/animationTracks.jsindex 5c18781a61..df01d7661e 100644--- a/server/services/sprites/animationTracks.js+++ b/server/services/sprites/animationTracks.js@@ -71,50 +71,69 @@ export const ANIMATION_TRACKS = Object.freeze({/** Known track ids, in registry order. */export const ANIMATION_TRACK_IDS = Object.freeze(Object.keys(ANIMATION_TRACKS));-// Fail fast at module load, the way navManifest.js and catalogTypes.js guard-// their registries: a row missing a bound would otherwise boot clean and-// surface much later as `NaN` out of a Math.min, or as `z.number().min(-// undefined)` throwing at the first sprite render. A bad row should block boot-// with a message naming the field, not corrupt a render hours later.-const claimedContractFields = new Map();-for (const id of ANIMATION_TRACK_IDS) {- const row = ANIMATION_TRACKS[id];- if (row.id !== id) throw new Error(`animationTracks: row '${id}' declares mismatched id '${row.id}'`);- if (typeof row.label !== 'string' || !row.label) throw new Error(`animationTracks: track '${id}' needs a label`);- if (typeof row.directional !== 'boolean') throw new Error(`animationTracks: track '${id}' needs a boolean 'directional'`);- for (const field of ['minFrameCount', 'maxFrameCount', 'defaultFrameCount', 'minFps', 'maxFps', 'defaultFps']) {- if (!Number.isInteger(row[field])) throw new Error(`animationTracks: track '${id}' needs an integer '${field}'`);- }- if (typeof row.contractFrameCountField !== 'string' || !row.contractFrameCountField) {- throw new Error(`animationTracks: track '${id}' needs a contractFrameCountField`);- }- if (row.contractFpsField !== null && (typeof row.contractFpsField !== 'string' || !row.contractFpsField)) {- throw new Error(`animationTracks: track '${id}' needs a contractFpsField (or null)`);- }- for (const [min, def, max] of [- ['minFrameCount', 'defaultFrameCount', 'maxFrameCount'],- ['minFps', 'defaultFps', 'maxFps'],- ]) {- if (!(row[min] <= row[def] && row[def] <= row[max])) {- throw new Error(`animationTracks: track '${id}' needs ${min} <= ${def} <= ${max}`);+/**+ * Validate a registry's rows, throwing on the first violation.+ *+ * Called at module load below (the navManifest.js / catalogTypes.js idiom): a+ * row missing a bound would otherwise boot clean and surface much later as+ * `NaN` out of a Math.min, or as `z.number().min(undefined)` throwing at the+ * first sprite render. A bad row should block boot with a message naming the+ * field, not corrupt a render hours later.+ *+ * Exported and pure — taking the table as an argument — so the guard can be+ * proven against a synthetic multi-row fixture. Asserting set-uniqueness over+ * the real (currently single-row) table would only re-derive the+ * implementation: the whole guard could be deleted and such a test would stay+ * green, which is exactly the regression it exists to prevent.+ */+export function assertAnimationTrackRows(tracks) {+ const claimedContractFields = new Map();+ for (const id of Object.keys(tracks)) {+ const row = tracks[id];+ if (row.id !== id) throw new Error(`animationTracks: row '${id}' declares mismatched id '${row.id}'`);+ if (typeof row.label !== 'string' || !row.label) throw new Error(`animationTracks: track '${id}' needs a label`);+ if (typeof row.directional !== 'boolean') throw new Error(`animationTracks: track '${id}' needs a boolean 'directional'`);+ for (const field of ['minFrameCount', 'maxFrameCount', 'defaultFrameCount', 'minFps', 'maxFps', 'defaultFps']) {+ if (!Number.isInteger(row[field])) throw new Error(`animationTracks: track '${id}' needs an integer '${field}'`);}- }- // Two tracks must not claim the same runtimeContract field. The anticipated- // failure is a second row copy-pasted from walk's: `resolveAnimationTarget`- // would then read the WALK's `walkFrameCount` for the scanner and, whenever- // that value happens to land inside the scanner's range, return it with- // `frameCountLocked: true` — silently pinning one track to another's contract- // and throwing a lock error citing a binding that never mentioned it.- for (const field of [row.contractFrameCountField, row.contractFpsField]) {- if (field === null) continue;- const owner = claimedContractFields.get(field);- if (owner) {- throw new Error(`animationTracks: contract field '${field}' is claimed by both '${owner}' and '${id}'`);+ if (typeof row.contractFrameCountField !== 'string' || !row.contractFrameCountField) {+ throw new Error(`animationTracks: track '${id}' needs a contractFrameCountField`);+ }+ if (row.contractFpsField !== null && (typeof row.contractFpsField !== 'string' || !row.contractFpsField)) {+ throw new Error(`animationTracks: track '${id}' needs a contractFpsField (or null)`);+ }+ for (const [min, def, max] of [+ ['minFrameCount', 'defaultFrameCount', 'maxFrameCount'],+ ['minFps', 'defaultFps', 'maxFps'],+ ]) {+ if (!(row[min] <= row[def] && row[def] <= row[max])) {+ throw new Error(`animationTracks: track '${id}' needs ${min} <= ${def} <= ${max}`);+ }+ }+ // Two tracks must not claim the same runtimeContract field. The anticipated+ // failure is a second row copy-pasted from walk's: `resolveAnimationTarget`+ // would then read the WALK's `walkFrameCount` for that track and, whenever+ // that value happens to land inside its range, return it with+ // `frameCountLocked: true` — silently pinning one track to another's+ // contract and throwing a lock error citing a binding that never mentioned+ // it. The knob name rides along so a row that names ONE field for BOTH of+ // its knobs doesn't report as "claimed by both 'walk' and 'walk'".+ for (const knob of ['contractFrameCountField', 'contractFpsField']) {+ const field = row[knob];+ if (field === null) continue;+ const owner = claimedContractFields.get(field);+ if (owner) {+ throw new Error(+ `animationTracks: contract field '${field}' is claimed by both '${owner.id}.${owner.knob}' and '${id}.${knob}'`,+ );+ }+ claimedContractFields.set(field, { id, knob });}- claimedContractFields.set(field, id);}}+assertAnimationTrackRows(ANIMATION_TRACKS);+/** True when `id` names a track this build knows. */export function isAnimationTrack(id) {return typeof id === 'string' && Object.prototype.hasOwnProperty.call(ANIMATION_TRACKS, id);diff --git a/server/services/sprites/animationTracks.test.js b/server/services/sprites/animationTracks.test.jsindex 913f609ff9..382ef331a2 100644--- a/server/services/sprites/animationTracks.test.js+++ b/server/services/sprites/animationTracks.test.js@@ -15,6 +15,7 @@ import { dirname, join } from 'path';import {WALK_TRACK, ANIMATION_TRACKS, ANIMATION_TRACK_IDS,isAnimationTrack, getAnimationTrack, clampTrackFrameCount, clampTrackFps,+ assertAnimationTrackRows,} from './animationTracks.js';import {staticImportSpecifiers, staticImportClosure, specifierMatchesPackage,@@ -72,15 +73,8 @@ describe('the registry rows', () => {}});- it('never lets two tracks claim the same runtimeContract field', () => {- // A second row copy-pasted from walk's would make resolveAnimationTarget- // read the WALK's contract value for that track and report it as locked.- // The module-load guard rejects it; this pins the property as a named case.- const claimed = ANIMATION_TRACK_IDS.flatMap((id) => [- ANIMATION_TRACKS[id].contractFrameCountField,- ANIMATION_TRACKS[id].contractFpsField,- ]).filter((f) => f !== null);- expect(new Set(claimed).size).toBe(claimed.length);+ it('accepts the shipped registry', () => {+ expect(() => assertAnimationTrackRows(ANIMATION_TRACKS)).not.toThrow();});it('is frozen so a caller cannot mutate the shared bounds', () => {@@ -89,6 +83,55 @@ describe('the registry rows', () => {});});+describe('the module-load row guard', () => {+ // Driven against SYNTHETIC rows, not the shipped table. Asserting properties+ // of the (single-row) real registry would only re-derive the implementation:+ // the guard could be deleted outright and such a test would stay green.+ const walk = getAnimationTrack(WALK_TRACK);+ const second = {+ ...walk, id: 'scanner', label: 'Scanner', minFrameCount: 3, defaultFrameCount: 4, maxFrameCount: 8,+ contractFrameCountField: 'scannerFrameCount', contractFpsField: 'scannerFps',+ };+ const twoRows = (overrides = {}) => ({ walk, scanner: { ...second, ...overrides } });++ it('accepts a well-formed second row', () => {+ expect(() => assertAnimationTrackRows(twoRows())).not.toThrow();+ });++ it('rejects a second row that copy-pastes walk\'s contract field', () => {+ // The regression the guard exists for: resolveAnimationTarget would read+ // the WALK's walkFrameCount for the scanner and report it frameCountLocked.+ expect(() => assertAnimationTrackRows(twoRows({ contractFrameCountField: 'walkFrameCount' })))+ .toThrow(/claimed by both 'walk\.contractFrameCountField' and 'scanner\.contractFrameCountField'/);+ });++ it('names both knobs when ONE row claims one field for both of them', () => {+ expect(() => assertAnimationTrackRows({ scanner: { ...second, contractFpsField: 'scannerFrameCount' } }))+ .toThrow(/'scanner\.contractFrameCountField' and 'scanner\.contractFpsField'/);+ });++ it('lets a row opt out of an fps contract field with null', () => {+ expect(() => assertAnimationTrackRows(twoRows({ contractFpsField: null }))).not.toThrow();+ // …and two such rows don't collide on "null".+ expect(() => assertAnimationTrackRows({+ walk: { ...walk, contractFpsField: null }, scanner: { ...second, contractFpsField: null },+ })).not.toThrow();+ });++ it.each([+ ['a mismatched id', { id: 'nope' }, /mismatched id/],+ ['a missing label', { label: '' }, /needs a label/],+ ['a non-boolean directional', { directional: 'yes' }, /boolean 'directional'/],+ ['a non-integer bound', { maxFrameCount: 8.5 }, /integer 'maxFrameCount'/],+ ['a default outside its range', { defaultFrameCount: 99 }, /minFrameCount <= defaultFrameCount <= maxFrameCount/],+ ['a default fps outside its range', { defaultFps: 99 }, /minFps <= defaultFps <= maxFps/],+ ['an empty contract frame-count field', { contractFrameCountField: '' }, /needs a contractFrameCountField/],+ ['an undefined contract fps field', { contractFpsField: undefined }, /contractFpsField \(or null\)/],+ ])('rejects %s', (_label, overrides, message) => {+ expect(() => assertAnimationTrackRows(twoRows(overrides))).toThrow(message);+ });+});+describe('getAnimationTrack — absent vs unrecognized', () => {it('treats an absent id as the default track, preserving pre-#3015 call sites', () => {expect(getAnimationTrack().id).toBe(WALK_TRACK);@@ -239,7 +282,13 @@ describe('client mirror parity', () => {// passes in precisely the scenario it exists for: raise the row's maxFps and// the client's hard-coded 24 still satisfies "≤ max" while the picker// silently stops offering speeds the server now accepts.- const options = clientWalkFpsOptionsFor(walk.defaultFps);+ // Measure the ceiling against the UN-SPLICED base list: the helper splices a+ // non-even current value into its options so the <select> never lies, so+ // seeding it with `defaultFps` would let a row whose default sat near a+ // raised max (maxFps 30, defaultFps 30) satisfy the pin via the spliced-in+ // value while the picker still stopped at the client's hard-coded 24.+ // A non-finite argument short-circuits the splice and returns the base list.+ const options = clientWalkFpsOptionsFor(NaN);expect(options[0]).toBe(walk.minFps);expect(Math.max(...options)).toBeLessThanOrEqual(walk.maxFps);expect(walk.maxFps - Math.max(...options)).toBeLessThan(2);