|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import { describe, expect, it } from 'vitest'; |
| 18 | +import { z } from 'zod'; |
18 | 19 | import { OverrideDeclarationSchema, OverrideDeclarationFields, CUSTOMIZATION_PACKAGE_SUFFIX } from './override-declaration.zod'; |
19 | 20 | import { OVERRIDE_TYPE_CLASSIFICATION, OVERRIDABLE_METADATA_TYPES } from './customization-package'; |
20 | 21 | import { getMetadataTypeSchema } from './metadata-type-schemas'; |
@@ -62,7 +63,20 @@ describe('OverrideDeclarationSchema — the shape', () => { |
62 | 63 | it(`refuses a \`${CUSTOMIZATION_PACKAGE_SUFFIX}\` package — the declaration names the BASE, never a pair`, () => { |
63 | 64 | const r = OverrideDeclarationSchema.safeParse({ package: `com.acme.crm${CUSTOMIZATION_PACKAGE_SUFFIX}`, basedOn: '3.2.0' }); |
64 | 65 | expect(r.success).toBe(false); |
65 | | - expect(issuesOf(r)).toContainEqual(expect.objectContaining({ code: 'custom', path: 'package' })); |
| 66 | + expect(issuesOf(r)).toContainEqual(expect.objectContaining({ code: 'invalid_format', path: 'package' })); |
| 67 | + }); |
| 68 | + |
| 69 | + it('accepts an id that merely contains the suffix\'s letters', () => { |
| 70 | + for (const id of ['com.acme.customx', 'com.acme.custom-crm', 'custom']) { |
| 71 | + expect(OverrideDeclarationSchema.safeParse({ package: id, basedOn: '1.0.0' }).success, id).toBe(true); |
| 72 | + } |
| 73 | + }); |
| 74 | + |
| 75 | + it('publishes the refusal into the JSON Schema as a pattern (no dropped refinement)', () => { |
| 76 | + const json = z.toJSONSchema(OverrideDeclarationSchema) as { properties: { package: { pattern?: string } } }; |
| 77 | + const pattern = new RegExp(json.properties.package.pattern ?? ''); |
| 78 | + expect(pattern.test('com.acme.crm')).toBe(true); |
| 79 | + expect(pattern.test(`com.acme.crm${CUSTOMIZATION_PACKAGE_SUFFIX}`)).toBe(false); |
66 | 80 | }); |
67 | 81 |
|
68 | 82 | it('describes basedOn as recorded and never judged (ADR-0146 D2)', () => { |
|
0 commit comments