Skip to content

Improving lua script with args and values - #6561

Merged
Mzack9999 merged 12 commits into
devfrom
feat-4790-lua
Jul 22, 2026
Merged

Improving lua script with args and values#6561
Mzack9999 merged 12 commits into
devfrom
feat-4790-lua

Conversation

@Mzack9999

@Mzack9999 Mzack9999 commented Oct 29, 2025

Copy link
Copy Markdown
Member

Proposed changes

Closes #4790

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • New Features
    • Extended Redis Lua script execution to accept optional keys and arguments inputs while remaining compatible with prior call patterns.
  • Bug Fixes
    • Improved Redis connectivity behavior by using the provided execution context for ping.
  • Tests
    • Added a new integration test covering Redis Lua script execution.
    • Reduced flakiness in headless UI “wait visible” checks by adjusting test timing and timeouts.

@Mzack9999 Mzack9999 self-assigned this Oct 29, 2025
@Mzack9999 Mzack9999 added the Type: Enhancement Most issues will probably ask for additions or changes. label Oct 29, 2025
@coderabbitai

coderabbitai Bot commented Oct 29, 2025

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Extended the RunLuaScript function signature to accept optional keys and args parameters. The function now converts these inputs to appropriate Redis EVAL types, improves context propagation, and includes Docker-based integration test coverage for Lua script execution. Also stabilized a headless browser test by parameterizing element-appearance delays to reduce timing flakiness.

Changes

Redis Lua Script API Support

Layer / File(s) Summary
RunLuaScript signature and argument conversion
pkg/js/libs/redis/redis.go
Function signature extended to accept keys and args as optional interface{} parameters. Added conversion logic for keys (to []string) and args (to []interface{}), supporting backward compatibility with empty strings. Context propagation improved by using the provided ctx for the initial Redis ping instead of context.TODO(). Updated Eval call passes the converted keys and args.
Integration test for Redis Lua script
internal/tests/integration/javascript_test.go
New javascriptRedisLuaScript test case added to the integration test suite. Registers redis-lua-script.yaml template and implements Docker-based test execution against a Redis container with --requirepass iamadmin authentication on port 6379/tcp.

Headless Test Timing Stabilization

Layer / File(s) Summary
Test timing stabilization with parameterized delays
pkg/protocols/headless/engine/page_actions_test.go
Introduced responseWithDelay helper to generate HTML responses with configurable client-side setTimeout delays. Updated TestActionWaitVisible subtests: "visible" case uses 500ms element-appearance delay with 5s timeout; "timeout" case uses 10s delay with 1s timeout to ensure consistent timing behavior and reduce flakiness.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A Lua script now dances with Redis's grace,
Keys and args find their proper place,
Docker tests ensure the magic runs true,
Context flows right, and timers stay true! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improving lua script with args and values' directly describes the main change: extending RunLuaScript to accept optional keys and args parameters for Lua script execution.
Linked Issues check ✅ Passed The PR fully addresses issue #4790 by enabling redis.RunLuaScript() to accept optional keys and args parameters, allowing dynamic argument passing to Redis Lua scripts as requested in the example template.
Out of Scope Changes check ✅ Passed All changes are scoped to the linked objectives: redis.go extends RunLuaScript signature with keys/args support, javascript_test.go adds the integration test case, and page_actions_test.go reduces test flakiness—all directly supporting the Lua script enhancement.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-4790-lua

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Mzack9999
Mzack9999 marked this pull request as ready for review October 29, 2025 11:49
@auto-assign
auto-assign Bot requested a review from dwisiswant0 October 29, 2025 11:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
pkg/js/libs/redis/redis.go (1)

223-243: Consider optimizing the args conversion to avoid redundant processing.

The current implementation converts args twice: []interface{}[]string[]interface{}. When args is already []interface{}, you could skip the intermediate []string conversion and directly prepare it for the Eval call.

Refactor to eliminate redundant conversion:

// Convert interface{} args directly to []interface{} for Eval
argsInterface := []interface{}{}
if args != nil {
	switch v := args.(type) {
	case []string:
		argsInterface = make([]interface{}, len(v))
		for i, arg := range v {
			argsInterface[i] = arg
		}
	case []interface{}:
		// Filter to only strings (or handle type conversion)
		for _, item := range v {
			if s, ok := item.(string); ok {
				argsInterface = append(argsInterface, s)
			}
		}
	}
}

This eliminates the intermediate argsSlice variable and avoids double conversion for []interface{} inputs.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82144e5 and cbe879c.

⛔ Files ignored due to path filters (2)
  • integration_tests/protocols/javascript/redis-lua-script.yaml is excluded by !**/*.yaml
  • pkg/js/generated/ts/redis.ts is excluded by !**/generated/**
📒 Files selected for processing (2)
  • cmd/integration-test/javascript.go (2 hunks)
  • pkg/js/libs/redis/redis.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: Format Go code using go fmt
Run static analysis with go vet

Files:

  • pkg/js/libs/redis/redis.go
  • cmd/integration-test/javascript.go
🧬 Code graph analysis (2)
pkg/js/libs/redis/redis.go (1)
pkg/js/generated/ts/redis.ts (1)
  • RunLuaScript (70-72)
cmd/integration-test/javascript.go (1)
pkg/testutils/integration.go (2)
  • TestCase (247-250)
  • RunNucleiTemplateAndGetResults (30-32)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (ubuntu-latest)
🔇 Additional comments (4)
cmd/integration-test/javascript.go (1)

15-15: LGTM!

The test case registration is consistent with other JavaScript test cases and properly disables on Windows/OSX platforms.

pkg/js/libs/redis/redis.go (3)

178-182: LGTM!

The documentation clearly demonstrates both backward-compatible usage (without keys/args) and the new signature with keys and args parameters.


183-183: LGTM!

The function signature correctly uses interface{} types for keys and args to support backward compatibility (nil values) and flexible type handling from JavaScript.


246-246: LGTM!

The Eval call correctly uses the converted keysSlice and argsInterface parameters to execute the Lua script with the provided keys and arguments.

Comment thread cmd/integration-test/javascript.go Outdated
Comment thread cmd/integration-test/javascript.go Outdated
Comment thread pkg/js/libs/redis/redis.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
pkg/js/libs/redis/redis.go (3)

205-217: Consider validating key types explicitly.

While fmt.Sprintf("%v", item) prevents silent data loss, it may still produce unexpected string representations for complex types (e.g., maps, structs). For Redis keys, only strings and basic types are typically meaningful.

Consider adding a default case to handle unexpected types:

 	// Convert interface{} to []string for keys (handle backwards compatibility)
 	keysSlice := []string{}
 	if keys != nil {
 		switch v := keys.(type) {
 		case []string:
 			keysSlice = v
 		case []interface{}:
 			keysSlice = make([]string, 0, len(v))
 			for _, item := range v {
 				keysSlice = append(keysSlice, fmt.Sprintf("%v", item))
 			}
+		default:
+			return nil, fmt.Errorf("keys must be []string or []interface{}, got %T", keys)
 		}
 	}

236-240: Eliminate unnecessary conversion by directly building []interface{}.

The current flow converts args through multiple types: []interface{} (from JS) → []string[]interface{} (for Eval). This is inefficient and adds complexity.

Consider refactoring to build []interface{} directly:

-	// Convert interface{} to []string for args (handle backwards compatibility)
-	argsSlice := []string{}
+	// Convert interface{} to []interface{} for args (handle backwards compatibility)
+	argsInterface := []interface{}{}
 	if args != nil {
 		switch v := args.(type) {
 		case []string:
-			argsSlice = v
+			argsInterface = make([]interface{}, len(v))
+			for i, s := range v {
+				argsInterface[i] = s
+			}
 		case []interface{}:
-			// Convert []interface{} to []string (from JavaScript arrays)
-			argsSlice = make([]string, 0, len(v))
-			for _, item := range v {
-				argsSlice = append(argsSlice, fmt.Sprintf("%v", item))
-			}
+			argsInterface = v
 		default:
 			return nil, fmt.Errorf("args must be []string or []interface{}, got %T", args)
 		}
 	}
-
-	// Convert []string args to []interface{} for Eval
-	argsInterface := make([]interface{}, len(argsSlice))
-	for i, arg := range argsSlice {
-		argsInterface[i] = arg
-	}

This preserves the original types from JavaScript (numbers, booleans, etc.) without unnecessary string conversions, which is more correct for Redis Lua scripts.


243-243: Consider using the provided context parameter.

The Eval call uses context.Background() instead of the ctx parameter passed to the function. This bypasses any timeout or cancellation configured by the caller.

Apply this diff to respect the caller's context:

-	infoCmd := client.Eval(context.Background(), script, keysSlice, argsInterface...)
+	infoCmd := client.Eval(ctx, script, keysSlice, argsInterface...)

Note: This pattern is already used in other functions in this file (e.g., line 43, 49, 84).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbe879c and 921b3d3.

📒 Files selected for processing (2)
  • cmd/integration-test/javascript.go (5 hunks)
  • pkg/js/libs/redis/redis.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/integration-test/javascript.go
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.go: Format Go code using go fmt ./...
Run static analysis using go vet ./...

Files:

  • pkg/js/libs/redis/redis.go
pkg/js/**/*.go

📄 CodeRabbit inference engine (CLAUDE.md)

JavaScript runtime custom implementations for code protocol templates should use auto-generated bindings from pkg/js/generated/

Files:

  • pkg/js/libs/redis/redis.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Lint
🔇 Additional comments (1)
pkg/js/libs/redis/redis.go (1)

174-183: LGTM! Clear documentation of backward compatibility.

The function signature and documentation clearly explain both the old and new usage patterns, making it easy for users to understand the changes.

Comment thread pkg/js/libs/redis/redis.go Outdated
@github-actions

github-actions Bot commented Apr 5, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity. It will be closed in 7 days if no further activity occurs. Please update if you wish to keep it open.

@github-actions github-actions Bot added the Status: Stale This issue/PR has been inactive for a while and may be closed soon if no further activity occ label Apr 5, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed due to inactivity. If you think this is a mistake or would like to continue working on it, please comment or feel free to reopen it.

@github-actions github-actions Bot added the Status: Abandoned This issue is no longer important to the requestor and no one else has shown an interest in it. label Apr 12, 2026
@github-actions github-actions Bot closed this Apr 12, 2026
@dwisiswant0 dwisiswant0 reopened this Apr 14, 2026
@github-actions github-actions Bot removed Status: Abandoned This issue is no longer important to the requestor and no one else has shown an interest in it. Status: Stale This issue/PR has been inactive for a while and may be closed soon if no further activity occ labels Apr 19, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 `@internal/tests/integration/javascript_test.go`:
- Around line 115-117: The test currently sets the container image with
Repository: "redis" and Tag: "latest", which makes the integration runs
non-deterministic; update the test to pin the Redis image to a specific stable
version or digest (e.g., replace Tag: "latest" with a concrete semver like
"7.0.11" or use an immutable digest) for both the Redis password brute and Redis
Lua script cases so test environments are reproducible; locate the occurrences
of Repository: "redis", Tag: "latest" in the test definitions
(integration/javascript_test.go) and change them to the chosen pinned tag or
digest and update any related test documentation/comments if present.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7ac038ea-2bbd-47ae-83c6-1af8a4f2ab43

📥 Commits

Reviewing files that changed from the base of the PR and between 79e0dda and 331b900.

⛔ Files ignored due to path filters (1)
  • internal/tests/integration/testdata/protocols/javascript/redis-lua-script.yaml is excluded by !**/*.yaml
📒 Files selected for processing (1)
  • internal/tests/integration/javascript_test.go

Comment thread internal/tests/integration/javascript_test.go
The two log() calls each emitted a [JS] stdout line that the integration
harness counted as a result, yielding 3 results vs the expected 1. The
matcher reads `response` from the final expression value (not stdout), so
returning the get RunLuaScript call directly keeps the assertion intact
with a single result.
@dwisiswant0

Copy link
Copy Markdown
Member

Test failed,

Avoid shared templates-dir update races across parallel go test packages and ignore known leveldb/ratelimit/memguardian goroutines in goleak.
Keep goleak ignores, drop DisableUpdateCheck so CI can install templates, and serialize UpdateIfOutdated across processes.
@Mzack9999
Mzack9999 merged commit 2710ba2 into dev Jul 22, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Enhancement Most issues will probably ask for additions or changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with Lua script execution in redis js module

2 participants