* Add test demonstrating validateQueryArgs race condition
Add concurrent test that demonstrates the thread-safety issue with
validateQueryArgs() using global viper state. The test fails with
data races when run with -race flag.
Issue #4706🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix validateQueryArgs thread-safety by passing config struct
Replace global viper state access with a queryConfig struct parameter
in validateQueryArgs(). This eliminates race conditions by reading
configuration once in the caller and passing immutable values.
Changes:
- Add queryConfig struct to hold validation parameters
- Update validateQueryArgs to accept config parameter
- Modify runQueryCmd to read viper once and create config
- Update all tests to pass config struct instead of using viper
This makes validateQueryArgs thread-safe and easier to test.
Fixes#4706🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
* Add test demonstrating race condition in AddCommands/ResetCommands
Added TestAddCommands_Concurrent which exposes data races when
AddCommands() and ResetCommands() are called concurrently.
Running with -race flag shows multiple race condition warnings.
This test demonstrates bug #4708 where these functions are not
thread-safe. While not a practical issue (only called during
single-threaded CLI initialization), proper synchronization
should be added.
Related to #4708🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix race condition in AddCommands/ResetCommands with mutex
Added thread-safe synchronization to AddCommands() and created a
new thread-safe ResetCommands() wrapper using a shared mutex.
The underlying cobra.Command methods are not thread-safe, causing
data races when called concurrently. While these functions are
typically only called during single-threaded CLI initialization,
adding proper synchronization ensures correctness and allows for
safe concurrent usage in tests.
Changes:
- Added commandMutex to protect concurrent access to rootCmd
- Updated AddCommands() with mutex lock/unlock
- Created ResetCommands() wrapper with mutex protection
- Updated test to use the new thread-safe ResetCommands()
Test now passes with -race flag with no warnings.
Fixes#4708🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
- JSON output format has changed to move the rows to under a `rows` property, with timing information under the `metadata` property
- Update timing display to show rows returned and rows fetched, as well as adding verbose mode which lists all scans
- Use enums for output mode and timing mode - timing is now either `on`, `off` or `verbose`
- Bugfix: ensure error is returned from ExecuteSystemClientCall. Closes#4246