fix(agent99): move dispatch reconciler to signal worker
This commit is contained in:
@@ -402,12 +402,80 @@ def test_agent99_retry_migration_matches_startup_bootstrap() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_api_runs_retry_schema_bootstrap_before_agent99_reconciler() -> None:
|
||||
def test_signal_worker_owns_agent99_reconciler_after_schema_bootstrap_gate() -> None:
|
||||
import inspect
|
||||
|
||||
from src import main as api_main
|
||||
from src.workers import signal_worker
|
||||
|
||||
source = inspect.getsource(api_main.lifespan)
|
||||
assert source.index("await init_db()") < source.index(
|
||||
api_source = inspect.getsource(api_main.lifespan)
|
||||
worker_source = inspect.getsource(signal_worker._main)
|
||||
|
||||
assert "run_agent99_controlled_dispatch_reconciler_loop" not in api_source
|
||||
assert worker_source.count(
|
||||
"run_agent99_controlled_dispatch_reconciler_loop()"
|
||||
) == 1
|
||||
assert worker_source.index(
|
||||
"if settings.DATABASE_BOOTSTRAP_DDL_ENABLED"
|
||||
) < worker_source.index(
|
||||
"run_agent99_controlled_dispatch_reconciler_loop()"
|
||||
)
|
||||
assert 'owner="cd_migration_preflight"' in worker_source
|
||||
assert 'owner="signal_worker"' in worker_source
|
||||
|
||||
|
||||
def test_signal_worker_agent99_reconciler_requires_url_and_token() -> None:
|
||||
import inspect
|
||||
|
||||
from src.workers import signal_worker
|
||||
|
||||
source = inspect.getsource(signal_worker._main)
|
||||
start = source.index("settings.AGENT99_SRE_ALERT_RELAY_URL.strip()")
|
||||
stop = source.index("# Setup graceful shutdown")
|
||||
ownership_block = source[start:stop]
|
||||
|
||||
assert "settings.AGENT99_SRE_ALERT_RELAY_TOKEN.strip()" in ownership_block
|
||||
assert "authenticated_relay_not_configured" in ownership_block
|
||||
assert (
|
||||
"signal_worker_agent99_controlled_dispatch_reconciler_skipped_fail_closed"
|
||||
in ownership_block
|
||||
)
|
||||
|
||||
|
||||
def test_signal_worker_gracefully_cancels_agent99_reconciler() -> None:
|
||||
import inspect
|
||||
|
||||
from src.workers import signal_worker
|
||||
|
||||
source = inspect.getsource(signal_worker._main)
|
||||
cancel = "agent99_controlled_dispatch_reconciler_task.cancel()"
|
||||
await_task = "await agent99_controlled_dispatch_reconciler_task"
|
||||
|
||||
assert cancel in source
|
||||
assert await_task in source
|
||||
assert source.index(cancel) < source.index(await_task)
|
||||
assert source.index(await_task) < source.index("await worker.stop()")
|
||||
|
||||
|
||||
def test_production_signal_worker_is_single_agent99_reconciler_owner() -> None:
|
||||
import inspect
|
||||
|
||||
from src import main as api_main
|
||||
from src.workers import signal_worker
|
||||
|
||||
root = Path(__file__).resolve().parents[3]
|
||||
manifest = yaml.safe_load(
|
||||
(root / "k8s/awoooi-prod/08-deployment-worker.yaml").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
)
|
||||
container = manifest["spec"]["template"]["spec"]["containers"][0]
|
||||
|
||||
assert manifest["spec"]["replicas"] == 1
|
||||
assert container["command"] == ["python", "-m", "src.workers.signal_worker"]
|
||||
assert "run_agent99_controlled_dispatch_reconciler_loop" not in (
|
||||
inspect.getsource(api_main.lifespan)
|
||||
)
|
||||
assert "run_agent99_controlled_dispatch_reconciler_loop" in (
|
||||
inspect.getsource(signal_worker._main)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user