mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
* feat(sandbox): pluggable per-engine registry (postgres/redis/mongo) Replaces the hardcoded postgres+redis branches in the provisioner and the env emitter with a registry of SandboxEngine specs (image, run args, readiness probe, connection, ROBOCO_TEST_* env) in a pure low module (roboco/models/sandbox.py). VALID_SANDBOX_SERVICES is derived from the registry — single source of truth — and the provisioner + orchestrator iterate it, so adding an engine is one class + one registry line, not another branch. Adds a mongo:8-alpine engine (ROBOCO_TEST_MONGO_*) as the third service alongside postgres/redis. Also fixes the cold-pull loop that stranded v0.19.0 board agents with empty error strings: docker run pulled inline under a 20s deadline, so a NAS cold pull was killed, cancelled, and re-pulled from scratch forever. _ensure_image now inspects + pulls (300s) before run; provisioning errors log type+message so a bare TimeoutError no longer shows as "". Panel edit-project dialog: postgres/redis toggles -> a Set<string> multi-select driven by a SANDBOX_SERVICES catalog, so new engines appear in the UI by adding to the catalog. Tests: engine parity (allowlist==registry, unique slugs/images, no None leak in env, SandboxInfo aggregates every engine), mongo provision + env injection, plus the existing postgres/redis provision/env/spawn/janitor suite updated to the registry shape. 821 unit / 5 skip green; ruff + mypy (360 files) clean. * docs(sandbox): reflect pluggable engine registry + mongo across docs CHANGELOG (0.19.0): Added entry for the pluggable sandbox engine registry (postgres/redis/mongo) + Fixed entry for the cold-pull loop/empty-error strand that boarded v0.19.0 board agents. docs/map (9 files): sandbox subsystem blurbs, SandboxProvisioner rows, _maybe_provision_sandbox/_append_sandbox_env rows, feature-flag rows, the migration-057 row + v0.17.0 delta, and the models.md VALID_SANDBOX_SERVICES note — all retitled to DB/Redis/Mongo via the engine registry (roboco/models/sandbox.py), with the one-class-one-line extension story and the _ensure_image cold-pull fix. Production-network (roboco_data) lines left as postgres+redis — mongo is sandbox-only, not a prod service. docs/rag (3 files): sandbox-db.md rewritten around the registry (engine list, generic _provision_engine, image pre-pull, ROBOCO_TEST_DB_*/REDIS_*/MONGO_* incl. MONGO_AUTH_DB=admin, single emit_env); config-reference sandbox flag row + subsection retitled; db-network-isolation framing broadened to postgres/redis/mongo. preconditions-and-rejections left untouched (its hit was an unrelated gateway see-also link). * test(e2e): harden umbrella close terminal reads with bounded wait-for-state The MegaTask umbrella close test flaked once on CI (ceo-approve returned 200 but the re-fetch saw awaiting_pm_review) then passed on re-run. The production path is deterministic: complete -> main_pm_complete -> submit_pm_review -> escalate_to_ceo -> ceo_approve -> commit, all on one session, all awaited; the fire-and-forget completion hooks are isolated (own session, best-effort, never touch task.status or the request session). 20 local runs could not reproduce it. The one real surface is the read pattern: the e2e stack commits on the uvicorn thread's loop and reads via a separate loop (run_db -> asyncio.run with a fresh engine), so a terminal single point-read can race a still-draining completion hook on a contended runner. Replace the two terminal point-reads with a bounded wait_for_status poll. Strictly better than a one-shot read: absorbs the transient, and a genuine state bug still surfaces via the timeout branch asserting against the last-read state. --------- Co-authored-by: Renn F <rennf93@users.noreply.github.com>
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
"""Project.sandbox_services / ProjectUpdate.sandbox_services validation.
|
|
|
|
Recognized services are whatever the engine registry exposes
|
|
(``VALID_SANDBOX_SERVICES`` in ``roboco.models.sandbox`` — postgres, redis,
|
|
mongo) — an unknown value must be rejected with a clear message rather than
|
|
silently accepted and later failing at provision time inside a container spawn.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
from roboco.models.base import Team
|
|
from roboco.models.project import Project, ProjectUpdate
|
|
|
|
|
|
def _project(sandbox_services: list[str] | None = None) -> Project:
|
|
return Project(
|
|
name="P",
|
|
slug="p",
|
|
git_url="https://example.com/r.git",
|
|
assigned_cell=Team.BACKEND,
|
|
created_by=uuid4(),
|
|
sandbox_services=sandbox_services,
|
|
)
|
|
|
|
|
|
def test_project_accepts_valid_sandbox_services() -> None:
|
|
project = _project(sandbox_services=["postgres", "redis"])
|
|
assert project.sandbox_services == ["postgres", "redis"]
|
|
|
|
|
|
def test_project_accepts_mongo() -> None:
|
|
project = _project(sandbox_services=["mongo"])
|
|
assert project.sandbox_services == ["mongo"]
|
|
|
|
|
|
def test_project_normalizes_sandbox_services_order_and_dupes() -> None:
|
|
project = _project(sandbox_services=["redis", "postgres", "redis"])
|
|
assert project.sandbox_services == ["postgres", "redis"]
|
|
|
|
|
|
def test_project_defaults_sandbox_services_to_none() -> None:
|
|
project = _project()
|
|
assert project.sandbox_services is None
|
|
|
|
|
|
def test_project_rejects_unknown_sandbox_service() -> None:
|
|
with pytest.raises(ValidationError):
|
|
_project(sandbox_services=["mysql"])
|
|
|
|
|
|
def test_project_update_accepts_valid_sandbox_services() -> None:
|
|
update = ProjectUpdate(sandbox_services=["postgres"])
|
|
assert update.sandbox_services == ["postgres"]
|
|
|
|
|
|
def test_project_update_rejects_unknown_sandbox_service() -> None:
|
|
with pytest.raises(ValidationError):
|
|
ProjectUpdate(sandbox_services=["mysql"])
|
|
|
|
|
|
def test_project_update_accepts_empty_list() -> None:
|
|
update = ProjectUpdate(sandbox_services=[])
|
|
assert update.sandbox_services == []
|