mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-08 05:45:07 -05:00
This pull request includes several changes to improve the backend functionality and configuration of the `autogpt_platform`. The most important changes involve adding a RabbitMQ service for testing, enhancing logging configuration, updating the linter script to handle errors gracefully, and modifying test configurations. Backend configuration improvements: * [`autogpt_platform/backend/docker-compose.test.yaml`](diffhunk://#diff-f6a211ff1c6d96d19adb5641ee287258a6af8d72a99e33dafb4a334094205a43R29-R43): Added RabbitMQ service configuration for testing, including health checks and environment variables. * [`autogpt_platform/backend/.env.example`](diffhunk://#diff-62020caf1b9a15e0e3b9b3b1b69d5f6464bf7643f62354cbbaabf755d57b6064R191-R192): Added a section delimiter for optional API keys for use in finding the optional keys end when auto generating integrations. Error handling and logging enhancements: * [`autogpt_platform/backend/linter.py`](diffhunk://#diff-0787e3ef718ac9963df64d9ab1d8e7a3b35dc4ab0cb874c65da6c2901e1e4991R3): Updated the `run` function to handle `subprocess.CalledProcessError` exceptions and print error output to `stderr` and prevent raising a stack trace when it should not. [[1]](diffhunk://#diff-0787e3ef718ac9963df64d9ab1d8e7a3b35dc4ab0cb874c65da6c2901e1e4991R3) [[2]](diffhunk://#diff-0787e3ef718ac9963df64d9ab1d8e7a3b35dc4ab0cb874c65da6c2901e1e4991L13-R23) Testing configuration updates: * [`autogpt_platform/backend/pyproject.toml`](diffhunk://#diff-26ebebd91da791c6484f07d9d91484a66f52836708f5294b24365603438b880cR111): Added `asyncio_default_fixture_loop_scope` to pytest configuration for better control over asyncio fixtures. * [`autogpt_platform/backend/run_tests.py`](diffhunk://#diff-f09930577243a4ef5213bf6191a3c500a4b8d3dcfee2d4b452cf7ce66b3c494fL55): Removed the `postgres-test` service from the test setup script as we need all of docker services up for the tests to run.
71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
|
|
def wait_for_postgres(max_retries=5, delay=5):
|
|
for _ in range(max_retries):
|
|
try:
|
|
result = subprocess.run(
|
|
[
|
|
"docker",
|
|
"compose",
|
|
"-f",
|
|
"docker-compose.test.yaml",
|
|
"exec",
|
|
"postgres-test",
|
|
"pg_isready",
|
|
"-U",
|
|
"postgres",
|
|
"-d",
|
|
"postgres",
|
|
],
|
|
check=True,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
if "accepting connections" in result.stdout:
|
|
print("PostgreSQL is ready.")
|
|
return True
|
|
except subprocess.CalledProcessError:
|
|
print(f"PostgreSQL is not ready yet. Retrying in {delay} seconds...")
|
|
time.sleep(delay)
|
|
print("Failed to connect to PostgreSQL.")
|
|
return False
|
|
|
|
|
|
def run_command(command, check=True):
|
|
try:
|
|
subprocess.run(command, check=check)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Command failed: {e}")
|
|
sys.exit(1)
|
|
|
|
|
|
def test():
|
|
# Start PostgreSQL with Docker Compose
|
|
run_command(
|
|
[
|
|
"docker",
|
|
"compose",
|
|
"-f",
|
|
"docker-compose.test.yaml",
|
|
"up",
|
|
"-d",
|
|
]
|
|
)
|
|
|
|
if not wait_for_postgres():
|
|
run_command(["docker", "compose", "-f", "docker-compose.test.yaml", "down"])
|
|
sys.exit(1)
|
|
|
|
# Run Prisma migrations
|
|
run_command(["prisma", "migrate", "dev"])
|
|
|
|
# Run the tests
|
|
result = subprocess.run(["pytest"] + sys.argv[1:], check=False)
|
|
|
|
run_command(["docker", "compose", "-f", "docker-compose.test.yaml", "down"])
|
|
|
|
sys.exit(result.returncode)
|