import { describe, expect, it } from 'vitest'
import {
  extractStrictRespondText,
  unwrapStrictRespondText,
} from '../src/dimsdk/core/strict-respond.ts'

describe('strict respond helpers', () => {
  it('extracts text from direct strict respond JSON', () => {
    expect(
      extractStrictRespondText('{"kind":"respond","text":"hello"}'),
    ).toBe('hello')
  })

  it('extracts text from fenced strict respond JSON', () => {
    expect(
      extractStrictRespondText('```json\n{"kind":"respond","text":"hello"}\n```'),
    ).toBe('hello')
  })

  it('extracts text from JSON-stringified strict respond JSON', () => {
    expect(
      extractStrictRespondText(
        JSON.stringify('{"kind":"respond","text":"hello"}'),
      ),
    ).toBe('hello')
  })

  it('falls back to the original value when no strict respond payload exists', () => {
    expect(unwrapStrictRespondText('plain text')).toBe('plain text')
  })
})
