Skip to content

Conversation

@vearne
Copy link
Owner

@vearne vearne commented Sep 19, 2025

Summary by CodeRabbit

  • New Features
    • Support Lua-based request bodies (luaBody) for HTTP and gRPC, enabling dynamic payload generation.
    • Added validation to prevent using both body and luaBody in the same test case.
  • Documentation
    • Restructured and expanded README/README_zh with detailed Install, Usage, Examples, and Advanced Usage (Lua scripting) guides.
    • Added example HTTP/gRPC test cases and enabled a gRPC rule file in default config.
  • Tests
    • Replaced legacy Lua test with a new Lua execution test.
  • Chores
    • Bump version to v0.2.0, upgrade to Go 1.24, refresh dependencies, and update lint tooling/config.

@coderabbitai
Copy link

coderabbitai bot commented Sep 19, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds LuaBody support for HTTP and gRPC requests, introduces a shared internal Lua VM, updates Lua-based rules to use it, adjusts configs and examples to demonstrate Lua usage, upgrades Go toolchain/dependencies, tweaks CI linting, restructures documentation, activates a gRPC rule file, updates tests, and bumps version.

Changes

Cohort / File(s) Summary of changes
CI and Tooling
.github/workflows/golang-ci.yml, .golangci.yml
Update golangci-lint image (v2.4.0), Go setup to 1.24; rework linter config to explicit enables, add complexity thresholds, migrate exclusions.
Docs
README.md, README_zh.md
Renumber and expand sections; add install methods, detailed usage, docker-compose example, and Advanced Usage with LuaBody/HttpLuaRule guidance.
Configs and Examples
config_files/autotest.yml, config_files/my_http_api.yml, config_files/my_grpc_api.yml
Enable a gRPC rule file; add HTTP and gRPC tests using luaBody to generate dynamic payloads with matching Lua verification rules.
Go Toolchain and Deps
go.mod
Upgrade to Go 1.24/toolchain 1.24.5; refresh direct and indirect dependencies (grpc, resty, jsonquery, otel, x/*, protobuf), broad modernization.
Config Structs
internal/config/config.go
Add LuaBody string yaml:"luaBody" to RequestHttp and RequestGrpc.
HTTP/GRPC Request Rendering
internal/command/http_call.go, internal/command/grpc_call.go
If LuaBody present, execute via shared Lua VM to produce request body; otherwise fall back to template rendering; add logging and error paths.
Pre-validation
internal/command/command.go
Enforce mutual exclusivity of Request.Body and Request.LuaBody in HTTP and gRPC checks; return error if both set.
Shared Lua VM
internal/luavm/init.go
New package exposing a locked global Lua state and ExecuteLuaWithGlobals to run scripts with globals and stack restoration.
Lua Rules Integration
internal/rule/http_lua_rule.go, internal/rule/grpc_lua_rule.go, internal/rule/init.go
Switch from per-package Lua VM to shared luavm; pass globals via ExecuteLuaWithGlobals; adjust init to register types on shared VM; remove local VM/mutex.
Tests
internal/rule/http_lua_rule_test.go, internal/rule/lua_test.go
Remove legacy TestLua from http lua rule tests; add new TestLua using shared VM to validate Lua execution against HttpResp.
Version
main.go
Bump version from v0.1.9 to v0.2.0.
GRPC Test Tool
test/mygrpccurl/main.go
Adjust imports and logging with slog; minor input handling changes; no API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CLI as CLI (autotest)
  participant Cmd as Command Layer
  participant Lua as luavm.ExecuteLuaWithGlobals
  participant HTTP as HTTP Client
  participant GRPC as gRPC Client

  rect rgb(235,245,255)
    note over User,CLI: Run HTTP test
    User->>CLI: autotest run
    CLI->>Cmd: renderRequestHttp(req)
    alt req.LuaBody present
      Cmd->>Lua: Execute luaBody + "return body()"
      Lua-->>Cmd: rendered JSON (or error)
      opt on error
        Cmd-->>CLI: fail test
      end
    else template body
      Cmd-->>Cmd: templateRender(req.Body)
    end
    Cmd->>HTTP: POST with body
    HTTP-->>Cmd: response
    Cmd-->>CLI: verify rules
  end

  rect rgb(245,235,255)
    note over User,CLI: Run gRPC test
    User->>CLI: autotest run
    CLI->>Cmd: renderRequestGrpc(req)
    alt req.LuaBody present
      Cmd->>Lua: Execute luaBody + "return body()"
      Lua-->>Cmd: rendered JSON (or error)
      opt on error
        Cmd-->>CLI: fail test
      end
    else template body
      Cmd-->>Cmd: templateRender(req.Body)
    end
    Cmd->>GRPC: Invoke RPC with body
    GRPC-->>Cmd: response
    Cmd-->>CLI: verify rules
  end

  rect rgb(235,255,245)
    note over Cmd,Lua: Lua-based rule verification
    Cmd->>Lua: Execute "return verify(r)" with globals (codeStr, bodyStr)
    Lua-->>Cmd: boolean result
    Cmd-->>CLI: pass/fail
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • fix lua print() #24 — Also refactors internal/rule/init.go to use a shared/global Lua VM, closely aligned with this PR’s luavm consolidation.

Poem

I nibble code like clover leaves, so bright,
A Lua breeze now fills our tests at night.
With shared VM and scripts that softly sing,
HTTP, gRPC—fresh payloads spring.
New version hops—v0.2.0 in sight,
I thump approval: “All green!”—delight. 🐇✨

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/request

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99dbaf8 and 906b415.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (20)
  • .github/workflows/golang-ci.yml (2 hunks)
  • .golangci.yml (1 hunks)
  • README.md (4 hunks)
  • README_zh.md (4 hunks)
  • config_files/autotest.yml (1 hunks)
  • config_files/my_grpc_api.yml (1 hunks)
  • config_files/my_http_api.yml (3 hunks)
  • go.mod (1 hunks)
  • internal/command/command.go (3 hunks)
  • internal/command/grpc_call.go (3 hunks)
  • internal/command/http_call.go (2 hunks)
  • internal/config/config.go (2 hunks)
  • internal/luavm/init.go (1 hunks)
  • internal/rule/grpc_lua_rule.go (2 hunks)
  • internal/rule/http_lua_rule.go (2 hunks)
  • internal/rule/http_lua_rule_test.go (0 hunks)
  • internal/rule/init.go (1 hunks)
  • internal/rule/lua_test.go (1 hunks)
  • main.go (1 hunks)
  • test/mygrpccurl/main.go (1 hunks)

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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 and usage tips.

@vearne vearne merged commit 06d6ec0 into main Sep 19, 2025
1 of 2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 16, 2025
@coderabbitai coderabbitai bot mentioned this pull request Nov 13, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants