Repository navigation
feat(roadmap): Seam the serve start and the roadmap table - #6150
Conversation
0973ce3 to
b2c6a4c
Compare
|
The steps of the job: Stopped at group 2. Failure class:
Reason: Last message of the agent (a claim that no check verified): Now the source change in The job discarded this work. Read it before you retry: diff --git a/src/devops_cli/commands/serve.py b/src/devops_cli/commands/serve.py
index 1c96e39e2..12e9f5a83 100644
--- a/src/devops_cli/commands/serve.py
+++ b/src/devops_cli/commands/serve.py
@@ -23,6 +23,7 @@ from devops_cli.output import (
print_info,
print_success,
)
+from devops_cli.server.start import get_server_starter
if TYPE_CHECKING:
pass
@@ -41,8 +42,8 @@ app = new_typer(
def uvicorn_options(
*, host: str, port: int, reload: bool, workers: int, log_level: str, service: bool
) -> dict[str, Any]:
- """The options that `devops serve` passes to `uvicorn.run`, besides the app. The start and
- its dry run both use them."""
+ """The options that `devops serve` passes to the server start, besides the app. The start
+ and its dry run both use them."""
if service:
return {"host": host, "port": port}
if reload:
@@ -123,8 +124,6 @@ def serve(
)
return
- import uvicorn
-
if service:
from devops_cli.config.constants import CONST_SERVICE_FAILURES_FILENAME
from devops_cli.config.settings import load_settings
@@ -179,7 +178,7 @@ def serve(
read_row_state=read_row_state,
)
- uvicorn.run(
+ get_server_starter().start(
service_app,
factory=True,
log_config=service_log_config(log_level),
@@ -228,6 +227,6 @@ def serve(
if reload:
# In reload mode, pass module string
- uvicorn.run("devops_cli.server.app:create_app", factory=True, **options)
+ get_server_starter().start("devops_cli.server.app:create_app", factory=True, **options)
else:
- uvicorn.run(fastapi_app, **options)
+ get_server_starter().start(fastapi_app, **options)
diff --git a/tests/roadmap/test_roadmap_run_service.py b/tests/roadmap/test_roadmap_run_service.py
index 9dade1e45..cfbea0e67 100644
--- a/tests/roadmap/test_roadmap_run_service.py
+++ b/tests/roadmap/test_roadmap_run_service.py
@@ -23,11 +23,26 @@ from devops_cli.roadmap.run import (
)
from devops_cli.server.service import TriggerBatch, no_round_pause
from tests.support.fakes.roadmap_store import InMemoryRoadmapStore
+from tests.support.fakes.server import FakeServerStarter
from tests.support.roadmap_run import NOW, OPENED, PLACED, REPO
pytestmark = pytest.mark.usefixtures("keyring_store")
+def install_fake_starter() -> FakeServerStarter:
+ """Install a `FakeServerStarter` for this case, and give it to the case.
+
+ `devops serve --service` starts the server through `devops_cli.server.start`, so the fake
+ records the start call and builds the app from the factory, as uvicorn does. The reset of the
+ test floor removes it after the case (`tests/conftest.py`).
+ """
+ from devops_cli.server.start import install_server_starter
+
+ fake = FakeServerStarter()
+ install_server_starter(fake)
+ return fake
+
+
@pytest.fixture
def service_settings(monkeypatch: pytest.MonkeyPatch) -> None:
"""The settings `devops serve --service` needs to manage REPO as a GitHub App."""
@@ -51,9 +66,9 @@ def test_service_wiring(
(#1532, #5553). The start removes the clone of an earlier lane."""
retired = service_state_dir() / REPO / "model-clone"
retired.mkdir(parents=True)
- with patch("uvicorn.run") as mock_uvicorn:
- res = cli(["serve", "--service"])
- fastapi_app = mock_uvicorn.call_args[0][0]()
+ fake = install_fake_starter()
+ res = cli(["serve", "--service"])
+ fastapi_app = fake.apps[0]
batch = TriggerBatch(repo=REPO, counts={OPENED: 1}, first_at=NOW, last_at=NOW)
with patch("devops_cli.roadmap.run.run_due_jobs") as mock_run:
@@ -110,9 +125,9 @@ def test_the_service_that_serve_starts_reads_its_halt_and_budget_from_the_volume
window = [[(datetime.now(UTC) - timedelta(minutes=5)).isoformat(), 60]]
(volume / CONST_SERVICE_BUDGET_FILENAME).write_text(json.dumps(window), encoding="utf-8")
- with patch("uvicorn.run") as mock_uvicorn:
- res = cli(["serve", "--service"])
- manager = mock_uvicorn.call_args[0][0]().state.service_manager
+ fake = install_fake_starter()
+ res = cli(["serve", "--service"])
+ manager = fake.apps[0].state.service_manager
assert (res.exit_code, manager.pause.halted(), manager.budget.spent()) == (0, True, 60)
@@ -133,9 +148,9 @@ def test_in_a_pod_the_service_reads_its_volume_only_when_it_holds_the_lease_of_t
halt = {"identity": "devops-roadmap[bot]", "repo": REPO, "kind": "GitHubUnauthenticatedError"}
(volume / CONST_SERVICE_HALT_FILENAME).write_text(json.dumps(halt), encoding="utf-8")
- with patch("uvicorn.run") as mock_uvicorn:
- res = cli(["serve", "--service"])
- manager = mock_uvicorn.call_args[0][0]().state.service_manager
+ fake = install_fake_starter()
+ res = cli(["serve", "--service"])
+ manager = fake.apps[0].state.service_manager
lease = manager.rows_lease
assert (
diff --git a/tests/server/test_server.py b/tests/server/test_server.py
index a14d12483..d42248944 100644
--- a/tests/server/test_server.py
+++ b/tests/server/test_server.py
@@ -3,7 +3,6 @@
from __future__ import annotations
import logging
-from collections.abc import Callable
from pathlib import Path
from typing import Any
from unittest.mock import patch
@@ -17,6 +16,7 @@ from devops_cli.commands.serve import app as serve_app
from devops_cli.config.constants import CONST_GITHUB_APP_PRIVATE_KEY_ENV
from devops_cli.server.app import create_app
from devops_cli.server.json_logs import service_log_config
+from tests.support.fakes.server import FakeServerStarter
pytestmark = pytest.mark.usefixtures("keyring_store")
@@ -26,6 +26,27 @@ def runner() -> CliRunner:
return CliRunner()
+class NoStartStarter(FakeServerStarter):
+ """A starter that fails the case: a run that starts no server reaches it never."""
+
+ def start(self, target: Any, /, **options: Any) -> None:
+ raise AssertionError("no server")
+
+
+def install_fake_starter(starter: FakeServerStarter | None = None) -> FakeServerStarter:
+ """Install a `FakeServerStarter` for this case, and give it to the case.
+
+ The start of `devops serve` goes through `devops_cli.server.start`, so the fake records the
+ call that the command made and builds the app from a factory as uvicorn does. The reset of
+ the test floor removes it after the case (`tests/conftest.py`).
+ """
+ from devops_cli.server.start import install_server_starter
+
+ fake = starter if starter is not None else FakeServerStarter()
+ install_server_starter(fake)
+ return fake
+
+
@pytest.fixture
def client() -> TestClient:
"""Fixture providing TestClient for FastAPI app."""
@@ -299,14 +320,14 @@ def test_serve_cli_help(runner: CliRunner) -> None:
def test_serve_cli_invocation_mocked(runner: CliRunner) -> None:
"""Test devops serve starts uvicorn server."""
- with patch("uvicorn.run") as mock_uvicorn:
- result = runner.invoke(serve_app, ["--host", "::1", "--port", "9000"])
- assert result.exit_code == 0
- assert mock_uvicorn.called
- assert (mock_uvicorn.call_args.kwargs["host"], mock_uvicorn.call_args.kwargs["port"]) == (
- "::1",
- 9000,
- )
+ fake = install_fake_starter()
+
+ result = runner.invoke(serve_app, ["--host", "::1", "--port", "9000"])
+
+ assert (result.exit_code, [(call.host, call.port) for call in fake.calls]) == (
+ 0,
+ [("::1", 9000)],
+ )
def test_serve_service_mode_flags_rejected(runner: CliRunner) -> None:
@@ -380,16 +401,15 @@ def test_serve_service_mode_success(runner: CliRunner, monkeypatch: pytest.Monke
monkeypatch.setenv("DEVOPS_CLI_SERVICE_REPOS", '["example-org/repo1"]')
_set_github_app(monkeypatch)
monkeypatch.setenv("DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS", '{"example-org/repo1":"secret-1"}')
+ fake = install_fake_starter()
+
+ result = runner.invoke(serve_app, ["--service", "--host", "::1", "--port", "8787"])
- with patch("uvicorn.run") as mock_uvicorn:
- result = runner.invoke(serve_app, ["--service", "--host", "::1", "--port", "8787"])
- assert (
- result.exit_code,
- mock_uvicorn.called,
- mock_uvicorn.call_args.kwargs["host"],
- mock_uvicorn.call_args.kwargs["port"],
- mock_uvicorn.call_args.kwargs["log_config"],
- ) == (0, True, "::1", 8787, service_log_config("info"))
+ calls = [
+ (call.host, call.port, call.factory, call.log_config == service_log_config("info"))
+ for call in fake.calls
+ ]
+ assert (result.exit_code, calls) == (0, [("::1", 8787, True, True)])
def test_serve_service_mode_leaves_logging_to_the_server(
@@ -405,25 +425,29 @@ def test_serve_service_mode_leaves_logging_to_the_server(
monkeypatch.setenv("DEVOPS_CLI_SERVICE_REPOS", '["example-org/repo1"]')
_set_github_app(monkeypatch)
monkeypatch.setenv("DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS", '{"example-org/repo1":"secret-1"}')
+ install_fake_starter()
- with patch("uvicorn.run"):
- result = runner.invoke(serve_app, ["--service"])
+ result = runner.invoke(serve_app, ["--service"])
logging.getLogger("devops_cli.server").warning("a record after the service command")
assert (result.exit_code, "a record after the service command" in caplog.text) == (0, True)
-def test_serve_service_mode_builds_the_app_after_the_server_applies_its_logging(
+def test_serve_service_mode_hands_the_starter_an_app_factory_and_the_json_log_config(
runner: CliRunner, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
) -> None:
- """uvicorn builds the service app from a factory after it applies the JSON `log_config`.
+ """The service start names a factory and the JSON `log_config`, and the fake builds the app.
- Building the app warns about each managed repository with no webhook secret. Built before the
- command called uvicorn, that warning had no handler yet and came out as plain text on stderr.
+ uvicorn applies `log_config` and then builds the app from the factory, so building the app
+ warns about each managed repository with no webhook secret after the JSON logging is on. A
+ command that built the app itself would pass the app, set no factory, and leave `apps` empty.
"""
monkeypatch.setenv("DEVOPS_CLI_SERVICE_REPOS", '["example-org/repo1", "example-org/repo2"]')
_set_github_app(monkeypatch)
monkeypatch.setenv("DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS", '{"example-org/repo1":"secret-1"}')
+ fake = install_fake_starter()
+
+ result = runner.invoke(serve_app, ["--service"])
def missing_secret_warnings() -> list[str]:
return [
@@ -432,24 +456,17 @@ def test_serve_service_mode_builds_the_app_after_the_server_applies_its_logging(
if record.getMessage().startswith("No webhook secret configured")
]
- warnings_when_run: list[list[str]] = []
-
- def run(app_factory: Callable[[], object], **_: object) -> None:
- warnings_when_run.append(missing_secret_warnings())
- app_factory()
-
- with patch("uvicorn.run", side_effect=run) as mock_uvicorn:
- result = runner.invoke(serve_app, ["--service"])
-
assert (
result.exit_code,
- mock_uvicorn.call_args.kwargs.get("factory"),
- warnings_when_run,
+ [call.factory for call in fake.calls],
+ [call.log_config == service_log_config("info") for call in fake.calls],
+ len(fake.apps),
missing_secret_warnings(),
) == (
0,
- True,
- [[]],
+ [True],
+ [True],
+ 1,
["No webhook secret configured for managed repository: example-org/repo2"],
)
@@ -470,13 +487,12 @@ def _plan_lines(output: str) -> list[str]:
def test_serve_dry_run_lists_the_bind_and_the_start(cli: Any, flag_first: bool) -> None:
"""A dry run builds no app, starts no server, and lists the bind and the start."""
argv = ["serve", "--host", "127.0.0.1", "--port", "9000", "--workers", "2"]
- with (
- patch("uvicorn.run", side_effect=AssertionError("no server")),
- patch("devops_cli.server.app.create_app", side_effect=AssertionError("no app")),
- ):
+ fake = install_fake_starter(NoStartStarter())
+ with patch("devops_cli.server.app.create_app", side_effect=AssertionError("no app")):
result = cli(["--dry-run", *argv] if flag_first else [*argv, "--dry-run"])
assert result.exit_code == 0, result.output
+ assert fake.calls == []
assert _plan_lines(result.output) == [
"BIND tcp 127.0.0.1:9000",
"START uvicorn rest app (host=127.0.0.1 port=9000 workers=2 log_level=info)",
@@ -485,8 +501,8 @@ def test_serve_dry_run_lists_the_bind_and_the_start(cli: Any, flag_first: bool)
def test_serve_service_dry_run_reads_no_settings(cli: Any) -> None:
"""`serve --service --dry-run` loads no settings and reads no credential."""
+ fake = install_fake_starter(NoStartStarter())
with (
- patch("uvicorn.run", side_effect=AssertionError("no server")),
patch(
"devops_cli.config.settings.load_settings", side_effect=AssertionError("no settings")
),
@@ -495,6 +511,7 @@ def test_serve_service_dry_run_reads_no_settings(cli: Any) -> None:
result = cli(["serve", "--service", "--port", "9000", "--dry-run"])
assert result.exit_code == 0, result.output
+ assert fake.calls == []
assert _plan_lines(result.output) == [
"BIND tcp 127.0.0.1:9000",
"START uvicorn service app (host=127.0.0.1 port=9000)",
@@ -505,9 +522,10 @@ def test_serve_starts_what_its_plan_lists(cli: Any) -> None:
"""The start passes uvicorn the options of the plan."""
argv = ["serve", "--host", "::1", "--port", "9000", "--workers", "2"]
planned = _plan_lines(cli([*argv, "--dry-run"]).output)
- with patch("uvicorn.run") as start:
- result = cli(argv)
+ fake = install_fake_starter()
+
+ result = cli(argv)
assert result.exit_code == 0, result.output
- options = " ".join(f"{name}={value}" for name, value in start.call_args.kwargs.items())
+ options = " ".join(f"{name}={value}" for name, value in fake.calls[0].options.items())
assert planned == ["BIND tcp ::1:9000", f"START uvicorn rest app ({options})"]The item is Blocked, and the job will not run it. Fix the cause. Then comment
|
b2c6a4c to
4a25abe
Compare
|
The steps of the job: Stopped at group 2. Failure class:
Reason: Last message of the agent (a claim that no check verified): Now let me read The item is Blocked, and the job will not run it. Fix the cause. Then comment
|
4a25abe to
b32bb32
Compare
|
The steps of the job: Stopped at group 2. Failure class:
Reason: Last message of the agent (a claim that no check verified): none. The item is Blocked, and the job will not run it. Fix the cause. Then comment
|
b32bb32 to
36d080a
Compare
🤖 I have created a release *beep* *boop* --- ## [0.175.0](v0.174.7...v0.175.0) (2026-11-18) ### Features * **roadmap:** Add a loopback gateway broker to a step ([#6157](#6157)) ([d15dfcf](d15dfcf)) * **roadmap:** Add RAG index rows to repository onboarding ([#6041](#6041)) ([59b424a](59b424a)) * **roadmap:** Seam the serve start and the roadmap table ([#6150](#6150)) ([de55e8b](de55e8b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
The serve and roadmap tests patched
uvicorn.runandrun_due_jobs, because no seam showed a test the ASGI app thatdevops servestarts or the lane table that a Service lane runs (#3885). This change adds the server start seam (ServerStarter, withFakeServerStarterand a contract test on a loopback port) andLaneSpecon the app state. It moves the body ofroadmap runintorun_roadmap_command, and adds the twodevops cicache cases over the git fake. The patch ceiling falls from 377 to 375.Closes #3885
Change:
openspec/changes/archive/2026-11-18-3885-add-the-seams-the-serve-and/