diff --git a/CHANGELOG.md b/CHANGELOG.md index 2536f98a..a674ce90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added support for creating a worksheet in GSheets integration - Refactor `launchdarkly` client to separate wrapper around LaunchDarkly SDK into its own package separate from the interface for agent specific flags +- Fixed bug in Redis integration that caused some raw Redis queries to error unexpectedly ## v1.17.0 diff --git a/workers/javascript/packages/plugins/redis/src/e2e.test.ts b/workers/javascript/packages/plugins/redis/src/e2e.test.ts index 964960c3..cc10eb16 100644 --- a/workers/javascript/packages/plugins/redis/src/e2e.test.ts +++ b/workers/javascript/packages/plugins/redis/src/e2e.test.ts @@ -371,6 +371,7 @@ describe('Redis Connection', () => { }); }); }); + describe('Redis Raw Commands', () => { test('executing an empty raw command does nothing', async () => { const newProps = buildPropsWithActionConfiguration( @@ -388,6 +389,41 @@ describe('Redis Raw Commands', () => { await assertDbStateHasNotChanged(); }); + test('executing a raw command works [DBSIZE]', async () => { + const newProps = buildPropsWithActionConfiguration( + RedisPluginV1.fromJson({ + raw: { + singleton: { + query: 'dbsize' + } + } + }) + ); + + const resp = await plugin.execute(newProps); + expect((resp.output as RawOutput).response).toEqual(6); + expect(newProps.mutableOutput.log[0]).toEqual('Running command: DBSIZE'); + await assertDbStateHasNotChanged(); + }); + + test('executing a raw command works [INFO]', async () => { + const newProps = buildPropsWithActionConfiguration( + RedisPluginV1.fromJson({ + raw: { + singleton: { + query: 'info' + } + } + }) + ); + + const resp = await plugin.execute(newProps); + // no need to make this assertion brittle by asserting on the entire output. this should suffice. + expect((resp.output as RawOutput).response).toContain('redis_version'); + expect(newProps.mutableOutput.log[0]).toEqual('Running command: INFO'); + await assertDbStateHasNotChanged(); + }); + test('executing a raw command works [GET]', async () => { const newProps = buildPropsWithActionConfiguration( RedisPluginV1.fromJson({ @@ -1493,7 +1529,7 @@ describe('Redis Misc. Checks', () => { expect('should not pass').toEqual(true); }) .catch((err) => { - expect(err.message).toMatch(`Invalid command. Received 'GET'`); + expect(err.message).toMatch(`Error executing command: ERR wrong number of arguments for 'get' command`); expect(err.code).toEqual(ErrorCode.INTEGRATION_SYNTAX); }); }); diff --git a/workers/javascript/packages/plugins/redis/src/index.ts b/workers/javascript/packages/plugins/redis/src/index.ts index 2bb8d48b..1a5f60e2 100644 --- a/workers/javascript/packages/plugins/redis/src/index.ts +++ b/workers/javascript/packages/plugins/redis/src/index.ts @@ -138,20 +138,21 @@ export default class RedisPlugin extends DatabasePlugin { try { const parts = trimmedCommand.split(/\s+/); - // Take the first part as the verb and the rest as args - const verb = parts.shift(); + // Take the first part as the command and the rest as args + const command = parts.shift(); const args = parts; - // If no verb or arg(s) exists after splitting, it means the input was not structured correctly. - if (!verb || args.length === 0) { + // If no command exists after splitting, it means the input was not structured correctly. + if (!command) { throw new IntegrationError(`Invalid command. Received '${trimmedCommand}'`, ErrorCode.INTEGRATION_SYNTAX, { pluginName: this.pluginName }); } - const commandDisplayString = `${verb.toUpperCase()} ${args.join(' ')}`; + + const commandDisplayString = `${command.toUpperCase()}${args.length ? ' ' + args.join(' ') : ''}`; mutableOutput.logInfo(`Running command: ${commandDisplayString}`); - const response = await client.sendCommand(new Redis.Command(verb, args)); + const response = await client.sendCommand(new Redis.Command(command, args)); // in some cases, we can format the response to make the output easier to consume let formattedResponse = response;