Skip to content

mdl: round-trip tests miss writer bugs #851

Closed

Description

@bpowers

The MDL round-trip tests could pass while the writer was wrong.
They compared too little of the model after a save and re-read, covered few of the corpus files, and never simulated the result, so several writer bugs shipped unnoticed (a | in documentation corrupting the next equations; 29 of 240 corpus files whose saved MDL would not re-open).

Gaps

  • (a) The equivalence check ignored variable type, units, documentation, graphical functions, and every per-element equation (all compared as the string "<arrayed>"), so a wrong dimension recovered for SUM(a[*]) would pass.
  • (b) Only 60 of 262 .mdl fixtures were in the corpus, with stale exclusions (xidz_zidz.mdl, test_lookups.mdl, test_lookups_inline.mdl round-trip fine).
  • (c) No test that every corpus file's saved MDL re-opens.
  • (d) No property test generating models and saving them.
  • (e) No check that the re-read model simulates the same.
  • (f) Checking the writer's output in Vensim itself is a manual, ignored test; that stays manual without a Vensim license.

Where each stands

  • (a) save_roundtrip_tests.rs: every corpus file, read, saved and read again, must equal the original model (views and equation spelling aside); its allowlist is empty.
  • (b), (c) mdl_roundtrip.rs: the three files are in the corpus, and corpus_reparse_ratchet covers every file.
  • (d) writer_proptest.rs: first_save_is_a_fixed_point over generated models with arrays, subranges, stocks, flows and lookups.
  • (e) tests/integration/save_meaning.rs: every corpus model saved in each format, simulated, and compared with the original.

Pointers

  • src/simlin-engine/src/mdl/save_roundtrip_tests.rs
  • src/simlin-engine/tests/integration/mdl_roundtrip.rs
  • src/simlin-engine/tests/integration/save_meaning.rs

Activity

  1. bpowers commented on Jul 7, 2026

    @bpowers
    OwnerAuthor

    Concrete motivation for gap (a) from the just-landed wildcard/bang subscript recovery (branch mdl-writer-hardening):

    The writer now recovers SUM(a[*]) -> SUM(a[Dim!]) by looking up variable a's declared dimension at the wildcard's position (WriterContext::dim_at, src/simlin-engine/src/mdl/writer.rs:252, used at writer.rs:737 for IndexExpr0::Wildcard). All three roundtrip gates are blind to a MIS-recovery of that dimension:

    • the corpus ratchets (tests/integration/mdl_roundtrip.rs) only check re-parse success and text idempotence;
    • the curated semantic check compares Equation::Arrayed(_, _, _, _) opaquely (the <arrayed> collapse noted in gap (a)), and ApplyToAll reductions are not semantically compared either.

    So a future change that recovers the WRONG declared dimension for a wildcard position would pass every gate. This makes gap (a) concretely load-bearing for the freshly-landed recovery path: at least one array fixture whose ApplyToAll/reduction equation TEXT is semantically compared across MDL->MDL roundtrip (not <arrayed>) is needed to guard dim_at.

    Discovered while hardening the MDL writer, 2026-07-06.

  2. changed the title [-]engine: MDL roundtrip harness coverage gaps let confirmed writer bugs ship undetected[/-] [+]mdl: round-trip tests miss writer bugs[/+] on Oct 12, 2026
  3. added
    engine
    hygiene
    on Oct 12, 2026
  4. bpowers commented on Oct 12, 2026

    @bpowers
    OwnerAuthor

    Closing: already fixed on main.

    All five gaps are covered after PR #1076 (f629e96): (a) mdl/save_roundtrip_tests.rs compares the full datamodel after read-save-read over every corpus .mdl with an empty EXPECTED list (:184); (b)/(c) tests/integration/mdl_roundtrip.rs lists xidz_zidz/lookups/lookups_inline (:36-39) and corpus_reparse_ratchet (:1896) has an empty allowlist; (d) mdl/writer_proptest.rs first_save_is_a_fixed_point (:813); (e) tests/integration/save_meaning.rs simulates every corpus save in every format pair against a ratcheted table.

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

    enginehygiene

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions