55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Adversarial test: Monty Inputs (JSON) keys must be valid identifiers and not keywords.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from tools.validate_tool_request import validate
|
|
|
|
DOC = """---
|
|
request_type: tool_request
|
|
schema_version: 1
|
|
request_id: "TR-test-monty-bad-keys"
|
|
created_utc: "2026-02-10T00:00:00Z"
|
|
requested_by: "core_draft"
|
|
approved_by: "operator"
|
|
approved_utc: "2026-02-10T00:01:00Z"
|
|
purpose: "Test monty inputs key enforcement"
|
|
backend: "monty"
|
|
language: "python"
|
|
network: "none"
|
|
cpu_limit: "1"
|
|
memory_limit_mb: 128
|
|
time_limit_sec: 5
|
|
---
|
|
|
|
## Code
|
|
data
|
|
|
|
## Inputs (JSON)
|
|
{"foo-bar": 1, "class": 2}
|
|
|
|
## Output Expectations
|
|
Reject.
|
|
|
|
## Risk Assessment
|
|
Low.
|
|
"""
|
|
|
|
def main() -> int:
|
|
with tempfile.TemporaryDirectory() as td:
|
|
p = Path(td) / "TR.md"
|
|
p.write_text(DOC, encoding="utf-8")
|
|
res = validate(str(p))
|
|
assert not res.ok, "Expected rejection for invalid Monty input keys"
|
|
joined = " ".join(res.errors).lower()
|
|
assert "identifiers" in joined or "invalid keys" in joined, f"Unexpected errors: {res.errors}"
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|
|
|