mirror of
https://github.com/Colton-z/AstraBox.git
synced 2026-09-28 22:22:59 +08:00
The open-source, self-hosted alternative to Claude Managed Agents: run Claude Code, Codex, Hermes, DeepSeek Harness and Pi as managed Agents on your own infrastructure, with conversations that start and resume in seconds.
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
"""Resolve the PostgreSQL test URL from the maintained local deployment."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from collections.abc import Mapping
|
|
from pathlib import Path
|
|
from urllib.parse import quote
|
|
|
|
_REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def resolve_postgresql_test_url(
|
|
env: Mapping[str, str] = os.environ,
|
|
*,
|
|
repo_root: Path = _REPO_ROOT,
|
|
) -> str:
|
|
"""Use an explicit test URL or the password generated by ``compose.sh``."""
|
|
explicit = env.get("ASTRABOX_TEST_POSTGRES_URL", "").strip()
|
|
if explicit:
|
|
return explicit
|
|
|
|
default_secret_dir = repo_root / ".astrabox" / "database-secrets"
|
|
secret_dir = Path(
|
|
env.get("ASTRABOX_LOCAL_DATABASE_SECRET_DIR", "").strip()
|
|
or default_secret_dir
|
|
)
|
|
password_file = secret_dir / "astrabox_password"
|
|
try:
|
|
password = password_file.read_text(encoding="utf-8").strip()
|
|
except OSError as exc:
|
|
raise RuntimeError(
|
|
"PostgreSQL tests need ASTRABOX_TEST_POSTGRES_URL or the maintained "
|
|
f"Compose credential at {password_file}. Start PostgreSQL with "
|
|
"scripts/compose.sh up -d postgres."
|
|
) from exc
|
|
if not password:
|
|
raise RuntimeError(f"PostgreSQL test password file is empty: {password_file}")
|
|
|
|
port_text = env.get("ASTRABOX_POSTGRES_PORT", "55432").strip()
|
|
try:
|
|
port = int(port_text)
|
|
except ValueError as exc:
|
|
raise RuntimeError(
|
|
f"ASTRABOX_POSTGRES_PORT must be an integer, got {port_text!r}"
|
|
) from exc
|
|
if not 1 <= port <= 65535:
|
|
raise RuntimeError(
|
|
f"ASTRABOX_POSTGRES_PORT must be between 1 and 65535, got {port}"
|
|
)
|
|
|
|
return (
|
|
"postgresql+asyncpg://astrabox:"
|
|
f"{quote(password, safe='')}@127.0.0.1:{port}/astrabox"
|
|
)
|