Skip to content

Add unit tests for the events-lambda#2153

Merged
mattgodbolt merged 3 commits into
mainfrom
events-lambda-tests
Jun 4, 2026
Merged

Add unit tests for the events-lambda#2153
mattgodbolt merged 3 commits into
mainfrom
events-lambda-tests

Conversation

@mattgodbolt
Copy link
Copy Markdown
Member

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

  • No new dependencies. Uses Node 22's built-in node:test runner. The AWS SDK clients are module-level singletons, so each test intercepts Client.prototype.send via node:test's built-in mock.method -- no aws-sdk-client-mock/sinon, no test framework.
  • 15 tests covering:
    • 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 --test in package.json; engines.node pinned to >=22 (matches the nodejs22.x runtime and satisfies eslint-plugin-n for the node:test import).
  • CI runs the suite (.github/workflows/python-tests.yaml).
  • Test files are named *.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 passed
  • make static-checks clean (events-lambda lint covers the new test files)
  • events zip rebuilt; confirmed no *.test.js inside

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 4, 2026 01:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 for events-connections, events-onconnect, events-ondisconnect, and events-sendmessage.
  • Add npm test script and set engines.node >= 22 for 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 thread .github/workflows/tests.yaml Outdated
Comment on lines +37 to +39
- name: Test events-lambda
working-directory: events-lambda
run: npm install && npm test
mattgodbolt and others added 2 commits June 3, 2026 20:42
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>
@mattgodbolt mattgodbolt merged commit bb46041 into main Jun 4, 2026
1 check passed
@mattgodbolt mattgodbolt deleted the events-lambda-tests branch June 4, 2026 01:49
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