Skip to content

🧪 test_fields: assert structure, not repr - #7453

Closed
GeigerJ2 wants to merge 1 commit into
aiidateam:mainfrom
GeigerJ2:test/fields-structured-assertions
Closed

🧪 test_fields: assert structure, not repr#7453
GeigerJ2 wants to merge 1 commit into
aiidateam:mainfrom
GeigerJ2:test/fields-structured-assertions

Conversation

@GeigerJ2

@GeigerJ2 GeigerJ2 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Possible follow-up to #7448.

#7448 re-enabled the node field fixtures, which a filter had been silently excluding from test_all_node_fields, and regenerated the eight files it had orphaned. Doing that showed they had drifted, and that __repr__ lost some field information along the way: is_attribute is no longer in it, and it prints backend_key where __init__ takes key, so QbStrField('exception', is_attribute=True) and QbStrField('attributes.exception', is_attribute=False) come out identical. Pinning repr() of typing constructs is also what forced the skipif < 3.14 guard.

The field regression tests compared `repr()` of each `QbField` against a
YAML reference file, which pinned the formatting of `__repr__` rather
than the field schema.

`__repr__` renders `backend_key`, which folds `is_attribute` into an
`attributes.` prefix, so the flag was never recorded and the encoding is
not injective: a field with key `exception` and `is_attribute=True` and
one with key `attributes.exception` and `is_attribute=False` render
identically. The reference files could not tell them apart.

It was also version-sensitive, since `repr()` of `typing` constructs is
not stable across releases, which is what forced the `skipif < 3.14`
guard. And it tied the files to a presentation detail: changing
`__repr__` rewrites all 46 references, which discourages fixing it.

Build the description in the test instead. The field key is dropped from
it, being the mapping key already, and `backend_key`, `is_attribute` and
`root` are emitted only where they carry information, which keeps the
files roughly the size they were:

    levelname: QbStrField(dtype=str, doc='The name of the log level')
    exception: QbStrField(backend_key=attributes.exception,
    is_attribute=True, dtype=str | None, root=str, doc='...')

`backend_key` differs from the key exactly when `is_attribute` is set,
since a non-attribute field may not be aliased, so both appear together
or not at all.

Dtypes go through `format_dtype`, stable across 3.10-3.14 by
construction rather than by whatever `typing` does this release. Its
`get_origin` guard is load-bearing: `isinstance(dict[str, Any], type)`
is `True` on 3.10 alone, which would render a bare `dict` there and
`dict[str, Any]` from 3.11 on.

`root` pins `extract_root_type`, previously covered only through the
`QbField` subclass it selects. Breaking its union branch now reports
`root=int -> root=Union` beside the class change rather than leaving the
cause to be inferred.

Regenerate all 46 reference files. The diff is large but mechanical: no
field changed, only how it is described.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f1e38a07-3ed1-45b5-ba02-9dfb8197d98d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.60%. Comparing base (1c8bfde) to head (3feefdd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7453      +/-   ##
==========================================
- Coverage   80.61%   80.60%   -0.01%     
==========================================
  Files         580      580              
  Lines       46722    46722              
==========================================
- Hits        37662    37657       -5     
- Misses       9060     9065       +5     

☔ 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.

@GeigerJ2

Copy link
Copy Markdown
Collaborator Author

Closing this for now, in favor of work on #7461.

@GeigerJ2 GeigerJ2 closed this Jul 17, 2026
@edan-bainglass

Copy link
Copy Markdown
Member

@GeigerJ2 #7461 does not address this part. Let's discuss 🙏

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.

2 participants