(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestFrontmatterLocationIntegration(t *testing.T) { |
| 13 | // Create a temporary file with frontmatter that has additional properties |
| 14 | tempFile := "/tmp/gh-aw/gh-aw/test_frontmatter_location.md" |
| 15 | |
| 16 | // Ensure the directory exists |
| 17 | err := os.MkdirAll(filepath.Dir(tempFile), 0755) |
| 18 | if err != nil { |
| 19 | t.Fatalf("Failed to create temp directory: %v", err) |
| 20 | } |
| 21 | |
| 22 | content := `--- |
| 23 | name: Test Workflow |
| 24 | on: push |
| 25 | permissions: |
| 26 | contents: read |
| 27 | invalid_property: value |
| 28 | another_bad_prop: bad_value |
| 29 | engine: claude |
| 30 | --- |
| 31 | |
| 32 | This is a test workflow with invalid additional properties in frontmatter. |
| 33 | ` |
| 34 | |
| 35 | err = os.WriteFile(tempFile, []byte(content), 0644) |
| 36 | if err != nil { |
| 37 | t.Fatalf("Failed to create temp file: %v", err) |
| 38 | } |
| 39 | defer os.Remove(tempFile) |
| 40 | |
| 41 | // Create a schema that doesn't allow additional properties |
| 42 | schemaJSON := `{ |
| 43 | "type": "object", |
| 44 | "properties": { |
| 45 | "name": {"type": "string"}, |
| 46 | "on": {"type": ["string", "object"]}, |
| 47 | "permissions": {"type": "object"}, |
| 48 | "engine": {"type": "string"} |
| 49 | }, |
| 50 | "additionalProperties": false |
| 51 | }` |
| 52 | |
| 53 | // Parse frontmatter |
| 54 | frontmatterResult, err := ExtractFrontmatterFromContent(content) |
| 55 | if err != nil { |
| 56 | t.Fatalf("Failed to extract frontmatter: %v", err) |
| 57 | } |
| 58 | |
| 59 | // Validate with location information |
| 60 | err = validateWithSchemaAndLocation(frontmatterResult.Frontmatter, schemaJSON, "test workflow", tempFile) |
| 61 | |
| 62 | if err == nil { |
| 63 | t.Fatal("Expected validation error for additional properties, got nil") |
| 64 | } |
| 65 | |
| 66 | errorMessage := err.Error() |
| 67 | t.Logf("Error message: %s", errorMessage) |
| 68 | |
| 69 | // Verify the error points to the correct location |
nothing calls this directly
no test coverage detected