-
Notifications
You must be signed in to change notification settings - Fork 125
Closed
Labels
enhancementNew feature or requestNew feature or requestlintingLinting rules and validationLinting rules and validationscriptsPowerShell, Bash, or Python scriptsPowerShell, Bash, or Python scripts
Description
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
- Comprehensive frontmatter extraction tests
- Schema selection tests for all file patterns
- Validation tests for each schema type
- Error message formatting tests
- Edge case handling (empty files, binary content, huge files)
- Integration test with real schema files
Dependencies
- [Issue]: Add Pester test infrastructure (config, directories, shared mocks) #193 (infrastructure)
- [Issue]: Integrate Pester tests into PR validation workflow #195 (LintingHelpers tests for shared utilities)
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.json
Related Issues
- Depends on: [Issue]: Add Pester test infrastructure (config, directories, shared mocks) #193, [Issue]: Integrate Pester tests into PR validation workflow #195
- Part of: [Issue]: Add Pester tests for LintingHelpers.psm1 module #196 (linting scripts)
- Parent: [Issue]: Add Pester unit testing framework for PowerShell scripts #190
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestlintingLinting rules and validationLinting rules and validationscriptsPowerShell, Bash, or Python scriptsPowerShell, Bash, or Python scripts