Skip to content

Fix #15279 (donate-cpu-server: modernize code and provide REST API) - #9084

Merged
danmar merged 7 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:daca-rest-server
Nov 29, 2026
Merged

danmar merged 7 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:daca-rest-server

Conversation

@danmar

@danmar danmar commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread tools/donate-cpu-server-rest.py Fixed
Comment thread tools/donate-cpu-server-rest.py Fixed

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cppcheck or testrunner.
  • The server and its tests could not be run. fastapi, uvicorn, jinja2 and httpx are not installed in the container, and with no network and no pip they could not be installed. The new test/tools/donate_cpu_server_rest_test.py would be skipped through importorskip.
  • I put stub fastapi, jinja2, uvicorn and pydantic modules in scratch/stubs so 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: 1 for 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 runs py_compile on 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.

Comment thread tools/donate-cpu-server-rest.py Outdated
def with_query(request: Request, **params: str) -> str:
query = dict(request.query_params)
query.update(params)
return request.url.path + '?' + urllib.parse.urlencode(query)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

dmcppcheck and others added 5 commits November 28, 2026 21:26
…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 dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cppcheck or testrunner: the PR changes only Python tools, a test and CI.
  • The server and its pytest suite could not be run. fastapi, uvicorn, jinja2 and httpx are not installed, and there is no network to install them. Instead I imported the module with stub fastapi/jinja2/uvicorn/pydantic modules and called parse_result directly.
  • Real gdb output. In this tree donate_cpu_lib.py (client 1.4.0) runs gdb --batch --eval-command=run --eval-command="bt 50" --return-child-result --args …. I compiled a small program that prints "Checking …" and then fails an assert, 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_result the same input as RESULT_CRASH_ASSERTION, varying only the assertion line (scratch/t.py, run with PYTHONPATH=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 undecoded scope['raw_path'], with the query string removed.

Automated review of f33f430 by Claude. The pull request was built and tested locally.

Comment thread tools/donate-cpu-server-rest.py Resolved
@danmar
danmar merged commit 16f7cd7 into cppcheck-opensource:main Nov 29, 2026
86 of 87 checks passed
@danmar
danmar deleted the daca-rest-server branch November 29, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants