fix: OpMeta Input computation requires bits - #260
Open
thedavidmeister wants to merge 1 commit into
Open
Conversation
An Input carrying `computation` with no `bits` is a computed input that never allocated the operand bits its computation reads, so schema-level validation now rejects it. `parameters` alongside `bits` stays valid: it is the spread shape every dynamic-input op meta ships. Closes #171 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 20 seconds. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
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. Comment |
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.
Closes #171.
What the issue claimed
Input's docs describe a discriminated union — constant inputs are counted byparameters, computed inputs are discriminated bybits(+ optionalcomputation) — but validation was per-field only, so two contradictory shapesvalidated. Only one of the two is actually a defect.
Fixed:
computationwithoutbits{"computation": "bits + 1"}with nobitsis a computation whose reservedbitskeyword reads operand bits that were never allocated.Input.bitsandInput.computationare both documented "Required only for computed(non-constant) inputs", and the sibling
Outputtype in the same file alreadyencodes exactly this as an enum whose
Computed(BitIntegerRange, Computation)cannot be split. Upstream's op meta JSON schema agrees on the output side:
ComputedOutputlistsbitsasrequired.Inputnow carries a struct-level#[validate(schema(...))]that rejectscomputationwith nobits. The repro from the issue,OpMeta::try_from(br#"{"name":"add","inputs":[{"computation":"bits + 1"}]}"#),returns
Erron this branch.test_opmeta_input_computation_validated's "valid" arm was that exact reproshape, so it gains the
bitsit was always missing; the rejection is pinned bythe new
test_opmeta_input_computation_requires_bits.Not fixed, because it is not a defect:
parameterswithbitsThe issue also called
{"parameters": [..], "bits": [0, 3]}contradictory. Itis not — it is the canonical shape of every dynamic-input opcode. In
rainlanguage/rain-metadata,schemas/op.meta.schema.jsonmakesparametersrequired on
InputArgswithbitsoptional beside it, and the shippedexamples carry both:
(
examples/op-meta/Add.op.meta.json;Call.op.meta.jsonis the same shape.)InputParameter.spread— "Specifies if an argument is dynamic in length" — hasno valid use at all if a parameter may not sit beside
bits, and theinputsdoc already resolves the count without ambiguity:
bitspresent means the countderives from the bits, not from
parameters.len(). Rejecting that shape wouldreject
addandcall.test_opmeta_input_parameters_alongside_bits_is_validpins it as accepted so it does not get "fixed" later.
Not touched
The
ValidationErrors::merge_allmisuse that drops nested errors is #173, stillopen; the NOTE comments pointing at it are unchanged.
QA
test_opmeta_input_computation_requires_bits— fails onbase (verified by restoring base behaviour in place: dropped the new
#[validate(schema(function = "validate_input_computation"))]attribute fromInputand re-rancargo test -p rain-metadata --lib meta::types::op::v1→13 passed; 1 failed, the failure beingassertion failed: OpMeta::try_from(br#"{"name":"add","inputs":[{"computation":"bits + 1"}]}"#.to_vec()).is_err(),i.e. the issue's own repro). The other two test edits are regression pins, not
discriminating, and pass on base by design:
test_opmeta_input_parameters_alongside_bits_is_valid(guards theadd/callspread shape against a future over-strict "fix") and the amended
test_opmeta_input_computation_validated(its ok arm now suppliesbits).Full module run on this branch:
14 passed; 0 failed.#[validate(schema(function = "validate_input_computation"))]onInput→attribute removed → killed by
test_opmeta_input_computation_requires_bits.if input.computation.is_some() && input.bits.is_none()→if input.bits.is_none()(drop the computation guard, over-reject everyconstant input) → killed by
test_input_parameter_spread_defaults_false(pre-existing test).
if input.computation.is_some() && input.bits.is_none()→if input.computation.is_some()(drop the bits guard, reject legitimatecomputed inputs) → killed by
test_opmeta_input_computation_validated.OpMeta.inputs,Input.bitsandInput.computationin this file (the issue's own stated intent oracle),cross-checked against the upstream op meta v1 JSON schema
rainlanguage/rain-metadataschemas/op.meta.schema.json(ComputedOutputrequires
bits;InputArgsrequiresparameters) and its shippedexamples/op-meta/Add.op.meta.json/Call.op.meta.json. Expected values comefrom those documents, not from the Rust implementation.
computationwith nobits,(B)
parameterstogether withbits. A is covered and now rejected. B iscovered as a finding rather than a change: it is refuted above with the
upstream schema and examples, and pinned as valid by a test, because enforcing
it would reject the real
addandcallop metas. The issue's own triageframing flagged it for a human call; the evidence answers it, and both halves
are resolved, so this closes OpMeta Input allows contradictory computed/constant shapes (computation without bits, parameters with bits) #171.