package com.easyagents.skill.validation;

import com.easyagents.skill.exception.SkillValidationException;
import org.junit.Assert;
import org.junit.Test;

/**
 * {@link SkillValidationReport} 命令式异常契约测试。
 */
public class SkillValidationReportTest {

    /**
     * 验证异常 getter 暴露首个错误定位，同时保留包含全部问题的报告。
     */
    @Test
    public void throwIfInvalidKeepsFirstErrorLocationAndCompleteReport() {
        SkillValidationReport report = new SkillValidationReport()
                .add(new SkillValidationIssue("DRAFT_WARNING", SkillValidationSeverity.WARNING,
                        "draft/SKILL.md", 1, 1, "草稿警告", null))
                .add(new SkillValidationIssue("FIRST_ERROR", SkillValidationSeverity.ERROR,
                        "demo/SKILL.md", 4, 7, "首个错误", "修复首个错误"))
                .add(new SkillValidationIssue("SECOND_ERROR", SkillValidationSeverity.ERROR,
                        "demo/scripts/run.sh", 2, 3, "第二个错误", null));

        try {
            report.throwIfInvalid();
            Assert.fail("应抛出 SkillValidationException");
        } catch (SkillValidationException exception) {
            Assert.assertEquals("FIRST_ERROR", exception.getCode());
            Assert.assertEquals("demo/SKILL.md", exception.getPath());
            Assert.assertEquals(Integer.valueOf(4), exception.getLine());
            Assert.assertEquals(Integer.valueOf(7), exception.getColumn());
            Assert.assertSame(report, exception.getReport());
            Assert.assertEquals(3, exception.getReport().getIssues().size());
        }
    }
}
