Summary
Create dedicated unit tests for Validate-MarkdownFrontmatter.ps1 which has complex schema validation logic requiring thorough testing.
Parent Issue: #190
Requirements
- Create
scripts/tests/linting/Validate-MarkdownFrontmatter.Tests.ps1
- Test YAML frontmatter parsing and extraction
- Test schema validation against multiple schema types
- Test schema-mapping.json pattern matching
- Test error reporting and edge cases
Implementation Details
Why Separate Issue
Validate-MarkdownFrontmatter.ps1 deserves dedicated attention because:
- Complex YAML parsing logic
- Multiple schema types (instruction, prompt, docs, etc.)
- Pattern-matching for schema selection
- Critical for repository documentation standards
Test Scenarios
Describe 'Validate-MarkdownFrontmatter.ps1' {
Context 'YAML Extraction' {
It 'Should extract frontmatter from valid markdown' {
$content = @"
---
title: Test
description: Test description
---
# Content
"@
$result = Get-Frontmatter -Content $content
$result.title | Should -Be 'Test'
}
It 'Should handle missing frontmatter' {
$content = '# No frontmatter'
$result = Get-Frontmatter -Content $content
$result | Should -BeNullOrEmpty
}
It 'Should handle malformed YAML' {
$content = @"
---
title: Test
bad-indent: value
---
"@
{ Get-Frontmatter -Content $content } | Should -Throw
}
}
Context 'Schema Selection' {
BeforeAll {
# Load schema mapping
$schemaMapping = Get-Content 'scripts/linting/schemas/schema-mapping.json' |
ConvertFrom-Json
}
It 'Should select instruction schema for .instructions.md' {
$schema = Get-SchemaForFile -Path 'test.instructions.md'
$schema | Should -Match 'instruction-frontmatter'
}
It 'Should select prompt schema for .prompt.md' {
$schema = Get-SchemaForFile -Path 'test.prompt.md'
$schema | Should -Match 'prompt-frontmatter'
}
It 'Should fall back to base schema for unknown types' {
$schema = Get-SchemaForFile -Path 'random.md'
$schema | Should -Match 'base-frontmatter'
}
}
Context 'Schema Validation' {
It 'Should pass valid instruction frontmatter' {
$frontmatter = @{
description = 'Test description'
applyTo = '**/*.ps1'
}
$result = Test-FrontmatterSchema -Data $frontmatter -SchemaType 'instruction'
$result.IsValid | Should -BeTrue
}
It 'Should fail instruction frontmatter missing required fields' {
$frontmatter = @{
title = 'Missing description and applyTo'
}
$result = Test-FrontmatterSchema -Data $frontmatter -SchemaType 'instruction'
$result.IsValid | Should -BeFalse
$result.Errors | Should -Contain '*description*'
}
}
}
Mock Data
$TestCases = @(
@{
Name = 'Valid docs frontmatter'
Content = @"
---
title: Getting Started
description: How to get started with the project
ms.date: 2025-01-15
---
"@
SchemaType = 'docs'
ExpectedValid = $true
}
@{
Name = 'Invalid date format'
Content = @"
---
title: Test
description: Test
ms.date: 01/15/2025
---
"@
SchemaType = 'docs'
ExpectedValid = $false
}
)
Acceptance Criteria
Dependencies
Estimated Effort
2-3 hours
Additional Context
Schema Files
Located in scripts/linting/schemas/:
base-frontmatter.schema.json
instruction-frontmatter.schema.json
prompt-frontmatter.schema.json
docs-frontmatter.schema.json
chatmode-frontmatter.schema.json
agent-frontmatter.schema.json
root-community-frontmatter.schema.json
schema-mapping.json
Related Issues
Summary
Create dedicated unit tests for
Validate-MarkdownFrontmatter.ps1which has complex schema validation logic requiring thorough testing.Parent Issue: #190
Requirements
scripts/tests/linting/Validate-MarkdownFrontmatter.Tests.ps1Implementation Details
Why Separate Issue
Validate-MarkdownFrontmatter.ps1deserves dedicated attention because:Test Scenarios
Mock Data
Acceptance Criteria
Dependencies
Estimated Effort
2-3 hours
Additional Context
Schema Files
Located in
scripts/linting/schemas/:base-frontmatter.schema.jsoninstruction-frontmatter.schema.jsonprompt-frontmatter.schema.jsondocs-frontmatter.schema.jsonchatmode-frontmatter.schema.jsonagent-frontmatter.schema.jsonroot-community-frontmatter.schema.jsonschema-mapping.jsonRelated Issues