Skip to content

Commit d5c6464

Browse files
authored
Add fuzz tests for frontmatter YAML parser (#3851)
1 parent 2f8a38f commit d5c6464

4 files changed

Lines changed: 608 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,6 @@ jobs:
233233
run: go mod verify
234234

235235
- name: Run fuzz tests
236-
run: go test -fuzz=FuzzExpressionParser -fuzztime=10s ./pkg/workflow/
236+
run: |
237+
go test -fuzz=FuzzParseFrontmatter -fuzztime=10s ./pkg/parser/
238+
go test -fuzz=FuzzExpressionParser -fuzztime=10s ./pkg/workflow/

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ bench-compare:
7171
go test -bench=. -benchmem -benchtime=100x -run=^$$ ./pkg/... | tee bench_results.txt
7272
@echo "Benchmark results saved to bench_results.txt"
7373

74+
# Run fuzz tests
75+
.PHONY: fuzz
76+
fuzz:
77+
@echo "Running fuzz tests for 30 seconds..."
78+
go test -fuzz=FuzzParseFrontmatter -fuzztime=30s ./pkg/parser/
79+
go test -fuzz=FuzzExpressionParser -fuzztime=30s ./pkg/workflow/
80+
7481
# Test JavaScript files
7582
.PHONY: test-js
7683
test-js: build-js
@@ -278,6 +285,9 @@ help:
278285
@echo " test-js - Run JavaScript tests"
279286
@echo " test-all - Run all tests (Go and JavaScript)"
280287
@echo " test-coverage - Run tests with coverage report"
288+
@echo " bench - Run benchmarks for performance testing"
289+
@echo " bench-compare - Run benchmarks with comparison output"
290+
@echo " fuzz - Run fuzz tests for 30 seconds"
281291
@echo " bundle-js - Build JavaScript bundler tool (./bundle-js <input> [output])"
282292
@echo " clean - Clean build artifacts"
283293
@echo " deps - Install dependencies"

pkg/parser/frontmatter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ func ExtractFrontmatterFromContent(content string) (*FrontmatterResult, error) {
143143
return nil, fmt.Errorf("failed to parse frontmatter: %w", err)
144144
}
145145

146+
// Ensure frontmatter is never nil (yaml.Unmarshal sets it to nil for empty YAML)
147+
if frontmatter == nil {
148+
frontmatter = make(map[string]any)
149+
}
150+
146151
// Extract markdown content (everything after the closing ---)
147152
var markdownLines []string
148153
if endIndex+1 < len(lines) {

0 commit comments

Comments
 (0)