Skip to content

Commit 077b387

Browse files
committed
fix(lint)!: refuse a stored page sort naming an unknown field, on every page sort slot
Every stored page sort slot (element dataSource.sort, a related list's sort and parentDataSource.sort, each sort-carrying block's own sort, interfaceConfig.sort, an app page's record.sort) is now asked existence and provenance by validateSortableFields, the member the page publish door runs: an unknown name is page-field-unknown at error, as the list door answers it 400 INVALID_SORT on every read. validatePageFieldBindings no longer reads a page sort, so each slot has one reader. Claude-Session: https://claude.ai/code/session_01Utp6CYvKbGaAgjBLQdkwPB Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5fa9375 commit 077b387

6 files changed

Lines changed: 400 additions & 44 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/lint': minor
3+
---
4+
5+
fix(lint)!: a stored page sort naming a field its object lacks is refused by `os validate` and at the page publish door (`page-field-unknown`, error), on every page sort slot (#30093)
6+
7+
Clause-②: no (narrowing) — an unknown sort field on a page slot moves from silent or warning to error: `os validate` / `os build` / `os lint` and the `page` publish door refuse a page sort they accepted before.
8+
Metadata-protocol: narrowed
9+
Skills-docs: none — `skills/**` and `content/docs/**` teach no page sort that names a field the object lacks, and nothing there describes an unknown page sort as a warning; the verdict and its fix line name the field, the object and the nearest declared field.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed or renamed: every page sort slot keeps its shape and meaning, and the build and the page publish door now give an unknown field there the verdict a list view sort already gets. A refused name never sorted anything (the list door answered every read 400 INVALID_SORT), so there is no rewrite that keeps what the author meant; the author names a real field, and the refusal says which. -->
12+
13+
**BREAKING** accept-set narrowing at the page publish door (`PUT /api/v1/meta/page/NAME`; Studio, REST and MCP authors) and in `os validate` / `os build` / `os lint`.
14+
15+
- **Before.** A page sort naming a field the object does not have saved green, and its first read, and every read after it, answered `400 INVALID_SORT` at the list door. A list page's `interfaceConfig.sort` and a `record:related_list` block's `sort` drew a `page-field-unknown` warning on the CLI alone; an element `dataSource.sort`, a related list's `parentDataSource.sort`, an app page's `record.sort` and the own `sort` of a `record:line_items`, `list-view` or `object-*` block were read by nothing.
16+
- **Now.** Every one of those slots is judged by `validateSortableFields`, the reference-integrity member the page publish door already runs, and an unknown name is `page-field-unknown` at `error`, at the slot's path, bound to the object the slot's renderer reads (`dataSource.object`, else the block's object prop; `interfaceConfig.source`, else the page's `object`; `parentDataSource.object`; `record.object`). The page door refuses it `422 INVALID_METADATA`. A registry-injected column on an `external` object is `page-field-unprovisioned` at `warning`, as before. `validatePageFieldBindings` no longer reads a page sort, so each slot has one reader.
17+
- **Not judged.** A dotted relationship path (the list door refuses it as its own verdict), a system column such as `created_at`, an object the stack (or the publish snapshot) does not carry, and an object with no field map.
18+
- **Not changed.** A stored page already carrying such a sort keeps loading; only its next save is judged, and its read answers 400 as it did before.
19+
20+
**What an author does.** Name a field the object declares, or add the field to the object. A refused name never sorted the page, so there is nothing to keep.

‎packages/lint/src/validate-page-field-bindings.test.ts‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,10 @@ describe('validatePageFieldBindings — a related list splits its child and pare
423423
]]);
424424
});
425425

426-
it('a dataSource-bound list checks sort, filter and relationshipField against the child too', () => {
426+
// [#30093] The list's `sort` is a stored page sort, judged by
427+
// `validateSortableFields` at the list door's grade
428+
// (`validate-sortable-fields.test.ts` pins every slot), so it is not read here.
429+
it('a dataSource-bound list checks filter and relationshipField against the child too, and leaves sort to the sort rule', () => {
427430
expect(findingsOf({
428431
dataSource: { object: 'crm_account' },
429432
properties: {
@@ -432,7 +435,6 @@ describe('validatePageFieldBindings — a related list splits its child and pare
432435
filter: [{ field: 'ghost_filter', operator: 'equals', value: 'x' }],
433436
},
434437
}).map(([, , path, message]) => [path, message])).toEqual([
435-
[`${LIST}.sort[0].field`, expect.stringContaining('"ghost_sort" is not a field on object "crm_account"')],
436438
[`${LIST}.filter[0].field`, expect.stringContaining('"ghost_filter" is not a field on object "crm_account"')],
437439
[`${LIST}.relationshipField`, expect.stringContaining('"ghost_fk" is not a field on object "crm_account"')],
438440
]);
@@ -731,30 +733,27 @@ describe('validatePageFieldBindings — false-positive floor', () => {
731733
});
732734
});
733735

734-
describe('validatePageFieldBindings — legacy bare-string sort (#4340)', () => {
735-
/**
736-
* `ListViewSchema.sort` still accepts `"created_at desc"`. Reading the whole
737-
* string as a field name reported `"amount desc"` as unknown — a finding
738-
* whose "field" the author never wrote, and one no fix could satisfy. The
739-
* shared `sortFieldRefs` reads its head instead, the way the renderer does.
740-
*/
741-
it('judges the head segment, not the whole "field desc" string', () => {
736+
// [#30093] A list page's `interfaceConfig.sort` is a stored page sort, judged
737+
// by `validateSortableFields` (existence at `error`, the legacy string form read
738+
// by its head — the #4340 reading, pinned there), so this walk reads none of it.
739+
describe('validatePageFieldBindings — a stored page sort is not read here (#30093)', () => {
740+
it('reports nothing for an unknown interfaceConfig.sort, in either form, and still reads the columns', () => {
742741
const listPage = (sort: unknown) => ({
743742
...baseStack(),
744743
pages: [
745744
{
746745
name: 'list_page',
747746
type: 'list',
748747
object: 'crm_lead',
749-
interfaceConfig: { source: 'crm_lead', columns: ['name'], sort },
748+
interfaceConfig: { source: 'crm_lead', columns: ['name', 'ghost_col'], sort },
750749
},
751750
],
752751
});
753-
expect(validatePageFieldBindings(listPage('amount desc'))).toEqual([]);
754-
const bad = validatePageFieldBindings(listPage('ghost_col desc'));
755-
expect(bad).toHaveLength(1);
756-
expect(bad[0].message).toContain('"ghost_col"');
757-
expect(bad[0].message).not.toContain('ghost_col desc');
752+
for (const sort of ['ghost_sort desc', [{ field: 'ghost_sort', order: 'desc' }]]) {
753+
expect(validatePageFieldBindings(listPage(sort)).map((f) => f.path)).toEqual([
754+
'pages[0].interfaceConfig.columns[1]',
755+
]);
756+
}
758757
});
759758
});
760759

‎packages/lint/src/validate-page-field-bindings.ts‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@
5252
* same skips, same rule id: the two surfaces agree on what counts as a field by
5353
* construction rather than by two lists that happen to match, which is the
5454
* drift #4330 had just finished removing from the system-field lists.
55+
*
56+
* ── Stored page sorts are not read here (#30093) ─────────────────────────
57+
*
58+
* A page `sort` is not a binding a renderer skips: it lowers into the list
59+
* door's ORDER BY, which answers an unknown name `400 INVALID_SORT` on the
60+
* first load and every load after it. So every page sort slot (a component's
61+
* `dataSource.sort`, a related list's `sort` and `parentDataSource.sort`, each
62+
* sort-carrying block's own `sort`, `interfaceConfig.sort`, an app page's
63+
* `record.sort`) is judged by `validateSortableFields`, under this family's
64+
* ids: `page-field-unknown` at `error`, `page-field-unprovisioned` at
65+
* `warning`. That member is the one the page publish door runs, so the miss
66+
* refuses the save instead of publishing a page that breaks on its first read.
67+
* Until #30093 this walk read two of those slots at `warning` and the rest
68+
* were read by nothing. The react surface's sort props are not page metadata
69+
* slots and keep their own reading in `validate-react-page-props`.
5570
*/
5671

5772
export const PAGE_FIELD_UNKNOWN = 'page-field-unknown';
@@ -600,6 +615,20 @@ export function checkFieldRefs(
600615
return findings;
601616
}
602617

618+
/**
619+
* [#30093] Is `ref` one a related list's `sort` prop yielded? A STORED page
620+
* sort lowers into the list door's ORDER BY, which answers an unknown name
621+
* `400 INVALID_SORT` on every load, so it is not the `skipped` miss this pass
622+
* grades: `validateSortableFields` asks every page sort slot existence,
623+
* provenance and sortability, under this family's ids, and it is the member the
624+
* page publish door runs. {@link relatedListFieldRefs} keeps yielding the
625+
* sort refs for its out-of-repo callers; only this walk sets them aside.
626+
*/
627+
function isPageSortRef(ref: FieldRef, propsPath: string): boolean {
628+
const sortPath = `${propsPath}.sort`;
629+
return ref.path === sortPath || ref.path.startsWith(`${sortPath}[`) || ref.path.startsWith(`${sortPath}.`);
630+
}
631+
603632
export function validatePageFieldBindings(stack: AnyRec): PageFieldFinding[] {
604633
const findings: PageFieldFinding[] = [];
605634
if (!stack || typeof stack !== 'object') return findings;
@@ -643,7 +672,14 @@ export function validatePageFieldBindings(stack: AnyRec): PageFieldFinding[] {
643672
// parent; without it, `properties.objectName` names the child.
644673
const split = relatedListFieldRefs(props, base);
645674
const dataSource = isRec(component.dataSource) ? component.dataSource : undefined;
646-
checkRefs(split.related, strName(dataSource?.object) ?? split.relatedObject, where);
675+
// [#30093] The list's `sort` is a stored page sort, judged by
676+
// `validateSortableFields` at the list door's grade (see
677+
// {@link isPageSortRef}); every other child-side ref stays here.
678+
checkRefs(
679+
split.related.filter((ref) => !isPageSortRef(ref, base)),
680+
strName(dataSource?.object) ?? split.relatedObject,
681+
where,
682+
);
647683
// `relationshipValueField` names a field on the PARENT — the record the
648684
// list hangs off, never its own child `dataSource`. The parent is the
649685
// list's own `parentDataSource.object` when it declares one (ruling B on
@@ -690,9 +726,10 @@ export function validatePageFieldBindings(stack: AnyRec): PageFieldFinding[] {
690726
if (cfg) {
691727
const cfgObject = strName(cfg.source) ?? strName(page.object);
692728
const base = `pages[${pi}].interfaceConfig`;
729+
// [#30093] `cfg.sort` is a stored page sort: `validateSortableFields`
730+
// judges it, at the list door's grade.
693731
const refs: FieldRef[] = [
694732
...fieldRefsFrom(cfg.columns, `${base}.columns`),
695-
...sortFieldRefs(cfg.sort, `${base}.sort`),
696733
...filterFieldRefs(cfg.filterBy, `${base}.filterBy`),
697734
];
698735
const userFilters = isRec(cfg.userFilters) ? cfg.userFilters : undefined;

0 commit comments

Comments
 (0)