(t *testing.T)
| 642 | } |
| 643 | |
| 644 | func TestRunValidate_WithConfig_Scopes(t *testing.T) { |
| 645 | tmpDir := t.TempDir() |
| 646 | |
| 647 | // Create a task with a touches field |
| 648 | task := `--- |
| 649 | id: "001" |
| 650 | title: "Task with touches" |
| 651 | status: pending |
| 652 | touches: ["cli/graph", "undefined-scope"] |
| 653 | --- |
| 654 | |
| 655 | A 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 | } |
nothing calls this directly
no test coverage detected