|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * #22472 — `record:approval_decision`, the approval decision panel, through the |
| 5 | + * authoring rules `os validate` / `os build` / `os lint` run. The ruling that |
| 6 | + * asked for the declaration (objectui#12045, 6079807016, letter 乙) gave its |
| 7 | + * reason as exactly these two doors: a type with no `ComponentPropsMap` row |
| 8 | + * passes any props bag, so a misspelled property drops in silence, and a type |
| 9 | + * the vocabulary does not declare inside the reserved `record` namespace is |
| 10 | + * refused outright. The spec-side pins (the row, the enum member, the print |
| 11 | + * classification) live beside the row in `@objectstack/spec`. |
| 12 | + */ |
| 13 | +import { describe, expect, it } from 'vitest'; |
| 14 | + |
| 15 | +import { runAuthoringRules } from './authoring-rules.js'; |
| 16 | +import { COMPONENT_PROPS_UNKNOWN_KEY, validateComponentProps } from './validate-component-props.js'; |
| 17 | +import { COMPONENT_TYPE_UNKNOWN, validateComponentTypes } from './validate-component-types.js'; |
| 18 | + |
| 19 | +type AnyRec = Record<string, unknown>; |
| 20 | + |
| 21 | +/** The request page plugin-approvals authors: one record page, one region. */ |
| 22 | +const requestPage = (components: unknown[]): AnyRec => ({ |
| 23 | + pages: [ |
| 24 | + { |
| 25 | + name: 'approval_request_detail', |
| 26 | + label: 'Approval request', |
| 27 | + type: 'record', |
| 28 | + object: 'sys_approval_request', |
| 29 | + regions: [{ name: 'main', components }], |
| 30 | + }, |
| 31 | + ], |
| 32 | +}); |
| 33 | + |
| 34 | +const ourRules = (stack: AnyRec) => |
| 35 | + runAuthoringRules('validate', { normalized: stack as never }).filter( |
| 36 | + (f) => f.rule.startsWith('component-props') || f.rule === COMPONENT_TYPE_UNKNOWN, |
| 37 | + ); |
| 38 | + |
| 39 | +describe('a node with no props passes both doors', () => { |
| 40 | + it.each([ |
| 41 | + ['no `properties` at all', { type: 'record:approval_decision' }], |
| 42 | + ['an empty `properties`', { type: 'record:approval_decision', properties: {} }], |
| 43 | + ['node-level keys only', { type: 'record:approval_decision', id: 'decision', className: 'mt-4' }], |
| 44 | + ])('%s', (_label, node) => { |
| 45 | + expect(validateComponentProps(requestPage([node]))).toEqual([]); |
| 46 | + expect(validateComponentTypes(requestPage([node]))).toEqual([]); |
| 47 | + expect(ourRules(requestPage([node]))).toEqual([]); |
| 48 | + }); |
| 49 | +}); |
| 50 | + |
| 51 | +describe('any authored key is a `component-props-unknown-key` finding, naming the key', () => { |
| 52 | + it.each(['showProgress', 'actions', 'requestId'])('`%s`', (key) => { |
| 53 | + const stack = requestPage([{ type: 'record:approval_decision', properties: { [key]: true } }]); |
| 54 | + const findings = validateComponentProps(stack); |
| 55 | + expect(findings).toHaveLength(1); |
| 56 | + const [f] = findings; |
| 57 | + expect(f.rule).toBe(COMPONENT_PROPS_UNKNOWN_KEY); |
| 58 | + expect(f.severity).toBe('warning'); |
| 59 | + expect(f.path).toBe(`pages[0].regions[0].components[0].properties.${key}`); |
| 60 | + expect(f.where).toBe('page "approval_request_detail" · record:approval_decision'); |
| 61 | + expect(f.message).toContain(`\`${key}\``); |
| 62 | + expect(f.message).toContain('`record:approval_decision`'); |
| 63 | + |
| 64 | + // The same finding reaches the shared pipeline the authoring commands run. |
| 65 | + const viaPipeline = ourRules(stack); |
| 66 | + expect(viaPipeline.map((x) => x.rule)).toEqual([COMPONENT_PROPS_UNKNOWN_KEY]); |
| 67 | + }); |
| 68 | +}); |
| 69 | + |
| 70 | +describe('a misspelled type in the reserved `record` namespace is refused', () => { |
| 71 | + it('`record:approval_decison` is `component-type-unknown`, offering the declared spelling', () => { |
| 72 | + const stack = requestPage([{ type: 'record:approval_decison' }]); |
| 73 | + const findings = validateComponentTypes(stack); |
| 74 | + expect(findings).toHaveLength(1); |
| 75 | + const [f] = findings; |
| 76 | + expect(f.rule).toBe(COMPONENT_TYPE_UNKNOWN); |
| 77 | + expect(f.severity).toBe('error'); |
| 78 | + expect(f.path).toBe('pages[0].regions[0].components[0].type'); |
| 79 | + expect(f.message).toContain('`record:approval_decison`'); |
| 80 | + expect(f.message).toContain("'record:approval_decision'"); |
| 81 | + |
| 82 | + expect(ourRules(stack).map((x) => x.rule)).toEqual([COMPONENT_TYPE_UNKNOWN]); |
| 83 | + }); |
| 84 | + |
| 85 | + it('control: the declared spelling in the same position is not refused', () => { |
| 86 | + expect(validateComponentTypes(requestPage([{ type: 'record:approval_decision' }]))).toEqual([]); |
| 87 | + }); |
| 88 | +}); |
0 commit comments