sched: server scheduler wiring, config section, transport lifespan, CLI flag (T12)
This commit is contained in:
+129
-6
@@ -88,7 +88,7 @@ def test_rpc_server_cli_uses_configured_store_and_transport(
|
||||
captured["drafts"] = drafts
|
||||
return object()
|
||||
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False):
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False, lifespan=None):
|
||||
captured["server"] = server
|
||||
captured["rpc_path"] = rpc_path
|
||||
captured["drafts"] = drafts
|
||||
@@ -135,7 +135,7 @@ def test_rpc_server_cli_uses_mcp_config_server(monkeypatch, tmp_path) -> None:
|
||||
captured["mcp_config_path"] = path
|
||||
return object()
|
||||
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False):
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False, lifespan=None):
|
||||
captured["server"] = server
|
||||
captured["rpc_path"] = rpc_path
|
||||
captured["drafts"] = drafts
|
||||
@@ -211,7 +211,7 @@ def test_rpc_server_cli_mcp_config_builds_registry_capable_server(
|
||||
)
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False):
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False, lifespan=None):
|
||||
captured["source_registry_admin"] = server.source_registry_admin
|
||||
captured["rpc_path"] = rpc_path
|
||||
captured["drafts"] = drafts
|
||||
@@ -268,7 +268,7 @@ def test_rpc_server_cli_mcp_config_with_config_uses_transport_settings(
|
||||
)
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False):
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False, lifespan=None):
|
||||
captured["server"] = server
|
||||
captured["rpc_path"] = rpc_path
|
||||
captured["drafts"] = drafts
|
||||
@@ -310,7 +310,7 @@ def test_rpc_server_cli_config_with_mcp_source_uses_mcp_builder(
|
||||
captured["build_drafts"] = drafts
|
||||
return object()
|
||||
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False):
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False, lifespan=None):
|
||||
captured["server"] = server
|
||||
captured["rpc_path"] = rpc_path
|
||||
captured["drafts"] = drafts
|
||||
@@ -422,7 +422,7 @@ def test_rpc_server_cli_config_uses_workflow_store_override(
|
||||
captured["build_drafts"] = drafts
|
||||
return object()
|
||||
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False):
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False, lifespan=None):
|
||||
captured["server"] = server
|
||||
captured["rpc_path"] = rpc_path
|
||||
captured["drafts"] = drafts
|
||||
@@ -442,3 +442,126 @@ def test_rpc_server_cli_config_uses_workflow_store_override(
|
||||
|
||||
assert result.exit_code == 0, result.output
|
||||
assert captured["workflow_store_root"] == (tmp_path / ".workflow").resolve()
|
||||
|
||||
|
||||
def test_rpc_server_cli_help_mentions_enable_scheduler() -> None:
|
||||
result = CliRunner().invoke(app, ["--help"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "--enable-scheduler" in result.output
|
||||
|
||||
|
||||
def test_rpc_server_cli_scheduler_disabled_by_default(monkeypatch, tmp_path) -> None:
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False, lifespan=None):
|
||||
captured["lifespan"] = lifespan
|
||||
return object()
|
||||
|
||||
def fake_uvicorn_run(app_obj, *, host, port, access_log):
|
||||
captured["app"] = app_obj
|
||||
|
||||
monkeypatch.setattr("wf_server.cli.create_rpc_app", fake_create_rpc_app)
|
||||
monkeypatch.setattr("wf_server.cli.uvicorn.run", fake_uvicorn_run)
|
||||
|
||||
result = CliRunner().invoke(app, ["--store-root", str(tmp_path / "store")])
|
||||
|
||||
assert result.exit_code == 0, result.output
|
||||
assert captured["app"] is not None
|
||||
assert captured["lifespan"] is None
|
||||
|
||||
|
||||
def test_rpc_server_cli_enable_scheduler_with_store_root_builds_app(
|
||||
monkeypatch, tmp_path
|
||||
) -> None:
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False, lifespan=None):
|
||||
captured["server"] = server
|
||||
captured["lifespan"] = lifespan
|
||||
return object()
|
||||
|
||||
def fake_uvicorn_run(app_obj, *, host, port, access_log):
|
||||
captured["app"] = app_obj
|
||||
|
||||
monkeypatch.setattr("wf_server.cli.create_rpc_app", fake_create_rpc_app)
|
||||
monkeypatch.setattr("wf_server.cli.uvicorn.run", fake_uvicorn_run)
|
||||
|
||||
result = CliRunner().invoke(
|
||||
app, ["--store-root", str(tmp_path / "store"), "--enable-scheduler"]
|
||||
)
|
||||
|
||||
assert result.exit_code == 0, result.output
|
||||
assert captured["server"] is not None
|
||||
assert captured["app"] is not None
|
||||
assert captured["lifespan"] is not None
|
||||
|
||||
|
||||
def test_rpc_server_cli_config_scheduler_section_enables_without_flag(
|
||||
monkeypatch, tmp_path
|
||||
) -> None:
|
||||
config_path = tmp_path / "wf.json"
|
||||
config_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"version": 1,
|
||||
"server": {
|
||||
"store": {"kind": "filesystem", "root": ".wf_store"},
|
||||
"scheduler": {"enabled": True},
|
||||
},
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False, lifespan=None):
|
||||
captured["lifespan"] = lifespan
|
||||
return object()
|
||||
|
||||
def fake_uvicorn_run(app_obj, *, host, port, access_log):
|
||||
captured["app"] = app_obj
|
||||
|
||||
monkeypatch.setattr("wf_server.cli.create_rpc_app", fake_create_rpc_app)
|
||||
monkeypatch.setattr("wf_server.cli.uvicorn.run", fake_uvicorn_run)
|
||||
|
||||
result = CliRunner().invoke(app, ["--config", str(config_path)])
|
||||
|
||||
assert result.exit_code == 0, result.output
|
||||
assert captured["lifespan"] is not None
|
||||
|
||||
|
||||
def test_rpc_server_cli_flag_overrides_disabled_config_scheduler(
|
||||
monkeypatch, tmp_path
|
||||
) -> None:
|
||||
config_path = tmp_path / "wf.json"
|
||||
config_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"version": 1,
|
||||
"server": {
|
||||
"store": {"kind": "filesystem", "root": ".wf_store"},
|
||||
"scheduler": {"enabled": False},
|
||||
},
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
def fake_create_rpc_app(server, *, rpc_path="/rpc", drafts=False, lifespan=None):
|
||||
captured["lifespan"] = lifespan
|
||||
return object()
|
||||
|
||||
def fake_uvicorn_run(app_obj, *, host, port, access_log):
|
||||
captured["app"] = app_obj
|
||||
|
||||
monkeypatch.setattr("wf_server.cli.create_rpc_app", fake_create_rpc_app)
|
||||
monkeypatch.setattr("wf_server.cli.uvicorn.run", fake_uvicorn_run)
|
||||
|
||||
result = CliRunner().invoke(
|
||||
app, ["--config", str(config_path), "--enable-scheduler"]
|
||||
)
|
||||
|
||||
assert result.exit_code == 0, result.output
|
||||
assert captured["lifespan"] is not None
|
||||
|
||||
Reference in New Issue
Block a user