feat: add agent schema validation with comprehensive testing (#774)

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:
Alex Verkhovsky
2025-10-20 05:14:50 -07:00
committed by GitHub
parent 2a6eb71612
commit 31666c1f0f
64 changed files with 2732 additions and 11 deletions

View File

@@ -0,0 +1,23 @@
# Test: Empty module name in path (src/modules//agents/)
# Expected: PASS - treated as core agent (empty module normalizes to null)
# Path context: src/modules//agents/test.agent.yaml
agent:
metadata:
id: empty-module-path
name: Empty Module in Path
title: Empty Module Path
icon: 🧪
# No module field - path has empty module name, treated as core
persona:
role: Test agent for empty module name in path
identity: I test the edge case where module name in path is empty.
communication_style: Clear
principles:
- Test path parsing edge cases
menu:
- trigger: help
description: Show help
action: display_help

View File

@@ -0,0 +1,23 @@
# Test: Malformed module path (no slash after module name) treated as core
# Expected: PASS - malformed path returns null, treated as core agent
# Path context: src/modules/bmm
agent:
metadata:
id: malformed-path
name: Malformed Path Test
title: Malformed Path
icon: 🧪
# No module field - will be treated as core since path parsing returns null
persona:
role: Test agent for malformed path edge case
identity: I test edge cases in path parsing.
communication_style: Clear
principles:
- Test edge case handling
menu:
- trigger: help
description: Show help
action: display_help

View File

@@ -0,0 +1,23 @@
# Test: Valid module agent with correct module field
# Expected: PASS
# Path context: src/modules/bmm/agents/module-agent-correct.agent.yaml
agent:
metadata:
id: bmm-test
name: BMM Test Agent
title: BMM Test
icon: 🧪
module: bmm
persona:
role: Test module agent
identity: I am a module-scoped test agent.
communication_style: Professional
principles:
- Test module validation
menu:
- trigger: help
description: Show help
action: display_help