Skip to content

Commit cae0178

Browse files
Merge branch 'official-stockfish:master' into master
2 parents f32782a + 144d3e9 commit cae0178

34 files changed

+1526
-488
lines changed

.github/workflows/server.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ jobs:
3939

4040
- name: Run server tests
4141
run: uv run python -m unittest discover -vb -s tests
42+
env:
43+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ repos:
99
- id: end-of-file-fixer
1010
- id: trailing-whitespace
1111
- repo: https://github.com/astral-sh/ruff-pre-commit
12-
rev: v0.11.13
12+
rev: v0.12.1
1313
hooks:
1414
- id: ruff
1515
args: [--fix, --exit-zero]
1616
- id: ruff-format
1717
- repo: https://github.com/astral-sh/uv-pre-commit
18-
rev: 0.7.11
18+
rev: 0.7.16
1919
hooks:
2020
- id: uv-lock

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies = []
99
[dependency-groups]
1010
dev = [
1111
"pre-commit>=4.2.0",
12-
"ruff>=0.11.13",
12+
"ruff>=0.12.1",
1313
]
1414

1515
[tool.ruff]

server/fishtest/__init__.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import threading
55
import traceback
66

7-
from fishtest import helpers
7+
import fishtest.github_api as gh
88
from fishtest.routes import setup_routes
99
from fishtest.rundb import RunDb
1010
from pyramid.authentication import AuthTktAuthenticationPolicy
@@ -56,7 +56,7 @@ def add_rundb(event):
5656
event.request.workerdb = rundb.workerdb
5757

5858
def add_renderer_globals(event):
59-
event["h"] = helpers
59+
pass
6060

6161
def check_blocked_user(event):
6262
request = event.request
@@ -79,18 +79,23 @@ def is_user_blocked(auth_user_id, userdb):
7979
return True
8080
return False
8181

82-
def init_rundb(event):
83-
# We do not want to do the following in the constructor of rundb since
84-
# it writes to the db and starts the flush timer.
82+
def init_app(event):
8583
if rundb.is_primary_instance():
84+
# Some initialization stuff that
85+
# - uses the network;
86+
# - accesses the db;
87+
# - starts new threads.
88+
gh.init(rundb.kvstore, rundb.actiondb)
8689
rundb.update_aggregated_data()
87-
# We install signal handlers when all cache-sensitive code in the
88-
# main thread is finished. In that way we can safely use
89-
# locks in the signal handlers (which also run in the main thread).
90-
signal.signal(signal.SIGINT, rundb.exit_run)
91-
signal.signal(signal.SIGTERM, rundb.exit_run)
9290
rundb.schedule_tasks()
9391

92+
# We install signal handlers when all code in the
93+
# main thread is finished. In that way we can safely use
94+
# locks in the signal handlers (which also run in the
95+
# main thread).
96+
signal.signal(signal.SIGINT, rundb.exit_run)
97+
signal.signal(signal.SIGTERM, rundb.exit_run)
98+
9499
def set_default_base_url(event):
95100
if not rundb._base_url_set:
96101
rundb.base_url = f"{event.request.scheme}://{event.request.host}"
@@ -100,7 +105,7 @@ def set_default_base_url(event):
100105
config.add_subscriber(check_shutdown, NewRequest)
101106
config.add_subscriber(add_renderer_globals, BeforeRender)
102107
config.add_subscriber(check_blocked_user, NewRequest)
103-
config.add_subscriber(init_rundb, ApplicationCreated)
108+
config.add_subscriber(init_app, ApplicationCreated)
104109
config.add_subscriber(set_default_base_url, NewRequest)
105110

106111
# Authentication

server/fishtest/api.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from datetime import UTC, datetime
77
from urllib.parse import urlparse
88

9+
import fishtest.github_api as gh
910
from fishtest.schemas import api_access_schema, api_schema, gzip_data
1011
from fishtest.stats.stat_util import SPRT_elo, get_elo
1112
from fishtest.util import strip_run, worker_name
@@ -35,7 +36,7 @@
3536
according to the route/URL mapping defined in `__init__.py`.
3637
"""
3738

38-
WORKER_VERSION = 282
39+
WORKER_VERSION = 288
3940

4041

4142
@exception_view_config(HTTPException)
@@ -227,17 +228,20 @@ def request_task(self):
227228
if "task_waiting" in result:
228229
return self.add_time(result)
229230

230-
# Strip the run of unneccesary information
231+
# Strip the run of unnecessary information
231232
run = result["run"]
232233
task = run["tasks"][result["task_id"]]
233234
min_task = {"num_games": task["num_games"], "start": task["start"]}
234235
if "stats" in task:
235236
min_task["stats"] = task["stats"]
236-
args = copy.copy(run["args"])
237-
book = args["book"]
238-
books = self.request.rundb.books
239-
if book in books:
240-
args["book_sri"] = books[book]["sri"]
237+
238+
# Add book checksum
239+
args = copy.copy(run["args"])
240+
book = args["book"]
241+
books = self.request.rundb.books
242+
if book in books:
243+
args["book_sri"] = books[book]["sri"]
244+
241245
min_run = {"_id": str(run["_id"]), "args": args, "my_task": min_task}
242246
result["run"] = min_run
243247
return self.add_time(result)
@@ -319,7 +323,7 @@ def stop_run(self):
319323

320324
@view_config(route_name="api_request_version")
321325
def request_version(self):
322-
# By being mor lax here we can be more strict
326+
# By being more lax here, we can be more strict
323327
# elsewhere since the worker will upgrade.
324328
self.validate_username_password()
325329
return self.add_time({"version": WORKER_VERSION})
@@ -346,6 +350,10 @@ def request_spsa(self):
346350

347351
@view_defaults(renderer="json")
348352
class UserApi(GenericApi):
353+
@view_config(route_name="api_rate_limit")
354+
def rate_limit(self):
355+
return gh.rate_limit()
356+
349357
@view_config(route_name="api_active_runs")
350358
def active_runs(self):
351359
runs = self.request.rundb.runs.find(

0 commit comments

Comments
 (0)