Repository navigation
feat(model)!: restrict identifiers to letters, digits, and underscores - #1068
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
| Layer / File(s) | Summary |
|---|---|
Identifier and name rules phlex/model/identifier.*, phlex/model/algorithm_name.*, phlex/model/data_cell_index.*, test/identifier_test.cpp, test/data_cell_index_test.cpp, test/data_layer_hierarchy_test.cpp, test/core_misc_test.cpp, test/max-parallelism/* |
Identifiers now reject invalid names, and algorithm_name no longer has a default constructor. Child layer names must be non-empty. Related tests and stage-name fixtures use valid names. |
Product specification and suffix types phlex/model/product_specification.*, phlex/model/handle.hpp, phlex/model/product_store.cpp, phlex/core/registration_api.hpp, form/form_*, test/multilayer_join_test.cpp, test/transform_node_test.cpp |
Product specifications store an optional creator and a suffix_t. Accessors, output registration, FORM product handling, and related tests use the updated suffix representation. |
Selector matching and provider routing phlex/configuration.cpp, phlex/core/consumer.cpp, phlex/core/detail/make_algorithm_name.cpp, phlex/core/index_router.*, phlex/core/producer_catalog.*, phlex/core/product_selector.*, phlex/core/provider_node.cpp, test/config_test.cpp, test/product_selector_test.cpp |
Selectors use suffix_t and handle absent creators. Consumer layer collection omits unspecified layers, and provider routing uses a shared unresolved-layer node for inputs without a specified layer. |
Python registration and suffix conversion plugins/python/src/modulewrap.cpp |
Python registration parses typed selector values, validates names and suffixes, and translates C++ exceptions into Python errors. |
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Feature
Suggested reviewers: knoepfel, beojan, greenc-fnal
Merge Risk: 
Minimal · previous review 78070
-
This change tightens identifier validation and removes empty-name defaults, which is a deliberate breaking change for consumers. No concrete defects were found in the supplied code, and the reported test results are local only. The main merge-readiness note is that downstream consumers must adopt the stricter naming rules.
Pre-merge checks: 
4
-
Full details: Title check
-
Explanation
The title names the main change: identifiers are restricted to letters, digits, and underscores. The changeset enforces this in identifier validation (identifier.cpp/hpp), and the rest of the diff follows from it: empty-capable values move to identifier_or_empty or std::optional, the default constructor is deleted, and tests are updated. The title is specific, uses a conventional type prefix, and flags the breaking change with '!'. It omits the wider effects (algorithm_name, product_specification, layer handling, Python validation), which is acceptable for a title.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #1068 +/- ##
==========================================
+ Coverage 91.19% 91.39% +0.19%
==========================================
Files 184 184
Lines 5986 6054 +68
Branches 962 972 +10
==========================================
+ Hits 5459 5533 +74
+ Misses 337 331 -6
Partials 190 190
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
beojan
left a comment
There was a problem hiding this comment.
Thanks! I didn't see anything glaring, but Gemini caught a few issues due to residual code:
-
Algorithm names get validated twice (once in
algorithm_name::createand then again here) and sometimes make it through the first validation, but fail the second. -
identifier::empty()still exists -
If a stage name is given as a command line argument and it fails validation, you don't get a nice error message.
It also complains about identifier_or_empty's move constructor from identifier not being noexcept any more.
I'd say this PR is big enough that 1 and 2 are in scope.
|
@phlexbot coverage |
|
Coverage workflow completed. Result: ✅ Coverage analysis passed. See the workflow run for detailed results. |
09782e4 to
bf61f97
Compare
Add a test case checking that the default source reports the name "Source", has the matching algorithm identifier, has an empty plugin, and compares equal across calls.
Replace the wildcard fallback in the producer catalog debug message with direct access to the query suffix. The empty-catalog check returns early, so reaching the b == e branch implies a specified suffix. The previous wildcard branch was therefore unreachable and could not be covered by tests, leaving an artificial gap in patch coverage. Suppress the unchecked-optional lint warning at the call site with a comment explaining the invariant. Add a direct test that find_producers returns no producers for an unknown suffix in a nonempty catalog, exercising this return path.
Add a Catch2 section asserting that `algorithm_name::create("")` throws
`std::runtime_error` with the message "Cannot create an empty algorithm
name." Include `catch2/matchers/catch_matchers.hpp` for `CHECK_THROWS_WITH`.
Add a Catch2 test case for `product_specification` covering `std::hash` and equality. It checks that named and unnamed specifications with identical fields hash equally, that duplicate insertions into an `std::unordered_set` are rejected, and that lookups distinguish differing creator, name, or type. Includes `product_specification.hpp`, `<functional>`, `<optional>`, and `<unordered_set>` as needed.
Add a test case verifying that `product_specification::create` with a leading-slash name yields no creator, the suffix as the given name, and an invalid type.
Add an index router test confirming unresolved provider layers receive no concrete indices, a product handle test for absent creator metadata, and a provider node test asserting that specifications without a creator throw std::runtime_error
Set bugprone-unchecked-optional-access.IgnoreValueCalls to true in .clang-tidy so calls to std::optional::value() no longer trigger warnings when they lack a preceding has_value() guard.
Moving an identifier never allocates, so the `identifier&&` constructor of identifier_or_empty can be declared noexcept. This lets callers and standard containers rely on the non-throwing move. Add comments noting that the `identifier const&` copy constructor is intentionally not noexcept, because copying the underlying string may allocate and throw.
Replace the identifier_or_empty plugin qualifier in algorithm_name with std::optional<identifier>, where an absent value means the name is unqualified. The constructor, plugin() accessor and to_string() now use the optional directly. Adapt the callers: - make_algorithm_name leaves the plugin absent when there is no configuration and otherwise uses the module label. - product_selector compares the optional plugin to the creator identifier. - product handle creator() builds its view from an empty string_view when the plugin is absent. - the product_specification hash mixes in whether a plugin is present before hashing it, so qualified and unqualified creators stay distinct. - the product_store default source test checks has_value() instead of empty(). Add tests for the optional plugin states, construction from typed components, parse rejection of ":algo", "plugin:", multiple colons and malformed components, and make_algorithm_name with and without a configuration.
A product_specification now always names its creator. The creator is a plain algorithm_name instead of std::optional<algorithm_name>, so every specification identifies the algorithm that produced it. Default construction and the creator-less (std::nullopt, suffix, type) constructor are removed. The text form must be `creator/suffix`. `creator/` denotes an explicit empty suffix. Bare text, `/suffix`, `/` and the empty string now throw std::runtime_error with a message that describes the expected form. Previously these were accepted as creator-less specifications. The text constructor now delegates to create() rather than assigning from it. Equality and std::hash cover the creator, suffix and type. The hash no longer mixes in a has-creator flag, because the creator is always present. Adapt callers to the non-optional creator: - provider_node copies the creator before the spec is moved and drops its creator-presence check, which can no longer fail. - product_selector matches against the always-present creator. - The product handle creator() view no longer needs an empty fallback. Tests are added for the following: - Constructibility and creator type. - Text parsing, including the rejected forms. - Round-tripping of `creator/`. - set_type mutation. - Hash and equality across all components. - Selector matching by creator, suffix and type. - Handle creator views. - Provider node naming. Existing tests are migrated to `creator/suffix` specifications. BREAKING CHANGE: product_specification no longer has a default constructor or a std::nullopt creator constructor. creator() returns algorithm_name const& rather than std::optional<algorithm_name> const&. Text specifications without a creator (e.g. "number", "/number") now throw std::runtime_error and must be written as "creator/number".
Algorithm-name text was checked twice by different rules. A private
character precheck accepted `[A-Za-z0-9_[]]`, and the identifier
constructor then re-validated with the stricter identifier grammar, so
`_x`, `1p:a` and `a[0]` passed the first check and failed the second,
with different exception types and unrelated messages.
The identifier grammar is now the only character rule. The precheck is
deleted. algorithm_name::create(text) parses structure and delegates to
a new public create(optional<string_view> plugin, string_view algorithm)
overload, which constructs the identifiers, catches their failure, and
rethrows with the composed name, the failing part (plugin label or
algorithm), and the rule. make_algorithm_name uses the same overload, and
the separate verify_name empty-name check is removed.
All malformed algorithm-name text now throws std::invalid_argument,
which the Python bindings report as ValueError. Messages quote the
offending text with fmt's `{:?}`, shortened to 64 characters, through one
private helper that identifier and algorithm_name share.
Report the field at each parse boundary:
- Product selectors read from configuration or Python name the field
(creator, layer, suffix, stage) that held the bad text.
- Python provider outputs name the field the same way.
- form_source parses its `creator` parameter once at registration and
stores the algorithm_name instead of reparsing it per product.
- load_module and load_source check the configuration label, which
becomes the plugin label of everything the entry registers, and name
the `modules` or `sources` section.
Remove identifier::empty(). An identifier is never empty, so its only
production uses were unreachable checks in creator_name and layer_name,
which are deleted along with their messages.
Add nothrow STATIC_CHECKs for identifier_or_empty. Tests cover create
and its overload, make_algorithm_name, product_specification::create,
the config boundaries, label validation, and Python ValueError reports.
BREAKING CHANGE: malformed algorithm names throw std::invalid_argument
instead of std::runtime_error, characters `[` and `]` are no longer
accepted in a name, identifier::empty() is removed, and a module or
source label that is not a valid identifier is rejected when loaded.
Read the plugin label in algorithm_name tests through value() instead of operator*. Both are guarded by a preceding REQUIRE(has_value()), so behavior is unchanged, and value() reports an error on an empty optional rather than being undefined. Also declare the expected-forms string in the structural-error test as a const pointer, matching the surrounding test style.
Identifier errors now say "an identifier" instead of "it" and state that an empty value is rejected, so the message no longer implies that an empty name is accepted when it does not start with a letter. The shared identifier_rule text is updated, and the error messages built from it change accordingly. Update the affected C++, Python, and CMake test expectations to match the new message text.
`creator_match()` already returns true when no creator is set, so the explicit `creator &&` check in `product_selector::match()` was redundant. Behavior is unchanged.
Separate invalid-name constructor checks from embedded-NUL checks on explicitly sized input, and give the empty identifier_or_empty case its own test. The NUL test comment explains why these constructors are exercised with the full byte sequence.
Remove the static `algorithm_name::create(char const*)` and
`algorithm_name::create(std::string_view)` overloads, and the matching
`product_specification::create` overloads. The text constructors now
parse their argument directly, so `algorithm_name{spec}` and
`product_specification{spec}` replace the removed factories. The
`algorithm_name::create(plugin, algorithm)` overload remains as the
validation point.
Parsing, error messages, and exception types are unchanged. Callers in
form, model, and tests are updated to use the constructors.
Move excerpt() out of the private detail header into detail/excerpt.cpp so the fmt dependency is no longer pulled into every includer. The function's behavior is unchanged.
Rename the badname transform test and its Jsonnet config to invalid_transform_name, and replace malformed selector values with descriptive strings (bad creator, bad layer, bad suffix) so each case names the field it exercises.
Move the product_specification test cases out of product_store_test.cpp into test/product_specification_test.cpp and register the new target in test/CMakeLists.txt. The moved test bodies are unchanged; only the includes needed by each file are adjusted.
Replace the direct `std::hash` equality checks with duplicate insertions into an `std::unordered_set`. Equal specifications must hash equal to be deduplicated, so the set checks cover the same contract. Add a duplicate check for an empty suffix and a comment explaining the hash/equality expectation.
Make detail::value_if_exists a header-only template that converts to any type T via boost::json::value_to, and read product selector fields through it. The suffix field is converted by a tag_invoke overload for suffix_t, so the optional and error handling of each field is shared. Malformed fields still report the field name in the error message. Update identifier_test to call the templated value_if_exists<identifier>.
64865f8 to
79b6a9f
Compare
All of @beojan's requested changes have been implemented.
Summary
PR 3a of the concept-registry stack, based on
main. Inserted beneath #1002after #1001 merged.
Make
identifiera validated, never-empty name, and remove the defaults thatrelied on an empty one.
instead of a
"*"layer key.layer_pathby walking the parent chain.[Source]toSource, which is avalid name.
providers are registered. Report failures as
ValueErrororRuntimeErrorinstead of letting C++ exceptions escape.
Evidence
main,identifieraccepts any text, including"", and hasa default constructor. This is the API change shown by the diff, not a
failing run.
After: the
identifiertest passes. It covers rejected names(punctuation, a leading digit or underscore, empty text, spaces, non-ASCII
bytes and embedded NUL) and moved-from identifiers.
mypy, which reports the same 12 errors inplugins/python/python/phlex/_typing.pyonmain. This PR changes no.pyfiles.
Local macOS evidence, not CI or sanitizer approval.
Merge Danger
Door: Two-way
A revert restores the permissive behaviour. #1002, #1003 and #1009 are stacked
on this PR and would need rebasing.
Blast Radius: Consumers
Breaking change. A name that is empty, starts with a character other than a
letter, or contains anything except letters, digits and underscores is now
rejected, in C++, in configuration, and in Python modules. Code that
default-constructs
identifieroralgorithm_nameno longer compiles.Overview
identifierto non-empty names that start with an ASCII letter and contain only ASCII letters, digits, or underscores.std::invalid_argument.identifier.algorithm_name.suffix_ttype for product suffixes.identifieroralgorithm_nameno longer compiles. Previously accepted names may now be rejected.Model (
phlex/model)identifier.hpp/.cpp: adds validation to both constructors. Adds a constexpr validator for_idqliterals, which throw"Invalid identifier query". Documents the validation rules.identifier_or_empty: its move-from-identifierconstructor is no longernoexcept, per the raw summary. A later commit reportedly made identifier move operationsnoexcept. Confirm this against the final source.algorithm_name:create(std::string_view)throws on an empty specification. The plugin argument is nowidentifier_or_empty. An empty plugin is allowed for colon-qualified names.product_specification: storessuffix_t. Adds astd::nullopt_tconstructor for specifications without a creator.creator()returnsstd::optional<algorithm_name>.plugin()andalgorithm()are removed.suffix()returnssuffix_t.data_cell_index:layer_path()builds the path by walking parents.to_string_this_layer()always printsname:number. A documentation comment states that child layer names must be non-empty identifiers.handle.hpp:creator()returns an empty view when no creator is set.suffix()returns astd::string_view.product_store.cpp: the default source algorithm name changes from[Source]toSource.Core (
phlex/core)index_router: unresolved provider inputs use a sharedunresolved_index_set_node_. This replaces the"*"identifier key.multilayer_join_slots_keys change fromidentifiertostd::string.consumer.cpp:layers_fromignores selectors without a layer.consumer::layers()therefore omits those selectors.provider_node.cpp: throwsstd::runtime_errorwhen the product specification has no creator.product_selector:matchreturnsfalsewhen a required creator is missing.suffixisstd::optional<suffix_t>.creator_nameformatting returns astd::string_view.producer_catalog:product_suffix_taliasessuffix_t.registration_api.hpp:output_producttakes asuffix_tfor the suffix.make_algorithm_name.cpp: passes the module label throughidentifier_or_empty.Configuration and FORM
configuration.cpp: parsessuffixdirectly as a string. It creates an optionalsuffix_tonly when the key exists.form/form_module.cpp: derives product labels fromsuffix().text().form/form_source.cpp: builds specifications withsuffix_t{name}.Python plugin (
plugins/python/src/modulewrap.cpp)"_py".std::invalid_argumentto PythonValueError. Maps other standard exceptions toRuntimeError. Unknown exceptions produce registration-specificRuntimeErrormessages..pyfiles change.Tests
identifier_test.cpp: adds validation, ASCII-name, construction, and move tests. Checks thatidentifieris not default-constructible. Switches fixtures to underscores.config_test.cpp: expectsInvalid identifierfor empty layer or creator.core_misc_test.cpp: removes thealgorithm_namedefault-constructor test.data_cell_index_test.cppanddata_layer_hierarchy_test.cpp: expectmake_child("", …)to throw.product_selector_test.cpp: empty-name tests check only that construction throws. Creator values change from"1"/"2"to"one"/"two".multilayer_join_test.cppandtransform_node_test.cpp: usesuffix_t{}.max-parallelismtest files: renamecommand-line-stageandconfigured-stagetocommand_line_stageandconfigured_stage.Verification status
mypy. Themypyfailure is 12 errors inplugins/python/python/phlex/_typing.py, which also fail onmain.Reviewer notes
#1002,#1003, and#1009need rebasing if this change is reverted.identifier_or_emptymovenoexceptbehavior against the final source before merge.