Skip to content

Remove duplicated blocks from test and demo files (1 of 4) - #31

Merged
danregima merged 1 commit into
mainfrom
claude/loving-archimedes-r7fcwy
Nov 20, 2026
Merged

danregima merged 1 commit into
mainfrom
claude/loving-archimedes-r7fcwy

Conversation

@drzo

@drzo drzo commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Description

First of four pull requests that refactor the 41 files left unformatted in #29. Each of those files contains duplicated blocks that the linter's copy/paste detector rejects whenever the file is changed. This batch covers the 12 test and demo files; the editor/LSP, AI and remaining files follow separately.

Type of Change

  • Code refactoring

Related Issues

Related to #29

Changes Made

Each duplicated block is replaced by a helper in the same file. No suppression markers are used.

  • demo_external_lsp.cpp: the clangd and pyright walkthroughs were two copies of one routine; they now share testLanguageServer() plus small helpers for printing the command, waiting on a flag, and the completion and hover requests.
  • demo_gpu_acceleration.cpp, test_gpu_simple.cpp, test_gpu_standalone.cpp: one backendTypeName() instead of repeated switch statements.
  • demo_lsp_editor_integration.cpp, demo_lsp_integration.cpp: one plugin-lookup helper instead of the same extension loop in each request handler.
  • demo_multi_cursor.cpp: printCursorPositions().
  • test/test_plugin_system.cpp: the two test plugins share a base class.
  • test/test_model_loader.cpp, test/test_bpe_tokenizer.cpp, test_benchmark_suite.cpp, test_performance_profiler.cpp: shared helpers for reading a report file, the test vocabulary and the tensor checks.

The files are then formatted with clang-format and made cpplint-clean like the rest of the code base.

Testing

  • All existing tests pass

  • Manual testing performed

  • Locally on Linux (GCC): 98/98 CTest tests; scripts/smoke_test.sh passes.

  • The five demo programs were built before and after and their output compared: identical, apart from timestamps and thread ids in one log. clangd is not installed in the test environment, so the clangd branch of demo_external_lsp only exercised its "not available" path.

  • clang-format 15.0.7, cpplint 1.6.1 and jscpd 3.5.3 report nothing on the 12 files.

Reviewer Notes

  • Three of these files are not part of any build target and did not compile before this change: test_gpu_standalone.cpp, test/test_bpe_tokenizer.cpp and test_benchmark_suite.cpp. They show the same errors as before and no new ones, so their refactoring is checked by the linters and by reading only.
  • Two small differences that are not pure moves: in test_benchmark_suite.cpp and test_performance_profiler.cpp the "file opened" assertion now lives in the helper, so a failure there reports the helper's line number; and in test_gpu_simple.cpp the shared backendTypeName() returns an empty string for an unknown backend where the original switch printed nothing.

Generated by Claude Code

First batch of the 41 files that were left unformatted because the
linter's copy/paste detector rejects them. Each duplicated block is
replaced by a helper in the same file; no suppression markers are used.

- demo_external_lsp.cpp: the clangd and pyright walkthroughs were two
  copies of one routine; they now share testLanguageServer() and small
  helpers for printing the command, waiting on a flag and the
  completion / hover requests.
- demo_gpu_acceleration.cpp, test_gpu_simple.cpp,
  test_gpu_standalone.cpp: one backendTypeName() instead of repeated
  switch statements.
- demo_lsp_editor_integration.cpp, demo_lsp_integration.cpp: one
  plugin-lookup helper instead of the same extension loop in each
  request handler.
- demo_multi_cursor.cpp: printCursorPositions().
- test/test_plugin_system.cpp: the two test plugins share a base class.
- test/test_model_loader.cpp, test/test_bpe_tokenizer.cpp,
  test_benchmark_suite.cpp, test_performance_profiler.cpp: shared
  helpers for reading a report file, the test vocabulary and the
  tensor checks.

The files are then formatted and made cpplint-clean like the rest.

Output of the five demo programs was compared before and after and is
unchanged. Three of these files (test_gpu_standalone.cpp,
test/test_bpe_tokenizer.cpp, test_benchmark_suite.cpp) are not part of
any build target and did not compile before this change either; they
show the same errors as before and no new ones.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011vmiZ7F3rQu7dith9sQw71

drzo commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Integration Tests failed once on 77dc01a and passed on a single re-run.

The first attempt failed on one item of the smoke test: demo_lsp_ui_integration GUI exited with status 5 under the virtual display. gui_main, demo_widget_framework and every other program passed in the same run.

Why I don't think it comes from this PR: the diff does not touch demo_lsp_ui_integration.cpp or anything under src/bolt/gui; the same check passed on main and on the previous PRs; and three local runs under xvfb-run kept the program up as expected.

What is not known: the cause. Exit status 5 is not one of the program's own exit codes that I can find, and the job log shows an orphaned Xvfb process at cleanup, so the virtual display is the likeliest suspect, but that is unconfirmed. If it happens again it needs a proper look (for example capturing the program's output in the smoke test rather than discarding it).


Generated by Claude Code

@danregima
danregima marked this pull request as ready for review November 20, 2026 15:22
Copilot AI balanced review requested due to automatic review settings November 20, 2026 15:22
@danregima
danregima merged commit 41eca26 into main Nov 20, 2026
68 of 71 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment thread demo_external_lsp.cpp
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

waitForFlag(completionReceived, std::chrono::seconds(5));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Late LSP responses corrupt expired stack storage

If a response arrives after requestCompletion times out and returns, its captured result and flag no longer exist. LspClient::messageProcessorFunc still invokes the callback, which writes into expired stack storage. requestHover has the same regression, allowing delayed responses to corrupt memory or crash the demo.

Learn more

The extracted helpers capture their local result objects and completion flags by reference. Returning after the five-second wait destroys those objects without removing the callback registered by LspClient::sendRequest. The message processor invokes that callback when the response eventually arrives. The remaining session keeps the client running during hover and shutdown, so delayed responses can still reach the destroyed objects. requestHover has the same problem. Previously, the captured objects remained in the session's scope until disconnect joined the message processor.

Example: clangd takes six seconds to answer completion. At five seconds, the completion helper returns and the demo starts waiting for hover. At six seconds, the completion callback assigns to the destroyed completion list and flag rather than live session variables.

Recommended fix: Store each request's result and completion status in shared, heap-owned state captured by value, with mutex/condition-variable synchronization. Alternatively, implement cancellation that removes the callback and waits for any in-flight invocation before allowing the captured state to die. Cover both completion and hover with a delayed-response test.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread demo_external_lsp.cpp
Comment on lines +111 to +112
// Requests completion at the given position and prints the first few items.
void requestCompletion(LspClient& client, const std::string& uri, const Position& position) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 New helpers lack Doxygen documentation

New helpers such as requestCompletion use ordinary // descriptions, not Doxygen comments. The code style guidelines require Doxygen-style documentation; this pattern repeats across the extracted helpers.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Two LSP request helpers leave callbacks referencing destroyed stack state after a timeout, allowing late responses to crash the process or corrupt memory.

1 open issue
What changed in this PR

This first follow-up to #29 removes duplicated blocks from 12 test and demo files so they can join the codebase’s formatting and lint cleanup.

Changes:

  • Extracts file-local helpers for language-server sessions, plugin lookup, GPU backend names, and cursor output.
  • Consolidates test plugin setup, vocabulary data, tensor checks, and report reading.
  • Applies formatting and lint-related cleanup across all 12 files.
File Description
test/​test_plugin_system.cpp Shares plugin metadata and lifecycle handling through a base class.
test/​test_model_loader.cpp Extracts assertion, model-filtering, and tensor-check helpers.
test/​test_bpe_tokenizer.cpp Reuses a shared test vocabulary.
test_performance_profiler.cpp Centralizes exported-file reading.
test_gpu_standalone.cpp Consolidates GPU backend-name formatting.
test_gpu_simple.cpp Reuses a backend-name helper while preserving empty fallback output.
test_benchmark_suite.cpp Centralizes report-file reading.
demo_multi_cursor.cpp Reuses cursor-position output logic.
demo_lsp_integration.cpp Shares plugin file-extension matching.
demo_lsp_editor_integration.cpp Centralizes plugin lookup by file type.
demo_gpu_acceleration.cpp Replaces repeated backend switches with a helper.
demo_external_lsp.cpp Unifies clangd and pyright sessions and extracts request helpers.

Review effort: Balanced

Comment thread demo_external_lsp.cpp
Comment on lines 122 to 124
client.completion(completionParams, [&completions, &completionReceived](const CompletionList& result) {
completions = result;
completionReceived = true;
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.

5 participants