Files
werkregie/doc/prs/2026-10-16-PR#92-matrix-source-crap.md
claude-code 1c3d38060f
werkator build succeeded after 01:00
werkator/deploy build succeeded after 00:26
werkator/vulnerability-data build succeeded after 02:28
werkator/mutation build failed after 16:00
MatrixSource at a Mutation-CRAP of at most 15 (#92)
Co-authored-by: claude-code <claude-code@javagil.de>
2026-10-16 17:55:14 +02:00

3.1 KiB

PR#92: MatrixSource at a Mutation-CRAP of at Most 15

Version: patch

WARNING: This document describes only the change applied in this PR. It may already be outdated once the next PR is merged. Historic PR documentation is not maintained along with new PRs; treat it as a snapshot.

Problem

matrix react needs sync.lock, which the running relay holds; an agent stops the relay for about 50 s per reaction. The relay is to send the reaction itself, which changes sources/MatrixSource.kt. A branch fails on each method above a Mutation-CRAP of 15 in a class it changes; 9 of its methods are above, MatrixSource.message at 812 on main, the highest of the nightly ratchet: a complexity of 28 without a killed mutant, since only a homeserver could drive it.

Non-Goals

  • No change of behaviour.
  • No reaction through the relay yet; that is the follow-up PR.

Specification

None; the behaviour stays the same.

Solution

The decisions move out of MatrixSource into functions that tests reach without a client; what stays in MatrixSource is the glue to Trixnity, at a complexity of at most 3, so that it stays at most 12 without a killed mutant (3² + 3).

  • MatrixEvents, new: what MatrixSource takes from Trixnity, tested with Trixnity's own data classes: incoming decides which event is a message of someone else, message builds the MatrixMessage from event, room and members, receiptTime takes the newest read receipt, baseUrl and isUrl the homeserver, crossSigned the trust level of the device.
  • MatrixMessages, free of the client library: unread, roomOf, readIn, encrypted and decrypted.
  • MatrixSource: decryptAgain hands each row to decrypted; login and verify take the lock by locked, which the follow-up PR also uses; verifyWith takes its checks from checkVerified, verifyBy, byRecoveryKey and byPassphrase; syncError names the cause of an ended sync.
  • New tests in MatrixEventsTest, MatrixMessagesTest and MatrixSourceTest.
  • pitestPartial mutationCrapCheck against main: the highest Mutation-CRAP of MatrixSource is 12, of MatrixEvents 11 (incoming, all mutants killed).

The ratchet of the nightly run falls from 812 to 272, now CodexSource.fetch; the change of dashboard/build.gradle.kts makes the check stricter, not weaker.

Open Questions

None.

Follow-up PRs

  • werkregie PR#93: matrix react no longer needs a stop of the relay. The relay, which holds sync.lock, sends the reaction with its own Matrix client, on request through a local socket. That PR changes MatrixSource, so it needs the limit of 15 that this PR reaches.