test_e2e.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """End-to-end smoke test using a mock 'bash' backend."""
  2. import shutil
  3. from pathlib import Path
  4. import pytest
  5. from drill.engine import Engine, ScenarioConfig
  6. @pytest.fixture
  7. def mock_scenario(tmp_path):
  8. scenario = tmp_path / "test-scenario.yaml"
  9. scenario.write_text("""
  10. scenario: e2e-smoke-test
  11. description: "Smoke test"
  12. user_posture: naive
  13. setup:
  14. helpers:
  15. - create_base_repo
  16. assertions:
  17. - "git rev-parse --is-inside-work-tree"
  18. turns:
  19. - intent: "List files in the current directory"
  20. limits:
  21. max_turns: 3
  22. turn_timeout: 10
  23. verify:
  24. criteria:
  25. - "Agent listed the files"
  26. observe: true
  27. """)
  28. return scenario
  29. @pytest.fixture
  30. def mock_backend(tmp_path):
  31. backend_dir = tmp_path / "backends"
  32. backend_dir.mkdir()
  33. (backend_dir / "mock.yaml").write_text("""
  34. name: mock
  35. cli: bash
  36. args: []
  37. required_env: []
  38. hooks:
  39. pre_run: []
  40. post_run: []
  41. shutdown: "exit"
  42. idle:
  43. quiescence_seconds: 1
  44. ready_pattern: "\\\\$"
  45. startup_timeout: 5
  46. terminal:
  47. cols: 80
  48. rows: 24
  49. session_logs:
  50. pattern: ""
  51. """)
  52. return backend_dir
  53. class TestE2ESmoke:
  54. def test_scenario_config_loads(self, mock_scenario):
  55. config = ScenarioConfig.from_yaml(mock_scenario)
  56. assert config.scenario == "e2e-smoke-test"
  57. def test_engine_setup_works(self, mock_scenario, mock_backend):
  58. fixtures_dir = Path(__file__).parent.parent / "fixtures"
  59. engine = Engine(
  60. scenario_path=mock_scenario,
  61. backend_name="mock",
  62. backends_dir=mock_backend,
  63. fixtures_dir=fixtures_dir,
  64. results_dir=Path("/tmp/drill-test-results"),
  65. )
  66. workdir = Path("/tmp/drill-e2e-smoke")
  67. if workdir.exists():
  68. shutil.rmtree(workdir)
  69. engine._setup(workdir)
  70. assert (workdir / "package.json").exists()
  71. assert (workdir / "src" / "index.js").exists()
  72. # Verify git state
  73. import subprocess
  74. result = subprocess.run(
  75. ["git", "branch", "--show-current"], cwd=workdir, capture_output=True, text=True
  76. )
  77. assert result.stdout.strip() == "main"
  78. result = subprocess.run(
  79. ["git", "log", "--oneline"], cwd=workdir, capture_output=True, text=True
  80. )
  81. assert "initial commit" in result.stdout
  82. # Cleanup
  83. shutil.rmtree(workdir, ignore_errors=True)