Add unit tests for the events-lambda#2153
Merged
Merged
Conversation
The events websocket lambda had no tests, only lint -- yet it has real logic (composite-key subscriptions, subscriber relay, ack handling, connection cleanup). Add a suite covering the DynamoDB connection layer and all three handlers, using the built-in node:test runner with no new runtime or test-framework dependency: the AWS SDK clients are intercepted by mocking Client.prototype.send. Wire `npm test` into package.json and CI (the test files are already excluded from the deployed zip by the build script). Pin engines.node to >=22 to match the nodejs22.x runtime. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a Node.js unit test suite for the events-lambda websocket handler/DynamoDB layer using Node 22’s built-in node:test, and wires those tests into CI to prevent regressions/bitrot.
Changes:
- Add
node --test-based unit tests forevents-connections,events-onconnect,events-ondisconnect, andevents-sendmessage. - Add
npm testscript and setengines.node >= 22for the lambda package. - Run the new events-lambda tests in the existing GitHub Actions workflow.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
events-lambda/package.json |
Adds Node >=22 engine requirement and npm test script using node --test. |
events-lambda/package-lock.json |
Records the Node engine requirement in the lockfile metadata. |
events-lambda/events-sendmessage.test.js |
Adds handler tests for subscribe routing, relay behavior, no-subscriber behavior, and unknown text echo. |
events-lambda/events-ondisconnect.test.js |
Adds disconnect tests covering success and error-swallowing behavior from the DynamoDB layer. |
events-lambda/events-onconnect.test.js |
Adds connect tests covering success and DynamoDB failure path. |
events-lambda/events-connections.test.js |
Adds DynamoDB-layer tests for add/update/unsubscribe/subscribers/remove and GUID sender cache/fallback. |
.github/workflows/python-tests.yaml |
Adds a CI step intended to run the new events-lambda test suite. |
Files not reviewed (1)
- events-lambda/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
11
to
+13
| "lint": "eslint --max-warnings=0 . --fix", | ||
| "format": "prettier --write ." | ||
| "format": "prettier --write .", | ||
| "test": "node --test" |
Comment on lines
+37
to
+39
| - name: Test events-lambda | ||
| working-directory: events-lambda | ||
| run: npm install && npm test |
It now runs static checks, Python tests, terraform validate, shellcheck, the lambda package builds and the events-lambda node tests, so the "Python tests" name and python-tests.yaml filename are misleading. The job (and required-check) name "build" is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Addresses review feedback: the job never set up Node, so the events-lambda lint/build/test ran on the runner's default version despite package.json requiring node >=22. Add actions/setup-node (Node 22, matching the nodejs22.x runtime) and switch the test step to npm ci for a deterministic install. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The events websocket lambda had no tests, only lint -- despite having real logic (composite-key subscriptions, subscriber relay, ack handling, connection cleanup). This adds a suite and runs it in CI, continuing the bitrot cleanup from #2152.
Approach
node:testrunner. The AWS SDK clients are module-level singletons, so each test interceptsClient.prototype.sendvianode:test's built-inmock.method-- noaws-sdk-client-mock/sinon, no test framework.events-connections.js-- the DynamoDB layer:add,update,unsubscribe,subscribers(query + merge),remove(scan + delete-all), and GUID-sender cache/fallback.events-onconnect/events-ondisconnect-- success and failure paths (incl. documenting that disconnect swallows DynamoDB errors and still returns 200).events-sendmessage-- subscribe routing, object-message relay to subscribers, the no-listeners 501, and unknown-text echo.Wiring
npm test->node --testinpackage.json;engines.nodepinned to>=22(matches thenodejs22.xruntime and satisfies eslint-plugin-n for thenode:testimport)..github/workflows/python-tests.yaml).*.test.js, which the lambda build script already excludes from the deployed zip (verified: the built package contains only the runtime source).Validation
npm test-- 15 passedmake static-checksclean (events-lambda lint covers the new test files)*.test.jsinside🤖 Generated with Claude Code