|
20 | 20 | * ## The dialect trap this file exists to pin |
21 | 21 | * |
22 | 22 | * `ListView.sort` and `record:related_list.sort` declare the SAME union |
23 | | - * (`string | Array<{field, order}>`) and mean DIFFERENT things by the string |
24 | | - * arm: |
| 23 | + * (`string | Array<{field, order}>`) in `@objectstack/spec` and mean DIFFERENT |
| 24 | + * things by the string arm: |
25 | 25 | * |
26 | 26 | * - ListView's string is the legacy space-separated clause, `'seq_no desc'` |
27 | 27 | * (`@objectstack/spec` `ui/view.zod.ts`, annotated `Legacy "field desc"`); |
|
30 | 30 | * |
31 | 31 | * Inheriting the string verbatim therefore does not produce "a sort in another |
32 | 32 | * notation" — it produces `$orderby` on a field whose NAME is the seven |
33 | | - * characters `seq_no desc`, which no object has. The route taken (and pinned |
34 | | - * below) is to normalize at this boundary, always to the ARRAY arm, through |
35 | | - * `@object-ui/core`'s `convertSortToQueryParams` — the repo's one definition of |
36 | | - * both authored dialects — so no second parser of the legacy string exists to |
37 | | - * drift from it. |
| 33 | + * characters `seq_no desc`, which no object has. The route taken is to resolve |
| 34 | + * that at this boundary, always to the ARRAY arm, through `@object-ui/core`'s |
| 35 | + * `convertSortToQueryParams`, so no second parser of the legacy string exists |
| 36 | + * to drift from it. `deriveRelatedLists` is the ONE place that knows it is |
| 37 | + * reading a ListView and writing a related list, which is why the resolution |
| 38 | + * belongs here and not as a tolerant reader on the consuming end |
| 39 | + * (AGENTS.md #0.1). |
38 | 40 | * |
39 | | - * `deriveRelatedLists` is the ONE place that knows it is reading a ListView and |
40 | | - * writing a related list, which is why the translation belongs here and not as |
41 | | - * a tolerant reader on the consuming end (AGENTS.md #0.1). |
| 41 | + * ## What objectui#8221 changed, and what it did NOT |
| 42 | + * |
| 43 | + * Decision batch #77 (option B) RETIRED the legacy space-separated clause: |
| 44 | + * `convertSortToQueryParams` no longer lowers it, it REFUSES it with a |
| 45 | + * diagnostic naming the array form. So this boundary no longer TRANSLATES a |
| 46 | + * ListView string — it drops it and says so, and the pins below moved with it. |
| 47 | + * |
| 48 | + * ⚠️ The trap the old translation prevented is still prevented, and that is the |
| 49 | + * assertion worth keeping: a legacy string must never reach the wire as a FIELD |
| 50 | + * NAME. "Refused, loudly" and "translated" both satisfy that; "forwarded |
| 51 | + * verbatim" does not, and is what a later well-meaning simplification here |
| 52 | + * would reintroduce. |
| 53 | + * |
| 54 | + * ⚠️ Measured, and the reason this is a behaviour change rather than a |
| 55 | + * tidy-up: `@objectstack/spec@17.3.0`'s `ListViewSchema.sort` STILL accepts the |
| 56 | + * string (`'name desc'` parses; `42` is refused `invalid_union`; a `bogusProp` |
| 57 | + * control is refused by name on the same call). A platform view carrying the |
| 58 | + * legacy clause is therefore still spec-legal and stops being inherited here. |
| 59 | + * The spec-side pull-back is its own card; until it lands, this diagnostic is |
| 60 | + * the only thing standing between an operator and a silently unordered list. |
42 | 61 | */ |
43 | 62 |
|
44 | | -import { describe, it, expect } from 'vitest'; |
| 63 | +import { describe, it, expect, vi } from 'vitest'; |
| 64 | +import { resetRetiredSortSpellingReports } from '@object-ui/core'; |
45 | 65 | import { deriveRelatedLists } from '../deriveRelatedLists'; |
46 | 66 |
|
47 | 67 | const PARENT = { name: 'task_version', label: 'Task Version', fields: {} }; |
@@ -89,23 +109,49 @@ describe('deriveRelatedLists — inherited default list-view sort (objectui#5795 |
89 | 109 | ]); |
90 | 110 | }); |
91 | 111 |
|
92 | | - it('THE DIALECT PIN — normalizes the legacy space-separated string arm', () => { |
93 | | - const entry = derive(childWithList({ sort: 'seq_no desc' })); |
94 | | - expect(entry.sort).toEqual([{ field: 'seq_no', order: 'desc' }]); |
95 | | - // Stated as its own assertion because it is the whole failure mode: an |
96 | | - // un-normalized inherit yields a FIELD literally named `seq_no desc`. |
97 | | - expect(entry.sort?.[0].field).toBe('seq_no'); |
98 | | - expect(entry.sort?.[0].field).not.toBe('seq_no desc'); |
99 | | - }); |
| 112 | + it('THE RETIREMENT PIN — a legacy string arm is REFUSED, and refused OUT LOUD (objectui#8221)', () => { |
| 113 | + resetRetiredSortSpellingReports(); |
| 114 | + const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); |
| 115 | + try { |
| 116 | + const entry = derive(childWithList({ sort: 'seq_no desc' })); |
100 | 117 |
|
101 | | - it('reads a bare legacy string as ascending', () => { |
102 | | - expect(derive(childWithList({ sort: 'seq_no' })).sort).toEqual([ |
103 | | - { field: 'seq_no', order: 'asc' }, |
104 | | - ]); |
| 118 | + // Nothing is inherited: the key is ABSENT, exactly as for a child that |
| 119 | + // declared no order at all. |
| 120 | + expect('sort' in entry).toBe(false); |
| 121 | + // The list itself is still derived — so the missing key means "this |
| 122 | + // order was refused", not "this derivation collapsed". |
| 123 | + expect(entry.childObject).toBe('check_item'); |
| 124 | + |
| 125 | + // The original failure mode stays impossible: the seven characters |
| 126 | + // `seq_no desc` must never travel as a FIELD NAME. |
| 127 | + expect(JSON.stringify(entry)).not.toContain('seq_no desc'); |
| 128 | + |
| 129 | + // And it is LOUD. A silent drop here is an operator's row order |
| 130 | + // disappearing with nothing in the console to explain it. |
| 131 | + expect(errorSpy).toHaveBeenCalledTimes(1); |
| 132 | + const message = String(errorSpy.mock.calls[0][0]); |
| 133 | + expect(message).toContain("[{ field: 'name', order: 'desc' }]"); |
| 134 | + expect(message).toContain('"seq_no desc"'); |
| 135 | + } finally { |
| 136 | + errorSpy.mockRestore(); |
| 137 | + } |
105 | 138 | }); |
106 | 139 |
|
107 | | - it('is case-insensitive about the legacy direction word', () => { |
108 | | - expect(derive(childWithList({ sort: 'seq_no DESC' })).sort).toEqual([ |
| 140 | + it('the other legacy spellings are refused the same way', () => { |
| 141 | + for (const spelling of ['seq_no', 'seq_no DESC']) { |
| 142 | + resetRetiredSortSpellingReports(); |
| 143 | + const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); |
| 144 | + try { |
| 145 | + expect('sort' in derive(childWithList({ sort: spelling }))).toBe(false); |
| 146 | + expect(errorSpy).toHaveBeenCalledTimes(1); |
| 147 | + } finally { |
| 148 | + errorSpy.mockRestore(); |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + // CONTROL — on the same derivation, the array arm still inherits, so the |
| 153 | + // refusals above are about the SPELLING and not a broken boundary. |
| 154 | + expect(derive(childWithList({ sort: [{ field: 'seq_no', order: 'desc' }] })).sort).toEqual([ |
109 | 155 | { field: 'seq_no', order: 'desc' }, |
110 | 156 | ]); |
111 | 157 | }); |
|
0 commit comments