Reviewing and refining generator and testing code - #327
Conversation
…minator enum helpers, shared _check, cross-reference comments
There was a problem hiding this comment.
Pull request overview
This PR is an internal cleanup/refactor across the generators and test suite. It centralizes a duplicated _check(condition, msg) helper into tests/test_utils.py, factors the field-order discriminator enum generation into shared helpers in src/struct_frame/base.py (consumed by C/C#/JS/Python/TypeScript generators), corrects a copy-paste bug where leading message comments were assigned instead of accumulated (result = ... → result += ...) in C/JS/TS/Python generators, tightens C/C++ round-trip test gating in tests/run_tests.py to require an explicit successful compilation result, and adds twin-maintenance notes plus a small simplification to the JS/TS GenericFrameParser.getInitialState().
Changes:
- Centralize
_checkintotests/test_utils.pyand replace duplicated copies in 7 test files. - Introduce
get_discriminator_enum_name/build_discriminator_enum_valuesshared helpers and refactor C/C#/JS/Python/TS discriminator enum generation; fix message-comment accumulation (+=) in those generators. - Gate C/C++ round-trip tests on
compilation.get(lang, False); add JS/TS twin-maintenance comments and simplifygetInitialState().
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_utils.py | New shared _check helper module. |
| tests/test_caching.py, test_equality.py, test_magic_bytes.py, test_no_packed.py, test_proto_field_types.py, test_validate_flag.py, test_wire_evolution.py | Remove local _check, import shared helper. |
| tests/run_tests.py | Require explicit successful compilation result for C/C++ round-trip phases (default flipped from True to False). |
| src/struct_frame/base.py | Add get_discriminator_enum_name and build_discriminator_enum_values helpers. |
| src/struct_frame/init.py | Export the new helpers. |
| src/struct_frame/c_gen.py | Use shared discriminator helpers; fix message-comment accumulation. |
| src/struct_frame/csharp_gen.py | Use shared discriminator helpers (output unchanged). |
| src/struct_frame/js_gen.py | Use shared discriminator helpers; fix message-comment accumulation in two generators. |
| src/struct_frame/py_gen.py | Use shared discriminator helpers; fix message-comment accumulation. |
| src/struct_frame/ts_gen.py | Use shared discriminator helpers; fix message-comment accumulation in two generators. |
| src/struct_frame/boilerplate/ts/frame-base.ts | Simplify getInitialState() (remove redundant branch); add twin-maintenance note. |
| src/struct_frame/boilerplate/js/frame-base.js | Add twin-maintenance note. |
| import os | ||
| import subprocess | ||
| import sys | ||
| from test_utils import _check |
Pull request created by AI Agent