Skip to content

Conversation

@vearne
Copy link
Owner

@vearne vearne commented Jan 13, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Lua preload files functionality, enabling users to configure external Lua files that are automatically loaded and available for use in test cases.
    • Introduced Lua utility functions (formatTimestamp, validateEmail, generateUUID, deepEquals) available globally when preload files are configured.
  • Documentation

    • Added comprehensive documentation on Lua preload files configuration in README with usage examples.
    • Added project coding guidelines and best practices in new AGENTS.md file.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 13, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request introduces Lua preload file support for the autotest framework. It adds configuration structures, a preload file loader with global tracking, resource initialization functions, and validation logic. Example Lua utilities and test cases demonstrate the feature's usage across HTTP and gRPC APIs.

Changes

Cohort / File(s) Summary
Lua Preload Infrastructure
internal/luavm/init.go, internal/luavm/init_test.go
Added global state management for tracking preloaded Lua files and their exported globals. Implemented LoadPreloadLuaFiles() public function with file reading, syntax validation, and state injection. Tests verify preload loading, error handling (syntax errors, missing files), global exposure, and execution of preloaded functions.
Configuration & Resource Initialization
internal/config/config.go, internal/resource/resource.go, internal/command/command.go
Added Lua struct with PreloadFiles field to AutoTestConfig. Added InitLuaVM() and ValidateLuaFiles() functions to handle path resolution, file validation, and Lua VM initialization. Integrated validation and initialization into command flow with error handling.
Test & Configuration Examples
config_files/autotest.yml, config_files/lua/utils.lua, config_files/my_grpc_api.yml, config_files/my_http_api.yml
Added utils.lua with utility functions (formatTimestamp, validateEmail, generateUUID, deepEquals). Updated autotest.yml to configure preload files and enable HTTP rules. Added gRPC test case (id: 9) and HTTP rule demonstrating preloaded function usage.
Documentation
AGENTS.md, README.md
Added new AGENTS.md file documenting coding guidelines, build/test commands, style conventions, and CI/CD practices. Extended README.md with "Lua Preload Files" subsection explaining configuration and usage.

Sequence Diagram(s)

sequenceDiagram
    participant Cmd as Command Handler
    participant Config as Config Parser
    participant Resource as Resource Manager
    participant LuaVM as Lua VM
    participant FS as File System
    
    Cmd->>Config: Parse configuration file
    Config->>FS: Read config.yml
    FS-->>Config: Config data
    Config->>Resource: ParseConfigFile()
    Note over Resource: Convert preload paths<br/>to absolute
    
    Cmd->>Resource: ValidateLuaFiles()
    Resource->>FS: Check preload file existence
    FS-->>Resource: File exists confirmation
    Resource-->>Cmd: Validation success
    
    Cmd->>Resource: InitLuaVM()
    Resource->>Resource: Resolve configDir
    Resource->>FS: Read preload files
    FS-->>Resource: File contents
    Resource->>LuaVM: LoadPreloadLuaFiles(files)
    LuaVM->>LuaVM: Validate syntax
    LuaVM->>LuaVM: Track globals
    LuaVM->>LuaVM: Store loaded content
    LuaVM-->>Resource: Preload loaded
    Resource-->>Cmd: Lua VM initialized
    
    Cmd->>Cmd: RunTestCases()
    Note over Cmd: Test cases execute<br/>with preloaded functions
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

  • support html report #21: Modifies internal/resource/resource.go's ParseConfigFile logic to handle path conversion, directly related to Lua preload path resolution added in this PR.
  • Feat/request #26: Extends internal/luavm package and integrates new public APIs (LoadPreloadLuaFiles, InitLuaVM) into command/config/rule execution flows.
  • optimize #27: Modifies internal/luavm/init.go initialization and execution infrastructure, overlapping with preload-file loading and state management changes.

Poem

🐰 A hop through Lua's verdant fields,
Where preloaded functions yield,
Utils trim and timestamps dance,
Global states in perfect trance,
Tests now sing with borrowed might,
Lua magic burning bright!

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68c685e and 4dcdfcb.

📒 Files selected for processing (11)
  • AGENTS.md
  • README.md
  • config_files/autotest.yml
  • config_files/lua/utils.lua
  • config_files/my_grpc_api.yml
  • config_files/my_http_api.yml
  • internal/command/command.go
  • internal/config/config.go
  • internal/luavm/init.go
  • internal/luavm/init_test.go
  • internal/resource/resource.go

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 ab2f097 into main Jan 13, 2026
1 of 2 checks passed
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