import { describe, expect, it } from 'vitest';

// Tests for the session start payload shape used by the WebUI
// Verifies the contract between server and frontend

describe('WebUI session.start payload contract', () => {
  it('has all required fields for frontend status bar', () => {
    const required = ['sessionId', 'model', 'provider', 'maxContext', 'projectName', 'cwd', 'mode', 'wsToken'];
    const sample = {
      sessionId: 'sess-123',
      model: 'claude-sonnet',
      provider: 'anthropic',
      maxContext: 200000,
      inputCost: 3,
      outputCost: 15,
      cacheReadCost: 0.3,
      projectName: 'myproject',
      cwd: '/tmp/myproject',
      mode: 'default',
      wsToken: 'abc123',
    };
    for (const field of required) {
      expect(sample).toHaveProperty(field);
    }
  });

  it('wsToken is a 32-char hex string', () => {
    // Token generated by randomBytes(16).toString('hex') = 32 hex chars
    const hexRe = /^[a-f0-9]{32}$/;
    expect(hexRe.test('a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6')).toBe(true);
    expect(hexRe.test('short')).toBe(false);
    expect(hexRe.test('not-hex-gggg-zzzz-1234567890123456')).toBe(false);
  });
});
