Skip to content

Generate operator cases for unowned documented examples - #4558

Open
evanchooly wants to merge 1 commit into
audits-candidatesfrom
audits-generator
Open

evanchooly wants to merge 1 commit into
audits-candidatesfrom
audits-generator

Conversation

@evanchooly

@evanchooly evanchooly commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Step 5, slice 7 of the operator-audit plan: the generator. Stacked on #4557.

Problems solved

Nothing knew which documented examples had no test. Ownership was only known from the fixtures' side. fetch.py current now lists every operator page at one pinned mongodb/docs commit (e4b0c153), and GenerateMainKt inventory writes audits/catalog/documented-examples.json. It matches each example to its owner by title, or by action text when the page renamed it after the fixture was written. Example: $bitOr's "Bitwise OR with a Long and Integer" has no fixture, so it is UNOWNED. Statuses are OWNED, UNOWNED, UNNAMED (generic titles like "main", which need a reviewed name) and AMBIGUOUS (two examples share a name, or one matches several owners).

Result: 197 pages read; 300 examples owned, 32 unowned, 11 unnamed.

The generator had no reviewed way to turn MQL into Morphia calls. audits/catalog/dsl-bindings.json maps each operator to its factory in one of four forms: positional, named (with chained options), projection, or fields. GenerateMainKt candidate captures MorphiaApiInventory of core's current source and stops on any stale binding: wrong owner, method, parameter types or varargs, or an option method missing from the factory's return type or its supertypes. Integration's compile step remains the real contract test.

Generation needed a path that never guesses. CaseGenerator emits one class per operator under dev.morphia.test.generated.expressions, plus a scenario.json per case. It works from the inventory's recorded source text only, so it needs no pages. A value is emitted only in the form its parameter type takes. Anything else becomes a gap in gaps.json beside the candidate, naming its reason or its first unbound node. For example, /pipeline/0: stage $match has no binding is the next adapter task.

First run

Four expressions cases were generated and integrated ($add, $bitOr, $dateDiff, $filter). Only $add's "Add Non-Integer Values to a Date" passes, and it is promoted: 443 tests pass under each mapper. The other three are excluded in audits/catalog/generation-review.json with their evidence:

  • $bitOr, a docs error. The page prints $bitAnd's results: Long("0"), Long("2") and Long("3"), where a | 63 is 63 each time. Serialization and behavior both pass.
  • $dateDiff. The server returns a long, which mongosh prints as Long('1'), but the page prints 1.
  • $filter with $$IDX. It is rejected by MongoDB 8.2, which is what the tests run, and 8.3 cannot start on these kernels.

Decisions for review

  • Snippet pages are a gap, not an extractor change here. 103 pages (most stage pages among them) keep their examples in tested code-example snippets (.. input:: /code-examples/...). The legacy extractor cannot resolve those, so the inventory lists them as skipped with that reason. A snippet resolver is the largest next unlock for generation.
  • Generated Java sits between // spotless:off and // spotless:on. The manifest pins each file's bytes, and Eclipse's 120-column wrapping would otherwise rewrite them. Imports are emitted in the configured order.
  • Exclusions, not requirements, for unverifiable cases. A minimumServer requirement would skip the $$IDX case on every host we run, so nothing would check it.
  • The inventory records unowned examples' source text (43 examples), like legacy-references.json already does. Pages themselves are still not committed.
  • Only aggregate pipelines are generated. Find and update examples are gaps until the query and update DSL get bindings.
  • FormMain manifest and the manifest test now go through Candidates.manifest, so regenerating the manifest keeps generated cases.
  • I'm not filing the $bitOr and $dateDiff page errors upstream without your go-ahead.

Review status

Self-reviewed only: the independent reviewer is at its weekly limit until Nov 26, and Codex and Copilot are out of quota. I'll rerun real reviews after the reset.

Verification

  • Core gate: 662 tests under each mapper (Critter first).
  • Audits: 445 tests under each mapper.
  • Spotless: leaves the generated file unchanged.
  • Regeneration: a second candidate of the committed tree matches it byte for byte.

Follow-up for you: #4563 tracks reporting the $bitOr and $dateDiff page errors to mongodb/docs. Nothing has been filed upstream.

Inventory every example on the current operator pages with its owner,
check reviewed DSL bindings against core's API, and generate a test and
scenario for each bound, unowned expressions example through the
candidate, integrate and promote path. Every other example is a named gap.

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