|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * [#18605] `enableOnInstall` — ONE AUTHORITY, and the two re-reads under it. |
| 5 | + * |
| 6 | + * The card measured the key declared in three published schemas. #18752 closed |
| 7 | + * the first half of the ruling (the install door now honours it). This file |
| 8 | + * pins the SECOND half — which of the other two declarations is a copy of the |
| 9 | + * request key and which means something else — so neither the fold nor a |
| 10 | + * silent unification can happen unobserved: |
| 11 | + * |
| 12 | + * 1. The authority is `PackageInstallRequestSchema` (`package-api.zod.ts`), |
| 13 | + * the request contract of `POST /api/v1/packages`. |
| 14 | + * 2. `InstallPackageRequestSchema` (`kernel/package-registry.zod.ts`) is a |
| 15 | + * COPY of the request key. It cannot be folded to a structural reference — |
| 16 | + * the authority sits above `kernel/` in the module graph, so |
| 17 | + * `PackageInstallRequestSchema.shape.enableOnInstall` spelled there is an |
| 18 | + * import cycle that dies under `OS_EAGER_SCHEMAS=1`, the mode `gen:schema` |
| 19 | + * and `check:authorable-surface` run in. The reference is therefore |
| 20 | + * MECHANICAL and lives here: the two declarations are parsed over one |
| 21 | + * matrix, and any drift on any cell reds. |
| 22 | + * 3. `MarketplaceInstallRequestSchema` (`marketplace/marketplace.zod.ts`) |
| 23 | + * means something else and stays. Its subject is a marketplace LISTING and |
| 24 | + * its door is the control plane's, not this platform's install door — so |
| 25 | + * what is pinned here is the difference that carries that reading, not the |
| 26 | + * sameness. |
| 27 | + */ |
| 28 | + |
| 29 | +import { describe, it, expect } from 'vitest'; |
| 30 | +import { PackageInstallRequestSchema } from './package-api.zod'; |
| 31 | +import { InstallPackageRequestSchema } from '../kernel/package-registry.zod'; |
| 32 | +import { MarketplaceInstallRequestSchema } from '../marketplace/marketplace.zod'; |
| 33 | + |
| 34 | +/** A manifest both install-request contracts accept, so only the key varies. */ |
| 35 | +const MANIFEST = { |
| 36 | + id: 'com.acme.crm', |
| 37 | + name: 'Acme CRM', |
| 38 | + version: '1.0.0', |
| 39 | + type: 'app', |
| 40 | +} as const; |
| 41 | + |
| 42 | +/** |
| 43 | + * The matrix. Each cell is a body the two contracts must answer identically — |
| 44 | + * absent (the default), both booleans, and the non-boolean spelling the door |
| 45 | + * itself treats as absent (recorded on `PackageInstallBodySchema`'s residual). |
| 46 | + */ |
| 47 | +const MATRIX: ReadonlyArray<{ name: string; enableOnInstall?: unknown }> = [ |
| 48 | + { name: 'absent — the declared default applies' }, |
| 49 | + { name: 'false — install present, not active', enableOnInstall: false }, |
| 50 | + { name: 'true — the default, spelled', enableOnInstall: true }, |
| 51 | + { name: "'false' — a string, refused by the declaration", enableOnInstall: 'false' }, |
| 52 | + { name: 'null — refused by the declaration', enableOnInstall: null }, |
| 53 | +]; |
| 54 | + |
| 55 | +describe('#18605 — `enableOnInstall` has ONE authority', () => { |
| 56 | + describe('the authority: `PackageInstallRequestSchema`', () => { |
| 57 | + it('defaults to `true` — the value the install door installs enabled on', () => { |
| 58 | + const parsed = PackageInstallRequestSchema.parse({ manifest: MANIFEST }); |
| 59 | + expect(parsed.enableOnInstall).toBe(true); |
| 60 | + }); |
| 61 | + |
| 62 | + it('carries `false` through — the value the install door installs disabled on', () => { |
| 63 | + const parsed = PackageInstallRequestSchema.parse({ manifest: MANIFEST, enableOnInstall: false }); |
| 64 | + expect(parsed.enableOnInstall).toBe(false); |
| 65 | + }); |
| 66 | + |
| 67 | + it('refuses a non-boolean by name rather than coercing it', () => { |
| 68 | + const result = PackageInstallRequestSchema.safeParse({ manifest: MANIFEST, enableOnInstall: 'false' }); |
| 69 | + expect(result.success).toBe(false); |
| 70 | + expect(result.error?.issues.some((i) => i.path.join('.') === 'enableOnInstall')).toBe(true); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + /** |
| 75 | + * ⭐ THE REFERENCE, made mechanical. `InstallPackageRequestSchema` restates |
| 76 | + * the authority's key; this is what holds the restatement equal to it in the |
| 77 | + * absence of an import that would be a cycle. |
| 78 | + */ |
| 79 | + describe('the COPY: `kernel/InstallPackageRequestSchema` answers exactly as the authority does', () => { |
| 80 | + for (const cell of MATRIX) { |
| 81 | + it(`agrees with the authority — ${cell.name}`, () => { |
| 82 | + const body: Record<string, unknown> = { manifest: MANIFEST }; |
| 83 | + if ('enableOnInstall' in cell) body.enableOnInstall = cell.enableOnInstall; |
| 84 | + |
| 85 | + const authority = PackageInstallRequestSchema.safeParse(body); |
| 86 | + const copy = InstallPackageRequestSchema.safeParse(body); |
| 87 | + |
| 88 | + expect(copy.success).toBe(authority.success); |
| 89 | + if (authority.success && copy.success) { |
| 90 | + expect(copy.data.enableOnInstall).toBe(authority.data.enableOnInstall); |
| 91 | + } |
| 92 | + }); |
| 93 | + } |
| 94 | + |
| 95 | + it('declares the key with the same type and default, not merely the same name', () => { |
| 96 | + const authorityOnly = PackageInstallRequestSchema.parse({ manifest: MANIFEST }).enableOnInstall; |
| 97 | + const copyOnly = InstallPackageRequestSchema.parse({ manifest: MANIFEST }).enableOnInstall; |
| 98 | + expect(typeof copyOnly).toBe('boolean'); |
| 99 | + expect(copyOnly).toBe(authorityOnly); |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | + /** |
| 104 | + * ⛔ The marketplace declaration is NOT folded, and these are the measured |
| 105 | + * differences that say why. If a later change makes this request a second |
| 106 | + * spelling of the install door's body, these reds are the notice. |
| 107 | + */ |
| 108 | + describe('the OTHER MEANING: `MarketplaceInstallRequestSchema` is a different request', () => { |
| 109 | + it('is keyed by a marketplace LISTING, not by a manifest', () => { |
| 110 | + expect(Object.keys(MarketplaceInstallRequestSchema.shape)).toContain('listingId'); |
| 111 | + expect(Object.keys(MarketplaceInstallRequestSchema.shape)).not.toContain('manifest'); |
| 112 | + }); |
| 113 | + |
| 114 | + it('refuses the install door\'s body — nothing can send one where the other is expected', () => { |
| 115 | + expect(MarketplaceInstallRequestSchema.safeParse({ manifest: MANIFEST }).success).toBe(false); |
| 116 | + expect(PackageInstallRequestSchema.safeParse({ listingId: 'com.acme.crm' }).success).toBe(false); |
| 117 | + }); |
| 118 | + |
| 119 | + it('declares `enableOnInstall` in its own right, defaulting to `true`', () => { |
| 120 | + const parsed = MarketplaceInstallRequestSchema.parse({ listingId: 'com.acme.crm' }); |
| 121 | + expect(parsed.enableOnInstall).toBe(true); |
| 122 | + }); |
| 123 | + }); |
| 124 | +}); |
0 commit comments