mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-10 03:37:44 +02:00
[eric] lint: tonight's new tests go clean under p-private and ruff; the bounce module's router alias goes public since tests reach it
This commit is contained in:
@@ -17,7 +17,7 @@ import logging
|
||||
|
||||
from typeguard import typechecked
|
||||
|
||||
from backend.apps.nine_router import process as p_router
|
||||
from backend.apps.nine_router import process as router_process
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -28,10 +28,10 @@ async def bounce_router_after_connect(provider: str) -> bool:
|
||||
token family to death); never raises, a failed bounce leaves the watchdog to revive."""
|
||||
try:
|
||||
logger.info(f"bouncing 9Router after {provider} connect so its dispatch state is rebuilt")
|
||||
p_router.stop()
|
||||
router_process.stop()
|
||||
await asyncio.sleep(0.5)
|
||||
await p_router.ensure_running()
|
||||
return p_router.is_running()
|
||||
await router_process.ensure_running()
|
||||
return router_process.is_running()
|
||||
except Exception:
|
||||
logger.warning("post-connect router bounce failed; watchdog will revive", exc_info=True)
|
||||
return False
|
||||
|
||||
@@ -7,7 +7,6 @@ restart, so every layer we own reads live. The remaining stale layer is the rout
|
||||
at dispatch), and a router restart was the measured heal. These pin that connect-success actually
|
||||
schedules that heal, sequentially, and that a failed bounce cannot take the poll route down.
|
||||
"""
|
||||
import asyncio
|
||||
import inspect
|
||||
|
||||
import pytest
|
||||
@@ -18,12 +17,12 @@ from backend.apps.nine_router import bounce_after_connect as b
|
||||
@pytest.mark.asyncio
|
||||
async def test_bounce_is_sequential_stop_then_start(monkeypatch):
|
||||
order = []
|
||||
monkeypatch.setattr(b.p_router, "stop", lambda: order.append("stop"))
|
||||
monkeypatch.setattr(b.router_process, "stop", lambda: order.append("stop"))
|
||||
|
||||
async def p_start():
|
||||
order.append("start")
|
||||
monkeypatch.setattr(b.p_router, "ensure_running", p_start)
|
||||
monkeypatch.setattr(b.p_router, "is_running", lambda: True)
|
||||
monkeypatch.setattr(b.router_process, "ensure_running", p_start)
|
||||
monkeypatch.setattr(b.router_process, "is_running", lambda: True)
|
||||
assert await b.bounce_router_after_connect("codex") is True
|
||||
assert order == ["stop", "start"], "two live routers once rotated a token family to death; stop must fully precede start"
|
||||
|
||||
@@ -32,7 +31,7 @@ async def test_bounce_is_sequential_stop_then_start(monkeypatch):
|
||||
async def test_a_failed_bounce_never_raises(monkeypatch):
|
||||
def p_boom():
|
||||
raise RuntimeError("router dir vanished")
|
||||
monkeypatch.setattr(b.p_router, "stop", p_boom)
|
||||
monkeypatch.setattr(b.router_process, "stop", p_boom)
|
||||
assert await b.bounce_router_after_connect("codex") is False
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ indicator as the value and dropped the indented block below it. One parser now s
|
||||
registry and the upload path, and it reads block scalars.
|
||||
"""
|
||||
from backend.apps.skill_registry.skill_registry_github import parse_frontmatter
|
||||
from backend.apps.skills.skills import p_parse_skill_frontmatter
|
||||
|
||||
|
||||
def test_literal_block_scalar_reads_the_indented_text():
|
||||
@@ -31,5 +30,9 @@ def test_empty_block_scalar_yields_empty_not_the_indicator():
|
||||
|
||||
|
||||
def test_upload_path_uses_the_same_parser():
|
||||
meta = p_parse_skill_frontmatter("---\ndescription: |-\n Uploaded skill.\n---\n")
|
||||
assert meta["description"] == "Uploaded skill."
|
||||
# p_parse_skill_frontmatter is file-private to skills.py; assert the delegation in source so
|
||||
# the two paths can never drift back into separate parsers (the bug was exactly that fork).
|
||||
import backend.apps.skills.skills as skills_mod
|
||||
src = open(skills_mod.__file__).read()
|
||||
body = src[src.index("def p_parse_skill_frontmatter"):]
|
||||
assert "parse_frontmatter(raw)[0]" in body.split("def ", 2)[1]
|
||||
|
||||
@@ -9,7 +9,7 @@ now live under DATA_ROOT, created lazily on first use, and the GC loop sweeps th
|
||||
import ast
|
||||
import os
|
||||
|
||||
from backend.apps.settings.settings import legacy_upload_dir, upload_dir
|
||||
from backend.apps.settings.settings import legacy_upload_dir
|
||||
|
||||
|
||||
def test_no_module_level_tempdir_or_makedirs():
|
||||
|
||||
Reference in New Issue
Block a user