diff --git a/.changeset/nav-platform-object-requires-object.md b/.changeset/nav-platform-object-requires-object.md new file mode 100644 index 00000000000..34f223daf88 --- /dev/null +++ b/.changeset/nav-platform-object-requires-object.md @@ -0,0 +1,9 @@ +--- +"@objectstack/spec": patch +"@objectstack/platform-objects": patch +--- + +Clause-②: no +Metadata-protocol: none + +An app menu entry naming a platform object the stack does not declare (`sys_task`, `sys_note`, or any `sys_`/`cloud_`/`ai_` name) is still refused by `defineStack` / `os validate`, but the refusal now names the fix: add `requiresObject: ''` to the entry (the menu hides it wherever the object is not registered) and do not declare a copy of the object in the package. A name without a platform prefix keeps the old message. The `sys_task` and `sys_note` docblocks now teach the menu entry with `requiresObject`. diff --git a/packages/platform-objects/src/work/sys-note.object.ts b/packages/platform-objects/src/work/sys-note.object.ts index 6b63449e46f..28e1749b701 100644 --- a/packages/platform-objects/src/work/sys-note.object.ts +++ b/packages/platform-objects/src/work/sys-note.object.ts @@ -10,6 +10,13 @@ import { ObjectSchema, Field } from '@objectstack/spec/data'; * customizable object — an organization adds fields and views — and comments * and attachments work on it as on any record. * + * Every environment carries it, so an app puts notes in its menu with a + * navigation entry naming it instead of declaring its own note object: + * `{ type: 'object', objectName: 'sys_note', requiresObject: 'sys_note' }`. + * The entry needs `requiresObject` — `defineStack` refuses a menu entry for an + * object the stack does not declare unless the entry says the object comes + * from elsewhere. + * * ## The heading a list shows * * The title is optional. A list and a record header show `heading`, which the diff --git a/packages/platform-objects/src/work/sys-task.object.ts b/packages/platform-objects/src/work/sys-task.object.ts index cfb635924ef..8d88205803d 100644 --- a/packages/platform-objects/src/work/sys-task.object.ts +++ b/packages/platform-objects/src/work/sys-task.object.ts @@ -10,7 +10,11 @@ export const TASK_DONE_STATUS = 'done'; * * Every environment carries it, whichever application is installed, so an app * puts tasks in its menu with a `type: 'object'` navigation entry naming - * `sys_task` instead of declaring its own task object. It is an ordinary + * `sys_task` instead of declaring its own task object: + * `{ type: 'object', objectName: 'sys_task', requiresObject: 'sys_task' }`. + * The entry needs `requiresObject` — `defineStack` refuses a menu entry for an + * object the stack does not declare unless the entry says the object comes + * from elsewhere. It is an ordinary * customizable object: an organization adds fields and views to it, and * comments and attachments work on it as on any record (`enable.files` is on; * the comment feed is on by default). diff --git a/packages/spec/src/stack-nav-platform-object-requires-object.test.ts b/packages/spec/src/stack-nav-platform-object-requires-object.test.ts new file mode 100644 index 00000000000..2f7d6155d53 --- /dev/null +++ b/packages/spec/src/stack-nav-platform-object-requires-object.test.ts @@ -0,0 +1,80 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * An app menu entry naming a platform object (`sys_task`, `sys_note`) that the + * stack does not declare. + * + * The refusal stays: the platform-prefix test cannot tell an object every + * environment carries from one a plugin contributes, so exempting the prefix + * would let a menu point at an absent object. What changes is the message: for + * a platform-prefixed name it names the fix, `requiresObject`, and warns + * against declaring a package copy, which "not defined in objects" alone + * invites. A name without the prefix keeps the old message. + */ + +import { describe, it, expect } from 'vitest'; +import { defineStack } from './stack.zod'; + +type Envelope = Error & { code?: string; status?: number; issues?: readonly string[] }; + +function refusalOf(run: () => unknown): Envelope | null { + try { + run(); + return null; + } catch (e) { + return e as Envelope; + } +} + +const manifest = { + id: 'app.example.starter', + name: 'Starter', + version: '1.0.0', + type: 'app' as const, + namespace: 'starter', +}; + +const company = { name: 'starter_company', label: 'Company', fields: { title: { type: 'text' as const } } }; + +const stackWithEntry = (entry: Record) => + ({ + manifest, + objects: [company], + apps: [ + { + name: 'starter', + label: 'Starter', + navigation: [ + { id: 'nav_companies', type: 'object', label: 'Companies', objectName: 'starter_company' }, + { id: 'nav_entry', type: 'object', label: 'Entry', ...entry }, + ], + }, + ], + }) as unknown as Parameters[0]; + +const base = (name: string) => + `App 'starter' navigation references object '${name}' which is not defined in objects.`; + +describe('app navigation naming a platform object the stack does not declare', () => { + it.each(['sys_task', 'sys_note'])('refuses %s without requiresObject, and the message names requiresObject', (name) => { + const refused = refusalOf(() => defineStack(stackWithEntry({ objectName: name }))); + expect(refused?.code).toBe('STACK_CROSS_REFERENCE_INVALID'); + expect(refused?.status).toBe(422); + const issue = refused?.issues?.find((i) => i.startsWith(base(name))); + expect(issue).toBeDefined(); + expect(issue).toContain(`requiresObject: '${name}'`); + expect(issue).toContain('do not declare a copy'); + }); + + it.each(['sys_task', 'sys_note'])('accepts %s with requiresObject naming it', (name) => { + expect(refusalOf(() => defineStack(stackWithEntry({ objectName: name, requiresObject: name })))).toBeNull(); + }); + + it('keeps the old message, with no requiresObject hint, for an unknown name without the platform prefix', () => { + const refused = refusalOf(() => defineStack(stackWithEntry({ objectName: 'starter_missing' }))); + expect(refused?.code).toBe('STACK_CROSS_REFERENCE_INVALID'); + expect(refused?.status).toBe(422); + expect(refused?.issues).toContain(base('starter_missing')); + expect(refused?.issues?.some((i) => i.includes('requiresObject'))).toBe(false); + }); +}); diff --git a/packages/spec/src/stack.zod.ts b/packages/spec/src/stack.zod.ts index 4277b5c4c26..fe3aa01de8a 100644 --- a/packages/spec/src/stack.zod.ts +++ b/packages/spec/src/stack.zod.ts @@ -6587,8 +6587,19 @@ function validateCrossReferences( // hides the entry when the object isn't in the SchemaRegistry, // and stack-level cross-ref validation must skip it. if (!nav.requiresObject) { + // A platform-prefixed name is still refused: the prefix test + // cannot tell an object every environment carries from one a + // plugin contributes, so exempting it would let a menu point at + // an object that is absent. The message names the fix instead — + // `requiresObject` — because "not defined in objects" alone + // invites declaring a package copy of a platform object. + const base = `App '${appName}' navigation references object '${nav.objectName}' which is not defined in objects.`; errors.push( - `App '${appName}' navigation references object '${nav.objectName}' which is not defined in objects.`, + isPlatformObjectName(nav.objectName) + ? `${base} '${nav.objectName}' is provided by the platform or a plugin, not by this stack: ` + + `add requiresObject: '${nav.objectName}' to the entry (the menu then hides it wherever the object ` + + `is not registered), and do not declare a copy of the object in this package.` + : base, ); } }