From a476bbaa5bbee6d853488cbf54c40b8f3ffb200b Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 13:36:10 +0000 Subject: [PATCH 1/8] fix(cli,spec,metadata-protocol): name the own field rows beside Modify All that protocol 19 narrows The migration text no longer claims every field read is kept beside Modify All, and os migrate meta --from 18 and --stored name each own field row the viewAllFields addition does not keep. Claude-Session: https://claude.ai/code/session_01QSeKYko9cFNzePK9vaCkYe Co-authored-by: Claude --- packages/cli/src/commands/migrate/meta.ts | 10 ++ .../cli/src/utils/own-field-row-narrowing.ts | 115 +++++++++++++++ .../metadata-protocol/src/stored-migration.ts | 8 +- .../src/stored-own-field-rows.ts | 50 +++++++ ...on-view-all-fields-beside-record-bypass.ts | 5 +- ...-view-all-modify-all-cast-no-field-vote.ts | 20 ++- packages/spec/src/migrations/index.ts | 6 + .../own-field-rows-beside-modify-all.ts | 131 ++++++++++++++++++ 8 files changed, 334 insertions(+), 11 deletions(-) create mode 100644 packages/cli/src/utils/own-field-row-narrowing.ts create mode 100644 packages/metadata-protocol/src/stored-own-field-rows.ts create mode 100644 packages/spec/src/migrations/own-field-rows-beside-modify-all.ts diff --git a/packages/cli/src/commands/migrate/meta.ts b/packages/cli/src/commands/migrate/meta.ts index 62e6334bfe4..1e400af9ee3 100644 --- a/packages/cli/src/commands/migrate/meta.ts +++ b/packages/cli/src/commands/migrate/meta.ts @@ -38,6 +38,7 @@ import { import { bootSchemaStack } from '../../utils/schema-migrate.js'; import { buildDataMigrationPlugins } from '../../utils/data-migration-plugins.js'; import { absentTableReads } from '../../utils/absent-table-reads.js'; +import { ownFieldRowNarrowingSites, printOwnFieldRowNarrowing, type OwnFieldRowNarrowingSite } from '../../utils/own-field-row-narrowing.js'; import type { StoredMigrationReport } from '@objectstack/metadata-protocol'; import { OCCUPANCY_HINT, probeMigrationTarget } from '../../utils/migrate-occupancy-gate.js'; import { describeOccupancy, JOURNAL_MODE_SWITCH_NOTE } from '../../utils/sqlite-occupancy.js'; @@ -1048,6 +1049,8 @@ export interface MigrationReport { elapsed: string; /** The per-site edits the protocol-19 form move left ({@link formMoveSites}); absent or empty when none. */ formMoveSites?: readonly FormMoveSite[]; + /** The own field rows beside Modify All protocol 19 narrows ({@link ownFieldRowNarrowingSites}); absent or empty when none. */ + ownFieldRowNarrowing?: readonly OwnFieldRowNarrowingSite[]; } /** @@ -1290,6 +1293,8 @@ export function printMigrationReport(report: MigrationReport): void { if (result.applied.length > 0) printAppliedEdits(result, report.write !== undefined); // ②b The sites the protocol-19 form move left in place or owes an edit. printFormMoveSites(report.formMoveSites ?? []); + // ②c The own field rows beside Modify All the `viewAllFields: true` above does not keep. + printOwnFieldRowNarrowing(report.ownFieldRowNarrowing ?? []); // Per-hop checkpoints. if (report.step) { @@ -1541,6 +1546,8 @@ export default class MigrateMeta extends Command { const result = applyMetaMigrationsToPackages(normalized, fromMajor, toMajor); // [ADR-0159, #37112] The per-site edits the protocol-19 form move leaves. const formSites = formMoveSites(normalized, fromMajor, toMajor); + // The own field rows beside Modify All that protocol 19 narrows (named, never rewritten). + const ownRowSites = ownFieldRowNarrowingSites(normalized, fromMajor, toMajor); // Prove the migrated stack is schema-valid — the "generated, provably valid // diff" the consumer agent reviews (ADR-0087 D3/D5). @@ -1598,6 +1605,8 @@ export default class MigrateMeta extends Command { // Only when the run crosses into protocol 19 and the form move // left a site: without one the payload is what it always was. ...(formSites.length > 0 ? { formMoveSites: formSites } : {}), + // Only when the run crosses into protocol 19 and an own field row narrows. + ...(ownRowSites.length > 0 ? { ownFieldRowNarrowing: ownRowSites } : {}), hops: flags.step ? result.hops.map((h) => ({ toMajor: h.toMajor, @@ -1654,6 +1663,7 @@ export default class MigrateMeta extends Command { ...(range ? { range } : {}), elapsed: timer.display(), formMoveSites: formSites, + ownFieldRowNarrowing: ownRowSites, }); // A write refused or undone, or one that left a change by hand, is a // failed run, reported above: what it did write stays written (#38922). diff --git a/packages/cli/src/utils/own-field-row-narrowing.ts b/packages/cli/src/utils/own-field-row-narrowing.ts new file mode 100644 index 00000000000..ca15ba96065 --- /dev/null +++ b/packages/cli/src/utils/own-field-row-narrowing.ts @@ -0,0 +1,115 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `os migrate meta --from N` — the own field rows beside Modify All that the + * protocol-19 field-axis split narrows although the chain writes + * `viewAllFields: true` beside the bit (ruling of record 6912661484, step 3). + * + * The edit line the chain prints for such an entry is right: the bit keeps the + * reads Modify All cast on every field the set's own rows leave alone. What it + * cannot keep is Modify All's vote OVER the set's own rows: up to protocol 18 a + * set with Modify All on `contact` and its own `'contact.salary': + * { readable: false }` row read and edited `salary`; from 19 that row binds + * and the field is hidden from the set's holders. Validate and build stay + * green either way, so without a line naming the row the upgrade takes the + * field away silently. The predicate is the spec's + * ({@link ownFieldRowsBesideModifyAll}), shared with the `--stored` review + * list; this module only walks a source stack for it and prints it. + */ + +import chalk from 'chalk'; +import { ALL_CONVERSIONS } from '@objectstack/spec'; +import { + applyMetaMigrations, + ownFieldRowsBesideModifyAll, + type OwnFieldRowBesideModifyAll, + type OwnFieldRowProtocol18Outcome, + type OwnFieldRowProtocol19Outcome, +} from '@objectstack/spec/migrations'; + +/** The conversion whose rewritten entries the list is read beside. */ +const CONVERSION_ID = 'permission-view-all-fields-beside-record-bypass'; + +/** One narrowed own field row of one source permission set. */ +export interface OwnFieldRowNarrowingSite extends OwnFieldRowBesideModifyAll { + /** The permission set's `name`. */ + set: string; + /** Where the set sits in the stack the chain replays: `permissions[0]`, or `packages[1].manifest.permissions[0]`. */ + at: string; +} + +function isPlainRecord(value: unknown): value is Record { + return value !== null && typeof value === 'object' && !Array.isArray(value); +} + +/** + * Every narrowed own field row of the stack's permission sets, read over the + * stack as it enters the conversion's hop (the chain replayed up to the major + * below it first, where `--from` is lower), and over each + * `packages[].manifest` body of an assembled stack the same way. Empty when the + * run does not cross into the conversion's major. + */ +export function ownFieldRowNarrowingSites( + stack: Record, + fromMajor: number, + toMajor: number, +): OwnFieldRowNarrowingSite[] { + const conversion = ALL_CONVERSIONS.find((c) => c.id === CONVERSION_ID); + if (!conversion) return []; + const major = conversion.toMajor; + if (!(fromMajor < major && toMajor >= major)) return []; + + const bodies: Array<{ prefix: string; body: Record }> = [{ prefix: '', body: stack }]; + if (Array.isArray(stack.packages)) { + stack.packages.forEach((entry, i) => { + if (isPlainRecord(entry) && isPlainRecord(entry.manifest)) bodies.push({ prefix: `packages[${i}].manifest.`, body: entry.manifest }); + }); + } + + const sites: OwnFieldRowNarrowingSite[] = []; + for (const { prefix, body } of bodies) { + const entering = fromMajor < major - 1 ? applyMetaMigrations(body, fromMajor, major - 1).stack : body; + const sets = (entering as { permissions?: unknown }).permissions; + if (!Array.isArray(sets)) continue; + sets.forEach((set, i) => { + if (!isPlainRecord(set)) return; + for (const row of ownFieldRowsBesideModifyAll(set)) { + sites.push({ set: String(set.name ?? ''), at: `${prefix}permissions[${i}]`, ...row }); + } + }); + } + return sites; +} + +const PROTOCOL_18: Record = { + 'read-and-edit': 'read and edit (Modify All voted over the set\'s own row)', +}; + +const PROTOCOL_19: Record = { + hidden: 'hidden, no read and no edit (the set\'s own `readable: false` row binds)', + 'read-only': 'read only (the set\'s own row binds, and it grants no edit)', + 'edit-only-where-when-matches': 'read, and edit only on the rows the row\'s `when` matches', +}; + +/** + * Group ②c — the narrowed own field rows, after the applied edits and the form + * move sites, before the semantic notices: each names the set, the entry, the + * row, the protocol-18 and protocol-19 answer through that set, and the choice. + */ +export function printOwnFieldRowNarrowing(sites: readonly OwnFieldRowNarrowingSite[]): void { + if (sites.length === 0) return; + console.log(chalk.bold(chalk.yellow( + ` ${sites.length} own field row(s) beside Modify All that protocol 19 narrows — ` + + 'the `viewAllFields: true` written beside the bit does not keep them:', + ))); + for (const site of sites) { + console.log( + ` ${chalk.yellow('⚠')} permission set '${site.set}' (${site.at}), objects entry '${site.object}', ` + + `field row '${site.field}'`, + ); + console.log(chalk.dim(` protocol 18: ${PROTOCOL_18[site.protocol18]}`)); + console.log(chalk.dim(` protocol 19: ${PROTOCOL_19[site.protocol19]}`)); + console.log(chalk.dim(` choice: ${site.choice}`)); + } + console.log(''); +} diff --git a/packages/metadata-protocol/src/stored-migration.ts b/packages/metadata-protocol/src/stored-migration.ts index 03b22caa106..0d6c5b74004 100644 --- a/packages/metadata-protocol/src/stored-migration.ts +++ b/packages/metadata-protocol/src/stored-migration.ts @@ -37,6 +37,7 @@ */ import { ALL_CONVERSIONS } from '@objectstack/spec'; +import { formatStoredOwnFieldRows, storedOwnFieldRows, type StoredOwnFieldRow } from './stored-own-field-rows.js'; /** * What a caller with a live automation engine hands back for a stored `flow` @@ -285,6 +286,8 @@ export interface StoredViewAllFieldsReview { object: string; /** The record-bypass bits the entry carries, in this order: `viewAllRecords`, then `modifyAllRecords`. */ bits: Array<'viewAllRecords' | 'modifyAllRecords'>; + /** Beside Modify All, the set's own field rows protocol 19 narrows ({@link storedOwnFieldRows}); absent when none. */ + ownFieldRows?: StoredOwnFieldRow[]; } /** @@ -421,7 +424,7 @@ export const VIEW_ALL_FIELDS_REVIEW_CONVERSION_ID = 'permission-view-all-fields- */ export function collectViewAllFieldsReview( body: unknown, -): Array<{ object: string; bits: Array<'viewAllRecords' | 'modifyAllRecords'> }> { +): Array> { if (body === null || typeof body !== 'object' || Array.isArray(body)) return []; const entry = ALL_CONVERSIONS.find((c) => c.id === VIEW_ALL_FIELDS_REVIEW_CONVERSION_ID); if (!entry) { @@ -456,7 +459,7 @@ export function collectViewAllFieldsReview( const bits: Array<'viewAllRecords' | 'modifyAllRecords'> = []; if (objectEntry.viewAllRecords === true) bits.push('viewAllRecords'); if (objectEntry.modifyAllRecords === true) bits.push('modifyAllRecords'); - return { object, bits }; + return { object, bits, ...storedOwnFieldRows(body, object) }; }); } @@ -571,6 +574,7 @@ export function formatStoredMigrationReport(report: StoredMigrationReport): stri ); for (const r of viewAll) { lines.push(` • permission/${r.name} ${describeScope(r)} — objects entry '${r.object}' (${r.bits.join(', ')})`); + lines.push(...formatStoredOwnFieldRows(r)); } lines.push( ' Before protocol 19 View All and Modify All also opened every field of the object; they now widen ' + diff --git a/packages/metadata-protocol/src/stored-own-field-rows.ts b/packages/metadata-protocol/src/stored-own-field-rows.ts new file mode 100644 index 00000000000..8295eefe26b --- /dev/null +++ b/packages/metadata-protocol/src/stored-own-field-rows.ts @@ -0,0 +1,50 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The own field rows of a STORED permission set that protocol 19 narrows + * beside its Modify All — the rows the View All Fields review list + * (`StoredViewAllFieldsReview`) names under the entry they sit beside. + * + * A stored set is read with the 19 meaning and never rewritten (ruling of + * record 7177446075, option A); the operator restores its reads by adding + * `viewAllFields: true` to the entry through the metadata API. Beside Modify + * All that does not restore a field the set's own row hides or locks: up to + * protocol 18 Modify All voted read and edit over the set's own rows, and from + * 19 an own row beats `viewAllFields`. So each such row is named with its + * protocol-18 and protocol-19 answer and the choice. The predicate is the + * spec's ({@link ownFieldRowsBesideModifyAll}), the one `os migrate meta + * --from 18` reads over a source; this module only selects one entry's rows + * and renders them. + */ + +import { ownFieldRowsBesideModifyAll, type OwnFieldRowBesideModifyAll } from '@objectstack/spec/migrations'; + +/** One own field row beside a listed entry's Modify All that protocol 19 narrows. */ +export type StoredOwnFieldRow = Omit; + +/** + * The narrowed own field rows of `body` beside its `objects` entry `object`, + * as the member the review entry carries: absent when there is none, so an + * entry without one keeps the shape it always had. + */ +export function storedOwnFieldRows(body: unknown, object: string): { ownFieldRows?: StoredOwnFieldRow[] } { + const rows = ownFieldRowsBesideModifyAll(body) + .filter((row) => row.object === object) + .map(({ object: _object, ...row }) => row); + return rows.length > 0 ? { ownFieldRows: rows } : {}; +} + +const PROTOCOL_19: Record = { + hidden: 'hidden, no read and no edit', + 'read-only': 'read only', + 'edit-only-where-when-matches': 'read, and edit only on the rows its `when` matches', +}; + +/** The lines naming one review entry's narrowed own field rows, nested under the entry's line. */ +export function formatStoredOwnFieldRows(entry: { ownFieldRows?: readonly StoredOwnFieldRow[] }): string[] { + return (entry.ownFieldRows ?? []).map( + (row) => + ` own field row '${row.field}' beside Modify All: protocol 18 read and edit, protocol 19 ` + + `${PROTOCOL_19[row.protocol19]} (adding \`viewAllFields: true\` does not change it); ${row.choice}`, + ); +} diff --git a/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts b/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts index 53a0d6c2935..bfeede946d4 100644 --- a/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts +++ b/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts @@ -78,8 +78,9 @@ const permissionViewAllFieldsBesideRecordBypass: MetadataConversion = { summary: "object-permission entry ('*' included) with 'viewAllRecords: true' or 'modifyAllRecords: true' and no " + "'viewAllFields': 'viewAllFields: true' written beside it (from protocol 19 View All and Modify All widen " - + 'records only and cast no field vote; the bit keeps every field read they cast. Modify All\'s edit vote ' - + 'is not kept, and the set\'s own readable: false rows now bind)', + + 'records only and cast no field vote; the bit keeps the field reads they cast, except a field the set\'s ' + + 'own readable: false row hides beside Modify All, which that row now binds. Modify All\'s edit vote is not ' + + 'kept)', apply(stack, emit) { return mapCollection(stack, 'permissions', (ps, path) => { const objects = (ps as { objects?: unknown }).objects; diff --git a/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts b/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts index dbe6dddee48..8e13901bea2 100644 --- a/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts +++ b/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts @@ -6,8 +6,9 @@ import type { SemanticMigration } from '../../types.js'; // All and Modify All stop voting on fields, and `viewAllFields` is the one // "every field" bit. The D2 conversion // `permission-view-all-fields-beside-record-bypass` writes `viewAllFields: true` -// beside the two bits in a SOURCE that predates the switch, which keeps every -// field read they cast; this entry names what changes anyway, and what a +// beside the two bits in a SOURCE that predates the switch, which keeps the +// field reads they cast but a field the set's own row hides beside Modify All; +// this entry names what changes anyway, and what a // deployment owes for the permission sets it STORES, which the conversion never // rewrites (ruling of record 7177446075, option A: stored sets are read with // the 19 meaning). No `relevantWhen`: a stack with no authored permission set @@ -51,16 +52,21 @@ export const entry: SemanticMigration = { + 'every sharing and RLS reader folds through, and any field no set names, which still follows the ' + 'object grant.\n\n' + 'SOURCE permission sets: `os migrate meta --from 18 --write` adds `viewAllFields: true` beside every ' - + 'such bit (the D2 conversion `permission-view-all-fields-beside-record-bypass`), so their field reads ' - + 'are kept. The conversion replays only there: it is a default flip, retired from the load path, so the ' - + 'authoring funnel skips it, and the artifact-ingestion door and every stored-row read ' - + '(`applyConversionsToStoredItem`) refuse it by id.\n\n' + + 'such bit (the D2 conversion `permission-view-all-fields-beside-record-bypass`), which keeps the field ' + + 'reads the bits cast, except a field the set\'s own `readable: false` row hides beside its Modify All: that ' + + 'row now binds. It keeps no edit Modify All cast. `os migrate meta --from 18` names each own field row ' + + 'beside Modify All that now hides its field, makes it read-only or limits its edit to the rows its `when` ' + + 'matches, with its protocol-18 and protocol-19 answer and the choice: change the row to keep the ' + + 'protocol-18 answer, or accept the narrowing. The conversion replays only there: it is a default flip, ' + + 'retired from the load path, so the authoring funnel skips it, and the artifact-ingestion door and every ' + + 'stored-row read (`applyConversionsToStoredItem`) refuse it by id.\n\n' + 'STORED permission sets (Studio-saved, in `sys_metadata`): they are NOT rewritten on upgrade and are ' + 'read with the 19 meaning, by maintainer ruling. Studio\'s permission matrix has no `viewAllFields` ' + 'control today (it keeps the key when it saves a set that already carries it), so restore a stored ' + 'set\'s reads by adding `viewAllFields: true` to its entry through the metadata API. ' + '`os migrate meta --stored` lists every affected entry of a stored set (`viewAllFieldsReview`, read-only: ' - + 'it writes nothing). The error direction is fewer fields seen, never a field opened.', + + 'it writes nothing), and under an entry with Modify All each own field row protocol 19 narrows beside it. ' + + 'The error direction is fewer fields seen, never a field opened.', acceptanceCriteria: 'Before or after moving a deployment to protocol 19, the one-step check, for every permission set in ' + 'source and every one stored in the deployment: the set is ' diff --git a/packages/spec/src/migrations/index.ts b/packages/spec/src/migrations/index.ts index 5f65f9305fb..e6b3d20c15f 100644 --- a/packages/spec/src/migrations/index.ts +++ b/packages/spec/src/migrations/index.ts @@ -35,6 +35,12 @@ export { composeMigrationChain, MigrationFloorError, } from './chain.js'; +export { + ownFieldRowsBesideModifyAll, + type OwnFieldRowBesideModifyAll, + type OwnFieldRowProtocol18Outcome, + type OwnFieldRowProtocol19Outcome, +} from './own-field-rows-beside-modify-all.js'; export { composeReleaseChanges, composeSpecChanges, diff --git a/packages/spec/src/migrations/own-field-rows-beside-modify-all.ts b/packages/spec/src/migrations/own-field-rows-beside-modify-all.ts new file mode 100644 index 00000000000..59bf09a5328 --- /dev/null +++ b/packages/spec/src/migrations/own-field-rows-beside-modify-all.ts @@ -0,0 +1,131 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The permission-set field rows the protocol-19 field-axis split narrows + * although `viewAllFields: true` is written beside the bit — one predicate, + * read by `os migrate meta --from 18` over a source and by + * `os migrate meta --stored` over a stored set. + * + * ## The shape + * + * Up to protocol 18 Modify All (`modifyAllRecords`) voted `readable: true` and + * `editable: true` on every field of its object, OVER the set's own field rows: + * a set holding Modify All on `contact` and its own `'contact.salary': + * { readable: false }` row still read and edited `salary`. From 19 the bit + * casts no field vote; the conversion `permission-view-all-fields-beside-record-bypass` + * writes `viewAllFields: true` beside it, which votes read only, and an own row + * of the same set beats it (specific beats general, ruling of record + * 6912661484). So beside Modify All an own row is the set's whole say on its + * field, and its holders get, through this set: + * + * - `readable: false`: no read and no edit (`hidden`); + * - `readable` true, no `editable: true` (an omitted `editable` is `false`): + * the read only (`read-only`); + * - `editable: true` beside a `when`: the edit on the rows the condition + * matches only (`edit-only-where-when-matches`); + * - `editable: true` and no `when`: what protocol 18 gave — not listed. + * + * View All (`viewAllRecords`) alone is not this shape: up to 18 the set's own + * row already beat its own View All (ADR-0066 D2 ⑧, note of 2026-11-15), and + * View All never voted an edit, so its own rows give the same answer on both + * sides of the split. + * + * ## Which entries + * + * Exactly the entries the conversion rewrites (it is run here, its emitted + * paths kept, its returned stack discarded), narrowed to those holding Modify + * All: an `objects` entry, the `'*'` entry included, with + * `modifyAllRecords: true` and no `viewAllFields` key. An entry whose author + * already wrote `viewAllFields` either way is left alone by the conversion and + * by this list. A field row `OBJECT.FIELD` belongs to the set's own entry for + * `OBJECT` when it has one and to its `'*'` entry otherwise: the lookup the + * field merge takes (`holdsSuperuserBypass`, `viewAllFieldsReadVote`). + * + * The answer is per SET: another set the same holder carries can still grant + * the field (union across sets is unchanged). + */ + +import { permissionViewAllFieldsBesideRecordBypass } from '../conversions/entries/19/permission-view-all-fields-beside-record-bypass.js'; + +/** What a holder of the set read and edited on the field through this set on protocol 18. */ +export type OwnFieldRowProtocol18Outcome = 'read-and-edit'; + +/** What a holder of the set reads and edits on the field through this set on protocol 19. */ +export type OwnFieldRowProtocol19Outcome = 'hidden' | 'read-only' | 'edit-only-where-when-matches'; + +/** One own field row beside Modify All whose answer protocol 19 narrows. */ +export interface OwnFieldRowBesideModifyAll { + /** The `objects` key whose Modify All covered the row: the object name, or `'*'`. */ + object: string; + /** The row's key in the set's `fields`, as written: `OBJECT.FIELD`. */ + field: string; + protocol18: OwnFieldRowProtocol18Outcome; + protocol19: OwnFieldRowProtocol19Outcome; + /** The one-line choice: change the row to keep the protocol-18 answer, or accept the narrowing. */ + choice: string; +} + +const CHOICE: Record = { + hidden: + 'to keep the protocol-18 read and edit, change the row to `readable: true, editable: true` (deleting it ' + + 'restores the read through `viewAllFields`, and the edit only where no set names the field); ' + + 'otherwise accept the narrowing.', + 'read-only': + 'to keep the protocol-18 edit, add `editable: true` to the row; otherwise accept the narrowing.', + 'edit-only-where-when-matches': + 'to keep the protocol-18 edit on every row, remove the row\'s `when`; otherwise accept the narrowing.', +}; + +function isDict(value: unknown): value is Record { + return value !== null && typeof value === 'object' && !Array.isArray(value); +} + +/** The narrowed outcome of one own row beside Modify All, or `undefined` when 19 answers as 18 did. */ +function narrowedOutcome(row: Record): OwnFieldRowProtocol19Outcome | undefined { + if (row.readable === false) return 'hidden'; + if (row.editable !== true) return 'read-only'; + if (typeof row.when === 'string' && row.when.trim() !== '') return 'edit-only-where-when-matches'; + return undefined; +} + +/** + * The own field rows of ONE permission-set body that protocol 19 narrows beside + * the set's Modify All — see the module header for the shape. In `fields` + * order; empty when the body is not a set or nothing is narrowed. + * + * ⛔ Throws when the conversion names a path of a shape this reader does not + * know: a list that silently came back empty would tell an upgrader that no + * row of the set narrows. + */ +export function ownFieldRowsBesideModifyAll(set: unknown): OwnFieldRowBesideModifyAll[] { + if (!isDict(set) || !isDict(set.objects) || !isDict(set.fields)) return []; + const objects = set.objects; + const pathToObject = new Map( + Object.keys(objects).map((name): [string, string] => [`permissions[0].objects.${name}.viewAllFields`, name]), + ); + const rewritten = new Set(); + permissionViewAllFieldsBesideRecordBypass.apply({ permissions: [set] }, (detail) => { + const object = pathToObject.get(detail.path); + if (object === undefined) { + throw new Error( + `the conversion '${permissionViewAllFieldsBesideRecordBypass.id}' reported a path of an unknown shape ` + + `('${detail.path}'), so the own field rows beside Modify All cannot be named.`, + ); + } + rewritten.add(object); + }); + + const out: OwnFieldRowBesideModifyAll[] = []; + for (const [field, row] of Object.entries(set.fields)) { + const dot = field.indexOf('.'); + if (dot <= 0 || !isDict(row)) continue; + const objectName = field.slice(0, dot); + const covering = objects[objectName] ? objectName : '*'; + const entry = objects[covering]; + if (!rewritten.has(covering) || !isDict(entry) || entry.modifyAllRecords !== true) continue; + const protocol19 = narrowedOutcome(row); + if (!protocol19) continue; + out.push({ object: covering, field, protocol18: 'read-and-edit', protocol19, choice: CHOICE[protocol19] }); + } + return out; +} From aff1e64ff38a55f555c5c7596d21494bf990d1d1 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 13:39:46 +0000 Subject: [PATCH 2/8] test: pin the own field rows beside Modify All in the dry run, --json and the stored review list Claude-Session: https://claude.ai/code/session_01QSeKYko9cFNzePK9vaCkYe Co-authored-by: Claude --- .../migrate-meta-own-field-row-38924.test.ts | 156 ++++++++++++++++++ .../src/stored-own-field-rows.test.ts | 70 ++++++++ .../own-field-rows-beside-modify-all.test.ts | 84 ++++++++++ 3 files changed, 310 insertions(+) create mode 100644 packages/cli/test/migrate-meta-own-field-row-38924.test.ts create mode 100644 packages/metadata-protocol/src/stored-own-field-rows.test.ts create mode 100644 packages/spec/src/migrations/own-field-rows-beside-modify-all.test.ts diff --git a/packages/cli/test/migrate-meta-own-field-row-38924.test.ts b/packages/cli/test/migrate-meta-own-field-row-38924.test.ts new file mode 100644 index 00000000000..a143ab0b7eb --- /dev/null +++ b/packages/cli/test/migrate-meta-own-field-row-38924.test.ts @@ -0,0 +1,156 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `os migrate meta --from 18` names each own field row beside Modify All that + * protocol 19 narrows, and no longer says every field read is kept (#38924). + * + * ## The defect these pin + * + * Up to protocol 18 Modify All voted read and edit on every field of its + * object OVER the set's own field rows, so a set with View All + Modify All on + * `contact` and its own `'contact.salary': { readable: false }` row read and + * edited `salary`. From 19 the chain writes `viewAllFields: true` beside the + * bit, and an own row beats it: the field is hidden from the set's holders. + * The dry run said the addition kept the set's field reads and named no entry, + * so the upgrade took the field away behind a green validate and build. + * + * Pinned through the public door, `MigrateMeta.run`, in process (no process is + * spawned and no kernel is booted, so this file sits in the `unit` tier by + * behaviour): + * - the fixture set is named with its row, its protocol-19 answer and the + * choice, and the "field reads are kept" wording is absent; + * - the control, a set with View All only and no field row of its own, keeps + * its plain edit line and is not named; + * - `--json` carries the list under one new key, present only when non-empty, + * and the payload's other keys are exactly what they were. + * + * ⛔ No major is hard-coded: the range is read off the conversion's own + * `toMajor`, so the file stays true for as long as the chain carries it. + */ + +import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { stripVTControlCharacters } from 'node:util'; +import { ALL_CONVERSIONS } from '@objectstack/spec'; +import MigrateMeta from '../src/commands/migrate/meta.js'; + +const CLI_ROOT = resolve(fileURLToPath(import.meta.url), '..', '..'); + +const CONVERSION_ID = 'permission-view-all-fields-beside-record-bypass'; +const MAJOR = ALL_CONVERSIONS.find((c) => c.id === CONVERSION_ID)!.toMajor; +const FROM = String(MAJOR - 1); + +const OBJECTS = ` + objects: [ + { name: 'contact', label: 'Contact', fields: { name: { type: 'text', label: 'Name' }, salary: { type: 'currency', label: 'Salary' } } }, + { name: 'account', label: 'Account', fields: { name: { type: 'text', label: 'Name' } } }, + ],`; + +/** The control alone: View All on `account`, no field row of its own. */ +const CONTROL_SET = ` + { name: 'auditor', label: 'Auditor', objects: { account: { allowRead: true, viewAllRecords: true } } },`; + +/** The card's fixture: View All + Modify All on `contact`, and its own row hiding `salary`. */ +const FIXTURE_SET = ` + { + name: 'hr_manager', label: 'HR Manager', + objects: { contact: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true } }, + fields: { 'contact.salary': { readable: false } }, + },`; + +const config = (id: string, sets: string) => ` +export default { + manifest: { id: 'com.example.${id}', name: 'Own Row', version: '1.0.0', type: 'app' },${OBJECTS} + permissions: [${sets} + ], +}; +`; + +/** Every member a replay's payload carried before this change, in order. */ +const REPLAY_KEYS = [ + 'from', 'to', 'protocolVersion', 'applied', 'todos', 'absentTodos', + 'specChanges', 'schemaValid', 'dataMigrations', 'duration', +]; + +let dir: string; + +async function runMeta(app: 'fixture' | 'control', flags: string[]): Promise { + const out: string[] = []; + const priorExitCode = process.exitCode; + const write = vi.spyOn(process.stdout, 'write').mockImplementation(((chunk: unknown, ...rest: unknown[]) => { + out.push(String(chunk)); + const done = rest.find((r) => typeof r === 'function') as (() => void) | undefined; + done?.(); + return true; + }) as never); + const log = vi.spyOn(console, 'log').mockImplementation((...a: unknown[]) => { out.push(a.join(' ')); }); + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + const error = vi.spyOn(console, 'error').mockImplementation(() => {}); + try { + await MigrateMeta.run([join(dir, app, 'objectstack.config.ts'), '--from', FROM, ...flags], { root: CLI_ROOT }); + } finally { + write.mockRestore(); + log.mockRestore(); + warn.mockRestore(); + error.mockRestore(); + process.exitCode = priorExitCode; + } + return stripVTControlCharacters(out.join('\n')); +} + +beforeAll(() => { + dir = mkdtempSync(join(tmpdir(), 'os-migrate-own-row-')); + mkdirSync(join(dir, 'fixture')); + mkdirSync(join(dir, 'control')); + writeFileSync(join(dir, 'fixture', 'objectstack.config.ts'), config('own-row-fixture', FIXTURE_SET + CONTROL_SET)); + writeFileSync(join(dir, 'control', 'objectstack.config.ts'), config('own-row-control', CONTROL_SET)); +}); + +afterAll(() => { + rmSync(dir, { recursive: true, force: true }); +}); + +describe('os migrate meta --from 18 — the own field rows beside Modify All protocol 19 narrows (#38924)', () => { + it('names the fixture set, its row and its protocol-19 answer, and says no more that field reads are kept', async () => { + const text = await runMeta('fixture', []); + + expect(text).toContain("permission set 'hr_manager' (permissions[0]), objects entry 'contact', field row 'contact.salary'"); + expect(text).toContain('protocol 18: read and edit'); + expect(text).toContain('protocol 19: hidden, no read and no edit'); + expect(text).toMatch(/choice: to keep the protocol-18 read and edit, .*otherwise accept the narrowing\./); + expect(text).not.toContain('so their field reads are kept'); + // The control set rides in the same stack and is not named. + expect(text).not.toContain("permission set 'auditor'"); + }, 60_000); + + it('the control (View All only, no field row of its own) keeps its plain edit line and names nothing', async () => { + const text = await runMeta('control', []); + + expect(text).toContain( + `permissions[0].objects.account.viewAllFields: viewAllFields absent beside viewAllRecords: true (the bit voted on every field) → true (${CONVERSION_ID})`, + ); + expect(text).not.toContain('own field row(s) beside Modify All'); + }, 60_000); + + it('--json carries the list under `ownFieldRowNarrowing` only when non-empty; every other key is unchanged', async () => { + const withRows = JSON.parse(await runMeta('fixture', ['--json'])); + const without = JSON.parse(await runMeta('control', ['--json'])); + + expect(Object.keys(without)).toEqual(REPLAY_KEYS); + expect(Object.keys(withRows)).toEqual([...REPLAY_KEYS.slice(0, 6), 'ownFieldRowNarrowing', ...REPLAY_KEYS.slice(6)]); + expect(withRows.ownFieldRowNarrowing).toEqual([ + { + set: 'hr_manager', + at: 'permissions[0]', + object: 'contact', + field: 'contact.salary', + protocol18: 'read-and-edit', + protocol19: 'hidden', + choice: expect.stringMatching(/otherwise accept the narrowing\.$/), + }, + ]); + }, 60_000); +}); diff --git a/packages/metadata-protocol/src/stored-own-field-rows.test.ts b/packages/metadata-protocol/src/stored-own-field-rows.test.ts new file mode 100644 index 00000000000..524f91cfe22 --- /dev/null +++ b/packages/metadata-protocol/src/stored-own-field-rows.test.ts @@ -0,0 +1,70 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The View All Fields review list of `os migrate meta --stored` names, under an + * entry with Modify All, each own field row protocol 19 narrows beside it — the + * same shape `os migrate meta --from 18` names in a source. A stored set is + * never rewritten, and adding `viewAllFields: true` through the API does not + * restore such a row, so the list says so per row. An entry with no such row + * keeps the shape and the line it always had. + */ + +import { describe, expect, it } from 'vitest'; +import { collectViewAllFieldsReview, formatStoredMigrationReport, type StoredMigrationReport } from './stored-migration.js'; + +const SET = { + name: 'hr_manager', + objects: { + contact: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true }, + account: { allowRead: true, viewAllRecords: true }, + }, + fields: { + 'contact.salary': { readable: false }, + 'contact.grade': { readable: true }, + // View All alone: the own row bound on 18 already, so nothing to name. + 'account.revenue': { readable: false }, + }, +}; + +// Asserted rather than annotated: the report grows members this file does not read. +const report = (viewAllFieldsReview: StoredMigrationReport['viewAllFieldsReview']): StoredMigrationReport => ({ + apply: false, + protocol: '19.0.0', + scanned: 1, + canonical: 1, + pending: 0, + rewritten: 0, + skipped: 0, + failed: 0, + rows: [], + decisionModeReview: [], + viewAllFieldsReview, +}) as StoredMigrationReport; + +describe('the stored View All Fields review list names the own field rows beside Modify All', () => { + it('carries `ownFieldRows` on the Modify All entry only, with the protocol-19 answer of each row', () => { + const entries = collectViewAllFieldsReview(SET); + expect(entries).toEqual([ + { + object: 'contact', + bits: ['viewAllRecords', 'modifyAllRecords'], + ownFieldRows: [ + expect.objectContaining({ field: 'contact.salary', protocol18: 'read-and-edit', protocol19: 'hidden' }), + expect.objectContaining({ field: 'contact.grade', protocol18: 'read-and-edit', protocol19: 'read-only' }), + ], + }, + // No own row narrows beside View All: the member is absent, not empty. + { object: 'account', bits: ['viewAllRecords'] }, + ]); + }); + + it('prints each narrowed row under its entry, and nothing extra under an entry without one', () => { + const scope = { id: 'r_1', name: 'hr_manager', organizationId: null, packageId: null, state: 'active' as const }; + const lines = formatStoredMigrationReport(report(collectViewAllFieldsReview(SET).map((e) => ({ ...scope, ...e })))); + const contact = lines.findIndex((l) => l.includes("objects entry 'contact'")); + expect(lines[contact + 1]).toContain("own field row 'contact.salary' beside Modify All: protocol 18 read and edit, protocol 19 hidden"); + expect(lines[contact + 2]).toContain("own field row 'contact.grade' beside Modify All: protocol 18 read and edit, protocol 19 read only"); + const account = lines.findIndex((l) => l.includes("objects entry 'account'")); + expect(lines[account + 1]).not.toContain('own field row'); + }); +}); diff --git a/packages/spec/src/migrations/own-field-rows-beside-modify-all.test.ts b/packages/spec/src/migrations/own-field-rows-beside-modify-all.test.ts new file mode 100644 index 00000000000..2cbf40c96b8 --- /dev/null +++ b/packages/spec/src/migrations/own-field-rows-beside-modify-all.test.ts @@ -0,0 +1,84 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `ownFieldRowsBesideModifyAll` — the own field rows beside Modify All that + * protocol 19 narrows although `viewAllFields: true` is written beside the bit. + * One predicate for `os migrate meta --from 18` and the `--stored` review list: + * each listed case, and each shape that answers on 19 as it did on 18, is + * pinned here. + */ + +import { describe, expect, it } from 'vitest'; +import { ownFieldRowsBesideModifyAll } from './own-field-rows-beside-modify-all.js'; + +const MODIFY_ALL = { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true }; + +describe('ownFieldRowsBesideModifyAll', () => { + it('names an own readable: false row beside Modify All: read and edit on 18, hidden on 19', () => { + const rows = ownFieldRowsBesideModifyAll({ + name: 'hr_manager', + objects: { contact: MODIFY_ALL }, + fields: { 'contact.salary': { readable: false } }, + }); + expect(rows).toEqual([ + expect.objectContaining({ object: 'contact', field: 'contact.salary', protocol18: 'read-and-edit', protocol19: 'hidden' }), + ]); + expect(rows[0]!.choice).toMatch(/otherwise accept the narrowing\.$/); + }); + + it('names a row with no editable: true as read-only, and an editable row with a `when` as a conditional edit', () => { + const rows = ownFieldRowsBesideModifyAll({ + name: 'hr_manager', + objects: { contact: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: { + 'contact.grade': { readable: true }, + 'contact.bonus': { readable: true, editable: false }, + 'contact.notes': { readable: true, editable: true, when: 'status == "open"' }, + // What 18 gave through this set: not listed. + 'contact.phone': { readable: true, editable: true }, + }, + }); + expect(rows.map((r) => [r.field, r.protocol19])).toEqual([ + ['contact.grade', 'read-only'], + ['contact.bonus', 'read-only'], + ['contact.notes', 'edit-only-where-when-matches'], + ]); + }); + + it('reads a row of an object the set does not name against its `*` entry', () => { + const rows = ownFieldRowsBesideModifyAll({ + name: 'ops_admin', + objects: { '*': MODIFY_ALL, account: { allowRead: true } }, + fields: { + 'contact.salary': { readable: false }, + // The explicit entry is the set's whole answer for `account`: no Modify All there. + 'account.revenue': { readable: false }, + }, + }); + expect(rows.map((r) => [r.object, r.field])).toEqual([['*', 'contact.salary']]); + }); + + it('lists nothing for View All alone: its own rows already bound on 18', () => { + expect(ownFieldRowsBesideModifyAll({ + name: 'auditor', + objects: { contact: { allowRead: true, viewAllRecords: true } }, + fields: { 'contact.salary': { readable: false }, 'contact.grade': { readable: true } }, + })).toEqual([]); + }); + + it('lists nothing for an entry whose author already wrote `viewAllFields`, either way: the conversion leaves it alone', () => { + for (const viewAllFields of [true, false]) { + expect(ownFieldRowsBesideModifyAll({ + name: 'hr_manager', + objects: { contact: { ...MODIFY_ALL, viewAllFields } }, + fields: { 'contact.salary': { readable: false } }, + })).toEqual([]); + } + }); + + it('answers an empty list for a body that is not a set, or a set with no field rows', () => { + expect(ownFieldRowsBesideModifyAll(null)).toEqual([]); + expect(ownFieldRowsBesideModifyAll([])).toEqual([]); + expect(ownFieldRowsBesideModifyAll({ name: 'x', objects: { contact: MODIFY_ALL } })).toEqual([]); + }); +}); From f3de9fc483591f9e9ac4e86d995e86b368dbef0a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 13:47:06 +0000 Subject: [PATCH 3/8] chore(spec): regenerate the migrations api-surface and export-origins; add the changeset Claude-Session: https://claude.ai/code/session_01QSeKYko9cFNzePK9vaCkYe Co-authored-by: Claude --- .../38924-own-field-rows-beside-modify-all.md | 28 +++++++++++++++++++ packages/spec/api-surface/migrations.json | 6 +++- packages/spec/export-origins/migrations.json | 6 +++- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .changeset/38924-own-field-rows-beside-modify-all.md diff --git a/.changeset/38924-own-field-rows-beside-modify-all.md b/.changeset/38924-own-field-rows-beside-modify-all.md new file mode 100644 index 00000000000..fd2717c93b9 --- /dev/null +++ b/.changeset/38924-own-field-rows-beside-modify-all.md @@ -0,0 +1,28 @@ +--- +'@objectstack/spec': patch +'@objectstack/cli': patch +'@objectstack/metadata-protocol': patch +--- + +fix(cli): `os migrate meta --from 18` names each own field row beside Modify All that protocol 19 narrows + +Clause-②: no +Metadata-protocol: none + +The upgrade text no longer says that the `viewAllFields: true` written beside View All or Modify All keeps every field read. It keeps the field reads the bits cast, except a field the set's own `readable: false` row hides beside Modify All, and it keeps no edit Modify All cast. The protocol-19 behaviour itself is unchanged. + +`os migrate meta --from 18` now lists each own field row beside Modify All whose answer changes on protocol 19: the permission set, the `objects` entry, the field row, what the set's holders got on 18 (read and edit), what they get on 19 (hidden, read only, or edit only on the rows the row's `when` matches), and the choice: change the row to keep the protocol-18 answer, or accept the narrowing. Example, for a set with View All and Modify All on `contact` and its own `'contact.salary': { readable: false }` row: + +```text + 1 own field row(s) beside Modify All that protocol 19 narrows — the `viewAllFields: true` written beside the bit does not keep them: + ⚠ permission set 'hr_manager' (permissions[0]), objects entry 'contact', field row 'contact.salary' + protocol 18: read and edit (Modify All voted over the set's own row) + protocol 19: hidden, no read and no edit (the set's own `readable: false` row binds) + choice: to keep the protocol-18 read and edit, change the row to `readable: true, editable: true` (...); otherwise accept the narrowing. +``` + +`--json` carries the same list under the new key `ownFieldRowNarrowing` (`set`, `at`, `object`, `field`, `protocol18`, `protocol19`, `choice`), present only when the list is not empty; no other key changes. + +`os migrate meta --stored` names the same rows of a stored permission set under its entry in the View All Fields review list, and its `--json` entries carry them as `ownFieldRows`, present only when there is one. View All alone is never listed: a set's own row already bound beside its own View All on 18. + +`@objectstack/spec/migrations` exports the predicate both commands read, `ownFieldRowsBesideModifyAll`. diff --git a/packages/spec/api-surface/migrations.json b/packages/spec/api-surface/migrations.json index f5f3ba59f1e..e5f28fbdc6e 100644 --- a/packages/spec/api-surface/migrations.json +++ b/packages/spec/api-surface/migrations.json @@ -11,6 +11,9 @@ "MigrationHopResult (interface)", "MigrationStep (interface)", "MigrationTodo (interface)", + "OwnFieldRowBesideModifyAll (interface)", + "OwnFieldRowProtocol18Outcome (type)", + "OwnFieldRowProtocol19Outcome (type)", "PreviousReleaseRegistries (interface)", "RETIRED_DEFS_BY_MAJOR (const)", "RETIRED_KEYS_BY_MAJOR (const)", @@ -37,6 +40,7 @@ "applyMetaMigrations (function)", "composeMigrationChain (function)", "composeReleaseChanges (function)", - "composeSpecChanges (function)" + "composeSpecChanges (function)", + "ownFieldRowsBesideModifyAll (function)" ] } diff --git a/packages/spec/export-origins/migrations.json b/packages/spec/export-origins/migrations.json index 77adacde943..eb015b5dd5c 100644 --- a/packages/spec/export-origins/migrations.json +++ b/packages/spec/export-origins/migrations.json @@ -11,6 +11,9 @@ "MigrationHopResult": "src/migrations/types.ts#MigrationHopResult (interface)", "MigrationStep": "src/migrations/types.ts#MigrationStep (interface)", "MigrationTodo": "src/migrations/types.ts#MigrationTodo (interface)", + "OwnFieldRowBesideModifyAll": "src/migrations/own-field-rows-beside-modify-all.ts#OwnFieldRowBesideModifyAll (interface)", + "OwnFieldRowProtocol18Outcome": "src/migrations/own-field-rows-beside-modify-all.ts#OwnFieldRowProtocol18Outcome (type)", + "OwnFieldRowProtocol19Outcome": "src/migrations/own-field-rows-beside-modify-all.ts#OwnFieldRowProtocol19Outcome (type)", "PreviousReleaseRegistries": "src/migrations/spec-changes.ts#PreviousReleaseRegistries (interface)", "RETIRED_DEFS_BY_MAJOR": "src/migrations/registry.ts#RETIRED_DEFS_BY_MAJOR (const)", "RETIRED_KEYS_BY_MAJOR": "src/migrations/registry.ts#RETIRED_KEYS_BY_MAJOR (const)", @@ -37,6 +40,7 @@ "applyMetaMigrations": "src/migrations/chain.ts#applyMetaMigrations (function)", "composeMigrationChain": "src/migrations/chain.ts#composeMigrationChain (function)", "composeReleaseChanges": "src/migrations/spec-changes.ts#composeReleaseChanges (function)", - "composeSpecChanges": "src/migrations/spec-changes.ts#composeSpecChanges (function)" + "composeSpecChanges": "src/migrations/spec-changes.ts#composeSpecChanges (function)", + "ownFieldRowsBesideModifyAll": "src/migrations/own-field-rows-beside-modify-all.ts#ownFieldRowsBesideModifyAll (function)" } } From 7f1d974e66e6487c267893cab7bb1abfde584bf5 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 14:00:46 +0000 Subject: [PATCH 4/8] refactor(spec): keep the own-row predicate beside the conversion layer on the root entry The stored-row reader is runtime code; the migrations entry pins the whole guidance registry into whatever imports it. Claude-Session: https://claude.ai/code/session_01QSeKYko9cFNzePK9vaCkYe Co-authored-by: Claude --- .changeset/38924-own-field-rows-beside-modify-all.md | 2 +- packages/cli/src/utils/own-field-row-narrowing.ts | 6 +++--- packages/metadata-protocol/src/stored-own-field-rows.ts | 2 +- packages/spec/api-surface/migrations.json | 6 +----- packages/spec/api-surface/root.json | 4 ++++ packages/spec/export-origins/migrations.json | 6 +----- packages/spec/export-origins/root.json | 4 ++++ packages/spec/src/conversions/index.ts | 6 ++++++ .../own-field-rows-beside-modify-all.test.ts | 0 .../own-field-rows-beside-modify-all.ts | 7 ++++++- packages/spec/src/migrations/index.ts | 6 ------ 11 files changed, 27 insertions(+), 22 deletions(-) rename packages/spec/src/{migrations => conversions}/own-field-rows-beside-modify-all.test.ts (100%) rename packages/spec/src/{migrations => conversions}/own-field-rows-beside-modify-all.ts (93%) diff --git a/.changeset/38924-own-field-rows-beside-modify-all.md b/.changeset/38924-own-field-rows-beside-modify-all.md index fd2717c93b9..b14dedcbd3c 100644 --- a/.changeset/38924-own-field-rows-beside-modify-all.md +++ b/.changeset/38924-own-field-rows-beside-modify-all.md @@ -25,4 +25,4 @@ The upgrade text no longer says that the `viewAllFields: true` written beside Vi `os migrate meta --stored` names the same rows of a stored permission set under its entry in the View All Fields review list, and its `--json` entries carry them as `ownFieldRows`, present only when there is one. View All alone is never listed: a set's own row already bound beside its own View All on 18. -`@objectstack/spec/migrations` exports the predicate both commands read, `ownFieldRowsBesideModifyAll`. +`@objectstack/spec` exports the predicate both commands read, `ownFieldRowsBesideModifyAll`, beside the conversion layer. diff --git a/packages/cli/src/utils/own-field-row-narrowing.ts b/packages/cli/src/utils/own-field-row-narrowing.ts index ca15ba96065..46bc4259ead 100644 --- a/packages/cli/src/utils/own-field-row-narrowing.ts +++ b/packages/cli/src/utils/own-field-row-narrowing.ts @@ -18,14 +18,14 @@ */ import chalk from 'chalk'; -import { ALL_CONVERSIONS } from '@objectstack/spec'; import { - applyMetaMigrations, + ALL_CONVERSIONS, ownFieldRowsBesideModifyAll, type OwnFieldRowBesideModifyAll, type OwnFieldRowProtocol18Outcome, type OwnFieldRowProtocol19Outcome, -} from '@objectstack/spec/migrations'; +} from '@objectstack/spec'; +import { applyMetaMigrations } from '@objectstack/spec/migrations'; /** The conversion whose rewritten entries the list is read beside. */ const CONVERSION_ID = 'permission-view-all-fields-beside-record-bypass'; diff --git a/packages/metadata-protocol/src/stored-own-field-rows.ts b/packages/metadata-protocol/src/stored-own-field-rows.ts index 8295eefe26b..d42a1ad47f2 100644 --- a/packages/metadata-protocol/src/stored-own-field-rows.ts +++ b/packages/metadata-protocol/src/stored-own-field-rows.ts @@ -17,7 +17,7 @@ * and renders them. */ -import { ownFieldRowsBesideModifyAll, type OwnFieldRowBesideModifyAll } from '@objectstack/spec/migrations'; +import { ownFieldRowsBesideModifyAll, type OwnFieldRowBesideModifyAll } from '@objectstack/spec'; /** One own field row beside a listed entry's Modify All that protocol 19 narrows. */ export type StoredOwnFieldRow = Omit; diff --git a/packages/spec/api-surface/migrations.json b/packages/spec/api-surface/migrations.json index e5f28fbdc6e..f5f3ba59f1e 100644 --- a/packages/spec/api-surface/migrations.json +++ b/packages/spec/api-surface/migrations.json @@ -11,9 +11,6 @@ "MigrationHopResult (interface)", "MigrationStep (interface)", "MigrationTodo (interface)", - "OwnFieldRowBesideModifyAll (interface)", - "OwnFieldRowProtocol18Outcome (type)", - "OwnFieldRowProtocol19Outcome (type)", "PreviousReleaseRegistries (interface)", "RETIRED_DEFS_BY_MAJOR (const)", "RETIRED_KEYS_BY_MAJOR (const)", @@ -40,7 +37,6 @@ "applyMetaMigrations (function)", "composeMigrationChain (function)", "composeReleaseChanges (function)", - "composeSpecChanges (function)", - "ownFieldRowsBesideModifyAll (function)" + "composeSpecChanges (function)" ] } diff --git a/packages/spec/api-surface/root.json b/packages/spec/api-surface/root.json index aaac8b3f738..52a7ea52732 100644 --- a/packages/spec/api-surface/root.json +++ b/packages/spec/api-surface/root.json @@ -113,6 +113,9 @@ "ObjectStackDefinitionParsed (type)", "ObjectStackDefinitionSchema (const)", "ObjectStackSchema (const)", + "OwnFieldRowBesideModifyAll (interface)", + "OwnFieldRowProtocol18Outcome (type)", + "OwnFieldRowProtocol19Outcome (type)", "P (const)", "PLATFORM_ALWAYS_ON_CAPABILITIES (const)", "PLATFORM_CAPABILITY_PROVIDERS (const)", @@ -201,6 +204,7 @@ "normalizePluginMetadata (function)", "normalizeStackInput (function)", "objectStackErrorMap (const)", + "ownFieldRowsBesideModifyAll (function)", "partitionAssembledViewArtifacts (function)", "safeParsePretty (function)", "stackConversionsOf (function)", diff --git a/packages/spec/export-origins/migrations.json b/packages/spec/export-origins/migrations.json index eb015b5dd5c..77adacde943 100644 --- a/packages/spec/export-origins/migrations.json +++ b/packages/spec/export-origins/migrations.json @@ -11,9 +11,6 @@ "MigrationHopResult": "src/migrations/types.ts#MigrationHopResult (interface)", "MigrationStep": "src/migrations/types.ts#MigrationStep (interface)", "MigrationTodo": "src/migrations/types.ts#MigrationTodo (interface)", - "OwnFieldRowBesideModifyAll": "src/migrations/own-field-rows-beside-modify-all.ts#OwnFieldRowBesideModifyAll (interface)", - "OwnFieldRowProtocol18Outcome": "src/migrations/own-field-rows-beside-modify-all.ts#OwnFieldRowProtocol18Outcome (type)", - "OwnFieldRowProtocol19Outcome": "src/migrations/own-field-rows-beside-modify-all.ts#OwnFieldRowProtocol19Outcome (type)", "PreviousReleaseRegistries": "src/migrations/spec-changes.ts#PreviousReleaseRegistries (interface)", "RETIRED_DEFS_BY_MAJOR": "src/migrations/registry.ts#RETIRED_DEFS_BY_MAJOR (const)", "RETIRED_KEYS_BY_MAJOR": "src/migrations/registry.ts#RETIRED_KEYS_BY_MAJOR (const)", @@ -40,7 +37,6 @@ "applyMetaMigrations": "src/migrations/chain.ts#applyMetaMigrations (function)", "composeMigrationChain": "src/migrations/chain.ts#composeMigrationChain (function)", "composeReleaseChanges": "src/migrations/spec-changes.ts#composeReleaseChanges (function)", - "composeSpecChanges": "src/migrations/spec-changes.ts#composeSpecChanges (function)", - "ownFieldRowsBesideModifyAll": "src/migrations/own-field-rows-beside-modify-all.ts#ownFieldRowsBesideModifyAll (function)" + "composeSpecChanges": "src/migrations/spec-changes.ts#composeSpecChanges (function)" } } diff --git a/packages/spec/export-origins/root.json b/packages/spec/export-origins/root.json index e853c4b68da..d0505bf4b67 100644 --- a/packages/spec/export-origins/root.json +++ b/packages/spec/export-origins/root.json @@ -112,6 +112,9 @@ "ObjectStackDefinitionParsed": "src/stack.zod.ts#ObjectStackDefinitionParsed (type)", "ObjectStackDefinitionSchema": "src/stack.zod.ts#ObjectStackDefinitionSchema (const)", "ObjectStackSchema": "src/stack.zod.ts#ObjectStackSchema (const)", + "OwnFieldRowBesideModifyAll": "src/conversions/own-field-rows-beside-modify-all.ts#OwnFieldRowBesideModifyAll (interface)", + "OwnFieldRowProtocol18Outcome": "src/conversions/own-field-rows-beside-modify-all.ts#OwnFieldRowProtocol18Outcome (type)", + "OwnFieldRowProtocol19Outcome": "src/conversions/own-field-rows-beside-modify-all.ts#OwnFieldRowProtocol19Outcome (type)", "P": "src/shared/expression.zod.ts#P (const)", "PLATFORM_ALWAYS_ON_CAPABILITIES": "src/kernel/platform-capabilities.ts#PLATFORM_ALWAYS_ON_CAPABILITIES (const)", "PLATFORM_CAPABILITY_PROVIDERS": "src/kernel/platform-capabilities.ts#PLATFORM_CAPABILITY_PROVIDERS (const)", @@ -200,6 +203,7 @@ "normalizePluginMetadata": "src/shared/metadata-collection.zod.ts#normalizePluginMetadata (function)", "normalizeStackInput": "src/shared/metadata-collection.zod.ts#normalizeStackInput (function)", "objectStackErrorMap": "src/shared/error-map.zod.ts#objectStackErrorMap (const)", + "ownFieldRowsBesideModifyAll": "src/conversions/own-field-rows-beside-modify-all.ts#ownFieldRowsBesideModifyAll (function)", "partitionAssembledViewArtifacts": "src/ui/assembled-views.zod.ts#partitionAssembledViewArtifacts (function)", "safeParsePretty": "src/shared/error-map.zod.ts#safeParsePretty (function)", "stackConversionsOf": "src/stack-provenance.ts#stackConversionsOf (function)", diff --git a/packages/spec/src/conversions/index.ts b/packages/spec/src/conversions/index.ts index 630ed35fa95..2babb86c0aa 100644 --- a/packages/spec/src/conversions/index.ts +++ b/packages/spec/src/conversions/index.ts @@ -31,3 +31,9 @@ export { applyConversionsToStoredItem, type StoredConversionOptions, } from './stored.js'; +export { + ownFieldRowsBesideModifyAll, + type OwnFieldRowBesideModifyAll, + type OwnFieldRowProtocol18Outcome, + type OwnFieldRowProtocol19Outcome, +} from './own-field-rows-beside-modify-all.js'; diff --git a/packages/spec/src/migrations/own-field-rows-beside-modify-all.test.ts b/packages/spec/src/conversions/own-field-rows-beside-modify-all.test.ts similarity index 100% rename from packages/spec/src/migrations/own-field-rows-beside-modify-all.test.ts rename to packages/spec/src/conversions/own-field-rows-beside-modify-all.test.ts diff --git a/packages/spec/src/migrations/own-field-rows-beside-modify-all.ts b/packages/spec/src/conversions/own-field-rows-beside-modify-all.ts similarity index 93% rename from packages/spec/src/migrations/own-field-rows-beside-modify-all.ts rename to packages/spec/src/conversions/own-field-rows-beside-modify-all.ts index 59bf09a5328..be476e40fab 100644 --- a/packages/spec/src/migrations/own-field-rows-beside-modify-all.ts +++ b/packages/spec/src/conversions/own-field-rows-beside-modify-all.ts @@ -43,9 +43,14 @@ * * The answer is per SET: another set the same holder carries can still grant * the field (union across sets is unchanged). + * + * It lives beside the conversion layer, on the package root, and not on the + * `@objectstack/spec/migrations` entry: the stored-row reader in + * `@objectstack/metadata-protocol` is runtime code, and that entry pins the + * whole `os migrate meta` guidance registry into whatever imports it. */ -import { permissionViewAllFieldsBesideRecordBypass } from '../conversions/entries/19/permission-view-all-fields-beside-record-bypass.js'; +import { permissionViewAllFieldsBesideRecordBypass } from './entries/19/permission-view-all-fields-beside-record-bypass.js'; /** What a holder of the set read and edited on the field through this set on protocol 18. */ export type OwnFieldRowProtocol18Outcome = 'read-and-edit'; diff --git a/packages/spec/src/migrations/index.ts b/packages/spec/src/migrations/index.ts index e6b3d20c15f..5f65f9305fb 100644 --- a/packages/spec/src/migrations/index.ts +++ b/packages/spec/src/migrations/index.ts @@ -35,12 +35,6 @@ export { composeMigrationChain, MigrationFloorError, } from './chain.js'; -export { - ownFieldRowsBesideModifyAll, - type OwnFieldRowBesideModifyAll, - type OwnFieldRowProtocol18Outcome, - type OwnFieldRowProtocol19Outcome, -} from './own-field-rows-beside-modify-all.js'; export { composeReleaseChanges, composeSpecChanges, From 169709458916713f82bf91cf731082116491a971 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 14:34:50 +0000 Subject: [PATCH 5/8] test(cli): pay the command's dynamic imports at module top in the own-row pin Claude-Session: https://claude.ai/code/session_01QSeKYko9cFNzePK9vaCkYe Co-authored-by: Claude --- .../test/migrate-meta-own-field-row-38924.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/cli/test/migrate-meta-own-field-row-38924.test.ts b/packages/cli/test/migrate-meta-own-field-row-38924.test.ts index a143ab0b7eb..d2cb795e4fe 100644 --- a/packages/cli/test/migrate-meta-own-field-row-38924.test.ts +++ b/packages/cli/test/migrate-meta-own-field-row-38924.test.ts @@ -35,6 +35,21 @@ import { join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { stripVTControlCharacters } from 'node:util'; import { ALL_CONVERSIONS } from '@objectstack/spec'; +// The packages the command reaches through dynamic imports, loaded at module top so the +// first load is paid during collection, never inside a clocked case (`check:test-source-alias`). +import '@objectstack/cloud-connection'; +import '@objectstack/driver-sql'; +import '@objectstack/driver-turso'; +import '@objectstack/metadata'; +import '@objectstack/metadata-protocol'; +import '@objectstack/platform-objects/plugin'; +import '@objectstack/plugin-hono-server'; +import '@objectstack/plugin-security'; +import '@objectstack/rest'; +import '@objectstack/service-automation'; +import '@objectstack/service-datasource'; +import '@objectstack/service-settings'; +import '@objectstack/service-storage'; import MigrateMeta from '../src/commands/migrate/meta.js'; const CLI_ROOT = resolve(fileURLToPath(import.meta.url), '..', '..'); From 126d7649cfbc70e046b4410d7084ccdd6dedca0e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 14:45:15 +0000 Subject: [PATCH 6/8] test(metadata-protocol): build the review report in its full shape now that it counts rows served invalid Claude-Session: https://claude.ai/code/session_01QSeKYko9cFNzePK9vaCkYe Co-authored-by: Claude --- packages/metadata-protocol/src/stored-own-field-rows.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/metadata-protocol/src/stored-own-field-rows.test.ts b/packages/metadata-protocol/src/stored-own-field-rows.test.ts index 524f91cfe22..ecd1c544529 100644 --- a/packages/metadata-protocol/src/stored-own-field-rows.test.ts +++ b/packages/metadata-protocol/src/stored-own-field-rows.test.ts @@ -26,7 +26,6 @@ const SET = { }, }; -// Asserted rather than annotated: the report grows members this file does not read. const report = (viewAllFieldsReview: StoredMigrationReport['viewAllFieldsReview']): StoredMigrationReport => ({ apply: false, protocol: '19.0.0', @@ -36,10 +35,11 @@ const report = (viewAllFieldsReview: StoredMigrationReport['viewAllFieldsReview' rewritten: 0, skipped: 0, failed: 0, + servedInvalid: 0, rows: [], decisionModeReview: [], viewAllFieldsReview, -}) as StoredMigrationReport; +}); describe('the stored View All Fields review list names the own field rows beside Modify All', () => { it('carries `ownFieldRows` on the Modify All entry only, with the protocol-19 answer of each row', () => { From 60ea167cb7c80872dae9202266f070eb4d8ee54c Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 16:05:59 +0000 Subject: [PATCH 7/8] fix: keep the house migrate sentence and classify the new normalized call site The semantic entry's naming sentence no longer spells the bare --from command (the house-sentence pin judges every such literal), and the own-row walker's call site is classified as reading package bodies, measured on an assembled stack in the per-card test. Claude-Session: https://claude.ai/code/session_01QSeKYko9cFNzePK9vaCkYe Co-authored-by: Claude --- .../test/migrate-meta-own-field-row-38924.test.ts | 15 +++++++++++++++ packages/cli/test/normalized-call-sites.test.ts | 4 ++++ ...sion-view-all-modify-all-cast-no-field-vote.ts | 8 ++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/cli/test/migrate-meta-own-field-row-38924.test.ts b/packages/cli/test/migrate-meta-own-field-row-38924.test.ts index d2cb795e4fe..e285b3c4326 100644 --- a/packages/cli/test/migrate-meta-own-field-row-38924.test.ts +++ b/packages/cli/test/migrate-meta-own-field-row-38924.test.ts @@ -51,6 +51,7 @@ import '@objectstack/service-datasource'; import '@objectstack/service-settings'; import '@objectstack/service-storage'; import MigrateMeta from '../src/commands/migrate/meta.js'; +import { ownFieldRowNarrowingSites } from '../src/utils/own-field-row-narrowing.js'; const CLI_ROOT = resolve(fileURLToPath(import.meta.url), '..', '..'); @@ -150,6 +151,20 @@ describe('os migrate meta --from 18 — the own field rows beside Modify All pro expect(text).not.toContain('own field row(s) beside Modify All'); }, 60_000); + it('reads each package body of an assembled stack under its own prefix, as the chain reports its edits', () => { + const set = { + name: 'hr_manager', + objects: { contact: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: { 'contact.salary': { readable: false } }, + }; + const sites = ownFieldRowNarrowingSites({ packages: [{ manifest: { permissions: [set] } }] }, MAJOR - 1, MAJOR); + expect(sites.map((s) => [s.at, s.set, s.field, s.protocol19])).toEqual([ + ['packages[0].manifest.permissions[0]', 'hr_manager', 'contact.salary', 'hidden'], + ]); + // A run that does not cross into the conversion's major names nothing. + expect(ownFieldRowNarrowingSites({ permissions: [set] }, MAJOR, MAJOR)).toEqual([]); + }); + it('--json carries the list under `ownFieldRowNarrowing` only when non-empty; every other key is unchanged', async () => { const withRows = JSON.parse(await runMeta('fixture', ['--json'])); const without = JSON.parse(await runMeta('control', ['--json'])); diff --git a/packages/cli/test/normalized-call-sites.test.ts b/packages/cli/test/normalized-call-sites.test.ts index 5b96a0ef216..ec3bd109b17 100644 --- a/packages/cli/test/normalized-call-sites.test.ts +++ b/packages/cli/test/normalized-call-sites.test.ts @@ -148,6 +148,10 @@ const SITES: Readonly> = { reads: 'packages', why: 'the protocol-19 form move\'s per-site lines (#37112): asks the move and its translation companion over the stack entering the 19 hop and over each `packages[i].manifest` body, each under its own prefix, as `applyMetaMigrationsToPackages` reports edits. Measured on an assembled stack in `meta.form-move-sites.test.ts` (a body\'s site reads `packages[0].manifest.views[0].formViews.other`).', }, + 'migrate/meta.ts :: ownFieldRowNarrowingSites(normalized': { + reads: 'packages', + why: 'the own field rows beside Modify All that protocol 19 narrows (#38924): read over the stack entering the 19 hop and over each `packages[i].manifest` body, each under its own prefix, as `formMoveSites` reads them. Measured on an assembled stack in `migrate-meta-own-field-row-38924.test.ts` (a body\'s site reads `packages[0].manifest.permissions[0]`).', + }, 'migrate/meta.ts :: planProtocolRange(normalized': { reads: 'top-level', why: 'reads the handshake range off `manifest`, where the load seam reads it (`AppPlugin`: `bundle.manifest || bundle`); a `preserve` artifact keeps `manifest` at the top level.', diff --git a/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts b/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts index 8e13901bea2..3370e627530 100644 --- a/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts +++ b/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts @@ -54,10 +54,10 @@ export const entry: SemanticMigration = { + 'SOURCE permission sets: `os migrate meta --from 18 --write` adds `viewAllFields: true` beside every ' + 'such bit (the D2 conversion `permission-view-all-fields-beside-record-bypass`), which keeps the field ' + 'reads the bits cast, except a field the set\'s own `readable: false` row hides beside its Modify All: that ' - + 'row now binds. It keeps no edit Modify All cast. `os migrate meta --from 18` names each own field row ' - + 'beside Modify All that now hides its field, makes it read-only or limits its edit to the rows its `when` ' - + 'matches, with its protocol-18 and protocol-19 answer and the choice: change the row to keep the ' - + 'protocol-18 answer, or accept the narrowing. The conversion replays only there: it is a default flip, ' + + 'row now binds. It keeps no edit Modify All cast. The same command, with or without `--write`, names each ' + + 'own field row beside Modify All that now hides its field, makes it read-only or limits its edit to the ' + + 'rows its `when` matches, with its protocol-18 and protocol-19 answer and the choice: change the row to ' + + 'keep the protocol-18 answer, or accept the narrowing. The conversion replays only there: it is a default flip, ' + 'retired from the load path, so the authoring funnel skips it, and the artifact-ingestion door and every ' + 'stored-row read (`applyConversionsToStoredItem`) refuse it by id.\n\n' + 'STORED permission sets (Studio-saved, in `sys_metadata`): they are NOT rewritten on upgrade and are ' From e659f7cf0dfd8967b4d5a24996e940a8f19d57bc Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 19:53:49 +0000 Subject: [PATCH 8/8] fix(spec,cli,metadata-protocol): a row-conditioned lock is its own outcome, and the step-19 text names only the rows it lists A row with a when and no editable: true locks only the rows the condition matches, so it is read-only-where-when-matches; every choice now leads to the one row shape the list never names. The step-19 sentence says the list covers the entries the run writes viewAllFields beside. Wildcard field keys are not listed, the stored line's choice no longer names viewAllFields, the element type of ownFieldRows is exported, and the changeset declares the widening. Claude-Session: https://claude.ai/code/session_01QSeKYko9cFNzePK9vaCkYe Co-authored-by: Claude --- .../38924-own-field-rows-beside-modify-all.md | 14 +++--- .../cli/src/utils/own-field-row-narrowing.ts | 7 ++- packages/metadata-protocol/src/index.ts | 1 + .../src/stored-own-field-rows.ts | 3 +- ...on-view-all-fields-beside-record-bypass.ts | 3 +- .../own-field-rows-beside-modify-all.test.ts | 42 ++++++++++++++++++ .../own-field-rows-beside-modify-all.ts | 43 +++++++++++++++---- ...-view-all-modify-all-cast-no-field-vote.ts | 10 +++-- 8 files changed, 101 insertions(+), 22 deletions(-) diff --git a/.changeset/38924-own-field-rows-beside-modify-all.md b/.changeset/38924-own-field-rows-beside-modify-all.md index b14dedcbd3c..3911eaabeca 100644 --- a/.changeset/38924-own-field-rows-beside-modify-all.md +++ b/.changeset/38924-own-field-rows-beside-modify-all.md @@ -6,23 +6,23 @@ fix(cli): `os migrate meta --from 18` names each own field row beside Modify All that protocol 19 narrows -Clause-②: no +Clause-②: yes (widening) Metadata-protocol: none +Widened: `@objectstack/spec` exports `ownFieldRowsBesideModifyAll` and the types `OwnFieldRowBesideModifyAll`, `OwnFieldRowProtocol18Outcome` and `OwnFieldRowProtocol19Outcome`; `os migrate meta --from N --json` gains the key `ownFieldRowNarrowing`, present only when the list is not empty; `StoredViewAllFieldsReview` (`os migrate meta --stored --json`) gains the optional member `ownFieldRows`, and `@objectstack/metadata-protocol` exports its element type `StoredOwnFieldRow`. Nothing a metadata author writes changes. + The upgrade text no longer says that the `viewAllFields: true` written beside View All or Modify All keeps every field read. It keeps the field reads the bits cast, except a field the set's own `readable: false` row hides beside Modify All, and it keeps no edit Modify All cast. The protocol-19 behaviour itself is unchanged. -`os migrate meta --from 18` now lists each own field row beside Modify All whose answer changes on protocol 19: the permission set, the `objects` entry, the field row, what the set's holders got on 18 (read and edit), what they get on 19 (hidden, read only, or edit only on the rows the row's `when` matches), and the choice: change the row to keep the protocol-18 answer, or accept the narrowing. Example, for a set with View All and Modify All on `contact` and its own `'contact.salary': { readable: false }` row: +`os migrate meta --from 18` now lists each own field row beside a Modify All bit that the run writes `viewAllFields: true` beside, where the row's answer changes on protocol 19. Each line names the permission set, the `objects` entry and the field row; what the set's holders got on protocol 18 (read and edit: Modify All voted over the set's own rows); what they get on 19 through that set (`hidden`, `read-only`, `read-only-where-when-matches` for a row-conditioned lock, or `edit-only-where-when-matches` for a row-conditioned edit); and the choice: change the row to keep the protocol-18 answer, or accept the narrowing. Following the choice takes the row off the list. A set that already carries `viewAllFields` beside the bit (a source the edit was applied to) is not listed; review its own rows beside Modify All by hand. Example, for a set with View All and Modify All on `contact` and its own `'contact.salary': { readable: false }` row: ```text 1 own field row(s) beside Modify All that protocol 19 narrows — the `viewAllFields: true` written beside the bit does not keep them: ⚠ permission set 'hr_manager' (permissions[0]), objects entry 'contact', field row 'contact.salary' protocol 18: read and edit (Modify All voted over the set's own row) protocol 19: hidden, no read and no edit (the set's own `readable: false` row binds) - choice: to keep the protocol-18 read and edit, change the row to `readable: true, editable: true` (...); otherwise accept the narrowing. + choice: to keep the protocol-18 read and edit, change the row to `readable: true, editable: true`; otherwise accept the narrowing. ``` -`--json` carries the same list under the new key `ownFieldRowNarrowing` (`set`, `at`, `object`, `field`, `protocol18`, `protocol19`, `choice`), present only when the list is not empty; no other key changes. - -`os migrate meta --stored` names the same rows of a stored permission set under its entry in the View All Fields review list, and its `--json` entries carry them as `ownFieldRows`, present only when there is one. View All alone is never listed: a set's own row already bound beside its own View All on 18. +`--json` carries the same list under `ownFieldRowNarrowing` (`set`, `at`, `object`, `field`, `protocol18`, `protocol19`, `choice`); no other key changes. -`@objectstack/spec` exports the predicate both commands read, `ownFieldRowsBesideModifyAll`, beside the conversion layer. +`os migrate meta --stored` names the same rows of a stored permission set under its entry in the View All Fields review list, and its `--json` entries carry them as `ownFieldRows`. View All alone is never listed: on 18.6.0 a set's own row already bound beside its own View All. Protocol 18 here means 18.6.0, the release the card measured. diff --git a/packages/cli/src/utils/own-field-row-narrowing.ts b/packages/cli/src/utils/own-field-row-narrowing.ts index 46bc4259ead..a3379afd4c4 100644 --- a/packages/cli/src/utils/own-field-row-narrowing.ts +++ b/packages/cli/src/utils/own-field-row-narrowing.ts @@ -88,7 +88,12 @@ const PROTOCOL_18: Record = { const PROTOCOL_19: Record = { hidden: 'hidden, no read and no edit (the set\'s own `readable: false` row binds)', 'read-only': 'read only (the set\'s own row binds, and it grants no edit)', - 'edit-only-where-when-matches': 'read, and edit only on the rows the row\'s `when` matches', + 'read-only-where-when-matches': + 'read, and locked on the rows the row\'s `when` matches (elsewhere the row votes nothing and the field ' + + 'follows the other sets and the object grant)', + 'edit-only-where-when-matches': + 'read, and this set votes the edit only on the rows the row\'s `when` matches (elsewhere the field follows ' + + 'the other sets and the object grant, and another set\'s lock is no longer out-voted)', }; /** diff --git a/packages/metadata-protocol/src/index.ts b/packages/metadata-protocol/src/index.ts index 15f630d3a35..fd43dd623aa 100644 --- a/packages/metadata-protocol/src/index.ts +++ b/packages/metadata-protocol/src/index.ts @@ -263,6 +263,7 @@ export type { StoredMigrationTodo, StoredViewAllFieldsReview, } from './stored-migration.js'; +export type { StoredOwnFieldRow } from './stored-own-field-rows.js'; export { computeMetadataDiagnostics, diff --git a/packages/metadata-protocol/src/stored-own-field-rows.ts b/packages/metadata-protocol/src/stored-own-field-rows.ts index d42a1ad47f2..a220584c5ae 100644 --- a/packages/metadata-protocol/src/stored-own-field-rows.ts +++ b/packages/metadata-protocol/src/stored-own-field-rows.ts @@ -37,7 +37,8 @@ export function storedOwnFieldRows(body: unknown, object: string): { ownFieldRow const PROTOCOL_19: Record = { hidden: 'hidden, no read and no edit', 'read-only': 'read only', - 'edit-only-where-when-matches': 'read, and edit only on the rows its `when` matches', + 'read-only-where-when-matches': 'read, and locked on the rows its `when` matches', + 'edit-only-where-when-matches': 'read, and this set votes the edit only on the rows its `when` matches', }; /** The lines naming one review entry's narrowed own field rows, nested under the entry's line. */ diff --git a/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts b/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts index bfeede946d4..09d3d3c8d47 100644 --- a/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts +++ b/packages/spec/src/conversions/entries/19/permission-view-all-fields-beside-record-bypass.ts @@ -28,7 +28,8 @@ import { isDict } from '../shared.js'; * Every `objects` entry of every permission set, the `'*'` entry included, * that carries `viewAllRecords: true` or `modifyAllRecords: true` and has no * `viewAllFields` key gets `viewAllFields: true`, so a source written while the - * bits read every field keeps every read they cast. An entry whose author + * bits read every field keeps the reads they cast, except the two losses + * listed below. An entry whose author * already wrote `viewAllFields` — either value — has spoken and is left alone, * which is also what makes a second replay a no-op. * diff --git a/packages/spec/src/conversions/own-field-rows-beside-modify-all.test.ts b/packages/spec/src/conversions/own-field-rows-beside-modify-all.test.ts index 2cbf40c96b8..49fa4f1b8ca 100644 --- a/packages/spec/src/conversions/own-field-rows-beside-modify-all.test.ts +++ b/packages/spec/src/conversions/own-field-rows-beside-modify-all.test.ts @@ -45,6 +45,48 @@ describe('ownFieldRowsBesideModifyAll', () => { ]); }); + it('names a row-conditioned lock (a `when`, no editable: true) as a lock on the matching rows only, not read-only', () => { + const rows = ownFieldRowsBesideModifyAll({ + name: 'deal_desk', + objects: { deal: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: { 'deal.amount': { readable: true, when: 'stage in ["approved"]' } }, + }); + expect(rows.map((r) => [r.field, r.protocol19])).toEqual([['deal.amount', 'read-only-where-when-matches']]); + }); + + it('each choice leads to a row the list no longer names, so the next run is quiet', () => { + // The row each choice spells, by outcome: the one shape 19 answers as 18 did. + const followed: Record> = { + hidden: { readable: true, editable: true }, + 'read-only': { readable: true, editable: true }, + 'read-only-where-when-matches': { readable: true, editable: true }, + 'edit-only-where-when-matches': { readable: true, editable: true }, + }; + const before = { + 'contact.a': { readable: false }, + 'contact.b': { readable: true }, + 'contact.c': { readable: true, when: 'status == "open"' }, + 'contact.d': { readable: true, editable: true, when: 'status == "open"' }, + }; + const listed = ownFieldRowsBesideModifyAll({ name: 'x', objects: { contact: MODIFY_ALL }, fields: before }); + expect(listed.map((r) => r.protocol19)).toEqual([ + 'hidden', 'read-only', 'read-only-where-when-matches', 'edit-only-where-when-matches', + ]); + for (const row of listed) { + expect(row.choice).toMatch(/`readable: true, editable: true`|add `editable: true`|remove the row's `when`/); + } + const after = Object.fromEntries(listed.map((r) => [r.field, followed[r.protocol19]])); + expect(ownFieldRowsBesideModifyAll({ name: 'x', objects: { contact: MODIFY_ALL }, fields: after })).toEqual([]); + }); + + it('never lists a `*.FIELD` row: no merge reads a wildcard field key', () => { + expect(ownFieldRowsBesideModifyAll({ + name: 'ops_admin', + objects: { '*': MODIFY_ALL }, + fields: { '*.salary': { readable: false } }, + })).toEqual([]); + }); + it('reads a row of an object the set does not name against its `*` entry', () => { const rows = ownFieldRowsBesideModifyAll({ name: 'ops_admin', diff --git a/packages/spec/src/conversions/own-field-rows-beside-modify-all.ts b/packages/spec/src/conversions/own-field-rows-beside-modify-all.ts index be476e40fab..4400123e4ea 100644 --- a/packages/spec/src/conversions/own-field-rows-beside-modify-all.ts +++ b/packages/spec/src/conversions/own-field-rows-beside-modify-all.ts @@ -19,12 +19,27 @@ * field, and its holders get, through this set: * * - `readable: false`: no read and no edit (`hidden`); - * - `readable` true, no `editable: true` (an omitted `editable` is `false`): - * the read only (`read-only`); - * - `editable: true` beside a `when`: the edit on the rows the condition - * matches only (`edit-only-where-when-matches`); + * - `readable` true, no `editable: true` (an omitted `editable` is `false`) + * and no `when`: the read only, on every row (`read-only`); + * - `readable` true, no `editable: true`, beside a `when`: a lock on the + * rows the condition matches only (`read-only-where-when-matches`). The + * read vote is row-blind, but the entry votes nothing on a row its `when` + * does not match (`fieldPermissionVote` answers `null`), so there the field + * answers as it did on 18 when no other set names it; + * - `editable: true` beside a `when`: this set's edit vote on the rows the + * condition matches only (`edit-only-where-when-matches`). On the other rows + * the entry is absent and the field follows the other sets and the object + * grant; what changes is the row-blind reading of the set's lock and the + * answer beside another set's lock, which Modify All out-voted on 18; * - `editable: true` and no `when`: what protocol 18 gave — not listed. * + * Each `choice` names the row that answers as protocol 18 did, which this + * list never names, so following the choice takes the row off the list. + * + * A row keyed `'*.FIELD'` is never listed: no merge reads a wildcard field + * key (field rows have no wildcard, ruling of record 6912661484), so it is + * inert on both sides of the split. + * * View All (`viewAllRecords`) alone is not this shape: up to 18 the set's own * row already beat its own View All (ADR-0066 D2 ⑧, note of 2026-11-15), and * View All never voted an edit, so its own rows give the same answer on both @@ -56,7 +71,11 @@ import { permissionViewAllFieldsBesideRecordBypass } from './entries/19/permissi export type OwnFieldRowProtocol18Outcome = 'read-and-edit'; /** What a holder of the set reads and edits on the field through this set on protocol 19. */ -export type OwnFieldRowProtocol19Outcome = 'hidden' | 'read-only' | 'edit-only-where-when-matches'; +export type OwnFieldRowProtocol19Outcome = + | 'hidden' + | 'read-only' + | 'read-only-where-when-matches' + | 'edit-only-where-when-matches'; /** One own field row beside Modify All whose answer protocol 19 narrows. */ export interface OwnFieldRowBesideModifyAll { @@ -70,13 +89,17 @@ export interface OwnFieldRowBesideModifyAll { choice: string; } +// Every choice leads to `readable: true, editable: true` with no `when`, the +// one row shape this list never names, so a run after following it is quiet. const CHOICE: Record = { hidden: - 'to keep the protocol-18 read and edit, change the row to `readable: true, editable: true` (deleting it ' - + 'restores the read through `viewAllFields`, and the edit only where no set names the field); ' + 'to keep the protocol-18 read and edit, change the row to `readable: true, editable: true`; ' + 'otherwise accept the narrowing.', 'read-only': 'to keep the protocol-18 edit, add `editable: true` to the row; otherwise accept the narrowing.', + 'read-only-where-when-matches': + 'to keep the protocol-18 edit on every row, change the row to `readable: true, editable: true` with no ' + + '`when`; otherwise accept the narrowing.', 'edit-only-where-when-matches': 'to keep the protocol-18 edit on every row, remove the row\'s `when`; otherwise accept the narrowing.', }; @@ -88,8 +111,9 @@ function isDict(value: unknown): value is Record { /** The narrowed outcome of one own row beside Modify All, or `undefined` when 19 answers as 18 did. */ function narrowedOutcome(row: Record): OwnFieldRowProtocol19Outcome | undefined { if (row.readable === false) return 'hidden'; - if (row.editable !== true) return 'read-only'; - if (typeof row.when === 'string' && row.when.trim() !== '') return 'edit-only-where-when-matches'; + const conditioned = typeof row.when === 'string' && row.when.trim() !== ''; + if (row.editable !== true) return conditioned ? 'read-only-where-when-matches' : 'read-only'; + if (conditioned) return 'edit-only-where-when-matches'; return undefined; } @@ -125,6 +149,7 @@ export function ownFieldRowsBesideModifyAll(set: unknown): OwnFieldRowBesideModi const dot = field.indexOf('.'); if (dot <= 0 || !isDict(row)) continue; const objectName = field.slice(0, dot); + if (objectName === '*') continue; // no merge reads a wildcard field key const covering = objects[objectName] ? objectName : '*'; const entry = objects[covering]; if (!rewritten.has(covering) || !isDict(entry) || entry.modifyAllRecords !== true) continue; diff --git a/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts b/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts index 3370e627530..3f839a01ca5 100644 --- a/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts +++ b/packages/spec/src/migrations/entries/semantic/19.permission-view-all-modify-all-cast-no-field-vote.ts @@ -55,9 +55,12 @@ export const entry: SemanticMigration = { + 'such bit (the D2 conversion `permission-view-all-fields-beside-record-bypass`), which keeps the field ' + 'reads the bits cast, except a field the set\'s own `readable: false` row hides beside its Modify All: that ' + 'row now binds. It keeps no edit Modify All cast. The same command, with or without `--write`, names each ' - + 'own field row beside Modify All that now hides its field, makes it read-only or limits its edit to the ' + + 'own field row beside a Modify All bit it writes `viewAllFields: true` beside in that run, where the row ' + + 'now hides its field, locks it (on every row or on the rows its `when` matches) or limits its edit to the ' + 'rows its `when` matches, with its protocol-18 and protocol-19 answer and the choice: change the row to ' - + 'keep the protocol-18 answer, or accept the narrowing. The conversion replays only there: it is a default flip, ' + + 'keep the protocol-18 answer, or accept the narrowing. It names no row beside an entry that already ' + + 'carries `viewAllFields` (a source the edit was applied to, by `--write` or by hand): review those rows ' + + 'against the criteria below. The conversion replays only there: it is a default flip, ' + 'retired from the load path, so the authoring funnel skips it, and the artifact-ingestion door and every ' + 'stored-row read (`applyConversionsToStoredItem`) refuse it by id.\n\n' + 'STORED permission sets (Studio-saved, in `sys_metadata`): they are NOT rewritten on upgrade and are ' @@ -88,6 +91,7 @@ export const entry: SemanticMigration = { + '`security-cross-set-field-reopen` on a field one set hides that another set\'s `viewAllFields` ' + 're-opens, so a bit added where the hide was meant is visible there.', // The edits this entry judges: every `viewAllFields: true` that conversion - // writes keeps a read; the criteria above say when to delete it instead. + // writes keeps the reads the bit cast but a field the set's own row hides + // beside Modify All; the criteria above say when to delete it instead. conversionIds: ['permission-view-all-fields-beside-record-bypass'], };