Enable Garnet Lua scripting#364
Conversation
📝 WalkthroughWalkthroughThis PR enables Redis Lua scripting throughout the TelegramSearchBot project. Lua script constants are exposed to tests, Garnet server configuration now includes Lua support with transaction mode, and a comprehensive integration test suite validates three Lua scripts covering coding agent jobs, agent chat locks, and music generation semaphores. ChangesLua Script Integration and Testing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@TelegramSearchBot.Test/AppBootstrap/GarnetLuaScriptIntegrationTests.cs`:
- Around line 17-19: The test currently uses GetAvailablePort() which closes the
probe socket before GarnetServer binds, causing a TOCTOU race; change the setup
so the test either binds and holds the listener until GarnetServer takes it
(have GetAvailablePort return an already-bound TcpListener or endpoint) or
modify GarnetServer/SchedulerBootstrap to accept an ephemeral port (0) and then
query the actual bound port after server.Start(); update the test to pass the
held/socket-backed endpoint into GarnetServer (or use port 0 and read
server.BoundPort after Start) instead of releasing the port between probe and
bind.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b621151a-c625-442c-9613-ddcbd0b97f67
📒 Files selected for processing (6)
TelegramSearchBot.LLM/Service/Tools/CodingAgentJobService.csTelegramSearchBot.LLM/TelegramSearchBot.LLM.csprojTelegramSearchBot.Test/AppBootstrap/GarnetLuaScriptIntegrationTests.csTelegramSearchBot/AppBootstrap/SchedulerBootstrap.csTelegramSearchBot/Service/AI/LLM/AgentChatBatchDispatchService.csTelegramSearchBot/Service/Tools/MusicGenerationToolService.cs
| var port = GetAvailablePort(); | ||
| using var server = new GarnetServer(SchedulerBootstrap.BuildGarnetArguments(port.ToString())); | ||
| server.Start(); |
There was a problem hiding this comment.
Avoid TOCTOU port reservation race in test server startup.
GetAvailablePort() releases the socket before GarnetServer binds, so another process can take that port and make this integration test flaky.
Suggested hardening
- var port = GetAvailablePort();
- using var server = new GarnetServer(SchedulerBootstrap.BuildGarnetArguments(port.ToString()));
- server.Start();
+ GarnetServer? server = null;
+ var port = 0;
+ for (var attempt = 0; attempt < 5 && server == null; attempt++) {
+ port = GetAvailablePort();
+ try {
+ server = new GarnetServer(SchedulerBootstrap.BuildGarnetArguments(port.ToString()));
+ server.Start();
+ } catch {
+ server?.Dispose();
+ server = null;
+ }
+ }
+ Assert.NotNull(server);
+ using (server) {
+ using var redis = await ConnectWithRetryAsync(port);
+ var db = redis.GetDatabase();
- using var redis = await ConnectWithRetryAsync(port);
- var db = redis.GetDatabase();
-
- await RunCodingAgentEnqueueScriptAsync(db);
- await RunAgentChatLockScriptsAsync(db);
- await RunMusicGenerationSemaphoreScriptAsync(db);
+ await RunCodingAgentEnqueueScriptAsync(db);
+ await RunAgentChatLockScriptsAsync(db);
+ await RunMusicGenerationSemaphoreScriptAsync(db);
+ }Also applies to: 150-157
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@TelegramSearchBot.Test/AppBootstrap/GarnetLuaScriptIntegrationTests.cs`
around lines 17 - 19, The test currently uses GetAvailablePort() which closes
the probe socket before GarnetServer binds, causing a TOCTOU race; change the
setup so the test either binds and holds the listener until GarnetServer takes
it (have GetAvailablePort return an already-bound TcpListener or endpoint) or
modify GarnetServer/SchedulerBootstrap to accept an ephemeral port (0) and then
query the actual bound port after server.Start(); update the test to pass the
held/socket-backed endpoint into GarnetServer (or use port 0 and read
server.BoundPort after Start) instead of releasing the port between probe and
bind.
PR Check ReportSummary
Test Results
Code Quality
Test Artifacts
LinksThis report is auto-generated by GitHub Actions |
Summary
Tests
Summary by CodeRabbit
Release Notes
Tests
Chores