|
| 1 | +package report |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/agent-ecosystem/skill-validator/types" |
| 8 | +) |
| 9 | + |
| 10 | +func compactFixture(dir string, results ...types.Result) *types.Report { |
| 11 | + r := &types.Report{ |
| 12 | + SkillDir: dir, |
| 13 | + Results: results, |
| 14 | + TokenCounts: []types.TokenCount{{File: "SKILL.md", Tokens: 100}}, |
| 15 | + ContentReport: &types.ContentReport{WordCount: 10}, |
| 16 | + ContaminationReport: &types.ContaminationReport{ContaminationLevel: "low"}, |
| 17 | + } |
| 18 | + r.Tally() |
| 19 | + return r |
| 20 | +} |
| 21 | + |
| 22 | +func TestPrintCompact_Passed(t *testing.T) { |
| 23 | + r := compactFixture("my-skill", |
| 24 | + types.Result{Level: types.Pass, Category: "Structure", Message: "SKILL.md found"}, |
| 25 | + types.Result{Level: types.Info, Category: "Structure", Message: "fyi"}, |
| 26 | + ) |
| 27 | + |
| 28 | + var buf strings.Builder |
| 29 | + PrintCompact(&buf, r) |
| 30 | + out := buf.String() |
| 31 | + |
| 32 | + if !strings.Contains(out, "✓ my-skill: passed") { |
| 33 | + t.Errorf("expected one-line passed summary, got:\n%s", out) |
| 34 | + } |
| 35 | + if got := strings.Count(out, "\n"); got != 1 { |
| 36 | + t.Errorf("a passing skill should occupy one line, got %d:\n%s", got, out) |
| 37 | + } |
| 38 | + if strings.Contains(out, "SKILL.md found") || strings.Contains(out, "fyi") { |
| 39 | + t.Errorf("pass and info findings should be omitted:\n%s", out) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func TestPrintCompact_ListsWarningsAndErrors(t *testing.T) { |
| 44 | + r := compactFixture("my-skill", |
| 45 | + types.Result{Level: types.Pass, Category: "Structure", Message: "SKILL.md found"}, |
| 46 | + types.Result{Level: types.Error, Category: "Links", Message: "broken link: ./gone.md"}, |
| 47 | + types.Result{Level: types.Warning, Category: "Structure", Message: "unknown directory: extras/"}, |
| 48 | + ) |
| 49 | + |
| 50 | + var buf strings.Builder |
| 51 | + PrintCompact(&buf, r) |
| 52 | + lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n") |
| 53 | + |
| 54 | + if len(lines) != 3 { |
| 55 | + t.Fatalf("expected a summary line plus two findings, got %d lines:\n%s", len(lines), buf.String()) |
| 56 | + } |
| 57 | + if !strings.Contains(lines[0], "✗ my-skill: ") || |
| 58 | + !strings.Contains(lines[0], "1 error") || !strings.Contains(lines[0], "1 warning") { |
| 59 | + t.Errorf("summary line should carry both counts, got: %s", lines[0]) |
| 60 | + } |
| 61 | + for _, line := range lines[1:] { |
| 62 | + if !strings.HasPrefix(line, " ") { |
| 63 | + t.Errorf("findings should be indented under the summary, got: %q", line) |
| 64 | + } |
| 65 | + } |
| 66 | + if !strings.Contains(lines[1], "broken link: ./gone.md") { |
| 67 | + t.Errorf("expected the error message, got: %s", lines[1]) |
| 68 | + } |
| 69 | + if !strings.Contains(lines[2], "unknown directory: extras/") { |
| 70 | + t.Errorf("expected the warning message, got: %s", lines[2]) |
| 71 | + } |
| 72 | + if strings.Contains(buf.String(), "SKILL.md found") { |
| 73 | + t.Errorf("pass findings should be omitted:\n%s", buf.String()) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +func TestPrintCompact_OmitsAnalysisSections(t *testing.T) { |
| 78 | + r := compactFixture("my-skill", |
| 79 | + types.Result{Level: types.Warning, Category: "Structure", Message: "meh"}, |
| 80 | + ) |
| 81 | + r.OtherTokenCounts = []types.TokenCount{{File: "extra.md", Tokens: 50}} |
| 82 | + |
| 83 | + var buf strings.Builder |
| 84 | + PrintCompact(&buf, r) |
| 85 | + out := buf.String() |
| 86 | + |
| 87 | + for _, unwanted := range []string{"Tokens", "Content Analysis", "Contamination Analysis", "Validating skill"} { |
| 88 | + if strings.Contains(out, unwanted) { |
| 89 | + t.Errorf("compact output should omit %q:\n%s", unwanted, out) |
| 90 | + } |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +func TestPrintCompact_WarningOnlyUsesWarningIcon(t *testing.T) { |
| 95 | + r := compactFixture("my-skill", |
| 96 | + types.Result{Level: types.Warning, Category: "Structure", Message: "meh"}, |
| 97 | + ) |
| 98 | + |
| 99 | + var buf strings.Builder |
| 100 | + PrintCompact(&buf, r) |
| 101 | + out := buf.String() |
| 102 | + |
| 103 | + if !strings.Contains(out, "⚠ my-skill: 1 warning") { |
| 104 | + t.Errorf("expected warning icon and count, got:\n%s", out) |
| 105 | + } |
| 106 | + if strings.Contains(out, "✗") { |
| 107 | + t.Errorf("a warning-only report should not use the error icon:\n%s", out) |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +func TestPrintMultiCompact(t *testing.T) { |
| 112 | + mr := &types.MultiReport{ |
| 113 | + Skills: []*types.Report{ |
| 114 | + compactFixture("a"), |
| 115 | + compactFixture("b", types.Result{Level: types.Warning, Category: "Structure", Message: "meh"}), |
| 116 | + compactFixture("c"), |
| 117 | + }, |
| 118 | + } |
| 119 | + for _, r := range mr.Skills { |
| 120 | + mr.Errors += r.Errors |
| 121 | + mr.Warnings += r.Warnings |
| 122 | + } |
| 123 | + |
| 124 | + var buf strings.Builder |
| 125 | + PrintMultiCompact(&buf, mr) |
| 126 | + out := buf.String() |
| 127 | + |
| 128 | + if !strings.Contains(out, "✓ a: passed") || !strings.Contains(out, "✓ c: passed") { |
| 129 | + t.Errorf("expected one-line summaries for passing skills, got:\n%s", out) |
| 130 | + } |
| 131 | + if !strings.Contains(out, "⚠ b: 1 warning") || !strings.Contains(out, " ") { |
| 132 | + t.Errorf("expected the failing skill's finding indented, got:\n%s", out) |
| 133 | + } |
| 134 | + if strings.Contains(out, strings.Repeat("━", 60)) { |
| 135 | + t.Errorf("compact output should not draw separators:\n%s", out) |
| 136 | + } |
| 137 | + if !strings.Contains(out, "3 skills validated") || !strings.Contains(out, "Total: ") { |
| 138 | + t.Errorf("expected the overall summary, got:\n%s", out) |
| 139 | + } |
| 140 | +} |
0 commit comments