diff --git a/.changeset/36776-retired-key-field-history-prescription.md b/.changeset/36776-retired-key-field-history-prescription.md new file mode 100644 index 00000000000..9afe84dfb53 --- /dev/null +++ b/.changeset/36776-retired-key-field-history-prescription.md @@ -0,0 +1,16 @@ +--- +'@objectstack/spec': patch +--- + +fix(spec): the `enable.trash`, `versioning`, `audit`, `auditTrail`, `trackChanges` and `feedTracked` refusals point at the field-history model that runs, not at `trackHistory` + +Clause-②: no +Metadata-protocol: none + +Four retired-key refusals and two field-key renames told an author to use per-field `trackHistory` for field history. On a field, `trackHistory` only opts a media or structured-JSON type into old → new values, and `false` turns nothing off; on the object, `enable.trackHistory` opens the history ledger, not the values. So an author following the refusal set a flag that did not do what it said. + +The `enable.trash` and `versioning` refusals now say that field history is on by default: a changed field's old → new values show on the record activity timeline, except a media or structured-JSON field, which opts in with `fieldHistory: true`; `enable.fieldHistory: false` turns them off for the object, and a field opts out with its own `fieldHistory: false`. A `lifecycle` policy stays the answer for retention. The field-key refusals for `audit` and `auditTrail` say to delete the key, because values already show by default, and name `fieldHistory: false` as the field's off switch (`fieldHistory: true` opts a media or structured-JSON field in). + +The field spellings `trackChanges` and `feedTracked`, which were refused with a rename to `trackHistory`, now get the same answer as `tracked`: values show by default, `fieldHistory: false` turns them off for the field (`true` opts a media or structured-JSON field in), and `enable.fieldHistory: false` turns them off for every field on the object. + +Wording only: every key that was refused is still refused, and nothing is newly refused. Nothing to migrate. diff --git a/packages/spec/src/data/authoring-key-lint.test.ts b/packages/spec/src/data/authoring-key-lint.test.ts index 00d7fbb836f..b83436a8d11 100644 --- a/packages/spec/src/data/authoring-key-lint.test.ts +++ b/packages/spec/src/data/authoring-key-lint.test.ts @@ -245,3 +245,32 @@ describe('lintAuthoredRecordKeys — an unknown key gets the shared rename rule' expect(runComparator({ dfltValue: 'x' }, declared)[0]?.suggestion).toBe('defaultValue'); }); }); + +describe('the retired `audit` / `auditTrail` field keys prescribe the field-history model that runs', () => { + // A field's change values show by default and its off switch is its own + // `fieldHistory: false` (`resolveFieldHistory`). `trackHistory` on a field + // only opts a media or JSON type in, so the refusal never names it. + for (const key of ['audit', 'auditTrail'] as const) { + const message = (): string => { + const r = FieldSchema.safeParse({ name: 'amount', type: 'number', [key]: true }); + expect(r.success, `\`${key}\` was not refused`).toBe(false); + if (r.success) throw new Error('unreachable'); + const issue = r.error.issues.find((i) => i.code === 'unrecognized_keys'); + expect(issue, `\`${key}\` was not refused as an unknown key`).toBeTruthy(); + return issue!.message; + }; + + it(`\`${key}\`: values already show by default, and the field's off switch is named`, () => { + const m = message(); + expect(m).toContain( + 'Delete the key: a changed field\'s old → new values already show on the record activity timeline by default', + ); + expect(m).toContain('`fieldHistory: false` is this field\'s off switch'); + expect(m).toContain('`fieldHistory: true` opts a media or structured-JSON field in'); + }); + + it(`\`${key}\`: never sends the author to \`trackHistory\``, () => { + expect(message()).not.toContain('trackHistory'); + }); + } +}); diff --git a/packages/spec/src/data/authoring-key-lint.ts b/packages/spec/src/data/authoring-key-lint.ts index d0bc066681f..c4eb9828354 100644 --- a/packages/spec/src/data/authoring-key-lint.ts +++ b/packages/spec/src/data/authoring-key-lint.ts @@ -127,8 +127,8 @@ export const FIELD_KEY_GUIDANCE: Readonly< startingNumber: { why: 'never a FieldSchema key. An autonumber counter resets per rendered prefix, which `autonumberFormat` itself determines.' }, validation: { why: 'field-level predicates are not a FieldSchema key — author a `validation` metadata item on the object, which carries its own message.' }, errorMessage: { why: 'pairs with the `validation` key that never existed; a `validation` metadata item carries its own message.' }, - audit: { why: 'the `auditTrail` family was pruned in 2026-06 as dead in both layers. Use `trackHistory` for the activity timeline.' }, - auditTrail: { why: 'pruned in 2026-06 as dead in both layers. Use `trackHistory` for the activity timeline.' }, + audit: { why: 'the `auditTrail` family was pruned in 2026-06 as dead in both layers. Delete the key: a changed field\'s old → new values already show on the record activity timeline by default, and `fieldHistory: false` is this field\'s off switch (`fieldHistory: true` opts a media or structured-JSON field in).' }, + auditTrail: { why: 'pruned in 2026-06 as dead in both layers. Delete the key: a changed field\'s old → new values already show on the record activity timeline by default, and `fieldHistory: false` is this field\'s off switch (`fieldHistory: true` opts a media or structured-JSON field in).' }, pii: { why: 'the `dataQuality` governance family was pruned in 2026-06 as dead in both layers — it enforced nothing.' }, dataQuality: { why: 'pruned in 2026-06 as dead in both layers, and its leftover `DataQualityRules` schema was deleted from the public API too — it enforced nothing.' }, encrypted: { why: 'the `encryptionConfig` family was pruned in 2026-06: it implied at-rest protection that never happened. The real channel is `type: \'secret\'`.' }, diff --git a/packages/spec/src/data/field-key-aliases.ts b/packages/spec/src/data/field-key-aliases.ts index cef015e932b..e5bb5c89171 100644 --- a/packages/spec/src/data/field-key-aliases.ts +++ b/packages/spec/src/data/field-key-aliases.ts @@ -92,7 +92,10 @@ const FIELD_ALIAS_ROWS: Readonly> = { component: 'widget', renderer: 'widget', control: 'widget', mimeTypes: 'accept', allowedTypes: 'accept', fileTypes: 'accept', maxFileSize: 'maxSize', maxBytes: 'maxSize', - trackChanges: 'trackHistory', feedTracked: 'trackHistory', + // NOTE: no `trackChanges` / `feedTracked` rows. They renamed onto + // `trackHistory`, whose `false` turns nothing off and whose `true` matters + // only for a media or structured-JSON type; both keys are answered in prose + // with the `fieldHistory` model beside `tracked` in `field.zod.ts`. permissions: 'requiredPermissions', requiredCapabilities: 'requiredPermissions', }; diff --git a/packages/spec/src/data/field.test.ts b/packages/spec/src/data/field.test.ts index dcc94424980..5f6521daebf 100644 --- a/packages/spec/src/data/field.test.ts +++ b/packages/spec/src/data/field.test.ts @@ -18,6 +18,7 @@ import { ObjectSchema } from './object.zod'; import { FormSelectOptionSchema } from '../ui/view.zod'; import { SnakeCaseIdentifierSchema, SystemIdentifierSchema } from '../shared/identifiers.zod'; import { MULTI_CAPABLE_TYPES, MULTI_OPTION_TYPES, isMultiValueField } from './field-value.zod'; +import { fieldSchemaAliases } from './field-key-aliases'; describe('FieldType', () => { it('should accept valid field types', () => { @@ -208,6 +209,22 @@ describe('FieldSchema — field-level `tracked` key guidance, naming `fieldHisto const m = unrecognizedKeyMessage({ ...FIELD, totallyBogusKey: true }); expect(m).not.toContain('fieldHistory'); }); + + // `trackChanges` / `feedTracked` used to rename onto `trackHistory`, whose + // `false` turns nothing off; they now take `tracked`'s answer. + for (const key of ['trackChanges', 'feedTracked'] as const) { + it(`\`${key}\` stays rejected with the \`fieldHistory\` answer, not a rename to \`trackHistory\``, () => { + const m = unrecognizedKeyMessage({ ...FIELD, [key]: false }); + expect(m).toContain(`\`${key}\` is not a field key`); + expect(m).toContain('Write `fieldHistory: false` to turn them off for this field'); + expect(m).toContain('`enable.fieldHistory: false` on the object'); + expect(m).not.toContain('trackHistory'); + }); + + it(`\`${key}\` is no longer a rename row onto \`trackHistory\``, () => { + expect(fieldSchemaAliases()).not.toHaveProperty(key); + }); + } }); describe('FieldSchema', () => { diff --git a/packages/spec/src/data/field.zod.ts b/packages/spec/src/data/field.zod.ts index 7067b11e104..0d3ab0d986d 100644 --- a/packages/spec/src/data/field.zod.ts +++ b/packages/spec/src/data/field.zod.ts @@ -1703,6 +1703,17 @@ const INLINE_EDIT_BOOLEAN_RETIRED = + 'name it in a field group of the parent (`fieldGroups[].relatedList`). ' + 'Run `os migrate meta --from 17` to list the mechanical edits for existing sources; `--write` applies the ones it can prove, and you apply the rest by hand.'; +/** + * The prose answer for a field-level spelling of "track this field's + * history" that is not a field key: it names the `fieldHistory` model + * (`resolveFieldHistory`), never `trackHistory`. + */ +function fieldHistorySpellingAnswer(key: string): string { + return `\`${key}\` is not a field key — a field's old → new values show on the record activity timeline ` + + 'by default. Write `fieldHistory: false` to turn them off for this field (`true` opts a media or ' + + 'structured-JSON field in), or `enable.fieldHistory: false` on the object to turn them off for every field.'; +} + export const FieldSchema = lazySchema(() => { const base = strictObject({ surface: 'this field', @@ -1741,10 +1752,13 @@ export const FieldSchema = lazySchema(() => { // CASE-SENSITIVELY on the authored spelling, so a row per spelling is the // only way this channel can cover a family, and `not_null` was the spelling // it would have missed. - tracked: - '`tracked` is not a field key — a field\'s old → new values show on the record activity timeline ' - + 'by default. Write `fieldHistory: false` to turn them off for this field (`true` opts a media or ' - + 'structured-JSON field in), or `enable.fieldHistory: false` on the object to turn them off for every field.', + // `trackChanges` / `feedTracked` (the Salesforce "Track Field History" / + // "Feed Tracking" spellings) used to RENAME onto `trackHistory`, whose + // `false` turns nothing off; they take `tracked`'s answer instead, so both + // stay refused and the author is sent to the switch that works. + tracked: fieldHistorySpellingAnswer('tracked'), + trackChanges: fieldHistorySpellingAnswer('trackChanges'), + feedTracked: fieldHistorySpellingAnswer('feedTracked'), // [ADR-0158 L3] The natural spellings of a quantity's unit on the field // itself, answered in prose because the targets are NESTED keys of // `unitConfig` — the form the `currency` answer above takes. None of them diff --git a/packages/spec/src/data/object.test.ts b/packages/spec/src/data/object.test.ts index 59704181f97..e08aa8ecd93 100644 --- a/packages/spec/src/data/object.test.ts +++ b/packages/spec/src/data/object.test.ts @@ -14,6 +14,7 @@ import { collectDroppedRefinements } from '../../scripts/lib/dropped-refinements import { Field } from './field.zod'; import { defineStack } from '../stack.zod'; import { isMaskedOnReadFieldType } from './masked-field-types'; +import { resolveFieldHistory } from './field-history-default'; import { CONTROLLED_BY_PARENT_MASTER_INVALID, type ControlledByParentMasterShape } from './controlled-by-parent-master'; import type { StateMachineValidation } from './validation.zod'; @@ -100,6 +101,65 @@ describe('ObjectCapabilities', () => { .not.toMatch(/#\d{3,5}/); }); + // `enable.trash` and `versioning` both promised history, so both refusals + // say where field history lives now. It is the model `resolveFieldHistory` + // enforces (values on by default, `enable.fieldHistory: false` for the + // object, a field's own `fieldHistory: false`, a media or structured-JSON + // field opting in with `fieldHistory: true`), never `trackHistory`: on a + // field that only opts a media or JSON type in and `false` turns nothing off. + describe('retired history-promising keys prescribe the field-history model that runs', () => { + const trashMessage = (): string => { + const r = ObjectCapabilities.safeParse({ trash: false }); + expect(r.success).toBe(false); + return r.success ? '' : r.error.issues.map((i) => i.message).join('\n'); + }; + const versioningMessage = (): string => { + try { + ObjectSchema.create({ + name: 'demo', + fields: { status: { type: 'text' } }, + versioning: { enabled: true }, + } as Record as Parameters[0]); + } catch (e) { + return (e as Error).message; + } + throw new Error('`versioning` was not refused'); + }; + + for (const [key, read] of [['enable.trash', trashMessage], ['versioning', versioningMessage]] as const) { + it(`${key}: values show by default, and the two off switches are named`, () => { + const message = read(); + expect(message).toContain( + 'Field history is on by default: a changed field\'s old → new values show on the record activity timeline', + ); + expect(message, 'the default-off types are named with their opt-in').toContain( + 'except a media or structured-JSON field, which opts in with `fieldHistory: true`.', + ); + expect(message).toContain('`enable.fieldHistory: false` turns them off for the object'); + expect(message).toContain('a field opts out with its own `fieldHistory: false`'); + expect(message).toMatch(/For retention, (use )?a (data lifecycle policy \(`lifecycle`\)|`lifecycle` policy)/); + }); + + it(`${key}: never sends the author to \`trackHistory\``, () => { + expect(read()).not.toContain('trackHistory'); + }); + } + + it('the prescription agrees with resolveFieldHistory', () => { + const text = { type: 'text' } as const; + expect(resolveFieldHistory(text, {}), 'values show by default').toBe(true); + expect(resolveFieldHistory(text, { enable: { fieldHistory: false } }), 'object off switch').toBe(false); + expect(resolveFieldHistory({ ...text, fieldHistory: false }, {}), 'field off switch').toBe(false); + expect(resolveFieldHistory({ ...text, trackHistory: false }, {}), 'trackHistory: false is no off switch').toBe(true); + const json = { type: 'json' } as const; + expect(resolveFieldHistory(json, {}), 'a structured-JSON field is off by default').toBe(false); + expect(resolveFieldHistory({ ...json, fieldHistory: true }, {}), 'fieldHistory: true opts it in').toBe(true); + const image = { type: 'image' } as const; + expect(resolveFieldHistory(image, {}), 'a media field is off by default').toBe(false); + expect(resolveFieldHistory({ ...image, fieldHistory: true }, {}), 'fieldHistory: true opts it in').toBe(true); + }); + }); + it('rejects unknown capability keys instead of stripping them', () => { const result = ObjectCapabilities.safeParse({ feedEnabled: true }); expect(result.success).toBe(false); @@ -1316,7 +1376,7 @@ describe('ObjectSchema.create()', () => { it('tombstone: dead metadata keys removed in 16.0 carry upgrade guidance', () => { const cases: Array<[string, unknown, string]> = [ - ['versioning', { enabled: true }, 'trackHistory'], + ['versioning', { enabled: true }, 'fieldHistory'], ['softDelete', { enabled: true }, 'the recycle bin that shipped later (ADR-0148)'], ['search', { fields: ['name'] }, 'searchableFields'], ['recordName', { type: 'autonumber' }, 'autonumber'], diff --git a/packages/spec/src/data/object.zod.ts b/packages/spec/src/data/object.zod.ts index c92d2d57002..c2fedead40b 100644 --- a/packages/spec/src/data/object.zod.ts +++ b/packages/spec/src/data/object.zod.ts @@ -192,6 +192,24 @@ export function stripLegacyApiMethods( return kept; } +/** + * Where a retired key that promised history sends the author for FIELD + * history — the `enable.trash` and `versioning` tombstones share it, so the + * two prescriptions cannot drift apart. It states the model + * `resolveFieldHistory` (`field-history-default.ts`) enforces: values show by + * default except for the `FIELD_HISTORY_DEFAULT_OFF_TYPES` (media and + * structured JSON), which opt in with `fieldHistory: true`; the object's off + * switch is `enable.fieldHistory: false`, a field's is its own + * `fieldHistory: false`. ⛔ Never `trackHistory` here: on a field it + * only opts a media or structured-JSON type in, and `false` is not an off + * switch; on the object it opens the history ledger, not the values. + */ +const FIELD_HISTORY_PRESCRIPTION = + 'Field history is on by default: a changed field\'s old → new values show on the record ' + + 'activity timeline, except a media or structured-JSON field, which opts in with ' + + '`fieldHistory: true`. `enable.fieldHistory: false` turns them off for the object, and a ' + + 'field opts out with its own `fieldHistory: false`.'; + /** * Tombstones for RETIRED capability flags — same doctrine as the tenancy * block and the top-level `UNKNOWN_KEY_GUIDANCE` map below: a retired @@ -209,8 +227,8 @@ const CAPABILITIES_RETIRED_KEY_GUIDANCE: Record = { 'soft-delete that never ran). Delete the key. The recycle bin that shipped ' + 'later (ADR-0148) has no flag: it takes every by-id delete of a business ' + 'object, and none of a platform object (`sys_`, `cloud_`, `ai_`), whose ' + - 'deletes stay permanent. For history use per-field `trackHistory` (audit ' + - 'trail), and for retention a `lifecycle` policy. ' + + 'deletes stay permanent. ' + FIELD_HISTORY_PRESCRIPTION + ' For retention, ' + + 'a `lifecycle` policy. ' + 'This edit left `os migrate meta` with the protocol-16.x conversions: apply it by hand, or run the tool on a release that still carries the conversion — https://objectstack.ai/docs/protocol-upgrade.', mru: '`enable.mru` was removed from @objectstack/spec in the 16.x line (' + @@ -1959,9 +1977,9 @@ const UNKNOWN_KEY_GUIDANCE: Record = { 'deletes are permanent.', versioning: '`versioning` was removed from the spec in 16.0 (ADR-0049) — no ' + - 'record-versioning engine ever read it (it snapshotted no history). Use ' + - 'per-field `Field.trackHistory` for field-level history, or a data ' + - 'lifecycle policy (`lifecycle`) for retention.', + 'record-versioning engine ever read it (it snapshotted no history). ' + + FIELD_HISTORY_PRESCRIPTION + ' For retention, use a data lifecycle ' + + 'policy (`lifecycle`).', search: '`search` (the SearchConfig block) was removed from the spec in 16.0 ' + '(ADR-0049) — no search-engine config was consumed. Declare the ' + @@ -4699,8 +4717,9 @@ const ObjectSchemaBase = strictObject( /** * Declarative semantic activity milestones (ADR-0052 §5b.2). When a watched * field transitions INTO `value`, the platform emits a templated activity-row - * on the record timeline — no `*.hook.ts` / `*.flow.ts`. Complements field-level - * `trackHistory` (which renders raw "Field: old → new"): use milestones for + * on the record timeline — no `*.hook.ts` / `*.flow.ts`. Complements the + * field-change rows (raw "Field: old → new", shown by default; off with + * `enable.fieldHistory: false` or a field's `fieldHistory: false`): use milestones for * business-meaningful events ("Deal won", "Task completed"). `summary` supports * `{field}` tokens interpolated from the record; the milestone summary takes * precedence over the field-change summary for the same update. Consumed by