The current test specification and test case structures in mandrel-mcp-th do not support custom script-based validation. To enable advanced, multi-language script validation (JavaScript, Python, Lua), we must add a validation_scripts field to both TestSpecification and TestCase structs, and update YAML parsing and validation logic accordingly.
- Add a
validation_scriptsfield toTestSpecificationandTestCase. - Support parsing of YAML files with and without the new field.
- Ensure backward compatibility for existing specs.
- Validate that scripts are correctly referenced and loaded.
- Provide unit tests for parsing, error cases, and edge conditions.
- Update documentation to reflect the new field.
- Update the Rust structs in
spec/mod.rs:TestSpecification:- Add:
pub validation_scripts: Option<Vec<ValidationScript>>
- Add:
TestCase:- Add:
pub validation_scripts: Option<Vec<String>>(references by name)
- Add:
- Define a new
ValidationScriptstruct:#[derive(Debug, Clone, Deserialize, Serialize)] pub struct ValidationScript { pub name: String, pub language: String, // "lua", "python", "javascript" pub execution_phase: Option<String>, // "before", "after" pub required: Option<bool>, pub source: String, }
- Update YAML parsing logic to support the new fields, using
serdewith#[serde(default)]for backward compatibility.
validation_scripts:
- name: "math_precision_validator"
language: "lua"
execution_phase: "after"
required: true
source: |
local request = context.request
local response = context.response
-- ...
tools:
- name: "add"
tests:
- name: "add_integers"
input: {"a": 5, "b": 3}
expected:
fields:
- path: "$[0].text"
pattern: "8"
validation_scripts: ["math_precision_validator"]- Use
Optionand#[serde(default)]to allow YAML files withoutvalidation_scripts. - Validate that all script references in test cases exist in the top-level
validation_scripts. - Provide clear error messages for missing or malformed scripts.
- RED: Write failing unit tests for YAML parsing with and without
validation_scripts. - GREEN: Implement struct changes and parsing logic.
- REFACTOR: Clean up code, improve error handling, and add documentation.
- Add tests for error cases (missing script, invalid YAML, etc.).
- Update documentation and examples.
- YAML with and without
validation_scriptsparses correctly. - Unit tests cover all parsing and error scenarios.
- Backward compatibility is maintained.
- Documentation is updated for the new field.
- All code follows project standards and passes CI checks.
spec/mod.rsfor struct and parsing changes.- YAML test specifications in
test-specs/for real-world examples. - Documentation in
docs/test-harness/and code comments.
- Embedding scripts directly in test cases (rejected for DRY and reusability).
- Using only script file paths (rejected for portability; inline source preferred).
- All acceptance criteria above are met.
- No regressions in existing test parsing.
- Scripts can be referenced and loaded in test execution pipeline (future phases).