|
| 1 | +// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +import { describe, expect, it } from 'vitest'; |
| 4 | +import { lintConfig } from '../src/commands/lint'; |
| 5 | + |
| 6 | +const RULE = 'naming/namespace-prefix'; |
| 7 | +const prefixIssues = (config: any) => lintConfig(config).filter((i) => i.rule === RULE); |
| 8 | + |
| 9 | +describe('lint — namespace-prefix advisory (ADR-0048 §3.3)', () => { |
| 10 | + it('warns on a bare-named page without the namespace prefix', () => { |
| 11 | + const issues = prefixIssues({ |
| 12 | + manifest: { namespace: 'crm' }, |
| 13 | + pages: [{ name: 'home', label: 'Home' }], |
| 14 | + }); |
| 15 | + expect(issues).toHaveLength(1); |
| 16 | + expect(issues[0].severity).toBe('warning'); |
| 17 | + expect(issues[0].path).toBe('pages[0].name'); |
| 18 | + expect(issues[0].fix).toBe('crm_home'); |
| 19 | + expect(issues[0].message).toContain('ADR-0048'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('accepts a namespace-prefixed name', () => { |
| 23 | + expect( |
| 24 | + prefixIssues({ manifest: { namespace: 'crm' }, flows: [{ name: 'crm_onboarding' }] }), |
| 25 | + ).toHaveLength(0); |
| 26 | + }); |
| 27 | + |
| 28 | + it('exempts an app named after the namespace (ADR-0019 single-app convention)', () => { |
| 29 | + // `defineApp({ name: 'crm' })` in namespace `crm` must NOT warn. |
| 30 | + expect( |
| 31 | + prefixIssues({ manifest: { namespace: 'crm' }, apps: [{ name: 'crm' }] }), |
| 32 | + ).toHaveLength(0); |
| 33 | + }); |
| 34 | + |
| 35 | + it('exempts platform-reserved sys_ names', () => { |
| 36 | + expect( |
| 37 | + prefixIssues({ manifest: { namespace: 'crm' }, pages: [{ name: 'sys_admin' }] }), |
| 38 | + ).toHaveLength(0); |
| 39 | + }); |
| 40 | + |
| 41 | + it('covers every bare-named UI/automation type', () => { |
| 42 | + const issues = prefixIssues({ |
| 43 | + manifest: { namespace: 'crm' }, |
| 44 | + apps: [{ name: 'other' }], |
| 45 | + pages: [{ name: 'home' }], |
| 46 | + dashboards: [{ name: 'overview' }], |
| 47 | + flows: [{ name: 'onboard' }], |
| 48 | + actions: [{ name: 'send' }], |
| 49 | + reports: [{ name: 'pipeline' }], |
| 50 | + datasets: [{ name: 'sales' }], |
| 51 | + }); |
| 52 | + expect(issues).toHaveLength(7); |
| 53 | + expect(new Set(issues.map((i) => i.severity))).toEqual(new Set(['warning'])); |
| 54 | + }); |
| 55 | + |
| 56 | + it('is silent when the package declares no namespace', () => { |
| 57 | + // No manifest.namespace → nothing to prefix against; stays quiet. |
| 58 | + expect(prefixIssues({ pages: [{ name: 'home' }] })).toHaveLength(0); |
| 59 | + }); |
| 60 | + |
| 61 | + it('does not touch objects (already prefix-enforced as an error) or views', () => { |
| 62 | + const issues = prefixIssues({ |
| 63 | + manifest: { namespace: 'crm' }, |
| 64 | + objects: [{ name: 'lead', fields: { id: { type: 'text' } } }], |
| 65 | + views: [{ name: 'lead.all' }], |
| 66 | + }); |
| 67 | + expect(issues).toHaveLength(0); |
| 68 | + }); |
| 69 | +}); |
0 commit comments