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: Explain replacement and startup requirements before database sync (#9752)
[._.]/ Adam Eivy954ca94ef62e
diff --git a/client/src/components/settings/DatabaseTab.jsx b/client/src/components/settings/DatabaseTab.jsxindex ada6efee2b..403d47cb83 100644--- a/client/src/components/settings/DatabaseTab.jsx+++ b/client/src/components/settings/DatabaseTab.jsx@@ -118,19 +118,34 @@ function BackendCard({ label, icon: Icon, backend, isActive, dbStatus, runAction{!isActive && (data?.installed || data?.configured) && (<>{/* Sync data from active into this backend */}- <button- onClick={() => setConfirmAction({- type: 'sync',- label: `Sync from ${activeLabel} to ${displayLabel}?`,- detail: `Copies data from the active ${activeLabel} database into ${displayLabel}. ${displayLabel} will be left in its current state (running or stopped).`,- action: () => runAction(`sync-${backend}`, syncDatabase, `Data synced from ${activeLabel} to ${displayLabel}`)- })}- disabled={busy}- className={`${btnClass} bg-port-border hover:bg-port-border/70 text-white`}- >- <RotateCw size={12} />- Sync from {activeLabel}- </button>+ {isRunning ? (+ <button+ onClick={() => setConfirmAction({+ type: 'sync',+ label: `Replace ${displayLabel} data with ${activeLabel} data?`,+ detail: `This replaces matching tables and their records in ${displayLabel} with a snapshot of ${activeLabel}; records are not merged. Back up ${displayLabel} first if you need to keep its current records. ${activeLabel} remains the active database.`,+ displayLabel,+ action: () => runAction(`sync-${backend}`, syncDatabase, `Data synced from ${activeLabel} to ${displayLabel}`)+ })}+ disabled={busy}+ className={`${btnClass} bg-port-border hover:bg-port-border/70 text-white`}+ >+ <RotateCw size={12} />+ Replace data from {activeLabel}...+ </button>+ ) : (+ <div className="flex items-center gap-2">+ <button+ disabled+ className={`${btnClass} bg-port-border/50 text-gray-500 cursor-not-allowed`}+ title={`${displayLabel} must be running to replace its data`}+ >+ <RotateCw size={12} />+ Replace data from {activeLabel}...+ </button>+ <span className="text-xs text-gray-500">Start {displayLabel} before replacing its data</span>+ </div>+ )}{/* Destroy */}{canDestroy && (@@ -139,6 +154,7 @@ function BackendCard({ label, icon: Icon, backend, isActive, dbStatus, runActiontype: 'destroy',label: `Destroy ${displayLabel} database and all its data?`,detail: 'This permanently removes the database files. You can set it up again later.',+ displayLabel,action: () => runAction(`destroy-${backend}`, () => destroyDatabase(backend), `${displayLabel} database destroyed`)})}disabled={busy}@@ -500,6 +516,7 @@ export function DatabaseTab() {type: 'migrate',label: `Migrate from ${direction.source} to ${direction.target}?`,detail: 'PortOS stops itself, transfers the data, and restarts on the new backend. This causes brief downtime and cannot be cancelled once the transfer starts.',+ targetLabel: direction.target === 'docker' ? 'Docker' : 'Native',action: () => handleMigrate(direction),})}onRecover={handleRecover}@@ -519,7 +536,7 @@ export function DatabaseTab() {{/* Confirmation dialog */}{confirmAction && (<div className={`bg-port-bg border rounded-lg p-4 space-y-3 ${- confirmAction.type === 'destroy' ? 'border-port-error/30' : 'border-port-warning/30'+ confirmAction.type === 'destroy' ? 'border-port-error/30' : confirmAction.type === 'sync' ? 'border-port-warning/30' : 'border-port-accent/20'}`}><p className="text-sm text-white">{confirmAction.label}</p>{confirmAction.detail && (@@ -532,11 +549,13 @@ export function DatabaseTab() {className={`flex items-center gap-2 px-3 py-1.5 text-sm font-medium rounded-lg transition-colors disabled:opacity-50 ${confirmAction.type === 'destroy'? 'bg-port-error/20 hover:bg-port-error/30 text-port-error'- : 'bg-port-warning/20 hover:bg-port-warning/30 text-port-warning'+ : confirmAction.type === 'sync'+ ? 'bg-port-warning/20 hover:bg-port-warning/30 text-port-warning'+ : 'bg-port-accent/20 hover:bg-port-accent/30 text-port-accent'}`}>{busy ? <BrailleSpinner /> : <ArrowRightLeft size={14} />}- Confirm+ {confirmAction.type === 'destroy' ? `Delete ${confirmAction.displayLabel} database` : confirmAction.type === 'sync' ? `Replace ${confirmAction.displayLabel} data` : `Migrate to ${confirmAction.targetLabel}`}</button><buttononClick={() => setConfirmAction(null)}diff --git a/client/src/components/settings/DatabaseTab.test.jsx b/client/src/components/settings/DatabaseTab.test.jsxindex b0be5cf3eb..d716bcd82a 100644--- a/client/src/components/settings/DatabaseTab.test.jsx+++ b/client/src/components/settings/DatabaseTab.test.jsx@@ -72,6 +72,110 @@ const renderTab = async () => {await waitFor(() => expect(screen.getByText(/Migrate Docker/i)).toBeTruthy());};+describe('DatabaseTab sync and replacement', () => {+ it('disables replace action for stopped targets and shows start requirement message', async () => {+ const stoppedDbStatus = {+ ...dbStatus,+ docker: { containerRunning: false, installed: true, daemonRunning: true },+ native: { configured: true, installed: true, running: true },+ mode: 'native',+ };+ getDatabaseStatus.mockResolvedValue(stoppedDbStatus);+ render(<DatabaseTab />);+ await waitFor(() => expect(getDatabaseStatus).toHaveBeenCalled());++ // Docker is stopped/not-active, so the replace button should be disabled with start message+ expect(screen.getByText(/Start Docker before replacing/i)).toBeTruthy();+ });++ it('enables replace action for running targets', async () => {+ const runningDbStatus = {+ ...dbStatus,+ docker: { containerRunning: true, installed: true, daemonRunning: true },+ native: { configured: true, installed: true, running: true },+ mode: 'docker',+ };+ getDatabaseStatus.mockResolvedValue(runningDbStatus);+ render(<DatabaseTab />);+ await waitFor(() => expect(getDatabaseStatus).toHaveBeenCalled());++ // Native is running and not active, so replace button should be enabled+ expect(screen.getByRole('button', { name: /Replace data from Docker/i })).toBeTruthy();+ });++ it('shows replacement warning in confirmation dialog when target is running', async () => {+ const nativeRunningStatus = {+ ...dbStatus,+ docker: { containerRunning: true, installed: true, daemonRunning: true },+ native: { configured: true, installed: true, running: true },+ mode: 'docker',+ };+ getDatabaseStatus.mockResolvedValue(nativeRunningStatus);+ render(<DatabaseTab />);+ await waitFor(() => expect(getDatabaseStatus).toHaveBeenCalled());++ fireEvent.click(screen.getByRole('button', { name: /Replace data from Docker/i }));++ expect(screen.getByText(/Replace Native data with Docker data\?/i)).toBeTruthy();+ expect(screen.getByText(/This replaces matching tables and their records/i)).toBeTruthy();+ expect(screen.getByText(/records are not merged/i)).toBeTruthy();+ expect(screen.getByText(/Back up Native first/i)).toBeTruthy();+ });++ it('uses explicit action verb "Replace Native data" in confirmation button', async () => {+ const nativeRunningStatus = {+ ...dbStatus,+ docker: { containerRunning: true, installed: true, daemonRunning: true },+ native: { configured: true, installed: true, running: true },+ mode: 'docker',+ };+ getDatabaseStatus.mockResolvedValue(nativeRunningStatus);+ render(<DatabaseTab />);+ await waitFor(() => expect(getDatabaseStatus).toHaveBeenCalled());++ fireEvent.click(screen.getByRole('button', { name: /Replace data from Docker/i }));++ expect(screen.getByRole('button', { name: /Replace Native data/i })).toBeTruthy();+ });++ it('uses explicit action verb "Delete Docker database" in destroy confirmation', async () => {+ const destroyableStatus = {+ ...dbStatus,+ docker: { containerRunning: false, installed: true, daemonRunning: true },+ native: { configured: true, installed: true, running: true },+ mode: 'native',+ };+ getDatabaseStatus.mockResolvedValue(destroyableStatus);+ render(<DatabaseTab />);+ await waitFor(() => expect(getDatabaseStatus).toHaveBeenCalled());++ fireEvent.click(screen.getByRole('button', { name: /Destroy$/i }));++ expect(screen.getByRole('button', { name: /Delete Docker database/i })).toBeTruthy();+ });++ it('cancel button does not make any request and closes dialog', async () => {+ const nativeRunningStatus = {+ ...dbStatus,+ docker: { containerRunning: true, installed: true, daemonRunning: true },+ native: { configured: true, installed: true, running: true },+ mode: 'docker',+ };+ getDatabaseStatus.mockResolvedValue(nativeRunningStatus);+ const { syncDatabase: syncDatabaseMock } = await import('../../services/api');++ render(<DatabaseTab />);+ await waitFor(() => expect(getDatabaseStatus).toHaveBeenCalled());++ fireEvent.click(screen.getByRole('button', { name: /Replace data from Docker/i }));+ fireEvent.click(screen.getByRole('button', { name: /Cancel/i }));++ expect(syncDatabaseMock).not.toHaveBeenCalled();+ // Confirmation dialog should be gone+ expect(screen.queryByText(/This replaces matching tables/i)).toBeNull();+ });+});+describe('DatabaseTab migration', () => {it('offers a migrate action when idle and reads status without a stale-poll interval', async () => {await renderTab();@@ -84,7 +188,7 @@ describe('DatabaseTab migration', () => {await renderTab();fireEvent.click(screen.getByRole('button', { name: /Migrate Docker/i }));- fireEvent.click(screen.getByRole('button', { name: /^Confirm$/i }));+ fireEvent.click(screen.getByRole('button', { name: /Migrate to Native/i }));await waitFor(() => expect(cutoverDatabase).toHaveBeenCalledWith({ source: 'docker', target: 'native' }));// Accepted only: a loading toast, never a success toast.@@ -107,7 +211,7 @@ describe('DatabaseTab migration', () => {await waitFor(() => expect(getDatabaseMaintenanceStatus).toHaveBeenCalledTimes(2));fireEvent.click(screen.getByRole('button', { name: /Migrate Docker/i }));- fireEvent.click(screen.getByRole('button', { name: /^Confirm$/i }));+ fireEvent.click(screen.getByRole('button', { name: /Migrate to Native/i }));await waitFor(() => expect(cutoverDatabase).toHaveBeenCalled());// The stale read (issued before acceptance) resolves late with idle data.