test(projects): add real-gremlin test scaffolding via testcontainers#181
Open
svozza wants to merge 2 commits into
Open
test(projects): add real-gremlin test scaffolding via testcontainers#181svozza wants to merge 2 commits into
svozza wants to merge 2 commits into
Conversation
Establishes the testing pattern for the ~15 Gremlin-touching lambdas (currently zero coverage) by spiking on lambda/projects. A single tinkerpop/gremlin-server testcontainer runs for the whole vitest run; per-file PartitionStrategy keyed by GREMLIN_PARTITION isolates each suite's writes. The lambda reads the env var and applies the strategy when set; production never sets it, so behavior is unchanged. lambda/projects is converted to ESM (matches lambda/github convention, lets tests import ../shared/response.js without packaging tricks) and gains GREMLIN_PORT/GREMLIN_PROTOCOL hooks so the SigV4 path can target a non-Neptune Gremlin server in tests. SigV4 still runs in tests; the container ignores the signed headers.
Switches projects_lambda packaging from npm_requirements (which walks
the lambda's own package.json for runtime deps) to the workspace build
pattern (npm run build -w projects). Required because gremlin and
gremlin-aws-sigv4 are now centralised in the root devDependencies and
hoisted at install time — the old packaging mode couldn't see them.
Also adds a createRequire banner to projects' esbuild invocation.
gremlin's bundled CJS does require('buffer') at module init, which
fails inside an ESM bundle without an injected require. Other workspace
lambdas don't hit this because they don't pull in any CJS deps that
self-require Node builtins.
Verified end-to-end against dev: aws lambda invoke against
collaborative-ai-dlc-projects-dev returns a real Neptune query result.
2096505 to
98d3a1f
Compare
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.
Summary
Establishes the testing pattern for the ~15 Gremlin-touching lambdas (currently zero coverage) by spiking on
lambda/projects. Continues the #41 rollout (ESM + tests).The approach: a real
tinkerpop/gremlin-serverruns in a testcontainer for the duration ofvitest run, and the lambda under test connects to it the same way it connects to Neptune in production — samegetConnectioncode path, same SigV4 signing (the container ignores the headers). Per-test isolation comes from aPartitionStrategythat is wired into the lambda only when the env varGREMLIN_PARTITIONis set; production never sets it, so production behavior is unchanged.A single
tinkerpop/gremlin-servertestcontainer is started once at the start ofvitest runand shared across every test file. Per-filePartitionStrategyisolates each suite's writes from every other suite's. Even when this rolls out to all 15 Gremlin lambdas, that's still one container per CI job.The pattern (what subsequent Gremlin lambdas will copy)
For each Gremlin lambda we want to test:
getConnection, conditionally applyPartitionStrategywhenGREMLIN_PARTITIONis set. No-op in production.GREMLIN_PARTITIONto a fresh UUID inbeforeAll, dynamic-import the handler, drive it like API Gateway does. Pin time withvi.useFakeTimers({ toFake: ['Date'] }). Seed non-handler-creatable state (e.g. non-owner member edges) through a small partition-scopedg.What's in this PR
lambda/projects/index.js— ESM-converted (was CJS), addedPartitionStrategyguard plusGREMLIN_PORT/GREMLIN_PROTOCOLenv hooks for non-Neptune Gremlin servers. SigV4 path unchanged for production.lambda/projects/package.json— aligned with the workspace template (private, scripts, esbuildbuild). Runtime deps removed; centralised in root devDependencies (matchesnotify/github-issues).terraform/modules/api/lambda/main.tf—projects_lambdaswitched fromnpm_requirements = trueto thenpm run build -w projectsbuild-script pattern (matchesws-message/notify).test/gremlin-setup.js— vitestglobalSetupthat bootstinkerpop/gremlin-server:3.7.3, plants inert AWS creds sofromNodeProviderChainresolves cleanly on CI runners.vitest.config.js— wires the global setup once for the whole run.lambda/projects/test/projects.test.js— 22 tests covering every routable branch (HTTP method × auth state × role).package.json— addslambda/projectsto workspaces, hoistsgremlin/gremlin-aws-sigv4/@aws-sdk/credential-providers/@smithy/*, addstestcontainers.Notable decisions
createHandler({ query })factories. That's dropped — the env-var partition seam is sufficient and keeps the lambda's structure unchanged.neptune-lambda-clientadoption (issue [Feature]: Harden Gremlin connection handling in lambdas #43) is out of scope. This PR only establishes the test scaffolding. The library swap is the next change and will benefit from being landable as an isolated diff with a green test suite already in place.lambda/projects. Required to import../shared/response.jscleanly from the test, matching the convention already used bylambda/github. Production zip layout is unaffected.createRequirebanner.gremlinandgremlin-aws-sigv4self-require('buffer')at module init; without the banner the ESM bundle fails on Lambda. Will likely change shape under [Feature]: Migrate Lambda bundling from esbuild CLI to Vite #174 (Vite migration).Test plan
npm test— all 175 tests pass (22 new + 153 existing); ~6s after image cachednpm run build -w projectsproduces a 673kb bundleterraform applyagainst dev —projects_lambdaredeployed with new package layoutaws lambda invokeagainstcollaborative-ai-dlc-projects-devreturns a real Neptune query result (verified end-to-end)TESTCONTAINERS_RYUK_DISABLED=true(Colima can't bind-mount the docker socket Ryuk needs). GHA runners use Docker Engine and don't need this.Refs #41