Skip to content

Unit tests: every module's tests rewritten on its purpose and branches #1714

Done

Description

@vmillet-dev

Context — The Rust tests were added piece by piece as the application grew: about 2,970 #[test] over 397 files and eight crates (engine 1,669, ui 1,032, drawing 91, text 49, richtext 44, platform 42, app 24, i18n 23). Some say the same thing twice, some pin an implementation detail where a behaviour should be held, and some conditional branches or failing cases have no test at all. Asked by the owner. The end-to-end suite is rewritten apart, in #1715: what a screen shows is walked there, what a rule decides is held here.

Change — The tests of every production module are rewritten from scratch around two questions: what is this module for, in the application's terms, and what does each of its conditions do. A module holds its passing cases and its failing cases, each named after the rule it holds. A test states one behaviour expected of an element — what it does for an input, what it refuses, how it fails — so that its name reads to a colleague as a requirement. A test that repeats another, or that a harmless refactor would break, is gone. Coverage is a consequence of this and never the aim: no test is written to light up a line.

To do

The method, for each module:

  1. Say in one line what the module is for, from its section of docs/architecture.md and from what a user sees of it.
  2. List its inputs, its outcomes, its error codes and every conditional branch, the ones the screen cannot reach included.
  3. Write the tests from that list without opening the old ones: for each rule a passing case and a failing case, the edges of each bound (empty, one, at the limit, past it), and the order of effects where it matters.
  4. Read the old tests afterwards: keep, in the new form, what one holds that the list missed (above all a defect once met); delete the rest, and say in the pull request which and why.
  5. Read the coverage report (cargo llvm-cov, as CI does) as a map, not a target: a branch left uncovered is tested, or is dead code and deleted, or is said to be unreachable.

The shape of a test:

  • One behaviour per test; its name states the case and its outcome; arrange, act, assert.
  • A test says what the element yields or refuses, never how it gets there: no assertion on a private helper, an internal structure or an order of calls that is not itself the rule. When no behaviour can be named in one sentence there is no test to write: the line it would have reached is either reached by a behaviour that matters, or it is dead and deleted.
  • Variants of one rule go in a table, not in copies. A test goes through the module's public function, not its private helpers.
  • State is tested against the real core on a temporary library; only the platform is faked, and no fake reimplements a core rule (→ "Testing").
  • A test that holds a rule of the project and not a function stays, rewritten if its form asks for it: the sweeps (no colour, gap, radius, text-size or duration literal outside theme::tokens), the contrast ≥ 4.5:1, the identity lists held whole. Each lot says which it kept.
  • Tests only. A defect met on the way is not fixed inside a rewrite: the failing test is the proof, and it goes to its own ticket (bug). Cryptography, key derivation and file formats are never touched (.claude/rules/security.md).

Every crate of the workspace that ships is in scope; the e2e driver (#1715), the benches and the website are not. The lots, each its own branch and pull request into dev/1.3.1, small enough to be read in one sitting, never mixing two areas, each deleting as many old tests as it replaces:

  • engine, by feature: notes (model, placeholder, markdown, calc, view, index, revisions, trash); folders and spaces; tags and bulk actions; attachments; import and export (transfer); the vault, libraries, backups, recovery and durable files; HTTP (variables, sending, cookie jar, history, scripts, runner, import, code generation); the tools, one lot per category and the identity lists apart; db and the migrations.
  • text, richtext, drawing, i18n, platform, app.
  • ui, by the shape of the screen: state/, services/, api/ and backend; notes/; http/; tools/; titlebar, banners, gate, palette; widgets/, theme/, keys.

Each pull request gives, for its lot, the number of tests before and after, the branches it found without a test, and the tests it kept from the old ones for a reason. When the last lot has merged, the ticket reports the same numbers per crate, the time of cargo test --workspace --exclude e2e, and the coverage of each crate before and after.

Tests

  • This ticket is about tests: on every pull request cargo test --workspace --exclude e2e, cargo clippy --workspace --all-targets --all-features -- -D warnings and cargo fmt --all --check are green, and no crate's coverage falls.
  • A check that a rewritten module means something: for a few modules of each lot, break one condition of the production code and see a test name the rule that broke; put it back. Said in the pull request.
  • No e2e scenario changes with this ticket.

Activity

  1. added
    test
    on Dec 1, 2026
  2. vmillet-dev commented on Dec 3, 2026

    @vmillet-dev
    OwnerAuthor

    Every lot is merged into dev/1.3.1, the last two being #1849 (notes) and #1850 (HTTP).

    Crate Tests before Tests after Coverage before Coverage after
    engine 1,668 2,022 97.51 % 98.69 %
    ui 1,028 1,553 92.19 % 96.66 %
    richtext 44 178 91.38 % 98.49 %
    drawing 91 156 99.54 % 99.81 %
    text 48 102 95.69 % 97.67 %
    platform 33 51 61.30 % 70.78 %
    i18n 23 44 97.83 % 98.88 %
    app 24 26 74.29 % 75.23 %
    All 2,959 4,132 94.11 % 97.32 %

    On Windows, the ignored tests left out (6 of them, before and after). Two of the 2,959 failed on a machine set to French; every one of the 4,132 passes.

    cargo test --workspace --exclude e2e, built and with nothing else running: 1 min 30 before, 1 min 41 to 1 min 50 after (one run of four took 2 min 17), for 40 % more tests.

    Thirty-two defects were met on the way, each with its own ticket and its own fix. What stays uncovered in platform and app is what is asked of the system: the tray, the notifications, the window's start.

  3. vmillet-dev commented on Dec 3, 2026

    @vmillet-dev
    OwnerAuthor

    A last pass on ui/state broke a sample of its conditions one by one: of 145, 79 were named by a test, 27 were not, 33 were cut without an answer and 6 unfinished. The ones that hold a behaviour now have their test, in #1857 (20 tests, 4,145 in all). The files of ui/state after http/runner, in order, were not measured. The ticket closes with that pull request.

  4. vmillet-dev commented on Dec 3, 2026

    @vmillet-dev
    OwnerAuthor

    The last tests (#1857) and the fix of a test that failed by chance (#1859) are in dev/1.3.1. #1858 brings the branch into main and closes this ticket.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    test

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions