diff --git a/.changeset/20015-name-field-id.md b/.changeset/20015-name-field-id.md new file mode 100644 index 00000000000..c9e5124a944 --- /dev/null +++ b/.changeset/20015-name-field-id.md @@ -0,0 +1,23 @@ +--- +"@objectstack/plugin-approvals": patch +"@objectstack/service-automation": patch +"@objectstack/service-messaging": patch +--- + +fix(plugin-approvals, service-automation, service-messaging): five system objects title their records with a text formula instead of the raw id (#20015) + +Clause-②: no + +ADR-0079 resolves a record's title as `nameField`, then `displayNameField`, then a derivation, and an explicit `nameField` takes precedence over the render-only `titleFormat`. Five system objects declared `nameField: 'id'` beside a composite `titleFormat`. A renderer that follows ADR-0079's order therefore showed the raw record id as the record page's title for: + +- `sys_approval_request`, whose `titleFormat` is `{process_name} · {record_id}`; +- `sys_approval_action`, whose `titleFormat` is `{action} · {step_name}`; +- `sys_approval_approver`, whose `titleFormat` is `{approver} · {request_id}`; +- `sys_automation_run`, whose `titleFormat` is `{flow_name} · {node_id}`; +- `sys_http_delivery`, whose `titleFormat` is `{label} → {url}`. + +Each object now declares `display_title`, a formula field with `returnType: 'text'` over the same columns, and points `nameField` and `displayNameField` at it. This is the migration the `titleFormat` schema text prescribes: "a composite to a formula field designated as nameField". The record title is now the text the `titleFormat` described. Where a source column is nullable (`step_name`, `node_id`, `label`), a row without it is titled by the other column alone. + +A formula field is computed when a record is read. It adds no database column, so no schema migration runs. Record reads and write responses now carry `display_title`. For these objects the server-side title accessor (`resolveRecordTitle`) now returns the formula's text instead of the raw id. + +`titleFormat` stays on all five objects, unchanged, for renderers that still read it first. `$search` resolution is unchanged: a formula field is never a search target, and neither was `id`. diff --git a/packages/plugins/plugin-approvals/src/sys-approval-action.object.ts b/packages/plugins/plugin-approvals/src/sys-approval-action.object.ts index 6c5a318d9ad..9f3e95d2feb 100644 --- a/packages/plugins/plugin-approvals/src/sys-approval-action.object.ts +++ b/packages/plugins/plugin-approvals/src/sys-approval-action.object.ts @@ -1,6 +1,7 @@ // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. import { ObjectSchema, Field } from '@objectstack/spec/data'; +import { F } from '@objectstack/spec'; import { APPROVAL_ACTION_KINDS, APPROVAL_ACTION_KIND_LABELS } from '@objectstack/spec/contracts'; /** @@ -22,8 +23,14 @@ export const SysApprovalAction = ObjectSchema.create({ isSystem: true, managedBy: 'append-only', description: 'Append-only audit trail for approval actions', - displayNameField: 'id', - nameField: 'id', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField) + // [ADR-0079] The record title is `display_title`, a text formula over the + // same two columns `titleFormat` names. The pointer used to be `id`: once a + // renderer honours ADR-0079's order (an explicit `nameField` wins over + // `titleFormat`), that made the record page's H1 the raw id. `titleFormat` + // stays for renderers that still read it first; + // `sys-approval-display-title.test.ts` holds the two to the same text. + displayNameField: 'display_title', + nameField: 'display_title', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField) titleFormat: '{action} · {step_name}', highlightFields: ['request_id', 'step_name', 'action', 'actor_id', 'via_override', 'created_at'], @@ -71,6 +78,17 @@ export const SysApprovalAction = ObjectSchema.create({ fields: { id: Field.text({ label: 'Action ID', required: true, readonly: true, group: 'System' }), + // [ADR-0079] The record title (`nameField` above). A formula is computed on + // read and has no stored column. `step_name` is nullable, so a row without + // one is titled by its action alone rather than failing to evaluate. + display_title: Field.formula({ + label: 'Title', + returnType: 'text', + expression: F`record.step_name != null ? record.action + ' · ' + record.step_name : record.action`, + description: 'Record title: the action and, when recorded, its step (computed on read)', + group: 'Action', + }), + organization_id: Field.lookup('sys_organization', { label: 'Organization', required: false, diff --git a/packages/plugins/plugin-approvals/src/sys-approval-approver.object.ts b/packages/plugins/plugin-approvals/src/sys-approval-approver.object.ts index bc8569c2153..839d1fad216 100644 --- a/packages/plugins/plugin-approvals/src/sys-approval-approver.object.ts +++ b/packages/plugins/plugin-approvals/src/sys-approval-approver.object.ts @@ -1,6 +1,7 @@ // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. import { ObjectSchema, Field } from '@objectstack/spec/data'; +import { F } from '@objectstack/spec'; /** * sys_approval_approver — Pending-approver index (issue #1745). @@ -32,14 +33,31 @@ export const SysApprovalApprover = ObjectSchema.create({ isSystem: true, managedBy: 'engine-owned', description: 'Normalized pending-approver rows for indexed inbox queries', - displayNameField: 'id', - nameField: 'id', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField) + // [ADR-0079] The record title is `display_title`, a text formula over the + // same two columns `titleFormat` names. The pointer used to be `id`: once a + // renderer honours ADR-0079's order (an explicit `nameField` wins over + // `titleFormat`), that made the record page's H1 the raw id. `titleFormat` + // stays for renderers that still read it first; + // `sys-approval-display-title.test.ts` holds the two to the same text. + displayNameField: 'display_title', + nameField: 'display_title', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField) titleFormat: '{approver} · {request_id}', highlightFields: ['request_id', 'approver', 'created_at'], fields: { id: Field.text({ label: 'Row ID', required: true, readonly: true, group: 'System' }), + // [ADR-0079] The record title (`nameField` above). A formula is computed on + // read and has no stored column. Both source columns are required, so the + // expression needs no null guard. + display_title: Field.formula({ + label: 'Title', + returnType: 'text', + expression: F`record.approver + ' · ' + record.request_id`, + description: 'Record title: the approver identity and its request (computed on read)', + group: 'Target', + }), + organization_id: Field.lookup('sys_organization', { label: 'Organization', required: false, diff --git a/packages/plugins/plugin-approvals/src/sys-approval-display-title.test.ts b/packages/plugins/plugin-approvals/src/sys-approval-display-title.test.ts new file mode 100644 index 00000000000..af1e43423a6 --- /dev/null +++ b/packages/plugins/plugin-approvals/src/sys-approval-display-title.test.ts @@ -0,0 +1,160 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The record title of the three approval objects that used to point + * `nameField` at `id` (#20015). + * + * ADR-0079 resolves a record's title as `nameField ?? displayNameField ?? + * derivation`, and an explicit `nameField` takes precedence over the + * render-only `titleFormat`. A renderer that honours that order therefore + * showed the raw id as the record page's H1 for `sys_approval_action`, + * `sys_approval_approver` and `sys_approval_request`, because each of them + * declared `nameField: 'id'` beside a composite `titleFormat`. + * + * Each object now points at `display_title`, a text formula over the same + * columns. This file asserts, per object, through the real engine: + * + * 1. the title field ADR-0079's order resolves is `display_title`, not `id`; + * 2. a seeded row read back through `findOne` carries the H1 the + * `titleFormat` intended, and that H1 is not the row's id; + * 3. the server-side title accessor (`resolveRecordTitle`) agrees; + * 4. the formula adds no stored column. + * + * Where a source column is nullable, a row without it is titled by the other + * column rather than failing to evaluate. + */ + +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; +import { ObjectQL, resolveRecordTitle } from '@objectstack/objectql'; +import { SqlDriver } from '@objectstack/driver-sql'; +import { resolveDisplayField } from '@objectstack/spec/data'; +import { SysApprovalAction } from './sys-approval-action.object.js'; +import { SysApprovalApprover } from './sys-approval-approver.object.js'; +import { SysApprovalRequest } from './sys-approval-request.object.js'; + +const SYS = { context: { isSystem: true } } as any; + +/** + * The H1 a `titleFormat`-first renderer draws: each `{field}` placeholder + * substituted with the row's value. It is the reference the formula has to + * reproduce, not a second title resolver. The parsed schema carries + * `titleFormat` as a `{ dialect: 'template', source }` envelope. + */ +function renderTitleFormat(titleFormat: unknown, row: Record): string { + const source = typeof titleFormat === 'string' ? titleFormat : (titleFormat as { source?: unknown })?.source; + if (typeof source !== 'string') throw new Error(`titleFormat carries no template source: ${JSON.stringify(titleFormat)}`); + return source.replace(/\{\{?\s*([a-zA-Z0-9_.]+)\s*\}?\}/g, (_m, key: string) => String(row[key] ?? '')); +} + +/** The H1 under ADR-0079's order: the value at the resolved title field. */ +function h1Of(schema: unknown, row: Record): unknown { + const field = resolveDisplayField(schema as any); + return field === undefined ? undefined : row[field]; +} + +/** The stored row as a hook body holds it: no formula value on it. */ +function storedOnly(row: Record): Record { + const { display_title: _omit, ...rest } = row; + return rest; +} + +describe('[#20015] approval objects resolve a real record title under ADR-0079 order', () => { + let engine: ObjectQL; + let driver: SqlDriver; + + beforeAll(async () => { + engine = new ObjectQL(); + driver = new SqlDriver({ + client: 'better-sqlite3', + connection: { filename: ':memory:' }, + useNullAsDefault: true, + }); + engine.registerDriver(driver, true); + await engine.init(); + for (const o of [SysApprovalRequest, SysApprovalAction, SysApprovalApprover]) { + engine.registry.registerObject(o as any, 'com.objectstack.test.20015'); + } + await engine.syncSchemas(); + }); + + afterAll(async () => { + try { await engine?.destroy(); } catch { /* noop */ } + }); + + it('points all three objects at display_title, a text formula', () => { + for (const schema of [SysApprovalRequest, SysApprovalAction, SysApprovalApprover]) { + expect(resolveDisplayField(schema as any)).toBe('display_title'); + const field = (schema.fields as Record).display_title; + expect(field?.type).toBe('formula'); + expect(field?.returnType).toBe('text'); + } + }); + + it('sys_approval_request: the H1 is "{process_name} · {record_id}", not the id', async () => { + const created = await engine.insert('sys_approval_request', { + process_name: 'flow:deal_desk', object_name: 'opportunity', record_id: 'opp_42', + status: 'pending', + }, SYS); + // The write response carries the title too (read-your-write). + expect(created.display_title).toBe('flow:deal_desk · opp_42'); + const row = await engine.findOne('sys_approval_request', { where: { id: created.id } }, SYS); + expect(row).not.toBeNull(); + + expect(h1Of(SysApprovalRequest, row!)).toBe('flow:deal_desk · opp_42'); + expect(h1Of(SysApprovalRequest, row!)).not.toBe(row!.id); + expect(h1Of(SysApprovalRequest, row!)).toBe(renderTitleFormat(SysApprovalRequest.titleFormat, row!)); + expect(resolveRecordTitle(SysApprovalRequest, storedOnly(row!))).toBe('flow:deal_desk · opp_42'); + }); + + it('sys_approval_action: the H1 is "{action} · {step_name}", and the action alone without a step', async () => { + const request = await engine.insert('sys_approval_request', { + process_name: 'flow:deal_desk', object_name: 'opportunity', record_id: 'opp_43', + status: 'pending', + }, SYS); + + const stepped = await engine.insert('sys_approval_action', { + request_id: request.id, action: 'approve', step_name: 'manager_review', + }, SYS); + const row = await engine.findOne('sys_approval_action', { where: { id: stepped.id } }, SYS); + expect(h1Of(SysApprovalAction, row!)).toBe('approve · manager_review'); + expect(h1Of(SysApprovalAction, row!)).not.toBe(row!.id); + expect(h1Of(SysApprovalAction, row!)).toBe(renderTitleFormat(SysApprovalAction.titleFormat, row!)); + expect(resolveRecordTitle(SysApprovalAction, storedOnly(row!))).toBe('approve · manager_review'); + + const stepless = await engine.insert('sys_approval_action', { + request_id: request.id, action: 'submit', + }, SYS); + const bare = await engine.findOne('sys_approval_action', { where: { id: stepless.id } }, SYS); + expect(bare!.step_name ?? null).toBeNull(); + expect(h1Of(SysApprovalAction, bare!)).toBe('submit'); + expect(resolveRecordTitle(SysApprovalAction, storedOnly(bare!))).toBe('submit'); + }); + + it('sys_approval_approver: the H1 is "{approver} · {request_id}", not the id', async () => { + const request = await engine.insert('sys_approval_request', { + process_name: 'flow:deal_desk', object_name: 'opportunity', record_id: 'opp_44', + status: 'pending', + }, SYS); + const created = await engine.insert('sys_approval_approver', { + request_id: request.id, approver: 'role:finance', + }, SYS); + const row = await engine.findOne('sys_approval_approver', { where: { id: created.id } }, SYS); + + expect(h1Of(SysApprovalApprover, row!)).toBe(`role:finance · ${request.id}`); + expect(h1Of(SysApprovalApprover, row!)).not.toBe(row!.id); + expect(h1Of(SysApprovalApprover, row!)).toBe(renderTitleFormat(SysApprovalApprover.titleFormat, row!)); + expect(resolveRecordTitle(SysApprovalApprover, storedOnly(row!))).toBe(`role:finance · ${request.id}`); + }); + + it('adds no stored column: the formula is computed on read', async () => { + for (const [object, sourceColumn] of [ + ['sys_approval_request', 'process_name'], + ['sys_approval_action', 'step_name'], + ['sys_approval_approver', 'approver'], + ] as const) { + const columns = Object.keys(await driver.getKnex()(object).columnInfo()); + expect(columns).toContain(sourceColumn); + expect(columns).not.toContain('display_title'); + } + }); +}); diff --git a/packages/plugins/plugin-approvals/src/sys-approval-request.object.ts b/packages/plugins/plugin-approvals/src/sys-approval-request.object.ts index 51ec92d3cb5..76c460b546c 100644 --- a/packages/plugins/plugin-approvals/src/sys-approval-request.object.ts +++ b/packages/plugins/plugin-approvals/src/sys-approval-request.object.ts @@ -1,6 +1,7 @@ // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. import { ObjectSchema, Field } from '@objectstack/spec/data'; +import { F } from '@objectstack/spec'; import { APPROVAL_STATUSES, APPROVAL_STATUS_LABELS, @@ -44,8 +45,14 @@ export const SysApprovalRequest = ObjectSchema.create({ isSystem: true, managedBy: 'engine-owned', description: 'Live approval instance tracked per submission', - displayNameField: 'id', - nameField: 'id', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField) + // [ADR-0079] The record title is `display_title`, a text formula over the + // same two columns `titleFormat` names. The pointer used to be `id`: once a + // renderer honours ADR-0079's order (an explicit `nameField` wins over + // `titleFormat`), that made the record page's H1 the raw id. `titleFormat` + // stays for renderers that still read it first; + // `sys-approval-display-title.test.ts` holds the two to the same text. + displayNameField: 'display_title', + nameField: 'display_title', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField) titleFormat: '{process_name} · {record_id}', highlightFields: ['process_name', 'object_name', 'record_id', 'status', 'current_step', 'submitter_id', 'updated_at'], @@ -103,6 +110,17 @@ export const SysApprovalRequest = ObjectSchema.create({ fields: { id: Field.text({ label: 'Request ID', required: true, readonly: true, group: 'System' }), + // [ADR-0079] The record title (`nameField` above). A formula is computed on + // read and has no stored column. Both source columns are required, so the + // expression needs no null guard. + display_title: Field.formula({ + label: 'Title', + returnType: 'text', + expression: F`record.process_name + ' · ' + record.record_id`, + description: 'Record title: the request source and the record it is about (computed on read)', + group: 'Target', + }), + // [#10101, the cloud#1395 Option A ruling] The SUBJECT record's // organization, with the acting context as fallback — resolved by the // SHARED platform-row resolver (`resolveRecordOrganizationField`, diff --git a/packages/plugins/plugin-approvals/src/translations/en.objects.generated.ts b/packages/plugins/plugin-approvals/src/translations/en.objects.generated.ts index 8c8972d68ec..31cb44d26b9 100644 --- a/packages/plugins/plugin-approvals/src/translations/en.objects.generated.ts +++ b/packages/plugins/plugin-approvals/src/translations/en.objects.generated.ts @@ -23,6 +23,10 @@ export const enObjects: NonNullable = { id: { label: "Request ID" }, + display_title: { + label: "Title", + help: "Record title: the request source and the record it is about (computed on read)" + }, organization_id: { label: "Organization", help: "Organization of the record this request is about (falls back to the acting context when the record has none)" @@ -212,6 +216,10 @@ export const enObjects: NonNullable = { id: { label: "Action ID" }, + display_title: { + label: "Title", + help: "Record title: the action and, when recorded, its step (computed on read)" + }, organization_id: { label: "Organization", help: "Tenant that owns this action (mirrors the parent request)" diff --git a/packages/plugins/plugin-approvals/src/translations/es-ES.objects.generated.ts b/packages/plugins/plugin-approvals/src/translations/es-ES.objects.generated.ts index 17a69af7dde..946b5aef792 100644 --- a/packages/plugins/plugin-approvals/src/translations/es-ES.objects.generated.ts +++ b/packages/plugins/plugin-approvals/src/translations/es-ES.objects.generated.ts @@ -23,6 +23,10 @@ export const esESObjects: NonNullable = { id: { label: "ID de solicitud" }, + display_title: { + label: "Título", + help: "Título del registro: el origen de la solicitud y el registro al que se refiere (calculado al leer)" + }, organization_id: { label: "Organización", help: "Organización del registro al que se refiere esta solicitud (recurre al contexto del actor cuando el registro no tiene ninguna)." @@ -212,6 +216,10 @@ export const esESObjects: NonNullable = { id: { label: "ID de acción" }, + display_title: { + label: "Título", + help: "Título del registro: la acción y, si consta, su paso (calculado al leer)" + }, organization_id: { label: "Organización", help: "Tenant que posee esta acción (refleja la solicitud principal)." diff --git a/packages/plugins/plugin-approvals/src/translations/ja-JP.objects.generated.ts b/packages/plugins/plugin-approvals/src/translations/ja-JP.objects.generated.ts index e1e35712301..ff60085bfae 100644 --- a/packages/plugins/plugin-approvals/src/translations/ja-JP.objects.generated.ts +++ b/packages/plugins/plugin-approvals/src/translations/ja-JP.objects.generated.ts @@ -23,6 +23,10 @@ export const jaJPObjects: NonNullable = { id: { label: "リクエスト ID" }, + display_title: { + label: "タイトル", + help: "レコードタイトル:申請のソースと対象レコード(読み取り時に計算)" + }, organization_id: { label: "組織", help: "このリクエストの対象レコードが属する組織(レコードに組織がない場合は操作コンテキストにフォールバック)" @@ -212,6 +216,10 @@ export const jaJPObjects: NonNullable = { id: { label: "アクション ID" }, + display_title: { + label: "タイトル", + help: "レコードタイトル:アクションと、記録されている場合はそのステップ(読み取り時に計算)" + }, organization_id: { label: "組織", help: "このアクションを所有するテナント(親リクエストと同じ)" diff --git a/packages/plugins/plugin-approvals/src/translations/zh-CN.objects.generated.ts b/packages/plugins/plugin-approvals/src/translations/zh-CN.objects.generated.ts index 3367c892782..85f126e8122 100644 --- a/packages/plugins/plugin-approvals/src/translations/zh-CN.objects.generated.ts +++ b/packages/plugins/plugin-approvals/src/translations/zh-CN.objects.generated.ts @@ -23,6 +23,10 @@ export const zhCNObjects: NonNullable = { id: { label: "请求 ID" }, + display_title: { + label: "标题", + help: "记录标题:请求来源及其所涉记录(读取时计算)" + }, organization_id: { label: "组织", help: "该请求所涉记录所属的组织(记录无组织时回退到操作上下文)" @@ -212,6 +216,10 @@ export const zhCNObjects: NonNullable = { id: { label: "动作 ID" }, + display_title: { + label: "标题", + help: "记录标题:操作,以及已记录时的步骤(读取时计算)" + }, organization_id: { label: "组织", help: "拥有该动作的租户(与父请求保持一致)" diff --git a/packages/services/service-automation/src/sys-automation-run-display-title.test.ts b/packages/services/service-automation/src/sys-automation-run-display-title.test.ts new file mode 100644 index 00000000000..663a33c2092 --- /dev/null +++ b/packages/services/service-automation/src/sys-automation-run-display-title.test.ts @@ -0,0 +1,115 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The record title of `sys_automation_run`, which used to point `nameField` + * at `id` (#20015). + * + * ADR-0079 resolves a record's title as `nameField ?? displayNameField ?? + * derivation`, and an explicit `nameField` takes precedence over the + * render-only `titleFormat`. A renderer that honours that order therefore + * showed the raw run id as the record page's H1, because the object declared + * `nameField: 'id'` beside `titleFormat: '{flow_name} · {node_id}'`. + * + * The object now points at `display_title`, a text formula over the same + * columns. This file asserts, through the real engine: the title field + * ADR-0079's order resolves; the H1 a seeded row reads back with, in both the + * node and the node-less shape; that the server-side title accessor agrees; + * and that the formula adds no stored column. + * + * The pointer-pair verdict pin (`sys-automation-run-pointer-pair-verdict.test.ts`) + * reads the same pointer for a different fact — that the title is not a key a + * seed row could match. + */ + +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; +import { ObjectQL, resolveRecordTitle } from '@objectstack/objectql'; +import { SqlDriver } from '@objectstack/driver-sql'; +import { resolveDisplayField } from '@objectstack/spec/data'; +import { SysAutomationRun } from './sys-automation-run.object.js'; + +const SYS = { context: { isSystem: true } } as any; + +/** + * The H1 a `titleFormat`-first renderer draws: each `{field}` placeholder + * substituted with the row's value. It is the reference the formula has to + * reproduce, not a second title resolver. The parsed schema carries + * `titleFormat` as a `{ dialect: 'template', source }` envelope. + */ +function renderTitleFormat(titleFormat: unknown, row: Record): string { + const source = typeof titleFormat === 'string' ? titleFormat : (titleFormat as { source?: unknown })?.source; + if (typeof source !== 'string') throw new Error(`titleFormat carries no template source: ${JSON.stringify(titleFormat)}`); + return source.replace(/\{\{?\s*([a-zA-Z0-9_.]+)\s*\}?\}/g, (_m, key: string) => String(row[key] ?? '')); +} + +/** The H1 under ADR-0079's order: the value at the resolved title field. */ +function h1Of(row: Record): unknown { + const field = resolveDisplayField(SysAutomationRun as any); + return field === undefined ? undefined : row[field]; +} + +/** The stored row as a hook body holds it: no formula value on it. */ +function storedOnly(row: Record): Record { + const { display_title: _omit, ...rest } = row; + return rest; +} + +describe('[#20015] sys_automation_run resolves a real record title under ADR-0079 order', () => { + let engine: ObjectQL; + let driver: SqlDriver; + + beforeAll(async () => { + engine = new ObjectQL(); + driver = new SqlDriver({ + client: 'better-sqlite3', + connection: { filename: ':memory:' }, + useNullAsDefault: true, + }); + engine.registerDriver(driver, true); + await engine.init(); + engine.registry.registerObject(SysAutomationRun as any, 'com.objectstack.test.20015'); + await engine.syncSchemas(); + }); + + afterAll(async () => { + try { await engine?.destroy(); } catch { /* noop */ } + }); + + it('points nameField at display_title, a text formula', () => { + expect(resolveDisplayField(SysAutomationRun as any)).toBe('display_title'); + const field = (SysAutomationRun.fields as Record).display_title; + expect(field?.type).toBe('formula'); + expect(field?.returnType).toBe('text'); + }); + + it('the H1 is "{flow_name} · {node_id}", not the run id', async () => { + const created = await engine.insert('sys_automation_run', { + flow_name: 'quote_approval', node_id: 'manager_gate', status: 'paused', + started_at: new Date('2026-09-24T00:00:00Z'), + }, SYS); + const row = await engine.findOne('sys_automation_run', { where: { id: created.id } }, SYS); + expect(row).not.toBeNull(); + + expect(h1Of(row!)).toBe('quote_approval · manager_gate'); + expect(h1Of(row!)).not.toBe(row!.id); + expect(h1Of(row!)).toBe(renderTitleFormat(SysAutomationRun.titleFormat, row!)); + expect(resolveRecordTitle(SysAutomationRun, storedOnly(row!))).toBe('quote_approval · manager_gate'); + }); + + it('a run with no node is titled by its flow alone', async () => { + const created = await engine.insert('sys_automation_run', { + flow_name: 'nightly_sweep', status: 'completed', + started_at: new Date('2026-09-24T00:00:00Z'), + }, SYS); + const row = await engine.findOne('sys_automation_run', { where: { id: created.id } }, SYS); + expect(row!.node_id ?? null).toBeNull(); + + expect(h1Of(row!)).toBe('nightly_sweep'); + expect(resolveRecordTitle(SysAutomationRun, storedOnly(row!))).toBe('nightly_sweep'); + }); + + it('adds no stored column: the formula is computed on read', async () => { + const columns = Object.keys(await driver.getKnex()('sys_automation_run').columnInfo()); + expect(columns).toContain('flow_name'); + expect(columns).not.toContain('display_title'); + }); +}); diff --git a/packages/services/service-automation/src/sys-automation-run-pointer-pair-verdict.test.ts b/packages/services/service-automation/src/sys-automation-run-pointer-pair-verdict.test.ts index 4023bac75f7..1e90b06f2de 100644 --- a/packages/services/service-automation/src/sys-automation-run-pointer-pair-verdict.test.ts +++ b/packages/services/service-automation/src/sys-automation-run-pointer-pair-verdict.test.ts @@ -28,8 +28,10 @@ import { SysAutomationRun } from './sys-automation-run.object.js'; * - a terminal row is telemetry under this object's own retention contract * (`class: 'telemetry'`, 30d sweep scoped to completed/failed), so seeded * run history deletes itself on the first Reaper pass that reaches its age. - * - the object has no natural key to be addressed BY: `nameField: 'id'`, the - * id is the engine's raw `runId`, and there is no `name` field at all. + * - the object has no natural key to be addressed BY: the id is the engine's + * raw `runId`, there is no `name` field at all, and the title pointer names + * a formula (`display_title`, #20015), which has no stored column a seed + * row could match on. * * Declaring would not make a real corpus resolvable; it would advertise run * rows as authorable seed content. To flip it: land a consumer that reads the @@ -64,6 +66,14 @@ describe('sys_automation_run — pointer pair stays undeclared (#11386 verdict)' it('has no natural key a seed dataset could address its rows by — one of the verdict\'s measured legs', () => { expect(fields.name).toBeUndefined(); - expect(SysAutomationRun.nameField).toBe('id'); + // [#20015] Re-judged, not dropped. This leg used to read the pointer as + // `id`. The pointer now names `display_title` so the record page's H1 is a + // real title under ADR-0079's order. The leg still holds: a formula is + // computed on read and has no stored column, so the title is not a key a + // seed row could match. If the pointer ever names a STORED column, this + // goes red and the verdict above needs re-deriving. + const titleField = SysAutomationRun.nameField as string; + expect(titleField).toBe('display_title'); + expect(fields[titleField]?.type).toBe('formula'); }); }); diff --git a/packages/services/service-automation/src/sys-automation-run.object.ts b/packages/services/service-automation/src/sys-automation-run.object.ts index 04eb7f433a8..a2016b9646c 100644 --- a/packages/services/service-automation/src/sys-automation-run.object.ts +++ b/packages/services/service-automation/src/sys-automation-run.object.ts @@ -1,6 +1,7 @@ // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. import { ObjectSchema, Field } from '@objectstack/spec/data'; +import { F } from '@objectstack/spec'; /** * sys_automation_run — Durable state of a **suspended** automation flow run. @@ -67,8 +68,14 @@ export const SysAutomationRun = ObjectSchema.create({ }, }, description: 'Durable automation run state: live suspended runs (resumable, ADR-0019) and terminal run history (completed / failed / cancelled / timed_out / refused, for observability).', - displayNameField: 'id', - nameField: 'id', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField) + // [ADR-0079] The record title is `display_title`, a text formula over the + // same two columns `titleFormat` names. The pointer used to be `id`: once a + // renderer honours ADR-0079's order (an explicit `nameField` wins over + // `titleFormat`), that made the record page's H1 the raw run id. + // `titleFormat` stays for renderers that still read it first; + // `sys-automation-run-display-title.test.ts` holds the two to the same text. + displayNameField: 'display_title', + nameField: 'display_title', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField) titleFormat: '{flow_name} · {node_id}', // `selected_count`/`acted_count` sit in the highlight set on purpose (#4354): // "selected 30, acted 0" has to be visible on the run row itself, not one @@ -78,6 +85,17 @@ export const SysAutomationRun = ObjectSchema.create({ fields: { id: Field.text({ label: 'Run ID', required: true, readonly: true, group: 'System' }), + // [ADR-0079] The record title (`nameField` above). A formula is computed on + // read and has no stored column. `node_id` is nullable, so a row without + // one is titled by its flow alone rather than failing to evaluate. + display_title: Field.formula({ + label: 'Title', + returnType: 'text', + expression: F`record.node_id != null ? record.flow_name + ' · ' + record.node_id : record.flow_name`, + description: 'Record title: the flow and, when recorded, its node (computed on read)', + group: 'Identity', + }), + // [#10101, the cloud#1395 Option A ruling] The SUBJECT record's // organization, with the acting context as fallback — resolved by the // SHARED platform-row resolver (`resolveRecordOrganizationField`, @@ -249,10 +267,11 @@ export const SysAutomationRun = ObjectSchema.create({ // contract (`class: 'telemetry'`, 30d sweep scoped to // completed/failed), so seeded run history deletes itself on the first // Reaper pass that reaches its age. - // - the row has no natural key to be addressed BY: `nameField: 'id'`, - // the id is the engine's raw `runId`, and the object declares no `name` - // field at all — the seed loader's default externalId does not exist - // here. + // - the row has no natural key to be addressed BY: the id is the + // engine's raw `runId`, the title (`nameField: 'display_title'`) is a + // formula with no stored column to match against, and the object + // declares no `name` field at all — the seed loader's default + // externalId does not exist here. // Declaring would therefore not make a real corpus resolvable; it would // advertise run rows as authorable seed content — precisely the wrong // signal for a metadata author (human or AI) reading the declaration as diff --git a/packages/services/service-messaging/src/objects/http-delivery-display-title.test.ts b/packages/services/service-messaging/src/objects/http-delivery-display-title.test.ts new file mode 100644 index 00000000000..db7c6b8a4f8 --- /dev/null +++ b/packages/services/service-messaging/src/objects/http-delivery-display-title.test.ts @@ -0,0 +1,116 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The record title of `sys_http_delivery`, which used to point `nameField` at + * `id` (#20015). + * + * ADR-0079 resolves a record's title as `nameField ?? displayNameField ?? + * derivation`, and an explicit `nameField` takes precedence over the + * render-only `titleFormat`. A renderer that honours that order therefore + * showed the raw delivery UUID as the record page's H1, because the object + * declared `nameField: 'id'` beside `titleFormat: '{label} → {url}'`. + * + * The object now points at `display_title`, a text formula over the same + * columns. This file asserts, through the real engine: the title field + * ADR-0079's order resolves; the H1 a seeded row reads back with, in both the + * labelled and the label-less shape; that the server-side title accessor + * agrees; and that the formula adds no stored column. + */ + +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; +import { ObjectQL, resolveRecordTitle } from '@objectstack/objectql'; +import { SqlDriver } from '@objectstack/driver-sql'; +import { resolveDisplayField } from '@objectstack/spec/data'; +import { HttpDelivery } from './http-delivery.object.js'; + +const SYS = { context: { isSystem: true } } as any; + +/** + * The H1 a `titleFormat`-first renderer draws: each `{field}` placeholder + * substituted with the row's value. It is the reference the formula has to + * reproduce, not a second title resolver. The parsed schema carries + * `titleFormat` as a `{ dialect: 'template', source }` envelope. + */ +function renderTitleFormat(titleFormat: unknown, row: Record): string { + const source = typeof titleFormat === 'string' ? titleFormat : (titleFormat as { source?: unknown })?.source; + if (typeof source !== 'string') throw new Error(`titleFormat carries no template source: ${JSON.stringify(titleFormat)}`); + return source.replace(/\{\{?\s*([a-zA-Z0-9_.]+)\s*\}?\}/g, (_m, key: string) => String(row[key] ?? '')); +} + +/** The H1 under ADR-0079's order: the value at the resolved title field. */ +function h1Of(row: Record): unknown { + const field = resolveDisplayField(HttpDelivery as any); + return field === undefined ? undefined : row[field]; +} + +/** The stored row as a hook body holds it: no formula value on it. */ +function storedOnly(row: Record): Record { + const { display_title: _omit, ...rest } = row; + return rest; +} + +/** Every column the object requires, so each case names only what it varies. */ +function delivery(overrides: Record): Record { + const now = new Date('2026-09-24T00:00:00Z'); + return { + source: 'webhook', ref_id: 'wh_1', dedup_key: `evt_${Math.random().toString(36).slice(2)}`, + url: 'https://hooks.example.com/in', payload_json: '{}', partition_key: 0, + status: 'pending', attempts: 0, created_at: now, updated_at: now, + ...overrides, + }; +} + +describe('[#20015] sys_http_delivery resolves a real record title under ADR-0079 order', () => { + let engine: ObjectQL; + let driver: SqlDriver; + + beforeAll(async () => { + engine = new ObjectQL(); + driver = new SqlDriver({ + client: 'better-sqlite3', + connection: { filename: ':memory:' }, + useNullAsDefault: true, + }); + engine.registerDriver(driver, true); + await engine.init(); + engine.registry.registerObject(HttpDelivery as any, 'com.objectstack.test.20015'); + await engine.syncSchemas(); + }); + + afterAll(async () => { + try { await engine?.destroy(); } catch { /* noop */ } + }); + + it('points nameField at display_title, a text formula', () => { + expect(resolveDisplayField(HttpDelivery as any)).toBe('display_title'); + const field = (HttpDelivery.fields as Record).display_title; + expect(field?.type).toBe('formula'); + expect(field?.returnType).toBe('text'); + }); + + it('the H1 is "{label} → {url}", not the delivery UUID', async () => { + const created = await engine.insert('sys_http_delivery', delivery({ label: 'order.created' }), SYS); + const row = await engine.findOne('sys_http_delivery', { where: { id: created.id } }, SYS); + expect(row).not.toBeNull(); + + expect(h1Of(row!)).toBe('order.created → https://hooks.example.com/in'); + expect(h1Of(row!)).not.toBe(row!.id); + expect(h1Of(row!)).toBe(renderTitleFormat(HttpDelivery.titleFormat, row!)); + expect(resolveRecordTitle(HttpDelivery, storedOnly(row!))).toBe('order.created → https://hooks.example.com/in'); + }); + + it('a delivery with no label is titled by its target URL alone', async () => { + const created = await engine.insert('sys_http_delivery', delivery({}), SYS); + const row = await engine.findOne('sys_http_delivery', { where: { id: created.id } }, SYS); + expect(row!.label ?? null).toBeNull(); + + expect(h1Of(row!)).toBe('https://hooks.example.com/in'); + expect(resolveRecordTitle(HttpDelivery, storedOnly(row!))).toBe('https://hooks.example.com/in'); + }); + + it('adds no stored column: the formula is computed on read', async () => { + const columns = Object.keys(await driver.getKnex()('sys_http_delivery').columnInfo()); + expect(columns).toContain('url'); + expect(columns).not.toContain('display_title'); + }); +}); diff --git a/packages/services/service-messaging/src/objects/http-delivery.object.ts b/packages/services/service-messaging/src/objects/http-delivery.object.ts index acc40e29581..687d58e60f5 100644 --- a/packages/services/service-messaging/src/objects/http-delivery.object.ts +++ b/packages/services/service-messaging/src/objects/http-delivery.object.ts @@ -1,6 +1,7 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. import { Field, ObjectSchema } from '@objectstack/spec/data'; +import { F } from '@objectstack/spec'; /** * `sys_http_delivery` — durable outbox row for one outbound-HTTP attempt @@ -42,8 +43,14 @@ export const HttpDelivery = ObjectSchema.create({ userActions: { create: false, edit: false, delete: false, import: false }, description: 'Durable outbox row for one outbound-HTTP attempt (ADR-0018). Managed by @objectstack/service-messaging; do not write directly.', - displayNameField: 'id', - nameField: 'id', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField) + // [ADR-0079] The record title is `display_title`, a text formula over the + // same two columns `titleFormat` names. The pointer used to be `id`: once a + // renderer honours ADR-0079's order (an explicit `nameField` wins over + // `titleFormat`), that made the record page's H1 the raw delivery UUID. + // `titleFormat` stays for renderers that still read it first; + // `http-delivery-display-title.test.ts` holds the two to the same text. + displayNameField: 'display_title', + nameField: 'display_title', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField) titleFormat: '{label} → {url}', highlightFields: ['source', 'url', 'status', 'attempts', 'next_retry_at'], @@ -93,6 +100,17 @@ export const HttpDelivery = ObjectSchema.create({ description: 'UUID — also doubles as the receiver-side idempotency key', }), + // [ADR-0079] The record title (`nameField` above). A formula is computed + // on read and has no stored column. `label` is nullable, so a row + // without one is titled by its target URL alone rather than failing to + // evaluate. + display_title: Field.formula({ + label: 'Title', + returnType: 'text', + expression: F`record.label != null ? record.label + ' → ' + record.url : record.url`, + description: 'Record title: the delivery label, when set, and its target URL (computed on read)', + }), + source: Field.text({ label: 'Source', required: true, diff --git a/packages/services/service-messaging/src/translations/en.objects.generated.ts b/packages/services/service-messaging/src/translations/en.objects.generated.ts index d9659852001..f1d9938dc5c 100644 --- a/packages/services/service-messaging/src/translations/en.objects.generated.ts +++ b/packages/services/service-messaging/src/translations/en.objects.generated.ts @@ -313,6 +313,10 @@ export const enObjects: NonNullable = { label: "Delivery ID", help: "UUID — also doubles as the receiver-side idempotency key" }, + display_title: { + label: "Title", + help: "Record title: the delivery label, when set, and its target URL (computed on read)" + }, source: { label: "Source", help: "Provenance domain, e.g. 'webhook' | 'flow'. UNIQUE(source, dedup_key)." diff --git a/packages/services/service-messaging/src/translations/es-ES.objects.generated.ts b/packages/services/service-messaging/src/translations/es-ES.objects.generated.ts index 9a168ea7f09..f4233f24290 100644 --- a/packages/services/service-messaging/src/translations/es-ES.objects.generated.ts +++ b/packages/services/service-messaging/src/translations/es-ES.objects.generated.ts @@ -313,6 +313,10 @@ export const esESObjects: NonNullable = { label: "Delivery ID", help: "UUID — also doubles as the receiver-side idempotency key" }, + display_title: { + label: "Título", + help: "Título del registro: la etiqueta de la entrega, si existe, y su URL de destino (calculado al leer)" + }, source: { label: "Source", help: "Provenance domain, e.g. 'webhook' | 'flow'. UNIQUE(source, dedup_key)." diff --git a/packages/services/service-messaging/src/translations/ja-JP.objects.generated.ts b/packages/services/service-messaging/src/translations/ja-JP.objects.generated.ts index 51136382d97..d902bf925e6 100644 --- a/packages/services/service-messaging/src/translations/ja-JP.objects.generated.ts +++ b/packages/services/service-messaging/src/translations/ja-JP.objects.generated.ts @@ -313,6 +313,10 @@ export const jaJPObjects: NonNullable = { label: "Delivery ID", help: "UUID — also doubles as the receiver-side idempotency key" }, + display_title: { + label: "タイトル", + help: "レコードタイトル:配信ラベル(設定されている場合)と送信先 URL(読み取り時に計算)" + }, source: { label: "Source", help: "Provenance domain, e.g. 'webhook' | 'flow'. UNIQUE(source, dedup_key)." diff --git a/packages/services/service-messaging/src/translations/zh-CN.objects.generated.ts b/packages/services/service-messaging/src/translations/zh-CN.objects.generated.ts index 00f6e7bf127..08bf60680bf 100644 --- a/packages/services/service-messaging/src/translations/zh-CN.objects.generated.ts +++ b/packages/services/service-messaging/src/translations/zh-CN.objects.generated.ts @@ -313,6 +313,10 @@ export const zhCNObjects: NonNullable = { label: "投递 ID", help: "UUID——同时作为接收方的幂等键" }, + display_title: { + label: "标题", + help: "记录标题:投递标签(如已设置)和目标 URL(读取时计算)" + }, source: { label: "来源", help: "来源域,如 'webhook' | 'flow'。UNIQUE(source, dedup_key)。"