MCPcopy Create free account
hub / github.com/driangle/taskmd / TestRunValidate_WithConfig_Scopes

Function TestRunValidate_WithConfig_Scopes

apps/cli/internal/cli/validate_test.go:644–706  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

642}
643
644func TestRunValidate_WithConfig_Scopes(t *testing.T) {
645 tmpDir := t.TempDir()
646
647 // Create a task with a touches field
648 task := `---
649id: "001"
650title: "Task with touches"
651status: pending
652touches: ["cli/graph", "undefined-scope"]
653---
654
655A task that touches scopes.
656`
657 if err := os.WriteFile(filepath.Join(tmpDir, "001-task.md"), []byte(task), 0644); err != nil {
658 t.Fatalf("failed to create test file: %v", err)
659 }
660
661 // Create a .taskmd.yaml config with scopes
662 config := `scopes:
663 cli/graph:
664 description: "Graph visualization"
665 paths:
666 - "apps/cli/internal/graph/"
667`
668 if err := os.WriteFile(filepath.Join(tmpDir, ".taskmd.yaml"), []byte(config), 0644); err != nil {
669 t.Fatalf("failed to create config file: %v", err)
670 }
671
672 // Use validateConfig directly with mock config data to avoid viper global state
673 v := validator.NewValidator(false)
674 tasks := []*model.Task{
675 {ID: "001", Title: "Task with touches", Touches: []string{"cli/graph", "undefined-scope"}},
676 }
677 validationResult := v.Validate(tasks)
678
679 configData := &validator.ConfigData{
680 Scopes: map[string]validator.ScopeConfig{
681 "cli/graph": {Description: "Graph visualization", Paths: []string{"apps/cli/internal/graph/"}},
682 },
683 TopKeys: []string{"scopes"},
684 ConfigPath: filepath.Join(tmpDir, ".taskmd.yaml"),
685 }
686
687 validateConfig(v, validationResult, tasks)
688 // Reset and test with actual config data
689 validationResult2 := v.Validate(tasks)
690 mergeValidationResults(validationResult2, v.ValidateConfig(configData))
691
692 knownScopes := map[string]bool{"cli/graph": true}
693 mergeValidationResults(validationResult2, v.ValidateTouchesAgainstScopes(tasks, knownScopes))
694
695 // Should have a warning about "undefined-scope"
696 foundUndefinedWarning := false
697 for _, issue := range validationResult2.Issues {
698 if strings.Contains(issue.Message, "undefined-scope") {
699 foundUndefinedWarning = true
700 break
701 }

Callers

nothing calls this directly

Calls 6

ValidateMethod · 0.95
ValidateConfigMethod · 0.95
validateConfigFunction · 0.85
mergeValidationResultsFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected