Repository navigation
Refuse a malformed NZ cell-support contract with a named error (#1202 follow-up) - #1219
Merged
Merged
Conversation
The round-3 review of #1202 found two older paths in _cell_contract that failed closed with bare errors on a malformed spec: a contract missing a target_* threshold raised KeyError while the thresholds were read, and matching lists of mappings on both gates reached a set() comparison and raised TypeError. _require_cell_contract_shape now runs first. It requires every key the contract is read for, and requires required_cells and required_scenarios to be non-empty lists of non-empty strings, naming the gate and the offending key or value. Tests: each of the eight omitted keys; mapping, mixed, empty, string and blank values for both lists; and the reviewer's matching-mapping case. All 19 fail with the check removed. One #1202 case, a string contract list, is now refused by this earlier check, and its expected message says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_cell_contract reads required_weight_kind and required_weight_entity, but the shape check did not list them, so a contract missing either passed the check and then raised a bare KeyError. Both are now required, with an omission test each (red without the fix: 2 failed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Merged by the NZ hub (session local_e407a527) at d41040b with --squash. Gates: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1202. Its round-3 review found two older paths in
_cell_contract(transport/entitlement.py) that fail closed on a malformed NZ spec, but with bare errors that don't say what's wrong:target_*threshold raisedKeyErrorwhile the thresholds were read;TypeErrorat aset()comparison.The change
_require_cell_contract_shaperuns before the contract is read. It requires every key the contract uses:required_cells;required_scenarios;aggregation_column.required_cellsandrequired_scenariosmust be non-empty lists of non-empty strings. A violation raises aValueErrornaming the gate and the offending key or value. A well-formed spec behaves exactly as before.Tests
test_transport_entitlement_graph.pygains 21 cases (10 omitted keys, 10 malformed lists, 1 matching mapping):required_weight_kindorrequired_weight_entity.All 21 fail when the check is removed (an in-memory mutant; r2 confirmed 24/24 direct mutation checks, including the changed existing case's 3 parameters). One #1202 case, a string contract list, is now refused by this earlier check; its expected message changes accordingly.
Runs on this tree:
test_transport_entitlement_graph.py: 67 tests at the final head d41040b, all passing in r2's full run (67 passed). The earlier run, at 05290df, had 65 tests: 64 passed and 1 failed, the case adjusted above, which then passed on re-run.test_nz_spec_package.py: 72 passed.test_transport_graph.py: 15 passed.test_transport_gate_bindings.py: 114 passed.ruff check,ruff format --check,tools/ci_test_plan.py verifyandgit diff --checkpass.Invariant, scoped: a contract that omits a required key, or declares a malformed
required_cellsorrequired_scenarioslist, is refused with a namedValueErrorbefore the threshold reads and the list set comparisons. Valid contracts behave as on main; r2 checked five valid declarations for identical graph JSON. The check does not type-check every value. For example,aggregation_column=[]still fails later with a bareTypeError, and a missingparametersobject fails with a genericTypeError. Both paths predate this PR and still fail closed.Review
_CELL_CONTRACT_KEYSomittedrequired_weight_kindandrequired_weight_entity, which_cell_contract's caller reads (entitlement.py ~374/380). Its executed deletion probes passed the shape check and then raised a bareKeyError. The reviewer's test run was cut short by the disk floor; ruff, the CI plan (658 files), the burndown (41 green) and diff-check passed._CELL_CONTRACT_KEYS. Those are the onlyparams[...],parameters[...]andcontract_params[...]reads of the contract in entitlement.py.🤖 Generated with Claude Code