Skip to content

Commit 8f51dd0

Browse files
spboyerCopilot
andcommitted
fix: address PR #92 coverage command review comments
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f3aa0c4 commit 8f51dd0

4 files changed

Lines changed: 52 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ Generate a skill-to-eval coverage grid showing which skills are fully covered, p
281281
| Flag | Short | Description |
282282
|------|-------|-------------|
283283
| `--format <fmt>` | `-f` | Output format: `text`, `markdown`, or `json` (default: `text`) |
284-
| `--discover <dir>` | | Additional directory to scan for skills/evals (repeatable) |
284+
| `--path <dir>` | | Additional directory to scan for skills/evals (repeatable) |
285285

286286
### `waza cache clear`
287287

cmd/waza/cmd_coverage.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func discoverSkillFiles(root string, discoverPaths []string) (map[string]string,
204204
}
205205
err := filepath.WalkDir(sr, func(path string, d fs.DirEntry, err error) error {
206206
if err != nil {
207-
return nil
207+
return fmt.Errorf("error walking %s: %w", path, err)
208208
}
209209
if d.IsDir() {
210210
name := d.Name()
@@ -216,7 +216,10 @@ func discoverSkillFiles(root string, discoverPaths []string) (map[string]string,
216216
if d.Name() != "SKILL.md" {
217217
return nil
218218
}
219-
absPath, _ := filepath.Abs(path)
219+
absPath, absErr := filepath.Abs(path)
220+
if absErr != nil {
221+
absPath = filepath.Clean(path)
222+
}
220223
if _, ok := seenPaths[absPath]; ok {
221224
return nil
222225
}
@@ -252,7 +255,7 @@ func discoverEvalFiles(root string, skillPaths map[string]string, discoverPaths
252255
}
253256
if err := filepath.WalkDir(evalRoot, func(path string, d fs.DirEntry, err error) error {
254257
if err != nil {
255-
return nil
258+
return fmt.Errorf("error walking %s: %w", path, err)
256259
}
257260
if d.IsDir() {
258261
name := d.Name()
@@ -262,7 +265,10 @@ func discoverEvalFiles(root string, skillPaths map[string]string, discoverPaths
262265
return nil
263266
}
264267
if d.Name() == "eval.yaml" || d.Name() == "eval.yml" {
265-
absPath, _ := filepath.Abs(path)
268+
absPath, absErr := filepath.Abs(path)
269+
if absErr != nil {
270+
absPath = filepath.Clean(path)
271+
}
266272
candidates[absPath] = struct{}{}
267273
}
268274
return nil
@@ -280,7 +286,10 @@ func discoverEvalFiles(root string, skillPaths map[string]string, discoverPaths
280286
} {
281287
p := filepath.Join(skillDir, rel)
282288
if isFile(p) {
283-
absPath, _ := filepath.Abs(p)
289+
absPath, absErr := filepath.Abs(p)
290+
if absErr != nil {
291+
absPath = filepath.Clean(p)
292+
}
284293
candidates[absPath] = struct{}{}
285294
}
286295
}

cmd/waza/cmd_coverage_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bytes"
5+
"encoding/json"
56
"os"
67
"path/filepath"
78
"testing"
@@ -123,6 +124,41 @@ func TestRenderCoverageMarkdown(t *testing.T) {
123124
assert.Contains(t, out, "| beta | 2 | file, prompt | ✅ Full |")
124125
}
125126

127+
func TestRenderCoverageJSON(t *testing.T) {
128+
report := &coverageReport{
129+
TotalSkills: 1,
130+
Covered: 1,
131+
Partial: 0,
132+
Uncovered: 0,
133+
CoveragePct: 100,
134+
Skills: []coverageSkillRow{
135+
{Skill: "alpha", Tasks: 2, Graders: []string{"file", "prompt"}, Coverage: "✅ Full"},
136+
},
137+
}
138+
139+
var buf bytes.Buffer
140+
require.NoError(t, renderCoverageJSON(&buf, report))
141+
142+
var decoded map[string]any
143+
require.NoError(t, json.Unmarshal(buf.Bytes(), &decoded))
144+
assert.Equal(t, float64(1), decoded["total_skills"])
145+
assert.Contains(t, buf.String(), "\n \"total_skills\"")
146+
}
147+
148+
func TestCoverageCommand_UnsupportedFormat(t *testing.T) {
149+
root := t.TempDir()
150+
writeSkill(t, root, filepath.Join("skills", "alpha"), "alpha")
151+
152+
cmd := newCoverageCommand()
153+
cmd.SetOut(new(bytes.Buffer))
154+
cmd.SetErr(new(bytes.Buffer))
155+
cmd.SetArgs([]string{root, "--format", "xml"})
156+
157+
err := cmd.Execute()
158+
require.Error(t, err)
159+
assert.Contains(t, err.Error(), `unsupported format "xml"`)
160+
}
161+
126162
func TestRootCommand_HasCoverageSubcommand(t *testing.T) {
127163
root := newRootCommand()
128164
found := false

site/src/content/docs/reference/cli.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ waza coverage [root]
274274

275275
| Flag | Description |
276276
|------|-------------|
277-
| `--format` | Output format: `text` (default), `markdown`, `json` |
277+
| `-f, --format` | Output format: `text` (default), `markdown`, `json` |
278278
| `--path` | Additional directories to scan for skills/evals (repeatable) |
279279

280280
### Examples

0 commit comments

Comments
 (0)