-
Notifications
You must be signed in to change notification settings - Fork 9
test(e2e): declarative YAML metric-test rig (replaces the CSV rig) #1380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mitasovr
merged 14 commits into
constructorfabric:main
from
mitasovr:claude/festive-nobel-487399
Jun 23, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2787999
test(e2e): collaboration metric coverage + declarative YAML fixture f…
7a2275c
test(e2e): implement the declarative YAML rig + specs + authoring skill
6752c46
Merge remote-tracking branch 'upstream/main' into claude/festive-nobe…
5487473
docs(e2e): document the CEL assert bindings + their code source
484e220
refactor(e2e): rename fixtures/ → specs/ + document CEL in the README
1fbacb4
fix(e2e): address CodeRabbit review — selector/resolver/coercion hard…
7fb42a3
refactor(e2e): drop find $-operators (CEL is the only expr language)
577cb12
docs(e2e): skill tweaks from review (@ktursunov)
ea0d208
Merge remote-tracking branch 'upstream/main' into claude/festive-nobe…
c078457
Merge branch 'main' into claude/festive-nobel-487399
mitasovr e52b4e2
fix(e2e): more review fixes (@ktursunov, CodeRabbit)
a3fa8cd
Merge remote-tracking branch 'origin/claude/festive-nobel-487399' int…
9eead95
Merge branch 'main' into claude/festive-nobel-487399
mitasovr 1567cb0
Merge branch 'main' into claude/festive-nobel-487399
mitasovr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| --- | ||
| name: metric-e2e-test | ||
| description: "Author and validate declarative YAML e2e tests for analytics metrics (src/ingestion/tests/e2e/specs/*.test.yaml). Use when asked to write/scaffold/validate an e2e test for a metric, seed bronze data for a test, add a fixture for a dashboard metric, or check a *.test.yaml. Covers schemas/, templates/, $ref+sibling composition, bronze records with duplicates, the batch endpoint POST /v1/metrics/queries, and expect rules (in / mongo-style find / equal subset / CEL assert)." | ||
| disable-model-invocation: false | ||
| user-invocable: true | ||
| allowed-tools: Bash, Read, Write, Edit, Glob, Grep | ||
| --- | ||
|
|
||
| # Author a metric e2e test (declarative YAML) | ||
|
|
||
| This skill writes and validates `*.test.yaml` fixtures that drive the full | ||
| `bronze → dbt silver → gold view → analytics-api` path and assert the result. | ||
|
|
||
| ## Source of truth (reference — open only if you need the detail) | ||
|
|
||
| This skill is self-contained for authoring. Consult these only when you need the | ||
| precise algorithm/DoD, or when this file and the spec disagree (the spec wins) — | ||
| no need to load them every time: | ||
|
|
||
| - FEATURE: [docs/domain/bronze-to-api-e2e/specs/feature-yaml-rig/FEATURE.md](../../../docs/domain/bronze-to-api-e2e/specs/feature-yaml-rig/FEATURE.md) — flows, the `resolve` algorithm, the expect engine, DoD. | ||
| - DESIGN: [docs/domain/bronze-to-api-e2e/specs/DESIGN.md](../../../docs/domain/bronze-to-api-e2e/specs/DESIGN.md) — principles `record-composition`, `schema-is-truth`; components `ref-resolver`, `schema-validator`, `expect-engine`. | ||
|
|
||
| ## Commands | ||
|
|
||
| - `/metric-e2e-test create <name> --metric <uuid> --tables <t1,t2>` — scaffold a new `<name>.test.yaml` (+ any missing `schemas/` and `templates/`). | ||
| - `/metric-e2e-test validate <path>` — resolve refs, schema-validate records, lint `cases`/`expect` without running ClickHouse. | ||
|
|
||
| (Plain prose like "write an e2e test for the emails-sent metric" triggers the same flow.) | ||
|
|
||
| ## File layout | ||
|
|
||
| ``` | ||
| src/ingestion/tests/e2e/specs/ | ||
| schemas/<db>.<table>.yaml # one JSON schema per bronze table (all real columns) | ||
| templates/<group>.yaml # reusable records (people, m365_email, …) | ||
| <name>.test.yaml # the test (discovered by the *.test.yaml suffix) | ||
| ``` | ||
|
|
||
| Files under `schemas/` and `templates/` are NOT tests (no `cases`) and are skipped by discovery. | ||
|
|
||
| ## The format | ||
|
|
||
| ### Records, `$ref`, and overrides | ||
|
|
||
| A record is a field map. It may carry `$ref: "<file>#/<json-pointer>"` to inherit | ||
| from another record; **sibling keys override the base** (closest wins). Paths are | ||
| relative to the file the `$ref` is written in; a `$ref` resolves in the context of | ||
| its own file (a `#/...` ref inside `templates/people.yaml` stays local to it). | ||
|
|
||
| ```yaml | ||
| # templates/m365_email.yaml | ||
| templates: | ||
| m365_email: # base — carries EVERY schema column (unused = null) | ||
| _airbyte_raw_id: "00000000-0000-0000-0000-000000000000" | ||
| _airbyte_extracted_at: "2026-01-05T00:00:00" | ||
| _airbyte_meta: "{}" | ||
| _airbyte_generation_id: 0 | ||
| tenant_id: "00000000-0000-0000-0000-000000000000" | ||
| source_id: m365-test | ||
| sendCount: null | ||
| # … every other column … | ||
| alice_email: | ||
| $ref: "#/templates/m365_email" | ||
| userPrincipalName: alice@example.com | ||
| ``` | ||
|
|
||
| ### `bronze` — what to seed | ||
|
|
||
| Keyed by table name (the key IS the table + which schema validates it). Each row = | ||
| `$ref` to a record + the fields under test. After resolution the row is **padded to | ||
| the full schema** (missing columns → null) and validated (`additionalProperties:false` | ||
| catches typos). Two identical rows = a real Airbyte re-sync duplicate (must dedup). | ||
|
|
||
| ```yaml | ||
| bronze: | ||
| bronze_m365.email_activity: | ||
| - $ref: templates/m365_email.yaml#/templates/alice_email | ||
| reportRefreshDate: "2026-01-05" | ||
| unique_key: m365-alice-20260105 | ||
| sendCount: 40 | ||
| - $ref: templates/m365_email.yaml#/templates/alice_email # duplicate → must NOT double | ||
| reportRefreshDate: "2026-01-05" | ||
| unique_key: m365-alice-20260105 | ||
| sendCount: 40 | ||
| ``` | ||
|
|
||
| ### `cases` — batch request + expectations | ||
|
|
||
| ```yaml | ||
| cases: | ||
| - name: <what this proves> | ||
| request: | ||
| url: /v1/metrics/queries | ||
| method: POST | ||
| body: | ||
| queries: | ||
| - id: collaboration # echoed back as results[].id | ||
| metric_id: <uuid> | ||
| $top: 50 | ||
| $filter: "person_id eq 'alice@example.com' and metric_date ge '2026-01-01' and metric_date le '2026-01-31'" | ||
| $orderby: metric_key | ||
| expect: | ||
| - assert: "status == 200" # HTTP code of the batch | ||
| - in: collaboration | ||
| assert: "result.status == 'ok'" # this query's own status (batch HTTP stays 200 on per-query error) | ||
| - in: collaboration | ||
| find: { metric_key: m365_emails_sent } # mongo-style selector → exactly one row (`it`) | ||
| equal: { value: 40, median: 20, range_min: 10, range_max: 40 } # subset; unlisted fields ignored | ||
| - in: collaboration | ||
| assert: "size(items) == 20" | ||
| - in: collaboration | ||
| find: { metric_key: slack_dm_ratio } | ||
| equal: { value: null } | ||
| ``` | ||
|
|
||
| - `in` — select the batch result by request `id` (omit when there is one query). | ||
| - `find` — exact field equality: `{field: value}` (selects one row). Anything richer (inequalities, counts, predicates) goes in a CEL `assert` — there is no second selector language. | ||
| - `equal` — subset equality; use for exact ints / `null`. | ||
| - `assert` — CEL boolean; use for inequalities / floats / counts. | ||
|
|
||
| ### `assert` (CEL) bindings | ||
|
|
||
| Assembled in `e2e_lib/expect_engine.py::evaluate_case` (the `bindings` dict), | ||
| converted to CEL in `_eval_cel`: | ||
|
|
||
| | Binding | Value | Present when | | ||
| |---|---|---| | ||
| | `it` | the single row matched by `find` | only with `find` (else `null` → `it.x` errors) | | ||
| | `items` | the selected result's `items` array | a result is selected (`in` or sole query) | | ||
| | `result` | the selected result `{id, status, metric_id, items, page_info}` | a result is selected | | ||
| | `results` | the full `results[]` of the batch | always | | ||
| | `status` | the batch HTTP status code (int) | always | | ||
|
|
||
| CEL is strictly typed and won't compare an `int` to a `double` — when a metric | ||
| value may be integral (`40`) and you compare against a fractional literal, cast it: | ||
| `double(it.value) > 39.5`. `status`/`size(...)` are ints (compare with int literals). | ||
| For exact / `null`, use `equal` (Python `==`), not `assert`. CEL macros available: | ||
| `size()`, `has()`, `.exists()`, `.all()`, `.map()`, `.filter()`. | ||
|
|
||
| ## Scaffolding a new test | ||
|
|
||
| 1. **Resolve the metric_id and its shape.** Find it in the seed catalog | ||
| (`grep -rn "<label>" src/backend/services/analytics-api/src/migration/*.rs`) and | ||
| the live `query_ref` rewrite for that metric. Note whether it returns a bullet | ||
| (`metric_key`/`value`/`median`/`range_*`) or per-person rows, and whether `median` | ||
| is company-wide (Team bullet) or team/org_unit (IC bullet). | ||
| 2. **Ensure a schema file per table.** If `schemas/<db>.<table>.yaml` is missing, | ||
| generate it from the REAL table (do not invent columns): | ||
| ```bash | ||
| export KUBECONFIG=<path to your dev cluster kubeconfig> | ||
| kubectl exec -n insight insight-clickhouse-0 -- clickhouse-client \ | ||
| --query "SELECT name, type FROM system.columns WHERE database='<db>' AND table='<table>' ORDER BY position FORMAT TSV" | ||
| ``` | ||
| Map CH types → JSON-schema: `Nullable(String)`→`[string,"null"]`, `Decimal/Float/Int`→`[number,"null"]` (`UInt*` non-null →`integer`), `Bool`→`[boolean,"null"]`, `DateTime*`→`{string, format: date-time}`, `JSON`→`[object,"null"]`. Set `additionalProperties: false` and list **every** column (incl. `_airbyte_*`). | ||
| 3. **Ensure base + variant templates.** The base record must contain every schema | ||
| column (incl. `_airbyte_*` — transforms depend on them); variants `$ref` the base | ||
| and override identity only. | ||
| 4. **Write `bronze`** with `$ref`+overrides; include a duplicate row when the metric | ||
| should dedup. | ||
| 5. **Write `cases`**: one batch `query` per metric under test; assert the few fields | ||
| that matter via `find`+`equal`, and counts/inequalities via `assert`. | ||
| 6. **Pick numbers that distinguish behaviors** — e.g. for a median test use values | ||
| where median ≠ mean (`[40,20,10]` → median 20, mean 23.33) so the test actually | ||
| pins the aggregation. | ||
|
|
||
| ## Validating a test (no ClickHouse needed) | ||
|
|
||
| - Every `$ref` resolves (file + pointer exist); no cycles. | ||
| - Each resolved+padded bronze record validates against `schemas/<table>.yaml` | ||
| (`additionalProperties:false`). | ||
| - Base templates cover **all** schema columns (quick check): | ||
| ```bash | ||
| python3 - <<'PY' | ||
| import yaml | ||
| s=set(yaml.safe_load(open("schemas/<db>.<table>.yaml"))["schemas"]["<db>.<table>"]["properties"]) | ||
| t=set(yaml.safe_load(open("templates/<group>.yaml"))["templates"]["<base>"]); t.discard("$ref") | ||
| print("missing", sorted(s-t), "extra", sorted(t-s)) | ||
| PY | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| ``` | ||
| - Each `expect` rule has `find`+(`equal`|`assert`) or a bare `assert`; `in` matches a | ||
| declared query `id`; CEL expressions parse. | ||
|
|
||
| ## Running | ||
|
ktursunov marked this conversation as resolved.
|
||
|
|
||
| ```bash | ||
| cd src/ingestion/tests/e2e | ||
| ls specs/*.test.yaml # list existing tests | ||
| ./e2e.sh test # run all tests (specs/ + meta/) | ||
| ./e2e.sh test -k <name> # run one test by name | ||
| ./e2e.sh test -k <name> -v # verbose (per-step log) | ||
| ./e2e.sh down # tear down the e2e compose stack + volumes (full reset) | ||
| ``` | ||
|
|
||
| `<name>` is the file stem (e.g. `collab_emails_sent` for `specs/collab_emails_sent.test.yaml`). Warm re-runs are fine — the session resets the multi-reader collab silver/staging tables at start (conftest). `./e2e.sh down` is only the e2e compose teardown (it is not a deploy), for when you want a fully clean ClickHouse. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create script that will query all existing metrics and their final schemas? Probably not in this pr