mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-13 10:15:21 +00:00
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
"""Tests for ``DeviceBroker.drain_output`` deadline + control handling."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
|
|
def _dispatch(broker):
|
|
envelope = {"invocation_id": "inv_test", "action": "run_command"}
|
|
return broker.dispatch_invocation("dev_x", "user_x", envelope)
|
|
|
|
|
|
def test_drain_output_returns_after_deadline_with_no_output(broker_env):
|
|
# Device never connects / posts output: the generator must stop once the
|
|
# deadline passes instead of looping forever.
|
|
broker, _fake = broker_env
|
|
inv = _dispatch(broker)
|
|
deadline = time.time() + 0.2
|
|
start = time.time()
|
|
chunks = list(
|
|
broker.drain_output(inv.invocation_id, timeout=0.05, deadline=deadline)
|
|
)
|
|
elapsed = time.time() - start
|
|
assert chunks == []
|
|
assert elapsed < 2.0
|
|
|
|
|
|
def test_drain_output_yields_then_stops_on_control(broker_env):
|
|
# A normal stream drains stdout then stops on the closing control chunk.
|
|
broker, _fake = broker_env
|
|
inv = _dispatch(broker)
|
|
broker.submit_output_chunk(inv.invocation_id, {"stream": "stdout", "chunk": "hello"})
|
|
broker.submit_output_chunk(
|
|
inv.invocation_id, {"stream": "control", "exit_code": 0, "duration_ms": 1}
|
|
)
|
|
deadline = time.time() + 5.0
|
|
chunks = list(
|
|
broker.drain_output(inv.invocation_id, timeout=0.05, deadline=deadline)
|
|
)
|
|
assert chunks[0] == {"stream": "stdout", "chunk": "hello"}
|
|
assert chunks[-1]["stream"] == "control"
|
|
assert chunks[-1]["exit_code"] == 0
|
|
|
|
|
|
def test_drain_output_stops_when_completed_without_control(broker_env):
|
|
# If the invocation is marked completed but no control chunk is on the
|
|
# stream, the completed flag still terminates the drain loop.
|
|
broker, fake = broker_env
|
|
inv = _dispatch(broker)
|
|
fake.hset(f"dev:inv:{inv.invocation_id}", mapping={"completed": "1"})
|
|
chunks = list(broker.drain_output(inv.invocation_id, timeout=0.05))
|
|
assert chunks == []
|
|
|
|
|
|
def test_drain_output_reports_error_when_redis_unavailable(monkeypatch):
|
|
# No Redis: the tool must get a clear control/error chunk, not hang.
|
|
from docsgpt.devices.broker import DeviceBroker
|
|
|
|
monkeypatch.setattr(
|
|
"docsgpt.devices.broker.get_redis_instance", lambda: None
|
|
)
|
|
broker = DeviceBroker()
|
|
chunks = list(broker.drain_output("inv_missing", timeout=0.05))
|
|
assert len(chunks) == 1
|
|
assert chunks[0]["stream"] == "control"
|
|
assert "unavailable" in chunks[0]["error"]
|