Skip to content

Commit 505d296

Browse files
authored
Drop legacy runtime routes (#99)
1 parent 10e917a commit 505d296

2 files changed

Lines changed: 9 additions & 49 deletions

File tree

main.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _runtime_error_notification_message(exc: Exception) -> str:
6969
error_text = f"{type(exc).__name__}: {exc}"
7070
if len(error_text) > 1200:
7171
error_text = error_text[:1197] + "..."
72-
is_health_check = request.path in {"/session-check", "/probe"}
72+
is_health_check = request.path == "/probe"
7373
if str(os.getenv("NOTIFY_LANG") or "").strip().lower().startswith("zh"):
7474
return "\n".join(
7575
(
@@ -348,8 +348,6 @@ def smoke():
348348
return jsonify({"ok": False, "error": str(exc)}), 500
349349

350350

351-
@app.post("/session-check")
352-
@app.get("/session-check")
353351
def session_check():
354352
if not _flag("FIRSTRADE_RUN_SESSION_CHECK_ON_HTTP"):
355353
return (
@@ -392,7 +390,6 @@ def session_check():
392390
)
393391

394392

395-
@app.post("/")
396393
@app.post("/run")
397394
@app.get("/run")
398395
def run_strategy():
@@ -437,11 +434,9 @@ def run_strategy():
437434
)
438435

439436

440-
@app.post("/precheck")
441-
@app.get("/precheck")
442437
@app.post("/dry-run")
443438
@app.get("/dry-run")
444-
def precheck():
439+
def dry_run():
445440
try:
446441
return jsonify(
447442
_run_strategy_cycle_with_report(

tests/test_request_handling.py

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ def route_methods():
1616

1717
def test_cloud_run_route_contracts_are_registered():
1818
assert route_methods() == {
19-
"/": ["GET", "POST"],
19+
"/": ["GET"],
2020
"/profiles": ["GET"],
2121
"/smoke": ["GET"],
22-
"/session-check": ["GET", "POST"],
2322
"/run": ["GET", "POST"],
24-
"/precheck": ["GET", "POST"],
2523
"/dry-run": ["GET", "POST"],
2624
"/probe": ["GET", "POST"],
2725
"/static/<path:filename>": ["GET"],
@@ -68,17 +66,17 @@ def test_run_endpoint_calls_strategy_cycle_when_gate_enabled(monkeypatch):
6866
assert response.get_json() == {"ok": True, "action_done": False}
6967

7068

71-
def test_session_check_endpoint_is_disabled_without_explicit_http_gate(monkeypatch):
69+
def test_probe_endpoint_is_disabled_without_explicit_http_gate(monkeypatch):
7270
monkeypatch.delenv("FIRSTRADE_RUN_SESSION_CHECK_ON_HTTP", raising=False)
7371
client = main.app.test_client()
7472

75-
response = client.get("/session-check")
73+
response = client.get("/probe")
7674

7775
assert response.status_code == 403
7876
assert response.get_json()["ok"] is False
7977

8078

81-
def test_session_check_endpoint_calls_service_when_gate_enabled(monkeypatch):
79+
def test_probe_endpoint_calls_service_when_gate_enabled(monkeypatch):
8280
monkeypatch.setenv("FIRSTRADE_RUN_SESSION_CHECK_ON_HTTP", "true")
8381
sent_messages = []
8482
monkeypatch.setattr(
@@ -89,7 +87,7 @@ def test_session_check_endpoint_calls_service_when_gate_enabled(monkeypatch):
8987
monkeypatch.setattr(main, "build_sender", lambda *_args, **_kwargs: sent_messages.append)
9088
client = main.app.test_client()
9189

92-
response = client.post("/session-check")
90+
response = client.post("/probe")
9391

9492
assert response.status_code == 200
9593
assert response.get_json() == {
@@ -100,26 +98,7 @@ def test_session_check_endpoint_calls_service_when_gate_enabled(monkeypatch):
10098
assert sent_messages == []
10199

102100

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-
122-
def test_session_check_endpoint_notifies_only_on_error(monkeypatch):
101+
def test_probe_endpoint_notifies_only_on_error(monkeypatch):
123102
monkeypatch.setenv("FIRSTRADE_RUN_SESSION_CHECK_ON_HTTP", "true")
124103
monkeypatch.setenv("TELEGRAM_TOKEN", "token-1")
125104
monkeypatch.setenv("GLOBAL_TELEGRAM_CHAT_ID", "chat-1")
@@ -139,7 +118,7 @@ def send(message):
139118
monkeypatch.setattr(main, "build_sender", fake_build_sender)
140119
client = main.app.test_client()
141120

142-
response = client.post("/session-check")
121+
response = client.post("/probe")
143122

144123
assert response.status_code == 500
145124
payload = response.get_json()
@@ -152,17 +131,6 @@ def send(message):
152131
assert "RuntimeError: session denied" in sent_messages[0][2]
153132

154133

155-
def test_root_post_calls_strategy_cycle_when_gate_enabled(monkeypatch):
156-
monkeypatch.setenv("FIRSTRADE_RUN_STRATEGY_ON_HTTP", "true")
157-
monkeypatch.setattr(main, "_run_strategy_cycle_with_report", lambda **_kwargs: {"ok": True, "action_done": False})
158-
client = main.app.test_client()
159-
160-
response = client.post("/")
161-
162-
assert response.status_code == 200
163-
assert response.get_json() == {"ok": True, "action_done": False}
164-
165-
166134
def test_run_endpoint_notifies_telegram_on_strategy_cycle_error(monkeypatch):
167135
sent_messages = []
168136

@@ -266,12 +234,9 @@ def fake_run_strategy_cycle_with_report(**kwargs):
266234
monkeypatch.setattr(main, "run_session_check", lambda: {"ok": True, "session_reused": True})
267235
client = main.app.test_client()
268236

269-
precheck_response = client.post("/precheck")
270237
dry_run_response = client.post("/dry-run")
271238
probe_response = client.post("/probe")
272239

273-
assert precheck_response.status_code == 200
274-
assert precheck_response.get_json()["ok"] is True
275240
assert dry_run_response.status_code == 200
276241
assert dry_run_response.get_json()["ok"] is True
277242
assert observed == {

0 commit comments

Comments
 (0)