|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * [#30261, ADR-0146 D2, D11] `overrideDeclarationRefusedByShape` — whether the |
| 5 | + * schema the save door judges a body by refuses an `overrides` key on it, so |
| 6 | + * that no save declaring the override can land. |
| 7 | + * |
| 8 | + * The census of `os migrate packageless-overlays` lists such a row |
| 9 | + * `cannot_declare` (never `movable`), and the two overlay-write closes leave |
| 10 | + * its write open (`overlayPairFixAdmits`). Pinned over the five overlay types |
| 11 | + * the ceremony moves, one well-formed body per shape: the view CONTAINER is the |
| 12 | + * one shape that answers `true`, in each of its spellings (`list`, |
| 13 | + * `listViews`, `form`, `formViews`); every other shape spreads |
| 14 | + * `OverrideDeclarationFields` and answers `false`. So does a `view` body that |
| 15 | + * claims no member of the union (refused by the container member and by a |
| 16 | + * member that carries the key alike), and a type the door validates with no |
| 17 | + * schema. |
| 18 | + */ |
| 19 | +import { describe, expect, it } from 'vitest'; |
| 20 | +import { DEFAULT_METADATA_TYPE_REGISTRY } from '@objectstack/spec/kernel'; |
| 21 | +import { overrideDeclarationRefusedByShape } from './protocol-packaged-base-refusal.js'; |
| 22 | + |
| 23 | +const grid = (columns: readonly string[]) => ({ |
| 24 | + type: 'grid', data: { provider: 'object', object: 'task' }, columns: columns.map((field) => ({ field })), |
| 25 | +}); |
| 26 | + |
| 27 | +/** One well-formed body per shape of the five overlay types, and whether its shape refuses the key. */ |
| 28 | +const SHAPES: ReadonlyArray<{ shape: string; type: string; body: Record<string, unknown>; refused: boolean }> = [ |
| 29 | + { shape: 'view container (list)', type: 'view', refused: true, body: { object: 'task', list: { label: 'All', ...grid(['title']) } } }, |
| 30 | + { shape: 'view container (listViews)', type: 'view', refused: true, body: { object: 'task', listViews: { mine: { label: 'Mine', ...grid(['title']) } } } }, |
| 31 | + { shape: 'view container (form)', type: 'view', refused: true, body: { object: 'task', form: { type: 'simple', fields: ['title'] } } }, |
| 32 | + { shape: 'view container (formViews)', type: 'view', refused: true, body: { object: 'task', formViews: { quick: { type: 'simple', fields: ['title'] } } } }, |
| 33 | + { shape: 'single view', type: 'view', refused: false, body: { name: 'task.all', object: 'task', viewKind: 'list', label: 'All', config: grid(['title']) } }, |
| 34 | + { shape: 'list overlay', type: 'view', refused: false, body: { name: 'task.all', label: 'All', object: 'task', viewKind: 'list', columns: [{ field: 'title', label: 'Title' }] } }, |
| 35 | + { shape: 'dashboard', type: 'dashboard', refused: false, body: { name: 'crm_board', label: 'Board', widgets: [] } }, |
| 36 | + { shape: 'report', type: 'report', refused: false, body: { name: 'crm_report', label: 'Report', type: 'summary', dataset: 'crm_metrics', rows: ['month'], values: ['amount_sum'] } }, |
| 37 | + { shape: 'translation', type: 'translation', refused: false, body: { name: 'crm_fr', label: 'French', locale: 'fr', messages: { save: 'Enregistrer' } } }, |
| 38 | + { shape: 'email template', type: 'email_template', refused: false, body: { name: 'crm_welcome', label: 'Welcome', subject: 'Welcome', bodyHtml: '<p>Hi</p>' } }, |
| 39 | +]; |
| 40 | + |
| 41 | +describe('[#30261] overrideDeclarationRefusedByShape: the shapes of the five overlay types that cannot carry the declaration', () => { |
| 42 | + it('the fixture covers every overlay type the ceremony moves', () => { |
| 43 | + const overlayTypes = DEFAULT_METADATA_TYPE_REGISTRY.filter((entry) => entry.allowEnvironmentOverlay).map((entry) => entry.type).sort(); |
| 44 | + expect([...new Set(SHAPES.map((s) => s.type))].sort()).toEqual(overlayTypes); |
| 45 | + }); |
| 46 | + |
| 47 | + for (const { shape, type, body, refused } of SHAPES) { |
| 48 | + it(`${shape}: ${refused ? 'refuses' : 'carries'} the \`overrides\` key`, () => { |
| 49 | + expect(overrideDeclarationRefusedByShape(type, body)).toBe(refused); |
| 50 | + // The answer is the key's, not the body's value: a body already |
| 51 | + // carrying a declaration is answered the same way. |
| 52 | + expect(overrideDeclarationRefusedByShape(type, { ...body, overrides: { package: 'com.acme.crm' } })).toBe(refused); |
| 53 | + }); |
| 54 | + } |
| 55 | + |
| 56 | + it('a view body that claims no member of the union is not answered `true` (the container member alone names the key)', () => { |
| 57 | + expect(overrideDeclarationRefusedByShape('view', { name: 'task.all', label: 'All' })).toBe(false); |
| 58 | + }); |
| 59 | + |
| 60 | + it('another finding on a container body does not hide the key: a container with an unknown key of its own still answers `true`', () => { |
| 61 | + expect(overrideDeclarationRefusedByShape('view', { object: 'task', list: { label: 'All', ...grid(['title']) }, colour: 'red' })).toBe(true); |
| 62 | + }); |
| 63 | + |
| 64 | + it('a type the save door validates with no schema answers `false`', () => { |
| 65 | + expect(overrideDeclarationRefusedByShape('function', { name: 'f' })).toBe(false); |
| 66 | + }); |
| 67 | +}); |
0 commit comments