From 53b6a15635e9ca0336f8bc8a72b2cb9a2e2c9167 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 14:53:23 +0000 Subject: [PATCH 1/3] test(metadata-protocol): pin the merged action list beside a package-less action on another object Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- ...l-meta-list-reads.action-owner-key.test.ts | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 packages/metadata-protocol/src/protocol-meta-list-reads.action-owner-key.test.ts diff --git a/packages/metadata-protocol/src/protocol-meta-list-reads.action-owner-key.test.ts b/packages/metadata-protocol/src/protocol-meta-list-reads.action-owner-key.test.ts new file mode 100644 index 00000000000..863ddcd052e --- /dev/null +++ b/packages/metadata-protocol/src/protocol-meta-list-reads.action-owner-key.test.ts @@ -0,0 +1,190 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#33904, ADR-0150 D4, ADR-0146 D8] The merged action list keys a + * package-less action by `(object, name)`: a package-less action bound to an + * object no package binds the name to is the environment's own item (or the + * platform's), listed beside the package's item, as the by-name read naming + * no package serves it beside one package holder (`judgeBareActionRead`). + * + * BASE (main 895783a1e): the list slots an action by name alone, so such a + * row stood in for the package's slot. Beside the package's code item alone + * it was served AS the package's item (its body, the package's `_packageId` + * and `_provenance: 'package'`), and the package's own item on its object + * left the list; beside the package's own stored row it lost to that row and + * left the list itself. A list scoped to the package served it in the + * package's slot. + * + * Driven over the protocol's own list read with a registry double that keys + * an action as the real one does: a package's item per package, a + * package-less item per object. + */ +import './lint-root-preload.testkit.js'; +import { describe, expect, it } from 'vitest'; +import { assertEngineFindOnePredicate } from '@objectstack/metadata-core'; +import { ObjectStackProtocolImplementation } from './protocol.js'; +import { NO_PACKAGE_SCOPED_READS } from './no-package-scoped-reads.testkit.js'; + +const A = 'com.acme.alpha'; +const NAME = 'approve'; + +interface StoredRow { id: string; type: string; name: string; package_id: string | null; state: string; metadata: string } + +const actionBody = (label: string, objectName: string | undefined) => ({ + name: NAME, label, type: 'url', target: 'https://example.com', ...(objectName !== undefined ? { objectName } : {}), +}); + +/** A's code item on `objectName`, as the registry lists it. */ +const shipped = (objectName: string | undefined) => ({ ...actionBody('alpha', objectName), _packageId: A, _provenance: 'package' }); +/** The registry's package-less entry the boot hydrates from a stored row (or a plugin registers). */ +const packageless = (label: string, objectName: string | undefined) => ({ ...actionBody(label, objectName), _provenance: 'org' }); + +const row = (id: string, packageId: string | null, label: string, objectName: string | undefined, state = 'active'): StoredRow => ({ + id, type: 'action', name: NAME, package_id: packageId, state, metadata: JSON.stringify(actionBody(label, objectName)), +}); + +const whereMatches = (r: Record, where: Record) => + Object.entries(where).every(([k, v]) => { + if (k.startsWith('$')) throw new Error(`[test double] unsupported WHERE combinator '${k}'`); + if (v !== null && typeof v === 'object' && Array.isArray((v as { $in?: unknown }).$in)) return (v as { $in: unknown[] }).$in.includes(r[k]); + return v === undefined || (r[k] ?? null) === v; + }); + +/** + * The protocol over a registry holding `items` (in registration order) and a + * store holding `rows`; `service` is a MetadataService listing, when given. + */ +function harness(items: Array>, rows: StoredRow[], service?: Array>) { + const ofPackage = (packageId?: string) => items.filter((i) => packageId === undefined || i._packageId === packageId); + const registry = { + ...NO_PACKAGE_SCOPED_READS, + getArtifactItem: (type: string, name: string, packageId?: string) => (type === 'action' + ? items.find((i) => i.name === name && i._packageId !== undefined && (packageId === undefined || i._packageId === packageId)) + : undefined), + getItem: (type: string, name: string, packageId?: string) => (type === 'action' + ? (packageId === undefined + ? items.find((i) => i.name === name && i._packageId === undefined) ?? items.find((i) => i.name === name) + : items.find((i) => i.name === name && i._packageId === packageId)) + : undefined), + listItems: (type: string, packageId?: string) => (type === 'action' ? ofPackage(packageId) : []), + packageScopedHoldersOf: (type: string, name: string) => (type === 'action' + ? [...new Set(items.filter((i) => i.name === name && typeof i._packageId === 'string').map((i) => i._packageId as string))] + : []), + getPackageScopedItem: (type: string, name: string, packageId: string) => (type === 'action' + ? items.find((i) => i.name === name && i._packageId === packageId) + : undefined), + getObject: () => undefined, + registerObject: () => undefined, + getPackage: () => undefined, + getAllPackages: () => [], + isPackageDisabled: () => false, + applyNavContributions: (app: unknown) => app, + }; + const engine: any = { + async find(table: string, opts?: { where?: Record; limit?: number }) { + if (table !== 'sys_metadata') return []; + const hits = rows.filter((r) => whereMatches(r as unknown as Record, opts?.where ?? {})); + return opts?.limit === undefined ? hits : hits.slice(0, opts.limit); + }, + async findOne(table: string, opts?: { where?: Record }) { + assertEngineFindOnePredicate(table, opts); + if (table !== 'sys_metadata') return null; + return rows.find((r) => whereMatches(r as unknown as Record, opts?.where ?? {})) ?? null; + }, + async insert() { + return {}; + }, + registry, + }; + const services = new Map(service ? [['metadata', { list: async (type: string) => (type === 'action' ? service : []) }]] : []); + return new ObjectStackProtocolImplementation(engine, () => services as Map, 'env_1'); +} + +/** The listed items of the name: object, label, package, provenance; sorted by object. */ +async function listed(protocol: ObjectStackProtocolImplementation, request: { packageId?: string; previewDrafts?: boolean } = {}) { + const answer: any = await protocol.getMetaItems({ type: 'action', ...request }); + return (answer.items as any[]) + .filter((it) => it?.name === NAME) + .map((it) => [it.objectName ?? null, it.label, it._packageId ?? null, it._provenance === 'package' ? 'package' : null, it._draft === true ? 'draft' : null]) + .sort((x, y) => String(x[0]).localeCompare(String(y[0]))); +} + +const both = (x: T, y: T): Array<[string, T[]]> => [['registered as written', [x, y]], ['registered the other way', [y, x]]]; + +describe('[#33904] the list naming no package lists a package-less action on another object beside the package\'s action', () => { + for (const [order, registered] of both(shipped('account'), packageless('env', 'contact'))) { + it(`A on account, the environment's row on contact, the registry holding both (${order}): both listed, the environment's with no package (BASE: one item, the environment's body as A's)`, async () => { + const protocol = harness(registered, [row('r-env', null, 'env', 'contact')]); + expect(await listed(protocol)).toEqual([ + ['account', 'alpha', A, 'package', null], + ['contact', 'env', null, null, null], + ]); + }); + } + + for (const [order, stored] of both(row('r-a', A, 'alpha custom', 'account'), row('r-env', null, 'env', 'contact'))) { + it(`A's own row on account beside the environment's row on contact (${order}): both listed (BASE: A's row alone)`, async () => { + const protocol = harness([shipped('account')], stored); + expect(await listed(protocol)).toEqual([ + ['account', 'alpha custom', A, 'package', null], + ['contact', 'env', null, null, null], + ]); + }); + } + + it('the environment\'s row object-less beside A on account: both listed', async () => { + const protocol = harness([shipped('account')], [row('r-env', null, 'env', undefined)]); + expect(await listed(protocol)).toEqual([ + ['account', 'alpha', A, 'package', null], + [null, 'env', null, null, null], + ]); + }); + + it('the MetadataService listing both copies: both listed once each', async () => { + const protocol = harness([shipped('account')], [row('r-env', null, 'env', 'contact')], + [shipped('account'), { ...actionBody('env (service copy)', 'contact') }]); + expect(await listed(protocol)).toEqual([ + ['account', 'alpha', A, 'package', null], + ['contact', 'env', null, null, null], + ]); + }); + + it('the draft preview: the environment\'s draft previews over its own item, A\'s item stays', async () => { + const protocol = harness([shipped('account')], [row('r-env', null, 'env', 'contact'), row('d-env', null, 'env draft', 'contact', 'draft')]); + expect(await listed(protocol, { previewDrafts: true })).toEqual([ + ['account', 'alpha', A, 'package', null], + ['contact', 'env draft', null, null, 'draft'], + ]); + }); + + it('the list scoped to A lists A\'s own item, never the environment\'s row on another object (BASE: the environment\'s body in A\'s slot)', async () => { + const protocol = harness([shipped('account'), packageless('env', 'contact')], [row('r-env', null, 'env', 'contact')]); + expect(await listed(protocol, { packageId: A })).toEqual([['account', 'alpha', A, 'package', null]]); + }); + + it('the list and the by-name read naming no package answer the environment\'s item on contact', async () => { + const protocol = harness([shipped('account'), packageless('env', 'contact')], [row('r-env', null, 'env', 'contact')]); + const read: any = await protocol.getMetaItem({ type: 'action', name: NAME }); + expect([read.item?.objectName, read.item?.label]).toEqual(['contact', 'env']); + expect((await listed(protocol)).filter(([object]) => object === 'contact').map(([, label]) => label)).toEqual(['env']); + }); +}); + +describe('[#33904] CONTROLS — what the list served before, it serves still', () => { + for (const [order, registered] of both(shipped('account'), packageless('env', 'account'))) { + it(`the environment's row on A's own object is A's customization: one item, its body in A's slot (${order})`, async () => { + const protocol = harness(registered, [row('r-env', null, 'env', 'account')]); + expect(await listed(protocol)).toEqual([['account', 'env', A, 'package', null]]); + }); + } + + it('no package holds the name: the environment\'s row is listed as itself', async () => { + const protocol = harness([packageless('env', 'contact')], [row('r-env', null, 'env', 'contact')]); + expect(await listed(protocol)).toEqual([['contact', 'env', null, null, null]]); + }); + + it('A on account alone: A\'s item', async () => { + const protocol = harness([shipped('account')], []); + expect(await listed(protocol)).toEqual([['account', 'alpha', A, 'package', null]]); + }); +}); From b1dd0eef48e7023202b2135e073562b8c67a83b2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 15:50:59 +0000 Subject: [PATCH 2/3] test(rest): pin the bare action read beside a disabled holder on another object Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- .../src/meta-qualified-item-route.test.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/rest/src/meta-qualified-item-route.test.ts b/packages/rest/src/meta-qualified-item-route.test.ts index b794c6ec928..6edacced16a 100644 --- a/packages/rest/src/meta-qualified-item-route.test.ts +++ b/packages/rest/src/meta-qualified-item-route.test.ts @@ -1050,6 +1050,33 @@ describe('#33456 — the bare action read grafts a holder\'s envelope only at it }); } + /** + * [#33904 item 2, ADR-0150 D4] A DISABLED package holding the name on + * another object lends the environment's item no envelope: the face would + * withhold an item stamped with a disabled package's `_packageId` (404). + * Reported on main `895783a1e` by the #33385 fold's harness probe; closed + * by #33898's owner-key lookup (the package bound at the served item's + * object, disabled holders included, and none there). + */ + describe('[#33904] a disabled holder on another object', () => { + const registryOnlyAction = (objectName: string) => + registry.registerItem('action', body('platform', objectName), 'name' as never); + for (const [shape, place] of [ + ['the environment\'s item (its row stored)', () => environmentAction('contact')], + ['a package-less registry item alone', () => registryOnlyAction('contact')], + ] as const) { + it(`A disabled on \`account\`, ${shape} on \`contact\`: served, with no package's envelope (BASE: A's \`_packageId\`, withheld 404)`, async () => { + for (const steps of bothOrders([() => shipAction(A, 'account'), place])) { + compose(); + steps.forEach((step) => step()); + registry.disablePackage(A); + const [status, , objectName, packageId, packaged] = await envelopeOf(); + expect([status, objectName, packageId, packaged]).toEqual([200, 'contact', undefined, false]); + } + }); + } + }); + describe('CONTROLs (unchanged)', () => { it('one package on one object with the environment\'s item on that object: its customization, under the package\'s envelope', async () => { shipAction(A, 'account'); From ac6ab305c55115518f31a2118efae0ddef4ce1b1 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 16:15:41 +0000 Subject: [PATCH 3/3] test(dogfood): pin the action list agreeing with the by-name read beside a package-less save on another object Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12 --- ...l-meta-list-reads.action-owner-key.test.ts | 190 ------------------ ...t-packageless-other-object.dogfood.test.ts | 87 ++++++++ 2 files changed, 87 insertions(+), 190 deletions(-) delete mode 100644 packages/metadata-protocol/src/protocol-meta-list-reads.action-owner-key.test.ts create mode 100644 packages/qa/dogfood/test/action-list-packageless-other-object.dogfood.test.ts diff --git a/packages/metadata-protocol/src/protocol-meta-list-reads.action-owner-key.test.ts b/packages/metadata-protocol/src/protocol-meta-list-reads.action-owner-key.test.ts deleted file mode 100644 index 863ddcd052e..00000000000 --- a/packages/metadata-protocol/src/protocol-meta-list-reads.action-owner-key.test.ts +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. - -/** - * [#33904, ADR-0150 D4, ADR-0146 D8] The merged action list keys a - * package-less action by `(object, name)`: a package-less action bound to an - * object no package binds the name to is the environment's own item (or the - * platform's), listed beside the package's item, as the by-name read naming - * no package serves it beside one package holder (`judgeBareActionRead`). - * - * BASE (main 895783a1e): the list slots an action by name alone, so such a - * row stood in for the package's slot. Beside the package's code item alone - * it was served AS the package's item (its body, the package's `_packageId` - * and `_provenance: 'package'`), and the package's own item on its object - * left the list; beside the package's own stored row it lost to that row and - * left the list itself. A list scoped to the package served it in the - * package's slot. - * - * Driven over the protocol's own list read with a registry double that keys - * an action as the real one does: a package's item per package, a - * package-less item per object. - */ -import './lint-root-preload.testkit.js'; -import { describe, expect, it } from 'vitest'; -import { assertEngineFindOnePredicate } from '@objectstack/metadata-core'; -import { ObjectStackProtocolImplementation } from './protocol.js'; -import { NO_PACKAGE_SCOPED_READS } from './no-package-scoped-reads.testkit.js'; - -const A = 'com.acme.alpha'; -const NAME = 'approve'; - -interface StoredRow { id: string; type: string; name: string; package_id: string | null; state: string; metadata: string } - -const actionBody = (label: string, objectName: string | undefined) => ({ - name: NAME, label, type: 'url', target: 'https://example.com', ...(objectName !== undefined ? { objectName } : {}), -}); - -/** A's code item on `objectName`, as the registry lists it. */ -const shipped = (objectName: string | undefined) => ({ ...actionBody('alpha', objectName), _packageId: A, _provenance: 'package' }); -/** The registry's package-less entry the boot hydrates from a stored row (or a plugin registers). */ -const packageless = (label: string, objectName: string | undefined) => ({ ...actionBody(label, objectName), _provenance: 'org' }); - -const row = (id: string, packageId: string | null, label: string, objectName: string | undefined, state = 'active'): StoredRow => ({ - id, type: 'action', name: NAME, package_id: packageId, state, metadata: JSON.stringify(actionBody(label, objectName)), -}); - -const whereMatches = (r: Record, where: Record) => - Object.entries(where).every(([k, v]) => { - if (k.startsWith('$')) throw new Error(`[test double] unsupported WHERE combinator '${k}'`); - if (v !== null && typeof v === 'object' && Array.isArray((v as { $in?: unknown }).$in)) return (v as { $in: unknown[] }).$in.includes(r[k]); - return v === undefined || (r[k] ?? null) === v; - }); - -/** - * The protocol over a registry holding `items` (in registration order) and a - * store holding `rows`; `service` is a MetadataService listing, when given. - */ -function harness(items: Array>, rows: StoredRow[], service?: Array>) { - const ofPackage = (packageId?: string) => items.filter((i) => packageId === undefined || i._packageId === packageId); - const registry = { - ...NO_PACKAGE_SCOPED_READS, - getArtifactItem: (type: string, name: string, packageId?: string) => (type === 'action' - ? items.find((i) => i.name === name && i._packageId !== undefined && (packageId === undefined || i._packageId === packageId)) - : undefined), - getItem: (type: string, name: string, packageId?: string) => (type === 'action' - ? (packageId === undefined - ? items.find((i) => i.name === name && i._packageId === undefined) ?? items.find((i) => i.name === name) - : items.find((i) => i.name === name && i._packageId === packageId)) - : undefined), - listItems: (type: string, packageId?: string) => (type === 'action' ? ofPackage(packageId) : []), - packageScopedHoldersOf: (type: string, name: string) => (type === 'action' - ? [...new Set(items.filter((i) => i.name === name && typeof i._packageId === 'string').map((i) => i._packageId as string))] - : []), - getPackageScopedItem: (type: string, name: string, packageId: string) => (type === 'action' - ? items.find((i) => i.name === name && i._packageId === packageId) - : undefined), - getObject: () => undefined, - registerObject: () => undefined, - getPackage: () => undefined, - getAllPackages: () => [], - isPackageDisabled: () => false, - applyNavContributions: (app: unknown) => app, - }; - const engine: any = { - async find(table: string, opts?: { where?: Record; limit?: number }) { - if (table !== 'sys_metadata') return []; - const hits = rows.filter((r) => whereMatches(r as unknown as Record, opts?.where ?? {})); - return opts?.limit === undefined ? hits : hits.slice(0, opts.limit); - }, - async findOne(table: string, opts?: { where?: Record }) { - assertEngineFindOnePredicate(table, opts); - if (table !== 'sys_metadata') return null; - return rows.find((r) => whereMatches(r as unknown as Record, opts?.where ?? {})) ?? null; - }, - async insert() { - return {}; - }, - registry, - }; - const services = new Map(service ? [['metadata', { list: async (type: string) => (type === 'action' ? service : []) }]] : []); - return new ObjectStackProtocolImplementation(engine, () => services as Map, 'env_1'); -} - -/** The listed items of the name: object, label, package, provenance; sorted by object. */ -async function listed(protocol: ObjectStackProtocolImplementation, request: { packageId?: string; previewDrafts?: boolean } = {}) { - const answer: any = await protocol.getMetaItems({ type: 'action', ...request }); - return (answer.items as any[]) - .filter((it) => it?.name === NAME) - .map((it) => [it.objectName ?? null, it.label, it._packageId ?? null, it._provenance === 'package' ? 'package' : null, it._draft === true ? 'draft' : null]) - .sort((x, y) => String(x[0]).localeCompare(String(y[0]))); -} - -const both = (x: T, y: T): Array<[string, T[]]> => [['registered as written', [x, y]], ['registered the other way', [y, x]]]; - -describe('[#33904] the list naming no package lists a package-less action on another object beside the package\'s action', () => { - for (const [order, registered] of both(shipped('account'), packageless('env', 'contact'))) { - it(`A on account, the environment's row on contact, the registry holding both (${order}): both listed, the environment's with no package (BASE: one item, the environment's body as A's)`, async () => { - const protocol = harness(registered, [row('r-env', null, 'env', 'contact')]); - expect(await listed(protocol)).toEqual([ - ['account', 'alpha', A, 'package', null], - ['contact', 'env', null, null, null], - ]); - }); - } - - for (const [order, stored] of both(row('r-a', A, 'alpha custom', 'account'), row('r-env', null, 'env', 'contact'))) { - it(`A's own row on account beside the environment's row on contact (${order}): both listed (BASE: A's row alone)`, async () => { - const protocol = harness([shipped('account')], stored); - expect(await listed(protocol)).toEqual([ - ['account', 'alpha custom', A, 'package', null], - ['contact', 'env', null, null, null], - ]); - }); - } - - it('the environment\'s row object-less beside A on account: both listed', async () => { - const protocol = harness([shipped('account')], [row('r-env', null, 'env', undefined)]); - expect(await listed(protocol)).toEqual([ - ['account', 'alpha', A, 'package', null], - [null, 'env', null, null, null], - ]); - }); - - it('the MetadataService listing both copies: both listed once each', async () => { - const protocol = harness([shipped('account')], [row('r-env', null, 'env', 'contact')], - [shipped('account'), { ...actionBody('env (service copy)', 'contact') }]); - expect(await listed(protocol)).toEqual([ - ['account', 'alpha', A, 'package', null], - ['contact', 'env', null, null, null], - ]); - }); - - it('the draft preview: the environment\'s draft previews over its own item, A\'s item stays', async () => { - const protocol = harness([shipped('account')], [row('r-env', null, 'env', 'contact'), row('d-env', null, 'env draft', 'contact', 'draft')]); - expect(await listed(protocol, { previewDrafts: true })).toEqual([ - ['account', 'alpha', A, 'package', null], - ['contact', 'env draft', null, null, 'draft'], - ]); - }); - - it('the list scoped to A lists A\'s own item, never the environment\'s row on another object (BASE: the environment\'s body in A\'s slot)', async () => { - const protocol = harness([shipped('account'), packageless('env', 'contact')], [row('r-env', null, 'env', 'contact')]); - expect(await listed(protocol, { packageId: A })).toEqual([['account', 'alpha', A, 'package', null]]); - }); - - it('the list and the by-name read naming no package answer the environment\'s item on contact', async () => { - const protocol = harness([shipped('account'), packageless('env', 'contact')], [row('r-env', null, 'env', 'contact')]); - const read: any = await protocol.getMetaItem({ type: 'action', name: NAME }); - expect([read.item?.objectName, read.item?.label]).toEqual(['contact', 'env']); - expect((await listed(protocol)).filter(([object]) => object === 'contact').map(([, label]) => label)).toEqual(['env']); - }); -}); - -describe('[#33904] CONTROLS — what the list served before, it serves still', () => { - for (const [order, registered] of both(shipped('account'), packageless('env', 'account'))) { - it(`the environment's row on A's own object is A's customization: one item, its body in A's slot (${order})`, async () => { - const protocol = harness(registered, [row('r-env', null, 'env', 'account')]); - expect(await listed(protocol)).toEqual([['account', 'env', A, 'package', null]]); - }); - } - - it('no package holds the name: the environment\'s row is listed as itself', async () => { - const protocol = harness([packageless('env', 'contact')], [row('r-env', null, 'env', 'contact')]); - expect(await listed(protocol)).toEqual([['contact', 'env', null, null, null]]); - }); - - it('A on account alone: A\'s item', async () => { - const protocol = harness([shipped('account')], []); - expect(await listed(protocol)).toEqual([['account', 'alpha', A, 'package', null]]); - }); -}); diff --git a/packages/qa/dogfood/test/action-list-packageless-other-object.dogfood.test.ts b/packages/qa/dogfood/test/action-list-packageless-other-object.dogfood.test.ts new file mode 100644 index 00000000000..51b4172f71a --- /dev/null +++ b/packages/qa/dogfood/test/action-list-packageless-other-object.dogfood.test.ts @@ -0,0 +1,87 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// [#33904, ADR-0146 D8 one effective read, ADR-0150 D4] Over HTTP, on a real +// boot of the showcase, the action list and the by-name read of a name agree +// when a package holds the name on one object and the environment saves a +// package-less action of the same name on another object, in both save orders. +// +// ## What was measured (stock showcase, admin session, main 68e726d631 + b8ac0e240e) +// +// The card's shape (a package's action on `account`, the environment's own +// package-less row on `contact`, both stored) was measured on a boot harness, +// where `getMetaItems({ type: 'action' })` left the environment's row out while +// the bare by-name read served it. Over HTTP the shape is not reached: +// +// - A managed code package's action name (`showcase_open_docs`): the +// package-less `PUT /meta/action/NAME` on another object is refused 403 +// `NOT_OVERRIDABLE` (sealed managed item), so no second row is stored. +// - A Studio-created package (writable): every save ends with ONE stored item +// of the name, and the list, `?names=`, `?package=` and the by-name reads +// all answer that one item. Which item that is (the later save's body under +// the package) is pinned here only as "the list answers what the by-name +// read answers"; the save door's choice is not this file's subject. +// +// The file is ISOLATED: it writes `/meta` and creates a package. + +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; +import { type VerifyStack } from '@objectstack/verify'; +import { bootShowcase } from './showcase-boot.js'; + +const PKG = 'com.example.qalistagree'; +const action = (name: string, label: string, objectName: string) => ({ + name, label, objectName, type: 'url', target: 'https://example.com', locations: ['record_more'], +}); + +describe('[#33904] the action list agrees with the by-name read beside a package-less save on another object', () => { + let stack: VerifyStack; + let admin: string; + + beforeAll(async () => { + stack = await bootShowcase(); + admin = await stack.signIn(); + const created = await stack.apiAs(admin, 'POST', '/packages', { + manifest: { + id: PKG, name: 'QA list agree', version: '0.1.0', type: 'app', namespace: 'qalistagree', + dependencies: { 'com.example.showcase': '*' }, + }, + }); + expect(created.status, await created.clone().text()).toBe(201); + }, 240_000); + + afterAll(async () => { await stack?.stop(); }); + + /** The identity a client reads off an action: its object, label and package. */ + const face = (a: any) => [a?.objectName ?? null, a?.label ?? null, a?._packageId ?? null]; + const listed = async (path: string, name: string) => { + const res = await stack.apiAs(admin, 'GET', path); + const body: any = await res.json(); + expect(res.status, JSON.stringify(body).slice(0, 400)).toBe(200); + return ((body?.data?.items ?? body?.items ?? []) as any[]).filter((a) => a?.name === name).map(face); + }; + const byName = async (path: string) => { + const res = await stack.apiAs(admin, 'GET', path); + const body: any = await res.json(); + expect(res.status, JSON.stringify(body).slice(0, 400)).toBe(200); + return face(body?.data?.item ?? body?.item ?? body?.data); + }; + const put = async (path: string, body: unknown) => { + const res = await stack.apiAs(admin, 'PUT', path, body); + expect(res.status, await res.clone().text()).toBe(200); + }; + + for (const order of ['the package\'s save first', 'the environment\'s save first'] as const) { + it(`${order}: the list, \`?names=\` and \`?package=\` each answer exactly what the by-name read answers`, async () => { + const name = order === 'the package\'s save first' ? 'qa_list_agree_pf' : 'qa_list_agree_ef'; + const savePackage = () => put(`/meta/action/${name}?package=${PKG}`, action(name, 'package on task', 'showcase_task')); + const saveEnvironment = () => put(`/meta/action/${name}`, action(name, 'environment on product', 'showcase_product')); + if (order === 'the package\'s save first') { await savePackage(); await saveEnvironment(); } + else { await saveEnvironment(); await savePackage(); } + + const bare = await byName(`/meta/action/${name}`); + expect(await listed('/meta/action', name)).toEqual([bare]); + expect(await listed(`/meta/action?names=${name}`, name)).toEqual([bare]); + const atPackage = await byName(`/meta/action/${name}?package=${PKG}`); + expect(await listed(`/meta/action?package=${PKG}`, name)).toEqual([atPackage]); + }, 120_000); + } +});