From b7a76cd324ef0edf6120abdb411846af9bd8a97b Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Sep 2026 20:15:47 +0000 Subject: [PATCH 1/3] feat(lint): resolve an interface page's whitelisted visualizations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WIP — rule, wiring, tests and changeset in place; verification pending. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_0174WZTU6XcFcS7g2kykC53i --- .../page-visualization-binding-integrity.md | 68 +++ packages/lint/src/index.ts | 21 + .../src/reference-integrity-suite.test.ts | 5 + .../lint/src/reference-integrity-suite.ts | 32 ++ ...lidate-page-visualization-bindings.test.ts | 470 +++++++++++++++++ .../validate-page-visualization-bindings.ts | 497 ++++++++++++++++++ scripts/cross-package-test-inputs.mjs | 11 + turbo.json | 3 + 8 files changed, 1107 insertions(+) create mode 100644 .changeset/page-visualization-binding-integrity.md create mode 100644 packages/lint/src/validate-page-visualization-bindings.test.ts create mode 100644 packages/lint/src/validate-page-visualization-bindings.ts diff --git a/.changeset/page-visualization-binding-integrity.md b/.changeset/page-visualization-binding-integrity.md new file mode 100644 index 00000000000..c5f38058f71 --- /dev/null +++ b/.changeset/page-visualization-binding-integrity.md @@ -0,0 +1,68 @@ +--- +"@objectstack/lint": minor +--- + +feat(lint): resolve an interface page's whitelisted visualizations at validate/build (#14073) + +Accept-set narrowing, `minor` under the family precedent (#14107, #14105, #14148). + +An interface `list` page whitelists renderers with +`interfaceConfig.appearance.allowedVisualizations`, and `InterfacePageConfigSchema` +is a closed shape with **no per-visualization binding key at all** — no +`calendar:`, no `kanban:`, no `map:`. So #13817's parse-time refinement, which +demands a `calendar:` block on a list VIEW that whitelists `calendar`, was +correctly not extended to this door: a requirement the page surface cannot +satisfy would be unauthorable. + +That left the page door with no check of any kind. Measured on objectui +`f0f774b0` (after objectui#7029 removed the invented `due_date` default), the +renderer derives each binding from the source object's fields +(`InterfaceListPage.tsx`, `view. ?? deriveFromObject(objectDef)`), and when +nothing derives there are exactly two outcomes, neither of which reaches the +author: + +- the entry LEADS the whitelist — it becomes the page's forced view type, is + force-pushed into the switcher's resolvable set, and every visitor lands on + the renderer's "Calendar configuration required" refusal screen; +- the entry is anywhere else — it is filtered out of the switcher **silently**, + while the switcher chrome still appears (it is shown on whitelist length). + +The new rule `page/visualization-without-binding` +(`validatePageVisualizationBindings`, a member of the reference-integrity suite, +so it runs on `validate` / `lint` / `compile`) asks the renderer's own question +at authoring time. For every `list` page, each whitelisted visualization must be +either derivable from the source object's declared fields — using the SAME +predicates the renderer applies, the field TYPE first and then the NAME regex +fallback (kanban: select-like type or status-like name; calendar and timeline: a +date-typed non-hidden non-system field, else a date-like name; gallery: +image-typed, no name leg; gantt: two distinct date fields; map: location-typed or +a geo-like name) — or bound by the block of the list view the page references +through `sourceView` (a `calendar:` block also binds a `timeline`, which is what +`resolveTimelineDateBinding` accepts). `grid` always passes. + +Severity tracks what the visitor sees: **`error`** when the unbound entry is +`allowedVisualizations[0]`, **`warning`** otherwise. Every message names +`sourceView` as the remedy, because on this door it is the one schema-legal +channel for a per-visualization binding — exactly how the shipped showcase map +page binds its `locationField`. + +Deliberately NOT stricter than the renderer: mirroring both predicates rather +than the type half alone means a page whose only date is a text field called +`due_date` still passes, because it still renders. The mirrored table is exported +(`OBJECTUI_DERIVATION_PREDICATES`) and pinned verbatim by a fixture test, and the +seven shipped `showcase_task` interface pages are pinned as a live regression +corpus — the two halves catch drift on either side of a mirror no build edge +connects. `chart` and `tree` get no verdict: the renderer derives no binding for +them on this seam, so the rule says nothing rather than guessing. + +**Migration.** A page reported by the new rule whitelists a visualization that +renders nothing: point the page at a list view that declares the block +(`interfaceConfig.sourceView`), give the source object a field the derivation can +find, or drop the entry from `appearance.allowedVisualizations`. Four skips keep +it quiet where it cannot know: a page that is not `type: 'list'`, an object this +stack does not define, an object with no readable field map (ADR-0015 +`external`), and a `sourceView` naming a view this stack does not declare (the +runtime hydrates stored view bodies over the network). + +No `packages/spec` change — the page surface stays closed, which is what ADR-0047 +§7 open question 3 asks for. diff --git a/packages/lint/src/index.ts b/packages/lint/src/index.ts index bd30cd220ed..273467ff0fa 100644 --- a/packages/lint/src/index.ts +++ b/packages/lint/src/index.ts @@ -468,6 +468,27 @@ export { } from './validate-page-field-bindings.js'; export type { PageFieldFinding, PageFieldSeverity } from './validate-page-field-bindings.js'; +// [#14073] The PAGE door's visualization whitelist, one layer out from the key +// resolution above. `appearance.allowedVisualizations` names a RENDERER, not a +// field, and `InterfacePageConfigSchema` has no per-visualization binding key +// for the author to fill in — so the renderer derives the binding from the +// source object's fields, or the page borrows one through `sourceView`. This +// rule mirrors that derivation at authoring time (the table it mirrors is +// exported so a consumer can read the predicates rather than retype them) and +// reports the whitelisted type that binds to nothing: `error` when it leads +// (the runtime reaches its renderer's refusal screen), `warning` otherwise +// (the type is dropped from the switcher silently). +export { + validatePageVisualizationBindings, + PAGE_VISUALIZATION_WITHOUT_BINDING, + OBJECTUI_DERIVATION_PREDICATES, +} from './validate-page-visualization-bindings.js'; +export type { + PageVisualizationFinding, + PageVisualizationSeverity, + VisualizationPredicate, +} from './validate-page-visualization-bindings.js'; + // [#13855] The shared field-group reference half both layout surfaces resolve // against — exported so an out-of-repo consumer (cloud graph-lint, the AI // authoring path) can ask the same question of the same index rather than diff --git a/packages/lint/src/reference-integrity-suite.test.ts b/packages/lint/src/reference-integrity-suite.test.ts index 2b872e5c038..6e907edb5e2 100644 --- a/packages/lint/src/reference-integrity-suite.test.ts +++ b/packages/lint/src/reference-integrity-suite.test.ts @@ -24,6 +24,11 @@ describe('reference-integrity suite — membership', () => { 'validateListViewFieldRefs', 'validateActionNameRefs', 'validatePageFieldBindings', + // [#14073] The same page, one question out: the BINDING behind each + // visualization `appearance.allowedVisualizations` whitelists, resolved + // against the source object's fields or the view named by `sourceView`. + // Placed beside the member that resolves the same page's field names. + 'validatePageVisualizationBindings', 'validateChartBindings', // [#14105] The dataset's OWN references, one level below the two binding // rules above it — the conscious edit this written-out list exists to diff --git a/packages/lint/src/reference-integrity-suite.ts b/packages/lint/src/reference-integrity-suite.ts index b13e57a4778..d90e64c9143 100644 --- a/packages/lint/src/reference-integrity-suite.ts +++ b/packages/lint/src/reference-integrity-suite.ts @@ -60,6 +60,19 @@ * miss empties or mis-selects the view's data gates, one whose miss drops a * decoration advises. * + * `validatePageVisualizationBindings` is the charter's question with the + * resolution target one level up (#14073): an interface page's + * `appearance.allowedVisualizations` entry names a RENDERER, and + * `InterfacePageConfigSchema` carries no per-visualization binding key for the + * author to fill in — so the binding is either derived from the source + * object's declared fields (objectui's own `InterfaceListPage` derivation, + * mirrored) or supplied by the list view the page names through `sourceView`. + * An entry that resolves to neither renders NOTHING: leading the whitelist it + * becomes the forced view type and every visitor gets the renderer's + * "configuration required" refusal screen (`error`); anywhere else it is + * dropped from the switcher without a word (`warning`). Both severities, like + * the two members above, and the same three skips. + * * Rules that check SHAPE rather than reference (view containers, responsive * styles, seed replay safety, seed state machines, seed/security posture) stay * out — they answer a different question and have their own call sites. @@ -92,6 +105,7 @@ import { validateSortableFields } from './validate-sortable-fields.js'; import { validateListViewFieldRefs } from './validate-list-view-field-refs.js'; import { validateActionNameRefs } from './validate-action-name-refs.js'; import { validatePageFieldBindings } from './validate-page-field-bindings.js'; +import { validatePageVisualizationBindings } from './validate-page-visualization-bindings.js'; import { validateChartBindings } from './validate-chart-bindings.js'; import { validateDatasetReferences } from './validate-dataset-references.js'; import { validateNavAccess } from './validate-nav-access.js'; @@ -220,6 +234,24 @@ export const REFERENCE_INTEGRITY_RULES: readonly ReferenceIntegrityRule[] = [ { name: 'validateListViewFieldRefs', runtimeTypes: ['flow', 'view'], run: validateListViewFieldRefs }, { name: 'validateActionNameRefs', run: validateActionNameRefs }, { name: 'validatePageFieldBindings', run: validatePageFieldBindings }, + // [#14073] The same page, one question out. `validatePageFieldBindings` + // above resolves the field NAMES an interface page writes; this member + // resolves the BINDING behind each visualization the page whitelists — + // `appearance.allowedVisualizations` names a renderer, and the page surface + // has no key to bind it with, so the binding is either derived from the + // source object's fields (objectui's `InterfaceListPage` derivation, + // mirrored) or supplied by the view the page names through `sourceView`. + // Squarely the charter's question with the resolution target one level up: + // the whitelist entry is a name written in metadata whose binding must + // resolve against what the stack declares (the object's fields, that view's + // blocks) or it renders nothing. + // + // NO `runtimeTypes`, i.e. the frozen `flow` default, and deliberately: it + // resolves against `stack.pages` and `stack.views`, neither of which the + // per-write snapshot carries, so crossing it onto `view` writes would report + // every page-door binding as unresolvable. Its page-typed sibling above + // takes the default for the same reason. + { name: 'validatePageVisualizationBindings', run: validatePageVisualizationBindings }, { name: 'validateChartBindings', run: validateChartBindings }, // [#14105] One level BELOW the two members above it. `validateChartBindings` // and `validateWidgetBindings` resolve a presentation's binding against the diff --git a/packages/lint/src/validate-page-visualization-bindings.test.ts b/packages/lint/src/validate-page-visualization-bindings.test.ts new file mode 100644 index 00000000000..89b3917cc6d --- /dev/null +++ b/packages/lint/src/validate-page-visualization-bindings.test.ts @@ -0,0 +1,470 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// [#14073] The page door's visualization whitelist. +// +// Two halves, and they check each other. The PREDICATE PIN below restates +// objectui's derivation table verbatim, so a change on THIS side of the mirror +// cannot be silent. The SHOWCASE PIN feeds the shipped interface pages — the +// exact pages the card was filed about — through the rule live, so a change on +// the OBJECTUI side (or in the showcase object's fields) shows up as a page +// that renders today being reported as unbound. Neither half alone is enough: +// the pin is a copy of a copy, and the showcase run cannot see a predicate the +// showcase happens not to exercise. +// +// The live imports are a declared cross-package coupling (`turbo.json`'s +// `@objectstack/lint#test` inputs and `scripts/cross-package-test-inputs.mjs`), +// which puts them in `check:examples-live-imports`' `inputs-declared` tier — +// both of CI's scoping layers move when the showcase moves. +// +// ⚠️ These pins assert the shipped app is CLEAN, which is the direction #8515's +// ruling allows to stay live: nothing here needs the showcase to keep a defect. +// If a showcase edit turns one red, the app is what changed. + +import { describe, it, expect } from 'vitest'; + +import { + validatePageVisualizationBindings, + PAGE_VISUALIZATION_WITHOUT_BINDING, + OBJECTUI_DERIVATION_PREDICATES, +} from './validate-page-visualization-bindings.js'; +import { REFERENCE_INTEGRITY_RULES } from './reference-integrity-suite.js'; + +import { Task } from '../../../examples/app-showcase/src/data/objects/task.object.js'; +import { TaskViews } from '../../../examples/app-showcase/src/ui/views/task.view.js'; +import { + TaskBoardPage, + TaskCalendarPage, + TaskGalleryPage, + TaskSchedulePage, + TaskTimelinePage, + TaskMapPage, + TaskAllViewsPage, +} from '../../../examples/app-showcase/src/ui/pages/task-visualizations.pages.js'; + +type AnyRec = Record; + +/** A `list` page with an `interfaceConfig`, spelled once. */ +function listPage(name: string, cfg: AnyRec): AnyRec { + return { name, type: 'list', interfaceConfig: cfg }; +} + +/** An object whose only fields are text — nothing any predicate can find. */ +const DATELESS: AnyRec = { + name: 'crm_note', + fields: { + title: { type: 'text' }, + body: { type: 'textarea' }, + }, +}; + +describe('the predicate table is a verbatim mirror of objectui', () => { + /** + * ⛔ Do NOT "fix" this list to match a changed rule — it is the specimen. + * + * Transcribed from objectui `f0f774b0`, + * `packages/app-shell/src/views/InterfaceListPage.tsx`: `SELECT_TYPES`, + * `DATE_TYPES`, `IMAGE_TYPES` (`:149-151`), `LOCATION_TYPES` (`:203`), + * `defaultKanbanFromObject` (`:153`), `defaultDateField` (`:163`), + * `defaultCalendarFromObject` (`:170`), `defaultGalleryFromObject` (`:175`), + * `defaultGanttFromObject` (`:185`), `defaultMapFromObject` (`:253`), and the + * `view. ?? derived` precedence at `:409-419` plus + * `resolveTimelineDateBinding` (`plugin-list/src/ListView.tsx:411-433`) for + * the timeline's second accepted block. + * + * When this goes red the question is never "which side do I edit?" — it is + * "did objectui's derivation move?". Re-read those symbols before touching + * either side. + */ + it('lists the derivation predicates exactly as the renderer applies them', () => { + expect(OBJECTUI_DERIVATION_PREDICATES).toEqual([ + { + visualization: 'kanban', + binding: 'groupByField', + types: ['select', 'multiselect', 'radio', 'enum', 'boolean'], + namePattern: 'status|stage|state|priority|category|kind', + viewBlocks: ['kanban'], + }, + { + visualization: 'calendar', + binding: 'startDateField', + types: ['date', 'datetime', 'time'], + namePattern: 'date|due|start|end|deadline|schedule', + viewBlocks: ['calendar'], + }, + { + visualization: 'timeline', + binding: 'startDateField', + types: ['date', 'datetime', 'time'], + namePattern: 'date|due|start|end|deadline|schedule', + viewBlocks: ['timeline', 'calendar'], + }, + { + visualization: 'gallery', + binding: 'coverField', + types: ['image', 'file', 'attachment', 'avatar', 'photo'], + namePattern: null, + viewBlocks: ['gallery'], + }, + { + visualization: 'gantt', + binding: 'startDateField + endDateField', + types: ['date', 'datetime', 'time'], + namePattern: null, + viewBlocks: ['gantt'], + }, + { + visualization: 'map', + binding: 'locationField', + types: ['location', 'geo', 'geolocation', 'geopoint', 'point'], + namePattern: 'location|address|geo|coords?|place|venue', + viewBlocks: ['map'], + }, + ]); + }); + + it('covers every visualization the renderer derives, and claims no others', () => { + // `grid` needs no binding; `chart` and `tree` have NO deriver on this seam, + // so the rule has no measured verdict about them (skip 3). This assertion + // is the boundary, written down: widening it is a measurement, not an edit. + expect(OBJECTUI_DERIVATION_PREDICATES.map((p) => p.visualization)).toEqual([ + 'kanban', 'calendar', 'timeline', 'gallery', 'gantt', 'map', + ]); + }); +}); + +describe('the shipped showcase interface pages (regression pin)', () => { + const showcasePages = [ + TaskBoardPage, // ['kanban'] + TaskCalendarPage, // ['calendar'] + TaskGalleryPage, // ['gallery'] + TaskSchedulePage, // ['gantt'] + TaskTimelinePage, // ['timeline'] + TaskMapPage, // ['map'], bound through `sourceView: 'map'` + TaskAllViewsPage, // the full switcher + ] as unknown as AnyRec[]; + + const stack: AnyRec = { + objects: [Task], + views: [TaskViews], + pages: showcasePages, + }; + + it('are all `list` pages carrying an `allowedVisualizations` whitelist', () => { + // Guards the pin below against going vacuously green: if `definePage` ever + // stopped emitting `type: 'list'`, every page would hit skip 1 and the + // zero-findings assertion would keep passing while checking nothing. + for (const page of showcasePages) { + expect(page.type).toBe('list'); + const cfg = page.interfaceConfig as AnyRec; + const appearance = cfg.appearance as AnyRec; + expect(Array.isArray(appearance.allowedVisualizations)).toBe(true); + expect((appearance.allowedVisualizations as string[]).length).toBeGreaterThan(0); + } + // …and every visualization the rule judges is actually exercised by them. + const whitelisted = new Set( + showcasePages.flatMap( + (p) => ((p.interfaceConfig as AnyRec).appearance as AnyRec).allowedVisualizations as string[], + ), + ); + for (const { visualization } of OBJECTUI_DERIVATION_PREDICATES) { + expect(whitelisted.has(visualization)).toBe(true); + } + }); + + it('derive every whitelisted visualization — zero findings', () => { + expect(validatePageVisualizationBindings(stack)).toEqual([]); + }); + + it('reports the SAME pages once the object loses its date fields', () => { + // The other direction on the same corpus: strip `showcase_task`'s date + // fields and the calendar / timeline / gantt pages must go red. Without + // this, "zero findings" is compatible with a rule that never fires. + const fields = { ...((Task as unknown as AnyRec).fields as AnyRec) }; + for (const dateField of ['due_date', 'start_date', 'end_date', 'created_at']) delete fields[dateField]; + const dated = validatePageVisualizationBindings({ + ...stack, + objects: [{ ...(Task as unknown as AnyRec), fields }], + }); + expect(dated.map((f) => `${f.severity}:${f.path}`)).toEqual([ + // ['calendar'] — leading, so the page IS the refusal screen + 'error:pages[1].interfaceConfig.appearance.allowedVisualizations[0]', + // ['gantt'] — leading + 'error:pages[3].interfaceConfig.appearance.allowedVisualizations[0]', + // ['timeline'] — leading + 'error:pages[4].interfaceConfig.appearance.allowedVisualizations[0]', + // the all-views switcher: calendar / timeline / gantt are NOT leading + 'warning:pages[6].interfaceConfig.appearance.allowedVisualizations[3]', + 'warning:pages[6].interfaceConfig.appearance.allowedVisualizations[4]', + 'warning:pages[6].interfaceConfig.appearance.allowedVisualizations[5]', + ]); + }); +}); + +describe('severity tracks what the visitor sees', () => { + it('gates when the unbound entry LEADS the whitelist', () => { + const findings = validatePageVisualizationBindings({ + objects: [DATELESS], + pages: [listPage('note_calendar', { + source: 'crm_note', + appearance: { allowedVisualizations: ['calendar'] }, + })], + }); + expect(findings).toHaveLength(1); + expect(findings[0].severity).toBe('error'); + expect(findings[0].rule).toBe(PAGE_VISUALIZATION_WITHOUT_BINDING); + expect(findings[0].where).toBe('page "note_calendar" · interfaceConfig.appearance'); + expect(findings[0].path).toBe('pages[0].interfaceConfig.appearance.allowedVisualizations[0]'); + // The message names the page, the visualization, and what was looked for. + expect(findings[0].message).toContain('note_calendar'); + expect(findings[0].message).toContain("'calendar'"); + expect(findings[0].message).toContain('startDateField'); + expect(findings[0].message).toContain('a field typed date / datetime / time'); + expect(findings[0].message).toContain('forced view type'); + // …and the hint names `sourceView` as the remedy on this door. + expect(findings[0].hint).toContain('sourceView'); + }); + + it('advises when the unbound entry is not the leading one', () => { + const findings = validatePageVisualizationBindings({ + objects: [DATELESS], + pages: [listPage('note_grid_then_calendar', { + source: 'crm_note', + appearance: { allowedVisualizations: ['grid', 'calendar'] }, + })], + }); + expect(findings).toHaveLength(1); + expect(findings[0].severity).toBe('warning'); + expect(findings[0].path).toBe('pages[0].interfaceConfig.appearance.allowedVisualizations[1]'); + expect(findings[0].message).toContain('SILENTLY'); + expect(findings[0].hint).toContain('sourceView'); + }); + + it('says nothing about `grid`, which needs no binding', () => { + expect(validatePageVisualizationBindings({ + objects: [DATELESS], + pages: [listPage('note_grid', { + source: 'crm_note', + appearance: { allowedVisualizations: ['grid'] }, + })], + })).toEqual([]); + }); + + it('says nothing about `chart` or `tree` — no deriver on this seam to mirror', () => { + expect(validatePageVisualizationBindings({ + objects: [DATELESS], + pages: [listPage('note_chart', { + source: 'crm_note', + appearance: { allowedVisualizations: ['chart', 'tree'] }, + })], + })).toEqual([]); + }); +}); + +describe('`sourceView` is the remedy, and the rule honours it', () => { + const calendarView = { + name: 'crm_note_views', + objectName: 'crm_note', + listViews: { + schedule: { + label: 'Schedule', + type: 'calendar', + columns: ['title'], + calendar: { startDateField: 'reminder' }, + }, + }, + }; + + it('passes a page bound through `sourceView` to a view carrying `calendar:`', () => { + expect(validatePageVisualizationBindings({ + objects: [DATELESS], + views: [calendarView], + pages: [listPage('note_calendar_bound', { + source: 'crm_note', + sourceView: 'schedule', + appearance: { allowedVisualizations: ['calendar'] }, + })], + })).toEqual([]); + }); + + it('still reports a visualization the referenced view does not bind', () => { + const findings = validatePageVisualizationBindings({ + objects: [DATELESS], + views: [calendarView], + pages: [listPage('note_calendar_and_kanban', { + source: 'crm_note', + sourceView: 'schedule', + appearance: { allowedVisualizations: ['calendar', 'kanban'] }, + })], + }); + expect(findings).toHaveLength(1); + expect(findings[0].severity).toBe('warning'); + expect(findings[0].message).toContain("'kanban'"); + expect(findings[0].message).toContain('the referenced view "schedule" declares no `kanban:` block'); + }); + + it('accepts a `calendar:` block as the TIMELINE axis (resolveTimelineDateBinding)', () => { + expect(validatePageVisualizationBindings({ + objects: [DATELESS], + views: [calendarView], + pages: [listPage('note_timeline_via_calendar', { + source: 'crm_note', + sourceView: 'schedule', + appearance: { allowedVisualizations: ['timeline'] }, + })], + })).toEqual([]); + }); + + it('resolves the ADR-0017 `.` spelling too', () => { + expect(validatePageVisualizationBindings({ + objects: [{ + ...DATELESS, + listViews: { 'crm_note.schedule': { columns: ['title'], calendar: { startDateField: 'reminder' } } }, + }], + pages: [listPage('note_qualified', { + source: 'crm_note', + sourceView: 'schedule', + appearance: { allowedVisualizations: ['calendar'] }, + })], + })).toEqual([]); + }); + + it('skips the page when `sourceView` names no view this stack declares', () => { + // Skip 4: the runtime hydrates a stored view body over the network, so a + // build-time miss is unknowable — never a finding. + expect(validatePageVisualizationBindings({ + objects: [DATELESS], + pages: [listPage('note_hydrated', { + source: 'crm_note', + sourceView: 'stored_elsewhere', + appearance: { allowedVisualizations: ['calendar'] }, + })], + })).toEqual([]); + }); +}); + +describe('the derivation, predicate by predicate', () => { + const pageFor = (viz: string) => listPage(`p_${viz}`, { + source: 'probe', + appearance: { allowedVisualizations: [viz] }, + }); + const run = (viz: string, fields: AnyRec) => + validatePageVisualizationBindings({ + objects: [{ name: 'probe', fields }], + pages: [pageFor(viz)], + }); + + it('derives kanban from a select-like TYPE, else a status-like NAME', () => { + expect(run('kanban', { stage_text: { type: 'text' } })).toEqual([]); // name fallback + expect(run('kanban', { flag: { type: 'boolean' } })).toEqual([]); // type + expect(run('kanban', { title: { type: 'text' } })).toHaveLength(1); + }); + + it('derives calendar from a date-like TYPE, else a date-like NAME', () => { + expect(run('calendar', { when: { type: 'datetime' } })).toEqual([]); + expect(run('calendar', { deadline_note: { type: 'text' } })).toEqual([]); // name fallback + expect(run('calendar', { title: { type: 'text' } })).toHaveLength(1); + }); + + it('derives gallery from an image-like TYPE ONLY — it has no name fallback', () => { + expect(run('gallery', { shot: { type: 'attachment' } })).toEqual([]); + // A field literally called `cover` is NOT enough: the renderer's gallery + // deriver has no name leg, so a lint that accepted one would be LOOSER + // than the runtime and miss a real blank-card page. + expect(run('gallery', { cover: { type: 'text' } })).toHaveLength(1); + }); + + it('needs TWO DISTINCT date fields for gantt', () => { + expect(run('gantt', { start_date: { type: 'date' }, end_date: { type: 'date' } })).toEqual([]); + expect(run('gantt', { start_date: { type: 'date' } })).toHaveLength(1); + // One date field cannot serve both legs. + expect(run('gantt', { due_date: { type: 'date' }, note: { type: 'text' } })).toHaveLength(1); + }); + + it('derives map from a location-like TYPE, else a geo-like NAME', () => { + expect(run('map', { spot: { type: 'geopoint' } })).toEqual([]); + expect(run('map', { venue: { type: 'text' } })).toEqual([]); // name fallback + expect(run('map', { title: { type: 'text' } })).toHaveLength(1); + }); + + it('skips hidden and framework-managed fields before any predicate', () => { + // `created_at` is a system column and `secret_date` is hidden — the + // renderer filters both out before `defaultDateField` ever sees them. + expect(run('calendar', { + created_at: { type: 'datetime' }, + secret_date: { type: 'date', hidden: true }, + flagged: { type: 'date', system: true }, + title: { type: 'text' }, + })).toHaveLength(1); + }); +}); + +describe('the skips', () => { + it('says nothing about a page that is not `type: list`', () => { + expect(validatePageVisualizationBindings({ + objects: [DATELESS], + pages: [{ + name: 'note_record', + type: 'record', + interfaceConfig: { source: 'crm_note', appearance: { allowedVisualizations: ['calendar'] } }, + }], + })).toEqual([]); + }); + + it('says nothing about an object this stack does not declare', () => { + expect(validatePageVisualizationBindings({ + objects: [DATELESS], + pages: [listPage('elsewhere', { + source: 'installed_by_a_package', + appearance: { allowedVisualizations: ['calendar'] }, + })], + })).toEqual([]); + }); + + it('says nothing about an object with no readable field map (ADR-0015 external)', () => { + expect(validatePageVisualizationBindings({ + objects: [{ name: 'ext_customer', external: true }], + pages: [listPage('ext', { + source: 'ext_customer', + appearance: { allowedVisualizations: ['calendar'] }, + })], + })).toEqual([]); + }); + + it('falls back to the page-level `object` when `interfaceConfig.source` is absent', () => { + const findings = validatePageVisualizationBindings({ + objects: [DATELESS], + pages: [{ + name: 'note_page_object', + type: 'list', + object: 'crm_note', + interfaceConfig: { appearance: { allowedVisualizations: ['calendar'] } }, + }], + }); + expect(findings).toHaveLength(1); + expect(findings[0].message).toContain('crm_note'); + }); + + it('tolerates a stack with no pages, no objects and no appearance at all', () => { + expect(validatePageVisualizationBindings({})).toEqual([]); + expect(validatePageVisualizationBindings({ pages: [listPage('bare', { source: 'crm_note' })] })).toEqual([]); + expect(validatePageVisualizationBindings({ + objects: [DATELESS], + pages: [listPage('empty_whitelist', { + source: 'crm_note', + appearance: { allowedVisualizations: [] }, + })], + })).toEqual([]); + }); +}); + +describe('suite wiring', () => { + it('runs as a member of the reference-integrity suite', () => { + const member = REFERENCE_INTEGRITY_RULES.find( + (r) => r.name === 'validatePageVisualizationBindings', + ); + expect(member).toBeDefined(); + expect(member?.run).toBe(validatePageVisualizationBindings); + // Frozen `flow` default: the per-write `view` snapshot carries no pages. + expect(member?.runtimeTypes).toBeUndefined(); + }); +}); diff --git a/packages/lint/src/validate-page-visualization-bindings.ts b/packages/lint/src/validate-page-visualization-bindings.ts new file mode 100644 index 00000000000..2e265aef9a2 --- /dev/null +++ b/packages/lint/src/validate-page-visualization-bindings.ts @@ -0,0 +1,497 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#14073] `appearance.allowedVisualizations` on an interface `list` page, + * resolved against a binding that actually exists — the #13748 ruling's + * loud-over-silent half, on the PAGE door. + * + * ## The door, and why it has no `calendar:` key to check + * + * `InterfacePageConfigSchema` is a CLOSED shape with no per-visualization + * binding key at all: an author whitelists `calendar` under + * `appearance.allowedVisualizations` and has nowhere on the page to say WHICH + * field supplies the event date. That is deliberate (ADR-0047's 2026-06-19 + * revision leaves the per-viz bindings on the object view), and it is why + * #13817's parse-time refinement — which demands a `calendar:` block on a + * LIST VIEW that whitelists `calendar` — was correctly not extended here: a + * requirement the page surface cannot satisfy would be unauthorable. + * + * So the page door gets the check one layer out. The renderer DERIVES the + * binding from the source object's fields; this rule asks the same question + * the renderer asks, at authoring time, and reports the two outcomes an author + * cannot otherwise see. + * + * ## What was measured on the renderer (the facts this rule mirrors) + * + * Measured on objectui `f0f774b0` (after objectui#7029 removed the invented + * `due_date` default), `packages/app-shell/src/views/InterfaceListPage.tsx`: + * + * - `:409-419` — for each whitelisted visualization the binding is + * `view. ?? deriveFromObject(objectDef)`. The referenced view's own + * block WINS; the derivation is the fallback, and it yields a REAL field + * name or `undefined` — never a literal. (`timeline` borrows + * `defaultCalendarFromObject`, `:414`.) + * - `:460` — `viewType` is `allowed[0]`, force-pushed into the switcher's + * resolvable set by `ListView` (`plugin-list/src/ListView.tsx:2137-2140`, + * "always allow switching back to the viewType") even when its binding did + * not resolve. So the LEADING entry with no binding mounts its renderer + * with no field, and `ObjectCalendar`'s `getCalendarConfig` + * (`plugin-calendar/src/ObjectCalendar.tsx:142-165`) returns `null` — the + * user lands on the refusal screen "Calendar configuration required". + * - A NON-leading entry with no binding is filtered out of the switcher + * SILENTLY; the switcher chrome still appears, because `showViewSwitcher` + * reads the whitelist's LENGTH (`:482`). Nothing says why the type is + * missing, at build time or at run time. + * + * Hence the two severities, tracking what the user actually sees: `error` when + * the unbound entry is `allowedVisualizations[0]` (the refusal screen is the + * whole page), `warning` otherwise (a whitelisted type that silently is not + * there). Both name `sourceView` as the remedy, because on this door it is the + * only schema-legal channel for a per-visualization binding — exactly how the + * shipped showcase map page binds its `locationField`. + * + * ## ⚠️ Drift risk, stated because it is real and unguarded by any build edge + * + * The predicate table below is a MIRROR of objectui's derivation, hand-carried + * across a repository boundary. Nothing compiles the two together, so an edit + * to `InterfaceListPage.tsx`'s helpers silently makes this rule wrong — in + * whichever direction the edit moves. {@link OBJECTUI_DERIVATION_PREDICATES} + * is exported and pinned VERBATIM by a fixture test + * (`validate-page-visualization-bindings.test.ts`) so at least a change on + * THIS side cannot be silent; a change on the objectui side is caught by the + * showcase regression pin in that same file, which fails when a page that + * renders today stops deriving. + * + * Mirroring BOTH of the renderer's predicates — the field TYPE first, then the + * NAME regex fallback — rather than the type half alone is the ruled shape + * (2026-09-03, on the measurement): the #13748 ruling targets silent WRONG + * screens, not working derivations, so a lint stricter than the runtime would + * refuse pages that render correctly today. Every skip below is written in + * that direction. + * + * ## The skips + * + * 1. A page that is not `type: 'list'`, or carries no `interfaceConfig`. + * Only a `list` page mounts `InterfaceListPage`. + * 2. An object this stack does not define, or one with no readable field map + * (ADR-0015 `external`) — the same skips every field-resolving rule in + * this package takes (ADR-0072 D1). + * 3. `grid`, which needs no binding, and every whitelisted value the + * renderer does not derive a binding for at all — `chart` and `tree` have + * no deriver on this seam, so this rule has NO measured verdict about + * them and says nothing rather than guessing. That gap is honest + * under-coverage, not an assertion that they are fine. + * 4. A `sourceView` that names no view THIS stack declares. The runtime + * hydrates a stored view body over the network + * (`InterfaceListPage.tsx:370-384`), so a build-time miss here is + * "unknowable", never "unbound". + * + * ## System / hidden fields + * + * The renderer skips hidden and framework-managed fields before applying any + * predicate (`firstFieldMatching`, `InterfaceListPage.tsx:137-147`, via + * `@object-ui/types`' `isSystemManagedField`). This rule takes the same skip + * through THIS package's shared answer — the `system` flag, else + * {@link SYSTEM_FIELDS} — rather than hand-copying objectui's name list, which + * is the drift `system-fields.ts` exists to prevent. The two sets differ on a + * handful of legacy spellings objectui also lists (`_id`, `createdAt`, + * `modified`, `locked`, `space`, `company_id`); every one of those differences + * makes THIS side skip FEWER fields, i.e. derive more and report less, which + * is the safe direction under the ruling above. + */ + +import { SYSTEM_FIELDS } from './system-fields.js'; + +export const PAGE_VISUALIZATION_WITHOUT_BINDING = 'page/visualization-without-binding'; + +export type PageVisualizationSeverity = 'error' | 'warning'; + +export interface PageVisualizationFinding { + /** + * `error` when the entry leads `allowedVisualizations` — it becomes the + * forced `viewType` and the runtime reaches its renderer's refusal screen. + * `warning` otherwise — the type is filtered out of the switcher silently. + */ + severity: PageVisualizationSeverity; + /** Diagnostic rule id. */ + rule: string; + /** Human-readable location, e.g. `page "showcase_task_calendar" · interfaceConfig.appearance`. */ + where: string; + /** Config path, e.g. `pages[0].interfaceConfig.appearance.allowedVisualizations[1]`. */ + path: string; + /** What is wrong. */ + message: string; + /** How to fix it. */ + hint: string; +} + +/** + * One row of the renderer's derivation, transcribed. + * + * `types` is the TYPE predicate (checked first, in the object's declaration + * order); `namePattern` is the NAME fallback's regex SOURCE, or `null` where + * the renderer has no name fallback for that visualization. `viewBlocks` are + * the keys on the referenced view that supply the binding directly — read + * ahead of any derivation, exactly as `view. ?? derived` does. + */ +export interface VisualizationPredicate { + visualization: string; + /** The binding key the renderer would produce (what the message names). */ + binding: string; + types: readonly string[]; + namePattern: string | null; + viewBlocks: readonly string[]; +} + +/** + * The mirrored table — objectui `f0f774b0`, + * `packages/app-shell/src/views/InterfaceListPage.tsx`: + * `SELECT_TYPES`/`DATE_TYPES`/`IMAGE_TYPES`/`LOCATION_TYPES` at `:149-151` + * and `:203`, `defaultKanbanFromObject` `:153`, `defaultDateField` `:163`, + * `defaultCalendarFromObject` `:170`, `defaultGalleryFromObject` `:175`, + * `defaultGanttFromObject` `:185`, `defaultMapFromObject` `:253`. + * + * ⛔ Pinned verbatim by the fixture test. Editing a row here without editing + * that pin is the drift this table's whole purpose is to make loud. + */ +export const OBJECTUI_DERIVATION_PREDICATES: readonly VisualizationPredicate[] = [ + { + visualization: 'kanban', + binding: 'groupByField', + types: ['select', 'multiselect', 'radio', 'enum', 'boolean'], + namePattern: 'status|stage|state|priority|category|kind', + viewBlocks: ['kanban'], + }, + { + visualization: 'calendar', + binding: 'startDateField', + types: ['date', 'datetime', 'time'], + namePattern: 'date|due|start|end|deadline|schedule', + viewBlocks: ['calendar'], + }, + { + // `timeline` borrows `defaultCalendarFromObject` verbatim + // (`InterfaceListPage.tsx:414`), and `resolveTimelineDateBinding` + // (`plugin-list/src/ListView.tsx:411-433`) additionally accepts a + // CALENDAR block's `startDateField` as the timeline axis — so a view that + // declares only `calendar:` binds the timeline too. + visualization: 'timeline', + binding: 'startDateField', + types: ['date', 'datetime', 'time'], + namePattern: 'date|due|start|end|deadline|schedule', + viewBlocks: ['timeline', 'calendar'], + }, + { + visualization: 'gallery', + binding: 'coverField', + types: ['image', 'file', 'attachment', 'avatar', 'photo'], + namePattern: null, + viewBlocks: ['gallery'], + }, + { + // Two DISTINCT date fields. The start leg prefers a + // `/start|begin|kickoff/i` name and the end leg a + // `/end|due|finish|deadline|close/i` name, each falling back to the next + // date-typed field; either leg coming up empty yields no binding at all. + visualization: 'gantt', + binding: 'startDateField + endDateField', + types: ['date', 'datetime', 'time'], + namePattern: null, + viewBlocks: ['gantt'], + }, + { + visualization: 'map', + binding: 'locationField', + types: ['location', 'geo', 'geolocation', 'geopoint', 'point'], + namePattern: 'location|address|geo|coords?|place|venue', + viewBlocks: ['map'], + }, +]; + +/** Needs no binding — always renders. */ +const ALWAYS_BOUND = 'grid'; + +/** `visualization -> its row`, for the per-entry lookup. */ +const PREDICATE_BY_VIZ: ReadonlyMap = new Map( + OBJECTUI_DERIVATION_PREDICATES.map((p) => [p.visualization, p]), +); + +/** The gantt legs, kept next to the table they refine. */ +const GANTT_START_NAME = /start|begin|kickoff/i; +const GANTT_END_NAME = /end|due|finish|deadline|close/i; + +type AnyRec = Record; + +function isRec(v: unknown): v is AnyRec { + return !!v && typeof v === 'object' && !Array.isArray(v); +} + +function strName(v: unknown): string | undefined { + return typeof v === 'string' && v.length > 0 ? v : undefined; +} + +/** Coerce a collection (array or name-keyed map) to an array of records. */ +function asArray(v: unknown): AnyRec[] { + if (Array.isArray(v)) return v.filter(isRec); + if (isRec(v)) return Object.entries(v).map(([name, def]) => ({ name, ...(isRec(def) ? def : {}) })); + return []; +} + +/** The slice of one field the predicates read, in DECLARATION order. */ +interface DerivableField { + name: string; + type?: string; +} + +/** + * The renderer's pre-filter, transcribed: hidden and framework-managed fields + * never reach a predicate (`InterfaceListPage.tsx:137-147`). + * + * `undefined` is skip 2 — the object declares NO readable field map, so no + * question about it can be answered (the `graphObjectOf` verdict in + * `object-graph.ts`, spelled the same way: zero declared names is "unknowable", + * not "nothing derives"). An EMPTY array is a real answer: the object declares + * business fields and none of them satisfies any predicate. + */ +function derivableFields(obj: AnyRec): DerivableField[] | undefined { + const declared = obj.fields; + if (!isRec(declared) && !Array.isArray(declared)) return undefined; + let declaredNames = 0; + const out: DerivableField[] = []; + for (const f of asArray(declared)) { + const name = strName(f.name); + if (!name) continue; + declaredNames++; + if (f.hidden === true || f.system === true || SYSTEM_FIELDS.has(name)) continue; + out.push({ name, type: strName(f.type) }); + } + return declaredNames === 0 ? undefined : out; +} + +/** `firstFieldMatching` — first field, in declaration order, satisfying `pred`. */ +function firstMatch( + fields: readonly DerivableField[], + pred: (f: DerivableField) => boolean, +): string | undefined { + return fields.find(pred)?.name; +} + +/** `types` first, then the `namePattern` fallback — the renderer's order. */ +function deriveSimple( + fields: readonly DerivableField[], + predicate: VisualizationPredicate, +): string | undefined { + const typed = firstMatch(fields, (f) => !!f.type && predicate.types.includes(f.type)); + if (typed) return typed; + if (predicate.namePattern === null) return undefined; + const byName = new RegExp(predicate.namePattern, 'i'); + return firstMatch(fields, (f) => byName.test(f.name)); +} + +/** `defaultGanttFromObject` — two distinct date fields, or nothing. */ +function deriveGantt( + fields: readonly DerivableField[], + dateTypes: readonly string[], +): string | undefined { + const dated = (f: DerivableField) => !!f.type && dateTypes.includes(f.type); + const start = + firstMatch(fields, (f) => dated(f) && GANTT_START_NAME.test(f.name)) + ?? firstMatch(fields, dated); + if (!start) return undefined; + const end = + firstMatch(fields, (f) => dated(f) && f.name !== start && GANTT_END_NAME.test(f.name)) + ?? firstMatch(fields, (f) => dated(f) && f.name !== start); + if (!end) return undefined; + return `${start} + ${end}`; +} + +/** The derivation for one visualization, or `undefined` when nothing resolves. */ +function deriveBinding( + fields: readonly DerivableField[], + predicate: VisualizationPredicate, +): string | undefined { + return predicate.visualization === 'gantt' + ? deriveGantt(fields, predicate.types) + : deriveSimple(fields, predicate); +} + +/** + * Every named list view addressable on one object, keyed the way + * `resolveSourceView` (`InterfaceListPage.tsx:56-74`) reads them. + * + * The renderer reads `objectDef.listViews` on the MERGED object definition — + * the metadata registry has already folded the stack's `defineView` aggregates + * onto it by then. A lint stack has not, so the aggregates in `stack.views` + * that target this object are folded in here, under the same keys, so the + * page's `sourceView: 'map'` resolves to the same view both sides. + */ +function namedViewsFor(stack: AnyRec, obj: AnyRec | undefined, objectName: string): Map { + const views = new Map(); + const add = (key: string, view: unknown) => { + if (isRec(view) && !views.has(key)) views.set(key, view); + }; + // The object's own declarations. `list_views` is a compatibility READ for + // stored pre-settlement documents, exactly as the renderer spells it. + const own = isRec(obj?.listViews) ? obj.listViews : isRec(obj?.list_views) ? obj.list_views : undefined; + if (own) for (const [key, lv] of Object.entries(own)) add(key, lv); + if (obj && isRec(obj.list)) add('list', obj.list); + + // `defineView` aggregates that target this object. A per-view + // `data.object` binding wins over the aggregate's own, the resolution order + // `validate-list-view-field-refs` reads. + for (const view of asArray(stack.views)) { + const aggregateObject = strName(view.objectName) ?? strName(view.object); + const boundTo = (lv: AnyRec): string | undefined => + (isRec(lv.data) ? strName(lv.data.object) : undefined) ?? aggregateObject; + if (isRec(view.listViews)) { + for (const [key, lv] of Object.entries(view.listViews)) { + if (isRec(lv) && boundTo(lv) === objectName) add(key, lv); + } + } + if (isRec(view.list) && boundTo(view.list) === objectName) add('list', view.list); + } + return views; +} + +/** A view "carries columns" only when its column list is non-empty (the renderer's test). */ +function hasColumns(v: AnyRec): boolean { + return Array.isArray(v.columns) && v.columns.length > 0; +} + +/** + * `resolveSourceView`, transcribed: the qualified `.` spelling + * ADR-0017 expansion produces, then the bare key, then the object's default + * `list` for the two default spellings; among the present candidates prefer + * one that actually carries columns. + */ +function resolveSourceView( + named: ReadonlyMap, + objectName: string, + sourceView: string, +): AnyRec | undefined { + const candidates = [ + named.get(`${objectName}.${sourceView}`), + named.get(sourceView), + ...(sourceView === 'default' || sourceView === 'list' ? [named.get('list')] : []), + ].filter(isRec); + return candidates.find(hasColumns) ?? candidates[0]; +} + +/** + * Does the referenced view supply this visualization's binding directly? + * + * Block PRESENCE is the test, not block completeness: the renderer takes + * `view.` whole (`view. ?? derived`), and whether that block is + * itself complete is the VIEW door's question, already owned by + * `view/layout-without-binding` and by `ListViewSchema`'s own + * `allowedVisualizations` ⇄ `calendar` refinement. Asking it twice here would + * report one defect on two doors with two different remedies. + * + * `options.` is read alongside the spec-canonical key because `ListView` + * merges the legacy `options` twin (`ListView.tsx:411-433` for the date axis, + * and the `options.map` bag `InterfaceListPage.tsx:432` forwards). + */ +function viewSuppliesBinding(view: AnyRec, predicate: VisualizationPredicate): boolean { + const options = isRec(view.options) ? view.options : undefined; + return predicate.viewBlocks.some((key) => isRec(view[key]) || (!!options && isRec(options[key]))); +} + +/** What the derivation looked for, in the author's vocabulary. */ +function describeSearch(predicate: VisualizationPredicate): string { + const types = `a field typed ${predicate.types.join(' / ')}`; + const byName = + predicate.namePattern === null + ? '' + : `, then a field whose NAME matches /${predicate.namePattern}/i`; + return predicate.visualization === 'gantt' + ? `two distinct fields typed ${predicate.types.join(' / ')} (a start and an end)` + : `${types}${byName}`; +} + +export function validatePageVisualizationBindings(stack: AnyRec): PageVisualizationFinding[] { + const findings: PageVisualizationFinding[] = []; + if (!isRec(stack)) return findings; + + const objects = new Map(); + for (const obj of asArray(stack.objects)) { + const name = strName(obj.name); + if (name && !objects.has(name)) objects.set(name, obj); + } + + const pages = asArray(stack.pages); + for (let pi = 0; pi < pages.length; pi++) { + const page = pages[pi]; + // Skip 1 — only a `list` page mounts `InterfaceListPage`. + if (page.type !== 'list') continue; + const cfg = isRec(page.interfaceConfig) ? page.interfaceConfig : undefined; + if (!cfg) continue; + + const appearance = isRec(cfg.appearance) ? cfg.appearance : undefined; + const allowed = appearance?.allowedVisualizations; + if (!Array.isArray(allowed) || allowed.length === 0) continue; + + const objectName = strName(cfg.source) ?? strName(page.object); + if (!objectName) continue; + // Skip 2 — an object this stack does not define, or one with no readable + // field map. Both are unknowable here, never a miss. + const obj = objects.get(objectName); + if (!obj) continue; + const fields = derivableFields(obj); + if (!fields) continue; + + // Skip 4 — a `sourceView` naming a view this stack does not declare. The + // runtime hydrates a stored body over the network, so the block may exist + // where no build can see it. + const sourceView = strName(cfg.sourceView); + let referencedView: AnyRec | undefined; + if (sourceView) { + referencedView = resolveSourceView(namedViewsFor(stack, obj, objectName), objectName, sourceView); + if (!referencedView) continue; + } + + const pageName = strName(page.name) ?? `#${pi}`; + const where = `page "${pageName}" · interfaceConfig.appearance`; + + for (let ai = 0; ai < allowed.length; ai++) { + const viz = strName(allowed[ai]); + // Skip 3 — `grid` needs no binding; a value with no deriver on this seam + // (`chart`, `tree`, or anything unregistered) gets no verdict at all. + if (!viz || viz === ALWAYS_BOUND) continue; + const predicate = PREDICATE_BY_VIZ.get(viz); + if (!predicate) continue; + + if (referencedView && viewSuppliesBinding(referencedView, predicate)) continue; + if (deriveBinding(fields, predicate)) continue; + + const leading = ai === 0; + findings.push({ + severity: leading ? 'error' : 'warning', + rule: PAGE_VISUALIZATION_WITHOUT_BINDING, + where, + path: `pages[${pi}].interfaceConfig.appearance.allowedVisualizations[${ai}]`, + message: + `page "${pageName}" whitelists the '${viz}' visualization, but nothing supplies its ` + + `\`${predicate.binding}\`: the renderer derives that binding from "${objectName}"'s ` + + `fields — it looks for ${describeSearch(predicate)} — and "${objectName}" has none` + + (sourceView + ? `, while the referenced view "${sourceView}" declares no \`${predicate.viewBlocks[0]}:\` block either.` + : ', and this page references no view that declares it.') + + ' ' + + (leading + ? `'${viz}' LEADS \`allowedVisualizations\`, so it becomes the page's forced view type: ` + + 'every visitor lands on the renderer\'s "configuration required" refusal screen.' + : `'${viz}' is filtered out of the visualization switcher SILENTLY — the switcher still ` + + 'appears (it is shown on whitelist length), the type is simply never there, with no ' + + 'message at build time or at run time.'), + hint: + `An interface page has no per-visualization binding key of its own — \`sourceView\` is the ` + + `one schema-legal channel. Point this page at a "${objectName}" list view that declares a ` + + `\`${predicate.viewBlocks[0]}:\` block (\`interfaceConfig.sourceView: ''\`), give ` + + `"${objectName}" a field the derivation can find (${describeSearch(predicate)}), or drop ` + + `'${viz}' from \`appearance.allowedVisualizations\`.`, + }); + } + } + + return findings; +} diff --git a/scripts/cross-package-test-inputs.mjs b/scripts/cross-package-test-inputs.mjs index 110ecda2e36..8d80673c27a 100644 --- a/scripts/cross-package-test-inputs.mjs +++ b/scripts/cross-package-test-inputs.mjs @@ -513,6 +513,17 @@ export const CROSS_PACKAGE_TEST_INPUTS = { 'examples/app-showcase/src/ui/pages/capability-map.page.ts', 'examples/app-showcase/src/ui/pages/command-center-jsx.page.ts', 'examples/app-showcase/src/ui/pages/start-here.page.ts', + // src/validate-page-visualization-bindings.test.ts (#14073) imports the + // seven shipped `showcase_task` interface pages, that object, and its + // view aggregate LIVE, and asserts each whitelisted visualization + // still derives a binding. The coupling runs in BOTH directions: a + // new whitelist entry on a page, a renamed or retyped field on the + // object (the date / select / image / location fields the derivation + // finds), or a `calendar:` / `map:` block moving on the view all + // change the rule's verdict, so each must re-run this package's suite. + 'examples/app-showcase/src/ui/pages/task-visualizations.pages.ts', + 'examples/app-showcase/src/data/objects/task.object.ts', + 'examples/app-showcase/src/ui/views/task.view.ts', 'sdui.manifest.json', ], heldBy: { diff --git a/turbo.json b/turbo.json index ff4197c6011..40d80a69aa1 100644 --- a/turbo.json +++ b/turbo.json @@ -155,6 +155,9 @@ "$TURBO_ROOT$/examples/app-showcase/src/ui/pages/capability-map.page.ts", "$TURBO_ROOT$/examples/app-showcase/src/ui/pages/command-center-jsx.page.ts", "$TURBO_ROOT$/examples/app-showcase/src/ui/pages/start-here.page.ts", + "$TURBO_ROOT$/examples/app-showcase/src/ui/pages/task-visualizations.pages.ts", + "$TURBO_ROOT$/examples/app-showcase/src/data/objects/task.object.ts", + "$TURBO_ROOT$/examples/app-showcase/src/ui/views/task.view.ts", "$TURBO_ROOT$/sdui.manifest.json" ] }, From 510101159f9ae5cc649079eb0d1c62447df3aeb5 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Sep 2026 20:22:09 +0000 Subject: [PATCH 2/3] feat(lint): resolve an interface page's whitelisted visualizations Register the new SYSTEM_FIELDS consumer in the census ledger and load the showcase corpus through an import.meta.url path rather than a static import, so the example modules stay out of this package's tsc rootDir. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_0174WZTU6XcFcS7g2kykC53i --- .../lint/src/system-fields-consumers.test.ts | 20 ++++++++ ...lidate-page-visualization-bindings.test.ts | 48 ++++++++++++++----- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/packages/lint/src/system-fields-consumers.test.ts b/packages/lint/src/system-fields-consumers.test.ts index 7fb37c2ea63..51a72622f31 100644 --- a/packages/lint/src/system-fields-consumers.test.ts +++ b/packages/lint/src/system-fields-consumers.test.ts @@ -407,6 +407,26 @@ const LEDGER: Record = { asksProvenance: true, why: 'Blanket .has read site. Provenance wired by #8340.', }, + 'validate-page-visualization-bindings.ts': { + kind: 'rule', + reach: ['direct'], + asksProvenance: false, + why: + 'Landed 2026-09-03 (#14073). The one consumer that reads the union in the OPPOSITE direction, which is ' + + 'why the #8116 obligation does not arise here. Every other rule in this ledger consults the union to ' + + 'decide NOT TO FLAG an author-written reference — that silence is what owes a provenance question. ' + + 'This rule resolves no reference at all: it mirrors objectui\'s binding DERIVATION, and reads the union ' + + 'once, to drop framework-managed columns from the candidate set before any predicate sees them ' + + '(`InterfaceListPage.tsx`\'s `isSystemManagedField` pre-filter). The union therefore makes this rule ' + + 'MORE likely to report, never silent about a name, and no field name it skips ever leaves the rule: ' + + 'the finding names a VISUALIZATION and the object, never a column. ' + + 'The unprovisioned-anchor case cannot arise on the path that remains, either: a derivation candidate is ' + + 'by construction an AUTHOR-DECLARED field, and `unprovisionedInjectedColumnsFor` excludes an ' + + 'author-declared column of an anchor\'s name by design (#7859) — so no binding this rule blesses can ' + + 'be an ADR-0015 anchor with no storage behind it. An external object that declares a mapped field map ' + + 'is judged like any other (the shipped `showcase_ext_customer` shape the sortable-fields row measured); ' + + 'one that declares none is skip 2 and unjudged.', + }, 'validate-react-page-props.ts': { kind: 'rule', reach: ['direct'], diff --git a/packages/lint/src/validate-page-visualization-bindings.test.ts b/packages/lint/src/validate-page-visualization-bindings.test.ts index 89b3917cc6d..38e51d57724 100644 --- a/packages/lint/src/validate-page-visualization-bindings.test.ts +++ b/packages/lint/src/validate-page-visualization-bindings.test.ts @@ -11,15 +11,29 @@ // the pin is a copy of a copy, and the showcase run cannot see a predicate the // showcase happens not to exercise. // -// The live imports are a declared cross-package coupling (`turbo.json`'s -// `@objectstack/lint#test` inputs and `scripts/cross-package-test-inputs.mjs`), -// which puts them in `check:examples-live-imports`' `inputs-declared` tier — -// both of CI's scoping layers move when the showcase moves. +// The showcase reads are a DECLARED cross-package coupling — the three modules +// are named on `@objectstack/lint#test`'s inputs in `turbo.json` and in +// `scripts/cross-package-test-inputs.mjs`, so both of CI's scoping layers move +// when the showcase moves. +// +// ⛔ They are loaded through a path built from `import.meta.url`, NOT by a +// static relative `import`, and that is not a style choice: a static import +// puts the example module inside this package's tsc program, where it is +// outside `rootDir` and reports TS6059. `tsconfig.test.json` inherits `rootDir` +// deliberately and must not loosen it, and `test-typecheck-debt.json` is an +// EXACT, shrink-only ratchet whose expansion is maintainer-only — so a static +// import here would have to buy its way past that ratchet. The path expression +// below is the shape `check:cross-package-test-inputs` recognises +// (`resolve(HERE, '')` seeded from `import.meta.url`, per AGENTS.md), so +// the coupling stays visible to the gate that scopes CI. Do not "tidy" it back +// into an import statement. // // ⚠️ These pins assert the shipped app is CLEAN, which is the direction #8515's // ruling allows to stay live: nothing here needs the showcase to keep a defect. // If a showcase edit turns one red, the app is what changed. +import { dirname, resolve } from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; import { describe, it, expect } from 'vitest'; import { @@ -29,9 +43,19 @@ import { } from './validate-page-visualization-bindings.js'; import { REFERENCE_INTEGRITY_RULES } from './reference-integrity-suite.js'; -import { Task } from '../../../examples/app-showcase/src/data/objects/task.object.js'; -import { TaskViews } from '../../../examples/app-showcase/src/ui/views/task.view.js'; -import { +type AnyRec = Record; + +const HERE = dirname(fileURLToPath(import.meta.url)); +const SHOWCASE_TASK_OBJECT = resolve(HERE, '../../../examples/app-showcase/src/data/objects/task.object.ts'); +const SHOWCASE_TASK_VIEWS = resolve(HERE, '../../../examples/app-showcase/src/ui/views/task.view.ts'); +const SHOWCASE_TASK_PAGES = resolve(HERE, '../../../examples/app-showcase/src/ui/pages/task-visualizations.pages.ts'); + +const loadShowcase = async (path: string): Promise => + (await import(pathToFileURL(path).href)) as AnyRec; + +const { Task } = await loadShowcase(SHOWCASE_TASK_OBJECT); +const { TaskViews } = await loadShowcase(SHOWCASE_TASK_VIEWS); +const { TaskBoardPage, TaskCalendarPage, TaskGalleryPage, @@ -39,9 +63,7 @@ import { TaskTimelinePage, TaskMapPage, TaskAllViewsPage, -} from '../../../examples/app-showcase/src/ui/pages/task-visualizations.pages.js'; - -type AnyRec = Record; +} = await loadShowcase(SHOWCASE_TASK_PAGES); /** A `list` page with an `interfaceConfig`, spelled once. */ function listPage(name: string, cfg: AnyRec): AnyRec { @@ -141,7 +163,7 @@ describe('the shipped showcase interface pages (regression pin)', () => { TaskTimelinePage, // ['timeline'] TaskMapPage, // ['map'], bound through `sourceView: 'map'` TaskAllViewsPage, // the full switcher - ] as unknown as AnyRec[]; + ] as AnyRec[]; const stack: AnyRec = { objects: [Task], @@ -179,11 +201,11 @@ describe('the shipped showcase interface pages (regression pin)', () => { // The other direction on the same corpus: strip `showcase_task`'s date // fields and the calendar / timeline / gantt pages must go red. Without // this, "zero findings" is compatible with a rule that never fires. - const fields = { ...((Task as unknown as AnyRec).fields as AnyRec) }; + const fields = { ...((Task as AnyRec).fields as AnyRec) }; for (const dateField of ['due_date', 'start_date', 'end_date', 'created_at']) delete fields[dateField]; const dated = validatePageVisualizationBindings({ ...stack, - objects: [{ ...(Task as unknown as AnyRec), fields }], + objects: [{ ...(Task as AnyRec), fields }], }); expect(dated.map((f) => `${f.severity}:${f.path}`)).toEqual([ // ['calendar'] — leading, so the page IS the refusal screen From fbd3e69dcd353bc21e966626eda6bd4272560b96 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Sep 2026 20:51:01 +0000 Subject: [PATCH 3/3] feat(lint): resolve an interface page's whitelisted visualizations Keep repo path literals out of the test's prose: the cross-package input gate reads path-shaped strings out of source text, comments included. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_0174WZTU6XcFcS7g2kykC53i --- .../src/validate-page-visualization-bindings.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/lint/src/validate-page-visualization-bindings.test.ts b/packages/lint/src/validate-page-visualization-bindings.test.ts index 38e51d57724..c5ffd113448 100644 --- a/packages/lint/src/validate-page-visualization-bindings.test.ts +++ b/packages/lint/src/validate-page-visualization-bindings.test.ts @@ -12,9 +12,9 @@ // showcase happens not to exercise. // // The showcase reads are a DECLARED cross-package coupling — the three modules -// are named on `@objectstack/lint#test`'s inputs in `turbo.json` and in -// `scripts/cross-package-test-inputs.mjs`, so both of CI's scoping layers move -// when the showcase moves. +// are named on `@objectstack/lint#test`'s inputs in `turbo.json` and in the +// `check:cross-package-test-inputs` registry beside it, so both of CI's scoping +// layers move when the showcase moves. // // ⛔ They are loaded through a path built from `import.meta.url`, NOT by a // static relative `import`, and that is not a style choice: a static import @@ -26,7 +26,9 @@ // below is the shape `check:cross-package-test-inputs` recognises // (`resolve(HERE, '')` seeded from `import.meta.url`, per AGENTS.md), so // the coupling stays visible to the gate that scopes CI. Do not "tidy" it back -// into an import statement. +// into an import statement — and note that the gate reads PATH LITERALS out of +// this file's source, comments included, so a prose reference to a repo file +// this test does not actually read would be reported as an undeclared input. // // ⚠️ These pins assert the shipped app is CLEAN, which is the direction #8515's // ruling allows to stay live: nothing here needs the showcase to keep a defect.