mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-02 02:58:10 +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/integration/__init__.py
Normal file
0
tests/integration/__init__.py
Normal file
89
tests/integration/test_cli.py
Normal file
89
tests/integration/test_cli.py
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
"""
|
||||
Integration tests for CLI interface.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import subprocess
|
||||
|
||||
from conftest import TESTED_VERSIONS
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
class TestCLIInterface:
|
||||
"""Tests for CLI command line interface."""
|
||||
|
||||
def test_cli_executable_help(self):
|
||||
"""Test that CLI executable --help works."""
|
||||
result = subprocess.run(
|
||||
['tg-build-deployment', '--help'],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert 'usage' in result.stdout.lower()
|
||||
|
||||
def test_cli_executable_exists(self):
|
||||
"""Test that tg-build-deployment is in PATH."""
|
||||
result = subprocess.run(
|
||||
['which', 'tg-build-deployment'],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
assert result.returncode == 0
|
||||
|
||||
def test_output_modes(self, run_configurator, test_config_dir, primary_version):
|
||||
"""Test -O and -R output modes."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
# Test -O mode
|
||||
stdout_o, _, code_o = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
assert code_o == 0
|
||||
assert len(stdout_o) > 0
|
||||
|
||||
# Test -R mode
|
||||
stdout_r, _, code_r = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
assert code_r == 0
|
||||
assert len(stdout_r) > 0
|
||||
|
||||
# Outputs should be different
|
||||
assert stdout_o != stdout_r
|
||||
|
||||
def test_platform_argument(self, run_configurator, test_config_dir, primary_version):
|
||||
"""Test -p/--platform argument."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
for platform in ['docker-compose', 'minikube-k8s']:
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', platform,
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
assert code == 0, f"Failed for platform {platform}"
|
||||
|
||||
def test_template_argument(self, run_configurator, test_config_dir):
|
||||
"""Test -t/--template argument."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
for template in TESTED_VERSIONS:
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', template,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
assert code == 0, f"Failed for template {template}"
|
||||
163
tests/integration/test_compilation.py
Normal file
163
tests/integration/test_compilation.py
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
"""
|
||||
Integration tests for template compilation across all combinations.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import json
|
||||
import yaml
|
||||
|
||||
from conftest import TESTED_VERSIONS
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@pytest.mark.parametrize("version", TESTED_VERSIONS)
|
||||
@pytest.mark.parametrize("platform", [
|
||||
"docker-compose",
|
||||
"podman-compose",
|
||||
"minikube-k8s",
|
||||
"gcp-k8s",
|
||||
"aks-k8s",
|
||||
"eks-k8s",
|
||||
"scw-k8s",
|
||||
"ovh-k8s",
|
||||
])
|
||||
@pytest.mark.parametrize("config", [
|
||||
"minimal.json",
|
||||
"complex-rag.json",
|
||||
"multi-service.json",
|
||||
"cloud-aws.json",
|
||||
])
|
||||
def test_tg_config_generation(version, platform, config, run_configurator, test_config_dir):
|
||||
"""Test TrustGraph config generation for all combinations."""
|
||||
config_file = str(test_config_dir / config)
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', version,
|
||||
'-p', platform,
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
|
||||
# Should succeed
|
||||
assert code == 0, f"Failed for {version}/{platform}/{config}: {stderr}"
|
||||
|
||||
# Should output valid JSON
|
||||
try:
|
||||
tg_config = json.loads(stdout)
|
||||
except json.JSONDecodeError as e:
|
||||
pytest.fail(f"Invalid JSON output for {version}/{platform}/{config}: {e}")
|
||||
|
||||
# Basic structure checks
|
||||
assert isinstance(tg_config, (dict, list)), "TrustGraph config should be dict or list"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@pytest.mark.parametrize("version", TESTED_VERSIONS)
|
||||
@pytest.mark.parametrize("platform", [
|
||||
"docker-compose",
|
||||
"podman-compose",
|
||||
"minikube-k8s",
|
||||
"gcp-k8s",
|
||||
"aks-k8s",
|
||||
"eks-k8s",
|
||||
"scw-k8s",
|
||||
"ovh-k8s",
|
||||
])
|
||||
@pytest.mark.parametrize("config", [
|
||||
"minimal.json",
|
||||
"complex-rag.json",
|
||||
"multi-service.json",
|
||||
"cloud-aws.json",
|
||||
])
|
||||
def test_resources_generation(version, platform, config, run_configurator, test_config_dir):
|
||||
"""Test platform resources generation for all combinations."""
|
||||
config_file = str(test_config_dir / config)
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', version,
|
||||
'-p', platform,
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
# Should succeed
|
||||
assert code == 0, f"Failed for {version}/{platform}/{config}: {stderr}"
|
||||
|
||||
# Should output valid YAML
|
||||
try:
|
||||
resources = yaml.safe_load(stdout)
|
||||
except yaml.YAMLError as e:
|
||||
pytest.fail(f"Invalid YAML output for {version}/{platform}/{config}: {e}")
|
||||
|
||||
# Basic structure checks
|
||||
if platform in ["docker-compose", "podman-compose"]:
|
||||
assert "services" in resources, "Docker Compose should have services"
|
||||
else:
|
||||
# Kubernetes resources
|
||||
assert resources is not None, "K8s resources should not be empty"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_compilation_minimal_docker_compose(run_configurator, test_config_dir, primary_version):
|
||||
"""Smoke test: minimal config on docker-compose."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
# Test TG config
|
||||
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)
|
||||
assert tg_config is not None
|
||||
|
||||
# Test resources
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
resources = yaml.safe_load(stdout)
|
||||
assert "services" in resources
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_compilation_minimal_k8s(run_configurator, test_config_dir, primary_version):
|
||||
"""Smoke test: minimal config on k8s."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
# Test TG config
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'minikube-k8s',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
|
||||
assert code == 0
|
||||
tg_config = json.loads(stdout)
|
||||
assert tg_config is not None
|
||||
|
||||
# Test resources
|
||||
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)
|
||||
assert resources is not None
|
||||
97
tests/integration/test_errors.py
Normal file
97
tests/integration/test_errors.py
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
"""
|
||||
Integration tests for error handling.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import json
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
class TestErrorHandling:
|
||||
"""Tests for error handling and reporting."""
|
||||
|
||||
def test_nonexistent_config_file(self, run_configurator, primary_version):
|
||||
"""Test error when config file doesn't exist."""
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', '/nonexistent/config.json',
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
assert code == 1
|
||||
assert len(stderr) > 0 # Error should be in stderr
|
||||
|
||||
def test_invalid_json_config(self, run_configurator, tmp_path, primary_version):
|
||||
"""Test error when config file has invalid JSON."""
|
||||
invalid_config = tmp_path / "invalid.json"
|
||||
invalid_config.write_text("{ invalid json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', str(invalid_config),
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
assert code == 1
|
||||
|
||||
def test_invalid_platform(self, run_configurator, test_config_dir, primary_version):
|
||||
"""Test error when platform is invalid."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'nonexistent-platform',
|
||||
'-i', config_file,
|
||||
'--latest-stable',
|
||||
'-R' # Use -R to trigger platform-specific generation
|
||||
])
|
||||
assert code == 1
|
||||
|
||||
def test_invalid_template_version(self, run_configurator, test_config_dir):
|
||||
"""Test error when template version doesn't exist."""
|
||||
config_file = str(test_config_dir / "minimal.json")
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', '999.999',
|
||||
'-p', 'docker-compose',
|
||||
'-i', config_file,
|
||||
'-O'
|
||||
])
|
||||
assert code == 1
|
||||
|
||||
def test_malformed_config_structure(self, run_configurator, tmp_path, primary_version):
|
||||
"""Test error when config structure is invalid."""
|
||||
# Valid JSON but wrong structure
|
||||
invalid_config = tmp_path / "bad_structure.json"
|
||||
invalid_config.write_text('{"wrong": "structure"}')
|
||||
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-t', primary_version,
|
||||
'-p', 'docker-compose',
|
||||
'-i', str(invalid_config),
|
||||
'--latest-stable',
|
||||
'-O'
|
||||
])
|
||||
# May succeed with warning or fail - either is acceptable
|
||||
# The important thing is it doesn't crash
|
||||
assert code in [0, 1]
|
||||
|
||||
def test_missing_required_args(self, run_configurator):
|
||||
"""Test error when required arguments are missing."""
|
||||
# Missing template
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-p', 'docker-compose',
|
||||
'-O'
|
||||
])
|
||||
assert code == 1
|
||||
|
||||
def test_error_goes_to_stderr(self, run_configurator):
|
||||
"""Test that errors are written to stderr, not stdout."""
|
||||
stdout, stderr, code = run_configurator([
|
||||
'-i', '/nonexistent/config.json'
|
||||
])
|
||||
assert code == 1
|
||||
# Errors should be in stderr
|
||||
assert len(stderr) > 0 or 'Exception' in stderr or code == 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue