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

test: restore libvips concurrency after the sprite suites and read the walk floor from the registry (#6004)

[._.]/ Adam Eivy2244b2130363
diff --git a/server/services/sprites/atlas.test.js b/server/services/sprites/atlas.test.js
index 22ec9e682f..e4a179f2a6 100644
--- a/server/services/sprites/atlas.test.js
+++ b/server/services/sprites/atlas.test.js
@@ -26,16 +26,10 @@ import {
writeWalkFramePng,
} from './spriteTestFixtures.js';
-capSharpThreads();
+const restoreSharpThreads = capSharpThreads();
+afterAll(restoreSharpThreads);
const TEST_ROOT = mkdtempSync(join(tmpdir(), 'sprite-atlas-test-'));
-// The narrowest walk span a compile will accept: the walk track's registry row
-// declares a 6–16 frame range and `resolveTrackUniformity` refuses anything
-// outside it, so 6 is the floor — still enough for varyArm to vary the
-// silhouette and for a mid-strip index to exist. Tests that pin the production
-// 9-column grid keep WALK_PHASES instead (#6004).
-const NARROW_WALK_FRAMES = 6;
-
vi.mock('../../lib/fileUtils.js', async (importOriginal) => {
const actual = await importOriginal();
Object.assign(actual.PATHS, {
@@ -61,7 +55,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, WALK_FPS } = await import('./walkPostprocess.js');
+const {
+ WALK_PHASES, walkPhaseLabels, WALK_FPS, WALK_MIN_FRAME_COUNT,
+} = await import('./walkPostprocess.js');
const { buildAtlasGrid, compiledGridUpToDate } = await import('./atlasGrid.js');
const { getAnimationTrack, SCANNER_TRACK, AMBIENT_TRACK } = await import('./animationTracks.js');
// #3152 — `scanner`/`ambient` are seeded STORE rows, so the compiler's real table
@@ -72,6 +68,14 @@ const {
} = await import('./animationTrackStore.js');
const EFFECTIVE_TRACKS = getEffectiveAnimationTracks();
+// The narrowest walk span a compile will accept: `resolveTrackUniformity`
+// refuses a direction outside the walk track's authoring range, so this tracks
+// the registry's floor rather than restating it — raising the floor adapts these
+// tests instead of breaking a dozen of them. Still wide enough for varyArm to
+// vary the silhouette and for a mid-strip index to exist; tests that pin the
+// production 9-column grid keep WALK_PHASES instead (#6004).
+const NARROW_WALK_FRAMES = WALK_MIN_FRAME_COUNT;
+
let seq = 0;
const newId = () => `atlas-char-${++seq}`;
const sha256 = (buf) => createHash('sha256').update(buf).digest('hex');
@@ -677,13 +681,14 @@ describe('compileAtlas', () => {
repartitioned.atlasSha256 = 'f'.repeat(64);
repartitioned.geometry = {
...repartitioned.geometry,
- // The same columns split differently — idle, a shortened walk, and a
- // scanner span taking the rest — so the spans still tile the grid and only
- // the SEMANTIC drift can be what triggers the recompile below.
+ // The same columns split differently — idle, a walk span one column
+ // short, and a scanner taking the column it gave up — so the spans still
+ // tile the grid at any walk width and only the SEMANTIC drift can be what
+ // triggers the recompile below.
tracks: {
idle: { start: 0, count: 1 },
- walk: { start: 1, count: 3 },
- scanner: { start: 4, count: NARROW_WALK_FRAMES - 3 },
+ walk: { start: 1, count: NARROW_WALK_FRAMES - 1 },
+ scanner: { start: NARROW_WALK_FRAMES, count: 1 },
},
};
await writeFile(pointerAbs, JSON.stringify(repartitioned));
diff --git a/server/services/sprites/spriteTestFixtures.js b/server/services/sprites/spriteTestFixtures.js
index 8dd949f0b1..66bd1c40bc 100644
--- a/server/services/sprites/spriteTestFixtures.js
+++ b/server/services/sprites/spriteTestFixtures.js
@@ -22,18 +22,26 @@ import { SPRITE_DIRECTIONS } from './prompts.js';
/**
* Cap libvips at one thread per call, for a suite whose images are all tiny.
+ * Returns the restore function the caller MUST hand to `afterAll`.
*
* Every sprite fixture and every compiled atlas cell is a 40–192px image, so a
* Sharp call's cost is its per-call overhead, not its pixel count — and the
* thread pool's setup/join IS most of that overhead at this size. CI already
* saturates each runner with several Vitest workers, so the pool only
* oversubscribes the box on top of that; the sprite suites measured markedly
- * less system time with it capped (#6004). Called explicitly by the suites that
- * want it rather than run on import, so importing a fixture never silently
- * reconfigures a worker that later runs an unrelated, image-heavy suite.
+ * less system time with it capped (#6004).
+ *
+ * `sharp.concurrency` reaches past the module graph into libvips itself, so it
+ * is PROCESS state: Vitest resets the module registry between files but reuses
+ * the worker process, and an uncapped setting would otherwise stick to every
+ * later file in that worker — including the imageGen suites that raster
+ * 700–1200px images near their hook timeout. Hence the restore, and hence
+ * calling this from a suite rather than running it on import.
*/
export function capSharpThreads() {
+ const previous = sharp.concurrency();
sharp.concurrency(1);
+ return () => sharp.concurrency(previous);
}
// Sharp PNG encoding is the expensive part; the same raw pixels show up in
diff --git a/server/services/sprites/walk.test.js b/server/services/sprites/walk.test.js
index 6e91f7611d..594ad19484 100644
--- a/server/services/sprites/walk.test.js
+++ b/server/services/sprites/walk.test.js
@@ -17,7 +17,8 @@ import { mkdir, writeFile, readFile, rm } from 'fs/promises';
import { createHash } from 'crypto';
import { capSharpThreads, lockAllAnchors, expectCarriesCorrection } from './spriteTestFixtures.js';
-capSharpThreads();
+const restoreSharpThreads = capSharpThreads();
+afterAll(restoreSharpThreads);
const TEST_ROOT = mkdtempSync(join(tmpdir(), 'sprite-walk-test-'));
vi.mock('../../lib/fileUtils.js', async (importOriginal) => {