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
test([issue-2918]): extract shared sprite candidate/lock fixtures
[._.]/ Adam Eivyf44c86aab737
diff --git a/server/services/sprites/atlas.test.js b/server/services/sprites/atlas.test.jsindex fea6bc711f..247ac1b688 100644--- a/server/services/sprites/atlas.test.js+++ b/server/services/sprites/atlas.test.js@@ -14,6 +14,7 @@ import { join } from 'path';import sharp from 'sharp';import { mkdir, writeFile, readFile } from 'fs/promises';import { createHash } from 'crypto';+import { lockAllAnchors as lockAllAnchorsFixture } from './spriteTestFixtures.js';const TEST_ROOT = mkdtempSync(join(tmpdir(), 'sprite-atlas-test-'));@@ -48,30 +49,9 @@ let seq = 0;const newId = () => `atlas-char-${++seq}`;const sha256 = (buf) => createHash('sha256').update(buf).digest('hex');-async function writeCandidatePng(path) {- const w = 64; const h = 64;- const buf = Buffer.alloc(w * h * 3);- for (let p = 0; p < w * h; p++) buf.set([255, 0, 255], p * 3);- for (let y = 10; y < 40; y++) for (let x = 22; x < 32; x++) buf.set([23, 107, 101], (y * w + x) * 3);- await mkdir(join(path, '..'), { recursive: true });- await sharp(buf, { raw: { width: w, height: h, channels: 3 } }).png().toFile(path);-}--async function placeCandidate(recordId, target, name) {- const candDir = join(TEST_ROOT, 'sprites', recordId, 'reference', 'candidates');- await writeCandidatePng(join(candDir, name));- await writeFile(join(candDir, `${name.replace(/\.png$/, '')}.generation.json`), JSON.stringify({- schemaVersion: 1, target, chromaKey: '#FF00FF',- }));- return `reference/candidates/${name}`;-}-async function lockAllAnchors(id) {await records.createRecord({ kind: 'character', name: 'Atlas Walker' }, id);- await lockReference(id, { target: 'main', candidate: await placeCandidate(id, 'main', 'walk-south-candidate-01.png') });- for (const dir of SPRITE_DIRECTIONS.filter((d) => d !== 'south')) {- await lockReference(id, { target: dir, candidate: await placeCandidate(id, dir, `walk-${dir}-candidate-01.png`) });- }+ await lockAllAnchorsFixture(TEST_ROOT, id, { lockReference, directions: SPRITE_DIRECTIONS });}/** Transparent 40×40 RGBA frame with an opaque 20×30 figure. */diff --git a/server/services/sprites/reference.test.js b/server/services/sprites/reference.test.jsindex 599a33e778..39b039a577 100644--- a/server/services/sprites/reference.test.js+++ b/server/services/sprites/reference.test.js@@ -12,6 +12,7 @@ import { tmpdir } from 'os';import { join } from 'path';import sharp from 'sharp';import { mkdir, writeFile, readFile } from 'fs/promises';+import { writeCandidatePng, placeCandidate as placeCandidateFixture } from './spriteTestFixtures.js';const TEST_ROOT = mkdtempSync(join(tmpdir(), 'sprite-reference-test-'));@@ -61,32 +62,7 @@ async function createCharacter(id, input = {}) {return records.createRecord({ kind: 'character', name: 'Hero', ...input }, id);}-// A green character rectangle on a magenta background — the legacy Pioneer-// shape, so auto-selection should keep magenta.-async function writeCandidatePng(path, { bg = { r: 255, g: 0, b: 255 }, fg = { r: 23, g: 107, b: 101 } } = {}) {- const w = 64; const h = 64;- const buf = Buffer.alloc(w * h * 3);- for (let y = 0; y < h; y++) {- for (let x = 0; x < w; x++) {- const inRect = x >= 20 && x < 30 && y >= 10 && y < 40;- const c = inRect ? fg : bg;- const i = (y * w + x) * 3;- buf[i] = c.r; buf[i + 1] = c.g; buf[i + 2] = c.b;- }- }- await mkdir(join(path, '..'), { recursive: true });- await sharp(buf, { raw: { width: w, height: h, channels: 3 } }).png().toFile(path);-}--async function placeCandidate(recordId, target, name, opts = {}) {- const candDir = join(TEST_ROOT, 'sprites', recordId, 'reference', 'candidates');- await mkdir(candDir, { recursive: true });- await writeCandidatePng(join(candDir, name), opts);- await writeFile(join(candDir, `${name.replace(/\.png$/, '')}.generation.json`), JSON.stringify({- schemaVersion: 1, target, chromaKey: opts.sidecarKey ?? '#FF00FF',- }));- return `reference/candidates/${name}`;-}+const placeCandidate = (recordId, target, name, opts) => placeCandidateFixture(TEST_ROOT, recordId, target, name, opts);async function lockMain(recordId) {const rel = await placeCandidate(recordId, 'main', 'walk-south-candidate-01.png');diff --git a/server/services/sprites/spriteTestFixtures.js b/server/services/sprites/spriteTestFixtures.jsnew file mode 100644index 0000000000..8fa0ac4125--- /dev/null+++ b/server/services/sprites/spriteTestFixtures.js@@ -0,0 +1,56 @@+/**+ * Shared reference-candidate fixture helpers for the sprite test suites+ * (reference.test.js, walk.test.js, atlas.test.js). Each export is+ * parameterized on the calling suite's TEST_ROOT rather than closing over a+ * module-level constant, so every suite keeps its own tmpdir and isolation.+ */+import { join } from 'path';+import sharp from 'sharp';+import { mkdir, writeFile } from 'fs/promises';++// A green/teal character rectangle on a magenta background — the legacy+// Pioneer shape, so auto chroma-key selection keeps magenta.+export async function writeCandidatePng(path, {+ bg = { r: 255, g: 0, b: 255 },+ fg = { r: 23, g: 107, b: 101 },+ rect = { x0: 20, x1: 30, y0: 10, y1: 40 },+} = {}) {+ const w = 64; const h = 64;+ const buf = Buffer.alloc(w * h * 3);+ for (let y = 0; y < h; y++) {+ for (let x = 0; x < w; x++) {+ const inRect = x >= rect.x0 && x < rect.x1 && y >= rect.y0 && y < rect.y1;+ const c = inRect ? fg : bg;+ const i = (y * w + x) * 3;+ buf[i] = c.r; buf[i + 1] = c.g; buf[i + 2] = c.b;+ }+ }+ await mkdir(join(path, '..'), { recursive: true });+ await sharp(buf, { raw: { width: w, height: h, channels: 3 } }).png().toFile(path);+}++export async function placeCandidate(testRoot, recordId, target, name, opts = {}) {+ const candDir = join(testRoot, 'sprites', recordId, 'reference', 'candidates');+ await writeCandidatePng(join(candDir, name), opts);+ await writeFile(join(candDir, `${name.replace(/\.png$/, '')}.generation.json`), JSON.stringify({+ schemaVersion: 1, target, chromaKey: opts.sidecarKey ?? '#FF00FF',+ }));+ return `reference/candidates/${name}`;+}++// Locks 'main' plus every other direction in `directions`, in south-first+// order — the shape shared by walk.test.js's characterWithLockedAnchors and+// atlas.test.js's lockAllAnchors (which only differ in which directions they+// pass and how they name/create the character beforehand).+export async function lockAllAnchors(testRoot, recordId, { lockReference, directions }) {+ await lockReference(recordId, {+ target: 'main',+ candidate: await placeCandidate(testRoot, recordId, 'main', 'walk-south-candidate-01.png'),+ });+ for (const dir of directions.filter((d) => d !== 'south')) {+ await lockReference(recordId, {+ target: dir,+ candidate: await placeCandidate(testRoot, recordId, dir, `walk-${dir}-candidate-01.png`),+ });+ }+}diff --git a/server/services/sprites/walk.test.js b/server/services/sprites/walk.test.jsindex 6b9f9f336a..8a2b247560 100644--- a/server/services/sprites/walk.test.js+++ b/server/services/sprites/walk.test.js@@ -10,9 +10,9 @@ import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';import { mkdtempSync, rmSync } from 'fs';import { tmpdir } from 'os';import { join } from 'path';-import sharp from 'sharp';import { mkdir, writeFile, readFile } from 'fs/promises';import { createHash } from 'crypto';+import { lockAllAnchors } from './spriteTestFixtures.js';const TEST_ROOT = mkdtempSync(join(tmpdir(), 'sprite-walk-test-'));@@ -77,30 +77,9 @@ let seq = 0;const newId = () => `walker-${++seq}`;const sha256 = (buf) => createHash('sha256').update(buf).digest('hex');-async function writeCandidatePng(path) {- const w = 64; const h = 64;- const buf = Buffer.alloc(w * h * 3);- for (let p = 0; p < w * h; p++) buf.set([255, 0, 255], p * 3);- for (let y = 10; y < 40; y++) for (let x = 20; x < 30; x++) buf.set([23, 107, 101], (y * w + x) * 3);- await mkdir(join(path, '..'), { recursive: true });- await sharp(buf, { raw: { width: w, height: h, channels: 3 } }).png().toFile(path);-}--async function placeCandidate(recordId, target, name) {- const candDir = join(TEST_ROOT, 'sprites', recordId, 'reference', 'candidates');- await writeCandidatePng(join(candDir, name));- await writeFile(join(candDir, `${name.replace(/\.png$/, '')}.generation.json`), JSON.stringify({- schemaVersion: 1, target, chromaKey: '#FF00FF',- }));- return `reference/candidates/${name}`;-}-async function characterWithLockedAnchors(id, directions = ['east']) {await records.createRecord({ kind: 'character', name: 'Walker' }, id);- await lockReference(id, { target: 'main', candidate: await placeCandidate(id, 'main', 'walk-south-candidate-01.png') });- for (const dir of directions.filter((d) => d !== 'south')) {- await lockReference(id, { target: dir, candidate: await placeCandidate(id, dir, `walk-${dir}-candidate-01.png`) });- }+ await lockAllAnchors(TEST_ROOT, id, { lockReference, directions });return id;}