Repository navigation
Fix #15279 (donate-cpu-server: modernize code and provide REST API) - #9084
Conversation
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no significant new problems in the new tools/donate-cpu-server-rest.py. The parsing, the reports and the path checks match what donate-cpu-server.py does as far as I could check.
The one new issue is minor and I checked it by reasoning, not by running the server. On the name detail pages (/check_library-…, /unknown_macro-…, /incomplete_var-…), the "packages.txt" link comes from request.url.path, which is already percent-decoded. The handler then decodes the path again with unquote_plus. For a name that contains a literal +, the link therefore asks for a different name and the list comes back empty.
The PR changes no C/C++ code, and the two CodeQL threads are from a bot, so they get no entries.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | packages.txt link on name pages is decoded twice, so names containing '+' break | AI review | tools/donate-cpu-server-rest.py:967 |
🆕 New |
@danmar, please fix, resolve or reply to the open and new comments: #1.
Testing
- The PR only adds a Python tool, its test and a CI step, so I did not build
cppcheckortestrunner. - The server and its tests could not be run.
fastapi,uvicorn,jinja2andhttpxare not installed in the container, and with no network and nopipthey could not be installed. The newtest/tools/donate_cpu_server_rest_test.pywould be skipped throughimportorskip. - I put stub
fastapi,jinja2,uvicornandpydanticmodules inscratch/stubsso that I could import the module and call the pure functions directly (parse_result,parse_info,safe_path, …).- The parser gives the expected results for the header, head and diff sections and for crash stack traces.
- The crash parser drops the first non-frame line after a stack trace when there is no blank line before it (it reported
syntaxError: 1for two warnings). Real clients only send gdb output for a crash, so this does not seem to matter in practice and I did not report it.
- Both new files parse with Python 3.7 grammar (
ast.parse(..., feature_version=(3,7))). That matters because CI runspy_compileon 3.7 as well. - The
+problem in the packages.txt link, reproduced by simulating the URL handling:
python3 -c "
import urllib.parse as u
name='operator+()'
href='/check_library-'+u.quote_plus(name); print('link', href)
decoded=u.unquote(href) # what scope['path'] / request.url.path holds
print('pkgs link', decoded+'?pkgs=1')
print('name parsed from pkgs link', repr(u.unquote_plus(decoded[len('/check_library-'):])))"
link /check_library-operator%2B%28%29
pkgs link /check_library-operator+()?pkgs=1
name parsed from pkgs link 'operator ()'
Automated review of 080b56e by Claude. The pull request was built and tested locally.
| def with_query(request: Request, **params: str) -> str: | ||
| query = dict(request.query_params) | ||
| query.update(params) | ||
| return request.url.path + '?' + urllib.parse.urlencode(query) |
There was a problem hiding this comment.
AI review
request.url.path is built from the percent-decoded scope['path']. On the name detail pages (/check_library-…, /unknown_macro-…, /incomplete_var-…) this link is then decoded a second time by _raw_suffix(), which uses unquote_plus.
For a name that contains a literal +, the report links to /check_library-operator%2B%28%29. The "packages.txt" link built here becomes /check_library-operator+()?pkgs=1, which is read back as the name operator (), so the list is empty.
Fix: build the link from the raw path (request.scope['raw_path']) or quote the path again, for example urllib.parse.quote(request.url.path), keeping + encoded as %2B.
There was a problem hiding this comment.
Fixed in cf6c0ba: with_query() now builds the link from the undecoded request.scope['raw_path'], so the path is kept exactly as it was requested.
I did not use urllib.parse.quote(request.url.path). It fixes operator+(), but it breaks the old style links where + is a space: /check_library-unsigned+int would become /check_library-unsigned%2Bint, which is read back as the name unsigned+int.
The new test test_html_name_pages_packages_link checks the link and its result for both /check_library-operator%2B%28%29 and /check_library-unsigned+int.
…sh report donate-cpu puts the assertion failure message before the " received signal " line. Parse it and show it first in the stack trace on crash.html. Stack traces with different assertion failures are not grouped together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ead in the crash report Only the stack trace of head is uploaded, so the old version is still shown as "Crash". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rsion if head has an assertion failure There is no stack trace for the old version, so when both versions crash and head has an assertion failure, the old version might have the same assertion failure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…link
request.url.path is decoded and the name pages decode the path again
('+' is a space). For a name with a '+', e.g. operator+(), the link
became /check_library-operator+()?pkgs=1 which gave the name
"operator ()" and an empty list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Older Starlette TestClient versions (0.27, used with Python 3.7) put the query string in scope['raw_path'], so '?pkgs=1' became part of the name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
The new assertion-failure parsing in tools/donate-cpu-server-rest.py does not match real gdb output. glibc writes the program name in front of the message (cppcheck: build/x.cpp:12: …: Assertion x' failed.), and gdb puts a blank line before Program received signal. The regex expects neither, so for real crashes assertions` stays empty. "Assert failed" and "Crash/Assertion failure" are then never shown, and stack traces are grouped without the assertion text. The test fixture uses an idealised format with no prefix and no blank line, so the tests pass anyway.
The earlier + problem in the packages.txt link (C4) is fixed in the code. Apart from that, I found no new problems.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | packages.txt link on name pages is decoded twice, so names containing '+' break | AI review | tools/donate-cpu-server-rest.py:967 |
✅ Fixed |
| 2 | Assertion regex misses real glibc/gdb output (program-name prefix, blank line before signal line) | AI review | tools/donate-cpu-server-rest.py:116 |
🆕 New |
@danmar, please fix, resolve or reply to the open and new comments: #2.
Testing
- I did not build
cppcheckortestrunner: the PR changes only Python tools, a test and CI. - The server and its pytest suite could not be run.
fastapi,uvicorn,jinja2andhttpxare not installed, and there is no network to install them. Instead I imported the module with stubfastapi/jinja2/uvicorn/pydanticmodules and calledparse_resultdirectly. - Real gdb output. In this tree
donate_cpu_lib.py(client 1.4.0) runsgdb --batch --eval-command=run --eval-command="bt 50" --return-child-result --args …. I compiled a small program that prints "Checking …" and then fails anassert, and ran it the same way with stderr merged:
$ gdb --batch --eval-command=run --eval-command="bt 50" --return-child-result --args ./a 2>&1 | cat -A
...
Checking x.c ...$
a: a.c:3: main: Assertion `c==5' failed.$
$
Program received signal SIGABRT, Aborted.$
The message starts with the program name (a: ), and a blank line separates it from the signal line.
- Parser on those variants. I fed the PR's
parse_resultthe same input asRESULT_CRASH_ASSERTION, varying only the assertion line (scratch/t.py, run withPYTHONPATH=stubs:/work/pr/tools python3 t.py):
"build/symboldatabase.cpp:6760: ...: Assertion `x == 1' failed." -> [ '...assertion...' ]
"cppcheck: build/symboldatabase.cpp:6760: ...: Assertion `x == 1' failed." -> []
"build/symboldatabase.cpp:6760: ...: Assertion `x == 1' failed.\n" (blank line before signal) -> []
Only the idealised form of the test fixture is recognised.
- C4 fix. I checked by reading the code that
with_query()/raw_path()now build the link from the undecodedscope['raw_path'], with the query string removed.
Automated review of f33f430 by Claude. The pull request was built and tested locally.
No description provided.