Skip to content

Remove $documents dependency from expression test helpers - #715

Open
eerxuan wants to merge 2 commits into
documentdb:mainfrom
eerxuan:remove-documents-dependency-upstream
Open

Remove $documents dependency from expression test helpers#715
eerxuan wants to merge 2 commits into
documentdb:mainfrom
eerxuan:remove-documents-dependency-upstream

Conversation

@eerxuan

@eerxuan eerxuan commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

What

Remove the dependency on the $documents aggregation stage from the shared
expression test helpers (execute_expression, execute_project) and two
inline call sites in test_expressions_combination_variables.py.

Why

These tests use a collectionless {aggregate: 1} pipeline with
{$documents: [{}]} purely as a scaffold to feed a single empty document
into $project. They do not test $documents itself — yet through the
shared helpers, ~205 expression test files inherit a hard dependency on
$documents support. Any engine that does not implement $documents cannot
run these tests at all, even though the behavior under test has nothing to do
with that stage.

Removing this dependency lets the expression compatibility suite run against
engines that don't yet support the $documents feature.

How

Swap the scaffold for collection.insert_one({}) plus an aggregate over the
named collection:

+    collection.insert_one({})
     return execute_command(
         collection,
         {
-            "aggregate": 1,
+            "aggregate": collection.name,
             "pipeline": [
-                {"$documents": [{}]},
                 {"$project": {"_id": 0, "result": expression}},
             ],
             "cursor": {},
         },
     )

This is logically identical: both feed exactly one empty document into
$project, so literal expressions and field references (which resolve to
missing against an empty document) behave the same. The collection fixture is
function-scoped, so each test still runs against a fresh single-document
collection.

Scope

  • expressions/utils/utils.py — the two shared helpers (execute_expression,
    execute_project) inherited by ~205 files.
  • test_expressions_combination_variables.py — two inline $documents sites
    (test_let_two_lets_same_projection, test_let_error_cross_let_variable_ref).
  • The _with_insert sibling helpers are unchanged (they already insert a
    populated document).

The expression compatibility tests use a collectionless
`{aggregate: 1}` + `$documents: [{}]` pipeline purely as a scaffold
to feed a single empty document into $project. They do not test
$documents itself, yet they inherit a hard dependency on $documents
support from the shared helpers.

Swap the scaffold for `collection.insert_one({})` plus an aggregate
over the named collection. This is logically identical: both feed
exactly one empty document to $project, so literal expressions and
field references (which resolve to missing against an empty doc)
behave the same. The `collection` fixture is function-scoped, so each
test still runs against a fresh single-document collection.

Updates the two shared helpers (execute_expression, execute_project)
that ~205 files inherit, plus two inline call sites in
test_expressions_combination_variables.py. The _with_insert sibling
helpers are unchanged.

Signed-off-by: Yunxuan Shi <yunxuan@amazon.com>
@eerxuan
eerxuan requested a review from a team as a code owner August 6, 2026 23:19
@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: compatibility test, enhancement
Project fields suggested: Component test-coverage · Priority P2 · Effort M · Status Needs Review
Confidence: 0.90 (mixed)

Reasoning

component from path globs (test-coverage); effort from diff stats (22+11 LOC, 2 files); LLM: Removes a hard $documents dependency from shared expression test helpers, unblocking ~205 test files from running against engines that don't implement $documents, with a logically equivalent insert-based scaffold.

If a label is wrong, remove it manually and ping @patty-chow so the rules can be tuned. The bot will not re-label items that already have component labels.

@documentdb-triage-tool documentdb-triage-tool Bot added compatibility test Compatibility test related enhancement New feature or request labels Aug 7, 2026
The $documents-removal commit made execute_expression/execute_project
insert a document and aggregate over the whole collection. Two newly
synced system-variable tests relied on the old $documents:[{}] contract
and broke:

- test_root_empty_document: needs a truly field-less input so $$ROOT is
  {}, but an inserted doc always carries an auto _id. It now shapes its
  own pipeline ($replaceWith:{$literal:{}}) instead of the shared helper.
- test_now_identical_across_getmore_batches: pre-loads 300 docs, so the
  whole-collection helper emitted 300 rows. It now uses an inline
  pipeline with $limit:1 to collapse to the single expected row.

The shared helpers stay on plain insert_one({}) so the ~359 literal
expression call sites gain no $replaceWith/$limit dependency.

Signed-off-by: Yunxuan Shi <yunxuan@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compatibility test Compatibility test related enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant