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): close the multi-track walkFrameCount lie and three inert-test gaps

[._.]/ Adam Eivy2e0b132a5e56
diff --git a/server/services/sprites/animationTracks.test.js b/server/services/sprites/animationTracks.test.js
index 382ef331a2..2c75123e71 100644
--- a/server/services/sprites/animationTracks.test.js
+++ b/server/services/sprites/animationTracks.test.js
@@ -228,6 +228,12 @@ describe('sharp-free leaf property', () => {
['animationTracks.js', join(SPRITES_DIR, 'animationTracks.js')],
['walkBounds.js', join(SPRITES_DIR, 'walkBounds.js')],
['animationTargets.js', join(SPRITES_DIR, 'animationTargets.js')],
+ // #3016: the atlas grid is the ONE definition of a column span, shared by
+ // the compiler (which imports sharp) and the layout sidecar (which must
+ // not). If either of these two ever reaches sharp, that split has silently
+ // collapsed and the sidecar builder drags the native image graph along.
+ ['atlasGrid.js', join(SPRITES_DIR, 'atlasGrid.js')],
+ ['atlasLayout.js', join(SPRITES_DIR, 'atlasLayout.js')],
])('%s reaches no native image/video dependency', (_label, entry) => {
const { packages } = staticImportClosure(entry);
const offending = [...packages].filter((p) => NATIVE.some((n) => specifierMatchesPackage(p, n)));
diff --git a/server/services/sprites/atlas.test.js b/server/services/sprites/atlas.test.js
index cb2b1618e8..8808ffbe47 100644
--- a/server/services/sprites/atlas.test.js
+++ b/server/services/sprites/atlas.test.js
@@ -43,7 +43,9 @@ const records = await import('./records.js');
const { lockReference, loadManifest } = await import('./reference.js');
const { compileAtlas, getAtlasState, ATLAS_COLUMNS, DEFAULT_ATLAS_GEOMETRY } = await import('./atlas.js');
const { SPRITE_DIRECTIONS } = await import('./prompts.js');
-const { WALK_PHASES, walkPhaseLabels } = await import('./walkPostprocess.js');
+const { WALK_PHASES, walkPhaseLabels, WALK_FPS } = await import('./walkPostprocess.js');
+const { buildAtlasGrid, compiledGridUpToDate } = await import('./atlasGrid.js');
+const { getAnimationTrack } = await import('./animationTracks.js');
let seq = 0;
const newId = () => `atlas-char-${++seq}`;
@@ -302,11 +304,30 @@ describe('compileAtlas', () => {
delete pointer.geometry.tracks;
await writeFile(pointerAbs, JSON.stringify(pointer));
+ // Assert the PRE-PIXEL predicate against the real on-disk geometry, not just
+ // the compile's return value: `created: false` also holds via the
+ // post-encode sha compare, so a test that only checked that would pass even
+ // with the legacy fallback deleted — i.e. while the pixel pipeline ran in
+ // full on every compile, which is the exact regression this guards.
+ const grid = buildAtlasGrid([{ id: 'walk', frameCount: WALK_PHASES.length }]);
+ expect(compiledGridUpToDate(pointer.geometry, { ...DEFAULT_ATLAS_GEOMETRY, ...grid })).toBe(true);
+
const again = await compileAtlas(id);
expect(again.created).toBe(false);
expect(again.version).toBe(first.version);
});
+ it('compiles a pre-fps run manifest at the legacy extraction rate, not the track default', async () => {
+ // Older run manifests carry no `frameRate` at all. The fallback must stay
+ // the rate their frames were extracted at (12), NOT the walk track's
+ // authoring default (10) — otherwise upgrading silently re-stamps every
+ // newly-compiled legacy set's geometry and its published previewFps.
+ const id = await finalizedCharacter();
+ const result = await compileAtlas(id);
+ expect(result.geometry.walkFps).toBe(WALK_FPS);
+ expect(WALK_FPS).not.toBe(getAnimationTrack('walk').defaultFps);
+ });
+
it('refuses to compile a set whose directions disagree on frame count', async () => {
const id = newId();
await lockAllAnchors(id);
diff --git a/server/services/sprites/atlasGrid.js b/server/services/sprites/atlasGrid.js
index 5b7b2fae9c..a73dceb679 100644
--- a/server/services/sprites/atlasGrid.js
+++ b/server/services/sprites/atlasGrid.js
@@ -134,10 +134,27 @@ const walkColumnsOf = (columns) =>
/**
* Walk frame count for a compiled atlas. Pointers written before #2970 have no
- * `walkFrameCount`, so fall back to counting the walk columns themselves.
+ * `walkFrameCount`, so fall back to the track descriptor and, failing that, to
+ * counting the walk columns themselves.
+ *
+ * The descriptor is consulted BEFORE the column count because "every non-anchor
+ * column is a walk frame" is only true of the single-track world this module
+ * ends: for a grid it can now build — `{ idle:{0,1}, walk:{1,12}, scanner:{13,4} }`
+ * — counting columns would report 16 walk frames. That matters as soon as a
+ * second track is registered (#3018), because a character carrying only that
+ * track would stamp `walkFrameCount: null` and the column heuristic would then
+ * publish a fabricated walk length in the sidecar and compare an app's runtime
+ * contract against it.
*/
export function resolveWalkFrameCount(geometry) {
if (Number.isInteger(geometry?.walkFrameCount)) return geometry.walkFrameCount;
+ // A PRESENT descriptor is authoritative and terminal: if it names no walk
+ // track, the answer is "none", not whatever the column heuristic would
+ // invent. Only an ABSENT one falls through to counting columns.
+ if (geometry?.tracks && typeof geometry.tracks === 'object' && !Array.isArray(geometry.tracks)) {
+ const span = geometry.tracks[WALK_TRACK];
+ return Number.isInteger(span?.count) ? span.count : null;
+ }
if (!Array.isArray(geometry?.columns)) return null;
return walkColumnsOf(geometry.columns).length;
}
@@ -293,7 +310,8 @@ export function compiledGridUpToDate(current, expected) {
* injectable so this leaf stays free of the error-handler import — callers pass
* the 422-shaped `compileError`. `defaultFps` covers a track whose historical
* manifests predate the fps field and must keep resolving to the exact value
- * they always did. Returns `{ id, frameCount, fps, labels }`.
+ * they always did. Returns `{ id, frameCount, fps }` — deliberately NOT the
+ * column labels, which `buildAtlasGrid` derives itself so the two can't disagree.
*/
export function resolveTrackUniformity(trackId, rows, {
tracks = ANIMATION_TRACKS,
@@ -333,5 +351,5 @@ export function resolveTrackUniformity(trackId, rows, {
throw error(`Direction ${direction} plays at ${rowFps} fps but the set uses ${fps} — reprocess all directions to the same speed before compiling`);
}
}
- return { id: trackId, frameCount, fps, labels: trackColumnLabels(trackId, frameCount) };
+ return { id: trackId, frameCount, fps };
}
diff --git a/server/services/sprites/atlasGrid.test.js b/server/services/sprites/atlasGrid.test.js
index 227453cfb2..ea2ab90cf3 100644
--- a/server/services/sprites/atlasGrid.test.js
+++ b/server/services/sprites/atlasGrid.test.js
@@ -179,6 +179,25 @@ describe('deriveTracks', () => {
.toThrow(/must be an object of column spans/);
});
+ it('spans the walk by position, so positional frame-NN labels group too', () => {
+ // A grid whose columns are `frame-00…` rather than the named gait phases
+ // must still describe ONE walk track, not ten singletons.
+ expect(deriveTracks(['idle', ...walkPhaseLabels(10)], 10).walk).toEqual({ start: 1, count: 10 });
+ // …and a pre-#2986 grid still describes its scanner placeholder honestly
+ // rather than folding it into the walk span.
+ expect(deriveTracks(['idle', ...walkPhaseLabels(6), 'scanner'], 6)).toEqual({
+ idle: { start: 0, count: 1 },
+ walk: { start: 1, count: 6 },
+ scanner: { start: 7, count: 1 },
+ });
+ // Any repeated non-walk column groups into its own span too.
+ expect(deriveTracks(['idle', 'w0', 'w1', 'scan-a', 'scan-a', 'scan-a'], 2)).toEqual({
+ idle: { start: 0, count: 1 },
+ walk: { start: 1, count: 2 },
+ 'scan-a': { start: 3, count: 3 },
+ });
+ });
+
it('reports an undescribable grid rather than lying about it', () => {
expect(() => deriveTracks(['idle', 'scanner', 'idle'], 0)).toThrow(/non-contiguously/);
expect(() => deriveTracks([], 0)).toThrow(/no column list/);
@@ -253,9 +272,8 @@ describe('compiledGridUpToDate', () => {
describe('resolveTrackUniformity', () => {
it('resolves a track from its per-direction rows', () => {
- expect(resolveTrackUniformity('walk', rowsFor(12, 10))).toEqual({
- id: 'walk', frameCount: 12, fps: 10, labels: walkPhaseLabels(12),
- });
+ // Labels are NOT returned — buildAtlasGrid derives them, so the two can't disagree.
+ expect(resolveTrackUniformity('walk', rowsFor(12, 10))).toEqual({ id: 'walk', frameCount: 12, fps: 10 });
});
it('enforces uniformity WITHIN a track', () => {
@@ -279,7 +297,6 @@ describe('resolveTrackUniformity', () => {
expect(walk.frameCount).toBe(12);
expect(scanner.frameCount).toBe(4);
expect(scanner.fps).toBe(6);
- expect(scanner.labels).toEqual(['scanner-00', 'scanner-01', 'scanner-02', 'scanner-03']);
// 4 frames would be rejected outright by the walk row it used to share.
expect(getAnimationTrack('walk').minFrameCount).toBeGreaterThan(scanner.frameCount);
expect(() => resolveTrackUniformity('walk', rowsFor(4, 6)))
@@ -315,10 +332,30 @@ describe('resolveTrackUniformity', () => {
});
describe('resolveWalkFrameCount', () => {
- it('prefers the declared count and falls back to counting non-anchor columns', () => {
+ it('prefers the declared count, then the descriptor, then the column count', () => {
expect(resolveWalkFrameCount({ walkFrameCount: 12 })).toBe(12);
+ // Pre-#2970 pointers carry no walkFrameCount…
expect(resolveWalkFrameCount({ columns: ['idle', 'a', 'b'] })).toBe(2);
+ // …and a pre-#2986 one is counted without its scanner placeholder.
expect(resolveWalkFrameCount({ columns: ['idle', 'a', 'b', 'scanner'] })).toBe(2);
expect(resolveWalkFrameCount({})).toBeNull();
});
+
+ it('reads a multi-track grid off the descriptor instead of counting columns', () => {
+ // "Every non-anchor column is a walk frame" is only true of a one-track
+ // grid. Once a second track exists, a character carrying only that track
+ // stamps no walkFrameCount, and counting columns would publish a fabricated
+ // walk length in the sidecar for an app's runtime contract to be checked
+ // against.
+ const grid = buildAtlasGrid(
+ [{ id: 'walk', frameCount: 12 }, { id: 'scanner', frameCount: 4 }],
+ TWO_TRACK_REGISTRY,
+ );
+ expect(resolveWalkFrameCount({ columns: grid.columns })).toBe(16);
+ expect(resolveWalkFrameCount({ columns: grid.columns, tracks: grid.tracks })).toBe(12);
+ // A grid with no walk track at all reports nothing rather than inventing one.
+ const scannerOnly = buildAtlasGrid([{ id: 'scanner', frameCount: 4 }], TWO_TRACK_REGISTRY);
+ expect(resolveWalkFrameCount({ columns: scannerOnly.columns, tracks: scannerOnly.tracks }))
+ .toBeNull();
+ });
});
diff --git a/server/services/sprites/atlasLayout.test.js b/server/services/sprites/atlasLayout.test.js
index f73e5678d8..c55c690a7e 100644
--- a/server/services/sprites/atlasLayout.test.js
+++ b/server/services/sprites/atlasLayout.test.js
@@ -8,10 +8,10 @@ import {
buildAtlasLayout, layoutSidecarPath, runtimeContractMismatch, ATLAS_LAYOUT_SCHEMA_VERSION,
} from './atlasLayout.js';
import { walkPhaseLabels } from './walkBounds.js';
-// The span math moved to atlasGrid.js (#3016) — one public path, no re-export
-// shim. The cases below exercise it through SIDECAR-shaped geometry fixtures;
-// atlasGrid.test.js owns the module's own unit coverage.
-import { buildAtlasGrid, deriveTracks, resolveWalkFrameCount } from './atlasGrid.js';
+// The span math moved to atlasGrid.js (#3016) and is unit-tested there. This
+// file asserts it only THROUGH `buildAtlasLayout`, i.e. as the sidecar a
+// consumer actually reads.
+import { buildAtlasGrid } from './atlasGrid.js';
import { ANIMATION_TRACKS } from './animationTracks.js';
const DIRECTIONS = ['S', 'SE', 'E', 'NE', 'N', 'NW', 'W', 'SW'];
@@ -42,55 +42,6 @@ describe('layoutSidecarPath', () => {
});
});
-describe('resolveWalkFrameCount', () => {
- it('prefers the declared count and falls back to counting non-anchor columns', () => {
- expect(resolveWalkFrameCount(geometryFor(12))).toBe(12);
- expect(resolveWalkFrameCount(legacyGeometryFor(12))).toBe(12);
- // Pre-#2970 pointers carry no walkFrameCount.
- expect(resolveWalkFrameCount({ columns: ['idle', 'a', 'b'] })).toBe(2);
- // …and a pre-#2986 one is counted without its scanner placeholder.
- expect(resolveWalkFrameCount({ columns: ['idle', 'a', 'b', 'c', 'scanner'] })).toBe(3);
- expect(resolveWalkFrameCount({})).toBeNull();
- });
-});
-
-describe('deriveTracks', () => {
- it('collapses the walk columns into one span and gives every other column its own', () => {
- // The compiled grid is idle + walk only (#2986) — no third track.
- expect(deriveTracks(['idle', ...walkPhaseLabels(6)], 6)).toEqual({
- idle: { start: 0, count: 1 },
- walk: { start: 1, count: 6 },
- });
- // A pre-#2986 grid still describes its scanner placeholder honestly rather
- // than folding it into the walk span.
- expect(deriveTracks(['idle', ...walkPhaseLabels(6), 'scanner'], 6)).toEqual({
- idle: { start: 0, count: 1 },
- walk: { start: 1, count: 6 },
- scanner: { start: 7, count: 1 },
- });
- });
-
- it('spans the walk by position, so positional frame-NN labels group too', () => {
- // A grid whose columns are `frame-00…` rather than the named gait phases
- // must still describe ONE walk track, not ten singletons.
- const columns = ['idle', ...walkPhaseLabels(10)];
- expect(deriveTracks(columns, 10).walk).toEqual({ start: 1, count: 10 });
- });
-
- it('describes a future multi-frame track as a span', () => {
- const columns = ['idle', 'w0', 'w1', 'scan-a', 'scan-a', 'scan-a'];
- expect(deriveTracks(columns, 2)).toEqual({
- idle: { start: 0, count: 1 },
- walk: { start: 1, count: 2 },
- 'scan-a': { start: 3, count: 3 },
- });
- });
-
- it('refuses a grid whose track columns are not contiguous', () => {
- expect(() => deriveTracks(['idle', 'scanner', 'idle'], 0)).toThrow(/non-contiguously/);
- });
-});
-
describe('buildAtlasLayout', () => {
it('describes the compiled grid, marking previewFps as authoring-only', () => {
const layout = buildAtlasLayout({