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: cover ForkSpriteModal, SpriteReferencePicker, and the SpriteLightbox open path (#3292)
[._.]/ Adam Eivyadbe64a1abeb
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 33282ba7c6..d712a39d60 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -44,6 +44,7 @@- **[issue-3265] Fixed a test that broke on its own once the calendar passed 2026-07-31.** An image-quota test compared against a reset timestamp baked into its fixture; once that instant passed, the code correctly ignored the stale time and the test started comparing against the wall clock, failing every run. The test now pins its own clock, and the ignore-a-past-reset path it accidentally exercised has coverage of its own.- **[issue-3267] Removed the unmount guard from the shared async-action hook, along with the test that could never fail.** The guard existed to avoid a "state update on an unmounted component" warning React stopped emitting in version 18, so its only remaining effect was to skip a no-op — while being the exact shape that froze every button backed by the hook under StrictMode. Its regression test asserted that the vanished warning never appeared, which stayed green even with the guard deleted; it now unmounts mid-request and asserts the action still resolves with its value.- **[issue-3250] Stabilize Music Video project-selection tests under CI load.** Project-selection coverage now waits for the requested project to be available before opening its board, preventing intermittent false failures.+- **[issue-3292] Three sprite dialogs that every suite mocked away now have tests of their own.** The fork-a-character dialog, the reference-sprite picker, and the click-to-enlarge preview each carry real logic — the submit gate, the exact payload sent when forking, search filtering by name and id, and which asset the enlarged view opens — but no test file, and every suite that rendered them swapped in a stub. The fork payload was the sharpest edge: the server only ever checked a hand-written example of it, so a mismatch between what the dialog sends and what the server accepts could have sat behind two passing suites. Both of the payloads the dialog actually builds are now asserted on the client and replayed through the real server schema. No behaviour changed.## Chief of Staffdiff --git a/client/src/components/sprites/ForkSpriteModal.test.jsx b/client/src/components/sprites/ForkSpriteModal.test.jsxnew file mode 100644index 0000000000..6dd481efd6--- /dev/null+++ b/client/src/components/sprites/ForkSpriteModal.test.jsx@@ -0,0 +1,210 @@+/**+ * Fork a character from its locked reference (#sprite-i2i).+ *+ * The modal is a thin form, so what only IT can get wrong is the wire body it+ * hands `forkSpriteRecord` — and that body is invisible to the server suite,+ * which validates `spriteForkSchema` against a hand-built object. So the+ * central assertion here is the EXACT payload (keys included, keys omitted,+ * values trimmed), not merely that the call happened — and `server/routes/+ * sprites.test.js` feeds those same two bodies through the real+ * `spriteForkSchema`, so a drift between the two shows up on one side or the+ * other instead of hiding behind two green suites.+ *+ * Also covered: the `canSubmit` gate (an un-gated empty name/prompt is a+ * guaranteed 400), and the success/error branches — the fork's whole payoff is+ * navigating to the new record, so a swallowed `onForked` strands the user.+ */++import { describe, it, expect, vi, beforeEach } from 'vitest';+import { fireEvent, render, screen } from '@testing-library/react';+import userEvent from '@testing-library/user-event';++const forkSpriteRecord = vi.fn();++vi.mock('../../services/apiSprites.js', () => ({+ forkSpriteRecord: (...args) => forkSpriteRecord(...args),+ // SpritePreview → SpriteLightbox → AssetPromptSection pulls this in; the+ // preview here is not zoomable, so it is never called.+ getSpriteAssetPrompt: vi.fn(() => Promise.resolve(null)),+}));++vi.mock('../ui/Toast', () => ({+ default: { success: vi.fn(), error: vi.fn() },+}));++import ForkSpriteModal from './ForkSpriteModal.jsx';+import toast from '../ui/Toast';++const SOURCE = { id: 'example-pioneer', name: 'Example Pioneer' };+const BACKENDS = [{ id: 'codex', label: 'Codex' }, { id: 'grok', label: 'Grok' }];++const renderModal = (props = {}) => render(+ <ForkSpriteModal+ open+ onClose={vi.fn()}+ source={SOURCE}+ referencePath="reference/example-pioneer-main-v1.png"+ backends={BACKENDS}+ mode="codex"+ onForked={vi.fn()}+ {...props}+ />,+);++const forkButton = () => screen.getByRole('button', { name: /Fork & generate/ });+const promptBox = () => screen.getByLabelText('Prompt — describe the change');+const nameBox = () => screen.getByLabelText('New name');+const idBox = () => screen.getByLabelText(/^Id/);++beforeEach(() => {+ vi.clearAllMocks();+ forkSpriteRecord.mockResolvedValue({ record: { id: 'example-pioneer-fork', name: 'Example Pioneer fork' } });+});++describe('ForkSpriteModal submit gating', () => {+ it('seeds the name from the source and stays disabled until a prompt is written', async () => {+ renderModal();+ expect(nameBox()).toHaveValue('Example Pioneer fork');+ expect(forkButton()).toBeDisabled();++ await userEvent.type(promptBox(), 'now with a red coat');+ expect(forkButton()).toBeEnabled();+ });++ it('disables on a name that is only whitespace', async () => {+ renderModal();+ await userEvent.type(promptBox(), 'now with a red coat');+ await userEvent.clear(nameBox());+ await userEvent.type(nameBox(), ' ');+ expect(forkButton()).toBeDisabled();+ });++ it('disables on a prompt that is only whitespace', async () => {+ renderModal();+ await userEvent.type(promptBox(), ' ');+ expect(forkButton()).toBeDisabled();+ });++ it('requires a backend pick while backends exist, and backfills a late-arriving mode', async () => {+ // `mode` can resolve after mount (the settings fetch lands later), which is+ // the only reason the gate can start unsatisfied with backends present.+ const { rerender } = render(+ <ForkSpriteModal+ open onClose={vi.fn()} source={SOURCE} backends={BACKENDS} mode="" onForked={vi.fn()}+ />,+ );+ await userEvent.type(promptBox(), 'now with a red coat');+ expect(forkButton()).toBeDisabled();++ rerender(+ <ForkSpriteModal+ open onClose={vi.fn()} source={SOURCE} backends={BACKENDS} mode="grok" onForked={vi.fn()}+ />,+ );+ expect(screen.getByRole('combobox')).toHaveValue('grok');+ expect(forkButton()).toBeEnabled();+ });++ it('keeps an explicit backend pick when a mode prop arrives afterwards', async () => {+ const { rerender } = render(+ <ForkSpriteModal+ open onClose={vi.fn()} source={SOURCE} backends={BACKENDS} mode="" onForked={vi.fn()}+ />,+ );+ await userEvent.selectOptions(screen.getByRole('combobox'), 'grok');+ rerender(+ <ForkSpriteModal+ open onClose={vi.fn()} source={SOURCE} backends={BACKENDS} mode="codex" onForked={vi.fn()}+ />,+ );+ expect(screen.getByRole('combobox')).toHaveValue('grok');+ });++ it('drops the backend requirement (and warns) when no backend is configured', async () => {+ renderModal({ backends: [], mode: '' });+ expect(screen.queryByRole('combobox')).not.toBeInTheDocument();+ expect(screen.getByText(/No image backend configured/)).toBeInTheDocument();++ await userEvent.type(promptBox(), 'now with a red coat');+ expect(forkButton()).toBeEnabled();+ });+});++describe('ForkSpriteModal wire body', () => {+ it('sends the trimmed full body with the default fidelity', async () => {+ renderModal();+ await userEvent.clear(nameBox());+ await userEvent.type(nameBox(), ' Example Settler ');+ await userEvent.type(idBox(), ' example-settler ');+ await userEvent.type(promptBox(), ' wearing a wide-brim hat ');+ await userEvent.selectOptions(screen.getByRole('combobox'), 'grok');+ await userEvent.click(forkButton());++ expect(forkSpriteRecord).toHaveBeenCalledTimes(1);+ expect(forkSpriteRecord).toHaveBeenCalledWith('example-pioneer', {+ name: 'Example Settler',+ id: 'example-settler',+ designPrompt: 'wearing a wide-brim hat',+ mode: 'grok',+ initImageStrength: 0.65,+ }, { silent: true });+ });++ it('omits id and mode entirely rather than sending empty strings', async () => {+ renderModal({ backends: [], mode: '' });+ await userEvent.type(promptBox(), 'now with a red coat');+ await userEvent.click(forkButton());++ const [, body] = forkSpriteRecord.mock.calls[0];+ expect(Object.keys(body).sort()).toEqual(['designPrompt', 'initImageStrength', 'name']);+ });++ it('sends the fidelity slider value as a number', async () => {+ renderModal();+ await userEvent.type(promptBox(), 'now with a red coat');+ fireEvent.change(screen.getByRole('slider'), { target: { value: '0.4' } });+ expect(screen.getByText('0.40')).toBeInTheDocument();++ await userEvent.click(forkButton());+ expect(forkSpriteRecord.mock.calls[0][1].initImageStrength).toBe(0.4);+ });+});++describe('ForkSpriteModal outcomes', () => {+ it('hands the new record back and closes on success', async () => {+ const onForked = vi.fn();+ const onClose = vi.fn();+ renderModal({ onForked, onClose });+ await userEvent.type(promptBox(), 'now with a red coat');+ await userEvent.click(forkButton());++ expect(toast.success).toHaveBeenCalledWith(+ 'Forked Example Pioneer → Example Pioneer fork — main render queued',+ );+ expect(onForked).toHaveBeenCalledWith({ id: 'example-pioneer-fork', name: 'Example Pioneer fork' });+ expect(onClose).toHaveBeenCalled();+ });++ it('names the turnaround as the seed when the source has a locked sheet', async () => {+ renderModal({ fromTurnaround: true });+ await userEvent.type(promptBox(), 'now with a red coat');+ await userEvent.click(forkButton());+ expect(toast.success).toHaveBeenCalledWith(+ 'Forked Example Pioneer → Example Pioneer fork — turnaround render queued',+ );+ });++ it('surfaces the server message and keeps the modal open on failure', async () => {+ forkSpriteRecord.mockRejectedValue(new Error('id already exists'));+ const onForked = vi.fn();+ const onClose = vi.fn();+ renderModal({ onForked, onClose });+ await userEvent.type(promptBox(), 'now with a red coat');+ await userEvent.click(forkButton());++ expect(toast.error).toHaveBeenCalledWith('id already exists');+ expect(toast.success).not.toHaveBeenCalled();+ expect(onForked).not.toHaveBeenCalled();+ expect(onClose).not.toHaveBeenCalled();+ });+});diff --git a/client/src/components/sprites/SpritePreview.test.jsx b/client/src/components/sprites/SpritePreview.test.jsxindex bc14a294f1..ec02ac6bc7 100644--- a/client/src/components/sprites/SpritePreview.test.jsx+++ b/client/src/components/sprites/SpritePreview.test.jsx@@ -30,4 +30,22 @@ describe('SpritePreview', () => {await userEvent.click(screen.getByRole('button', { name: 'Close preview' }));expect(screen.queryByRole('button', { name: 'Close preview' })).not.toBeInTheDocument();});++ it('opens the lightbox on the SAME asset the thumbnail shows', async () => {+ // The lightbox resolves its own URL from (recordId, path, version) rather+ // than reusing the thumbnail's — so a mis-threaded prop would enlarge a+ // different (or cache-stale) file while the thumbnail still looks right.+ render(+ <SpritePreview recordId="field-medic" path="reference/walk-south-v1.png" version="v7" zoomable />,+ );+ const expectedSrc = '/data/sprites/field-medic/reference/walk-south-v1.png?v=v7';+ expect(screen.getByRole('img')).toHaveAttribute('src', expectedSrc);++ await userEvent.click(screen.getByRole('button', { name: /Enlarge/ }));++ // aria-label carries the record-relative path; both images point at it.+ expect(screen.getByRole('dialog')).toHaveAttribute('aria-label', 'Preview reference/walk-south-v1.png');+ const srcs = screen.getAllByRole('img').map((img) => img.getAttribute('src'));+ expect(srcs).toEqual([expectedSrc, expectedSrc]);+ });});diff --git a/client/src/components/sprites/SpriteReferencePicker.test.jsx b/client/src/components/sprites/SpriteReferencePicker.test.jsxnew file mode 100644index 0000000000..c6488a93f7--- /dev/null+++ b/client/src/components/sprites/SpriteReferencePicker.test.jsx@@ -0,0 +1,132 @@+/**+ * Pick an existing sprite's locked main reference to seed a new one (#sprite-i2i).+ *+ * The picker is the only thing standing between the user and an i2i seed, so+ * the behaviours worth pinning are the ones a re-render can quietly break:+ * - `excludeId` dropping the sprite being edited (seeding a main from its own+ * not-yet-locked reference is nonsensical)+ * - case-insensitive search across BOTH name and id — an id-only match is the+ * reason the filter concatenates the two+ * - `onSelect(item)` handing back the whole row (the caller needs `path`, not+ * just the id) and then closing+ * - the empty-state sentinel: "nothing locked yet" and "nothing matches your+ * search" are different problems with different fixes+ */++import { describe, it, expect, vi, beforeEach } from 'vitest';+import { render, screen } from '@testing-library/react';+import userEvent from '@testing-library/user-event';++const listSpriteReferenceSources = vi.fn();++vi.mock('../../services/apiSprites.js', () => ({+ listSpriteReferenceSources: (...args) => listSpriteReferenceSources(...args),+ // Pulled in transitively by SpritePreview → SpriteLightbox → AssetPromptSection.+ getSpriteAssetPrompt: vi.fn(() => Promise.resolve(null)),+}));++import SpriteReferencePicker from './SpriteReferencePicker.jsx';++const SOURCES = [+ { id: 'example-pioneer', name: 'Example Pioneer', path: 'reference/example-pioneer-main-v1.png' },+ { id: 'example-medic', name: 'Field Medic', path: 'reference/example-medic-main-v1.png' },+ { id: 'example-rover', name: 'Dust Rover', path: 'reference/example-rover-main-v1.png' },+];++const renderPicker = (props = {}) => render(+ <SpriteReferencePicker open onClose={vi.fn()} onSelect={vi.fn()} {...props} />,+);++const searchBox = () => screen.getByLabelText('Search reference sprites');++beforeEach(() => {+ vi.clearAllMocks();+ listSpriteReferenceSources.mockResolvedValue(SOURCES);+});++describe('SpriteReferencePicker', () => {+ it('fetches silently and drops the excluded sprite from the grid', async () => {+ renderPicker({ excludeId: 'example-pioneer' });++ expect(await screen.findByText('Field Medic')).toBeInTheDocument();+ expect(listSpriteReferenceSources).toHaveBeenCalledWith({ silent: true });+ expect(screen.getByText('Dust Rover')).toBeInTheDocument();+ expect(screen.queryByText('Example Pioneer')).not.toBeInTheDocument();+ });++ it('filters case-insensitively on the name', async () => {+ renderPicker();+ await screen.findByText('Field Medic');++ await userEvent.type(searchBox(), 'DUST');+ expect(screen.getByText('Dust Rover')).toBeInTheDocument();+ expect(screen.queryByText('Field Medic')).not.toBeInTheDocument();+ });++ it('filters on the id too, so an id-only match still resolves', async () => {+ renderPicker();+ await screen.findByText('Field Medic');++ // "example-rover" is nowhere in the display name "Dust Rover" — matching on+ // the id is what keeps a renamed sprite findable by what it's stored as.+ await userEvent.type(searchBox(), 'EXAMPLE-ROVER');+ expect(screen.getByText('Dust Rover')).toBeInTheDocument();+ expect(screen.queryByText('Field Medic')).not.toBeInTheDocument();+ expect(screen.queryByText('Example Pioneer')).not.toBeInTheDocument();+ });++ it('clears the search back to the full list', async () => {+ renderPicker();+ await screen.findByText('Field Medic');++ await userEvent.type(searchBox(), 'dust');+ expect(screen.queryByText('Field Medic')).not.toBeInTheDocument();++ await userEvent.click(screen.getByRole('button', { name: 'Clear search' }));+ expect(searchBox()).toHaveValue('');+ expect(screen.getByText('Field Medic')).toBeInTheDocument();+ });++ it('hands the whole row to onSelect and then closes', async () => {+ const order = [];+ const onSelect = vi.fn(() => order.push('select'));+ const onClose = vi.fn(() => order.push('close'));+ renderPicker({ onSelect, onClose });+ await screen.findByText('Field Medic');++ await userEvent.click(screen.getByText('Field Medic'));+ expect(onSelect).toHaveBeenCalledWith(SOURCES[1]);+ expect(order).toEqual(['select', 'close']);+ });++ it('distinguishes an empty catalog from an empty search result', async () => {+ const { unmount } = renderPicker();+ await screen.findByText('Field Medic');+ await userEvent.type(searchBox(), 'nothing matches this');+ expect(screen.getByText('No reference sprites match your search.')).toBeInTheDocument();+ unmount();++ listSpriteReferenceSources.mockResolvedValue([]);+ renderPicker();+ expect(await screen.findByText(/No sprites with a locked main reference yet/)).toBeInTheDocument();+ });++ it('falls back to an empty list when the fetch fails', async () => {+ listSpriteReferenceSources.mockRejectedValue(new Error('offline'));+ renderPicker();+ expect(await screen.findByText(/No sprites with a locked main reference yet/)).toBeInTheDocument();+ });++ it('refetches on each open and resets the search on close', async () => {+ const { rerender } = renderPicker();+ await screen.findByText('Field Medic');+ await userEvent.type(searchBox(), 'dust');++ rerender(<SpriteReferencePicker open={false} onClose={vi.fn()} onSelect={vi.fn()} />);+ rerender(<SpriteReferencePicker open onClose={vi.fn()} onSelect={vi.fn()} />);++ expect(await screen.findByText('Field Medic')).toBeInTheDocument();+ expect(searchBox()).toHaveValue('');+ expect(listSpriteReferenceSources).toHaveBeenCalledTimes(2);+ });+});diff --git a/server/routes/sprites.test.js b/server/routes/sprites.test.jsindex bc00be00d5..f4c4fa2af6 100644--- a/server/routes/sprites.test.js+++ b/server/routes/sprites.test.js@@ -373,6 +373,37 @@ describe('sprites routes', () => {expect(reference.forkSprite).toHaveBeenCalledWith('pioneer', expect.objectContaining({ name: 'Pioneer Fork', designPrompt: 'now with a red coat' }));});+ // The two bodies ForkSpriteModal.jsx actually builds — full (an id typed and a+ // backend picked) and minimal (both omitted). The client suite mocks+ // apiSprites.js, so a schema that rejected or silently stripped one of these+ // keys would stay invisible behind two green suites; the case above only+ // proves a HAND-BUILT subset. Keep these in step with the client's+ // "ForkSpriteModal wire body" cases.+ it('POST /:id/fork accepts the exact body ForkSpriteModal sends', async () => {+ const modalBody = {+ name: 'Example Settler',+ id: 'example-settler',+ designPrompt: 'wearing a wide-brim hat',+ mode: 'grok',+ initImageStrength: 0.65,+ };+ const r = await request(app).post('/api/sprites/pioneer/fork').send(modalBody);+ expect(r.status).toBe(201);+ // Exact, not objectContaining: a stripped key must fail here.+ expect(reference.forkSprite).toHaveBeenCalledWith('pioneer', modalBody);+ });++ it('POST /:id/fork accepts the modal body with id and mode omitted', async () => {+ const modalBody = {+ name: 'Example Settler',+ designPrompt: 'wearing a wide-brim hat',+ initImageStrength: 0.65,+ };+ const r = await request(app).post('/api/sprites/pioneer/fork').send(modalBody);+ expect(r.status).toBe(201);+ expect(reference.forkSprite).toHaveBeenCalledWith('pioneer', modalBody);+ });+it('POST /:id/fork rejects a missing design prompt at the schema', async () => {const bad = await request(app).post('/api/sprites/pioneer/fork').send({ name: 'Pioneer Fork' });expect(bad.status).toBe(400);