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: speed up heavy git and sprite integration suites (#4394)
[._.]/ Adam Eivy9125134f2c6a
diff --git a/.changelog/next/changed-issue-4394.md b/.changelog/next/changed-issue-4394.mdnew file mode 100644index 0000000000..bbccde08bc--- /dev/null+++ b/.changelog/next/changed-issue-4394.md@@ -0,0 +1 @@+- Server unit tests skip the heavy git and sprite integration suites under VITEST_FAST, and those suites share cached git/PNG fixtures so the full run is faster.diff --git a/server/lib/README.md b/server/lib/README.mdindex 96b2922340..5977574bcc 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -379,6 +379,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| Module | Purpose ||---|---|+| `gitTestRepo.js` | Shared real-git sandbox for integration tests (#4394): one initialized template (working tree + bare origin) per worker, then `fs.cp` into a fresh temp dir. `makeGitSandbox({ origin })`, `attachBareOrigin(scratch, repo)`, `materializeGitRepo(dest)`, `destroyGitSandbox`, plus `SKIP_HEAVY_INTEGRATION` (`VITEST_FAST=1`). Still real git — just not rebuilt from `init`+`commit`+`push` in every `beforeEach`. || `mirrorParity.js` | Source-comparison primitives for the `*.mirror.test.js` server↔client parity tests: `stripCommentsAndNormalize` (so per-side commentary may diverge but logic may not), `extractDeclaration(src, name)` (balanced `{}`/`()`/`[]` walk over `function` / `async function` / `const`), and `compareDeclaration(serverSrc, clientSrc, name)`. Use these instead of hand-rolling a brace-walker per mirror. Pure — no `vitest` import — so callers own the assertions. || `mockPathsDataRoot.js` | Shared Vitest helpers for `PATHS.data → temp dir` and no-peer record creation guards. || `settingsTestUtil.js` | `bindSettingsFile(dataRoot)` → `writeSettingsFile`/`mergeSettingsFile`: direct settings.json disk writes that also drop the `getSettings()` read cache (dynamic-import reset) so a stale cache can't survive a bypass-`save()` write. |diff --git a/server/lib/branchUpstreamGuard.test.js b/server/lib/branchUpstreamGuard.test.jsindex 21af773374..3d53c0592c 100644--- a/server/lib/branchUpstreamGuard.test.js+++ b/server/lib/branchUpstreamGuard.test.js@@ -8,13 +8,16 @@* would assert the author's belief rather than git's behavior. The first test* below is the bypass probe: it reproduces the bug with the un-fixed command, so* the flag the fix adds is demonstrably load-bearing.+ *+ * Sandboxes come from `gitTestRepo.js` (one template per worker, then copied).+ * `VITEST_FAST=1` skips the real-git describes and keeps `isSafeBranchUpstream`.*/import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtemp, rm, writeFile } from 'fs/promises';-import { tmpdir } from 'os';+import { writeFile } from 'fs/promises';import { join } from 'path';import { execGit } from './execGit.js';+import { makeGitSandbox, destroyGitSandbox, SKIP_HEAVY_INTEGRATION } from './gitTestRepo.js';import {enforceSafeBranchUpstream,isSafeBranchUpstream,@@ -30,33 +33,21 @@ async function commit(subject) {await execGit(['commit', '-m', subject], repo);}-/** A real bare remote on disk — no network, no mocked remote-tracking refs. */-async function addOrigin() {- const remote = join(scratch, 'origin.git');- await execGit(['init', '--bare', '-b', 'main', remote], scratch);- await execGit(['remote', 'add', 'origin', remote], repo);- await execGit(['push', '-u', 'origin', 'main'], repo);-}-/** The `branch.<name>.merge` a config-derived push (`HEAD:<merge>`) would target. */const mergeRef = async (branch) => (await readBranchUpstream(repo, branch)).merge;-beforeEach(async () => {- scratch = await mkdtemp(join(tmpdir(), 'portos-branch-upstream-'));- repo = join(scratch, 'primary');- await execGit(['init', '-b', 'main', repo], scratch);- // Local identity so the suite doesn't depend on (or read) the host's git config.- await execGit(['config', 'user.email', '[email protected]'], repo);- await execGit(['config', 'user.name', 'Example Agent'], repo);- await commit('initial');- await addOrigin();-});+function useOriginSandbox() {+ beforeEach(async () => {+ ({ scratch, repo } = await makeGitSandbox({ origin: true, prefix: 'portos-branch-upstream-' }));+ });+ afterEach(async () => {+ await destroyGitSandbox(scratch);+ });+}-afterEach(async () => {- await rm(scratch, { recursive: true, force: true }).catch(() => {});-});+describe.skipIf(SKIP_HEAVY_INTEGRATION)('the bug this guard exists for (#4172)', () => {+ useOriginSandbox();-describe('the bug this guard exists for (#4172)', () => {it('git auto-tracks refs/heads/main when a worktree branch is cut from origin/main', async () => {// The UN-fixed command, verbatim. If this ever stops recording `main`, the// `--no-track` flag in worktreeManager.js has become unnecessary — and this@@ -102,7 +93,9 @@ describe('isSafeBranchUpstream', () => {});});-describe('readBranchUpstream', () => {+describe.skipIf(SKIP_HEAVY_INTEGRATION)('readBranchUpstream', () => {+ useOriginSandbox();+it('reports both halves of a configured upstream', async () => {expect(await readBranchUpstream(repo, 'main')).toEqual({ remote: 'origin', merge: 'refs/heads/main' });});@@ -120,7 +113,9 @@ describe('readBranchUpstream', () => {});});-describe('enforceSafeBranchUpstream', () => {+describe.skipIf(SKIP_HEAVY_INTEGRATION)('enforceSafeBranchUpstream', () => {+ useOriginSandbox();+it('repairs a branch left tracking the default branch', async () => {const path = join(scratch, 'wt-legacy');// A branch in the shape every pre-fix agent worktree had.diff --git a/server/lib/gitTestRepo.js b/server/lib/gitTestRepo.jsnew file mode 100644index 0000000000..62b5ed0b23--- /dev/null+++ b/server/lib/gitTestRepo.js@@ -0,0 +1,128 @@+/**+ * Shared real-git sandboxes for integration tests (#4394).+ *+ * Suites that pin git's own defaults (autoSetupMerge, cherry/patch-id,+ * worktree list spelling) must keep talking to a real repository — a mocked+ * `execGit` would only assert the author's belief. What they do NOT need is+ * to `init` + `config` + `commit` + optional `init --bare` + `push` in every+ * `beforeEach`. This module builds that template once per worker and+ * `fs.cp`s it into a fresh temp dir.+ *+ * Pure-logic tests should not call these helpers at all.+ */+import { mkdtemp, rm, writeFile, cp, mkdir, readdir } from 'fs/promises';+import { tmpdir } from 'os';+import { join } from 'path';+import { execGit } from './execGit.js';++export const SKIP_HEAVY_INTEGRATION = ['1', 'true', 'yes'].includes(+ String(process.env.VITEST_FAST || '').toLowerCase(),+);++const TEMPLATE_PREFIX = 'portos-git-template-';+const DEFAULT_IDENTITY = Object.freeze({+ email: '[email protected]',+ name: 'Example Agent',+});++let templatePromise;++async function copyTree(src, dest) {+ await mkdir(dest, { recursive: true });+ const entries = await readdir(src, { withFileTypes: true });+ await Promise.all(entries.map((entry) => cp(+ join(src, entry.name),+ join(dest, entry.name),+ { recursive: true, force: true },+ )));+}++async function configureIdentity(repo, identity = DEFAULT_IDENTITY) {+ await execGit(['config', 'user.email', identity.email], repo);+ await execGit(['config', 'user.name', identity.name], repo);+ await execGit(['config', 'commit.gpgsign', 'false'], repo);+}++async function stripOrigin(repo) {+ await execGit(['remote', 'remove', 'origin'], repo, { ignoreExitCode: true });+ await execGit(['branch', '--unset-upstream'], repo, { ignoreExitCode: true });+}++async function buildTemplate() {+ const scratch = await mkdtemp(join(tmpdir(), TEMPLATE_PREFIX));+ const repo = join(scratch, 'primary');+ const origin = join(scratch, 'origin.git');+ await execGit(['init', '-b', 'main', repo], scratch);+ await configureIdentity(repo);+ await writeFile(join(repo, 'initial.txt'), 'initial');+ await execGit(['add', '-A'], repo);+ await execGit(['commit', '-m', 'initial'], repo);+ await execGit(['init', '--bare', '-b', 'main', origin], scratch);+ await execGit(['remote', 'add', 'origin', origin], repo);+ await execGit(['push', '-u', 'origin', 'main'], repo);+ return { scratch, repo, origin };+}++function getTemplate() {+ templatePromise ??= buildTemplate();+ return templatePromise;+}++/**+ * Fresh parent dir + working tree (`scratch/primary`), optionally with a+ * private bare origin at `scratch/origin.git`. The origin URL is rewritten+ * to the copy so two sandboxes never share a remote.+ */+export async function makeGitSandbox({+ origin = false,+ prefix = 'portos-git-',+ identity,+} = {}) {+ const template = await getTemplate();+ const scratch = await mkdtemp(join(tmpdir(), prefix));+ const repo = join(scratch, 'primary');+ await cp(template.repo, repo, { recursive: true, force: true });+ if (identity) await configureIdentity(repo, identity);+ let originPath = null;+ if (origin) {+ originPath = join(scratch, 'origin.git');+ await cp(template.origin, originPath, { recursive: true, force: true });+ await execGit(['remote', 'set-url', 'origin', originPath], repo);+ } else {+ await stripOrigin(repo);+ }+ return { scratch, repo, origin: originPath };+}++/**+ * Attach a private bare origin at `scratch/origin.git` and push `main`.+ * Same shape the suites used to build with `init --bare` + `push -u`, so+ * tests that already call `addOrigin()` after extra local commits still+ * publish those commits.+ */+export async function attachBareOrigin(scratch, repo) {+ const template = await getTemplate();+ const originPath = join(scratch, 'origin.git');+ await cp(template.origin, originPath, { recursive: true, force: true });+ await execGit(['remote', 'add', 'origin', originPath], repo);+ await execGit(['push', '-u', 'origin', 'main'], repo);+ return originPath;+}++/**+ * Copy the working-tree template *into* an existing directory (typically+ * the `mkdtemp` result). Used when the suite wants the repo root to BE the+ * temp dir — `git worktree list` spelling / realpath checks.+ */+export async function materializeGitRepo(dest, { identity } = {}) {+ const template = await getTemplate();+ await copyTree(template.repo, dest);+ await stripOrigin(dest);+ if (identity) await configureIdentity(dest, identity);+ return dest;+}++export async function destroyGitSandbox(scratch) {+ if (!scratch) return;+ await rm(scratch, { recursive: true, force: true }).catch(() => {});+}diff --git a/server/lib/gitTestRepo.test.js b/server/lib/gitTestRepo.test.jsnew file mode 100644index 0000000000..b43c0e91fe--- /dev/null+++ b/server/lib/gitTestRepo.test.js@@ -0,0 +1,73 @@+import { describe, it, expect, afterEach } from 'vitest';+import { mkdtemp, writeFile } from 'fs/promises';+import { existsSync } from 'fs';+import { tmpdir } from 'os';+import { join } from 'path';+import { execGit } from './execGit.js';+import {+ makeGitSandbox,+ attachBareOrigin,+ materializeGitRepo,+ destroyGitSandbox,+} from './gitTestRepo.js';++const sandboxes = [];+afterEach(async () => {+ await Promise.all(sandboxes.splice(0).map((s) => destroyGitSandbox(s)));+});++describe('makeGitSandbox', () => {+ it('yields a real repo on main with the template commit and no origin by default', async () => {+ const box = await makeGitSandbox({ prefix: 'portos-git-fx-' });+ sandboxes.push(box.scratch);+ expect((await execGit(['rev-parse', '--abbrev-ref', 'HEAD'], box.repo)).stdout.trim()).toBe('main');+ expect((await execGit(['log', '-1', '--pretty=%s'], box.repo)).stdout.trim()).toBe('initial');+ const remotes = (await execGit(['remote'], box.repo)).stdout.trim();+ expect(remotes).toBe('');+ });++ it('rewrites origin to the sandbox copy so two sandboxes cannot share a remote', async () => {+ const a = await makeGitSandbox({ origin: true, prefix: 'portos-git-fx-a-' });+ const b = await makeGitSandbox({ origin: true, prefix: 'portos-git-fx-b-' });+ sandboxes.push(a.scratch, b.scratch);++ const urlA = (await execGit(['remote', 'get-url', 'origin'], a.repo)).stdout.trim();+ const urlB = (await execGit(['remote', 'get-url', 'origin'], b.repo)).stdout.trim();+ expect(urlA).toBe(a.origin);+ expect(urlB).toBe(b.origin);+ expect(urlA).not.toBe(urlB);++ await writeFile(join(a.repo, 'only-a.txt'), 'a');+ await execGit(['add', '-A'], a.repo);+ await execGit(['commit', '-m', 'only a'], a.repo);+ await execGit(['push', 'origin', 'main'], a.repo);++ const inB = await execGit(['cat-file', '-e', 'origin/main:only-a.txt'], b.repo, { ignoreExitCode: true });+ expect(inB.exitCode).not.toBe(0);+ });+});++describe('attachBareOrigin / materializeGitRepo', () => {+ it('publishes commits made before the origin was attached', async () => {+ const box = await makeGitSandbox({ prefix: 'portos-git-fx-att-' });+ sandboxes.push(box.scratch);+ await writeFile(join(box.repo, 'ahead.txt'), 'ahead');+ await execGit(['add', '-A'], box.repo);+ await execGit(['commit', '-m', 'ahead of origin'], box.repo);++ const origin = await attachBareOrigin(box.scratch, box.repo);+ expect(existsSync(origin)).toBe(true);+ expect((await execGit(['log', '-1', '--pretty=%s', 'origin/main'], box.repo)).stdout.trim())+ .toBe('ahead of origin');+ });++ it('fills an existing directory as a standalone repo root', async () => {+ const dest = await mkdtemp(join(tmpdir(), 'portos-git-fx-mat-'));+ sandboxes.push(dest);+ await materializeGitRepo(dest, { identity: { email: '[email protected]', name: 'Test' } });+ const top = (await execGit(['rev-parse', '--show-toplevel'], dest)).stdout.trim();+ expect(top).toBeTruthy();+ expect((await execGit(['log', '-1', '--pretty=%s'], dest)).stdout.trim()).toBe('initial');+ expect((await execGit(['config', 'user.email'], dest)).stdout.trim()).toBe('[email protected]');+ });+});diff --git a/server/lib/index.js b/server/lib/index.jsindex 22241d03f3..0afac106d7 100644--- a/server/lib/index.js+++ b/server/lib/index.js@@ -353,6 +353,7 @@ export * from './workspaceRoots.js';export * from './zodCompat.js';// === Test support (consumed by *.test.js files) ===+export * from './gitTestRepo.js';export * from './mockPathsDataRoot.js';export * from './settingsTestUtil.js';export * from './testHelper.js';diff --git a/server/lib/primaryCheckoutGuard.test.js b/server/lib/primaryCheckoutGuard.test.jsindex 347d7f2e54..fd4579dde3 100644--- a/server/lib/primaryCheckoutGuard.test.js+++ b/server/lib/primaryCheckoutGuard.test.js@@ -5,13 +5,21 @@* `execGit`: the whole value of this module is that it reads git state* correctly, and a mock that returns whatever the test author expected `git* rev-parse` to print proves nothing about that.+ *+ * Sandboxes come from `gitTestRepo.js` (one template per worker, then copied).+ * `VITEST_FAST=1` skips the real-git describes and keeps the prose helpers.*/import { describe, it, expect, beforeEach, afterEach } from 'vitest';-import { mkdtemp, rm, writeFile } from 'fs/promises';-import { tmpdir } from 'os';+import { rm, writeFile } from 'fs/promises';import { join } from 'path';import { execGit } from './execGit.js';+import {+ makeGitSandbox,+ attachBareOrigin,+ destroyGitSandbox,+ SKIP_HEAVY_INTEGRATION,+} from './gitTestRepo.js';import {capturePrimaryCheckoutState,detectPrimaryCheckoutDrift,@@ -37,10 +45,7 @@ async function commit(subject) {* network, no mocked `rev-parse`).*/async function addOrigin() {- const remote = join(scratch, 'origin.git');- await execGit(['init', '--bare', '-b', 'main', remote], scratch);- await execGit(['remote', 'add', 'origin', remote], repo);- await execGit(['push', '-u', 'origin', 'main'], repo);+ await attachBareOrigin(scratch, repo);}/** Land a commit on the remote and fast-forward `repo` onto it, as a pull would. */@@ -56,21 +61,18 @@ async function pullFromOrigin(subject) {await execGit(['pull', '--ff-only'], repo);}-beforeEach(async () => {- scratch = await mkdtemp(join(tmpdir(), 'portos-branch-jack-'));- repo = join(scratch, 'primary');- await execGit(['init', '-b', 'main', repo], scratch);- // Local identity so the suite doesn't depend on (or read) the host's git config.- await execGit(['config', 'user.email', '[email protected]'], repo);- await execGit(['config', 'user.name', 'Example Agent'], repo);- await commit('initial');-});+function useGitSandbox() {+ beforeEach(async () => {+ ({ scratch, repo } = await makeGitSandbox({ prefix: 'portos-branch-jack-' }));+ });+ afterEach(async () => {+ await destroyGitSandbox(scratch);+ });+}-afterEach(async () => {- await rm(scratch, { recursive: true, force: true }).catch(() => {});-});+describe.skipIf(SKIP_HEAVY_INTEGRATION)('capturePrimaryCheckoutState', () => {+ useGitSandbox();-describe('capturePrimaryCheckoutState', () => {it('reads the current branch and HEAD', async () => {const state = await capturePrimaryCheckoutState(repo);expect(state.path).toBe(repo);@@ -86,7 +88,9 @@ describe('capturePrimaryCheckoutState', () => {});});-describe('detectPrimaryCheckoutDrift', () => {+describe.skipIf(SKIP_HEAVY_INTEGRATION)('detectPrimaryCheckoutDrift', () => {+ useGitSandbox();+it('reports no drift when the primary checkout is untouched', async () => {const baseline = await capturePrimaryCheckoutState(repo);// Simulate the run happening entirely elsewhere: nothing touches `repo`.diff --git a/server/package.json b/server/package.jsonindex eec9cf20f6..ccddb675fc 100644--- a/server/package.json+++ b/server/package.json@@ -10,6 +10,7 @@"dev": "node --watch index.js","start": "node index.js","test": "vitest run",+ "test:fast": "VITEST_FAST=1 vitest run","test:watch": "vitest","test:ci": "vitest run --bail=1 --silent=passed-only --reporter=default --reporter=github-actions","test:coverage": "vitest run --coverage",diff --git a/server/services/sprites/atlas.test.js b/server/services/sprites/atlas.test.jsindex 981cb15ab2..183e2af570 100644--- a/server/services/sprites/atlas.test.js+++ b/server/services/sprites/atlas.test.js@@ -5,6 +5,10 @@* versioning, and compile idempotency. Fixtures lock a real reference set* (real normalize + chroma-key selection) and hand-write the walk artifacts* with a correct hash chain.+ *+ * Candidate / walk-frame PNGs are Sharp-encoded once per unique pixel config+ * (`spriteTestFixtures.js`) then written from the cached buffer. Excluded from+ * `npm run test:fast` (`VITEST_FAST=1`).*/import { describe, it, expect, beforeEach, afterEach, afterAll, vi } from 'vitest';@@ -14,7 +18,12 @@ import { join } from 'path';import sharp from 'sharp';import { mkdir, writeFile, readFile, rm } from 'fs/promises';import { createHash } from 'crypto';-import { lockAllAnchors as lockAllAnchorsFixture, placeCandidate, trackSpan as fullSpan } from './spriteTestFixtures.js';+import {+ lockAllAnchors as lockAllAnchorsFixture,+ placeCandidate,+ trackSpan as fullSpan,+ writeWalkFramePng,+} from './spriteTestFixtures.js';const TEST_ROOT = mkdtempSync(join(tmpdir(), 'sprite-atlas-test-'));@@ -63,33 +72,7 @@ async function lockAllAnchors(id) {await lockAllAnchorsFixture(TEST_ROOT, id, { lockReference, directions: SPRITE_DIRECTIONS });}-/** Transparent 40×40 RGBA frame with an opaque 20×30 figure. */-/**- * `armX` (optional) adds a protruding block at that column — a stand-in for a- * swinging limb, so a direction's frames differ in SILHOUETTE and not just in- * tint. Registration bugs (#3021) only show up across differing silhouettes:- * with the identical-shape default, every placement rule agrees and an- * inter-cell assertion would pass vacuously.- */-async function walkFramePng(path, tint, armX = null, speck = false) {- const w = 40; const h = 40;- const buf = Buffer.alloc(w * h * 4);- for (let y = 5; y < 35; y++) {- for (let x = 10; x < 30; x++) {- buf.set([tint, 107, 101, 255], (y * w + x) * 4);- }- }- if (armX !== null) {- for (let y = 12; y < 20; y++) {- for (let x = armX; x < armX + 6; x++) buf.set([tint, 107, 101, 255], (y * w + x) * 4);- }- }- // A lone opaque pixel below the sole — the despill survivor / dropped shadow- // that used to drag the whole frame's grounding down with it.- if (speck) buf.set([tint, 107, 101, 255], (35 * w + 20) * 4);- await mkdir(join(path, '..'), { recursive: true });- await sharp(buf, { raw: { width: w, height: h, channels: 4 } }).png().toFile(path);-}+const walkFramePng = writeWalkFramePng;async function buildFinalizedWalkSet(recordId, {frameCount = WALK_PHASES.length, fps, varyArm = false, alignment = null, speckFrames = [],diff --git a/server/services/sprites/spriteTestFixtures.js b/server/services/sprites/spriteTestFixtures.jsindex 017259944b..8544a11d4a 100644--- a/server/services/sprites/spriteTestFixtures.js+++ b/server/services/sprites/spriteTestFixtures.js@@ -10,19 +10,39 @@* synthetic registry row: a new span field (or a new required registry field)* would otherwise be a six-file edit, and any file that missed it would go* green on a stale shape.+ *+ * `writeCandidatePng` / `writeWalkFramePng` cache the Sharp-encoded buffer+ * per unique pixel config so atlas/walk/reference suites don't re-encode the+ * same 64×64 (or 40×40) fixture for every candidate and walk frame.*/import { join } from 'path';import sharp from 'sharp';import { mkdir, writeFile } from 'fs/promises';import { SPRITE_DIRECTIONS } from './prompts.js';-// 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, {+// Sharp PNG encoding is the expensive part; the same raw pixels show up in+// dozens of tests. Cache the encoded buffer per unique pixel config and+// `writeFile` it — still a real PNG, just not re-encoded every time.+const candidatePngCache = new Map();+const walkFramePngCache = new Map();++function candidateCacheKey({bg = { r: 255, g: 0, b: 255 },fg = { r: 23, g: 107, b: 101 },rect = { x0: 20, x1: 30, y0: 10, y1: 40 },} = {}) {+ return JSON.stringify({ bg, fg, rect });+}++async function encodeCandidatePng(opts = {}) {+ const key = candidateCacheKey(opts);+ const hit = candidatePngCache.get(key);+ if (hit) return hit;+ const {+ bg = { r: 255, g: 0, b: 255 },+ fg = { r: 23, g: 107, b: 101 },+ rect = { x0: 20, x1: 30, y0: 10, y1: 40 },+ } = opts;const w = 64; const h = 64;const buf = Buffer.alloc(w * h * 3);for (let y = 0; y < h; y++) {@@ -33,8 +53,53 @@ export async function writeCandidatePng(path, {buf[i] = c.r; buf[i + 1] = c.g; buf[i + 2] = c.b;}}+ const png = await sharp(buf, { raw: { width: w, height: h, channels: 3 } }).png().toBuffer();+ candidatePngCache.set(key, png);+ return png;+}++// 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, opts = {}) {+ const png = await encodeCandidatePng(opts);+ await mkdir(join(path, '..'), { recursive: true });+ await writeFile(path, png);+}++/**+ * Transparent 40×40 RGBA frame with an opaque 20×30 figure.+ *+ * `armX` (optional) adds a protruding block at that column — a stand-in for a+ * swinging limb, so a direction's frames differ in SILHOUETTE and not just in+ * tint. Registration bugs (#3021) only show up across differing silhouettes:+ * with the identical-shape default, every placement rule agrees and an+ * inter-cell assertion would pass vacuously.+ *+ * `speck` paints a lone opaque pixel below the sole — the despill survivor /+ * dropped shadow that used to drag the whole frame's grounding down with it.+ */+export async function writeWalkFramePng(path, tint, armX = null, speck = false) {+ const key = `${tint}|${armX}|${speck}`;+ let png = walkFramePngCache.get(key);+ if (!png) {+ const w = 40; const h = 40;+ const buf = Buffer.alloc(w * h * 4);+ for (let y = 5; y < 35; y++) {+ for (let x = 10; x < 30; x++) {+ buf.set([tint, 107, 101, 255], (y * w + x) * 4);+ }+ }+ if (armX !== null) {+ for (let y = 12; y < 20; y++) {+ for (let x = armX; x < armX + 6; x++) buf.set([tint, 107, 101, 255], (y * w + x) * 4);+ }+ }+ if (speck) buf.set([tint, 107, 101, 255], (35 * w + 20) * 4);+ png = await sharp(buf, { raw: { width: w, height: h, channels: 4 } }).png().toBuffer();+ walkFramePngCache.set(key, png);+ }await mkdir(join(path, '..'), { recursive: true });- await sharp(buf, { raw: { width: w, height: h, channels: 3 } }).png().toFile(path);+ await writeFile(path, png);}export async function placeCandidate(testRoot, recordId, target, name, opts = {}) {diff --git a/server/services/sprites/walk.test.js b/server/services/sprites/walk.test.jsindex 6d6a25eda6..499eabd81d 100644--- a/server/services/sprites/walk.test.js+++ b/server/services/sprites/walk.test.js@@ -4,6 +4,9 @@* with tamper checks, walk-set finalization + immutability, and the loop* trimmer. The queue and the deterministic postprocess are mocked — the* postprocess itself is covered by walkPostprocess.test.js.+ *+ * Anchor candidates share the cached PNG encoder in `spriteTestFixtures.js`.+ * Excluded from `npm run test:fast` (`VITEST_FAST=1`).*/import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';diff --git a/server/services/worktreeReap.test.js b/server/services/worktreeReap.test.jsindex ac28d2a2fc..0e9921117c 100644--- a/server/services/worktreeReap.test.js+++ b/server/services/worktreeReap.test.js@@ -6,6 +6,9 @@* on git's own `commit-tree` + `cherry` patch-id behavior — a hand-mirrored copy* wouldn't catch git-version quirks, and that detection is the safety gate the* reaper trusts before deleting anything.+ *+ * Repos are copied from the shared `gitTestRepo.js` template. The whole file+ * is excluded from `npm run test:fast` (`VITEST_FAST=1`).*/import { describe, it, expect, beforeEach, afterEach } from 'vitest';import { mkdtemp, rm, writeFile, mkdir } from 'fs/promises';@@ -13,6 +16,7 @@ import { existsSync, realpathSync } from 'fs';import { tmpdir } from 'os';import { join } from 'path';import { execGit } from '../lib/execGit.js';+import { materializeGitRepo, SKIP_HEAVY_INTEGRATION } from '../lib/gitTestRepo.js';import { isBranchMergedInto } from './git.js';import { reapMergedWorktrees } from './worktreeManager.js';@@ -37,21 +41,16 @@ async function initRepo() {// `git worktree list` records the canonical /private/var path, which would// break the reaper's startsWith() location checks and our path assertions.const created = realpathSync(await mkdtemp(join(tmpdir(), 'portos-reap-')));- await execGit(['init', '-b', 'main'], created);+ await materializeGitRepo(created, { identity: { email: '[email protected]', name: 'Test' } });// Adopt git's spelling of the root. `git worktree list` reports paths the way// git normalized them, and the reaper's containment check compares those// against a root derived from this value — so any disagreement (8.3 short// names like C:\\Users\\RUNNER~1, drive-letter case) makes every worktree look// like it lives somewhere unmanaged and nothing is reaped.- const dir = (await execGit(['rev-parse', '--show-toplevel'], created)).stdout.trim() || created;- await execGit(['config', 'user.email', '[email protected]'], dir);- await execGit(['config', 'user.name', 'Test'], dir);- await execGit(['config', 'commit.gpgsign', 'false'], dir);- await commitFile(dir, 'base.txt', 'base\n', 'base');- return dir;+ return (await execGit(['rev-parse', '--show-toplevel'], created)).stdout.trim() || created;}-describe('isBranchMergedInto', () => {+describe.skipIf(SKIP_HEAVY_INTEGRATION)('isBranchMergedInto', () => {let dir;beforeEach(async () => { dir = await initRepo(); });afterEach(async () => { await rm(dir, { recursive: true, force: true }); });@@ -114,7 +113,7 @@ describe('isBranchMergedInto', () => {});});-describe('reapMergedWorktrees', () => {+describe.skipIf(SKIP_HEAVY_INTEGRATION)('reapMergedWorktrees', () => {let dir;beforeEach(async () => { dir = await initRepo(); });afterEach(async () => { await rm(dir, { recursive: true, force: true }); });diff --git a/server/vitest.config.js b/server/vitest.config.jsindex 1fb8164e76..e279e7e4f9 100644--- a/server/vitest.config.js+++ b/server/vitest.config.js@@ -41,9 +41,19 @@ export default defineConfig({// The slashdo submodule ships its own node:test suites; vitest can't// parse them and the broad `../lib/**` glob would otherwise pick them up// as "no test suite found" failures that break --bail=1 CI runs.+ // Heavy disk/git/Sharp integration suites. `npm run test:fast`+ // (VITEST_FAST=1) drops them so a unit-only loop stays cheap; `npm test`+ // and CI keep the full run. The git-guard files are NOT listed here —+ // their real-git describes honor SKIP_HEAVY_INTEGRATION, and the leftover+ // pure-logic cases still run under --fast.exclude: ['**/node_modules/**','../lib/slashdo/**',+ ...(process.env.VITEST_FAST ? [+ 'services/worktreeReap.test.js',+ 'services/sprites/atlas.test.js',+ 'services/sprites/walk.test.js',+ ] : []),],coverage: {provider: 'v8',