import { describe, expect, it, vi } from 'vitest'; import { SessionBoundRuntime } from '../src/services/session-bound-runtime.js'; describe('SessionBoundRuntime', () => { it('starts account work only when authenticated and stops it on logout', () => { const start = vi.fn(); const stop = vi.fn(); const runtime = new SessionBoundRuntime(start, stop); expect(runtime.reconcile('login-required')).toBe(false); expect(start).not.toHaveBeenCalled(); expect(runtime.reconcile('authenticated')).toBe(true); expect(runtime.reconcile('authenticated')).toBe(true); expect(start).toHaveBeenCalledOnce(); expect(runtime.reconcile('login-required')).toBe(false); expect(stop).toHaveBeenCalledOnce(); }); it.each(['unknown', 'login-required', 'unreachable'] as const)( 'treats %s as waiting for an extension dump', (state) => { const runtime = new SessionBoundRuntime(vi.fn(), vi.fn()); expect(runtime.reconcile(state)).toBe(false); }, ); });