Skip to content

Port the form rules to core (operator audits step 5, slice 4a) - #4545

Open
evanchooly wants to merge 1 commit into
audits-case-adapterfrom
audits-case-rules
Open

evanchooly wants to merge 1 commit into
audits-case-adapterfrom
audits-case-rules

Conversation

@evanchooly

Copy link
Copy Markdown
Member

Step 5, slice 4a of the operator audits (design). Stacked on #4544.

Problem

The generated-case runner (#4542) compares Morphia's emitted pipeline with the documented one byte for byte. Many documented examples use a different but equivalent spelling than Morphia emits, which the lock migration already reviewed as declared form rules (COND_ARRAY, EQ_SHORTHAND, REGEX_FORM, ...). Those rules lived only in the audits module (FormEquivalence), so any fixture with a declared rule could not move to the runner. For example, cond/condExpressionOperator documents $cond: {if, then, else} while Morphia emits $cond: [a, b, c]. Under strict comparison the serialization check fails, even though the review has already accepted the two forms as the same expression.

Changes

  • FormRules (core test code) ports FormEquivalence to Java. It covers every rule that rewrites a form. ALTERNATIVE_COMMANDS picks among documented commands rather than rewriting one, so it is not ported, and the runner still treats it as unsupported. An unknown rule name also counts as unsupported.
  • Golden vectors in generated/vectors/rules.json cover positive and negative cases for each rule: 25 in all. Both the Kotlin and the Java implementations are tested against them (RuleVectorsTest, FormRulesTest), and the audits test requires a vector for every rewriting rule. Expected outputs come from the Kotlin rules.
  • OperatorCaseRunner applies the scenario's comparison.rules to both the documented and the emitted pipeline before the serialization check.
  • FormMigration.documented now allows overrides with rules. Overrides with retypes, corrections, collections or ALTERNATIVE_COMMANDS still cannot migrate. FixtureMigration.scenario writes the override's rules into scenario.json.
  • cond/condExpressionOperator is converted under COND_ARRAY and passes under both mappers. Form report: 135 overrides. Inventory: 555 examples, 137 OVERRIDDEN, 98 locked.

Decisions for review

  • Expected outputs are stored as strings. Each vector's expected output is a string of extended JSON. Storing it as a JSON document would not work: {$regex: "p", $options: "i"} read back from JSON becomes a regular expression, so the canonical document form could not survive a round trip. For the same reason, an input key that starts with # is read with $ in its place. That lets a vector feed {$regex: "p", $options: "mi"} as a document and check that its options are sorted.
  • The two ports are kept aligned by test. The Java port duplicates the Kotlin rules instead of sharing one implementation, because core's tests cannot depend on the audits module. The shared vectors hold the two together, and a new rule fails RuleVectorsTest until it has a vector.

Printed-result constraints come in the next slice (4b).

FormRules is a Java port of the audits FormEquivalence, held to it by
shared golden vectors. The case runner applies a scenario's declared
rules to both sides of the serialization check, and overrides with
rules can now migrate; cond/condExpressionOperator is converted.

This branch has not been deployed

No deployments
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.

1 participant