Skip to content

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

address review (claude): reject duplicate contract-field claims, close two guard holes

[._.]/ Adam Eivy39a4fe85da19
diff --git a/server/services/sprites/animationTargets.test.js b/server/services/sprites/animationTargets.test.js
index 39568775fb..e5be7a50eb 100644
--- a/server/services/sprites/animationTargets.test.js
+++ b/server/services/sprites/animationTargets.test.js
@@ -5,7 +5,7 @@
* walk.test.js; this file pins the rules those depend on.
*/
-import { describe, it, expect } from 'vitest';
+import { describe, it, expect, vi } from 'vitest';
import {
WALK_TRACK, resolveAnimationTarget, withTrackTarget, targetDrift, describeTargetSource,
} from './animationTargets.js';
@@ -92,6 +92,31 @@ describe('resolveAnimationTarget precedence', () => {
})).toMatchObject({ frameCount: 16, fps: 24, source: 'app' });
});
+ it('ignores the contract\'s fps entirely for a track that declares no fps field', async () => {
+ // A registry row may set `contractFpsField: null` — a track whose speed an
+ // app has no say in. The app rung must then fall through to
+ // set/derived/default and report fpsLocked:false rather than reading some
+ // other track's contract key. Only one track exists today, so stand up a
+ // null-fps row via a scoped module mock to keep that branch covered.
+ vi.resetModules();
+ const real = await vi.importActual('./animationTracks.js');
+ const nullFpsRow = { ...real.ANIMATION_TRACKS.walk, contractFpsField: null };
+ vi.doMock('./animationTracks.js', () => ({
+ ...real,
+ ANIMATION_TRACKS: { walk: nullFpsRow },
+ getAnimationTrack: (id) => {
+ if (id === undefined || id === null || id === real.WALK_TRACK) return nullFpsRow;
+ throw new Error(`Unknown animation track '${String(id)}'`);
+ },
+ }));
+ const { resolveAnimationTarget: resolveWithNullFps } = await import('./animationTargets.js');
+ expect(resolveWithNullFps({
+ runtimeContract: { walkFrameCount: 16, walkFps: 24 },
+ })).toMatchObject({ frameCount: 16, fps: 10, source: 'app', fpsLocked: false });
+ vi.doUnmock('./animationTracks.js');
+ vi.resetModules();
+ });
+
it('rejects an unrecognized track instead of resolving it against walk\'s range', () => {
// Sentinel discipline: absent ⇒ the default track; unrecognized ⇒ an error
// naming the known tracks, never a silent fall-through to 6–16 / 4–24.
diff --git a/server/services/sprites/animationTracks.js b/server/services/sprites/animationTracks.js
index bed5403b93..5c18781a61 100644
--- a/server/services/sprites/animationTracks.js
+++ b/server/services/sprites/animationTracks.js
@@ -76,6 +76,7 @@ export const ANIMATION_TRACK_IDS = Object.freeze(Object.keys(ANIMATION_TRACKS));
// 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}'`);
@@ -98,6 +99,20 @@ for (const id of ANIMATION_TRACK_IDS) {
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 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}'`);
+ }
+ claimedContractFields.set(field, id);
+ }
}
/** True when `id` names a track this build knows. */
diff --git a/server/services/sprites/animationTracks.test.js b/server/services/sprites/animationTracks.test.js
index e39eb4e090..913f609ff9 100644
--- a/server/services/sprites/animationTracks.test.js
+++ b/server/services/sprites/animationTracks.test.js
@@ -56,7 +56,10 @@ describe('the registry rows', () => {
expect(typeof row.label).toBe('string');
expect(typeof row.directional).toBe('boolean');
expect(typeof row.contractFrameCountField).toBe('string');
- expect(typeof row.contractFpsField).toBe('string');
+ // `null` is legal here — a track whose speed an app has no say in — so
+ // this must stay as permissive as the module-load guard, or the first row
+ // that uses the null form goes red while booting perfectly fine.
+ expect(row.contractFpsField === null || typeof row.contractFpsField === 'string').toBe(true);
for (const field of ['minFrameCount', 'maxFrameCount', 'defaultFrameCount', 'minFps', 'maxFps', 'defaultFps']) {
expect(Number.isInteger(row[field]), `${id}.${field} must be an integer`).toBe(true);
}
@@ -69,6 +72,17 @@ 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('is frozen so a caller cannot mutate the shared bounds', () => {
expect(() => { ANIMATION_TRACKS.walk.minFrameCount = 1; }).toThrow();
expect(ANIMATION_TRACKS.walk.minFrameCount).toBe(6);
@@ -219,11 +233,16 @@ describe('client mirror parity', () => {
});
it('seeds the fps picker within the walk row\'s range', () => {
- // The list is even-stepped, so it need not END on the max — but it must
- // start at the floor and never offer a value the server would reject.
+ // The list is even-stepped, so it need not END exactly on the max — but it
+ // must start at the floor, never offer a value the server would reject, AND
+ // stay within one step of the ceiling. Without that upper pin the guard
+ // 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);
expect(options[0]).toBe(walk.minFps);
expect(Math.max(...options)).toBeLessThanOrEqual(walk.maxFps);
+ expect(walk.maxFps - Math.max(...options)).toBeLessThan(2);
});
it('keeps the publish form\'s hard-coded frame-count bounds in step', () => {