feat: add agent schema validation with comprehensive testing
Introduce automated validation for agent YAML files using Zod to ensure
schema compliance across all agent definitions. This feature validates
17 agent files across core and module directories, catching structural
errors and maintaining consistency.
Schema Validation (tools/schema/agent.js):
- Zod-based schema validating metadata, persona, menu, prompts, and critical actions
- Module-aware validation: module field required for src/modules/**/agents/,
optional for src/core/agents/
- Enforces kebab-case unique triggers and at least one command target per menu item
- Validates persona.principles as array (not string)
- Comprehensive refinements for data integrity
CLI Validator (tools/validate-agent-schema.js):
- Scans src/{core,modules/*}/agents/*.agent.yaml
- Parses with js-yaml and validates using Zod schema
- Reports detailed errors with file paths and field paths
- Exits 1 on failures, 0 on success
- Accepts optional project_root parameter for testing
Testing (679 lines across 3 test files):
- test/test-cli-integration.sh: CLI behavior and error handling tests
- test/unit-test-schema.js: Direct schema validation unit tests
- test/test-agent-schema.js: Comprehensive fixture-based tests
- 50 test fixtures covering valid and invalid scenarios
- ESLint configured to support CommonJS test files
- Prettier configured to ignore intentionally broken fixtures
CI Integration (.github/workflows/lint.yaml):
- Renamed from format-check.yaml to lint.yaml
- Added schema-validation job running npm run validate:schemas
- Runs in parallel with prettier and eslint jobs
- Validates on all pull requests
Data Cleanup:
- Fixed src/core/agents/bmad-master.agent.yaml: converted persona.principles
from string to array format
Documentation:
- Updated schema-classification.md with validation section
- Documents validator usage, enforcement rules, and CI integration
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
23
test/fixtures/agent-schema/valid/prompts/empty-prompts.agent.yaml
vendored
Normal file
23
test/fixtures/agent-schema/valid/prompts/empty-prompts.agent.yaml
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
# Test: Empty prompts array
|
||||
# Expected: PASS - empty array valid for optional field
|
||||
|
||||
agent:
|
||||
metadata:
|
||||
id: empty-prompts
|
||||
name: Empty Prompts
|
||||
title: Empty Prompts
|
||||
icon: 🧪
|
||||
|
||||
persona:
|
||||
role: Test agent with empty prompts
|
||||
identity: I am a test agent with empty prompts array.
|
||||
communication_style: Clear
|
||||
principles:
|
||||
- Test empty arrays
|
||||
|
||||
prompts: []
|
||||
|
||||
menu:
|
||||
- trigger: help
|
||||
description: Show help
|
||||
action: display_help
|
||||
21
test/fixtures/agent-schema/valid/prompts/no-prompts.agent.yaml
vendored
Normal file
21
test/fixtures/agent-schema/valid/prompts/no-prompts.agent.yaml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Test: No prompts field (optional)
|
||||
# Expected: PASS
|
||||
|
||||
agent:
|
||||
metadata:
|
||||
id: no-prompts
|
||||
name: No Prompts
|
||||
title: No Prompts
|
||||
icon: 🧪
|
||||
|
||||
persona:
|
||||
role: Test agent without prompts
|
||||
identity: I am a test agent without prompts field.
|
||||
communication_style: Clear
|
||||
principles:
|
||||
- Test optional fields
|
||||
|
||||
menu:
|
||||
- trigger: help
|
||||
description: Show help
|
||||
action: display_help
|
||||
27
test/fixtures/agent-schema/valid/prompts/valid-prompts-minimal.agent.yaml
vendored
Normal file
27
test/fixtures/agent-schema/valid/prompts/valid-prompts-minimal.agent.yaml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# Test: Prompts with required id and content only
|
||||
# Expected: PASS
|
||||
|
||||
agent:
|
||||
metadata:
|
||||
id: valid-prompts-minimal
|
||||
name: Valid Prompts Minimal
|
||||
title: Valid Prompts
|
||||
icon: 🧪
|
||||
|
||||
persona:
|
||||
role: Test agent with minimal prompts
|
||||
identity: I am a test agent with minimal prompt structure.
|
||||
communication_style: Clear
|
||||
principles:
|
||||
- Test minimal prompts
|
||||
|
||||
prompts:
|
||||
- id: prompt1
|
||||
content: This is a valid prompt content
|
||||
- id: prompt2
|
||||
content: Another valid prompt
|
||||
|
||||
menu:
|
||||
- trigger: help
|
||||
description: Show help
|
||||
action: display_help
|
||||
29
test/fixtures/agent-schema/valid/prompts/valid-prompts-with-description.agent.yaml
vendored
Normal file
29
test/fixtures/agent-schema/valid/prompts/valid-prompts-with-description.agent.yaml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# Test: Prompts with optional description field
|
||||
# Expected: PASS
|
||||
|
||||
agent:
|
||||
metadata:
|
||||
id: valid-prompts-description
|
||||
name: Valid Prompts With Description
|
||||
title: Valid Prompts Desc
|
||||
icon: 🧪
|
||||
|
||||
persona:
|
||||
role: Test agent with prompts including descriptions
|
||||
identity: I am a test agent with complete prompt structure.
|
||||
communication_style: Clear
|
||||
principles:
|
||||
- Test complete prompts
|
||||
|
||||
prompts:
|
||||
- id: prompt1
|
||||
content: This is a valid prompt content
|
||||
description: This prompt does something useful
|
||||
- id: prompt2
|
||||
content: Another valid prompt
|
||||
description: This prompt does something else
|
||||
|
||||
menu:
|
||||
- trigger: help
|
||||
description: Show help
|
||||
action: display_help
|
||||
Reference in New Issue
Block a user