Repository navigation
Fix seven bugs found during the refactor; give tests their own temp paths - #35
Conversation
…aths Each fix has a regression test unless noted. - EditorStore ran its listeners with its mutex held, so a listener that called back into the store deadlocked. Listeners are now copied under the lock and called after it is released. getSelectedFile() returns a copy instead of a reference to a member read without the lock. - ProtocolMessage did not round-trip: data was escaped on output but never unescaped on input, documentId and userId were not escaped at all, and a non-numeric number field threw from deserialize(). All string fields are now escaped and unescaped, and a bad number reads as 0. Messages without special characters are byte-identical. - KoboldCpp requests put stop sequences and chat role names into the JSON unescaped and left control characters other than \n \r \t raw. Every string in a request body now goes through one escaper that covers all of U+0000..U+001F. The two OpenAI-style request builders are exposed in bolt::ai::detail so they can be tested. - TensorUtils divided by the element count for an empty tensor (NaN). It now returns zeros. - The test runner only caught std::exception, so a test that threw anything else ended the whole test program. It now records that test as an error. - YaccGrammarSystem::validate_description did not reset the generator before collecting errors. Latent today, since nothing records a generator error yet; the added test passes with or without the fix. - unified_rag_manager.cpp returned one result when asked for none. Untested: the file is not part of the build. Tests wrote to fixed paths under /tmp. The same test sources are built into several test programs that CTest runs in parallel, so two processes could create, read and delete the same file; this is the likely cause of the intermittent failures seen earlier. Add bolt::test::uniqueTempPath(), which gives each process its own path under the system temp directory, and use it for the 33 such paths in test/. This also removes the assumption that /tmp exists on Windows. One new CTest entry (the TestFramework suite): 99 tests. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011vmiZ7F3rQu7dith9sQw71
Bugbot needs on-demand usage enabledBugbot uses usage-based billing for this team and requires on-demand usage to be enabled. A team admin can enable on-demand usage in the Cursor dashboard. |
| pos = data.find("\":\"", pos) + 3; | ||
| auto end = data.find("\"", pos); | ||
| return data.substr(pos, end - pos); | ||
| return detail::unescapeJsonStringAt(data, pos); |
There was a problem hiding this comment.
🔴 Remote edits hit the first line
A remote edit below the first line now reaches DocumentOperation::deserialize with its operation fields intact. extractInt reads past position instead of line and falls back to zero. The server inserts or deletes text on the first line instead.
Learn more
A WebSocket text edit carries a serialized operation inside the outer message’s data string. The new unescaping restores the inner JSON for handleDocumentOperation, so its text now reaches the collaborative session rather than being lost at the first escaped quote. DocumentOperation::deserialize passes a composite key to extractInt. The lookup finds the composite key, but the subsequent colon search starts at the beginning of that match. It takes the colon after position, passes a substring beginning with { to std::stoi, and returns zero on failure. applyOperation then applies the edit at that position and records it in the document history.
Example: In a document with lines aaa and bbb, an insert of X at line 1, character 1 changes aaa to aXaa and leaves bbb untouched. The intended result is aaa followed by bXbb.
Recommended fix: Parse position.line and position.character from the nested operation object and reject invalid coordinates instead of substituting zero. Add a regression test that deserializes the outer message, applies its operation to a multiline document, and checks that line 0 remains unchanged.
Was this helpful? React with 👍 or 👎 to provide feedback.
| std::vector<std::function<void()>> listeners; | ||
| { | ||
| std::lock_guard<std::mutex> lock(mutex_); | ||
| listeners = listeners_; | ||
| } | ||
| for (auto& listener : listeners) { |
| const bool completed = finished.wait_for(std::chrono::seconds(10)) == std::future_status::ready; | ||
| if (completed) { | ||
| worker.join(); | ||
| } else { | ||
| worker.detach(); | ||
| } | ||
| BOLT_ASSERT_TRUE(completed); |
There was a problem hiding this comment.
🔍 Deadlock test timeout leaves suite blocked
On a real deadlock, worker.detach() leaves the singleton locked. runSingleTest catches the assertion and continues, so later editor tests can still hang.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if (c == '\\' && pos + 1 < data.size()) { | ||
| c = data[++pos]; | ||
| if (c == 'n') | ||
| c = '\n'; | ||
| else if (c == 'r') | ||
| c = '\r'; | ||
| else if (c == 't') | ||
| c = '\t'; |
There was a problem hiding this comment.
| BOLT_ASSERT_TRUE(gf != nullptr); | ||
| } | ||
|
|
||
| BOLT_TEST(GGMLTest, TensorUtilsEmptyTensor) { |
There was a problem hiding this comment.
🔍 New regressions bypass required GoogleTest
The new feature regression cases use BOLT_TEST instead of the required GoogleTest framework. The GoogleTest targets already support that framework.
Was this helpful? React with 👍 or 👎 to provide feedback.
| BOLT_ASSERT_THROWS(std::runtime_error, | ||
| FileSystemUtils::readFile(bolt::test::uniqueTempPath("bolt_nonexistent_file_xyz.txt"))); |
There was a problem hiding this comment.
| pos = data.find("\":\"", pos) + 3; | ||
| auto end = data.find("\"", pos); | ||
| return data.substr(pos, end - pos); | ||
| return detail::unescapeJsonStringAt(data, pos); |
There was a problem hiding this comment.
🟥 Nonmembers can edit shared documents
unescapeJsonStringAt now restores structured edits from WebSocket clients. handleDocumentOperation applies them to the named document without checking whether the sending connection joined it.
Was this helpful? React with 👍 or 👎 to provide feedback.
Description
Fixes the bugs that were found, and left alone, while refactoring in #33 and #34, and stops the tests sharing fixed paths under
/tmp.Type of Change
Related Issues
Related to #33 and #34
Changes Made
Bug fixes
EditorStoredeadlock. Listeners ran with the store's mutex held, so a listener that called back into the store hung. Listeners are now copied under the lock and called after it is released.getSelectedFile()returns a copy instead of a reference to a member read without the lock.getCurrentDocument()still returns a raw pointer; it now has a comment about its lifetime.ProtocolMessageround-trip.datawas escaped on output but never unescaped on input;documentIdanduserIdwere not escaped at all; a non-numeric number field threw fromdeserialize(). All string fields are now escaped and unescaped, and a bad number reads as 0.\n,\r,\twere left raw. Every string in a request body now goes through one escaper covering all of U+0000–U+001F. The two OpenAI-style request builders are exposed inbolt::ai::detailso they can be tested.TensorUtilson an empty tensor. Error, MAE and stats divided by the element count and returned NaN; they now return zeros.std::exception, so a test throwing anything else ended the whole test program. It now records that test as an error.YaccGrammarSystem::validate_description. It did not reset the generator before collecting errors.unified_rag_manager.cpp. It returned one result when asked for none.Test temp paths
bolt::test::uniqueTempPath()intest_framework.hppgives each test process its own path under the system temp directory./tmp/...paths used as real files or directories intest/. The same test sources are built into several test programs that CTest runs in parallel, so two processes could create, read and delete the same file; that is the likely cause of the intermittent failures seen earlier. It also removes the assumption that/tmpexists on Windows.Testing
Unit tests added/updated
All existing tests pass
Locally on Linux (GCC), two build trees: 99/99 CTest tests (one new entry, the
TestFrameworksuite), three consecutive parallel runs all green;scripts/smoke_test.shpasses.New tests:
EditorStore.ListenerMayCallBackIntoStore; threeProtocolMessagetests (round-trip, unchanged wire format for plain messages, bad number); five KoboldCpp request tests (plain requests byte-identical, stop sequences, control characters, roles);GGMLTest.TensorUtilsEmptyTensor;TestFramework.NonStandardExceptionIsRecordedAsErrorandUniqueTempPathKeepsNameAndExtension;E2E_YaccGrammar.GrammarSystem_ValidateAfterFailedGenerate.Shown to fail without the fix: the
EditorStoreand empty-tensor tests. Not re-checked against the old code: theProtocolMessage, KoboldCpp and test-runner tests.Reviewer Notes
top_krounded up, so that a hybrid query withtop_k == 1still returns one result.EditorStorelisteners now run after the lock is dropped, so another thread can change the store between a change and its notification, and a listener added during a notification is not called in that round.ProtocolMessagewith a non-numerictypenow deserializes as type 0 (JOIN_DOCUMENT) instead of being rejected as unparseable; a missingtypealready behaved that way. A non-numeric cursor position reads as 0.FLT_MAXand max = lowest; they are now 0.sendDocumentStatewrites user ids and names unescaped into its nested state JSON.:token, so the documented syntax (vm test : dis { }) and built-in templates such asECHO_SERVERfail validation./api/v1/generatebody uses the fixed escaper but has no direct test.test_rwkv_integration.cpp(a fixed place for a user-supplied model) andtest_gpu_acceleration.cpp(its paths are never created). About two dozen root-level demo and standalone test programs also use fixed/tmppaths; they are not run in parallel by CTest and are not changed here.Generated by Claude Code