mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 17:39:39 +02:00
Squashed 'ai-context/trustgraph-templates/' content from commit 42a5fd1b
git-subtree-dir: ai-context/trustgraph-templates git-subtree-split: 42a5fd1b678f32be378062e30451e2052ccb95dd
This commit is contained in:
commit
74cc8a4685
1216 changed files with 116347 additions and 0 deletions
0
tests/validation/__init__.py
Normal file
0
tests/validation/__init__.py
Normal file
111
tests/validation/test_schema.py
Normal file
111
tests/validation/test_schema.py
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
"""
|
||||
Schema validation tests for generated outputs.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import json
|
||||
import yaml
|
||||
import jsonschema
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def schemas_dir():
|
||||
"""Path to schemas directory."""
|
||||
return Path(__file__).parent.parent / "schemas"
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
def test_tg_config_matches_schema(run_configurator, test_config_dir, schemas_dir, primary_version):
|
||||
"""Test that TrustGraph config matches schema."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
tg_config = json.loads(stdout)
|
||||
schema_file = schemas_dir / "trustgraph-config.schema.json"
|
||||
|
||||
with open(schema_file) as f:
|
||||
schema = json.load(f)
|
||||
|
||||
try:
|
||||
jsonschema.validate(instance=tg_config, schema=schema)
|
||||
except jsonschema.ValidationError as e:
|
||||
pytest.fail(f"Schema validation failed: {e}")
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
def test_docker_compose_matches_schema(run_configurator, test_config_dir, schemas_dir, primary_version):
|
||||
"""Test that Docker Compose output matches schema."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
compose_data = yaml.safe_load(stdout)
|
||||
schema_file = schemas_dir / "docker-compose.schema.json"
|
||||
|
||||
with open(schema_file) as f:
|
||||
schema = json.load(f)
|
||||
|
||||
try:
|
||||
jsonschema.validate(instance=compose_data, schema=schema)
|
||||
except jsonschema.ValidationError as e:
|
||||
pytest.fail(f"Schema validation failed: {e}")
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
def test_kubernetes_resources_match_schema(run_configurator, test_config_dir, schemas_dir, primary_version):
|
||||
"""Test that Kubernetes resources match schema."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'minikube-k8s',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
resources = yaml.safe_load(stdout)
|
||||
schema_file = schemas_dir / "kubernetes-resource.schema.json"
|
||||
|
||||
with open(schema_file) as f:
|
||||
schema = json.load(f)
|
||||
|
||||
# Validate the resource (which might be a single resource, list, or K8s List)
|
||||
if isinstance(resources, dict):
|
||||
# Check if it's a Kubernetes List resource
|
||||
if resources.get('kind') == 'List' and 'items' in resources:
|
||||
resources_to_validate = resources['items']
|
||||
else:
|
||||
resources_to_validate = [resources]
|
||||
elif isinstance(resources, list):
|
||||
resources_to_validate = resources
|
||||
else:
|
||||
pytest.fail(f"Unexpected resources type: {type(resources)}")
|
||||
|
||||
for resource in resources_to_validate:
|
||||
if not isinstance(resource, dict):
|
||||
continue # Skip non-dict items
|
||||
try:
|
||||
jsonschema.validate(instance=resource, schema=schema)
|
||||
except jsonschema.ValidationError as e:
|
||||
pytest.fail(f"Schema validation failed for resource: {e}")
|
||||
78
tests/validation/test_semantics_docker.py
Normal file
78
tests/validation/test_semantics_docker.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
"""
|
||||
Semantic validation tests for Docker Compose resources.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add parent directory to path for validators import
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
from validators import docker_compose
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
@pytest.mark.parametrize("config", ["minimal.json", "complex-rag.json"])
|
||||
def test_docker_compose_semantic_validation(config, run_configurator, test_config_dir, primary_version):
|
||||
"""Test semantic validation of Docker Compose resources."""
|
||||
config_file = str(test_config_dir / config)
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
is_valid, errors = docker_compose.validate_docker_compose_manifest(stdout)
|
||||
|
||||
if not is_valid:
|
||||
error_msg = "\n".join(errors)
|
||||
pytest.fail(f"Semantic validation failed for {config}:\n{error_msg}")
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
def test_docker_compose_service_dependencies(run_configurator, test_config_dir, primary_version):
|
||||
"""Test that service dependencies reference valid services."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
compose_data = docker_compose.parse_docker_compose_yaml(stdout)
|
||||
errors = docker_compose.validate_service_dependencies(compose_data)
|
||||
|
||||
if errors:
|
||||
pytest.fail(f"Invalid service dependencies:\n" + "\n".join(errors))
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
def test_docker_compose_no_port_conflicts(run_configurator, test_config_dir, primary_version):
|
||||
"""Test that there are no port conflicts."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
compose_data = docker_compose.parse_docker_compose_yaml(stdout)
|
||||
errors = docker_compose.validate_port_conflicts(compose_data)
|
||||
|
||||
if errors:
|
||||
pytest.fail(f"Port conflicts detected:\n" + "\n".join(errors))
|
||||
78
tests/validation/test_semantics_k8s.py
Normal file
78
tests/validation/test_semantics_k8s.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
"""
|
||||
Semantic validation tests for Kubernetes resources.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add parent directory to path for validators import
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
from validators import kubernetes
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
@pytest.mark.parametrize("config", ["minimal.json", "complex-rag.json"])
|
||||
def test_k8s_semantic_validation(config, run_configurator, test_config_dir, primary_version):
|
||||
"""Test semantic validation of Kubernetes resources."""
|
||||
config_file = str(test_config_dir / config)
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'minikube-k8s',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
is_valid, errors = kubernetes.validate_kubernetes_manifest(stdout)
|
||||
|
||||
if not is_valid:
|
||||
error_msg = "\n".join(errors)
|
||||
pytest.fail(f"Semantic validation failed for {config}:\n{error_msg}")
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
def test_k8s_selector_labels_match(run_configurator, test_config_dir, primary_version):
|
||||
"""Test that Deployment selectors match pod labels."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'minikube-k8s',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
resources = kubernetes.parse_kubernetes_yaml(stdout)
|
||||
errors = kubernetes.validate_selector_labels_match(resources)
|
||||
|
||||
if errors:
|
||||
pytest.fail(f"Selector/label mismatch:\n" + "\n".join(errors))
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
def test_k8s_volume_references(run_configurator, test_config_dir, primary_version):
|
||||
"""Test that volumeMounts reference defined volumes."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'minikube-k8s',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
resources = kubernetes.parse_kubernetes_yaml(stdout)
|
||||
errors = kubernetes.validate_volume_references(resources)
|
||||
|
||||
if errors:
|
||||
pytest.fail(f"Invalid volume references:\n" + "\n".join(errors))
|
||||
83
tests/validation/test_semantics_tg.py
Normal file
83
tests/validation/test_semantics_tg.py
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
"""
|
||||
Semantic validation tests for TrustGraph configuration.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add parent directory to path for validators import
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
from validators import trustgraph
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
@pytest.mark.parametrize("config", ["minimal.json", "complex-rag.json", "multi-service.json"])
|
||||
def test_tg_config_semantic_validation(config, run_configurator, test_config_dir, primary_version):
|
||||
"""Test semantic validation of TrustGraph configuration."""
|
||||
config_file = str(test_config_dir / config)
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
is_valid, errors = trustgraph.validate_trustgraph_config(stdout)
|
||||
|
||||
if not is_valid:
|
||||
error_msg = "\n".join(errors)
|
||||
# Some errors might be warnings, so we log them but don't necessarily fail
|
||||
# Adjust this based on strictness requirements
|
||||
if any("missing" in err.lower() or "required" in err.lower() for err in errors):
|
||||
pytest.fail(f"Semantic validation failed for {config}:\n{error_msg}")
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
def test_tg_config_has_llm(run_configurator, test_config_dir, primary_version):
|
||||
"""Test that TrustGraph config includes LLM provider."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
tg_config = trustgraph.parse_trustgraph_config(stdout)
|
||||
errors = trustgraph.validate_llm_configuration(tg_config)
|
||||
|
||||
# LLM should be configured
|
||||
if errors:
|
||||
# This might be a warning rather than error for some configs
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
def test_tg_config_structure(run_configurator, test_config_dir, primary_version):
|
||||
"""Test that TrustGraph config has required structure."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
tg_config = trustgraph.parse_trustgraph_config(stdout)
|
||||
errors = trustgraph.validate_required_structure(tg_config)
|
||||
|
||||
if errors:
|
||||
pytest.fail(f"Invalid TrustGraph config structure:\n" + "\n".join(errors))
|
||||
57
tests/validation/test_syntax.py
Normal file
57
tests/validation/test_syntax.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
"""
|
||||
Syntax validation tests for generated outputs.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import json
|
||||
import yaml
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
@pytest.mark.parametrize("platform", ["docker-compose", "minikube-k8s"])
|
||||
@pytest.mark.parametrize("config", ["minimal.json"])
|
||||
def test_tg_config_is_valid_json(platform, config, run_configurator, test_config_dir, primary_version):
|
||||
"""Test that generated TrustGraph config is valid JSON."""
|
||||
config_file = str(test_config_dir / config)
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', platform,
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
# Should parse as valid JSON
|
||||
try:
|
||||
parsed = json.loads(stdout)
|
||||
assert parsed is not None
|
||||
except json.JSONDecodeError as e:
|
||||
pytest.fail(f"Invalid JSON: {e}")
|
||||
|
||||
|
||||
@pytest.mark.validation
|
||||
@pytest.mark.parametrize("platform", ["docker-compose", "minikube-k8s"])
|
||||
@pytest.mark.parametrize("config", ["minimal.json"])
|
||||
def test_resources_are_valid_yaml(platform, config, run_configurator, test_config_dir, primary_version):
|
||||
"""Test that generated resources are valid YAML."""
|
||||
config_file = str(test_config_dir / config)
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', platform,
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
|
||||
# Should parse as valid YAML
|
||||
try:
|
||||
parsed = yaml.safe_load(stdout)
|
||||
assert parsed is not None
|
||||
except yaml.YAMLError as e:
|
||||
pytest.fail(f"Invalid YAML: {e}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue