2323 *
2424 * CONTROLS. Entries without a filter reach the bridge exactly as before, and
2525 * the top-level unknown-key posture is unchanged.
26+ *
27+ * [#28609] The entry is now the spec's `AggregationNodeSchema` itself, closed at
28+ * the producer, instead of this tool's own closed copy of its members. So a
29+ * refused entry reads here in the very words the REST query door prints for
30+ * the same body (`packages/rest/src/aggregation-entry-undeclared-key-door.test.ts`
31+ * pins that half against the same spec message), and the retired `distinct`
32+ * answers its tombstone sentence on both doors. `tools/list` declares
33+ * `distinct` as a schema nothing satisfies (`not: {}`), with the removal text.
2634 */
2735
2836import { describe , it , expect , beforeEach } from 'vitest' ;
2937
38+ import { AggregationNodeSchema } from '@objectstack/spec/data' ;
39+
3040import { MCPServerRuntime } from './mcp-server-runtime.js' ;
3141import type { McpDataBridge } from './mcp-http-tools.js' ;
3242
@@ -54,6 +64,13 @@ function makeBridge(): RecordingBridge {
5464
5565let nextId = 1 ;
5666
67+ /** The refusal the spec node prints for one entry — the words the REST door answers too. */
68+ function nodeRefusal ( entry : Record < string , unknown > ) : string {
69+ const parsed = AggregationNodeSchema . safeParse ( entry ) ;
70+ expect ( parsed . success , 'the spec node refuses this entry' ) . toBe ( false ) ;
71+ return parsed . error ! . issues [ 0 ] ! . message ;
72+ }
73+
5774async function rpc ( runtime : MCPServerRuntime , bridge : RecordingBridge , method : string , params ?: unknown ) {
5875 const body = { jsonrpc : '2.0' , id : nextId ++ , method, ...( params === undefined ? { } : { params } ) } ;
5976 const req = new Request ( 'http://localhost/api/v1/mcp' , {
@@ -124,6 +141,8 @@ describe('aggregate_records — the aggregation entry (#28550)', () => {
124141 } ) ;
125142 expect ( refused ) . toBe ( true ) ;
126143 expect ( text ) . toContain ( 'bogusKey' ) ;
144+ // [#28609] The spec node's own sentence, the one REST prints for this entry.
145+ expect ( text ) . toContain ( nodeRefusal ( { function : 'count' , alias : 'n' , bogusKey : 1 } ) ) ;
127146 expect ( bridge . calls ) . toHaveLength ( 0 ) ;
128147 } ) ;
129148
@@ -135,16 +154,18 @@ describe('aggregate_records — the aggregation entry (#28550)', () => {
135154 expect ( refused ) . toBe ( true ) ;
136155 expect ( text ) . toContain ( 'where' ) ;
137156 expect ( text ) . toContain ( 'filter' ) ;
157+ expect ( text ) . toContain ( nodeRefusal ( { function : 'count' , alias : 'n' , where : { status : 'active' } } ) ) ;
138158 expect ( bridge . calls ) . toHaveLength ( 0 ) ;
139159 } ) ;
140160
141- it ( 'the retired `distinct` entry key is refused, not dropped ' , async ( ) => {
161+ it ( 'the retired `distinct` entry key is refused with its tombstone sentence, as on REST ' , async ( ) => {
142162 const { refused, text } = await aggregate ( runtime , bridge , {
143163 objectName : 'showcase_project' ,
144164 aggregations : [ { function : 'sum' , field : 'budget' , alias : 's' , distinct : true } ] ,
145165 } ) ;
146166 expect ( refused ) . toBe ( true ) ;
147- expect ( text ) . toContain ( 'distinct' ) ;
167+ expect ( text ) . toContain ( '`query.aggregations[].distinct` was removed in @objectstack/spec 17 (ADR-0049)' ) ;
168+ expect ( text ) . not . toContain ( 'Unrecognized key' ) ;
148169 expect ( bridge . calls ) . toHaveLength ( 0 ) ;
149170 } ) ;
150171
@@ -170,13 +191,17 @@ describe('aggregate_records — the aggregation entry (#28550)', () => {
170191 expect ( bridge . calls ) . toHaveLength ( 0 ) ;
171192 } ) ;
172193
173- it ( '`tools/list` advertises the entry as closed, with `filter` declared' , async ( ) => {
194+ it ( '`tools/list` advertises the entry as closed, with `filter` declared and `distinct` unsatisfiable ' , async ( ) => {
174195 const json = await rpc ( runtime , bridge , 'tools/list' ) ;
175196 const tool = ( json . result ?. tools ?? [ ] ) . find ( ( t : any ) => t . name === 'aggregate_records' ) ;
176197 expect ( tool ) . toBeDefined ( ) ;
177198 const entry = tool . inputSchema ?. properties ?. aggregations ?. items ;
178199 expect ( entry ?. additionalProperties ) . toBe ( false ) ;
179- expect ( Object . keys ( entry ?. properties ?? { } ) . sort ( ) ) . toEqual ( [ 'alias' , 'field' , 'filter' , 'function' ] ) ;
200+ expect ( Object . keys ( entry ?. properties ?? { } ) . sort ( ) ) . toEqual ( [ 'alias' , 'distinct' , 'field' , 'filter' , 'function' ] ) ;
201+ // [#28609] The tombstone: declared so the refusal carries its prescription,
202+ // and advertised as a schema no value satisfies.
203+ expect ( entry ?. properties ?. distinct ?. not ) . toEqual ( { } ) ;
204+ expect ( entry ?. properties ?. distinct ?. description ) . toMatch ( / ^ \[ R E M O V E D \] / ) ;
180205 expect ( entry ?. required ) . toEqual ( expect . arrayContaining ( [ 'function' , 'alias' ] ) ) ;
181206 } ) ;
182207} ) ;
0 commit comments