Files
skillshare/internal/sync/classify_test.go
T
Willie 7858cb2c40 feat(api): add sync-matrix API and ClassifySkillForTarget
Backend for Filter Studio feature:
- ClassifySkillForTarget() in internal/sync/classify.go — determines
  skill sync status per target (synced/excluded/not_included/
  skill_target_mismatch) with reason strings
- firstMatchingPattern() helper in filter.go for exclude reason reporting
- GET /api/sync-matrix — returns full skill×target classification matrix
- POST /api/sync-matrix/preview — what-if preview with draft patterns
- 8 classify unit tests + 7 handler tests (empty, filters, query param,
  preview, invalid pattern, missing target)
2026-03-17 04:48:42 +08:00

37 lines
1.9 KiB
Go

package sync
import "testing"
func TestClassifySkillForTarget(t *testing.T) {
tests := []struct {
name string
flatName string
targets []string
targetName string
include []string
exclude []string
wantStatus string
wantReason string
}{
{name: "synced_no_filters", flatName: "my-skill", targets: nil, targetName: "claude", wantStatus: "synced"},
{name: "excluded_by_pattern", flatName: "legacy-tool", targets: nil, targetName: "claude", exclude: []string{"legacy*"}, wantStatus: "excluded", wantReason: "legacy*"},
{name: "not_included", flatName: "backend-api", targets: nil, targetName: "claude", include: []string{"frontend*"}, wantStatus: "not_included"},
{name: "included_by_pattern", flatName: "frontend-design", targets: nil, targetName: "claude", include: []string{"frontend*"}, wantStatus: "synced"},
{name: "skill_target_mismatch", flatName: "my-skill", targets: []string{"cursor"}, targetName: "claude", wantStatus: "skill_target_mismatch", wantReason: "cursor"},
{name: "skill_target_match", flatName: "my-skill", targets: []string{"claude", "cursor"}, targetName: "claude", wantStatus: "synced"},
{name: "exclude_wins_over_include", flatName: "frontend-legacy", targets: nil, targetName: "claude", include: []string{"frontend*"}, exclude: []string{"*legacy*"}, wantStatus: "excluded", wantReason: "*legacy*"},
{name: "include_miss_beats_exclude_match", flatName: "legacy-tool", targets: nil, targetName: "claude", include: []string{"frontend*"}, exclude: []string{"legacy*"}, wantStatus: "not_included"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
status, reason := ClassifySkillForTarget(tt.flatName, tt.targets, tt.targetName, tt.include, tt.exclude)
if status != tt.wantStatus {
t.Errorf("status = %q, want %q", status, tt.wantStatus)
}
if tt.wantReason != "" && reason != tt.wantReason {
t.Errorf("reason = %q, want %q", reason, tt.wantReason)
}
})
}
}