Skip to content

chore(models): regenerate against schema 0.2.0 + close the drift - #7

Open
tbsvttr wants to merge 1 commit into
refactor/core-onlyfrom
chore/regen-models-schema-0.2.0
Open

chore(models): regenerate against schema 0.2.0 + close the drift#7
tbsvttr wants to merge 1 commit into
refactor/core-onlyfrom
chore/regen-models-schema-0.2.0

Conversation

@tbsvttr

@tbsvttr tbsvttr commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #6.

Closes the drift Scott flagged in the initial review. models.py here has been on schema line 0.1.0 since the port; content repos ship 0.2.0. Every end-to-end validation test was xfailed against datasworn_version mismatches and downstream shape drift. This PR proves out the "regenerate + post-process" workflow: fetch the current distribution schema, run datamodel-code-generator, run scripts/post_process_models.py, and everything lines up.

What's in here

  • Regenerated models.py against https://raw.githubusercontent.com/datasworn-community/datasworn/main/packages/core/json/datasworn.schema.json (v0.2.0).
  • New post-processor pass feat(models): convert RootModel[str] wrappers to TypeAlias + resolve discriminated-union bases #5: leading-underscore JSON keys (_id, _source, _comment, …) get renamed to field_id etc. 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 the field_ prefix) while keeping Field(alias='_X') intact — so .id reads naturally without breaking JSON validation. 126 attrs renamed.
  • Handle the compact single-line 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.
  • Updated post-processor docstring to describe all five bugs it handles (previously said "two").
  • Renamed the ironsmith/starsmith xfail group to test_community_known_content_bugs with 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 the DictKey pattern ^[a-z][a-z0-9_]*$. Content-quality bugs to file against datasworn-community/community-content, not drift.
  • Rewrote test_root_model_str_wrappers_gone to inspect the source (re.findall(r\"^class \\w+\\(RootModel\\[str\\]\\):\", source)) instead of runtime shape. Runtime check tripped on ConditionMeterKey(RootModel[DictKey]) because DictKey post-processes to Annotated[str, …] and pydantic collapses it to `str`. Source-level check matches what the post-processor actually operates on.
  • README refresh: replaced the "known drift ⚠️" warning with a schema-line status, swapped the regen command to fetch the distribution schema (not the source schema), and updated step 3 to reflect that a green test run now confirms the regen.
  • .gitignore: added tests/.cache/.

Post-processor stats after regen

  • 3 date-field pattern strips
  • 82 RootModel[str]TypeAlias rewrites (multiline + compact)
  • 5 discriminated-union bases resolved
  • 126 field_XX attribute renames
  • 3 Features/Dangers/Denizens stub sites rewritten

Test results

```
tests/test_load_rules_packages.py .......xx [ 75%]
tests/test_type_alias_ergonomics.py ... [100%]

======================== 10 passed, 2 xfailed in 0.46s =========================
```

  • ✅ classic, delve, lodestar, starforged, sundered_isles
  • ✅ ancient_wonders, fe_runners
  • ❎ ironsmith, starsmith — xfail on content-quality bugs (not drift)
  • ✅ all 3 ergonomics tests

Test plan

  • Regenerate models.py cleanly from schema 0.2.0
  • Post-processor idempotent on second run (re-run reports "no changes")
  • uv run pytest tests/ green: 10 passed, 2 xfailed, no failures
  • CI green on this branch
  • Follow-up: file content-quality bugs against community-content for ironsmith + starsmith

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.
@tbsvttr tbsvttr self-assigned this Jul 16, 2026
@tbsvttr
tbsvttr requested a review from scottbenton July 16, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant