Skip to content

✅ test(spec): the Fields tables must name fields that exist - #768

Merged
nstarman merged 1 commit into
GalacticDynamics:mainfrom
nstarman:claude/spec-fields-conformance
Aug 20, 2026
Merged

nstarman merged 1 commit into
GalacticDynamics:mainfrom
nstarman:claude/spec-fields-conformance

Conversation

@nstarman

Copy link
Copy Markdown
Contributor

The follow-up I flagged on #762. Three spec sections have now been found describing fields
the class does not have — Scale (#750), Shear (#762), and Tangent below — every one
by accident rather than by looking. This closes the class.

Every !!! info section with a Fields block is now checked against
dataclasses.fields. Ten sections qualify, out of 140.

It found a fifth stale entry immediately

Tangent documented a manifold field that has never existed
dataclasses.fields(Tangent) is (data, chart, basis, semantic, frame). The manifold is
reached through M, a property derived from the chart.

The same section's "Post-init checks" were wrong in two more ways: there is no
__post_init__ on Tangent at all, and the check it names does not exist either.

def __check_init__(self) -> None:          # not __post_init__
    self.M.check_chart(self.chart)         # not manifold.has_chart(chart)
    self.chart.check_data(self.data, keys=True)

Corrected, including the note that M is derived rather than stored — which is exactly
the fact the phantom row obscured.

Two deliberate limits

Sets, not sequences. Translate looked like a second defect: the spec orders its
fields (delta, chart, semantic_kind, right_add) while dataclasses.fields gives
(delta, chart, right_add, semantic_kind). It has a custom __init__, and the spec
matches the constructor — the order a reader would actually use. Enforcing
dataclasses.fields order would have failed a section that is right, so only membership
is checked.

Per-type sections only. The exported-objects table earlier in the spec is a curated
summary — the coordinax.charts row omits 50-odd class names on purpose — so it is not an
__all__ mirror and is deliberately untouched. (I nearly built that check during #730
before noticing.)

The test can actually fail

Verified in both directions rather than assumed:

spec claims a field the class lacks  -> Tangent: spec documents field(s) the class
                                        does not have: ['manifold']
class has a field the spec omits     -> Linear: spec documents field(s) the class
                                        does not have: ['grup']

Both spellings of a Fields block are parsed — bullet list and markdown table, both in use
— and a guard test asserts the parser still finds at least eight sections, since a regex
that quietly stops matching would pass forever and prove nothing.

tests/unit + docs: 3868 passed, 5 skipped.

Three spec sections have now been found describing fields the class does not
have -- `Scale` (GalacticDynamics#750), `Shear` (GalacticDynamics#762), and `Tangent` here -- each by accident
rather than by looking. This closes the class: every `!!! info` section with a
**Fields** block is checked against `dataclasses.fields`.

`Tangent` was the fifth stale entry. It listed a `manifold` field that has never
existed; the manifold is reached through `M`, a property derived from the chart.
Its "Post-init checks" were wrong too -- the hook is `__check_init__`, and it
calls `M.check_chart(chart)`, not `manifold.has_chart(chart)`.

Two deliberate limits:

Sets, not sequences. `Translate` defines its own `__init__` whose parameter
order is the useful one to document and differs from `dataclasses.fields`;
enforcing order would fail a section that is right.

Per-type sections only. The exported-objects table is a curated summary -- the
`coordinax.charts` row omits 50-odd class names on purpose -- so it is not an
`__all__` mirror and is left alone.

Both spellings of a Fields block are parsed, bullet list and table, and a guard
test asserts the parser still finds sections: a regex that quietly matches
nothing would pass forever.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 20, 2026 02:56
@github-actions github-actions Bot added 📝 Add / update documentation Add or update documentation. ✅ Add / update / pass tests Add, update, or pass tests. labels Aug 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a regression test to keep docs/spec.md’s per-type Fields blocks in sync with actual dataclass fields, preventing spec drift in documented public APIs. Updates the Tangent spec section to remove a non-existent manifold field and to describe the correct init-time validation behavior (M derived from the chart; checks performed in __check_init__).

Changes:

  • Introduce a unit test that parses docs/spec.md !!! info sections with Fields blocks and asserts set equality with dataclasses.fields(...).
  • Fix the Tangent spec section by removing the phantom manifold field and correcting the init-checks description.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/unit/test_spec_fields_match_code.py New test that enforces Fields blocks in the spec match real dataclass fields (membership, not order).
docs/spec.md Correct Tangent documentation: remove non-field manifold, clarify M is derived, and fix init-checks text.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.66%. Comparing base (ff1167a) to head (924f9e1).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #768      +/-   ##
==========================================
+ Coverage   96.57%   96.66%   +0.08%     
==========================================
  Files         267      267              
  Lines        8963     9079     +116     
==========================================
+ Hits         8656     8776     +120     
+ Misses        307      303       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nstarman nstarman added this to the v0.24.0 milestone Aug 20, 2026
@nstarman
nstarman merged commit d7a8c69 into GalacticDynamics:main Aug 20, 2026
16 checks passed
@nstarman
nstarman deleted the claude/spec-fields-conformance branch August 20, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📝 Add / update documentation Add or update documentation. ✅ Add / update / pass tests Add, update, or pass tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants