Skip to content

Compare declared result arrays as multisets and convert the $graphLookup cases - #4568

Open
evanchooly wants to merge 1 commit into
audits-named-argumentsfrom
audits-unordered-arrays
Open

evanchooly wants to merge 1 commit into
audits-named-argumentsfrom
audits-unordered-arrays

Conversation

@evanchooly

Copy link
Copy Markdown
Member

Closes #4562, the follow-up to #4554's open question, as you asked. Stacked on #4567.

Problem

$graphLookup builds its as array in no defined order. The page says so: "Documents returned in the as field are not guaranteed to be in any order." Two cases couldn't leave the legacy path because of it:

  • graphLookup/withinASingleCollection: the runner seeds identical data into two databases and runs the documented pipeline and Morphia's. The server listed reportingHierarchy in a different order in each run, so the strict behavior check failed even though both held the same documents.
  • graphLookup/withAQueryFilter: the same failure, in connections who play golf, which is projected from the array $graphLookup builds.

The only leniency available was ordering for the top-level result list. Nested arrays always compared in order.

Change

Comparison. A scenario's comparison.unorderedArrays lists RFC 6901 pointers within each result. Each named array matches as a multiset: the same items, as often, in any order. Every other array, including arrays inside a named array's items, stays ordered.

  • Audits module (Kotlin):

    • BsonComparisonPolicy.unorderedArrays and PublishedComparison.compareResults(..., unorderedArrays) do the matching.
    • They use a perfect bipartite matching, shared through a new Matching helper. The two existing result-row matchers use it too. Matching matters because printed constraints overlap: a printed 4 matches both Int32 4 and Double 4.0.
    • A failure is reported as the new UNMATCHED_ITEM difference.
    • PublishedComparison now builds paths relative to each row, as BsonComparison already did, so a pointer means the same thing in ordered and unordered results.
  • Core (Java): StrictBson and PrintedResults port the same behavior.

  • Golden vectors: 14 new ones (8 strict, 6 printed) cover:

    • a reordered match;
    • a multiplicity mismatch and a type mismatch inside a reordered item;
    • overlapping printed constraints;
    • per-row paths, an exact path and an escaped path;
    • inner arrays staying ordered.

    Both implementations run them and agree.

Declaration. A form-review declaration lists unorderedArrays: [{path, reason}]. capture rejects:

  • a path that isn't a pointer into a result;
  • a blank reason;
  • a repeated path.

It then carries the arrays into the override and the scenario. Only a scenario that declares one carries the key, so the other 349 scenarios are unchanged. The field is omitted from the catalogs when it's empty.

Runner. OperatorCaseRunner applies the declared arrays to the behavior check and the published check (documents or printed). It also refuses unknown comparison fields, and any unordered path that doesn't start with /.

The two cases.

  • Each declares its array, and the reason quotes the page.
  • Their bodies change graphLookup(EXAMPLE_TEST_COLLECTION) to the documented collections, employees and people. The ledger records both as reviewed body edits, as Keep documented collection names in cut-over scenarios #4554 did for $dateAdd.
  • Both convert, cutover.json drops them, and their declarations move to migrated.

Decisions for review

  • Pointers address each result, not the result list, and an item's nested pointers use its expected position. That matches how BsonComparison's other policies already worked.
  • No wildcards. Each array is named exactly, with evidence. A reordered array nobody declared still fails.
  • The collections check stays strict. These are reads, so the collections don't change, and nothing here needs it relaxed.

Verification

  • Core operator tests (aggregation, query, generated, and the runner, vector, manifest and binding checks): 678 pass under Critter, then reflection.
  • Audits suite: 452 pass under both mappers. FormMigrationTest gains checks that a valid declaration reaches the override and that the three bad forms are rejected.

Self-reviewed only: the independent reviewers are out of quota until 2026-11-26.

…kup cases

A scenario's comparison.unorderedArrays names result arrays, by pointer
within each result, that the server builds in no defined order. The
strict and printed-result comparators in both the audits module and core
match them as multisets, held together by new golden vectors. A
form-review declaration lists each with its evidence; capture checks it
and carries it into the scenario.

Both $graphLookup cases declare the array $graphLookup builds, convert,
and pass under both mappers; their bodies now look up the documented
collections, recorded as reviewed body edits. Closes #4562.

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