import assert from 'node:assert/strict'
import test from 'node:test'

import {
  buildRuntimePatch,
  getRuntimePreset,
  listRuntimePresets,
  normalizePresetCode,
} from './runtime-presets.mjs'

test('runtime presets expose classroom local runtimes', () => {
  const codes = listRuntimePresets().map(p => p.code)
  assert.deepEqual(codes, ['codex', 'qoder', 'claude-code', 'codebuddy', 'trae', 'custom'])
})

test('codex preset renders stdin execution in the skill session workdir', () => {
  const preset = getRuntimePreset('codex')
  assert.equal(preset.runtimeCode, 'local-codex')
  assert.equal(preset.command, 'codex')
  assert.ok(preset.args.includes('--json'))
  assert.ok(preset.args.includes('{workdir}'))
  assert.ok(preset.args.includes('-'))
})

test('qoder aliases normalize to the qoder preset', () => {
  assert.equal(normalizePresetCode('qoder'), 'qoder')
  assert.equal(normalizePresetCode('qodr'), 'qoder')
  assert.equal(normalizePresetCode('qoder-cloud-agent'), 'qoder')
})

test('buildRuntimePatch creates API-ready local runtime payload', () => {
  const patch = buildRuntimePatch('qoder', { command: '/usr/local/bin/qoder', enabled: true })
  assert.deepEqual(patch, {
    name: '本地 Qoder',
    command: '/usr/local/bin/qoder',
    args: ['-'],
    healthcheckArgs: ['--version'],
    purposeScopes: ['create', 'evaluate', 'run'],
    timeoutMs: 300000,
    enabled: true,
    notes: 'Lite 学员包本地运行时：通过 stdin 接收 AIPROS Skill 任务，在会话工作目录生成文件产物。',
  })
})
