Skip to content

test(mesh-store): direct unit tests for MeshStore's own orchestration logic - #126

Merged
Mearman merged 4 commits into
mainfrom
test/mesh-store-mutation-coverage
Sep 15, 2026
Merged

Mearman merged 4 commits into
mainfrom
test/mesh-store-mutation-coverage

Conversation

@Mearman

@Mearman Mearman commented Sep 15, 2026

Copy link
Copy Markdown
Member

Summary

  • MeshStore's constructor takes no injectable deps (unlike its extracted collaborators), and its own orchestration-level logic -- requireTransport/requireIdentity's guard errors, the connected getter, init()'s connect-vs-becomeCoordinator-vs-EADDRINUSE branching, the events getter's dispatch table, federation/listener/room-join-approval passthroughs, constructor wiring, and shutdown() -- was previously exercised only indirectly through wireTestTransport-based integration tests.
  • Uses a hand-built fake MeshTransport passed to the real setTransport() for deterministic control over init()'s branches, and reaches the private collaborators via a narrow cast to assert delegating wrappers actually call through -- justified in the file's own header comment.
  • Raises src/core/mesh-store.ts's mutation score from a freshly-measured 51.85% (47 killed, 9 timeout, 52 survived) toward the repo's 80% threshold.

Closes #103

Test plan

  • pnpm typecheck
  • pnpm lint
  • pnpm test (65 files, 524 tests, full suite green)

MeshStore's constructor takes no injectable deps (unlike its extracted
collaborators), and its own orchestration-level logic -- requireTransport/
requireIdentity's guard errors, the connected getter, init()'s connect-vs-
becomeCoordinator-vs-EADDRINUSE branching, the events getter's dispatch
table, federation/listener/room-join-approval passthroughs, and shutdown()
-- was previously exercised only indirectly through wireTestTransport-based
integration tests, which don't isolate MeshStore's own branching from its
collaborators' real behaviour.

Uses a hand-built fake MeshTransport passed to the real setTransport() for
deterministic control over init()'s branches, and reaches the private
roomProtocol/connectionApproval/peerLifecycle/deliveryEngine/staleAgentChecker
collaborators via a narrow cast to assert a delegating wrapper actually
calls through -- TypeScript's private is compile-time only, and this is
exactly the kind of whitebox check a one-line pass-through method needs
that no public-API-only test can express. Covers every currently-open
survivor/timeout this file's mutation score reports except the events
getter's onMessage/onPeerConnected dispatch pair sharing a mutant with an
already-covered branch, and getFederationFingerprint (no test infrastructure
for a real TLS identity certificate exists yet).
…aced

Verified against a real run rather than trusting the prior commit's
own unverified claim about what remained (which named the wrong
survivors entirely -- neither of the two it named was actually still
open). The real gaps: constructor wiring for both discovery backends
(observable via discovery.advertise's own "Available:" error message),
the getOnPatch closure passed to DeliveryEngine (observable via a real
broadcastPatch call), ConnectionApproval's queueDelivery closure and
MeshStore.deliver()'s own delegation (both observable via drainDelivery
picking up the queued event), and shutdown()'s pending-markRead-timer
clearing loop.

Two survivors remain genuinely open, left for follow-up rather than
forced: FederationManager's own meshName string (needs a real two-way
federation connection to observe, the kind of setup
federation.integration.test.ts already has but doesn't currently
assert this specific field against), and a handful of Timeout-classified
mutants inside init()'s branches and the events getter that this file's
own new tests do correctly fail fast against, but where the whole
command-runner suite still doesn't exit within budget for an unrelated
reason -- timeouts already count as caught for scoring purposes, so
these don't block the threshold, only slow the run.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review Completed 2026-09-15T11:22:34.044731Z bec92a1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…and isShutDown

Verified against a fresh mutation run: the EADDRINUSE-degrade onError
message assertion only checked its first half, missing a mutant on the
second half's own string literal. shutdown()'s isShutDown = true flip
had no assertion at all -- fixed via its one observable effect
(fireLocalDelivery's own isShutDown() guard on scheduling further
markRead timers) rather than reaching into the private field directly.

One survivor remains genuinely open: FederationManager's meshName
string, which needs a real two-way federation connection to observe --
left for follow-up rather than forced with a contrived unit test.
…ranch

Verified against a fresh mutation run the previous commit's own
isShutDown test still survived -- fireLocalDelivery returns before
ever reaching the isShutDown-guarded timer push unless onDelivery is
set, so the assertion never actually exercised the line it claimed to
cover. Fixed by setting store.onDelivery, then confirmed directly: with
this.isShutDown = true manually flipped to false in the source, the
test now genuinely fails (pending length 1 instead of 0), and passes
against the real code -- proof the fix actually distinguishes the two,
not just that it was plausible.
@Mearman
Mearman merged commit 13f94ab into main Sep 15, 2026
6 checks passed
@Mearman
Mearman deleted the test/mesh-store-mutation-coverage branch September 15, 2026 13:05
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.

Raise src/core/mesh-store.ts mutation score to 80%

1 participant