From 5dc538ca1f70d1e67c8b7d1b64d8244dcdafdd1d Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 23:19:23 +0000 Subject: [PATCH 1/5] test(spec): pin the declared-selection case of the bulk-actions conversion Claude-Session: https://claude.ai/code/session_016WV4cxRh6Sbfo2Xm49JPx6 Co-authored-by: Claude --- ...-actions-to-action-selection-39395.test.ts | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts diff --git a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts new file mode 100644 index 00000000000..a452745e8b7 --- /dev/null +++ b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts @@ -0,0 +1,106 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `view-bulk-actions-to-action-selection` (protocol 19) — the object that + * ALREADY declares `actionLayout.selection`. + * + * The source half (`os migrate meta --from 18 --write`) writes the arm + * `{ pinned: , more?: }` from the list's order. The + * stored half (`os migrate meta --stored --apply`) then replays this same + * entry over a Studio-saved view row with the deployment's declared objects + * and actions beside it (`judgeStoredViewBulkActions` builds exactly the + * `{ views: [row], objects, actions }` stack used here). The row is rewritten + * when the declared arm is the one the entry would write — key for key, in + * order — and left as stored, with its TODO, when it is any other arm: a + * declared arrangement is never overwritten and never read as agreeing with a + * list it does not spell. + */ + +import { describe, expect, it } from 'vitest'; + +import { ALL_CONVERSIONS } from '../../registry.js'; +import type { ConversionApplication, ConversionTodoDetail } from '../../types.js'; + +const ID = 'view-bulk-actions-to-action-selection'; +const entry = () => ALL_CONVERSIONS.find((c) => c.id === ID)!; + +/** Four actions of `crm_lead`, declared in alphabetical order, all already placed at `selection`. */ +const ACTIONS = ['alpha_act', 'beta_act', 'gamma_act', 'delta_act'].map((name) => ({ + name, + label: name, + objectName: 'crm_lead', + type: 'script', + locations: ['record', 'selection'], +})); + +/** A Studio-saved list view row naming `names`, as the stored pass reads it. */ +const row = (names: string[]) => ({ + name: 'lead_grid', + object: 'crm_lead', + list: { type: 'grid', data: { provider: 'object', object: 'crm_lead' }, columns: ['name'], bulkActions: names }, +}); + +/** The stack the stored pass replays the entry over: the row alone, beside the deployment's declarations. */ +const storedStack = (names: string[], selection: unknown) => ({ + views: [row(names)], + objects: [{ name: 'crm_lead', actionLayout: { selection } }], + actions: structuredClone(ACTIONS), +}); + +function run(stack: Record) { + const applied: ConversionApplication[] = []; + const todos: ConversionTodoDetail[] = []; + const out = entry().apply(structuredClone(stack), (d) => applied.push(d), { + atRest: true, + reportTodo: (t) => todos.push(t), + }) as { views: Array<{ list: Record }>; objects: Array> }; + return { out, applied, todos }; +} + +describe(`${ID} — a declared actionLayout.selection`, () => { + // Not the default order (alpha, beta, …), so keeping it needs the arm. + const TWO = ['beta_act', 'alpha_act']; + const FOUR = ['delta_act', 'beta_act', 'alpha_act', 'gamma_act']; + + it('rewrites the row when the declared arm is the one the source half writes (pinned only)', () => { + const { out, applied, todos } = run(storedStack(TWO, { pinned: ['beta_act', 'alpha_act'] })); + expect(todos).toEqual([]); + expect(out.views[0]!.list).not.toHaveProperty('bulkActions'); + // The row is the whole write: no action and no object is touched. + expect(applied.filter((d) => !d.path.startsWith('views[0]'))).toEqual([]); + expect(out.objects[0]!.actionLayout).toEqual({ selection: { pinned: ['beta_act', 'alpha_act'] } }); + }); + + it('rewrites the row when the declared arm is the one the source half writes (pinned and more)', () => { + const arm = { pinned: ['delta_act', 'beta_act', 'alpha_act'], more: ['gamma_act'] }; + const { out, applied, todos } = run(storedStack(FOUR, arm)); + expect(todos).toEqual([]); + expect(out.views[0]!.list).not.toHaveProperty('bulkActions'); + expect(applied.filter((d) => !d.path.startsWith('views[0]'))).toEqual([]); + }); + + it.each([ + ['another order', TWO, { pinned: ['alpha_act', 'beta_act'] }], + ['the same order split differently', TWO, { pinned: ['beta_act'], more: ['alpha_act'] }], + ['an empty more beside the pinned the entry writes', TWO, { pinned: ['beta_act', 'alpha_act'], more: [] }], + ['a subset of the names', FOUR, { pinned: ['delta_act', 'beta_act', 'alpha_act'] }], + ['a superset of the names', TWO, { pinned: ['beta_act', 'alpha_act', 'gamma_act'] }], + ])('leaves the row as stored, with its TODO, when the declared arm is %s', (_label, names, arm) => { + const { out, applied, todos } = run(storedStack(names, arm)); + expect(applied).toEqual([]); + expect(todos.map((t) => t.path)).toEqual(['views[0].list.bulkActions']); + expect(todos[0]!.reason).toContain('actionLayout.selection'); + expect(out.views[0]!.list.bulkActions).toEqual(names); + expect(out.objects[0]!.actionLayout).toEqual({ selection: arm }); + }); + + it('still writes the arm where the object declares none, and still leaves an undeclared object as stored', () => { + const fresh = run({ ...storedStack(TWO, undefined), objects: [{ name: 'crm_lead' }] }); + expect(fresh.todos).toEqual([]); + expect(fresh.out.objects[0]!.actionLayout).toEqual({ selection: { pinned: ['beta_act', 'alpha_act'] } }); + + const orphan = run({ ...storedStack(TWO, undefined), objects: [] }); + expect(orphan.applied).toEqual([]); + expect(orphan.todos.map((t) => t.path)).toEqual(['views[0].list.bulkActions']); + }); +}); From ed800997085330959e79f8a541134158af2ec2f8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 23:20:27 +0000 Subject: [PATCH 2/5] fix(spec): rewrite a bulk-actions list when the object already declares the same selection arm Claude-Session: https://claude.ai/code/session_016WV4cxRh6Sbfo2Xm49JPx6 Co-authored-by: Claude --- .../view-bulk-actions-to-action-selection.ts | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts index 5b65c27043d..40c96d5cc01 100644 --- a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts +++ b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts @@ -62,7 +62,14 @@ import { type Dict, isDict } from '../shared.js'; * package's action, a misspelling), or its object cannot be told; * - lists the same actions in an order another list of the object contradicts; * - needs `actionLayout.selection` on an object the stack does not declare, or - * on one that already has a `selection` arm. + * on one that already has a different `selection` arm. + * + * An object whose `selection` arm is already the one this conversion would + * write (`pinned` and `more` the same names in the same order, `more` present + * exactly when it names any) needs nothing more: its lists move and the arm is + * left as declared. That is the state the source half leaves behind, so the + * stored half rewrites a Studio-saved row against it. Any other arm is the + * author's arrangement and is never overwritten, nor read as agreeing. * * A list left as stored is refused by the protocol-19 schema until it is * moved by hand. @@ -299,25 +306,51 @@ function planObject( .filter((n, i, all) => all.indexOf(n) === i); if (byDefault.join('\u0000') === plan.names.join('\u0000')) return plan; + const pinned = plan.names.slice(0, OBJECT_SELECTION_ACTIONS_LIMIT); + const more = plan.names.slice(OBJECT_SELECTION_ACTIONS_LIMIT); + const arm = more.length > 0 ? { pinned, more } : { pinned }; const objects = Array.isArray(stack.objects) ? stack.objects : []; const oi = objects.findIndex((o) => isDict(o) && o.name === object); const target = oi >= 0 ? (objects[oi] as Dict) : undefined; const layout = target?.actionLayout; - if (!target || (isDict(layout) && layout.selection !== undefined)) { + const declaredArm = isDict(layout) ? layout.selection : undefined; + // The arm this conversion would write is already declared (the source half + // wrote it): the order is kept, and there is nothing to write. + if (target && declaredArm !== undefined && isSameArm(declaredArm, arm)) return plan; + if (!target || declaredArm !== undefined) { plan.todo = `The selection bar of object \`${object}\` drew its actions in the order its list views name ` + `them (${plan.names.map((n) => `\`${n}\``).join(', ')}), which is not their default order, and keeping it ` - + `needs the object's \`actionLayout.selection\`, which ${target ? 'it already declares' : 'this metadata does not declare the object to carry'}. ` - + 'Left as stored; add `\'selection\'` to the `locations` of each action they name, write the order as ' - + 'the object\'s `actionLayout.selection`, and delete the key on each view.'; + + `needs the object's \`actionLayout.selection\` to be ${JSON.stringify(arm)}, which ` + + `${target ? `it does not: it declares ${JSON.stringify(declaredArm)}` : 'this metadata does not declare the object to carry'}. ` + + 'Left as stored; add `\'selection\'` to the `locations` of each action they name, write the order you ' + + 'keep as the object\'s `actionLayout.selection`, and delete the key on each view.'; return plan; } - const pinned = plan.names.slice(0, OBJECT_SELECTION_ACTIONS_LIMIT); - const more = plan.names.slice(OBJECT_SELECTION_ACTIONS_LIMIT); - plan.arm = more.length > 0 ? { pinned, more } : { pinned }; + plan.arm = arm; plan.objectPath = `objects[${oi}]`; return plan; } +/** Two arrays of names, equal in length, element and order. */ +function sameNames(a: unknown, b: readonly string[]): boolean { + return Array.isArray(a) && a.length === b.length && a.every((n, i) => n === b[i]); +} + +/** + * Whether a declared `selection` arm is exactly the one this conversion writes: + * the same keys (`pinned`, and `more` only when it names any), each naming the + * same actions in the same order. Strict on purpose: `more: []`, a reordered or + * re-split arm is the author's arrangement, which this conversion never + * overwrites and never reads as agreeing with a list it does not spell. + */ +function isSameArm(declared: unknown, arm: { pinned: string[]; more?: string[] }): boolean { + if (!isDict(declared)) return false; + const keys = Object.keys(declared).filter((k) => declared[k] !== undefined).sort(); + const want = Object.keys(arm).sort(); + if (keys.join('\u0000') !== want.join('\u0000')) return false; + return sameNames(declared.pinned, arm.pinned) && (arm.more === undefined || sameNames(declared.more, arm.more)); +} + /** The TODO path of one list. */ function todoAt(list: ListSite): string { return `${list.path}.bulkActions`; From 932b03a84396a6dab993117271cdc9d4e268341f Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 23:25:57 +0000 Subject: [PATCH 3/5] chore(changeset): stored bulk-actions list beside an equal declared selection Claude-Session: https://claude.ai/code/session_016WV4cxRh6Sbfo2Xm49JPx6 Co-authored-by: Claude --- .../39395-stored-bulk-actions-declared-selection.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .changeset/39395-stored-bulk-actions-declared-selection.md diff --git a/.changeset/39395-stored-bulk-actions-declared-selection.md b/.changeset/39395-stored-bulk-actions-declared-selection.md new file mode 100644 index 00000000000..bbfd2af2739 --- /dev/null +++ b/.changeset/39395-stored-bulk-actions-declared-selection.md @@ -0,0 +1,12 @@ +--- +'@objectstack/spec': patch +--- + +fix(spec): `os migrate meta --stored --apply` rewrites a stored list view's `bulkActions` when the object already declares the same `actionLayout.selection` + +Clause-②: no +Metadata-protocol: none + +The protocol-19 conversion `view-bulk-actions-to-action-selection` left every list of an object as stored, with a TODO, whenever the object already declared `actionLayout.selection`, without comparing it. The source half (`os migrate meta --from 18 --write`) writes exactly that arm when a list's order is not the default one, so after the source edits a Studio-saved list view row stayed unconverted, `--stored --apply` exited 1, and its TODO prescribed the edit that was already made. + +The conversion now compares the declared arm with the one it would write: `pinned` (the first three names) and `more` (the rest, present only when it names any), the same names in the same order. When they are equal, the lists move and the arm is left as declared, so the stored pass rewrites the row without `bulkActions`. Any other arm (another order, the same order split differently between `pinned` and `more`, an empty `more`, fewer or more names) is the author's arrangement: it is never overwritten, the row stays as stored, and the TODO now names the arm the list's order needs beside the arm the object declares. The workaround (re-save the view without `bulkActions`) still works. From 76b5105984f80ef2a580b942bbfd2e6e6c6231c0 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 00:43:56 +0000 Subject: [PATCH 4/5] fix(spec): accept a declared selection arm that already draws a stored list's order A stored row replays alone, so an arm the source half merged from several lists is wider than the row; judge it by the merge's own criterion. Claude-Session: https://claude.ai/code/session_016WV4cxRh6Sbfo2Xm49JPx6 Co-authored-by: Claude --- ...-stored-bulk-actions-declared-selection.md | 6 +- ...-actions-to-action-selection-39395.test.ts | 52 +++++++++++++--- .../view-bulk-actions-to-action-selection.ts | 62 +++++++++++-------- 3 files changed, 83 insertions(+), 37 deletions(-) diff --git a/.changeset/39395-stored-bulk-actions-declared-selection.md b/.changeset/39395-stored-bulk-actions-declared-selection.md index bbfd2af2739..37872ee55e3 100644 --- a/.changeset/39395-stored-bulk-actions-declared-selection.md +++ b/.changeset/39395-stored-bulk-actions-declared-selection.md @@ -2,11 +2,11 @@ '@objectstack/spec': patch --- -fix(spec): `os migrate meta --stored --apply` rewrites a stored list view's `bulkActions` when the object already declares the same `actionLayout.selection` +fix(spec): `os migrate meta --stored --apply` rewrites a stored list view's `bulkActions` when the object's declared `actionLayout.selection` already draws its order Clause-②: no Metadata-protocol: none -The protocol-19 conversion `view-bulk-actions-to-action-selection` left every list of an object as stored, with a TODO, whenever the object already declared `actionLayout.selection`, without comparing it. The source half (`os migrate meta --from 18 --write`) writes exactly that arm when a list's order is not the default one, so after the source edits a Studio-saved list view row stayed unconverted, `--stored --apply` exited 1, and its TODO prescribed the edit that was already made. +The protocol-19 conversion `view-bulk-actions-to-action-selection` left every list of an object as stored, with a TODO, whenever the object already declared `actionLayout.selection`, without comparing it. The source half (`os migrate meta --from 18 --write`) writes exactly that arm when a list's order is not the default one, merged from every list of the object, so after the source edits a Studio-saved list view row stayed unconverted, `--stored --apply` exited 1, and its TODO prescribed the edit that was already made. -The conversion now compares the declared arm with the one it would write: `pinned` (the first three names) and `more` (the rest, present only when it names any), the same names in the same order. When they are equal, the lists move and the arm is left as declared, so the stored pass rewrites the row without `bulkActions`. Any other arm (another order, the same order split differently between `pinned` and `more`, an empty `more`, fewer or more names) is the author's arrangement: it is never overwritten, the row stays as stored, and the TODO now names the arm the list's order needs beside the arm the object declares. The workaround (re-save the view without `bulkActions`) still works. +The conversion now reads the declared arm against the list's order, the way it already reads each list against the merged order of several lists: the arm agrees when it names every action the list names, its order (`pinned`, then `more`) restricted to those names is the list's, and each name is pinned exactly when it is among the list's first three. When it agrees (the arm the conversion would write, or a wider one the source half merged from more lists), the list moves and the arm is left as declared; the named actions still gain `'selection'` where they lack it. Any other arm (another order, a name moved across the `pinned`/`more` split, an action of the list not named, not an arm) is the author's arrangement: it is never overwritten, the row stays as stored, and the TODO now names the declared arm beside an arm that would keep the list's order. The workaround (re-save the view without `bulkActions`) still works. diff --git a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts index a452745e8b7..5c42048f3aa 100644 --- a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts +++ b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts @@ -10,10 +10,12 @@ * entry over a Studio-saved view row with the deployment's declared objects * and actions beside it (`judgeStoredViewBulkActions` builds exactly the * `{ views: [row], objects, actions }` stack used here). The row is rewritten - * when the declared arm is the one the entry would write — key for key, in - * order — and left as stored, with its TODO, when it is any other arm: a - * declared arrangement is never overwritten and never read as agreeing with a - * list it does not spell. + * when the declared arm already draws its order — every name in the arm, the + * arm's order restricted to the row's names is the row, each name on the side + * of the pinned / more split it would get (the criterion the entry's own + * multi-list merge applies to each list) — and left as stored, with its TODO, + * for any other arm: a declared arrangement is never overwritten and never + * read as agreeing with a list it does not keep. */ import { describe, expect, it } from 'vitest'; @@ -24,8 +26,8 @@ import type { ConversionApplication, ConversionTodoDetail } from '../../types.js const ID = 'view-bulk-actions-to-action-selection'; const entry = () => ALL_CONVERSIONS.find((c) => c.id === ID)!; -/** Four actions of `crm_lead`, declared in alphabetical order, all already placed at `selection`. */ -const ACTIONS = ['alpha_act', 'beta_act', 'gamma_act', 'delta_act'].map((name) => ({ +/** Five actions of `crm_lead`, declared in alphabetical order, all already placed at `selection`. */ +const ACTIONS = ['alpha_act', 'beta_act', 'gamma_act', 'delta_act', 'epsilon_act'].map((name) => ({ name, label: name, objectName: 'crm_lead', @@ -79,17 +81,49 @@ describe(`${ID} — a declared actionLayout.selection`, () => { expect(applied.filter((d) => !d.path.startsWith('views[0]'))).toEqual([]); }); + it.each([ + ['the arm the entry writes with an empty more', TWO, { pinned: ['beta_act', 'alpha_act'], more: [] }], + ['wider, naming another action after the row', TWO, { pinned: ['beta_act', 'alpha_act', 'gamma_act'] }], + ['wider, naming another action between the row', TWO, { pinned: ['beta_act', 'gamma_act', 'alpha_act'] }], + ['wider in more', FOUR, { pinned: ['delta_act', 'beta_act', 'alpha_act'], more: ['gamma_act', 'epsilon_act'] }], + ])('rewrites the row when the declared arm is %s', (_label, names, arm) => { + const { out, applied, todos } = run(storedStack(names, arm)); + expect(todos).toEqual([]); + expect(out.views[0]!.list).not.toHaveProperty('bulkActions'); + expect(applied.filter((d) => !d.path.startsWith('views[0]'))).toEqual([]); + expect(out.objects[0]!.actionLayout).toEqual({ selection: arm }); + }); + + it('rewrites each stored row of an object whose arm the source half merged from several lists', () => { + // Source half: views [beta, alpha] and [beta, alpha, gamma] merge to pinned [beta, alpha, gamma]. + const source = run({ + views: [{ ...row(TWO), name: 'lead_short' }, { ...row([...TWO, 'gamma_act']), name: 'lead_long' }], + objects: [{ name: 'crm_lead' }], + actions: structuredClone(ACTIONS), + }); + expect(source.todos).toEqual([]); + const arm = (source.out.objects[0]!.actionLayout as { selection: unknown }).selection; + expect(arm).toEqual({ pinned: ['beta_act', 'alpha_act', 'gamma_act'] }); + // Stored half: each row replayed alone against that arm. + for (const names of [TWO, [...TWO, 'gamma_act']]) { + const { out, applied, todos } = run(storedStack(names, arm)); + expect(todos).toEqual([]); + expect(out.views[0]!.list).not.toHaveProperty('bulkActions'); + expect(applied.filter((d) => !d.path.startsWith('views[0]'))).toEqual([]); + } + }); + it.each([ ['another order', TWO, { pinned: ['alpha_act', 'beta_act'] }], ['the same order split differently', TWO, { pinned: ['beta_act'], more: ['alpha_act'] }], - ['an empty more beside the pinned the entry writes', TWO, { pinned: ['beta_act', 'alpha_act'], more: [] }], ['a subset of the names', FOUR, { pinned: ['delta_act', 'beta_act', 'alpha_act'] }], - ['a superset of the names', TWO, { pinned: ['beta_act', 'alpha_act', 'gamma_act'] }], + ['wider, moving a named action to more', TWO, { pinned: ['gamma_act', 'delta_act', 'beta_act'], more: ['alpha_act'] }], + ['not an arm', TWO, ['beta_act', 'alpha_act']], ])('leaves the row as stored, with its TODO, when the declared arm is %s', (_label, names, arm) => { const { out, applied, todos } = run(storedStack(names, arm)); expect(applied).toEqual([]); expect(todos.map((t) => t.path)).toEqual(['views[0].list.bulkActions']); - expect(todos[0]!.reason).toContain('actionLayout.selection'); + expect(todos[0]!.reason).toContain(`the arm it declares, ${JSON.stringify(arm)}, is not`); expect(out.views[0]!.list.bulkActions).toEqual(names); expect(out.objects[0]!.actionLayout).toEqual({ selection: arm }); }); diff --git a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts index 40c96d5cc01..0d79ae5eddb 100644 --- a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts +++ b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts @@ -64,12 +64,17 @@ import { type Dict, isDict } from '../shared.js'; * - needs `actionLayout.selection` on an object the stack does not declare, or * on one that already has a different `selection` arm. * - * An object whose `selection` arm is already the one this conversion would - * write (`pinned` and `more` the same names in the same order, `more` present - * exactly when it names any) needs nothing more: its lists move and the arm is - * left as declared. That is the state the source half leaves behind, so the - * stored half rewrites a Studio-saved row against it. Any other arm is the - * author's arrangement and is never overwritten, nor read as agreeing. + * An object whose `selection` arm already draws the lists' order needs + * nothing more: its lists move and the arm is left as declared. It draws it + * when every name the lists merge to is named by the arm, the arm's order + * (`pinned`, then `more`) restricted to those names is theirs, and each name + * sits on the side of the split it would get here (the first three pinned, + * the rest in `more`). An arm the source half wrote from more lists than a + * stored row carries is such an arm, so the stored half rewrites a + * Studio-saved row against it. For a list not in the default order, any other + * arm is the author's arrangement: it is never overwritten, nor read as + * agreeing. (A list already in the default order moves before any arm is + * read.) * * A list left as stored is refused by the protocol-19 schema until it is * moved by hand. @@ -314,14 +319,15 @@ function planObject( const target = oi >= 0 ? (objects[oi] as Dict) : undefined; const layout = target?.actionLayout; const declaredArm = isDict(layout) ? layout.selection : undefined; - // The arm this conversion would write is already declared (the source half - // wrote it): the order is kept, and there is nothing to write. - if (target && declaredArm !== undefined && isSameArm(declaredArm, arm)) return plan; + // The declared arm already draws this order (the source half wrote it, from + // these lists or from more of the object's lists): there is nothing to write. + if (target && declaredArm !== undefined && armKeepsOrder(declaredArm, plan.names)) return plan; if (!target || declaredArm !== undefined) { plan.todo = `The selection bar of object \`${object}\` drew its actions in the order its list views name ` - + `them (${plan.names.map((n) => `\`${n}\``).join(', ')}), which is not their default order, and keeping it ` - + `needs the object's \`actionLayout.selection\` to be ${JSON.stringify(arm)}, which ` - + `${target ? `it does not: it declares ${JSON.stringify(declaredArm)}` : 'this metadata does not declare the object to carry'}. ` + + `them (${plan.names.map((n) => `\`${n}\``).join(', ')}), which is not their default order. Keeping it needs ` + + 'the object\'s `actionLayout.selection` to name them in that order with the first three pinned and the rest ' + + `in \`more\` (as ${JSON.stringify(arm)} does), which ` + + `${target ? `the arm it declares, ${JSON.stringify(declaredArm)}, is not` : 'this metadata does not declare the object to carry'}. ` + 'Left as stored; add `\'selection\'` to the `locations` of each action they name, write the order you ' + 'keep as the object\'s `actionLayout.selection`, and delete the key on each view.'; return plan; @@ -331,24 +337,30 @@ function planObject( return plan; } -/** Two arrays of names, equal in length, element and order. */ -function sameNames(a: unknown, b: readonly string[]): boolean { - return Array.isArray(a) && a.length === b.length && a.every((n, i) => n === b[i]); +/** The string entries of a declared arm part, or `undefined` when it is not an array of strings. */ +function armPart(part: unknown): string[] | undefined { + if (part === undefined) return []; + return Array.isArray(part) && part.every((n) => typeof n === 'string') ? part : undefined; } /** - * Whether a declared `selection` arm is exactly the one this conversion writes: - * the same keys (`pinned`, and `more` only when it names any), each naming the - * same actions in the same order. Strict on purpose: `more: []`, a reordered or - * re-split arm is the author's arrangement, which this conversion never - * overwrites and never reads as agreeing with a list it does not spell. + * Whether a declared `selection` arm already draws `names` in their order, as + * the arm this conversion writes would: every name is in the arm, the arm's + * order (`pinned`, then `more`) restricted to the names is `names`, and each + * name is pinned exactly when it is among the first three. The same criterion + * the multi-list merge applies to each list, so an arm the source half built + * from several lists agrees with each of them read alone. Any other arm (a + * name missing, another order, a name on the other side of the split, not an + * arm at all) is the author's arrangement, never read as agreeing. */ -function isSameArm(declared: unknown, arm: { pinned: string[]; more?: string[] }): boolean { +function armKeepsOrder(declared: unknown, names: readonly string[]): boolean { if (!isDict(declared)) return false; - const keys = Object.keys(declared).filter((k) => declared[k] !== undefined).sort(); - const want = Object.keys(arm).sort(); - if (keys.join('\u0000') !== want.join('\u0000')) return false; - return sameNames(declared.pinned, arm.pinned) && (arm.more === undefined || sameNames(declared.more, arm.more)); + const pinned = armPart(declared.pinned); + const more = armPart(declared.more); + if (!pinned || !more) return false; + const drawn = [...pinned, ...more].filter((n) => names.includes(n)); + if (drawn.join('\u0000') !== names.join('\u0000')) return false; + return names.every((n, i) => pinned.includes(n) === i < OBJECT_SELECTION_ACTIONS_LIMIT); } /** The TODO path of one list. */ From 171441c25ff3da46b4c5f7c5f5cfe8f73e181181 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 01:18:39 +0000 Subject: [PATCH 5/5] fix(spec): read the declared selection arm's own pinned/more split for a stored list The source half's merge lets a list's names land in more, so a row replayed alone agrees with the merged arm when the arm keeps its order. Claude-Session: https://claude.ai/code/session_016WV4cxRh6Sbfo2Xm49JPx6 Co-authored-by: Claude --- ...-stored-bulk-actions-declared-selection.md | 2 +- ...-actions-to-action-selection-39395.test.ts | 37 +++++++++++------ .../view-bulk-actions-to-action-selection.ts | 41 +++++++++---------- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/.changeset/39395-stored-bulk-actions-declared-selection.md b/.changeset/39395-stored-bulk-actions-declared-selection.md index 37872ee55e3..38da82c3c3d 100644 --- a/.changeset/39395-stored-bulk-actions-declared-selection.md +++ b/.changeset/39395-stored-bulk-actions-declared-selection.md @@ -9,4 +9,4 @@ Metadata-protocol: none The protocol-19 conversion `view-bulk-actions-to-action-selection` left every list of an object as stored, with a TODO, whenever the object already declared `actionLayout.selection`, without comparing it. The source half (`os migrate meta --from 18 --write`) writes exactly that arm when a list's order is not the default one, merged from every list of the object, so after the source edits a Studio-saved list view row stayed unconverted, `--stored --apply` exited 1, and its TODO prescribed the edit that was already made. -The conversion now reads the declared arm against the list's order, the way it already reads each list against the merged order of several lists: the arm agrees when it names every action the list names, its order (`pinned`, then `more`) restricted to those names is the list's, and each name is pinned exactly when it is among the list's first three. When it agrees (the arm the conversion would write, or a wider one the source half merged from more lists), the list moves and the arm is left as declared; the named actions still gain `'selection'` where they lack it. Any other arm (another order, a name moved across the `pinned`/`more` split, an action of the list not named, not an arm) is the author's arrangement: it is never overwritten, the row stays as stored, and the TODO now names the declared arm beside an arm that would keep the list's order. The workaround (re-save the view without `bulkActions`) still works. +The conversion now reads the declared arm against the list's order the way it already reads each list against the merged order of several lists: the arm agrees when it names every action the list names and its order (`pinned`, then `more`) restricted to those names is the list's. Which of them are buttons is the arm's own split, as declared, never recomputed from one list, since the merge already lets a list's names land in `more`; so an arm the source half merged from several lists agrees with each of their rows replayed alone. When it agrees, the list moves and the arm is left as declared; the named actions still gain `'selection'` where they lack it. Any other arm (another order, an action of the list not named, not an arm) is the author's arrangement: it is never overwritten, the row stays as stored, and the TODO now names the declared arm beside an arm that would keep the list's order. The workaround (re-save the view without `bulkActions`) still works. diff --git a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts index 5c42048f3aa..19f456da5dc 100644 --- a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts +++ b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection-39395.test.ts @@ -10,12 +10,12 @@ * entry over a Studio-saved view row with the deployment's declared objects * and actions beside it (`judgeStoredViewBulkActions` builds exactly the * `{ views: [row], objects, actions }` stack used here). The row is rewritten - * when the declared arm already draws its order — every name in the arm, the - * arm's order restricted to the row's names is the row, each name on the side - * of the pinned / more split it would get (the criterion the entry's own - * multi-list merge applies to each list) — and left as stored, with its TODO, - * for any other arm: a declared arrangement is never overwritten and never - * read as agreeing with a list it does not keep. + * when the declared arm already keeps its order — every name in the arm, and + * the arm's order (pinned, then more) restricted to the row's names is the + * row; which names are buttons is the arm's own split, as the entry's + * multi-list merge lets a list's names land in more — and left as stored, + * with its TODO, for any other arm: a declared arrangement is never + * overwritten and never read as agreeing with a list it does not keep. */ import { describe, expect, it } from 'vitest'; @@ -86,6 +86,10 @@ describe(`${ID} — a declared actionLayout.selection`, () => { ['wider, naming another action after the row', TWO, { pinned: ['beta_act', 'alpha_act', 'gamma_act'] }], ['wider, naming another action between the row', TWO, { pinned: ['beta_act', 'gamma_act', 'alpha_act'] }], ['wider in more', FOUR, { pinned: ['delta_act', 'beta_act', 'alpha_act'], more: ['gamma_act', 'epsilon_act'] }], + // The arm keeps the row's order; which names are buttons is the arm's own + // split, and the source half's merge accepts a list whose names land in more. + ['the same order split differently', TWO, { pinned: ['beta_act'], more: ['alpha_act'] }], + ['wider, with a named action in more', TWO, { pinned: ['gamma_act', 'delta_act', 'beta_act'], more: ['alpha_act'] }], ])('rewrites the row when the declared arm is %s', (_label, names, arm) => { const { out, applied, todos } = run(storedStack(names, arm)); expect(todos).toEqual([]); @@ -94,18 +98,25 @@ describe(`${ID} — a declared actionLayout.selection`, () => { expect(out.objects[0]!.actionLayout).toEqual({ selection: arm }); }); - it('rewrites each stored row of an object whose arm the source half merged from several lists', () => { - // Source half: views [beta, alpha] and [beta, alpha, gamma] merge to pinned [beta, alpha, gamma]. + it.each([ + ['one a prefix of the other', [TWO, [...TWO, 'gamma_act']], { pinned: ['beta_act', 'alpha_act', 'gamma_act'] }], + [ + 'the shorter one past the third place of the merged order', + [['alpha_act', 'beta_act', 'gamma_act', 'epsilon_act', 'delta_act'], ['epsilon_act', 'delta_act']], + { pinned: ['alpha_act', 'beta_act', 'gamma_act'], more: ['epsilon_act', 'delta_act'] }, + ], + ])('rewrites each stored row of an object whose arm the source half merged from two lists, %s', (_label, lists, merged) => { + // Source half: both lists in one stack, the object declaring no arm. const source = run({ - views: [{ ...row(TWO), name: 'lead_short' }, { ...row([...TWO, 'gamma_act']), name: 'lead_long' }], + views: lists.map((names, i) => ({ ...row(names), name: `lead_grid_${i}` })), objects: [{ name: 'crm_lead' }], actions: structuredClone(ACTIONS), }); expect(source.todos).toEqual([]); const arm = (source.out.objects[0]!.actionLayout as { selection: unknown }).selection; - expect(arm).toEqual({ pinned: ['beta_act', 'alpha_act', 'gamma_act'] }); + expect(arm).toEqual(merged); // Stored half: each row replayed alone against that arm. - for (const names of [TWO, [...TWO, 'gamma_act']]) { + for (const names of lists) { const { out, applied, todos } = run(storedStack(names, arm)); expect(todos).toEqual([]); expect(out.views[0]!.list).not.toHaveProperty('bulkActions'); @@ -115,9 +126,9 @@ describe(`${ID} — a declared actionLayout.selection`, () => { it.each([ ['another order', TWO, { pinned: ['alpha_act', 'beta_act'] }], - ['the same order split differently', TWO, { pinned: ['beta_act'], more: ['alpha_act'] }], + ['another order across the split', TWO, { pinned: ['alpha_act'], more: ['beta_act'] }], ['a subset of the names', FOUR, { pinned: ['delta_act', 'beta_act', 'alpha_act'] }], - ['wider, moving a named action to more', TWO, { pinned: ['gamma_act', 'delta_act', 'beta_act'], more: ['alpha_act'] }], + ['wider, in another order', TWO, { pinned: ['alpha_act', 'gamma_act', 'beta_act'] }], ['not an arm', TWO, ['beta_act', 'alpha_act']], ])('leaves the row as stored, with its TODO, when the declared arm is %s', (_label, names, arm) => { const { out, applied, todos } = run(storedStack(names, arm)); diff --git a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts index 0d79ae5eddb..bd2d26fd19e 100644 --- a/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts +++ b/packages/spec/src/conversions/entries/19/view-bulk-actions-to-action-selection.ts @@ -64,15 +64,16 @@ import { type Dict, isDict } from '../shared.js'; * - needs `actionLayout.selection` on an object the stack does not declare, or * on one that already has a different `selection` arm. * - * An object whose `selection` arm already draws the lists' order needs - * nothing more: its lists move and the arm is left as declared. It draws it - * when every name the lists merge to is named by the arm, the arm's order - * (`pinned`, then `more`) restricted to those names is theirs, and each name - * sits on the side of the split it would get here (the first three pinned, - * the rest in `more`). An arm the source half wrote from more lists than a - * stored row carries is such an arm, so the stored half rewrites a - * Studio-saved row against it. For a list not in the default order, any other - * arm is the author's arrangement: it is never overwritten, nor read as + * An object whose `selection` arm already keeps the lists' order needs + * nothing more: its lists move and the arm is left as declared. It keeps it + * when it names every action the lists merge to, and its order (`pinned`, + * then `more`) restricted to those names is theirs. Which names are buttons + * is read from the arm as declared, never recomputed from one list: the + * merge below already lets a list's names fall in `more`. So an arm the + * source half merged from several lists keeps the order of each of them, and + * the stored half rewrites each Studio-saved row against it. For a list not + * in the default order, any other arm (a name missing, another order, not an + * arm) is the author's arrangement: it is never overwritten, nor read as * agreeing. (A list already in the default order moves before any arm is * read.) * @@ -325,8 +326,8 @@ function planObject( if (!target || declaredArm !== undefined) { plan.todo = `The selection bar of object \`${object}\` drew its actions in the order its list views name ` + `them (${plan.names.map((n) => `\`${n}\``).join(', ')}), which is not their default order. Keeping it needs ` - + 'the object\'s `actionLayout.selection` to name them in that order with the first three pinned and the rest ' - + `in \`more\` (as ${JSON.stringify(arm)} does), which ` + + 'the object\'s `actionLayout.selection` to name them all in that order (`pinned`, then `more`), ' + + `as ${JSON.stringify(arm)} does, which ` + `${target ? `the arm it declares, ${JSON.stringify(declaredArm)}, is not` : 'this metadata does not declare the object to carry'}. ` + 'Left as stored; add `\'selection\'` to the `locations` of each action they name, write the order you ' + 'keep as the object\'s `actionLayout.selection`, and delete the key on each view.'; @@ -344,14 +345,13 @@ function armPart(part: unknown): string[] | undefined { } /** - * Whether a declared `selection` arm already draws `names` in their order, as - * the arm this conversion writes would: every name is in the arm, the arm's - * order (`pinned`, then `more`) restricted to the names is `names`, and each - * name is pinned exactly when it is among the first three. The same criterion - * the multi-list merge applies to each list, so an arm the source half built - * from several lists agrees with each of them read alone. Any other arm (a - * name missing, another order, a name on the other side of the split, not an - * arm at all) is the author's arrangement, never read as agreeing. + * Whether a declared `selection` arm already keeps `names` in their order: + * every name is in the arm, and the arm's order (`pinned`, then `more`) + * restricted to the names is `names`. Which of them are buttons is the arm's + * own split, as declared: the multi-list merge above lets a list's names land + * in `more` too, so an arm the source half built from several lists keeps the + * order of each of them read alone. Any other arm (a name missing, another + * order, not an arm) is the author's arrangement, never read as agreeing. */ function armKeepsOrder(declared: unknown, names: readonly string[]): boolean { if (!isDict(declared)) return false; @@ -359,8 +359,7 @@ function armKeepsOrder(declared: unknown, names: readonly string[]): boolean { const more = armPart(declared.more); if (!pinned || !more) return false; const drawn = [...pinned, ...more].filter((n) => names.includes(n)); - if (drawn.join('\u0000') !== names.join('\u0000')) return false; - return names.every((n, i) => pinned.includes(n) === i < OBJECT_SELECTION_ACTIONS_LIMIT); + return drawn.join('\u0000') === names.join('\u0000'); } /** The TODO path of one list. */