Skip to content

feat: report sums over value-object members and derived measures - #563

Merged
dmealing merged 6 commits into
mainfrom
fm/mo-report-measures-money
Nov 13, 2026
Merged

dmealing merged 6 commits into
mainfrom
fm/mo-report-measures-money

Conversation

@dmealing

@dmealing dmealing commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Value-object members in report @of (FR-044 R12). A dimension or measure @of can name Entity.field.member for a value object stored with @storage: flattened, and the report reads that member's own column. A sum/avg/min/max over a numeric member loads only when the report also groups by each non-numeric member of the same value object (its currency). Refused at load: jsonb value-object members, unknown members, and deeper paths. The Cube exporter refuses member paths. Loader and report-shape rules are implemented in TypeScript, C#, Java and Python, with conformance fixtures.
  • measure.derived with @expr (FR-044 R13). A new measure subtype computes add, subtract, multiply or divide over two operands. Each operand is a numeric measure.aggregate or measure.ratio on the entity, a numeric attribute dimension the report lists, or a numeric literal. divide returns null on a zero divisor. meta migrate lowers it on Postgres, SQLite, MySQL and D1, and the Cube exporter writes it as a number member. Loader rule M11 and report rule R13 apply in every loader port, with a conformance fixture per refusal.
  • Agent guidance and generated docs. The meta init agent guide and the metaobjects-authoring skill now route grouped totals and dashboard reports to object.report before the @sql escape. The reference docs, the metamodel docs fixtures and the CHANGELOG cover the new vocabulary.

Vocabulary changes are additive. metamodelVersion and expected-registry.json are updated for the new measure.derived subtype.

Validation

Reports this covers

A large-application smoke test wrote its dashboard reports in the reporting vocabulary and
fell back to a hand-written @sql view for five of them. This PR moves two onto the vocabulary,
and a scratch copy of that app returns the same rows as the original @sql on Postgres and SQLite:

  • Revenue by client by month: a sum of Payment.amount.amount (a flattened Money) grouped by
    its currency member and by client, through the R12 member path.
  • Member utilization: billable hours divided by capacity hours (weekly capacity x 52 / 12),
    through measure.derived.

Budget burn stays @sql in that app, because its budget is a jsonb value object and its cost is
hours x rate (a product measure). Both are out of scope here. The other remaining @sql cases
(a calendar-month spine with no facts, product measures, a member read out of a jsonb value
object) are unchanged.

Risk Assessment

✅ Low: The C#, Java and Python ports match the TypeScript reference: loader rules M10/M11, R12 and R13, @of member resolution, and measure.derived typing. The fixtures and docs match the code. The only issue found is a misplaced doc comment.

Testing

I drove the built meta CLI against disposable projects outside the worktree. meta migrate created the report views on SQLite and on a throwaway Postgres 16 container, and I seeded rows and queried the views. A third container, MySQL 8.4, ran the view SQL for the divide-parentheses fix. Sums over the flattened Money member, utilization, non-billable hours, billable share and budget burn all matched hand-calculated values. Four adversarial variants were refused by the loader. The full scripts/ci-local.sh run (all ports, Testcontainers lanes, the gates lane, the cube live check and the mutation gate) exited 0. The configured ts-fast/ts-unit baseline had already passed. I also ran the two targeted codegen test files, 16 tests, all passing. The change has no UI, so there are no screenshots. I stopped the Postgres and MySQL containers I started.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Sum of a flattened Money member by currency, kind and month builds a view that returns the right totals (SQLite and Postgres) ✅ pass live scenario-queries.txt, scenario-pg-queries.txt: USD Jan = 300.30 (Postgres exact; SQLite 300.2999… float noise), EUR Jan = 50, USD Feb = 10; largest and average also correct
Utilization percent = billable hours × 100 / (weekly capacity × 52 / 12), and a member with zero capacity gives NULL ✅ pass live scenario-queries.txt, scenario-pg-queries.txt: Ann (40 h/week) has capacity 173.33, utilization 57.69, non-billable 30, billable share 76.92. Bob (0 capacity) has utilization NULL.
Budget burn = cost / budget, with NULL for a NULL or zero budget ✅ pass live scenario-queries.txt, scenario-pg-queries.txt: project A 250/1000 = 0.25; NULL budget and zero budget both give NULL, with no divide-by-zero error.
Adversarial: summing a Money member without grouping by its currency is refused ✅ pass live adv-nocurrency run: ERR_INVALID_REPORT … would be combined. List an attribute dimension … Payment.amount.currency
Adversarial: invalid derived expressions are refused (unknown operand, derived-of-derived, non-numeric literal) ✅ pass live adv-unknownref, adv-derivedofderived, adv-divbyzeroliteral runs each ended in ERR_INVALID_MEASURE with an actionable message
MySQL: a derived divide over a difference of integral sums keeps its dividend parentheses (review-1 fix) ✅ pass live mysql-result.txt: the view returns 7.0000, which is (170-100)/10; the wrong precedence would give 160. The SQL in mysql-hoursgap-view.sql shows (CAST(SUM…) - CAST(SUM…)) / NULLIF(…).
Full regression: complete scripts/ci-local.sh across all ports and gates ✅ pass live ci-local-full.log ends with EXIT 0; 52 steps passed, none failed
Evidence: SQLite view results, checked against the hand-computed oracle
== v_revenuebymonth
['currency', 'kind', 'received_on_month', 'revenue', 'largest', 'average_payment', 'payments']
('EUR', 'card', '2026-01-01', 50, 50, 50.0, 1)
('USD', 'card', '2026-01-01', 300.29999999999995, 200.2, 150.14999999999998, 2)
('USD', 'card', '2026-02-01', 10, 10, 10.0, 1)
== v_currencymix
['kind', 'currencies', 'payments']
('card', 2, 4)
== v_memberutilization
['member_id', 'member_name', 'weekly_capacity_hours', 'worked_on_month', 'total_hours', 'billable_hours', 'capacity_hours', 'utilization', 'non_billable_hours', 'billable_share_pct']
(1, 'Ann', 40, '2026-10-01', 130, 100, 173.33333333333334, 57.692307692307686, 30.0, 76.92307692307693)
(2, 'Bob', 0, '2026-10-01', 8, 8, 0.0, None, 0.0, 100.0)
== v_projectburn
['project_id', 'project_budget', 'cost', 'budget_burn']
(1, 1000, 250, 0.25)
(2, None, 50, None)
(3, 0, 20, None)
Evidence: Postgres view results
== v_revenuebymonth
Timing is on.
Border style is 2.
Line style is unicode.
Null display is "(null)".
psql:~/.psqlrc:19: error: \pset: unknown option: unicode
Pager is always used.
EUR|card|2026-01-01|50.00|50.00|50.0000000000000000|1
USD|card|2026-01-01|300.30|200.20|150.1500000000000000|2
USD|card|2026-02-01|10.00|10.00|10.0000000000000000|1
Time: 1.363 ms
== v_memberutilization
Timing is on.
Border style is 2.
Line style is unicode.
Null display is "(null)".
psql:~/.psqlrc:19: error: \pset: unknown option: unicode
Pager is always used.
1|Ann|40.00|2026-10-01|130.00|100.00|173.3333333333333333|57.6923076923076923|30.00|76.92307692307692307700
2|Bob|0.00|2026-10-01|8.00|8.00|0.00000000000000000000|(null)|0.00|100.00000000000000000000
Time: 1.592 ms
== v_projectburn
Timing is on.
Border style is 2.
Line style is unicode.
Null display is "(null)".
psql:~/.psqlrc:19: error: \pset: unknown option: unicode
Pager is always used.
1|1000.00|250.00|0.25000000000000000000
2|(null)|50.00|(null)
3|0.00|20.00|(null)
Time: 1.338 ms
Evidence: MySQL result for (170-100)/10, expected 7.0000

project_id all_hours billed_hours hours_gap_per_budget 1 170 100 7.0000

project_id	all_hours	billed_hours	hours_gap_per_budget
1	170	100	7.0000
Evidence: Full ci-local.sh run (exit 0)
metaobjects local CI  (mode: full — all ports + reactor + docker, 8 lanes at once)

── prelude (serial): install, drift gates, workspace build ──

── ▶ dependencies installed ──────────────────────────────────────────────
bun install v1.3.14 (0d9b296a)

Checked 564 installs across 593 packages (no changes) [7.00ms]
── ✓ dependencies installed (0s)

── ▶ doc-template drift ──────────────────────────────────────────────
synced: {run-worktree}/templates/docs/entity-page.md.mustache -> {run-worktree}/server/typescript/packages/codegen-ts/templates/docs/entity-page.md.mustache
synced: {run-worktree}/templates/docs/template-page.md.mustache -> {run-worktree}/server/typescript/packages/codegen-ts/templates/docs/template-page.md.mustache
synced: {run-worktree}/templates/api/agent-api.md.mustache -> {run-worktree}/server/typescript/packages/codegen-ts/templates/api/agent-api.md.mustache
synced: {run-worktree}/templates/api/entity-api.md.mustache -> {run-worktree}/server/typescript/packages/codegen-ts/templates/api/entity-api.md.mustache
synced: {run-worktree}/templates/api/index.md.mustache -> {run-worktree}/server/typescript/packages/codegen-ts/templates/api/index.md.mustache
generated {run-worktree}/server/typescript/packages/codegen-ts/src/render-engine/embedded-templates.generated.ts (5 template(s): api/agent-api.md, api/entity-api.md, api/index.md, docs/entity-page.md, docs/template-page.md)
doc templates synced from canonical root: {run-worktree}/templates (docs api)
── ✓ doc-template drift (0s)

── ▶ embedded-library drift ──────────────────────────────────────────────
wrote 6 embedded library file(s) + 2 manifest(s) to server/typescript/packages/metadata/src/library/embedded-library.generated.ts, server/java/metadata/src/main/java/com/metaobjects/library/EmbeddedLibrary.java and server/csharp/MetaObjects/Library/EmbeddedLibrary.cs
── ✓ embedded-library drift (1s)

── ▶ ts build ──────────────────────────────────────────────
bun install v1.3.14 (0d9b296a)

Checked 564 installs across 593 packages (no changes) [7.00ms]
@metaobjectsdev/forge build: Exited with code 0
@metaobjectsdev/render build: Exited with code 0
@metaobjectsdev/metadata build: Exited with code 0
@metaobjectsdev/sdk build: bundled agent-context → {run-worktree}/server/typescript/packages/sdk/agent-context
@metaobjectsdev/conformance build: Exited with code 0
@metaobjectsdev/runtime-web build: Exited with code 0
@metaobjectsdev/sdk build: Exited with code 0
@metaobjectsdev/docs-site build: Exited with code 0
@metaobjectsdev/angular build: Exited with code 0
@metaobjectsdev/tanstack build: Exited with code 0
@metaobjectsdev/react build: Exited with code 0
@metaobjectsdev/migrate-ts build: Exited with code 0
@metaobjectsdev/runtime-ts build: Exited with code 0
@metaobjectsdev/ai-runtime build: Exited with code 0
@metaobjectsdev/codegen-ts build: Exited with code 0
@metaobjectsdev/codegen-ts-angular build: Exited with code 0
@metaobjectsdev/codegen-ts-react build: Exited with code 0
@metaobjectsdev/codegen-ts-tanstack build: Exited with code 0
@metaobjectsdev/test-generators build: Exited with code 0
@metaobjectsdev/cli build: Exited with code 0
── ✓ ts build (6s)
  ▸ started Postgres sidecar 'metaobjects-ci-sidecar-kowEie'
    METAOBJECTS_TEST_PG_URL -> 127.0.0.1:36179

── lanes (up to 8 at once; each lane's log prints when it finishes) ──
  ▸ lane java started
  ▸ lane python started
  ▸ lane mutation started
  ▸ lane csharp started
  ▸ lane ts-integ started
  ▸ lane ts started
  ▸ lane cube started
  ▸ lane gates started

╔═════════════ lane: gates ═════════════

── ▶ leak-scan (security) ──────────────────────────────────────────────
leak-scan: clean
── ✓ leak-scan (security) (0s)

── ▶ pom-version parity ──────────────────────────────────────────────
check-pom-versions: ✓ 3 parent + 1 property pom(s) match reactor 8.3.0
── ✓ pom-version parity (1s)

── ▶ bun-version parity ──────────────────────────────────────────────
check-bun-version: bun 1.3.14 matches the workflow pin.
── ✓ bun-version parity (0s)

── ▶ uv.lock version parity ──────────────────────────────────────────────
check-uv-lock-version: uv.lock agrees with pyproject.toml (1.3.0)
── ✓ uv.lock version parity (0s)

── ▶ publish-intent parity ──────────────────────────────────────────────
publish-intent parity: OK (lockstep 1.3.0; 2 declared source-only)
── ✓ publish-intent parity (0s)

── ▶ publish-set parity ──────────────────────────────────────────────
   1. @metaobjectsdev/metadata  (server/typescript/packages/metadata)
   2. @metaobjectsdev/render  (server/typescript/packages/render)
   3. @metaobjectsdev/docs-site  (server/typescript/packages/docs-site)
   4. @metaobjectsdev/migrate-ts  (server/typescript/packages/migrate-ts)
   5. @metaobjectsdev/codegen-ts  (server/typescript/packages/codegen-ts)
   6. @metaobjectsdev/runtime-ts  (server/typescript/packages/runtime-ts)
   7. @metaobjectsdev/sdk  (server/typescript/packages/sdk)
   8. @metaobjectsdev/runtime-web  (client/web/packages/runtime-web)
   9. @metaobjectsdev/codegen-ts-react  (server/typescript/packages/codegen-ts-react)
  10. @metaobjectsdev/codegen-ts-tanstack  (server/typescript/packages/codegen-ts-tanstack)
  11. @metaobjectsdev/react  (client/web/packages/react)
  12. @metaobjectsdev/tanstack  (client/web/packages/tanstack)
  13. @metaobjectsdev/cli  (server/typescript/packages/cli)
  14. @metaobjectsdev/ai-runtime  (server/typescript/packages/ai-runtime)
publish set: OK (lockstep 1.3.0; 14 packages, tier-ordered, closed over sibling deps)
ok:   happy path: private + off-lockstep excluded, order [metadata, render, docs-site, cli]
ok:   untiered member: threw on "publish order undeclared"
ok:   unclosed set: threw on "not closed over its own runtime dependencies"
ok:   inverted tier order: threw on "publishes a dependency AFTER its dependent"
ok:   regression: docs-site (#2) publishes before cli (#12) in the real tree
ok:   regression: docs-site has a declared tier

publish-set tests: all passed
── ✓ publish-set parity (0s)

── ▶ no committed pre-release version ──────────────────────────────────────────────
check-no-prerelease-versions: ✓ no pre-release version in any version d

... [5394822 bytes truncated] ...

pression
src/super-resolve.ts:173:9
-       if (referrerScope === undefined) return undefined;
+       if (false) return undefined;

[Survived] ConditionalExpression
src/super-resolve.ts:175:9
-       if (parsed === undefined) return undefined; // degenerate (empty segment)
+       if (false) return undefined; // degenerate (empty segment)

[Survived] ConditionalExpression
src/super-resolve.ts:177:9
-       if (current === undefined) return undefined;
+       if (false) return undefined;

[Survived] ConditionalExpression
src/super-resolve.ts:195:9
-       if (found !== undefined) return found;
+       if (true) return found;

[Survived] ArrayDeclaration
src/super-resolve.ts:264:31
-     const pending: MetaData[] = [];
+     const pending: MetaData[] = ["Stryker was here"];

[Survived] ConditionalExpression
src/super-resolve.ts:266:9
-       if (n.superRef !== undefined) pending.push(n);
+       if (true) pending.push(n);

[Survived] ConditionalExpression
src/super-resolve.ts:278:11
-         if (e instanceof RefOverDropError) return "over-drop";
+         if (true) return "over-drop";

[Survived] ConditionalExpression
src/super-resolve.ts:284:40
-       if (node.superRef === undefined || node.superResolved !== undefined) return;
+       if (node.superRef === undefined || false) return;

[Survived] ConditionalExpression
src/super-resolve.ts:285:9
-       if (attempted.has(node)) return; // already resolved-or-failed this pass — never re-report
+       if (false) return; // already resolved-or-failed this pass — never re-report

[Survived] StringLiteral
src/super-resolve.ts:287:69
-       const effectivePkg = node.package ?? node.fileDefaultPackage ?? "";
+       const effectivePkg = node.package ?? node.fileDefaultPackage ?? "Stryker was here!";

[Survived] ConditionalExpression
src/super-resolve.ts:293:9
-       if (isChildTargetingRef(node.superRef)) {
+       if (true) {

[Survived] ConditionalExpression
src/super-resolve.ts:295:11
-         if (parsed !== undefined) {
+         if (true) {

[Survived] ConditionalExpression
src/super-resolve.ts:297:13
-           if (ownerNode !== undefined && ownerNode !== "over-drop") resolveNode(ownerNode);
+           if (true) resolveNode(ownerNode);

[Survived] LogicalOperator
src/super-resolve.ts:297:13
-           if (ownerNode !== undefined && ownerNode !== "over-drop") resolveNode(ownerNode);
+           if (ownerNode !== undefined || ownerNode !== "over-drop") resolveNode(ownerNode);

[Survived] ConditionalExpression
src/super-resolve.ts:297:13
-           if (ownerNode !== undefined && ownerNode !== "over-drop") resolveNode(ownerNode);
+           if (true && ownerNode !== "over-drop") resolveNode(ownerNode);

[Survived] ConditionalExpression
src/super-resolve.ts:297:40
-           if (ownerNode !== undefined && ownerNode !== "over-drop") resolveNode(ownerNode);
+           if (ownerNode !== undefined && true) resolveNode(ownerNode);

[Survived] StringLiteral
src/super-resolve.ts:297:54
-           if (ownerNode !== undefined && ownerNode !== "over-drop") resolveNode(ownerNode);
+           if (ownerNode !== undefined && ownerNode !== "") resolveNode(ownerNode);

[Survived] ObjectLiteral
src/super-resolve.ts:332:19
-             target: { type: target.type, subType: target.subType },
+             target: {},

[Survived] ObjectLiteral
src/super-resolve.ts:333:21
-             referrer: { type: node.type, subType: node.subType },
+             referrer: {},

[Survived] StringLiteral
src/super-resolve.ts:351:15
-           kind: "unresolved",
+           kind: "",

Ran 0.98 tests per mutant on average.
--------------------|------------------|----------|-----------|------------|----------|----------|
                    | % Mutation score |          |           |            |          |          |
File                |  total | covered | # killed | # timeout | # survived | # no cov | # errors |
--------------------|--------|---------|----------|-----------|------------|----------|----------|
All files           |  55.40 |   55.40 |      952 |        27 |        788 |        0 |        0 |
 parser-core.ts     |  46.03 |   46.03 |      481 |         0 |        564 |        0 |        0 |
 provider.ts        |  62.12 |   62.12 |       40 |         1 |         25 |        0 |        0 |
 serializer-json.ts |  66.98 |   66.98 |      197 |        18 |        106 |        0 |        0 |
 subtype-rules.ts   |  69.23 |   69.23 |      113 |         4 |         52 |        0 |        0 |
 super-resolve.ts   |  75.30 |   75.30 |      121 |         4 |         41 |        0 |        0 |
--------------------|--------|---------|----------|-----------|------------|----------|----------|
19:25:34 (2243457) INFO MutationTestReportHelper Final mutation score of 55.40 is greater than or equal to break threshold 35
19:25:35 (2243457) INFO HtmlReporter Your report can be found at: file://{run-worktree}/server/typescript/packages/metadata/reports/mutation/mutation.html
19:25:35 (2243457) INFO MutationTestExecutor Done in 21 minutes and 30 seconds.
── ✓ completeness-gate (mutation) (21m31s)
╚═════════════ lane: mutation — ✓ 21m31s ═════════════

══════════════════════ SUMMARY ══════════════════════
  ✓ dependencies installed
  ✓ doc-template drift
  ✓ embedded-library drift  (1s)
  ✓ ts build  (6s)
  ✓ java-reactor (install)  (5m17s)
  ✓ conformance: python  (4m02s)
  ✓ integration-tests (python)  (2m07s)
  ✓ completeness-gate (mutation)  (21m31s)
  ✓ conformance: csharp  (2m59s)
  ✓ integration-tests (csharp)  (11m54s)
  ✓ migrate-ts real-PG suite  (1m11s)
  ✓ runtime-ts real-PG dialect matrix  (2s)
  ✓ prisma real-PG round trip  (13s)
  ✓ brownfield recipe real-PG check  (5s)
  ✓ integration-tests (ts)  (7m53s)
  ✓ ts typecheck  (33s)
  ✓ conformance: typescript  (7m40s)
  ✓ ts unit suites  (35s)
  ✓ integration-tests (kotlin)  (11m48s)
  ✓ integration-tests (java)  (4m10s)
  ✓ showcase current in all ports  (2m12s)
  ✓ cube-model live check (Cube + Postgres)  (3m27s)
  ✓ leak-scan (security)
  ✓ pom-version parity  (1s)
  ✓ bun-version parity
  ✓ uv.lock version parity
  ✓ publish-intent parity
  ✓ publish-set parity
  ✓ no committed pre-release version
  ✓ script-name hook collisions
  ✓ ci lane selection
  ✓ extract field kinds
  ✓ no-magic gate wired (5 ports)
  ✓ test-file references resolve  (1s)
  ✓ metamodel-version bump
  ✓ positioning claims
  ✓ hosted assess prompt builds
  ✓ migration guides vs registry
  ✓ peer-range bounds
  ✓ owned template copies current
  ✓ reference templates lint
  ✓ shipped doc examples load  (3s)
  ✓ no retired $apiPrefix
  ✓ site payload is true  (51s)
  ✓ site reference is fresh  (1s)
  ✓ release tag gate  (24s)
  ✓ scripts/ typecheck  (9s)
  ✓ requirements ledger verifies  (4s)
  ✓ requirements cover vocabulary  (2s)
  ✓ metamodel scaffolder  (1s)
  ✓ requirement harness
  ✓ fixture-lint
── slowest steps ──
    21m31s  completeness-gate (mutation)
    11m54s  integration-tests (csharp)
    11m48s  integration-tests (kotlin)
     7m53s  integration-tests (ts)
     7m40s  conformance: typescript
     5m17s  java-reactor (install)
     4m10s  integration-tests (java)
     4m02s  conformance: python
     3m27s  cube-model live check (Cube + Postgres)
     2m59s  conformance: csharp
     2m12s  showcase current in all ports
     2m07s  integration-tests (python)
── lanes (wall time, ran 8 at once) ──
    21m31s  mutation
    14m53s  csharp
    11m48s  kotlin-integ
     9m24s  ts-integ
     8m48s  ts
     6m09s  python
     5m17s  java
     4m10s  java-integ
     3m27s  cube
     2m12s  showcase
     1m37s  gates
  total wall time: 21m46s
══════════════════════════════════════════════════════
LOCAL CI PASSED
EXIT 0
Evidence: MySQL view SQL emitted for the fixed divide case
  SELECT
    p.`id` AS `project_id`,
    p.`budget` AS `project_budget`,
    CAST(SUM(t.`hours`) AS SIGNED) AS `all_hours`,
    CAST(SUM(CASE WHEN t.`billable` = TRUE THEN t.`hours` END) AS SIGNED) AS `billed_hours`,
    (CAST(SUM(t.`hours`) AS SIGNED) - CAST(SUM(CASE WHEN t.`billable` = TRUE THEN t.`hours` END) AS SIGNED)) / NULLIF(p.`budget`, 0) AS `hours_gap_per_budget`
  FROM `time_entries` t
  INNER JOIN `projects` p ON p.`id` = t.`project_id`
  GROUP BY p.`id`, p.`budget`

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • 🚨 server/typescript/packages/codegen-ts/src/projection/report-ddl-emit.ts:138 - On MySQL, a derived divide loses its dividend's parentheses and returns a wrong value without any error. realOf() is a no-op on MySQL, so the code decides whether to parenthesise by testing real.startsWith("CAST("). On MySQL an aggregate is CAST(SUM(x) AS SIGNED) when x is an int, long or currency field (castFor/INTEGRAL_SUM). So for divide(subtract(revenue, refunds), budget), with revenue and refunds as sums of int, long or currency fields, the emitter writes CAST(SUM(a) AS SIGNED) - CAST(SUM(b) AS SIGNED) / NULLIF(c, 0). That computes a - b/c, not (a - b)/c. add fails the same way. So does a left operand that starts with a ratio whose numerator is cast, e.g. divide(add(ratio, x), y). Postgres and SQLite are not affected, because realOf always wraps the dividend in CAST there. The MySQL test (report-derived-measures.test.ts:79) covers only a dividend that is not cast, (m.weekly_capacity_hours * 52) / 12. Fix: decide by dialect, not by text prefix, e.g. const dividend = d === "mysql" ? derived(t.left, d, factRef, false) : realOf(derived(t.left, d, factRef), d);. Then add a MySQL test that divides a difference of two integral sums.
  • ⚠️ CHANGELOG.md:14 - The change registers new vocabulary: measure.derived, its @expr, and new descriptions in expected-registry.json. But metamodelVersion stays at 1.3, the value that 1.3.0 shipped with (released 2026-11-11, commit c75c30a; METAMODEL_VERSION = "1.3" in registry-manifest.ts:124). CHANGELOG.md says "If this ships after 1.3.0, the release moves metamodelVersion", but 1.3.0 has already shipped, so the condition is already true. CLAUDE.md says "any change to the registered vocabulary is also a version edit". scripts/check-metamodel-version.mjs compares against the last release tag, so it should require a move to 1.4 once the v1.3.0 tag is present. This worktree has no v1.3.0 tag, which may be why the gate passes here. Choose one: bump now with node scripts/check-metamodel-version.mjs --set 1.4 and state the move in the [Unreleased] entry, or confirm that the bump is deliberately left for the release cut and reword the sentence.
  • ℹ️ server/typescript/packages/metadata/src/core/reporting/report-describe.ts:123 - Adding describeExpr had left the existing JSDoc of describeMeasure stacked above describeExpr's own one-line doc comment, so it documented the wrong function. I moved that JSDoc back above describeMeasure and extended it to cover the derived-measure branch. Only comments changed.

🔧 Fix applied.
📝 2 wording or comment-placement notes left for the author (no fix round spent):

  • ℹ️ server/typescript/packages/metadata/src/core/reporting/report-describe.ts:123 - Adding describeExpr had left the existing JSDoc of describeMeasure stacked above describeExpr's own one-line doc comment, so it documented the wrong function. I moved that JSDoc back above describeMeasure and extended it to cover the derived-measure branch. Only comments changed.
  • ℹ️ server/csharp/MetaObjects/Loader/ValidationPasses.Reporting.cs:1107 - The new XML-doc / Javadoc block for the R12 value-object-units check was inserted in the middle of the existing doc block of CheckReportMeasure / checkReportMeasure. The R3 description ("R3 for one @measures item ... returns null") now sits stacked directly above the R12 doc and documents the wrong method, and CheckReportMeasure / checkReportMeasure itself is left with no doc. The TypeScript and Python ports placed the new helpers before the doc block correctly. Fix: move the R3 doc block down to sit directly above CheckReportMeasure / checkReportMeasure. Sites: server/csharp/MetaObjects/Loader/ValidationPasses.Reporting.cs:1107 (stacked above the R12 summary; method at :1202), server/java/metadata/src/main/java/com/metaobjects/loader/ReportingValidation.java:1192 (stacked above the R12 Javadoc; method at :1300). Comments only, no behavior change.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Sum of a flattened Money member by currency, kind and month builds a view that returns the right totals (SQLite and Postgres) ✅ pass live scenario-queries.txt, scenario-pg-queries.txt: USD Jan = 300.30 (Postgres exact; SQLite 300.2999… float noise), EUR Jan = 50, USD Feb = 10; largest and average also correct
Utilization percent = billable hours × 100 / (weekly capacity × 52 / 12), and a member with zero capacity gives NULL ✅ pass live scenario-queries.txt, scenario-pg-queries.txt: Ann (40 h/week) has capacity 173.33, utilization 57.69, non-billable 30, billable share 76.92. Bob (0 capacity) has utilization NULL.
Budget burn = cost / budget, with NULL for a NULL or zero budget ✅ pass live scenario-queries.txt, scenario-pg-queries.txt: project A 250/1000 = 0.25; NULL budget and zero budget both give NULL, with no divide-by-zero error.
Adversarial: summing a Money member without grouping by its currency is refused ✅ pass live adv-nocurrency run: ERR_INVALID_REPORT … would be combined. List an attribute dimension … Payment.amount.currency
Adversarial: invalid derived expressions are refused (unknown operand, derived-of-derived, non-numeric literal) ✅ pass live adv-unknownref, adv-derivedofderived, adv-divbyzeroliteral runs each ended in ERR_INVALID_MEASURE with an actionable message
MySQL: a derived divide over a difference of integral sums keeps its dividend parentheses (review-1 fix) ✅ pass live mysql-result.txt: the view returns 7.0000, which is (170-100)/10; the wrong precedence would give 160. The SQL in mysql-hoursgap-view.sql shows (CAST(SUM…) - CAST(SUM…)) / NULLIF(…).
Full regression: complete scripts/ci-local.sh across all ports and gates ✅ pass live ci-local-full.log ends with EXIT 0; 52 steps passed, none failed
  • scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchains
  • meta migrate --from-db --db file:./t.db --dialect sqlite --slug init --apply on a disposable project built from the reporting-value-object-members and reporting-derived-measures fixtures, then queried the four views against hand-computed values
  • meta migrate --from-db --dialect postgres --apply against a throwaway postgres:16-alpine container, then queried v_revenuebymonth, v_memberutilization and v_projectburn
  • Four adversarial metadata variants through meta migrate --dry-run: no currency dimension, unknown operand, derived-of-derived and a non-numeric literal
  • MySQL: generated the v_hoursgap view SQL (derived divide over a difference of two integral sums) and ran it in a throwaway mysql:8.4 container
  • bun test on report-derived-measures.test.ts and report-value-object-members.test.ts in codegen-ts (16 pass)
  • scripts/ci-local.sh (the full run, exit 0)
  • Baseline already run: scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchains
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Validated in one no-mistakes run.

…ixing its units (FR-044 R12)

A dimension's or aggregate measure's @Of may name Entity.field.member, a member
of a value object stored with @storage: flattened. The report reads the member's
own column (amount_amount, amount_currency). A report that sums, averages or
takes the min or max of a numeric member must group by every non-numeric member
of the same value object, so amounts in different currencies are never combined.
jsonb members, unknown members and deeper paths are refused at load. The Cube
exporter refuses member references.

Loader rules and report-shape derivation in TypeScript, C#, Java and Python,
with shared conformance fixtures for the positive case and each refusal.
…es (FR-044 R13)

Ports measure.derived (M11 @expr validation, R13 dimension operands, the
nullable-decimal column type) to the C#, Java and Python loaders, so all four
loader ports pass the shared derived and value-object fixtures.

Also:
- docs: reporting.md, the authoring skill references, the FR-044 spec (R11
  amendment) and an FR-037 R5 note; CHANGELOG under Unreleased.
- a measureDerived requirement, with the requirement harness regenerated.
- fixture counts (490) in AGENTS.md and CONFORMANCE.md, the site payload and
  the site reference regenerated.
- cube-members.ts: imports moved above valueObjectMemberError, so the eject
  scanner sees every import and the ejected cube template compiles.
- Java: a measure whose @agg is outside the closed set no longer throws an NPE
  in the value-object unit check.
- test typecheck fixes for the derived and value-object Cube tests.
@dmealing
dmealing merged commit 8ef0f03 into main Nov 13, 2026
9 checks passed
@dmealing
dmealing deleted the fm/mo-report-measures-money branch November 13, 2026 01:16
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