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: settle AuK inference fixtures without polling deadlines (#11581)

[._.]/ Adam Eivy061e02e5cec9
diff --git a/server/services/voice/aukRuntime.test.js b/server/services/voice/aukRuntime.test.js
index 3027858917..078682784d 100644
--- a/server/services/voice/aukRuntime.test.js
+++ b/server/services/voice/aukRuntime.test.js
@@ -1,8 +1,11 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { EventEmitter } from 'node:events';
+import { EventEmitter, once } from 'node:events';
import { PassThrough } from 'node:stream';
import { pinPlatform, pinArch } from '../../lib/testHelper.js';
const children = [];
+const requests = new EventEmitter();
+const renders = [];
+let controller;
const access = vi.fn();
let failWrite = false;
vi.mock('node:fs/promises', () => ({ access: (...args) => access(...args), mkdir: vi.fn(),
@@ -11,7 +14,15 @@ vi.mock('../../lib/childProcess.js', () => ({ execFile: vi.fn(), spawn: vi.fn(()
const child = new EventEmitter();
child.stdin = new PassThrough(); child.stdout = new PassThrough(); child.stderr = new PassThrough();
child.kill = vi.fn(() => { child.emit('close', null); return true; });
- if (failWrite) child.stdin.write = (_data, cb) => cb(new Error('EPIPE'));
+ // Signal the actual write, after the runtime installs its failure/abort handlers.
+ child.stdin.on('data', data => {
+ child.request = JSON.parse(data.toString());
+ requests.emit('request', child);
+ });
+ if (failWrite) child.stdin.write = (_data, cb) => {
+ requests.emit('request', child);
+ cb(new Error('EPIPE'));
+ };
children.push(child); return child;
}) }));
vi.mock('../../lib/processEnv.js', () => ({ safeChildProcessOptions: value => value, whichFirst: vi.fn() }));
@@ -24,46 +35,64 @@ beforeEach(() => {
restorePlatform = pinPlatform('darwin');
restoreArch = pinArch('arm64');
access.mockReset().mockResolvedValue(); children.length = 0; failWrite = false;
+ controller = new AbortController();
+ renders.length = 0;
});
-afterEach(() => {
- unloadAuk();
- restorePlatform();
- restoreArch();
- vi.useRealTimers();
+afterEach(async () => {
+ try {
+ // A failed assertion can leave a render in readiness checks or inference.
+ controller.abort();
+ await Promise.allSettled(renders);
+ unloadAuk();
+ } finally {
+ requests.removeAllListeners();
+ restorePlatform();
+ restoreArch();
+ }
});
+const render = (text, opts = {}) => {
+ const result = synthesizeAuk(text, opts, controller.signal);
+ renders.push(result);
+ // Own rejections immediately, even if an earlier assertion skips the await.
+ result.catch(() => {});
+ return result;
+};
+const nextRequest = () => once(requests, 'request').then(([child]) => child);
const response = child => child.stdout.write(`${JSON.stringify({ ok: true, latencyMs: 1500, firstAudioMs: 1500 })}\n`);
describe('AuK resident inference lifecycle', () => {
it('reuses a warm worker, refuses overlapping inference, and keeps actual full-audio latency', async () => {
- const first = synthesizeAuk('Hello.', { instructions: 'Warm alto', genSeconds: 4 });
- await vi.waitFor(() => expect(children).toHaveLength(1));
- await expect(synthesizeAuk('Overlap')).rejects.toMatchObject({ status: 409 });
- response(children[0]);
+ const firstRequest = nextRequest();
+ const first = render('Hello.', { instructions: 'Warm alto', genSeconds: 4 });
+ const child = await firstRequest;
+ await expect(render('Overlap')).rejects.toMatchObject({ status: 409 });
+ response(child);
expect(await first).toMatchObject({ firstAudioMs: 1500, engine: 'auk' });
- const second = synthesizeAuk('Again.', {});
- await vi.waitFor(async () => expect((await getAukStatus()).busy).toBe(true));
- response(children[0]);
+ const secondRequest = nextRequest();
+ const second = render('Again.', {});
+ expect(await secondRequest).toBe(child);
+ response(child);
await second;
expect(children).toHaveLength(1);
});
it('preserves all narration text in bounded model segments within one worker request', async () => {
const text = 'A thoughtful character walks toward the old library. '.repeat(12);
- const render = synthesizeAuk(text, { referenceAudio: '/example/reference.wav' });
- await vi.waitFor(() => expect(children).toHaveLength(1));
- const request = JSON.parse(children[0].stdin.read().toString());
+ const written = nextRequest();
+ const result = render(text, { referenceAudio: '/example/reference.wav' });
+ const child = await written;
+ const request = child.request;
expect(request.segments.length).toBeGreaterThan(1);
expect(request.segments.map(segment => segment.text).join('')).toBe(text);
expect(request.segments.every(segment => segment.seconds <= 12)).toBe(true);
expect(request.referenceAudio).toBe('/example/reference.wav');
- response(children[0]);
- await render;
+ response(child);
+ await result;
});
it('kills a canceled worker and releases the busy state for a later request', async () => {
- const controller = new AbortController();
- const pending = synthesizeAuk('Hello.', {}, controller.signal);
- const failure = expect(pending).rejects.toThrow('stopped');
- await vi.waitFor(() => expect(children).toHaveLength(1));
+ const written = nextRequest();
+ const pending = render('Hello.', {});
+ await written;
controller.abort();
- await failure;
+ await expect(pending).rejects.toThrow('stopped');
expect(children[0].kill).toHaveBeenCalledWith('SIGKILL');
expect(await getAukStatus()).toMatchObject({ busy: false, loaded: false });
});
@@ -71,31 +100,31 @@ describe('AuK resident inference lifecycle', () => {
['spawn error', child => child.emit('error', new Error('ENOENT')), 503],
['stdin stream error', child => child.stdin.emit('error', new Error('EPIPE')), 502],
])('discards the worker after a %s so the next request re-spawns', async (_name, fail, status) => {
- const failed = synthesizeAuk('Hello.', {});
- const check = expect(failed).rejects.toMatchObject({ status });
- await vi.waitFor(() => expect(children).toHaveLength(1));
- fail(children[0]);
- await check;
+ const written = nextRequest();
+ const failed = render('Hello.', {});
+ fail(await written);
+ await expect(failed).rejects.toMatchObject({ status });
expect(children[0].kill).toHaveBeenCalledWith('SIGKILL');
expect(await getAukStatus()).toMatchObject({ busy: false, loaded: false });
- const retry = synthesizeAuk('Again.', {});
- await vi.waitFor(() => expect(children).toHaveLength(2));
- response(children[1]);
+ const retryRequest = nextRequest();
+ const retry = render('Again.', {});
+ const child = await retryRequest;
+ expect(children).toHaveLength(2);
+ response(child);
await retry;
});
it('kills the worker and clears it when the request write fails', async () => {
failWrite = true;
- const failed = synthesizeAuk('Hello.', {});
- const check = expect(failed).rejects.toThrow('could not be sent');
- await vi.waitFor(() => expect(children).toHaveLength(1));
- await check;
+ const failed = render('Hello.', {});
+ await expect(failed).rejects.toThrow('could not be sent');
+ expect(children).toHaveLength(1);
expect(children[0].kill).toHaveBeenCalledWith('SIGKILL');
expect((await getAukStatus()).loaded).toBe(false);
});
it('never starts a process or reports readiness for missing model artifacts', async () => {
access.mockRejectedValue(new Error('missing'));
expect(await getAukStatus()).toMatchObject({ ready: false, loaded: false });
- await expect(synthesizeAuk('Hello.')).rejects.toMatchObject({ status: 503 });
+ await expect(render('Hello.')).rejects.toMatchObject({ status: 503 });
expect(children).toHaveLength(0);
});
});