Skip to content

test(core): assert DeliveryEngine's queueing, merge, and delivery logic directly - #128

Merged
Mearman merged 4 commits into
mainfrom
chore/mutation-delivery-engine
Sep 15, 2026
Merged

Mearman merged 4 commits into
mainfrom
chore/mutation-delivery-engine

Conversation

@Mearman

@Mearman Mearman commented Sep 15, 2026

Copy link
Copy Markdown
Member

Summary

  • Direct, DI-based unit tests for DeliveryEngine, previously exercised only indirectly through integration tests
  • Covers presence/queueing/membership-merge/state-sync/patch-application (delivery-engine.test.ts) and local-delivery/broadcast/notification/mark-read (delivery-engine-delivery.test.ts)
  • Split across two files to satisfy the repo's max-lines lint rule

Closes #106. Part of the mutation-testing epic tracked in #64.

Mutation score: 43.36% -> 97.79% (221/226 scoreable, verified with a full local Stryker run). The four remaining survivors are all provable equivalent mutants, documented in place rather than chased.

Test plan

  • pnpm typecheck
  • pnpm lint
  • pnpm test (673 passed)
  • Verified mutation score with a real Stryker run

…ic directly

DeliveryEngine was previously exercised only indirectly through end-to-end
room-send/state-sync integration tests, leaving many individual branches
unobserved: version-gate boundaries in mergeRoom/applyStateSync/applyPatch,
subscribedRooms union-vs-replace at equal versions, the queueDelivery and
local-delivery dedup caps' exact eviction behaviour, timer-scheduled
auto-mark-read (including the isShutDown races at both schedule and fire
time), and applyStateSync's per-event-type replay rules.

Split across two files (delivery-engine.test.ts and
delivery-engine-delivery.test.ts) to stay under the repo's max-lines cap,
each with its own copy of the shared DeliveryEngineDeps harness: the first
covers presence/queueing/membership-merge/state-sync/patch-application, the
second covers local-delivery/broadcast/notification/mark-read.
A scoped mutation run against the DI-based test suite surfaced nine
survivors, two of which are genuine equivalents (documented below) and
seven of which were real gaps:

- queueDelivery's eviction cap and mergeMemberOps's stamp-comparison
  boundary are provably equivalent mutants: splice's own deleteCount
  computation and reassigning a Map entry to its own current value are
  both no-ops regardless of whether the mutated boundary operator fires,
  so no test can distinguish them from the original.
- applyPatch(room_upsert) never had a same-version case: only strictly
  lower and strictly higher versions were tested, leaving the equal-
  version merge path (the only path the equality half of the version
  guard actually gates) unobserved.
- fireLocalDelivery's already-read skip only ever ran a room_message
  through it, never a dm, leaving the dm half of that condition
  unobserved.
- fireLocalDelivery's own scheduled mark-read timer had no test for the
  store shutting down between scheduling and firing (only the
  applyPatch(delivery) codepath's equivalent timer had one).
- findMessageLocation's two internal lookups, and markRead's own
  separate lookup, were only ever exercised against single-message
  arrays, where a mutated always-true predicate is indistinguishable
  from a real id match.

Rebalanced the split across both files afterward to stay under the
repo's max-lines cap: deliver/drainDelivery and the onPatch-callback
tests moved from delivery-engine-delivery.test.ts into
delivery-engine.test.ts, which had more headroom.
… real equivalent

applyPatch's agent_offline case had no test at all -- a full local mutation
run against the current test suite surfaced it as a genuine survivor once
the earlier gap-closing pass's own new coverage pushed enough of the file's
other branches into range to actually reach it.

Also documents (rather than chases) the two remaining survivors against
queueDelivery's own length guard: both are provably equivalent, since
Array.prototype.splice with a non-positive deleteCount is a no-op
regardless of which operator or literal the guard condition uses.
…tants

A fresh full mutation run against the current test suite confirms 97.79%
(221/226 scoreable) with exactly four surviving locations, all provable
equivalents rather than gaps: queueDelivery's length-guard boundary
(already documented), mergeMemberOps' stamp-comparison boundary, the
deliveryQueues-replay dedup set's unreachable fallback array, and
applyPatch(agent_offline)'s redundant same-reference Map.set. Each is
explained in place rather than chased with a contrived test.
@Mearman
Mearman marked this pull request as ready for review September 15, 2026 22:40
@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-15T22:42:47.944211Z be7293f Draft marked ready
ℹ️ 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.

@Mearman
Mearman merged commit 3982352 into main Sep 15, 2026
6 checks passed
@Mearman
Mearman deleted the chore/mutation-delivery-engine branch September 15, 2026 22:40
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.21.18 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raise src/core/delivery-engine.ts mutation score to 80%

1 participant