import { describe, expect, it } from 'vitest';
import { ManualClock, OfficeRuntime, memoryLogger } from '../src/index.ts';
import { advance, demoOffice, iso } from './helpers.ts';

const hook = { project: 'PixelOffice', projectDir: '/x/PixelOffice', slot: '%1' };

describe('restoreState (спека хостинга 4.2 п. 6)', () => {
  it('снимок из памяти: статусы, агенты, люди сразу на местах; журнал не нужен', () => {
    const clock = new ManualClock();
    const a = new OfficeRuntime({ office: demoOffice(), clock, log: memoryLogger() });
    a.ingestFromSource(a.sourceByName('manual')!, [{ type: 'status', entityId: 'p6', status: 'online', at: iso(clock) }]);
    a.ingestFromSource(a.sourceByName('claude-hook')!, [{ type: 'status', agent: hook, status: 'working', at: iso(clock) }]);
    advance(a, clock, 2000);
    const b = new OfficeRuntime({ office: demoOffice(), clock, log: memoryLogger() });
    b.restoreState(a.persistedState());
    expect(b.store.get('p6')?.status).toBe('online');
    expect(b.store.get('agent:p1:PixelOffice:%1')?.status).toBe('working');
    const p6 = b.hello().characters.find((c) => c.id === 'p6');
    expect(p6?.pose).toBe('sit'); // bootstrap: сразу на своём месте, без шествия от входа
  });
});
