|
| 1 | +//go:build windows |
| 2 | + |
| 3 | +package structure |
| 4 | + |
| 5 | +import ( |
| 6 | + "strings" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/agent-ecosystem/skill-validator/types" |
| 10 | +) |
| 11 | + |
| 12 | +func TestInventoryFilesUsesForwardSlashes(t *testing.T) { |
| 13 | + dir := t.TempDir() |
| 14 | + writeFile(t, dir, "references/guide.md", "guide content") |
| 15 | + writeFile(t, dir, "references/images/diagram.png", "fake image") |
| 16 | + writeFile(t, dir, "scripts/setup.sh", "#!/bin/bash") |
| 17 | + |
| 18 | + inventory := inventoryFiles(dir) |
| 19 | + for _, rel := range inventory { |
| 20 | + if strings.Contains(rel, `\`) { |
| 21 | + t.Errorf("inventory path contains backslash: %s", rel) |
| 22 | + } |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func TestOrphanCheckWithForwardSlashReferences(t *testing.T) { |
| 27 | + // This is the exact scenario from issue #63: skill author writes |
| 28 | + // forward-slash paths in SKILL.md, which is the cross-platform convention. |
| 29 | + // On Windows, filepath.WalkDir returns backslash paths, so the orphan |
| 30 | + // checker must normalize before comparing. |
| 31 | + dir := t.TempDir() |
| 32 | + writeFile(t, dir, "references/other.md", "reference content") |
| 33 | + |
| 34 | + body := "See references/other.md." |
| 35 | + results := CheckOrphanFiles(dir, body, Options{}) |
| 36 | + |
| 37 | + requireResult(t, results, types.Pass, "all files in references/ are referenced") |
| 38 | + requireNoLevel(t, results, types.Warning) |
| 39 | +} |
| 40 | + |
| 41 | +func TestOrphanCheckNestedForwardSlashReference(t *testing.T) { |
| 42 | + dir := t.TempDir() |
| 43 | + writeFile(t, dir, "references/guide.md", "See .") |
| 44 | + writeFile(t, dir, "references/images/diagram.png", "fake image") |
| 45 | + |
| 46 | + body := "Read the [guide](references/guide.md)." |
| 47 | + results := CheckOrphanFiles(dir, body, Options{}) |
| 48 | + |
| 49 | + requireNoResultContaining(t, results, types.Warning, "diagram.png") |
| 50 | + requireResult(t, results, types.Pass, "all files in references/ are referenced") |
| 51 | +} |
| 52 | + |
| 53 | +func TestPythonImportResolvesOnWindows(t *testing.T) { |
| 54 | + dir := t.TempDir() |
| 55 | + writeFile(t, dir, "scripts/main.py", "from helpers.merge_runs import merge\nmerge()") |
| 56 | + writeFile(t, dir, "scripts/helpers/__init__.py", "") |
| 57 | + writeFile(t, dir, "scripts/helpers/merge_runs.py", "def merge(): pass") |
| 58 | + |
| 59 | + body := "Run scripts/main.py to start." |
| 60 | + results := CheckOrphanFiles(dir, body, Options{}) |
| 61 | + |
| 62 | + requireNoResultContaining(t, results, types.Warning, "merge_runs.py") |
| 63 | + requireResult(t, results, types.Pass, "all files in scripts/ are referenced") |
| 64 | +} |
0 commit comments