Skip to content

Commit a40eee9

Browse files
committed
test(spec): pin the closed aggregation entry at the producer
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5m158G1nvmxNYr7Jwq
1 parent 7a0a298 commit a40eee9

1 file changed

Lines changed: 52 additions & 7 deletions

File tree

‎packages/spec/src/data/query.test.ts‎

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,50 @@ describe('FieldNode — the nested-select object form is REMOVED', () => {
189189
* (`direction` → `order` is not a typo), which is why the alias table is the
190190
* load-bearing half.
191191
*/
192+
describe('AggregationNode — closed: an undeclared entry key is refused by name (#28609)', () => {
193+
it('refuses a slip, naming the surface and the key — it used to be stripped and the call answered', () => {
194+
const r = AggregationNodeSchema.safeParse({ function: 'sum', field: 'amount', alias: 's', bogusKey: true });
195+
expect(r.success).toBe(false);
196+
expect(r.error!.issues[0]!.code).toBe('unrecognized_keys');
197+
expect(r.error!.issues[0]!.message).toMatch(/^Unrecognized key\(s\) on this aggregation entry: `bogusKey`\./);
198+
});
199+
200+
it('names `filter` for `where` / `filters` / `conditions`, and `alias` for `as`', () => {
201+
for (const [key, canonical] of [['where', 'filter'], ['filters', 'filter'], ['conditions', 'filter'], ['as', 'alias']] as const) {
202+
const r = AggregationNodeSchema.safeParse({ function: 'count', alias: 'n', [key]: key === 'as' ? 'x' : { a: 1 } });
203+
expect(r.success, key).toBe(false);
204+
expect(r.error!.issues[0]!.message, key).toContain(`\`${key}\` → \`${canonical}\``);
205+
}
206+
});
207+
208+
it('the retired `distinct` answers its tombstone, not the generic refusal, and is never suggested', () => {
209+
const tomb = AggregationNodeSchema.safeParse({ function: 'sum', field: 'amount', alias: 's', distinct: true });
210+
expect(tomb.error!.issues.map((i) => i.code)).toEqual(['invalid_type']);
211+
const typo = AggregationNodeSchema.safeParse({ function: 'sum', field: 'amount', alias: 's', distinc: true });
212+
expect(typo.error!.issues[0]!.message).not.toContain('`distinct`');
213+
});
214+
215+
it('closes the entry through `QueryAST.aggregations` and `EngineAggregateOptionsSchema.aggregations`', () => {
216+
const entry = { function: 'count', alias: 'n', bogusKey: 1 };
217+
for (const r of [
218+
QuerySchema.safeParse({ object: 'order', aggregations: [entry] }),
219+
EngineAggregateOptionsSchema.safeParse({ aggregations: [entry] }),
220+
]) {
221+
expect(r.success).toBe(false);
222+
expect(JSON.stringify(r.error!.issues)).toContain('Unrecognized key(s) on this aggregation entry: `bogusKey`');
223+
}
224+
});
225+
226+
it('CONTROL — entries with only declared members parse as before', () => {
227+
const entries = [
228+
{ function: 'count', alias: 'n' },
229+
{ function: 'sum', field: 'amount', alias: 's' },
230+
{ function: 'count', alias: 'big', filter: { amount: { $gt: 100 } } },
231+
];
232+
for (const e of entries) expect(AggregationNodeSchema.parse(e)).toEqual(e);
233+
});
234+
});
235+
192236
describe('SortNode — closed, and `direction` carries its translation', () => {
193237
it('accepts the canonical two-key node, defaulting `order` to asc', () => {
194238
expect(SortNodeSchema.parse({ field: 'updated_at', order: 'desc' }))
@@ -240,7 +284,7 @@ describe('SortNode — closed, and `direction` carries its translation', () => {
240284

241285
it('leaves the REST of the query dialect open — the carve-out is this schema only', () => {
242286
// `query.zod.ts` stays classed `open` in the strictness ledger; only
243-
// `SortNodeSchema` was re-classed authorable. Pinned so a later blanket
287+
// `SortNodeSchema` and (#28609) `AggregationNodeSchema` were closed. Pinned so a later blanket
244288
// `.strict()` on the file is a deliberate decision with its own ruling
245289
// rather than a side effect of this change (#4001 tracks the top level).
246290
expect(QuerySchema.safeParse({ object: 'sales', nonsenseKey: 1 }).success).toBe(true);
@@ -738,12 +782,13 @@ describe('AggregationNode.distinct — REMOVED (ADR-0049)', () => {
738782
}
739783
});
740784

741-
it('a legal aggregation parses and carries NO `distinct` property (non-strict strip path)', () => {
742-
// `AggregationNodeSchema` is `z.object()`, not `.strict()`. A bare
743-
// deletion would therefore have made zod SILENTLY STRIP a caller's
744-
// `distinct` — replacing a divergent flag with an ignored one, which is
745-
// the #3733 / ADR-0104 shape. The tombstone is what makes the removal
746-
// audible; this pins that the surviving members are untouched by it.
785+
it('a legal aggregation parses and carries NO `distinct` property', () => {
786+
// When `distinct` was retired `AggregationNodeSchema` was `z.object()`,
787+
// not `.strict()`, so a bare deletion would have made zod SILENTLY STRIP
788+
// a caller's `distinct` — the #3733 / ADR-0104 shape. The tombstone made
789+
// the removal audible; since #28609 the node is closed too, and the
790+
// tombstone still answers first (the block below). This pins that the
791+
// surviving members are untouched by it.
747792
const parsed = AggregationNodeSchema.parse({ function: 'sum', field: 'amount', alias: 'total' });
748793
expect(parsed).not.toHaveProperty('distinct');
749794
expect(parsed).toEqual({ function: 'sum', field: 'amount', alias: 'total' });

0 commit comments

Comments
 (0)