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
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import DependencyImpactPanel from './DependencyImpactPanel.jsx';
import { getMusicVideoDependencyImpact } from '../../services/apiMusicVideo.js';
vi.mock('../../services/apiMusicVideo.js', () => ({ getMusicVideoDependencyImpact: vi.fn() }));
const project = { id: 'example-project', scenes: [{ sceneId: 'a', label: 'Example shot' }], revisions: [] };
const impact = { basis: 'example-basis', shots: [{ sceneId: 'a', reasons: ['Selected plate changed'] }], evidence: [{ id: 'old-review' }], estimate: { maxGenerations: 1, outputSeconds: 5, evidenceRebuilds: 1 } };
beforeEach(() => vi.clearAllMocks());
describe('rendered stale impact', () => {
it('shows cause, downstream impact and a bounded estimate before the explicit repair action', async () => {
getMusicVideoDependencyImpact.mockResolvedValue(impact);
const repair = vi.fn();
render(<DependencyImpactPanel project={project} onRepair={repair} />);
await screen.findByRole('region', { name: 'Stale asset impact' });
expect(screen.getByText(/Example shot: Selected plate changed/)).toBeInTheDocument();
expect(screen.getByText(/Up to 1 clip submissions.*5 seconds.*1 evidence/)).toBeInTheDocument();
expect(repair).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole('button', { name: 'Repair affected dependencies' }));
expect(repair).toHaveBeenCalledWith('example-basis');
});
it('shows the impact as unavailable, with no error or retry, when host control is refused', async () => {
getMusicVideoDependencyImpact.mockRejectedValue(Object.assign(new Error('Host control requires an operator session.'), { code: 'HOST_CONTROL_FORBIDDEN', status: 403 }));
render(<DependencyImpactPanel project={project} onRepair={vi.fn()} />);
expect(await screen.findByText(/Asset dependency check needs an operator session/)).toBeInTheDocument();
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Repair affected dependencies' })).not.toBeInTheDocument();
expect(getMusicVideoDependencyImpact).toHaveBeenCalledWith('example-project', { silent: true, hostControlOptional: true });
});
it('says no clips are needed when only review evidence is stale', async () => {
getMusicVideoDependencyImpact.mockResolvedValue({ ...impact, shots: [], estimate: { maxGenerations: 0, outputSeconds: 0, evidenceRebuilds: 2 } });
render(<DependencyImpactPanel project={project} onRepair={vi.fn()} />);
expect(await screen.findByText(/No new clips needed; 2 evidence records/)).toBeInTheDocument();
expect(screen.queryByText(/Up to 0 clip/)).not.toBeInTheDocument();
});
it('drops an older project response and keeps an active repair disabled', async () => {
let resolveOld;
getMusicVideoDependencyImpact.mockReturnValueOnce(new Promise((resolve) => { resolveOld = resolve; })).mockResolvedValueOnce(impact);
const { rerender } = render(<DependencyImpactPanel project={project} onRepair={vi.fn()} />);
rerender(<DependencyImpactPanel project={{ ...project, id: 'new-project', revisions: [{ status: 'open' }] }} onRepair={vi.fn()} />);
await screen.findByRole('region', { name: 'Stale asset impact' });
resolveOld({ shots: [], evidence: [] });
await waitFor(() => expect(screen.getByRole('button', { name: 'Repair affected dependencies' })).toBeDisabled());
});
it('says WHY Repair is disabled while a revision is open, and offers it again once that is gone (#9940)', async () => {
getMusicVideoDependencyImpact.mockResolvedValue(impact);
const { rerender } = render(<DependencyImpactPanel project={{ ...project, revisions: [{ id: 'mvrev-open', status: 'open' }] }} onRepair={vi.fn()} />);
const button = await screen.findByRole('button', { name: 'Repair affected dependencies' });
expect(button).toBeDisabled();
expect(button).toHaveAccessibleDescription(/A revision is already open — resume or cancel it/);
rerender(<DependencyImpactPanel project={{ ...project, revisions: [{ id: 'mvrev-open', status: 'canceled' }] }} onRepair={vi.fn()} />);
await waitFor(() => expect(screen.getByRole('button', { name: 'Repair affected dependencies' })).toBeEnabled());
expect(screen.queryByText(/already open/)).not.toBeInTheDocument();
});
});