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
fix: show request-correlated ClinVar sync progress (#10062)
[._.]/ Adam Eivy056d04fa00b0
diff --git a/client/src/components/meatspace/tabs/GenomeTab.jsx b/client/src/components/meatspace/tabs/GenomeTab.jsxindex 41599c0da3..21dc6e4dbb 100644--- a/client/src/components/meatspace/tabs/GenomeTab.jsx+++ b/client/src/components/meatspace/tabs/GenomeTab.jsx@@ -2,6 +2,8 @@ import { useState, useEffect, useCallback, useRef } from 'react';import toast from '../../ui/Toast';import {Upload, Download, Trash2, Search, Dna, AlertTriangle, Save} from 'lucide-react';import BrailleSpinner from '../../BrailleSpinner';+import socket from '../../../services/socket';+import { uuidv4 } from '../../../lib/uuid';// Native ZIP parser — replaces fflate's unzipSync/strFromU8async function parseZipText(arrayBuffer, ext = '.txt') {const data = new Uint8Array(arrayBuffer);@@ -137,6 +139,12 @@ export default function GenomeTab() {const [clinvarExpanded, setClinvarExpanded] = useState({});const [clinvarFilter, setClinvarFilter] = useState('all');const [clinvarStarFilter, setClinvarStarFilter] = useState(0);+ const activeClinvarSyncRef = useRef(null);+ useEffect(() => () => {+ const active = activeClinvarSyncRef.current;+ if (active) socket.off('genome:clinvar-progress', active.onProgress);+ activeClinvarSyncRef.current = null;+ }, []);const dropRef = useRef(null);const notesTimerRef = useRef({});const jumpRef = useRef(null);@@ -318,12 +326,22 @@ export default function GenomeTab() {// ClinVar handlersconst handleClinvarSync = useCallback(async () => {+ if (activeClinvarSyncRef.current) return;+ const requestId = uuidv4();+ const onProgress = (frame) => {+ if (activeClinvarSyncRef.current?.requestId === requestId &&+ frame?.requestId === requestId && typeof frame.message === 'string') {+ setClinvarProgress(frame.message);+ }+ };+ activeClinvarSyncRef.current = { requestId, onProgress };+ socket.on('genome:clinvar-progress', onProgress);setClinvarSyncing(true);setClinvarProgress('Starting ClinVar sync...');- const result = await api.syncClinvar().catch(() => {- setClinvarProgress('');- return null;- });+ const result = await api.syncClinvar(requestId).catch(() => null);+ socket.off('genome:clinvar-progress', onProgress);+ if (activeClinvarSyncRef.current?.requestId !== requestId) return;+ activeClinvarSyncRef.current = null;if (result) {toast.success(`ClinVar synced: ${formatCount(result.variantCount)} variants indexed`);setClinvarStatus(result);diff --git a/client/src/components/meatspace/tabs/GenomeTab.test.jsx b/client/src/components/meatspace/tabs/GenomeTab.test.jsxnew file mode 100644index 0000000000..49d59b48da--- /dev/null+++ b/client/src/components/meatspace/tabs/GenomeTab.test.jsx@@ -0,0 +1,66 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';+import { act, fireEvent, render, screen, waitFor, cleanup } from '@testing-library/react';+import { afterEach } from 'vitest';++const mocks = vi.hoisted(() => ({ listeners: new Set(), sync: vi.fn(), success: vi.fn() }));+vi.mock('../../../services/socket', () => ({ default: {+ on: vi.fn((event, handler) => mocks.listeners.add(handler)),+ off: vi.fn((event, handler) => mocks.listeners.delete(handler))+} }));+vi.mock('../../../services/api', () => ({+ getGenomeSummary: vi.fn(async () => ({ uploaded: true, markers: [] })),+ getClinvarStatus: vi.fn(async () => ({ synced: false })),+ syncClinvar: mocks.sync+}));+vi.mock('../../ui/Toast', () => ({ default: { success: mocks.success } }));+vi.mock('../EpigeneticTracker', () => ({ default: () => null }));+import GenomeTab from './GenomeTab';++const emit = (frame) => act(() => { for (const handler of mocks.listeners) handler(frame); });+const begin = async () => {+ fireEvent.click(await screen.findByRole('button', { name: 'Sync ClinVar Database' }));+ return mocks.sync.mock.calls.at(-1)[0];+};+beforeEach(() => { mocks.listeners.clear(); mocks.sync.mockReset(); mocks.success.mockClear(); });+afterEach(cleanup);++describe('ClinVar progress interaction', () => {+ it('shows matching live phases, ignores other/settled runs, and trusts HTTP metadata', async () => {+ let resolve;+ mocks.sync.mockImplementationOnce(() => new Promise(r => { resolve = r; }));+ render(<GenomeTab />);+ const requestId = await begin();+ expect(mocks.listeners.size).toBe(1);+ emit({ requestId: 'other-request', message: 'Wrong run' });+ expect(screen.getByText('Starting ClinVar sync...')).toBeInTheDocument();+ for (const message of ['Downloading variants', 'Parsing variants', 'Building index']) {+ emit({ requestId, message });+ expect(screen.getByText(message)).toBeInTheDocument();+ }+ await act(async () => resolve({ synced: true, variantCount: 12 }));+ expect(screen.getByText('12 variants indexed')).toBeInTheDocument();+ expect(mocks.listeners.size).toBe(0);+ mocks.sync.mockReturnValueOnce(new Promise(() => {}));+ fireEvent.click(screen.getByRole('button', { name: 'Re-sync' }));+ emit({ requestId, message: 'Old sync' });+ expect(screen.queryByText('Old sync')).not.toBeInTheDocument();+ expect(screen.getByText('Starting ClinVar sync...')).toBeInTheDocument();+ });++ it('releases running state after failure and removes listeners across remount', async () => {+ let reject;+ mocks.sync.mockImplementationOnce(() => new Promise((_, r) => { reject = r; }));+ const view = render(<GenomeTab />);+ await begin();+ await act(async () => reject(new Error('Download failed')));+ expect(screen.queryByText('Starting ClinVar sync...')).not.toBeInTheDocument();+ expect(screen.getByRole('button', { name: 'Sync ClinVar Database' })).toBeEnabled();+ mocks.sync.mockReturnValue(new Promise(() => {}));+ await begin();+ view.unmount();+ expect(mocks.listeners.size).toBe(0);+ render(<GenomeTab />);+ await begin();+ await waitFor(() => expect(mocks.listeners.size).toBe(1));+ });+});diff --git a/client/src/services/apiMeatspace.js b/client/src/services/apiMeatspace.jsindex 4612ddfec2..4862f8bec0 100644--- a/client/src/services/apiMeatspace.js+++ b/client/src/services/apiMeatspace.js@@ -25,7 +25,7 @@ export const deleteGenomeData = () => request('/meatspace/genome', { method: 'DE// MeatSpace - Genome ClinVarexport const getClinvarStatus = () => request('/meatspace/genome/clinvar/status');-export const syncClinvar = () => request('/meatspace/genome/clinvar/sync', { method: 'POST' });+export const syncClinvar = (requestId, options) => request('/meatspace/genome/clinvar/sync', { method: 'POST', ...(requestId ? { body: JSON.stringify({ requestId }) } : {}), ...options });export const scanClinvar = () => request('/meatspace/genome/clinvar/scan', { method: 'POST' });// MeatSpace - Epigenetic Lifestyle Trackingdiff --git a/server/lib/genomeValidation.js b/server/lib/genomeValidation.jsindex 4cfb053e7e..c25ca33a75 100644--- a/server/lib/genomeValidation.js+++ b/server/lib/genomeValidation.js@@ -1,5 +1,9 @@import { z } from 'zod';+export const genomeClinvarSyncSchema = z.object({+ requestId: z.string().uuid().optional()+});+export const genomeUploadSchema = z.object({content: z.string().min(100, 'Genome file content too short'),filename: z.string().min(1, 'Filename required')diff --git a/server/lib/socketEventContracts.js b/server/lib/socketEventContracts.jsindex 9283253c46..981f73d866 100644--- a/server/lib/socketEventContracts.js+++ b/server/lib/socketEventContracts.js@@ -44,6 +44,10 @@ const loomRunSnapshot = (production) => Object.freeze({});export const SOCKET_EVENT_CONTRACTS = Object.freeze({+ 'genome:clinvar-progress': {+ direction: 'server-to-client', summary: 'ClinVar download and indexing progress for an optional client request ID.',+ payloadSchema: { type: 'object', required: ['message'], properties: { message: { type: 'string' }, requestId: { type: 'string', format: 'uuid' } } },+ },'music-video:song-revision': {direction: 'server-to-client', summary: 'A song revision changed; apply the persisted project snapshot.',payloadSchema: { type: 'object', required: ['projectId', 'project'], properties: { projectId: { type: 'string' }, project: { type: 'object' } } },diff --git a/server/routes/genome.js b/server/routes/genome.jsindex 4491f74509..3865f0b827 100644--- a/server/routes/genome.js+++ b/server/routes/genome.js@@ -6,6 +6,7 @@ import { asyncHandler, ServerError } from '../lib/errorHandler.js';import { validateRequest } from '../lib/validation.js';import {genomeUploadSchema,+ genomeClinvarSyncSchema,genomeSearchSchema,genomeSaveMarkerSchema,genomeUpdateNotesSchema,@@ -100,9 +101,10 @@ router.get('/clinvar/status', asyncHandler(async (req, res) => {// POST /api/meatspace/genome/clinvar/sync — Download and index ClinVar databaserouter.post('/clinvar/sync', asyncHandler(async (req, res) => {+ const { requestId } = validateRequest(genomeClinvarSyncSchema, req.body ?? {});const io = req.app.get('io');const onProgress = (message) => {- if (io) io.emit('genome:clinvar-progress', { message });+ if (io) io.emit('genome:clinvar-progress', { message, ...(requestId ? { requestId } : {}) });};const result = await clinvarService.syncClinvar(onProgress);diff --git a/server/routes/genome.test.js b/server/routes/genome.test.jsindex e077fd672a..c5a3f4ab59 100644--- a/server/routes/genome.test.js+++ b/server/routes/genome.test.js@@ -8,6 +8,8 @@ vi.mock('../services/genome.js', () => ({}));vi.mock('../services/clinvar.js', () => ({+ syncClinvar: vi.fn(),+ invalidateClinvarCache: vi.fn(),deleteClinvar: vi.fn(async () => undefined),}));@@ -23,7 +25,7 @@ vi.mock('../services/epigenetic.js', () => ({}));const { deleteGenome } = await import('../services/genome.js');-const { deleteClinvar } = await import('../services/clinvar.js');+const { deleteClinvar, syncClinvar } = await import('../services/clinvar.js');const { logEntry } = await import('../services/epigenetic.js');const { default: genomeRoutes } = await import('./genome.js');@@ -93,3 +95,29 @@ describe('POST /api/meatspace/genome/epigenetic/:id/log', () => {});});});+++describe('ClinVar sync progress', () => {+ beforeEach(() => vi.clearAllMocks());++ it.each([undefined, { requestId: '11111111-1111-4111-8111-111111111111' }])('preserves legacy POST and correlates progress for %j', async (body) => {+ const app = makeApp();+ const emit = vi.fn();+ app.set('io', { emit });+ syncClinvar.mockImplementationOnce(async (onProgress) => {+ onProgress('Indexing variants');+ return { synced: true, variantCount: 12 };+ });+ const req = request(app).post('/api/meatspace/genome/clinvar/sync');+ const response = await (body ? req.send(body) : req);+ expect(response.status).toBe(200);+ expect(response.body).toEqual({ synced: true, variantCount: 12 });+ expect(emit).toHaveBeenCalledWith('genome:clinvar-progress', { message: 'Indexing variants', ...body });+ });++ it('rejects malformed correlation IDs before starting a sync', async () => {+ const response = await request(makeApp()).post('/api/meatspace/genome/clinvar/sync').send({ requestId: 123 });+ expect(response.status).toBe(400);+ expect(syncClinvar).not.toHaveBeenCalled();+ });+});