diff --git a/.changeset/38930-custom-pair-info.md b/.changeset/38930-custom-pair-info.md new file mode 100644 index 00000000000..faebe02c25d --- /dev/null +++ b/.changeset/38930-custom-pair-info.md @@ -0,0 +1,16 @@ +--- +'@objectstack/service-package': patch +--- + +Clause-②: no +Metadata-protocol: none + +The boot no longer warns that a customization pair the platform created "declares no engines.protocol range". The +log level moved for platform-created pairs only: a `.custom` package written by the ensure door (Studio's first +customization of an App) has no `engines`, so on every restart it was reported as `[protocol] package 'APP.custom' +declares no engines.protocol range; rehydrating without a compatibility check` at `warn`, about a manifest nothing in +the project declares. It is now one `info` line saying the platform created the pair for its App. A pair is +recognised by the App relation the ensure door writes — its App is installed, and it declares the App's pair +namespace and a dependency on the App — never by the `.custom` id alone. Every other package with no range, +including any package you authored, keeps the warning exactly as before. Nothing is stamped on existing pairs and no +data is migrated; nothing to do on upgrade. diff --git a/packages/services/service-package/src/hydration-platform-pair-log-level.test.ts b/packages/services/service-package/src/hydration-platform-pair-log-level.test.ts new file mode 100644 index 00000000000..464a574f895 --- /dev/null +++ b/packages/services/service-package/src/hydration-platform-pair-log-level.test.ts @@ -0,0 +1,140 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { describe, it, expect, vi } from 'vitest'; +import { PackageServicePlugin } from './index.js'; + +/** + * The boot's `no-range` line, per who wrote the package (maintainer ruling + * 7350104973 on the v19 upgrade-docs card, option C). + * + * The ensure door (`ensurePairOnce`, `@objectstack/metadata-protocol` + * `protocol-customization-package.ts`) writes a customization pair with no + * `engines`, so every Studio-created pair used to WARN at every boot that it + * "declares no engines.protocol range" — a warning about the platform's own + * manifest that nothing in the project can act on. Such a pair now rehydrates + * with an INFO line saying the platform created it. A package a user authored + * that declares no range keeps the warning exactly as before. + * + * "Platform-created" is the App relation the door writes and judges an + * existing pair by — the installed base, the base's pair namespace, a + * dependency on the base — never the `.custom` id alone. + */ + +/** A code-registered App, the read-only base a pair customizes. */ +const APP = { id: 'crm', name: 'CRM', version: '2.3.0', type: 'app', namespace: 'crm', engines: { protocol: '^19' } }; + +/** The manifest exactly as the ensure door writes it for APP (no `engines`). */ +const PAIR = { + id: 'crm.custom', + name: 'CRM (custom)', + version: '0.1.0', + type: 'module', + namespace: 'crm_custom', + dependencies: { crm: '^2' }, +}; + +/** A package a user authored, declaring no range. */ +const USER = { id: 'acme.tools', name: 'Acme tools', version: '1.0.0', type: 'module', namespace: 'acme' }; + +const NO_RANGE_WARNING = (id: string) => + `[protocol] package '${id}' declares no engines.protocol range; rehydrating without a compatibility check (ADR-0087).`; + +function row(manifest: { id: string; version: string }) { + return { + id: manifest.id, + version: manifest.version, + manifest: JSON.stringify(manifest), + metadata: '{}', + hash: 'h', + created_at: 't', + updated_at: 't', + }; +} + +/** A registry that holds what `installPackage` gives it, seeded with the code-registered packages. */ +function makeRegistry(seeded: Array>) { + const held = new Map }>( + seeded.map((m) => [String(m.id), { manifest: m }]), + ); + return { + installPackage: vi.fn((manifest: Record) => { + const rec = { manifest }; + held.set(String(manifest.id), rec); + return rec; + }), + getPackage: vi.fn((id: string) => held.get(id)), + }; +} + +async function boot(stored: Array<{ id: string; version: string }>, seeded: Array> = [APP]) { + const registry = makeRegistry(seeded); + const execute = vi.fn(async ({ sql }: { sql: string }) => { + if (/SELECT \* FROM sys_packages/i.test(sql)) return { rows: stored.map(row) }; + return { rows: [] }; + }); + const services = new Map([['objectql', { execute, registry }]]); + const logger = { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }; + const ctx = { + logger, + getService: (n: string) => services.get(n), + registerService: (n: string, s: unknown) => services.set(n, s), + } as never; + await new PackageServicePlugin().start(ctx); + const said = (fn: ReturnType) => + fn.mock.calls.map((c: unknown[]) => String(c[0])).filter((m: string) => m.startsWith('[protocol]')); + return { registry, warns: said(logger.warn), infos: said(logger.info), errors: logger.error }; +} + +describe('boot rehydration: the no-range line of a platform-created customization pair (ruling 7350104973)', () => { + it('a pair the ensure door created rehydrates with an info line naming the platform, and no warning', async () => { + const { registry, warns, infos, errors } = await boot([PAIR]); + + expect(registry.installPackage).toHaveBeenCalledWith(expect.objectContaining({ id: 'crm.custom' }), 'authored'); + expect(errors).not.toHaveBeenCalled(); + expect(warns).toEqual([]); + expect(infos).toHaveLength(1); + expect(infos[0]).toContain(`package 'crm.custom'`); + expect(infos[0]).toContain(`the platform created for 'crm'`); + }); + + it('a pair whose App is itself a stored row hydrates after it and is still named platform-created', async () => { + const storedApp = { ...APP, id: 'sales', namespace: 'sales' }; + const pair = { ...PAIR, id: 'sales.custom', namespace: 'sales_custom', dependencies: { sales: '^2' } }; + // Stored order puts the pair first; the dependency order hydrates the App before it. + const { warns, infos } = await boot([pair, storedApp], []); + + expect(warns).toEqual([]); + expect(infos).toHaveLength(1); + expect(infos[0]).toContain(`the platform created for 'sales'`); + }); +}); + +describe('boot rehydration: a package a user authored keeps the no-range warning (ruling 7350104973)', () => { + it('a user package that declares no range warns exactly as before', async () => { + const { warns, infos } = await boot([USER]); + + expect(warns).toEqual([NO_RANGE_WARNING('acme.tools')]); + expect(infos).toEqual([]); + }); + + it('a pair-shaped id alone is not the marker: a `.custom` package without the pair namespace warns', async () => { + const lookalike = { ...PAIR, namespace: 'crm_tools' }; + const { warns, infos } = await boot([lookalike]); + + expect(warns).toEqual([NO_RANGE_WARNING('crm.custom')]); + expect(infos).toEqual([]); + }); + + it('a `.custom` package that declares no dependency on its base warns', async () => { + const { dependencies: _dropped, ...noDependency } = PAIR; + const { warns } = await boot([noDependency]); + + expect(warns).toEqual([NO_RANGE_WARNING('crm.custom')]); + }); + + it('a `.custom` package whose base is not installed warns', async () => { + const { warns } = await boot([PAIR], []); + + expect(warns).toEqual([NO_RANGE_WARNING('crm.custom')]); + }); +}); diff --git a/packages/services/service-package/src/index.ts b/packages/services/service-package/src/index.ts index 49251c2f051..3b4c7036d77 100644 --- a/packages/services/service-package/src/index.ts +++ b/packages/services/service-package/src/index.ts @@ -5,6 +5,7 @@ import { declaredDependencyIds, orderHydrationBatch } from '@objectstack/core'; import { createHash } from 'node:crypto'; import { checkProtocolCompat } from '@objectstack/metadata-core'; import type { ObjectStackManifest } from '@objectstack/spec/kernel'; +import { customizationBasePackageId, customizationNamespace } from '@objectstack/spec/kernel'; import type { IDataEngine } from '@objectstack/spec/contracts'; import { ensurePackageTable, @@ -452,6 +453,37 @@ interface PackageStorageDeclaration { ensure(): Promise; } +/** + * [ADR-0146 D3, maintainer ruling 7350104973] The base a stored package is the + * PLATFORM-CREATED customization pair of, or `undefined` when it is not one. + * + * The ensure door (`ensurePairOnce`, `@objectstack/metadata-protocol`) writes + * the pair with no `engines`, so its boot `no-range` line is about the + * platform's own manifest, not the user's: such a pair is reported at `info`, + * naming the platform; every other package keeps the warning. The marker is + * the App relation the door writes and judges an existing pair by + * (`customizationPairEnsureRefusal`) — the base is installed, the package + * declares the base's pair namespace and a dependency on the base — ⛔ never + * the `.custom` id alone. Existing pairs already carry it: nothing is stamped + * and nothing is migrated. + */ +function platformCreatedPairBase( + manifest: { id?: unknown; namespace?: unknown; dependencies?: unknown } | undefined, + getInstalled: (id: string) => { manifest?: { namespace?: unknown } } | undefined, +): string | undefined { + const baseId = customizationBasePackageId(manifest?.id); + if (baseId === null) return undefined; + const base = getInstalled(baseId); + if (!base) return undefined; + const namespace = customizationNamespace(base.manifest?.namespace); + if (!namespace.ok || manifest?.namespace !== namespace.value) return undefined; + const dependencies = manifest?.dependencies; + const range = typeof dependencies === 'object' && dependencies !== null && !Array.isArray(dependencies) + ? (dependencies as Record)[baseId] + : undefined; + return typeof range === 'string' && range !== '' ? baseId : undefined; +} + /** * Carry a `sys_packages` row's stored times onto the registry record its boot * hydration just installed: `created_at` as `installedAt`, `updated_at` as @@ -839,7 +871,16 @@ export class PackageServicePlugin implements Plugin { ); continue; } - if (compat.status === 'no-range') { + const pairBase = compat.status === 'no-range' + ? platformCreatedPairBase(rec.manifest, (pkg) => registry.getPackage(pkg)) + : undefined; + if (pairBase !== undefined) { + logger.info( + `[protocol] package '${id}' is the customization package the platform created for '${pairBase}' ` + + `(ADR-0146 D3), which declares no engines.protocol range; rehydrating it without a ` + + `compatibility check (ADR-0087). Nothing to act on.`, + ); + } else if (compat.status === 'no-range') { logger.warn( `[protocol] package '${id}' declares no engines.protocol range; ` + `rehydrating without a compatibility check (ADR-0087).`, diff --git a/packages/services/service-package/vitest.config.ts b/packages/services/service-package/vitest.config.ts index 102d2036cc7..55a42b8f8d2 100644 --- a/packages/services/service-package/vitest.config.ts +++ b/packages/services/service-package/vitest.config.ts @@ -42,6 +42,9 @@ export default defineConfig({ // The install-refusal pins read the boundary's status-to-code mapping // (`standardErrorCodeForHttpStatus`) from the source, like the rest. { find: /^@objectstack\/spec\/api$/, replacement: path.resolve(__dirname, '../../spec/src/api/index.ts') }, + // The boot's platform-created-pair line reads the pairing rules + // (`customizationBasePackageId`, `customizationNamespace`) from the source. + { find: /^@objectstack\/spec\/kernel$/, replacement: path.resolve(__dirname, '../../spec/src/kernel/index.ts') }, ], }, });