Harden M8 preflight foundation
This commit is contained in:
@@ -581,6 +581,46 @@ class TestDefaultCategories:
|
||||
assert "Other" in DEFAULT_CATEGORIES
|
||||
|
||||
|
||||
class TestToolContracts:
|
||||
def test_config_must_be_mapping(self):
|
||||
with pytest.raises(ValueError, match="YAML mapping"):
|
||||
Tool.from_dict(["not", "a", "mapping"])
|
||||
|
||||
def test_legacy_source_string_is_normalized(self):
|
||||
tool = Tool.from_dict({"name": "legacy-source", "source": "old/tool"})
|
||||
assert tool.source is not None
|
||||
assert tool.source.type == "imported"
|
||||
assert tool.source.original_tool == "old/tool"
|
||||
|
||||
def test_contracts_roundtrip(self):
|
||||
tool = Tool(
|
||||
name="contract-tool",
|
||||
input_schema={"type": "string"},
|
||||
output_schema={"type": "array", "items": {"type": "integer"}},
|
||||
)
|
||||
restored = Tool.from_dict(tool.to_dict())
|
||||
assert restored.input_schema == {"type": "string"}
|
||||
assert restored.output_schema["type"] == "array"
|
||||
|
||||
def test_empty_contracts_are_preserved(self):
|
||||
tool = Tool(name="open-contract", input_schema={}, output_schema={})
|
||||
serialized = tool.to_dict()
|
||||
assert serialized["input_schema"] == {}
|
||||
assert serialized["output_schema"] == {}
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("field", "schema"),
|
||||
[
|
||||
("input_schema", "string"),
|
||||
("output_schema", {"type": "not-a-json-schema-type"}),
|
||||
("output_schema", {"required": "name"}),
|
||||
],
|
||||
)
|
||||
def test_invalid_contract_is_rejected(self, field, schema):
|
||||
with pytest.raises(ValueError, match=field):
|
||||
Tool(name="bad-contract", **{field: schema})
|
||||
|
||||
|
||||
class TestAgentContext:
|
||||
def test_toolstep_profile_roundtrip(self):
|
||||
step = ToolStep(tool="my-tool", output_var="out", profile="architect")
|
||||
|
||||
Reference in New Issue
Block a user