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

import {
  buildCreatorSystemPrompt,
  chooseEvaluationReadTargets,
  SKILL_EVALUATOR_RUNTIME_CONTRACT,
  SKILL_RUNNER_RUNTIME_CONTRACT,
} from './skill-run.js'

test('creator system prompt passes configured agent skill through without platform output contracts', () => {
  const prompt = buildCreatorSystemPrompt([
    '# Configured Skill Creator',
    '直接完成用户交给智能体的任务。',
  ].join('\n'))

  assert.match(prompt, /Configured Skill Creator/)
  assert.match(prompt, /直接完成用户交给智能体的任务/)
  assert.doesNotMatch(prompt, /skill\.spec\.json|output_schema|evaluation_rubric|最终交付只能|平台会把 spec 编译/)
})

test('runner runtime contract forbids prose-only fake tool execution', () => {
  assert.match(SKILL_RUNNER_RUNTIME_CONTRACT, /真实运行/)
  assert.match(SKILL_RUNNER_RUNTIME_CONTRACT, /必须真实发起对应工具调用/)
  assert.match(SKILL_RUNNER_RUNTIME_CONTRACT, /禁止在正文里模拟工具调用格式/)
  assert.match(SKILL_RUNNER_RUNTIME_CONTRACT, /没有收到工具结果前/)
})

test('evaluator runtime contract forces real package file inspection', () => {
  assert.match(SKILL_EVALUATOR_RUNTIME_CONTRACT, /真实评测/)
  assert.match(SKILL_EVALUATOR_RUNTIME_CONTRACT, /必须先调用 list_files/)
  assert.match(SKILL_EVALUATOR_RUNTIME_CONTRACT, /必须调用 read_file 阅读 SKILL\.md、examples\.md、rubric\.md、skill\.spec\.json/)
  assert.match(SKILL_EVALUATOR_RUNTIME_CONTRACT, /不允许只根据用户消息或历史印象评分/)
  assert.match(SKILL_EVALUATOR_RUNTIME_CONTRACT, /不得使用固定分、历史分或模板化评分/)
})

test('evaluation preflight reads the structured source spec with the standard package files', () => {
  assert.deepEqual(chooseEvaluationReadTargets([
    'rubric.md',
    'skill.spec.json',
    'examples.md',
    'SKILL.md',
    'notes.txt',
  ]), [
    'SKILL.md',
    'examples.md',
    'rubric.md',
    'skill.spec.json',
  ])
})
