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 { useState } from 'react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
// Mock the API so a suggest/proposal call returns a deterministic usage count.
const suggestWritersRoomContinuation = vi.fn();
const suggestWritersRoomCdBridge = vi.fn();
const sendWritersRoomCdBridge = vi.fn();
vi.mock('../../services/apiWritersRoom', () => ({
suggestWritersRoomContinuation: (...args) => suggestWritersRoomContinuation(...args),
suggestWritersRoomCdBridge: (...args) => suggestWritersRoomCdBridge(...args),
sendWritersRoomCdBridge: (...args) => sendWritersRoomCdBridge(...args),
}));
import LiveContinuationPanel from './LiveContinuationPanel';
import CdBridgePanel from './CdBridgePanel';
beforeEach(() => {
suggestWritersRoomContinuation.mockReset();
suggestWritersRoomCdBridge.mockReset();
sendWritersRoomCdBridge.mockReset();
});
const liveMode = { enabled: true, dailyCallBudget: 100, usage: { count: 0 } };
const getCursorContext = () => ({ before: 'Some prose before. ', after: '', selection: '' });
// Harness mirrors WorkEditor's lifted shared-usage state: a single `liveUsage`
// owned by the parent, passed to both panels with one setter.
function Harness() {
const [liveUsage, setLiveUsage] = useState(liveMode.usage);
return (
<MemoryRouter>
<LiveContinuationPanel
workId="wr-work-1"
liveMode={liveMode}
usage={liveUsage}
onUsageChange={setLiveUsage}
getCursorContext={getCursorContext}
onInsert={() => {}}
registerTrigger={() => {}}
/>
<CdBridgePanel
workId="wr-work-1"
liveMode={liveMode}
usage={liveUsage}
onUsageChange={setLiveUsage}
getCursorContext={getCursorContext}
onLinked={() => {}}
/>
</MemoryRouter>
);
}
describe('live text-suggest budget shares across panels', () => {
it('a continuation suggest updates the CD bridge readout too', async () => {
suggestWritersRoomContinuation.mockResolvedValue({ options: [], usage: { count: 7 } });
render(<Harness />);
// Both panels start at the full budget. Each readout names the budget it
// reports in visible text (#3567), so match the labeled strings.
expect(screen.getByText('Suggestions: 100 / 100 left today')).toBeInTheDocument();
expect(screen.getByText('Suggestions (shared): 100 / 100 left today')).toBeInTheDocument();
// Spend budget from the continuation panel.
fireEvent.click(screen.getByRole('button', { name: 'Suggest a continuation from the cursor' }));
// BOTH readouts reflect the new count — the CD bridge panel did NOT make
// the call but still updates because the counter is lifted into the parent.
await waitFor(() => {
expect(screen.getByText('Suggestions: 93 / 100 left today')).toBeInTheDocument();
expect(screen.getByText('Suggestions (shared): 93 / 100 left today')).toBeInTheDocument();
});
});
it('a CD bridge proposal updates the continuation readout too', async () => {
suggestWritersRoomCdBridge.mockResolvedValue({ proposal: null, usage: { count: 12 } });
render(<Harness />);
fireEvent.click(screen.getByRole('button', { name: 'Propose treatment: Turns the prose at your cursor into a Creative Director treatment' }));
await waitFor(() => {
expect(screen.getByText('Suggestions: 88 / 100 left today')).toBeInTheDocument();
expect(screen.getByText('Suggestions (shared): 88 / 100 left today')).toBeInTheDocument();
});
});
});