mirror of
https://github.com/bleak-ai/gcontext.git
synced 2026-08-11 13:19:23 +02:00
API: replace the marketplace (submit/approve/reject/moderation) with a minimal counter table (id + downloads). Single upsert endpoint auto-creates rows on first ping, X-Source: site exclusion preserved. Inline migration copies existing counts and drops legacy tables. Removes slowapi, pyyaml, manifest validation, and all moderation routes. CLI: gcontext add now pings the API after a successful registry install so the download counter reflects real usage. Fire-and-forget with 3s timeout, gated to skip when GCONTEXT_REGISTRY is overridden (tests, private registries). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
73 lines
1.8 KiB
Python
73 lines
1.8 KiB
Python
import os
|
|
import socket
|
|
import subprocess
|
|
import time
|
|
|
|
import pytest
|
|
|
|
CONTAINER = "gcontext-api-test-pg"
|
|
PORT = 55433
|
|
|
|
|
|
def _wait_for_port(port: int, timeout: float = 30.0) -> None:
|
|
deadline = time.time() + timeout
|
|
while time.time() < deadline:
|
|
with socket.socket() as sock:
|
|
sock.settimeout(1)
|
|
if sock.connect_ex(("127.0.0.1", port)) == 0:
|
|
return
|
|
time.sleep(0.5)
|
|
raise RuntimeError("postgres did not come up")
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def postgres():
|
|
subprocess.run(["docker", "rm", "-f", CONTAINER], capture_output=True)
|
|
subprocess.run(
|
|
[
|
|
"docker", "run", "-d", "--name", CONTAINER,
|
|
"-e", "POSTGRES_PASSWORD=test",
|
|
"-e", "POSTGRES_DB=workflows",
|
|
"-p", f"{PORT}:5432",
|
|
"postgres:16-alpine",
|
|
],
|
|
check=True,
|
|
capture_output=True,
|
|
)
|
|
_wait_for_port(PORT)
|
|
os.environ["DATABASE_URL"] = (
|
|
f"postgresql+psycopg://postgres:test@127.0.0.1:{PORT}/workflows"
|
|
)
|
|
os.environ["ADMIN_TOKEN"] = "test-admin-token"
|
|
from app.db import init_db
|
|
|
|
for _ in range(30):
|
|
try:
|
|
init_db()
|
|
break
|
|
except Exception:
|
|
time.sleep(1)
|
|
else:
|
|
raise RuntimeError("could not initialize the database")
|
|
yield
|
|
subprocess.run(["docker", "rm", "-f", CONTAINER], capture_output=True)
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(postgres):
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.db import engine
|
|
from app.main import app
|
|
from app.models import Base
|
|
|
|
Base.metadata.drop_all(engine())
|
|
Base.metadata.create_all(engine())
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
|
|
|
|
@pytest.fixture()
|
|
def admin():
|
|
return {"Authorization": "Bearer test-admin-token"}
|