From 335092d5d91d170feee09bce7d35c77cbdc7ae30 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 27 May 2026 12:52:54 -0700 Subject: [PATCH 1/2] Add section 18 in test coverage Signed-off-by: Alina (Xi) Li --- docs/testing/TEST_COVERAGE.md | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/testing/TEST_COVERAGE.md b/docs/testing/TEST_COVERAGE.md index 75a34080..eba9f397 100644 --- a/docs/testing/TEST_COVERAGE.md +++ b/docs/testing/TEST_COVERAGE.md @@ -417,6 +417,43 @@ For each invalid_type in [string, object, array, ...]: --- +### 18. Accumulator Coverage + +**Rule**: Each accumulator must be tested for its expression error propagation, empty-group result, order dependence, and sibling-accumulator interactions. Tests live under + `tests/core/operator/accumulators/$accumulator/`. Sibling-accumulator interactions live in `tests/core/operator/accumulators/test_accumulators_$op_integration.py`. + + The expression-form of dual-form operators (`$max`, `$min`, `$sum`, `$avg`, `$first`, `$last`, etc.) is tested separately under `tests/core/operator/expressions/accumulator/$op/` and is out of scope for the + accumulator-form file. + + **Expression Error Propagation**: + Errors raised during sub-expression evaluation propagate through the accumulator without being caught: + - `{$op: {$divide: [1, "$v"]}}` → `CONVERSION_FAILURE_ERROR` (field violation) + - `{$op: {$divide: ["$v", 0]}}` → `DIVIDE_BY_ZERO_V2_ERROR` (literal violation) + + **Empty-Group Behavior**: + Each accumulator defines a result for an empty group (zero matching documents). Verify the documented value for `{$group: {_id: null, r: {$op: ...}}}` against an empty collection. Result varies per accumulator + (e.g. 0, null, [], {}) — refer to the accumulator's spec. + + **Order Dependence**: + Some accumulators are order-dependent (their result depends on input order); others are order-independent. Verify per accumulator which category it belongs to per its spec, and: + + - For order-dependent accumulators, tests asserting a specific result must include a preceding `$sort`. Tests without `$sort` are flaky. (e.g. $first) + - For order-independent accumulators, the result must be the same regardless of input order. Verify this by running the same input twice with different `$sort` directions and asserting identical results. + + **Tested in Other Folders** (in scope, but add under a different folder): + - **Host-stage compatibility** — when adding a new accumulator, add one smoke case for each host stage that supports it (`$group`, `$bucket`, `$bucketAuto`, `$setWindowFields`) under that stage's folder + (`stages/$stage/`), per the container-features rule (one test per sub-feature, no edge cases). Edge cases that are genuinely accumulator-specific stay in `accumulators/$op/`. + - **Stage-level error codes** (e.g. `$bucketAuto` wrapping `DIVIDE_BY_ZERO_V2_ERROR` as `BadValue`) — under `stages/bucketAuto/`, parameterized over a representative accumulator. + + ** Scope that Covered by Other rules**: + - **Numeric equivalence in grouping** (used by `$addToSet`, `$setUnion`) — covered by §9 Numeric Equivalence in Grouping/Comparison. + - **Output type validation** — covered by §1 Data Type Coverage. + + **Out of Scope**: + - **BSON comparison ordering** (used by `$max`/`$min`/`$top`/`$bottom`) — `bson_types/test_bson_types_ordering.py`; per-accumulator coverage limited to a small wiring sample. + +--- + ## Test Category Checklist For any DocumentDB feature, ensure coverage of: From 571d86e72a2d037371a32a7bf44131f256b081e6 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 27 May 2026 14:10:53 -0700 Subject: [PATCH 2/2] exclude Code() as well Signed-off-by: Alina (Xi) Li --- docs/testing/TEST_COVERAGE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/testing/TEST_COVERAGE.md b/docs/testing/TEST_COVERAGE.md index eba9f397..e0fc1fe8 100644 --- a/docs/testing/TEST_COVERAGE.md +++ b/docs/testing/TEST_COVERAGE.md @@ -451,6 +451,7 @@ For each invalid_type in [string, object, array, ...]: **Out of Scope**: - **BSON comparison ordering** (used by `$max`/`$min`/`$top`/`$bottom`) — `bson_types/test_bson_types_ordering.py`; per-accumulator coverage limited to a small wiring sample. + - **JavaScript Code type** — the BSON `Code` type is deprecated; accumulator tests should not include `Code` constant or `Code`-valued field tests. ---