chore(models): regenerate against schema 0.2.0 + close the drift - #7
Open
tbsvttr wants to merge 1 commit into
Open
chore(models): regenerate against schema 0.2.0 + close the drift#7tbsvttr wants to merge 1 commit into
tbsvttr wants to merge 1 commit into
Conversation
Regenerated models.py from the current core distribution schema (v0.2.0) — the same shape content repos ship on main. The bundled copy has been on the 0.1.0 line since the port; every end-to-end validation test was xfailed against `datasworn_version` mismatches and downstream shape drift. The regen surfaced a fifth codegen misbehavior (leading-underscore JSON keys like `_id`, `_source`, `_comment` renamed to `field_id` etc. by datamodel-code-generator to avoid colliding with pydantic's private namespace). Added a fifth post-processor pass to rename them back to the natural attr name while keeping `Field(alias='_X')` intact, so `.id` reads naturally without breaking JSON validation. Also handled the compact single-line RootModel[str] shape that codegen emits for description-only fields (CssColor). Post-processor now applies: - 3 date-field pattern strips - 82 RootModel[str] -> TypeAlias rewrites (multiline + compact) - 5 discriminated-union bases resolved - 126 field_X -> X attribute renames - 3 Features/Dangers/Denizens stub sites rewritten Test results after regen: 10 passed, 2 xfailed. All 5 official rulesets validate cleanly; community `ancient_wonders` and `fe_runners` also green. Only `ironsmith` and `starsmith` xfail, and those are legitimate content-quality bugs in community-content (option `[key]` values with spaces — don't match the DictKey pattern `^[a-z][a-z0-9_]*$`). Renamed the xfail group to make it clear those are bugs to file upstream, not drift. README updates: replaced the "known drift" warning with an accurate schema-line status, swapped the regen command to fetch the distribution schema (`datasworn.schema.json`) rather than the source schema, and documented that a green test run now confirms the regen worked.
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.
Stacked on #6.
Closes the drift Scott flagged in the initial review.
models.pyhere has been on schema line 0.1.0 since the port; content repos ship 0.2.0. Every end-to-end validation test wasxfailed againstdatasworn_versionmismatches and downstream shape drift. This PR proves out the "regenerate + post-process" workflow: fetch the current distribution schema, run datamodel-code-generator, runscripts/post_process_models.py, and everything lines up.What's in here
models.pyagainsthttps://raw.githubusercontent.com/datasworn-community/datasworn/main/packages/core/json/datasworn.schema.json(v0.2.0)._id,_source,_comment, …) get renamed tofield_idetc. by datamodel-code-generator to avoid colliding with pydantic's private namespace. Added a pass that renames them back to the natural attr name (dropping thefield_prefix) while keepingField(alias='_X')intact — so.idreads naturally without breaking JSON validation. 126 attrs renamed.RootModel[str]shape. Codegen emits a compact one-line form for description-only fields (e.g.CssColor); the multiline regex missed those. Added an inline variant.test_community_known_content_bugswith a clear reason — those failures are option[key]values with spaces ("area of expertise","define the dark power in you","true name") that don't match theDictKeypattern^[a-z][a-z0-9_]*$. Content-quality bugs to file againstdatasworn-community/community-content, not drift.test_root_model_str_wrappers_goneto inspect the source (re.findall(r\"^class \\w+\\(RootModel\\[str\\]\\):\", source)) instead of runtime shape. Runtime check tripped onConditionMeterKey(RootModel[DictKey])becauseDictKeypost-processes toAnnotated[str, …]and pydantic collapses it to `str`. Source-level check matches what the post-processor actually operates on..gitignore: addedtests/.cache/.Post-processor stats after regen
RootModel[str]→TypeAliasrewrites (multiline + compact)field_X→Xattribute renamesFeatures/Dangers/Denizensstub sites rewrittenTest results
```
tests/test_load_rules_packages.py .......xx [ 75%]
tests/test_type_alias_ergonomics.py ... [100%]
======================== 10 passed, 2 xfailed in 0.46s =========================
```
Test plan
models.pycleanly from schema 0.2.0uv run pytest tests/green: 10 passed, 2 xfailed, no failures