Repository navigation
Issue #1063: test: round-trip the shipped seed through the portable format - #1497
Merged
Merged
Conversation
…ormat Exports every seed model, mapping group and crosswalk the converter accepts, imports it into two empty installs with different row Ids, and asserts A == B == C byte for byte (Portability Spec §3, guarantee 5). Today models 4, 10 and 13 round-trip; groups and crosswalks join once model 1 exports. Fixes the model 10 (CTDL) failure the test found: import marked an entity Array=Yes from a list reference, so an entity with no containing parent came back with its own Array. References no longer set it (#1471). The MDR database fixtures now fail instead of skipping when CI is set and PostgreSQL can't start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bjagg
approved these changes
Nov 9, 2026
bjagg
left a comment
Contributor
There was a problem hiding this comment.
Thanks, Gary. I checked it at dc97c73:
- It proves the guarantee for what it covers. It compares
dump_canonicaloutput, the same bytes the export endpoint returns, byte for byte, A against B and A against C. Model Ids really differ:{4, 10, 13}in the seed,{1, 2, 3}in the first install and{1001, 1002, 1003}in the second. It runs in about 6 s. - It catches import losses. Making import drop element
Descriptionor associationNotesfails it. Reverting yourmodel_converter.pyfix fails both it and the new unit test. - Fail-in-CI, skip-locally works for
test/bases/lif/mdr_restapi/. With no Postgres andCIunset: 84 passed, 296 skipped. WithCI=true: 295 errors instead of skips.
Notes, none blocking:
- Coverage is narrower than "the seed" suggests. Today only models 4 (CEDS) and 10 (CTDL) carry content; 13 is 267 bytes with no elements. No mapping group or crosswalk round-trips, because each one has a model that's refused.
_try(:80-85) drops any refused file, and the only floor,EXPORTING_MODELS, covers models. Once groups start exporting after #1388, a converter regression that makes them refuse would leave this passing with 0 groups. A floor on group and crosswalk counts, raised as they come in, would close that. - A round trip can't see a field export drops. Dropping entity
Descriptionfrom export still passes, because file A never had it. The same goes for fields the seed leaves empty in models 4 and 10, such asActivationDate,TagsandExample.test_model_converter.py's synthetic round trip covers those, so it's a limit of this test rather than a gap in the suite. It may be worth one line in the docstring. - Conflict with #1498. #1498 deletes the whole "any association" merge in
_import_elementsthat this PR narrows, so the two will conflict, and with #1498 in, your fix is moot. Whichever lands second should take #1498's version and rerun this test. It's the round trip that would catch a mistake there. - Other suites still skip in CI:
control_plane_restapi/test_api_key_endpoints.py,developer_keys/test_workspace_store.py,test_schema_drift_service.pyand fourtest/scripts/files. The description scopes the change correctly; this is a possible follow-up. - Minor: on a Mac where Homebrew links
initdbinto/opt/homebrew/bin, the tests run without the PATH entry, so "they skip" isn't true on every Mac.
Approving.
Merged
12 tasks done
dereck-symmetry
pushed a commit
that referenced
this pull request
Nov 10, 2026
dereck-symmetry
pushed a commit
that referenced
this pull request
Nov 10, 2026
…ter branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 tasks done
bjagg
pushed a commit
that referenced
this pull request
Nov 11, 2026
…tained models (#1489) ##### Description of Change Adds the one-time conversion of the overlay models 17 (StateU LIF) and 18 (Org2 LIF) into self-contained models, in place, as decided on #1388 (ADR `data_model/0004`). Merging changes nothing at runtime: the new module is imported only by the script, and running the script is a manual step on each environment. **`components/lif/mdr_services/overlay_converter.py`**, per overlay: - **Step 0:** attributes stored with an overlay's model but associated directly from a base entity move to the base model (cbeach47's §11 line). Ids are unchanged. In the seed: 8 of model 17's attributes move to model 1. It refuses two candidates that would give the base one `UniqueName` twice. - **Steps 1–4:** the overlay's schema decides what it shows. Every foreign element it shows is copied into it, with the inclusion row's flags, along with any value set a shown attribute uses from another model. - **Step 5:** associations are rewritten or copied between the model's own rows, and every `ExtendedBy` row the overlay declares is soft-deleted. That includes the 69 inside model 16 and the ownerless 1846. - **Step 6:** own elements the schema doesn't show are soft-deleted. - **Step 7:** `BaseDataModelId` is cleared, `CopiedFrom*` is set to the base model, and the inclusion rows are deleted. - **Step 8:** every live mapping row on the model's side is re-pointed through the Id map. **It checks itself before anything commits.** Every model it touches (1, 16, 17 and 18) must generate the same schema in all 16 flag combinations, once Ids are mapped, and 17, 18 and their mapping groups must export. `required` is compared as a set, since own elements keep their Ids and the copies get new ones (option 2 on #1388). Any failure raises `ConversionFailed`, and the caller rolls back. **It refuses what the comparison can't see** (`outside_references`). After every step, a live row of a model it doesn't compare that still uses an entity or attribute it soft-deleted or changed in place fails the run: an association at either end, a `TargetEntityId`, or an inclusion row. So does a soft-deleted association of such a model, and any live mapping row, on any side, that still goes through a soft-deleted element. A row belongs to its `ExtendedByDataModelId`, or with none to its parent entity's model. **`scripts/convert_overlays.py`** runs it in `public` and then every `tenant_*` schema, each in its own transaction: - It refuses to start while `remove_test_data.py`'s rows are still live (#1479, #1487). - It skips a schema that's already converted, so a re-run converts only what's left. - It locks the 11 tables the conversion reads or writes, in `EXCLUSIVE` mode with a 10s `lock_timeout`. Reads go on and writes wait, so an MDR edit can't commit mid-run and be lost. - It writes each schema's undo record to `--undo-dir` (on a dry run too): the Id map, every row inserted or soft-deleted, and the old value of every column updated in place. - It rolls back unless `--apply`. A schema that fails its check, can't get its locks, or hits any other error is rolled back and reported, and the other schemas still run. - The undo record says `committed: false` until the commit succeeds, so a failed commit leaves a record that says so. **Docs:** four *Migration defaults* lines in spec §11 (step 0, a value set used from another model, the `ExtendedBy` rows inside other models, and 1846), a `scripts/README.md` row, and a CHANGELOG entry. **Not in this PR: `reference_data/transformations/`.** I measured it rather than regenerating it (details on #1388). The paths are names, and 105 rules in the three top-level files go through model 1 elements that 17's schema doesn't show, so they can't resolve after the conversion. Regenerating the numeric Ids from a seed run would give Ids that are wrong on dev. bjagg checked dev read-only, in all 10 schemas: none of its live mapping rows fail step 8, so the 105 rules are only in the reference files. **A follow-up PR re-exports the files from dev after dev is converted, and lists the rules that drop out** (agreed on #1388). ##### Before `--apply` on dev The MDR API image must include this PR first. Its workflow's `paths:` already cover `components/lif/mdr_services/**`. 1. Run `remove_test_data.py --apply`, including #1487's rows. 2. Take an RDS snapshot. A committed run has no automatic undo: the undo record lists every change, but reversing it is manual. 3. Run the dry run and read its output for every schema. bjagg's read-only check on 11-09 found no live row that step 8 would refuse, and no row outside 17/18 that uses what 17 soft-deletes. 4. Announce an MDR edit freeze. Writes wait on the locks, and a request can time out while they do. 5. Run `--apply`, then copy the undo directory out of the container before it stops. ##### Related Issues Refs #1388 ##### Type of Change - [x] New feature (non-breaking change which adds functionality) ##### Project Area(s) Affected - [x] components/ - [x] scripts/ - [x] test/ or e2e/ - [x] Documentation (docs/, READMEs, ARCHITECTURE.md, CLAUDE.md) `mdr_services` is packaged only by `lif_mdr_api`. ##### Testing 35 tests, all against a real Postgres. The DB-backed ones skip without `initdb`, so locally I ran them in a container with Postgres. - **On the seed after #1444's and #1479's cleanups:** - the whole seed converts and passes every check, leaving no inclusion rows on 17 or 18. Its figures are pinned: each model's copy counts, 17's soft-deleted entities and attributes by Id, every soft-delete count, and the 5 re-pointed mapping rows (group 25's 4 on step 0's attributes, group 26's 1); - step 0 moves exactly the 8 attributes; - step 0 refuses an attribute whose name the base already has, or that has another association; - it refuses an overlay with inclusion rows but no base (#1445); - it refuses a mapping row whose path goes through a row the schema hides; - it refuses when another model still uses a row it soft-deletes (bjagg's probe: a model-2 association to attribute 1820), and when a mapping row on another side goes through one; - step 0 refuses two candidates with one `UniqueName`; - the self-check fails a conversion whose copies lose a column (`Description` on attributes, `Relationship` on entity associations). - **Pure parts (16):** - the render set; - the schema rewrite, which changes only Ids, `DataModelId`, `ExtendedBy` and `Extension`; - mapping paths; - `required` order ignored, while a changed `required` and a changed `enum` order are still caught. - **Runner (8):** - it refuses before the cleanup; - it skips a converted schema; - a dry run converts, writes its undo record with `committed: false`, and changes no row in the 9 tables it writes; - `--apply` commits and a re-run skips; - it doesn't start while another transaction holds a write; - any other error rolls that schema back and is reported; - a failed commit leaves the undo record at `committed: false`; - a `tenant_*` schema converts its own rows and leaves `public` unchanged. Mutation checks: no `required` sorting, sorting every list, no commit on `--apply`, the undo record always marked `committed`, and no table lock. Each one is caught by exactly the test it should be. Full suite, Postgres-backed tests included: 1864 passed, 1 skipped (the snapshot regenerator, which runs only with `LIF_UPDATE_SCHEMA_SNAPSHOTS=1`). That run was on `e9e4e58`. After the lock fix, the merge of `main` (#1487) and the pins, I re-ran the converter's, the runner's and `remove_test_data`'s tests on `92adef4`: 38 passed, 0 skipped. After bjagg's review and a merge of `main` (#1464, #1496), on `af9f658`: the converter's and the runner's 35 pass, 0 skipped. After a further merge of `main` (#1488), the full suite with Postgres on `3abc49c`: 1893 passed, 1 skipped (the snapshot regenerator). After a merge of `main` (#1501, #1498, #1497) on `99e7079`: the converter's and the runner's 35 pass against Postgres, 0 skipped (#1498 changed the generator the self-check uses), and the full suite with Postgres: 1909 passed, 1 skipped (the snapshot regenerator). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: dereck <dereck.haskins@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From Claude:
Description of Change
#1063 now covers the portable format's done-test (bjagg's re-scope). Export the shipped models, mapping groups and crosswalks, import them into an empty install with different row Ids, export again, and compare byte for byte (
docs/specs/mdr-portable-file-format.md§3, guarantee 5). Per the plan's note on this issue, the test fails rather than skips when CI has no database.1. Seed round trip:
test/bases/lif/mdr_restapi/test_portable_seed_round_trip.pybackup.sqlthat the converter exports, then every mapping group and crosswalk whose two models are both among them.clone_lif_schema(..., false), and the second one's sequences start at 1000.A == B == Cbyte for byte, file by file. The model Ids are disjoint across the three:{4, 10, 13}, then{1, 2, 3}, then{1001, 1002, 1003}.{4, 10, 13}must still export, so losing one fails the test.NOT_MIGRATED. Content is discovered rather than listed, so groups and crosswalks join the round trip on their own once model 1 exports (MDR portability: convert models 17 and 18 from overlays to self-contained models, in place #1388/MDR portability: measure and clean data that blocks export, in every schema #1393).2. A converter bug the test found:
components/lif/mdr_services/model_converter.pyModel 10 (CTDL) didn't round-trip. 45 entities that are only children of list references came back with
"Array": true. The cause:Arrayfrom any association that places it in a list, references included.Array.The generator emits a reference as a single object whatever its child's
Array(spec §11, #1471). Setting it from a reference therefore did nothing for the reference, and it made the entity's top-level schema a list. Import now skips references there; containing associations and root entities behave as before.A new test,
test_a_list_reference_leaves_its_child_entity_list_setting_alone, failed before the fix. It belongs in this PR because the round trip can't pass without it.3. Fail, don't skip, in CI
The
testing.postgresqlfixtures now callpytest.failwhenCIis set and PostgreSQL can't start. They still skip locally. That coversconftest.pyand the two copies intest/scripts/.pr-ci.ymlhas no Postgres service; the runner image just happens to ship it.test_postgres_unavailable.pycovers both branches.How to review / test
PATH="/opt/homebrew/opt/postgresql@16/bin:$PATH" uv run pytest \ test/bases/lif/mdr_restapi/test_portable_seed_round_trip.py \ test/bases/lif/mdr_restapi/test_model_converter.py \ test/bases/lif/mdr_restapi/test_postgres_unavailable.py -rsWithout the PATH entry on macOS, the database tests skip locally.
Related Issues
Closes #1063
Refs #1223
Type of Change
Project Area(s) Affected
Checklist
uv run ruff check)uv run ruff format)uv run ty check)Testing
Automated tests added/updated
test/bases/lif/mdr_restapi/+test/scripts, with Postgres running: 481 passed. The one skip is the existingLIF_UPDATE_SCHEMA_SNAPSHOTSswitch.pre-commit on the changed files, including the full
pytest testhook: passed.Checks that the test fails when it should: it caught the CTDL difference before the fix, and adding model 1 to the floor makes it fail with
seed models that no longer export: {1}.Not checked end to end: the CI gate with Postgres absent.
testing.postgresqlfinds the Homebrew install even offPATH, so the unit tests, which make the server start fail, are the evidence.Additional Notes
mdr_servicesis packaged only bylif_mdr_api..github/workflows/lif_mdr_api.ymlwatchescomponents/lif/mdr_services/**.Array = "No", where it used to be"Yes". Models already imported keep their rows.has/relevantrelationship cases andskipped_constraintsin the upload response. The re-scope drops them, because the converter doesn't use that path.🤖 Generated with Claude Code