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: drain sprite-walk test bodies before removing the fixture root (#12660)

[._.]/ Adam Eivy1d80dd12f13e
diff --git a/scripts/spriteWalkCleanup.test.js b/scripts/spriteWalkCleanup.test.js
new file mode 100644
index 0000000000..f9a8888733
--- /dev/null
+++ b/scripts/spriteWalkCleanup.test.js
@@ -0,0 +1,62 @@
+import { expect, it } from 'vitest';
+import { mkdtempSync, rmSync, readFileSync, writeFileSync, existsSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, dirname, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { createVitestTempFixture, fixtureReadyFailureSource, runFixtureToCompletion } from './lib/vitestTempRootFixture.js';
+
+// The nested run's own ceiling; the outer budget adds headroom so it is never tighter.
+const RUN_CEILING_MS = 120000;
+
+// Pins the regression uniquely (#12660): a different worker's --bail=1 failure
+// settles a sprite-walk test's wrapper while its body is still writing into the
+// suite's tmpdir root. Teardown must wait for that body, or the body's next
+// store write recreates the root after `rmSync` and the run reports
+// `test temp leak: sprite-walk-test-`.
+it('drains sprite-walk fixture writes after another worker triggers fail-fast', async () => {
+ const host = mkdtempSync(join(tmpdir(), 'sprite-walk-cancel-'));
+ try {
+ const fixtureRun = createVitestTempFixture(host, 'server', '');
+ const { args } = fixtureRun;
+ const fixture = join(host, 'fixture');
+ const ready = join(fixture, 'ready');
+ const finished = join(fixture, 'finished');
+ const sourcePath = fileURLToPath(new URL('../server/services/sprites/walk.test.js', import.meta.url));
+ const targetName = '409s when the direction anchor is not locked';
+ const header = `it('${targetName}', async () => {`;
+ const input = readFileSync(sourcePath, 'utf8')
+ .replace(/(['"])(\.\.?\/[^'"]+)\1/g, (_, quote, specifier) => JSON.stringify(resolve(dirname(sourcePath), specifier)));
+ expect(input).toContain(header);
+ // Hooks after a file run in reverse registration order, so a wait registered
+ // before the suite's own teardown hook runs after it: it observes the body's
+ // settlement in the broken control too, where the suite's hooks do not wait.
+ const settled = `afterAll(restoreSharpThreads);
+afterAll(async () => {
+ const { existsSync } = await import('node:fs');
+ await vi.waitFor(() => expect(existsSync(${JSON.stringify(finished)})).toBe(true), { timeout: 5000 });
+});`;
+ expect(input).toContain('afterAll(restoreSharpThreads);');
+ const source = input.replace('afterAll(restoreSharpThreads);', settled).replace(header, `${header.replace('async () =>', 'async ({ signal }) =>')}
+ const { writeFileSync } = await import('node:fs');
+ const cancelled = new Promise(resolve => signal.addEventListener('abort', () => setImmediate(resolve), { once: true }));
+ writeFileSync(${JSON.stringify(ready)}, 'ready');
+ await cancelled;
+ await records.createRecord({ kind: 'character', name: 'Interrupted' }, 'interrupted-walker');
+ writeFileSync(${JSON.stringify(finished)}, 'finished');
+ return;`);
+ expect(source).toContain('await cancelled;');
+ writeFileSync(join(fixture, 'lifecycle.test.js'), source);
+ writeFileSync(join(fixture, 'failure.test.js'), fixtureReadyFailureSource(ready));
+ args[args.indexOf('--maxWorkers') + 1] = '2';
+ args.push('--bail=1', '--testNamePattern', `${targetName}|controlled sibling failure`);
+ const result = await runFixtureToCompletion(fixtureRun, RUN_CEILING_MS);
+ const output = `${result.stdout}\n${result.stderr}`;
+ expect(result.error, output).toBeUndefined();
+ expect(result.status, output).toBe(1);
+ expect(output).toContain('controlled sibling failure');
+ expect(existsSync(finished), output).toBe(true);
+ expect(output).not.toMatch(/ENOTEMPTY|ENOENT|Unhandled|test temp leak:/);
+ } finally {
+ rmSync(host, { recursive: true, force: true });
+ }
+}, RUN_CEILING_MS + 15000);
diff --git a/server/services/sprites/walk.test.js b/server/services/sprites/walk.test.js
index 700a9e4f88..3727885b3b 100644
--- a/server/services/sprites/walk.test.js
+++ b/server/services/sprites/walk.test.js
@@ -11,12 +11,13 @@ import { spriteEvents } from './events.js';
* Excluded from `npm run test:fast` (`VITEST_FAST=1`).
*/
-import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';
+import { describe, it as vitestIt, expect, vi, beforeEach, afterAll } from 'vitest';
import { existsSync, mkdtempSync, rmSync, readFileSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { mkdir, writeFile, readFile, rm } from 'fs/promises';
import { createHash } from 'crypto';
+import { ownTestBodies } from '../../lib/mockPathsDataRoot.js';
import {
capSharpThreads, lockAllAnchors, lockAllAnchorsReal, expectCarriesCorrection, normalizeManifestForComparison,
writeCandidatePng,
@@ -25,6 +26,11 @@ import {
const restoreSharpThreads = capSharpThreads();
afterAll(restoreSharpThreads);
const TEST_ROOT = mkdtempSync(join(tmpdir(), 'sprite-walk-test-'));
+// Fail-fast cancellation (--bail from another worker) settles a test's wrapper
+// while its body keeps writing into TEST_ROOT; teardown drains the bodies first
+// so the root is not removed under them and recreated by their next write.
+const owned = ownTestBodies(vitestIt);
+const it = owned.it;
vi.mock('../../lib/fileUtils.js', async (importOriginal) => {
const actual = await importOriginal();
@@ -437,7 +443,13 @@ beforeEach(() => {
probeVideoDuration.mockResolvedValue(null);
rmSync(join(TEST_ROOT, 'sprite-records.json'), { force: true });
});
-afterAll(() => rmSync(TEST_ROOT, { recursive: true, force: true }));
+afterAll(async () => {
+ try {
+ await owned.drain();
+ } finally {
+ rmSync(TEST_ROOT, { recursive: true, force: true });
+ }
+});
describe('startWalkGeneration', () => {
it('409s when the direction anchor is not locked', async () => {
@@ -518,13 +530,15 @@ describe('startWalkGeneration', () => {
// for it regardless (#3022), so the prompt must ask for 6 — putting a number
// in it that the tool silently ignores is what made the old picker a lie.
// (The full fallback table is unit-tested in lib/grokVideoClip.test.js.)
- it.each([2, 5])('asks grok for 6s when %ss is requested, since %ss is not deliverable', async (duration) => {
- const id = await characterWithLockedAnchors(newId(), ['east']);
- const result = await startWalkGeneration(id, { direction: 'east', duration });
- expect(result.duration).toBe(6);
- expect(executeTuiRun.mock.calls[0][0].prompt).toContain('for 6 seconds');
- expect(executeTuiRun.mock.calls[0][0].prompt).not.toContain(`for ${duration} seconds`);
- });
+ for (const duration of [2, 5]) {
+ it(`asks grok for 6s when ${duration}s is requested, since ${duration}s is not deliverable`, async () => {
+ const id = await characterWithLockedAnchors(newId(), ['east']);
+ const result = await startWalkGeneration(id, { direction: 'east', duration });
+ expect(result.duration).toBe(6);
+ expect(executeTuiRun.mock.calls[0][0].prompt).toContain('for 6 seconds');
+ expect(executeTuiRun.mock.calls[0][0].prompt).not.toContain(`for ${duration} seconds`);
+ });
+ }
// Own completion through the persisted invalidation stream, not waitFor's
// one-second polling budget. Subscribe before releasing the fake TUI so a