~bigbes/lethe

ref: a93ad6a09c0fb5f4ca9323e61cc5bd8efb26c19d lethe/web/src/api/adapters.test.ts -rw-r--r-- 1.9 KiB
a93ad6a0 — Eugene Blikh docs(lethe-web-ui-foundation): record execute deviations across all 6 phases a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { describe, it, expect } from 'vitest'
import { adaptSession } from './adapters'
import type { SessionDTO } from './adapters'

function makeDTO(overrides: Partial<SessionDTO> = {}): 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())
  })
})