imsd-messages/tests
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jorijn van der Graaf 9707c9fa26
Store: the message database on Crafter.DB
One table without an ordered column: Crafter.DB enforces the order on
every write, and a List() import after a restart can carry an older
stamp than the last row, so a conversation is sorted on read. A row
carries the plan it was written under, the SIM's country code and its
operator, a column each. Messages are looked up by imsd id (unique
across imsd's runs by its run token: an id names one message, and an
empty one — a text imsd has not answered yet — none); read marks and
deletes go per message and per conversation; every write but a Compact
is caught at this one boundary — a store that refuses one (Crafter.DB's
IOError: the disk full, the file system read-only) answers nullopt from
Add, false or a count of 0 (a row appended before its Flush failed is
tombstoned; an in-place write whose Flush failed stays in the row as the
process reads it; SetState's state and imsd's id land in place even when
a reason cannot — the id is inline in the row, 64 bytes as imsd bounds
it, one past that refused rather than thrown), and tells its
onWriteState listener once of the refusal and once of the next write
that got room, which is one that grew a file: Crafter.DB allocates its
extents, so a write that fit the ones it had (an in-place one, a short
row) is no recovery. So a refused write ends no caller's process and the
app's banner can say so. A lock file beside the table, held for the
store's life, makes a second store on the same directory throw
LockedError (the table's own lock sits on an inode a Compact replaces);
it is built on Crafter.DB's File and Os — the directory made 0700 at
every component, the file 0600 and never a symlink, a lock that fails
for any reason but another holder an IOError, not a LockedError. Every
change a call answers as made — a row id, true, a count — is committed
before the call returns, so a row Add returned is on disk. The file's
format is held by the build: static_asserts on the row's size and layout
fingerprint (Crafter.DB's Layout) and on the stored values of Direction
and MessageState, so a column changed without a version bump fails the
build and not a user's open, and an enumerator moved fails it where an
open would misread the stored states without a word.

Tested: tests/Store in a temp directory: the round trip, the sort of a
later-appended older message, the updates, the lookup by imsd id and an
erased row's, an id past imsd's bound refused, the lock from a second
open, persistence across a reopen, Compact, a row kept by a child
process that ends without a flush, the private file modes, and a write
refused under the file-size limit (told once with its reason, the rows
before it standing, an in-place write going through and telling nothing,
a state landing without its refused reason and imsd's id beside it, the
next Add after the limit's lifting telling of the recovery once), and a
Flush failing after its Append (the descriptor pointed at /dev/null for
the one write) tombstoning the row Add refused.
2026-11-18 01:12:27 +01:00
..
Model Model: messages, conversations and the banner 2026-11-17 22:24:23 +01:00
Number Number: the conversation key of an address 2026-11-17 06:14:18 +01:00
Store Store: the message database on Crafter.DB 2026-11-18 01:12:27 +01:00
Time Time: ISO 8601 stamps, civil dates and the captions 2026-11-17 06:14:18 +01:00
Wrap Wrap: word wrap and ellipsis over a measure function 2026-11-17 06:14:18 +01:00