feat(spec,cli): validate dataset measure aggregation by field semantics#2208
Merged
Conversation
A measure that SUMs a percentage/rate field produces a meaningless total (it can exceed 100%); rates must AVG. Authoring tools and `os validate` had no notion of this, so a hand-authored — or AI-authored — dataset could summon a "win-probability" measure as SUM and pass every check. - @objectstack/spec/data: new aggregation-policy — `defaultAggregateFor` (rates AVG, amounts SUM) and `isIncoherentAggregate`. The single source of truth for field→aggregation semantics, shared by authoring (dataset derivation) and validation so the two cannot drift. - @objectstack/cli validateWidgetBindings: new `measure-aggregate-incoherent` advisory — checks every dataset's measures against its object's field types and flags SUM/count_distinct of a percent field. Runs at validate/compile/build through the existing widget-binding pass; never false-positives when the object's field types are unknown. Tests: spec policy unit tests + cli validator cases (sum-on-percent flagged, avg clean, currency-sum clean, no-objects no-op, count_distinct flagged).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 2 package(s): 93 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
xuyushun441-sys
added a commit
that referenced
this pull request
Jun 22, 2026
…rts (#2209) #2208 added three @objectstack/spec/data exports (defaultAggregateFor, isIncoherentAggregate, MEASURE_FIELD_TYPES) but did not regenerate the public API-surface snapshot, so the `check:api-surface` gate failed on main. Intentional addition: 0 breaking, 3 added. Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
A dataset measure that SUMs a
percent/rate field produces a meaningless total (it routinely exceeds 100%) — rates must AVG. Nothing at author time knew this, so a hand-authored or AI-authored dataset could declare a win-probability measure assumand passos validate/compileclean. (Surfaced on a live AI-built CRM dashboard: a probability column summed to 145%, 200%.)What
@objectstack/spec/data— newaggregation-policy(the single source of truth for field→aggregation semantics, shared by authoring and validation so they can't drift):defaultAggregateFor(fieldType)— rates (percent) AVG, additive amounts SUM.isIncoherentAggregate(aggregate, fieldType)— true only for genuinely meaningless cases (today: SUM/count_distinctof a percent); never raises when the type is unknown.@objectstack/clivalidateWidgetBindings— newmeasure-aggregate-incoherentadvisory: checks every dataset's measures against its bound object's field types and flags an incoherent aggregation. Runs at validate/compile/build through the existing widget-binding pass; never false-positives without the object's field types (e.g. cross-package datasets).Notes
suppressWarnings: ['measure-aggregate-incoherent'].isIncoherentAggregateto replace its local copy.Tests
aggregation-policy.test.ts(policy + coherence matrix).validate-widget-bindings.test.ts— sum-on-percent flagged, avg clean, currency-sum clean,count_distinct-of-percent flagged, no-objects no-op. 33/33 in that file; 6612 spec tests green.🤖 Generated with Claude Code