test(shared): direct coverage for the blockchain event bus and HTTP metrics hook - #162
Merged
dev-fani merged 1 commit intoAug 30, 2026
Merged
Conversation
…rectly Adds two dedicated spec files for shared infrastructure that was only ever covered incidentally through module-level tests. src/shared/events/index.spec.ts exercises the in-process bus's own contract independent of any module handler: fan-out to every current subscriber, the returned unsubscribe function detaching one listener without affecting others, publishing with zero subscribers being a no-op, each publish being delivered independently (not coalesced), and a double unsubscribe being harmless. The unsubscribe test fails if onBlockchainEvent's teardown is broken. src/shared/http/plugins/metrics.spec.ts builds a minimal Fastify instance with one parameterized route and asserts the http_requests_total counter is labeled by route *pattern* rather than the concrete URL (the cardinality guard the file comment describes), and that an unmatched 404 is recorded as `unmatched` rather than dropped. closes fanilabs#125 closes fanilabs#126
|
@hartz0 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Two pieces of shared infrastructure that every module depends on had no dedicated test — coverage was entirely incidental, coming from module-level tests that call handlers directly or from a full HTTP integration test that happens to run the plugin as a side effect. This PR adds a spec file for each, testing the component's own contract at its own boundary.
src/shared/events/index.spec.ts— closes #125The in-process
publishBlockchainEvent/onBlockchainEventbus that all seven event-consuming modules subscribe to. New tests, all going through the real bus rather than a handler:onBlockchainEventstops further delivery to that listener only, leaving others attachedpublishBlockchainEventcalls are each delivered independently — not batched or coalescedThe unsubscribe test is a genuine regression guard: if
onBlockchainEvent's teardown stopped detaching the listener, the "without affecting others" assertion (leavescalled exactly once) fails.src/shared/http/plugins/metrics.spec.ts— closes #126The
onResponsehook that recordshttp_requests_total/http_request_duration_seconds. New tests build a minimal Fastify instance with one parameterized route and assert:/api/v1/deliveries/abc-123) is recorded under the route pattern (/api/v1/deliveries/:chainDeliveryId), and the concrete ids never become their own time series — the label-cardinality guard the file's header comment describesroute="unmatched"rather than droppedAssertions read the shared
prom-clientregistry via a before/after delta, since it accumulates across the suite.Testing
pnpm exec vitest run src/shared/events/index.spec.ts src/shared/http/plugins/metrics.spec.ts→ 7 passingpnpm exec eslintclean on both new filestsc --noEmitintroduces no new errors