import { describe, it, expect } from 'vitest' import { adaptSession } from './adapters' import type { SessionDTO } from './adapters' function makeDTO(overrides: Partial = {}): SessionDTO { return { owner: 'bigbes', tool: 'claude-code', host: 'laptop', session_id: 'abc123', started_at: 1_000_000, ended_at: 1_001_000, source_file: '/path/to/session.jsonl', summary: 'A test session', turn_count: 5, tokens_in_total: 1234, tokens_out_total: 5678, ...overrides, } } describe('adaptSession', () => { it('started_at=0 → started="1970-01-01T00:00:00.000Z"', () => { const s = adaptSession(makeDTO({ started_at: 0, ended_at: 0 })) expect(s.started).toBe('1970-01-01T00:00:00.000Z') }) it('working_dir absent → cwd === ""', () => { const s = adaptSession(makeDTO({ working_dir: undefined })) expect(s.cwd).toBe('') }) it('model absent → model === undefined (not null)', () => { const s = adaptSession(makeDTO({ model: undefined })) expect(s.model).toBeUndefined() }) it('id is composite ${tool}/${host}/${session_id}', () => { const s = adaptSession(makeDTO({ tool: 'opencode', host: 'workpc', session_id: 'xyz789' })) expect(s.id).toBe('opencode/workpc/xyz789') const parts = s.id.split('/') expect(parts[0]).toBe('opencode') expect(parts[1]).toBe('workpc') expect(parts[2]).toBe('xyz789') }) it('ended_at === started_at → ended === null', () => { const ts = 1_000_000 const s = adaptSession(makeDTO({ started_at: ts, ended_at: ts })) expect(s.ended).toBeNull() }) it('ended_at > started_at → ended is the ISO of ended_at', () => { const startedAt = 1_000_000 const endedAt = 1_001_000 const s = adaptSession(makeDTO({ started_at: startedAt, ended_at: endedAt })) expect(s.ended).toBe(new Date(endedAt * 1000).toISOString()) }) })