Skip to content

1.06 Journal Entries and Posting Rules: Exit Evidence

Evidence · Step: 1.06 Journal Entries and Posting Rules (Pure Core)

Step 1.06 Journal Entries and Posting Rules (Pure Core)
Date 2026-11-11
Result Passed
Deliverable File Contents
Entries crates/core/src/entry.rs EntryDraft and LineDraft (unvalidated requests); BalancedEntry and Line (validated); AccountsView, the read access validation needs
Validation crates/core/src/validate.rs validate(draft, accounts) -> Result<BalancedEntry, PostingError>
Errors crates/core/src/error.rs PostingError with stable codes 1001–1010, pinned by a test
Time crates/core/src/time.rs Timestamp in microseconds, passed in, never read from a clock
Fixtures crates/core/tests/worked_entries.rs, crates/core/tests/common/mod.rs Every journal table in docs/accounting/entries/, read from the docs
Spec docs/spec.md §1, §3, §4 and the remaining mentions Rewritten from the transfer model to journal entries

The scaffold’s transfer model (id.rs, state.rs, transfer.rs and the old error enums) is removed. mezgeb-offline now uses EntryId, PositiveAmount and the new Timestamp.

Checked in this order; lines in their order in the entry.

Code Rule
1001 At least 2 lines
1002 At most 100 lines
1003 At most 32 metadata keys and 4,096 bytes
1004 Every amount is greater than zero
1005 Every account exists
1006 Every account is open
1007 Each line’s currency is its account’s currency
1008 No two lines share an account and side, unless the draft allows it
1009 Each currency’s debit and credit totals fit in an i64
1010 Debits equal credits in every currency

Rules 1002 (too many lines) and 1009 (overflow) are not in the step’s list. They were added so that validation can never be slowed by a huge entry or produce totals that cannot be stored.

Requirement Test Result
Unit test per rule, including rejection rule_too_few_lines … rule_unbalanced, one per code, plus rules_are_checked_in_order and balances_each_currency_separately Pass
Any entry validate accepts sums to zero per currency accepted_entries_balance_per_currency (property) Pass
Changing one amount of a valid entry is always rejected changing_one_amount_is_rejected (property) Pass: always Unbalanced in that line’s currency
The worked examples are encoded as test fixtures every_worked_entry_validates Pass: all 24 journal tables (OB and E01–E18, including each part of E04, E13, E14 and E15)

In total: 71 tests in mezgeb-core. Coverage of non-test code in entry.rs, validate.rs, error.rs and time.rs: 100% of lines and regions.

The fixtures are read from the documentation rather than copied into code, so they cannot drift from it. To confirm the test really reads the docs, the fee line of E07 was changed from 2 to 3 in a scratch copy. The test failed with E07 #1: [1010] ETB debits (10000) do not equal credits (10100), and the file was restored.

Each fixture’s computed total is also checked against the Total row printed in the docs.

BalancedEntry has no public constructor other than validate. Its fields are private; its only constructor is pub(crate) and called only from validate; it has no Default, Deserialize or From implementation. Pass.

Gate: all fixtures validate, and every mutated fixture is rejected with the expected code.

Each of the 24 fixtures is mutated in 7 ways, and each mutation must fail with its code:

Mutation Expected code
Remove all but one line 1001
Set one amount to zero 1004
Point a line at an unknown account 1005
Freeze one account 1006
Put one line in USD 1007
Repeat a line 1008
Add one santim to one line 1010

every_mutated_worked_entry_is_rejected: 168 mutations, all rejected with the expected code. Result: passed.