test: extraction middleware, module registry, and event flow test suites#7
Open
maurcarvalho wants to merge 8 commits intomainfrom
Open
test: extraction middleware, module registry, and event flow test suites#7maurcarvalho wants to merge 8 commits intomainfrom
maurcarvalho wants to merge 8 commits intomainfrom
Conversation
added 8 commits
February 24, 2026 16:40
…ain code - apps/orders-service/src/main.ts: standalone HTTP server using libs/modules/orders - apps/orders-service/Dockerfile: multi-stage build for the extracted service - apps/orders-service/tsconfig.json: extends root, includes shared libs - apps/orders-service/project.json: Nx project config - Dockerfile (root): monolith build - docker-compose.l3.yml: both services running (orders-db + main-db + redis) Zero domain code duplication. The handlers, entities, and value objects are identical to the monolith. Only infrastructure wiring differs.
The extracted Orders process is a worker that listens for events and publishes events. The monolith (or API gateway) continues to serve REST endpoints. An HTTP layer can be added later if the module needs an independent API surface (separate team, SLA, deployment cadence).
L3 means fully independent: the extracted Orders service serves its own HTTP API on port 3001, owns its database, and registers its own event listeners. This is the whole point of extraction.
- Add Next.js middleware: rejects /api/orders/* with 410 Gone when EXTRACTED_MODULES=orders is set - Update register-listeners.ts: skip orders listeners when extracted - Set EXTRACTED_MODULES=orders in docker-compose.l3.yml monolith service Extraction is a configuration change, not a code change.
Each module defines its own registerXxxListeners() function. The orchestrator loops MODULE_REGISTRARS, skipping any module listed in EXTRACTED_MODULES. Adding or extracting a module is a one-line change in one place.
…s, stockQuantity default - next.config.js: add NormalModuleReplacementPlugin for @tiny-store/* paths so Next.js webpack resolves /internal subpath imports - register-listeners.ts: use static imports instead of require() to avoid CommonJS/ESM interop issues in Next.js server components - product.entity.ts: add default:0 to stockQuantity column
New test categories for L3 extraction infrastructure: Unit tests (tests/unit/): - module-registry.spec.ts: validates MODULE_REGISTRY skips extracted modules, handles whitespace/casing in EXTRACTED_MODULES, always registers event store. Uses jest.isolateModules for clean env. - extraction-middleware.spec.ts: validates 410 Gone for extracted module routes, passthrough for others, response shape. Integration tests (tests/integration/): - event-flow.spec.ts: EventBus pub/sub, async handlers, event cascading (OrderPlaced → InventoryReserved → OrderConfirmed → PaymentProcessed), singleton isolation. Scripts: npm run test:extraction, npm run test:events Results: 22 unit + 7 integration = 29 new tests, all passing. Existing 211 tests unaffected.
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.
Test Suites for L3 Extraction Infrastructure
Adds 29 new tests covering the extraction mechanism introduced in PR #6.
Unit Tests (
npm run test:extraction)Module Registry (9 tests)
Extraction Middleware (13 tests)
Integration Tests (
npm run test:events)Event Flow (7 tests)
Also includes (from PR #6 base)
Test results