Skip to content

Commit 10e917a

Browse files
authored
clarify runtime route roles (#98)
1 parent 7798ca1 commit 10e917a

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ def run_strategy():
439439

440440
@app.post("/precheck")
441441
@app.get("/precheck")
442+
@app.post("/dry-run")
443+
@app.get("/dry-run")
442444
def precheck():
443445
try:
444446
return jsonify(
@@ -477,7 +479,7 @@ def precheck():
477479
@app.post("/probe")
478480
@app.get("/probe")
479481
def probe():
480-
return health()
482+
return session_check()
481483

482484

483485
if __name__ == "__main__":

tests/test_request_handling.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_cloud_run_route_contracts_are_registered():
2222
"/session-check": ["GET", "POST"],
2323
"/run": ["GET", "POST"],
2424
"/precheck": ["GET", "POST"],
25+
"/dry-run": ["GET", "POST"],
2526
"/probe": ["GET", "POST"],
2627
"/static/<path:filename>": ["GET"],
2728
}
@@ -99,6 +100,25 @@ def test_session_check_endpoint_calls_service_when_gate_enabled(monkeypatch):
99100
assert sent_messages == []
100101

101102

103+
def test_probe_alias_calls_session_check_service_when_gate_enabled(monkeypatch):
104+
monkeypatch.setenv("FIRSTRADE_RUN_SESSION_CHECK_ON_HTTP", "true")
105+
monkeypatch.setattr(
106+
main,
107+
"run_session_check",
108+
lambda: {"ok": True, "session_reused": False, "snapshot_persisted": True},
109+
)
110+
client = main.app.test_client()
111+
112+
response = client.post("/probe")
113+
114+
assert response.status_code == 200
115+
assert response.get_json() == {
116+
"ok": True,
117+
"session_reused": False,
118+
"snapshot_persisted": True,
119+
}
120+
121+
102122
def test_session_check_endpoint_notifies_only_on_error(monkeypatch):
103123
monkeypatch.setenv("FIRSTRADE_RUN_SESSION_CHECK_ON_HTTP", "true")
104124
monkeypatch.setenv("TELEGRAM_TOKEN", "token-1")
@@ -241,17 +261,23 @@ def fake_run_strategy_cycle_with_report(**kwargs):
241261
observed.update(kwargs)
242262
return {"ok": True, "action_done": False}
243263

264+
monkeypatch.setenv("FIRSTRADE_RUN_SESSION_CHECK_ON_HTTP", "true")
244265
monkeypatch.setattr(main, "_run_strategy_cycle_with_report", fake_run_strategy_cycle_with_report)
266+
monkeypatch.setattr(main, "run_session_check", lambda: {"ok": True, "session_reused": True})
245267
client = main.app.test_client()
246268

247269
precheck_response = client.post("/precheck")
270+
dry_run_response = client.post("/dry-run")
248271
probe_response = client.post("/probe")
249272

250273
assert precheck_response.status_code == 200
251274
assert precheck_response.get_json()["ok"] is True
275+
assert dry_run_response.status_code == 200
276+
assert dry_run_response.get_json()["ok"] is True
252277
assert observed == {
253278
"dry_run_override": True,
254279
"send_cycle_notification": False,
255280
"dispatch_plugin_alerts": False,
256281
}
257282
assert probe_response.status_code == 200
283+
assert probe_response.get_json()["ok"] is True

0 commit comments

Comments
 (0)