Skip to content

Fix critical bugs, improve safety, and add tests/CI - #11

Merged
mostafa merged 7 commits into
mainfrom
improvements
Feb 21, 2026
Merged

mostafa merged 7 commits into
mainfrom
improvements

Conversation

@mostafa

@mostafa mostafa commented Feb 21, 2026 •

Copy link
Copy Markdown
Member

Ticket(s)

N/A - issues found via code review.

Description

Critical bug fixes

  • Fix OnNewPool dispatching to "onConfigLoaded" instead of "onNewPool" (copy-paste bug)
  • Fix OnTraffic swallowing error (returning nil instead of err)
  • Add sync.Mutex to protect Goja VM from concurrent access (not goroutine-safe)
  • Use checked type assertion in RunFunction to prevent panics on unexpected JS return types
  • Fix hardcoded "OnTrafficFromClient" in RunFunction error log to use actual function name

Helper function improvements

  • Add argument bounds checking to btoa, atob, and parseSQL (prevents panic on no-arg calls)
  • Handle errors from base64 decode and SQL parse instead of silently discarding them
  • Switch btoa/atob from RawStdEncoding to StdEncoding for browser compatibility
  • Replace deprecated golang.org/x/exp/maps with stdlib maps/slices

Copy-paste artifact cleanup

  • Fix default metrics socket path from gatewayd-plugin-cache.sock to gatewayd-plugin-js.sock
  • Update stale "Template plugin" description

CI/CD

  • Update GitHub Actions to latest versions (checkout@v4, setup-go@v5, gh-release@v2)
  • Add CI workflow with golangci-lint, govulncheck, go test with coverage, and coveralls
  • Add .golangci.yaml configuration

Tests

  • Add 32 unit tests covering function registration, RunFunction paths, GetHooks, GetPluginConfig, all 21 hook methods for passthrough and correct dispatch

Related PRs

None.

Development Checklist

  • I have added a descriptive title to this PR.
  • I have squashed related commits together.
  • I have rebased my branch on top of the latest main branch.
  • I have performed a self-review of my own code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added docstring(s) and type annotations to my code.
  • I have made corresponding changes to the documentation (docs).
  • I have added tests for my changes.

Legal Checklist

- Fix OnNewPool dispatching to "onConfigLoaded" instead of "onNewPool" (copy-paste bug)
- Fix OnTraffic swallowing error by returning nil instead of err
- Add sync.Mutex to protect Goja VM from concurrent access (not goroutine-safe)
- Use checked type assertion in RunFunction to prevent panics on unexpected JS return types
- Fix hardcoded "OnTrafficFromClient" in RunFunction error log to use actual function name
- Add argument bounds checking to btoa, atob, and parseSQL to prevent
  panics when called with no arguments from JS
- Handle errors from base64 decode and SQL parse instead of silently
  discarding them; throw JS TypeErrors on invalid input
- Switch btoa/atob from RawStdEncoding to StdEncoding for browser
  compatibility (standard base64 with padding)
- Replace deprecated golang.org/x/exp/maps with stdlib maps/slices
- Fix default metrics socket path from gatewayd-plugin-cache.sock to
  gatewayd-plugin-js.sock
- Update stale "Template plugin" description to reflect actual purpose
- actions/checkout v3 -> v4
- actions/setup-go v3 -> v5
- softprops/action-gh-release v1 -> v2
- Add test.yaml workflow that runs on push/PR with golangci-lint,
  govulncheck, go test with coverage, and coveralls reporting
- Add .golangci.yaml configuration matching the cache plugin's style,
  with depguard rules for this project's dependencies
- Test RegisterFunction/RegisterFunctions with valid and missing JS functions
- Test RunFunction for success, not-found, JS error, and wrong return type
- Test GetHooks returns only registered (non-nil) hooks
- Test GetPluginConfig returns correct metadata
- Test all 21 hook methods pass through correctly without JS functions
- Test all 21 hook methods dispatch to the correct JS function name
  (prevents copy-paste bugs like the OnNewPool fix)
- Test NewJSPlugin constructor
@mostafa mostafa self-assigned this Feb 21, 2026
@mostafa mostafa changed the title Improvements Fix critical bugs, improve safety, and add tests/CI Feb 21, 2026
- Move context.Context to first parameter in RunFunction (revive)
- Rename unused parameters to _ in GRPCServer, GRPCClient, GetPluginConfig (revive)
- Define static ErrUnexpectedReturnType and wrap with fmt.Errorf (err113)
- Fix gofumpt formatting in OnTrafficFromServer and OnTrafficToClient
- Change NewJSPlugin to take *Plugin to avoid copying sync.Mutex (govet/copylocks)
- Extract setupHelpers to reduce nesting complexity in main() (nestif)
- Rename short parameter name vm -> runtime (varnamelen)
@mostafa
mostafa merged commit 73b850d into main Feb 21, 2026
2 checks passed
@mostafa
mostafa deleted the improvements branch February 21, 2026 21:54
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.

1 participant