feat: add scan mode so conversations stay in sync without sending
Stopping the bot previously halted conversation syncing too. On the
multi-account path the run-flag check sat above both the reply-sync and
response-check branches, so a stop left only MediaSyncService's coarse
30-minute chat refresh. The legacy single-account path did the opposite
and kept syncing while stopped — one boolean meaning two things.
Replace the boolean with an explicit three-way mode:
running — discover, screen, send, automate replies
scan — refresh chats, detect replies, check responses; send nothing
and discover nothing; actionable replies surface as backlog
stopped — everything halts, including background media sync
scan differs from browser.dryRun, which still discovers and pays for AI
screening before suppressing the send.
The mode persists in runtime_state.bot_mode; a migration backfills it
from bot_running, and rows written by an older build still read
correctly. Both loops now gate on the mode, the account runtime loop
reconciles background media sync on transitions only, and the dashboard
and agent API expose all three states.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a40651930
commit
14d92e14ee
38 files changed
+724
-140
No files matched your search
@@ -12,6 +12,7 @@ import { createDashboardRoutes } from '../../apps/dashboard/src/app/router.js';
|
||||
|
||||
interface TestStatsOverrides {
|
||||
isRunning?: boolean;
|
||||
mode?: 'running' | 'scan' | 'stopped';
|
||||
recentActivity?: readonly unknown[];
|
||||
accounts?: readonly unknown[];
|
||||
}
|
||||
@@ -21,6 +22,7 @@ const server = setupServer();
|
||||
function createStats(overrides: TestStatsOverrides = {}) {
|
||||
return {
|
||||
isRunning: overrides.isRunning ?? false,
|
||||
mode: overrides.mode ?? (overrides.isRunning ? 'running' : 'stopped'),
|
||||
dryRunMode: true,
|
||||
totalProcessed: 18,
|
||||
totalMessagesSent: 12,
|
||||
@@ -402,9 +404,9 @@ describe('dashboard foundation', () => {
|
||||
installSuccessfulApi();
|
||||
let startRequests = 0;
|
||||
server.use(
|
||||
http.post('/api/start', () => {
|
||||
http.post('/api/mode', () => {
|
||||
startRequests += 1;
|
||||
return HttpResponse.json({ success: true, running: true });
|
||||
return HttpResponse.json({ success: true, running: true, mode: 'running' });
|
||||
}),
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
@@ -424,10 +426,32 @@ describe('dashboard foundation', () => {
|
||||
expect(startRequests).toBe(1);
|
||||
});
|
||||
|
||||
it('offers scan mode alongside start and posts the chosen mode', async () => {
|
||||
installSuccessfulApi();
|
||||
let requested: string | null = null;
|
||||
server.use(
|
||||
http.post('/api/mode', async ({ request }) => {
|
||||
requested = ((await request.json()) as { mode: string }).mode;
|
||||
return HttpResponse.json({ success: true, running: false, mode: 'scan' });
|
||||
}),
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
renderDashboard();
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Scan mode' }));
|
||||
const dialog = screen.getByRole('dialog', { name: 'Switch to scan mode?' });
|
||||
expect(dialog).toHaveTextContent('nothing is sent');
|
||||
|
||||
await user.click(within(dialog).getByRole('button', { name: 'Confirm scan mode' }));
|
||||
|
||||
expect(await screen.findByText('Scanning', { selector: '[data-bot-status]' })).toBeInTheDocument();
|
||||
expect(requested).toBe('scan');
|
||||
});
|
||||
|
||||
it('shows a start failure inside the confirmation dialog instead of a stray toast', async () => {
|
||||
installSuccessfulApi();
|
||||
server.use(
|
||||
http.post('/api/start', () => HttpResponse.json({ error: 'Browser runtime is not ready' }, { status: 503 })),
|
||||
http.post('/api/mode', () => HttpResponse.json({ error: 'Browser runtime is not ready' }, { status: 503 })),
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
renderDashboard();
|
||||
|
||||
@@ -4,16 +4,23 @@ import { deriveShellStatus } from '../../apps/dashboard/src/app/shell-status.js'
|
||||
describe('global shell status', () => {
|
||||
it('derives safety-critical labels from authoritative snapshots', () => {
|
||||
expect(deriveShellStatus({
|
||||
stats: { isRunning: true, dryRunMode: true, invitationCooldown: { reason: 'Reddit cooldown' } },
|
||||
stats: { mode: 'running', dryRunMode: true, invitationCooldown: { reason: 'Reddit cooldown' } },
|
||||
reddit: { ready: true, loggedIn: true, status: 'authenticated' },
|
||||
realtime: { status: 'reconnecting', isStale: true },
|
||||
sync: { syncing: true, syncingKind: 'full' },
|
||||
})).toEqual({
|
||||
bot: 'Running (dry run)', reddit: 'Reddit authenticated', realtime: 'Realtime reconnecting (stale)',
|
||||
cooldown: 'Reddit cooldown', sync: 'Full sync active', controlAction: 'stop', controlDisabled: false,
|
||||
cooldown: 'Reddit cooldown', sync: 'Full sync active', controlAction: 'stopped', controlDisabled: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('labels scan mode and offers a full start as the next step', () => {
|
||||
expect(deriveShellStatus({
|
||||
stats: { mode: 'scan', dryRunMode: false, invitationCooldown: null },
|
||||
realtime: { status: 'connected', isStale: false },
|
||||
})).toMatchObject({ bot: 'Scanning', controlAction: 'running' });
|
||||
});
|
||||
|
||||
it('guards bot controls until the authoritative bot state is available', () => {
|
||||
expect(deriveShellStatus({ realtime: { status: 'idle', isStale: true } })).toMatchObject({
|
||||
bot: 'Bot state unavailable', controlDisabled: true,
|
||||
|
||||
Reference in new issue
Block a user