From 86e86495695d55d6f2d84564e41407765c7b6015 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 10:08:00 +0000 Subject: [PATCH 1/4] fix(objectql,runtime): package-less actions keep one slot per owner key; the route serves the one on its key Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- .../objectql/src/action-package-addressing.ts | 10 ++ .../objectql/src/package-scoped-resolver.ts | 9 +- packages/objectql/src/registry.ts | 152 +++++++++++++++++- packages/runtime/src/action-execution.ts | 74 ++++++++- 4 files changed, 236 insertions(+), 9 deletions(-) diff --git a/packages/objectql/src/action-package-addressing.ts b/packages/objectql/src/action-package-addressing.ts index 7142fb02608..573528456df 100644 --- a/packages/objectql/src/action-package-addressing.ts +++ b/packages/objectql/src/action-package-addressing.ts @@ -62,10 +62,20 @@ export function actionOwnerScopedRegistry(registry: PackageScopedRegistry, owner const item = registry.getPackageScopedItem(type, name, packageId, member); return type !== 'action' || owns(item) ? item : undefined; }, + // [ADR-0150 D4] The environment-scoped action ON this owner key: a + // registry that keeps one package-less action per owner key + // (`getEnvironmentScopedActions`) is asked for every one of them, never + // only the bare slot's, which may sit on another key. getEnvironmentScopedItem: (type: string, name: string, member?: string) => { + if (type === 'action' && typeof registry.getEnvironmentScopedActions === 'function') { + return registry.getEnvironmentScopedActions(name).find(owns); + } const item = registry.getEnvironmentScopedItem(type, name, member); return type !== 'action' || owns(item) ? item : undefined; }, + ...(typeof registry.getEnvironmentScopedActions === 'function' + ? { getEnvironmentScopedActions: (name: string) => registry.getEnvironmentScopedActions!(name).filter(owns) } + : {}), }; } diff --git a/packages/objectql/src/package-scoped-resolver.ts b/packages/objectql/src/package-scoped-resolver.ts index d9d3da788f8..7f80cc56f20 100644 --- a/packages/objectql/src/package-scoped-resolver.ts +++ b/packages/objectql/src/package-scoped-resolver.ts @@ -118,11 +118,16 @@ export interface PackageScopedQuery extends PackageScopedHoldersQuery { readonly includeDisabledPackages?: boolean; } -/** The registry slice the registry adapter reads — every member of it, and no other. */ +/** + * The registry slice the registry adapter reads — every member of it, and no other. + * [ADR-0150 D4] `getEnvironmentScopedActions`, where a registry has it, is the + * environment-scoped `action` items of a name, one per owner key: the + * owner-key view (`actionOwnerScopedRegistry`) reads the item on its own key. + */ export type PackageScopedRegistry = Pick< SchemaRegistry, 'getPackage' | 'getAllPackages' | 'packageScopedHoldersOf' | 'getPackageScopedItem' | 'getEnvironmentScopedItem' ->; +> & Partial>; /** * Resolve a bare name by ADR-0150 D3 over the registry's holders: the rule diff --git a/packages/objectql/src/registry.ts b/packages/objectql/src/registry.ts index 8728bd488ed..09decdf4040 100644 --- a/packages/objectql/src/registry.ts +++ b/packages/objectql/src/registry.ts @@ -3793,6 +3793,51 @@ function storedRowPackageOf(entry: BundleEntry): string | undefined { return typeof stamped === 'string' && stamped !== '' && stamped !== 'sys_metadata' ? stamped : undefined; } +/** + * [ADR-0150 D4] The mark that opens and separates a package-less action's + * owner-key slot. An action is identified by `(owner, owning object, name)`, + * so the platform's action bound to `lead` and the environment's object-less + * action of the same name are two items under two keys, never one contested + * name. The bare slot `name` holds the package-less action registered last; + * each package-less action of another owner key it displaced keeps its own + * slot under this mark, one per owner key. Like {@link OVERLAY_SLOT_MARK}, a + * control character never occurs in an object or action name, so no reader of + * the other key forms mistakes this one for its own: it is never a bare key + * and never ends `:name`, so it adds no package holder and is no artifact. + */ +const PACKAGELESS_ACTION_SLOT_MARK = '\u0001'; + +/** [ADR-0150 D4] A package-less action's owner key: its object, or `global` for every object-less spelling. */ +function packagelessActionOwnerKey(action: unknown): string { + const owner = standaloneActionOwnerKey(action); + return isObjectLessActionKey(owner) ? GLOBAL_ACTION_OBJECT_KEY : owner; +} + +/** `lead` + `approve` → the owner-key slot of the package-less `approve` bound to `lead`. */ +function packagelessActionSlotKey(ownerKey: string, name: string): string { + return `${PACKAGELESS_ACTION_SLOT_MARK}${ownerKey}${PACKAGELESS_ACTION_SLOT_MARK}${name}`; +} + +/** + * [ADR-0150 D4] The owner-key slots of the package-less action `name` + * ({@link packagelessActionSlotKey}), in the store's order: the package-less + * actions of the name beside the one in the bare slot, one per owner key. + */ +function packagelessActionSlotEntriesOf(collection: Map, name: string): BundleEntry[] { + const out: BundleEntry[] = []; + for (const [key, item] of collection) { + if (!isPackagelessActionSlotKey(key)) continue; + const sep = key.indexOf(PACKAGELESS_ACTION_SLOT_MARK, 1); + if (sep > 0 && key.slice(sep + 1) === name) out.push({ key, item }); + } + return out; +} + +/** Is `key` a package-less action's owner-key slot ({@link packagelessActionSlotKey})? */ +function isPackagelessActionSlotKey(key: string): boolean { + return key.startsWith(PACKAGELESS_ACTION_SLOT_MARK); +} + /** * [#32408, contract review F2, delta review N1] What a door's registration * brings to a bundled name: the package and the members it adds to its @@ -6745,7 +6790,9 @@ export class SchemaRegistry { for (const [key, action] of collection) { if (!action || typeof action !== 'object' || typeof (action as any).name !== 'string') continue; const name: string = (action as any).name; - if (key !== name && collection.has(name)) continue; + // [ADR-0150 D4] A package-less action of another owner key than the + // bare slot's is its own item, never shadowed by it. + if (key !== name && !isPackagelessActionSlotKey(key) && collection.has(name)) continue; if (parseOverlaySlotKey(key) !== undefined ? !servedOverlays.has(key) : overlaysOf.has(key)) continue; if (isObjectLessActionKey(standaloneActionOwnerKey(action))) continue; // [#28877] …and so is an action that launches into a disabled package. @@ -8898,6 +8945,12 @@ export class SchemaRegistry { } } + // [ADR-0150 D4] A package-less action never erases a package-less action + // of another owner key: the one it displaces from the bare slot keeps its + // own key's slot ({@link keepPackagelessActionOwnerKeys}). + if (type === 'action' && !packageId && rowPackage === undefined) { + this.keepPackagelessActionOwnerKeys(collection, bareKey, item); + } this.noteItem(type, storageKey); collection.set(storageKey, item); // [#33050] A slot the package's own body registration writes is one its @@ -8919,6 +8972,61 @@ export class SchemaRegistry { this.log(`[Registry] Registered ${type}: ${storageKey}`); } + /** + * [ADR-0150 D4] Before a package-less action `incoming` takes the bare slot + * of `name`: the package-less action of the same owner key it replaces + * leaves its owner-key slot (one key, one item: the later registration + * stays, as in the bare slot), and the bare slot's present item, when its + * owner key is another, moves to that key's own slot + * ({@link packagelessActionSlotKey}). So the platform's action bound to + * `lead` and the environment's object-less action of the name are both + * kept, in either registration order, and each is read on its own key. + */ + private keepPackagelessActionOwnerKeys(collection: Map, name: string, incoming: unknown): void { + const ownerKey = packagelessActionOwnerKey(incoming); + const sameKey = packagelessActionSlotKey(ownerKey, name); + if (collection.has(sameKey)) { + this.noteItem('action', sameKey); + collection.delete(sameKey); + } + const occupant = collection.get(name); + if (occupant === undefined || packagelessActionOwnerKey(occupant) === ownerKey) return; + const aside = packagelessActionSlotKey(packagelessActionOwnerKey(occupant), name); + this.noteItem('action', aside); + collection.set(aside, occupant); + this.log(`[Registry] Kept package-less action ${name} on ${packagelessActionOwnerKey(occupant)} beside the one on ${ownerKey}`); + } + + /** + * [ADR-0150 D4] The slot a removal of the package-less action `name`'s own + * entry retires ({@link removeRuntimeShadow}, {@link removeOverlayEntry}): + * the bare slot, unless another owner key's slot holds the one + * tenant-authored item of the name (ADR-0010 `_provenance: 'org'`, the + * stored row the removal heals) while the bare slot holds code's. + */ + private packagelessActionEntryToRetire(collection: Map, name: string): string { + const aside = packagelessActionSlotEntriesOf(collection, name); + if (aside.length === 0 || isTenantAuthored(collection.get(name))) return name; + const tenant = aside.filter(({ item }) => isTenantAuthored(item)); + return tenant.length === 1 ? tenant[0].key : name; + } + + /** + * [ADR-0150 D4] Retire one package-less action slot of `name`. When it is + * the bare slot, the first other owner key's item takes it, so the bare + * slot holds a package-less action of the name whenever one is kept. + */ + private retirePackagelessActionSlot(collection: Map, name: string, key: string): void { + collection.delete(key); + if (key !== name) return; + const [next] = packagelessActionSlotEntriesOf(collection, name); + if (next === undefined) return; + this.noteItem('action', next.key); + collection.delete(next.key); + this.noteItem('action', name); + collection.set(name, next.item); + } + /** * Validate Metadata against Spec Zod Schemas */ @@ -8994,7 +9102,10 @@ export class SchemaRegistry { } if (collection.has(name)) { - collection.delete(name); + // [ADR-0150 D4] …and another owner key's package-less action takes the + // bare slot it leaves ({@link retirePackagelessActionSlot}). + if (type === 'action') this.retirePackagelessActionSlot(collection, name, name); + else collection.delete(name); this.log(`[Registry] Unregistered ${type}: ${name}`); return; } @@ -9831,6 +9942,23 @@ export class SchemaRegistry { return unbound[0]?.item as T | undefined; } + /** + * [ADR-0150 D4] Every environment-scoped `action` item of `name` + * ({@link getEnvironmentScopedItem}'s test), one per owner key: the bare + * slot's, then each other owner key's package-less action + * ({@link packagelessActionSlotKey}). An action is identified by its owner + * key too, so a reader of one owner key (`actionOwnerScopedRegistry`) finds + * the item on its key, never only the bare slot's of another key. + */ + getEnvironmentScopedActions(name: string): T[] { + const collection = this.metadata.get('action'); + if (!collection) return []; + const holders = new Set(this.compositeHoldersOf(collection, name)); + return this.bareSlotEntriesOf('action', collection, name) + .filter(({ item }) => this.overlaySlotBinding('action', item, name, collection, holders) === null) + .map(({ item }) => item as T); + } + /** * [ADR-0150 D3, #31680 child E8] Does a by-name read of `type` consult * `(package, name)` — is it one of `PACKAGE_SCOPED_READ_TYPES` @@ -9905,6 +10033,7 @@ export class SchemaRegistry { getPackageScopedItem: (type, itemName, packageId, member) => this.isPackageDisabled(packageId) ? undefined : this.getPackageScopedItem(type, itemName, packageId, member), getEnvironmentScopedItem: (type, itemName, member) => this.getEnvironmentScopedItem(type, itemName, member), + getEnvironmentScopedActions: (itemName: string) => this.getEnvironmentScopedActions(itemName), }; const objectLess = actionOwnerScopedRegistry(live, GLOBAL_ACTION_OBJECT_KEY); const packages = objectLess.packageScopedHoldersOf('action', name); @@ -9939,13 +10068,17 @@ export class SchemaRegistry { * The bare-slot entries of `(type, name)`: one, or a bundle's members, canonical first. * [#33127, ADR-0150 D4] …then its package overlay slots ({@link overlaySlotKey}): every * stored row of the name, each bound to its package, read as the bare slot's entry is. + * [ADR-0150 D4] An action's package-less items of the other owner keys + * ({@link packagelessActionSlotKey}) follow the bare slot's: each is one + * more package-less item of the name, judged as the bare slot's is. */ private bareSlotEntriesOf(type: string, collection: Map, name: string): BundleEntry[] { const disc = ITEM_KEY_DISCRIMINATORS[type]; const bare = disc ? collectBundle(collection, name, disc).bare : collection.has(name) ? [{ key: name, item: collection.get(name) }] : []; - return [...bare, ...overlaySlotEntriesOf(collection, name, disc)]; + const otherOwnerKeys = type === 'action' ? packagelessActionSlotEntriesOf(collection, name) : []; + return [...bare, ...otherOwnerKeys, ...overlaySlotEntriesOf(collection, name, disc)]; } /** @@ -10189,7 +10322,10 @@ export class SchemaRegistry { if (key !== name && key.endsWith(`:${name}`)) { const it = item as any; if (it && it._packageId && it._packageId !== 'sys_metadata') { - collection.delete(name); + // [ADR-0150 D4] …the package-less action's own entry, which may sit + // in another owner key's slot ({@link packagelessActionEntryToRetire}). + if (type === 'action') this.retirePackagelessActionSlot(collection, name, this.packagelessActionEntryToRetire(collection, name)); + else collection.delete(name); // [#28356] An object may carry the shadow as a bound action; the // artifact it uncovers may bind elsewhere ({@link attachBoundActions}). if (type === 'action') this.invalidateAll(); @@ -10264,11 +10400,15 @@ export class SchemaRegistry { } if (!collection.has(name)) return false; - const plain = collection.get(name) as any; + // [ADR-0150 D4] A package-less action's own entry may sit in another + // owner key's slot beside the bare one ({@link packagelessActionEntryToRetire}). + const key = type === 'action' ? this.packagelessActionEntryToRetire(collection, name) : name; + const plain = collection.get(key) as any; if (plain && plain._packageId && plain._packageId !== 'sys_metadata' && !isTenantAuthored(plain)) { return false; } - collection.delete(name); + if (type === 'action') this.retirePackagelessActionSlot(collection, name, key); + else collection.delete(name); // [#28356] …and an object may carry the retired entry as a bound action // ({@link attachBoundActions}): drop the cached folds, as // {@link unregisterItem} does, or a deleted runtime action stays listed. diff --git a/packages/runtime/src/action-execution.ts b/packages/runtime/src/action-execution.ts index 2f53b4ac9e8..4bf62b5d287 100644 --- a/packages/runtime/src/action-execution.ts +++ b/packages/runtime/src/action-execution.ts @@ -6095,12 +6095,19 @@ export async function resolveRouteActionDeclaration(deps: ActionExecutionDeps, }); if (census !== undefined) return census; const item: any = (envelope as { item?: unknown } | null | undefined)?.item; + // [ADR-0150 D4] The bare read names no object, so of the name's + // package-less actions — one per owner key — it answers one: the + // route's is the one on its own key, bound first, then object-less. + const onRoute = packagelessActionOnRouteBeside(ql, objectName, actionName, item); + if (onRoute !== undefined) return { action: onRoute, obj }; const declared = item !== null && typeof item === 'object' && item.name === actionName && ownsRoute(item); return { action: declared ? item : undefined, obj }; } try { const fromRegistry: any = ql?.registry?.getItem?.('action', actionName); + const onRoute = packagelessActionOnRouteBeside(ql, objectName, actionName, fromRegistry); + if (onRoute !== undefined) return { action: onRoute, obj }; if (fromRegistry && ownsRoute(fromRegistry)) return { action: fromRegistry, obj }; } catch { /* registry without an item lookup → fall through to the metadata service */ @@ -6269,6 +6276,8 @@ type RouteHolderReading = owners: RouteHolders; /** The rung the router reaches first: bound to the routed object, else object-less. */ rung: RouteHolders; + /** [ADR-0150 D4] Is {@link rung} the bound one (some holder's item is bound to the routed object)? */ + boundRung: boolean; }; /** [ADR-0150 D4] Is a registry item a package's (`_packageId`), not package-less? */ @@ -6276,6 +6285,46 @@ function packagedItem(item: any): boolean { return typeof item?._packageId === 'string' && item._packageId !== ''; } +/** [ADR-0150 D4] Is an item package-less: no package stamp, or the stored-row sentinel? */ +function packagelessItem(item: any): boolean { + return !packagedItem(item) || item._packageId === 'sys_metadata'; +} + +/** + * [ADR-0150 D4] The package-less action of `actionName` that answers the route + * of `objectName`, when the read the route took (`answered`) is a package-less + * action of ANOTHER owner key. An action is identified by `(owner, owning + * object, name)`, and the registry keeps the name's package-less actions one + * per owner key (the platform's bound to `lead` beside the environment's + * object-less one), while a read that names no object answers only one of + * them. Binding first, then owner: the route's is the package-less action + * bound to the routed object, else the object-less one — the order the + * engine reaches a handler in ({@link actionHandlerObjectKeys}), so the + * declaration the route judges and the handler it runs are one item's. + * + * `undefined` — the read's answer stands — when the answer is no + * package-less action, already the one on the route's key, or the host's + * registry cannot list the name's items; and when no package-less action is + * on the route's key. + */ +function packagelessActionOnRouteBeside(ql: any, objectName: string, actionName: string, answered: any): any | undefined { + if (answered === null || typeof answered !== 'object' || answered.name !== actionName || !packagelessItem(answered)) return undefined; + const registry: any = ql?.registry; + if (typeof registry?.listItems !== 'function') return undefined; + let packageless: any[]; + try { + packageless = (registry.listItems('action', undefined, { includeDisabledPackages: true }) ?? []) + .filter((item: any) => item?.name === actionName && packagelessItem(item)); + } catch { + return undefined; + } + const bound = isObjectLessActionKey(objectName) ? [] : packageless.filter((item) => standaloneActionOwnerKey(item) === objectName); + const rung = bound.length > 0 ? bound : packageless.filter((item) => isObjectLessActionKey(standaloneActionOwnerKey(item))); + if (rung.length !== 1) return undefined; + const ownerKey = (item: any) => (isObjectLessActionKey(standaloneActionOwnerKey(item)) ? GLOBAL_ACTION_OBJECT_KEY : standaloneActionOwnerKey(item)); + return ownerKey(rung[0]) === ownerKey(answered) ? undefined : rung[0]; +} + async function readRouteHolders( args: { ql: any; objectName: string; actionName: string }, /** @@ -6329,6 +6378,7 @@ async function readRouteHolders( isDisabled, owners: file(ownerItems), rung: file(bound.length > 0 ? bound : ownerItems.filter(isObjectLess)), + boundRung: bound.length > 0, }; } @@ -6360,7 +6410,25 @@ async function environmentOwnerOfUnheldRoute( if (reading === undefined) return none; if (reading.degraded) return { action: undefined, obj, degraded: true, reason: reading.reason }; if (reading.owners.served.length > 0 || reading.owners.disabled.length > 0) return none; - return reading.rung.environment.length === 1 ? { action: reading.rung.environment[0], obj } : none; + if (reading.rung.environment.length === 1) return { action: reading.rung.environment[0], obj }; + // [ADR-0150 D4] Binding first, then owner: the platform's item bound to + // the routed object is the route's own key, beside no package holder there. + return platformItemOnBoundRung(reading) ?? none; +} + +/** + * [ADR-0150 D4] The platform's item bound to the routed object, when it is + * the only item on the route's bound rung: binding first, then owner, so it + * answers that route whatever package-less action of another key the name + * has (the environment's object-less one included), and the declaration the + * route judges is the item whose handler the engine reaches first there. + * `undefined` on the object-less rung, and beside any other item on the + * bound one: those compositions keep their answers. + */ +function platformItemOnBoundRung(reading: Extract): any | undefined { + const { rung, boundRung } = reading; + if (!boundRung || rung.platform.length !== 1) return undefined; + return rung.served.length === 0 && rung.disabled.length === 0 && rung.environment.length === 0 ? rung.platform[0] : undefined; } /** @@ -6415,6 +6483,10 @@ async function routeHolderCensus( const { owners, rung } = reading; if (owners.served.length === 0 && owners.disabled.length > 0) return { action: undefined, obj }; if (rung.environment.length === 1) return { action: rung.environment[0], obj }; + // [ADR-0150 D4] …the platform's item bound to the routed object, alone on + // that rung: the route's own key, binding first, then owner. + const platform = platformItemOnBoundRung(reading); + if (platform !== undefined) return { action: platform, obj }; if (rung.served.length !== 1 || rung.platform.length > 0) return undefined; let envelope: unknown; try { From e9e65df4c513258a499395a5039569075a9c8619 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 10:19:29 +0000 Subject: [PATCH 2/4] test: pin the package-less action per owner key, and its route; changeset Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- .changeset/package-less-action-two-keys.md | 26 ++++ .../src/action-package-addressing.test.ts | 87 +++++++++++ packages/objectql/src/registry.ts | 57 ++++--- .../src/action-package-addressing.test.ts | 143 +++++++++++++++++- 4 files changed, 294 insertions(+), 19 deletions(-) create mode 100644 .changeset/package-less-action-two-keys.md diff --git a/.changeset/package-less-action-two-keys.md b/.changeset/package-less-action-two-keys.md new file mode 100644 index 00000000000..3c4789886d3 --- /dev/null +++ b/.changeset/package-less-action-two-keys.md @@ -0,0 +1,26 @@ +--- +'@objectstack/objectql': patch +'@objectstack/runtime': patch +--- + +fix(objectql,runtime)!: a package-less action is kept on its own owner key, and a route serves the one on its key, so the declaration it judges and the handler it runs are one item's (ADR-0150 D4) + +Clause-②: no (narrowing) — `/actions/OBJECT/NAME` answers with the declaration of the package-less action bound to `OBJECT` (its `requiredPermissions` and every other gate) wherever the platform binds `NAME` to `OBJECT` beside the environment's object-less `NAME`, in either registration order; a caller those requirements refuse is refused `403 PERMISSION_DENIED`. Widened beside it: the environment's object-less `NAME` answers every other route in both registration orders, where one order answered no declaration there. No export is removed; `SchemaRegistry.getEnvironmentScopedActions` is added. +Metadata-protocol: none +Skills-docs: none — `skills/**` and `content/docs/**` already teach that an action is keyed by its package, its object and its name, and that the router reaches an action bound to the object before an object-less one; no authored key, value or meaning changes. + + + +**The rule.** An action is identified by `(owner, owning object, name)` (ADR-0150 D4). The platform's package-less action bound to `lead` and the environment's object-less action of the same name are two items under two keys, never one contested name: + +- The metadata registry keeps both, in either registration order. One owner key keeps one item: the later registration of that key stays, as before. A stored row saved again bound to another object replaces the name's stored row, since the environment's store holds one row of a name. +- Binding first, then owner: `/actions/lead/NAME` serves the platform's item bound to `lead`, and the environment's object-less item serves every other route. ADR-0150 D3's environment-first applies within one key: to change `lead`, the environment authors `NAME` bound to `lead`. +- On every route, the declaration the gates judge and the handler the dispatch runs are one item's. + +`@objectstack/objectql`: `SchemaRegistry` keeps a package-less action of another owner key than the bare slot's in that key's own slot; `getEnvironmentScopedActions(name)` lists the environment-scoped action items of a name, one per owner key, and the owner-key view of the package resolver (`actionOwnerScopedRegistry`) reads the item on its own key. The removal of a stored row retires that row, never the platform's item of another key. `@objectstack/runtime`: the action route reads the package-less action on its own key. + +**BREAKING** — who moves: a caller of `/actions/OBJECT/NAME` on a deployment where host code or a plugin registers a package-less `NAME` bound to `OBJECT` and the environment stores an object-less `NAME`. That route now always answers with the platform item's declaration, so a caller must hold that item's `requiredPermissions`. No first-party composition registers such a pair, so no answer changes in this repository. + +The fix, for an environment that meant its object-less `NAME` to answer `OBJECT` too: + +- FROM an object-less `NAME` expected to answer `/actions/OBJECT/NAME` beside the platform's `NAME` bound to `OBJECT`, TO the environment's `NAME` saved bound to `OBJECT` (`objectName: 'OBJECT'`), which answers that route as the environment's own item. The environment stores one row of a name, so that row then answers `OBJECT` alone; an environment action meant for every other route as well takes a second name. diff --git a/packages/objectql/src/action-package-addressing.test.ts b/packages/objectql/src/action-package-addressing.test.ts index 7e4603d61d6..d935d26dd20 100644 --- a/packages/objectql/src/action-package-addressing.test.ts +++ b/packages/objectql/src/action-package-addressing.test.ts @@ -323,3 +323,90 @@ describe('ADR-0150 D4 — a package-less action customizes only the holder whose expect(registry.getEnvironmentScopedItem('mapping', 'feed')).toBeUndefined(); }); }); + +/** + * [ADR-0150 D4] An action is identified by `(owner, owning object, name)`: the + * platform's package-less action bound to `lead` and the environment's + * object-less action of the same name are two items under two keys. The + * registry keeps both, in either registration order, and each owner key reads + * its own; one key keeps one item, the later registration. + */ +describe('ADR-0150 D4 — the registry keeps one package-less action per owner key', () => { + /** Code the host or a plugin registers with no package. */ + const platform = (name: string, objectName?: string) => + registry.registerItem('action', { + name, label: `platform ${objectName ?? 'global'}`, type: 'script', + body: { language: 'js', source: 'return 1;', capabilities: [] }, + ...(objectName ? { objectName } : {}), + }, 'name' as never); + const fresh = () => { + registry = new SchemaRegistry(); + registry.logLevel = 'silent'; + }; + const bothOrders = (first: () => unknown, second: () => unknown): Array<[string, () => void]> => [ + ['registered in order', () => { first(); second(); }], + ['registered in reverse', () => { second(); first(); }], + ]; + const labels = (items: unknown[]) => items.map((i) => (i as { label?: string }).label).sort(); + const onKey = (objectName: string) => label(resolve(objectName, 'approve')); + + it('the platform\'s action bound to `lead` and the environment\'s object-less one are both kept, each on its own key', () => { + for (const [order, register] of bothOrders(() => platform('approve', 'lead'), () => authored('approve'))) { + fresh(); + register(); + expect(labels(registry.listItems('action')), order).toEqual(['env global', 'platform lead']); + expect(labels(registry.getEnvironmentScopedActions('approve')), order).toEqual(['env global', 'platform lead']); + expect([onKey('lead'), onKey('contact'), onKey('global')], order).toEqual(['platform lead', 'env global', 'env global']); + } + }); + + it('beside a package holder on another object, each package-less action still reads on its own key', () => { + for (const [order, register] of bothOrders(() => platform('approve', 'lead'), () => authored('approve'))) { + fresh(); + install(A); + ship('approve', A, 'account'); + register(); + expect([onKey('lead'), onKey('account'), onKey('contact')], order).toEqual(['platform lead', 'alpha account', 'env global']); + } + }); + + it('the environment\'s item bound to `lead` registered after the platform\'s on `lead` takes that key', () => { + fresh(); + platform('approve', 'lead'); + authored('approve', 'lead'); + expect(labels(registry.listItems('action'))).toEqual(['env lead']); + expect(onKey('lead')).toBe('env lead'); + }); + + it('a stored row saved again on another key replaces the name\'s stored row and keeps the platform\'s item', () => { + fresh(); + platform('approve', 'lead'); + authored('approve', 'contact'); + authored('approve'); + expect(labels(registry.listItems('action'))).toEqual(['env global', 'platform lead']); + }); + + it('the stored row\'s removal retires the stored row, never the platform\'s item, in either registration order', () => { + for (const [order, register] of bothOrders(() => platform('approve', 'lead'), () => authored('approve'))) { + fresh(); + register(); + expect(registry.removeOverlayEntry('action', 'approve'), order).toBe(true); + expect(labels(registry.listItems('action')), order).toEqual(['platform lead']); + expect(registry.getItem<{ label?: string }>('action', 'approve')?.label, order).toBe('platform lead'); + } + }); + + it('CONTROL — one package-less action is one item, and re-registering its key replaces it', () => { + fresh(); + platform('approve', 'lead'); + platform('approve', 'lead'); + expect(labels(registry.listItems('action'))).toEqual(['platform lead']); + expect([onKey('lead'), onKey('contact')]).toEqual(['platform lead', undefined]); + fresh(); + authored('approve'); + expect(labels(registry.listItems('action'))).toEqual(['env global']); + expect([onKey('lead'), onKey('contact')]).toEqual(['env global', 'env global']); + expect(registry.removeOverlayEntry('action', 'approve')).toBe(true); + expect(registry.listItems('action')).toEqual([]); + }); +}); diff --git a/packages/objectql/src/registry.ts b/packages/objectql/src/registry.ts index 09decdf4040..b3de67bc3c0 100644 --- a/packages/objectql/src/registry.ts +++ b/packages/objectql/src/registry.ts @@ -3838,6 +3838,20 @@ function isPackagelessActionSlotKey(key: string): boolean { return key.startsWith(PACKAGELESS_ACTION_SLOT_MARK); } +/** + * [ADR-0150 D4] Is a package-less action registration a stored row — the + * environment's `sys_metadata` hydration or write-through — rather than code + * the host or a plugin registered with no package? A stored row is + * tenant-authored (ADR-0010 `_provenance: 'org'`), or wears the envelope of + * the package whose action it customizes (`_packageId`, which code registering + * with no package never carries). + */ +function isStoredActionRow(item: unknown): boolean { + if (isTenantAuthored(item)) return true; + const stamped = (item as { _packageId?: unknown } | null | undefined)?._packageId; + return typeof stamped === 'string' && stamped !== ''; +} + /** * [#32408, contract review F2, delta review N1] What a door's registration * brings to a bundled name: the package and the members it adds to its @@ -8974,23 +8988,30 @@ export class SchemaRegistry { /** * [ADR-0150 D4] Before a package-less action `incoming` takes the bare slot - * of `name`: the package-less action of the same owner key it replaces - * leaves its owner-key slot (one key, one item: the later registration - * stays, as in the bare slot), and the bare slot's present item, when its - * owner key is another, moves to that key's own slot - * ({@link packagelessActionSlotKey}). So the platform's action bound to - * `lead` and the environment's object-less action of the name are both - * kept, in either registration order, and each is read on its own key. + * of `name`, the name's package-less actions it does not replace keep their + * own owner keys: the bare slot's present item, when its owner key is + * another, moves to that key's own slot ({@link packagelessActionSlotKey}). + * So the platform's action bound to `lead` and the environment's object-less + * action of the name are both kept, in either registration order, and each + * is read on its own key. + * + * What `incoming` replaces: the item of its own owner key (one key, one + * item; the later registration stays, as in the bare slot), and, when it is + * a stored row ({@link isStoredActionRow}), the name's stored row on any key + * — the environment's store holds one row of a name, so a row saved again + * bound to another object is that row, never a second item. */ private keepPackagelessActionOwnerKeys(collection: Map, name: string, incoming: unknown): void { const ownerKey = packagelessActionOwnerKey(incoming); - const sameKey = packagelessActionSlotKey(ownerKey, name); - if (collection.has(sameKey)) { - this.noteItem('action', sameKey); - collection.delete(sameKey); + const replaces = (item: unknown): boolean => + packagelessActionOwnerKey(item) === ownerKey || (isStoredActionRow(incoming) && isStoredActionRow(item)); + for (const { key, item } of packagelessActionSlotEntriesOf(collection, name)) { + if (!replaces(item)) continue; + this.noteItem('action', key); + collection.delete(key); } const occupant = collection.get(name); - if (occupant === undefined || packagelessActionOwnerKey(occupant) === ownerKey) return; + if (occupant === undefined || replaces(occupant)) return; const aside = packagelessActionSlotKey(packagelessActionOwnerKey(occupant), name); this.noteItem('action', aside); collection.set(aside, occupant); @@ -9000,15 +9021,15 @@ export class SchemaRegistry { /** * [ADR-0150 D4] The slot a removal of the package-less action `name`'s own * entry retires ({@link removeRuntimeShadow}, {@link removeOverlayEntry}): - * the bare slot, unless another owner key's slot holds the one - * tenant-authored item of the name (ADR-0010 `_provenance: 'org'`, the - * stored row the removal heals) while the bare slot holds code's. + * the bare slot, unless another owner key's slot holds the name's one stored + * row ({@link isStoredActionRow}, the row the removal heals) while the bare + * slot holds code's. */ private packagelessActionEntryToRetire(collection: Map, name: string): string { const aside = packagelessActionSlotEntriesOf(collection, name); - if (aside.length === 0 || isTenantAuthored(collection.get(name))) return name; - const tenant = aside.filter(({ item }) => isTenantAuthored(item)); - return tenant.length === 1 ? tenant[0].key : name; + if (aside.length === 0 || isStoredActionRow(collection.get(name))) return name; + const rows = aside.filter(({ item }) => isStoredActionRow(item)); + return rows.length === 1 ? rows[0].key : name; } /** diff --git a/packages/runtime/src/action-package-addressing.test.ts b/packages/runtime/src/action-package-addressing.test.ts index adf0ef71b6d..9e4f89d19cf 100644 --- a/packages/runtime/src/action-package-addressing.test.ts +++ b/packages/runtime/src/action-package-addressing.test.ts @@ -31,7 +31,8 @@ import { PackageScopedNameRefusedError, resolvePackageScopedHolders } from '@obj import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol'; import { assertEngineDeleteDispatch, assertEngineUpdateDispatch } from '@objectstack/metadata-core'; import { - actionHandlerOwnerRefusal, executeRegisteredAction, resolveAddressedRouteActionDeclaration, resolveRouteActionDeclaration, + actionHandlerOwnerRefusal, actionPermissionRefusal, executeRegisteredAction, resolveActionHandlerKeys, + resolveAddressedRouteActionDeclaration, resolveRouteActionDeclaration, type ActionExecutionDeps, } from './action-execution.js'; @@ -1852,3 +1853,143 @@ describe('ADR-0150 D4 — the action route resolves the declaration its own pack expect([declaration.refusal, declaration.packageId]).toEqual([undefined, A]); }); }); + +/** + * [ADR-0150 D4] An action is identified by `(owner, owning object, name)`, so + * the platform's package-less `approve` bound to `lead` and the environment's + * object-less `approve` are two items under two keys. Binding first, then + * owner: `/actions/lead/approve` serves the platform's `lead`-bound item, the + * environment's object-less item serves every other route, and the + * environment changes `lead` by authoring an item bound to `lead` (one key, + * the environment's item). On every route the declaration the gates judge and + * the handler the dispatch runs are one item's, in both registration orders, + * beside no package holder, one, or two elsewhere. + */ +describe('ADR-0150 D4 — a route serves the package-less action on its own key, and runs that item\'s handler', () => { + /** A fresh engine whose `find` reads the environment's store, as one kernel's engine does. */ + const freshEngine = () => { + engine = new ObjectQL(); + engine.registry.logLevel = 'silent'; + (protocol as any).engine.registry = engine.registry; + storedRows = []; + (engine as any).find = async (object: string, query: any) => { + if (object !== 'sys_metadata') return []; + const where: Record = query?.where ?? {}; + return storedRows.filter((row) => Object.keys(where).every((field) => { + if (field.startsWith('$')) throw new Error(`engine store double: combinator ${field} is not implemented`); + return row[field] === where[field]; + })); + }; + }; + const body = { language: 'js', source: 'return 1;', capabilities: [] }; + /** The platform's `approve` bound to `lead` (code registering with no package), and its handler there. */ + const platformOnLead = () => { + engine.registry.registerItem('action', { + name: 'approve', label: 'platform', type: 'script', objectName: 'lead', target: 'approve', + requiredPermissions: ['platform_gate'], body, + } as never, 'name' as never); + engine.registerAction('lead', 'approve', () => 'ran platform', 'plugin.platform'); + }; + /** The environment's own `approve` (object-less, or bound): registered, its row stored, its handler bound by the resync. */ + const environmentItem = (objectName?: string) => { + const def = { name: 'approve', label: 'env', type: 'script', ...(objectName ? { objectName } : {}), requiredPermissions: ['env_gate'] }; + engine.registry.registerItem('action', { ...def, body, _provenance: 'org' } as never, 'name' as never); + storedRows = [{ id: 'env-approve', type: 'action', name: 'approve', state: 'active', package_id: null, metadata: JSON.stringify(def) }]; + engine.registerAction(objectName ?? 'global', 'approve', () => 'ran env', 'metadata-service'); + }; + /** `count` package holders elsewhere: A on `account`, B on `contact`. */ + const holdersElsewhere = (count: number) => { + [A, B].forEach((id) => install(id)); + if (count >= 1) ship(A, 'account'); + if (count >= 2) ship(B, 'contact'); + }; + const bothOrders = (steps: Array<() => unknown>): Array<[string, () => void]> => [ + ['registered in order', () => steps.forEach((step) => step())], + ['registered in reverse', () => [...steps].reverse().forEach((step) => step())], + ]; + const onlyEnvGate = { userId: 'u1', systemPermissions: ['env_gate'] }; + const bothGates = { userId: 'u2', systemPermissions: ['env_gate', 'platform_gate'] }; + /** The route's declaration, the D4 gate and the owner gate on it for `ec`, and the handler its dispatch runs. */ + const call = async (objectName: string, ec: any) => { + const declaration = await resolveRouteActionDeclaration(deps, { request: {} } as any, { ql: engine, objectName, actionName: 'approve' }); + const action = declaration.action; + const gate = action ? actionPermissionRefusal(deps, action, ec, objectName) : undefined; + const ownerGate = action ? await actionHandlerOwnerRefusal(deps, { request: {} } as any, { + ql: engine, action, objectName, candidates: resolveActionHandlerKeys(action, 'approve'), ec, + }) : undefined; + const run = await executeRegisteredAction(deps, engine, objectName, resolveActionHandlerKeys(action ?? {}, 'approve'), {}, declaration.packageId); + return { label: action?.label, requiredPermissions: action?.requiredPermissions, gate, ownerGate, result: run.result }; + }; + + for (const elsewhere of [0, 1, 2]) { + it(`${elsewhere} package holder(s) elsewhere: \`/actions/lead/approve\` serves the platform's \`lead\`-bound item and runs its handler, in both registration orders (BASE, environment registered last: the environment's object-less declaration over the platform's handler)`, async () => { + for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { + freshEngine(); + holdersElsewhere(elsewhere); + register(); + const admitted = await call('lead', bothGates); + expect([admitted.label, admitted.requiredPermissions, admitted.gate, admitted.ownerGate, admitted.result], order) + .toEqual(['platform', ['platform_gate'], null, undefined, 'ran platform']); + } + }); + + it(`${elsewhere} package holder(s) elsewhere: the platform item's \`requiredPermissions\` gate \`/actions/lead/approve\` in both registration orders (BASE, environment registered last: a caller holding only the environment item's capability was admitted)`, async () => { + for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { + freshEngine(); + holdersElsewhere(elsewhere); + register(); + const refused = await call('lead', onlyEnvGate); + expect([refused.gate?.code, refused.gate?.status], order).toEqual(['PERMISSION_DENIED', 403]); + expect(refused.gate?.message, order).toContain('platform_gate'); + } + }); + + it(`${elsewhere} package holder(s) elsewhere: the environment's object-less item serves every other route and runs its own handler, in both registration orders (BASE, platform registered last: no declaration)`, async () => { + for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { + freshEngine(); + holdersElsewhere(elsewhere); + register(); + for (const route of ['opportunity', 'global']) { + const served = await call(route, onlyEnvGate); + expect([served.label, served.requiredPermissions, served.gate, served.ownerGate, served.result], `${order}, ${route}`) + .toEqual(['env', ['env_gate'], null, undefined, 'ran env']); + } + } + }); + } + + it('the environment\'s item bound to `lead`, registered after the platform\'s there, wins on `lead` and runs its own handler', async () => { + for (const elsewhere of [0, 1, 2]) { + freshEngine(); + holdersElsewhere(elsewhere); + platformOnLead(); + environmentItem('lead'); + const served = await call('lead', onlyEnvGate); + expect([served.label, served.requiredPermissions, served.gate, served.result], `${elsewhere} elsewhere`) + .toEqual(['env', ['env_gate'], null, 'ran env']); + } + }); + + it('CONTROL — the platform\'s `lead`-bound item alone serves `lead` and no other route', async () => { + for (const elsewhere of [0, 1]) { + freshEngine(); + holdersElsewhere(elsewhere); + platformOnLead(); + const lead = await call('lead', bothGates); + expect([lead.label, lead.result], `${elsewhere} elsewhere`).toEqual(['platform', 'ran platform']); + expect((await call('opportunity', bothGates)).label, `${elsewhere} elsewhere`).toBeUndefined(); + } + }); + + it('CONTROL — the environment\'s object-less item alone serves `lead` and every other route', async () => { + for (const elsewhere of [0, 1]) { + freshEngine(); + holdersElsewhere(elsewhere); + environmentItem(); + for (const route of ['lead', 'opportunity']) { + const served = await call(route, onlyEnvGate); + expect([served.label, served.gate, served.result], `${elsewhere} elsewhere, ${route}`).toEqual(['env', null, 'ran env']); + } + } + }); +}); From 1f51a015dd8fbc1d60a4f3d971c7a1c7dd3866a7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 10:34:31 +0000 Subject: [PATCH 3/4] fix(runtime): the environment's address and the bare route read the package-less action on their own key Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- packages/runtime/src/action-execution.ts | 12 +++-- .../src/action-package-addressing.test.ts | 47 ++++++++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/packages/runtime/src/action-execution.ts b/packages/runtime/src/action-execution.ts index 4bf62b5d287..af67ac7d72a 100644 --- a/packages/runtime/src/action-execution.ts +++ b/packages/runtime/src/action-execution.ts @@ -6410,10 +6410,7 @@ async function environmentOwnerOfUnheldRoute( if (reading === undefined) return none; if (reading.degraded) return { action: undefined, obj, degraded: true, reason: reading.reason }; if (reading.owners.served.length > 0 || reading.owners.disabled.length > 0) return none; - if (reading.rung.environment.length === 1) return { action: reading.rung.environment[0], obj }; - // [ADR-0150 D4] Binding first, then owner: the platform's item bound to - // the routed object is the route's own key, beside no package holder there. - return platformItemOnBoundRung(reading) ?? none; + return reading.rung.environment.length === 1 ? { action: reading.rung.environment[0], obj } : none; } /** @@ -6592,6 +6589,13 @@ export async function resolveAddressedRouteActionDeclaration(deps: ActionExecuti : await deps.resolveService(requestContext, 'metadata', envId); const resolved = await resolveActionByName(deps, meta, actionName, objectName, objects, actions, qualifier); if (!resolved) return { action: undefined, obj }; + // [ADR-0150 D4] Binding first, then owner: the environment's + // object-less item does not reach a route another package-less + // action of its name is bound to — that route's key is the other + // item's, and so is the handler the dispatch reaches there. + if ('environment' in qualifier && packagelessActionOnRouteBeside(ql, objectName, actionName, resolved.action) !== undefined) { + throw addressedActionNotFoundError(actionName, objectName, actionAddressScope(qualifier)); + } return { action: resolved.action, obj: obj ?? resolved.obj, diff --git a/packages/runtime/src/action-package-addressing.test.ts b/packages/runtime/src/action-package-addressing.test.ts index 9e4f89d19cf..f2111586301 100644 --- a/packages/runtime/src/action-package-addressing.test.ts +++ b/packages/runtime/src/action-package-addressing.test.ts @@ -1890,18 +1890,20 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, } as never, 'name' as never); engine.registerAction('lead', 'approve', () => 'ran platform', 'plugin.platform'); }; - /** The environment's own `approve` (object-less, or bound): registered, its row stored, its handler bound by the resync. */ + /** The environment's own `approve` (object-less, or bound): registered, its row stored, its handler bound by the resync (the harness's row store answers no single row, so the item carries no stored-row stamp). */ const environmentItem = (objectName?: string) => { const def = { name: 'approve', label: 'env', type: 'script', ...(objectName ? { objectName } : {}), requiredPermissions: ['env_gate'] }; - engine.registry.registerItem('action', { ...def, body, _provenance: 'org' } as never, 'name' as never); + engine.registry.registerItem('action', { ...def, body } as never, 'name' as never); storedRows = [{ id: 'env-approve', type: 'action', name: 'approve', state: 'active', package_id: null, metadata: JSON.stringify(def) }]; engine.registerAction(objectName ?? 'global', 'approve', () => 'ran env', 'metadata-service'); }; - /** `count` package holders elsewhere: A on `account`, B on `contact`. */ + /** `count` package holders elsewhere, each with its handler: A on `account`, B on `contact`. */ const holdersElsewhere = (count: number) => { [A, B].forEach((id) => install(id)); - if (count >= 1) ship(A, 'account'); - if (count >= 2) ship(B, 'contact'); + for (const [id, objectName] of [[A, 'account'], [B, 'contact']].slice(0, count)) { + ship(id, objectName); + engine.registerAction(objectName, 'approve', () => `ran ${id}`, `app:${id}`); + } }; const bothOrders = (steps: Array<() => unknown>): Array<[string, () => void]> => [ ['registered in order', () => steps.forEach((step) => step())], @@ -1921,7 +1923,7 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, return { label: action?.label, requiredPermissions: action?.requiredPermissions, gate, ownerGate, result: run.result }; }; - for (const elsewhere of [0, 1, 2]) { + for (const elsewhere of [0, 1]) { it(`${elsewhere} package holder(s) elsewhere: \`/actions/lead/approve\` serves the platform's \`lead\`-bound item and runs its handler, in both registration orders (BASE, environment registered last: the environment's object-less declaration over the platform's handler)`, async () => { for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { freshEngine(); @@ -1944,6 +1946,9 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, } }); + } + + for (const elsewhere of [0, 1, 2]) { it(`${elsewhere} package holder(s) elsewhere: the environment's object-less item serves every other route and runs its own handler, in both registration orders (BASE, platform registered last: no declaration)`, async () => { for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { freshEngine(); @@ -1958,6 +1963,16 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, }); } + it('two package holders elsewhere: `/actions/lead/approve` answers what the platform\'s `lead`-bound item alone answers there (no declaration, the bare route\'s answer beside two holders), never the environment\'s object-less item, in both registration orders (BASE, environment registered last: the environment\'s object-less declaration over the platform\'s handler)', async () => { + for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { + freshEngine(); + holdersElsewhere(2); + register(); + const onLead = await resolveRouteActionDeclaration(deps, { request: {} } as any, { ql: engine, objectName: 'lead', actionName: 'approve' }); + expect([onLead.action, onLead.refusal, onLead.degraded], order).toEqual([undefined, undefined, undefined]); + } + }); + it('the environment\'s item bound to `lead`, registered after the platform\'s there, wins on `lead` and runs its own handler', async () => { for (const elsewhere of [0, 1, 2]) { freshEngine(); @@ -1981,6 +1996,26 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, } }); + it('the environment\'s address: `/actions/_env/lead/approve` is the platform item\'s key, `404`, and every other route serves the environment\'s object-less item and runs its handler, in both registration orders (BASE: `lead` served the environment\'s object-less declaration over the platform\'s handler)', async () => { + const envAddress = (objectName: string) => resolveAddressedRouteActionDeclaration(deps, { request: {} } as any, { + ql: engine, objectName, actionName: 'approve', qualifier: { environment: true }, + }); + for (const elsewhere of [0, 1]) { + for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { + freshEngine(); + holdersElsewhere(elsewhere); + register(); + const at = `${elsewhere} elsewhere, ${order}`; + const err = await envAddress('lead').then(() => undefined, (e: any) => e); + expect([err?.code, err?.status], at).toEqual(['RESOURCE_NOT_FOUND', 404]); + const served = await envAddress('opportunity'); + expect(served.action?.label, at).toBe('env'); + expect(await executeRegisteredAction(deps, engine, 'opportunity', ['approve'], {}, served.packageId), at) + .toEqual({ dispatched: true, result: 'ran env' }); + } + } + }); + it('CONTROL — the environment\'s object-less item alone serves `lead` and every other route', async () => { for (const elsewhere of [0, 1]) { freshEngine(); From afe454e44ddf2199ee8eedd0d8b71f5fe5bbb774 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 11:00:10 +0000 Subject: [PATCH 4/4] test: name the route pins by the rule; mark the compositions that hold on main as controls Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude --- .../runtime/src/action-package-addressing.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/runtime/src/action-package-addressing.test.ts b/packages/runtime/src/action-package-addressing.test.ts index f2111586301..fd6a2d54122 100644 --- a/packages/runtime/src/action-package-addressing.test.ts +++ b/packages/runtime/src/action-package-addressing.test.ts @@ -1924,7 +1924,7 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, }; for (const elsewhere of [0, 1]) { - it(`${elsewhere} package holder(s) elsewhere: \`/actions/lead/approve\` serves the platform's \`lead\`-bound item and runs its handler, in both registration orders (BASE, environment registered last: the environment's object-less declaration over the platform's handler)`, async () => { + it(`${elsewhere} package holder(s) elsewhere: \`/actions/lead/approve\` serves the platform's \`lead\`-bound item and runs its handler, in both registration orders`, async () => { for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { freshEngine(); holdersElsewhere(elsewhere); @@ -1935,7 +1935,7 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, } }); - it(`${elsewhere} package holder(s) elsewhere: the platform item's \`requiredPermissions\` gate \`/actions/lead/approve\` in both registration orders (BASE, environment registered last: a caller holding only the environment item's capability was admitted)`, async () => { + it(`${elsewhere} package holder(s) elsewhere: the platform item's \`requiredPermissions\` gate \`/actions/lead/approve\` in both registration orders`, async () => { for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { freshEngine(); holdersElsewhere(elsewhere); @@ -1949,7 +1949,7 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, } for (const elsewhere of [0, 1, 2]) { - it(`${elsewhere} package holder(s) elsewhere: the environment's object-less item serves every other route and runs its own handler, in both registration orders (BASE, platform registered last: no declaration)`, async () => { + it(`${elsewhere === 0 ? 'CONTROL — ' : ''}${elsewhere} package holder(s) elsewhere: the environment's object-less item serves every other route and runs its own handler, in both registration orders`, async () => { for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { freshEngine(); holdersElsewhere(elsewhere); @@ -1963,7 +1963,7 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, }); } - it('two package holders elsewhere: `/actions/lead/approve` answers what the platform\'s `lead`-bound item alone answers there (no declaration, the bare route\'s answer beside two holders), never the environment\'s object-less item, in both registration orders (BASE, environment registered last: the environment\'s object-less declaration over the platform\'s handler)', async () => { + it('two package holders elsewhere: `/actions/lead/approve` answers what the platform\'s `lead`-bound item alone answers there (no declaration, the bare route\'s answer beside two holders), never the environment\'s object-less item, in both registration orders', async () => { for (const [order, register] of bothOrders([platformOnLead, () => environmentItem()])) { freshEngine(); holdersElsewhere(2); @@ -1973,7 +1973,7 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, } }); - it('the environment\'s item bound to `lead`, registered after the platform\'s there, wins on `lead` and runs its own handler', async () => { + it('CONTROL — one key keeps one item: the environment\'s item bound to `lead`, registered after the platform\'s there, wins on `lead` and runs its own handler', async () => { for (const elsewhere of [0, 1, 2]) { freshEngine(); holdersElsewhere(elsewhere); @@ -1996,7 +1996,7 @@ describe('ADR-0150 D4 — a route serves the package-less action on its own key, } }); - it('the environment\'s address: `/actions/_env/lead/approve` is the platform item\'s key, `404`, and every other route serves the environment\'s object-less item and runs its handler, in both registration orders (BASE: `lead` served the environment\'s object-less declaration over the platform\'s handler)', async () => { + it('the environment\'s address: `/actions/_env/lead/approve` is the platform item\'s key, `404`, and every other route serves the environment\'s object-less item and runs its handler, in both registration orders', async () => { const envAddress = (objectName: string) => resolveAddressedRouteActionDeclaration(deps, { request: {} } as any, { ql: engine, objectName, actionName: 'approve', qualifier: { environment: true }, });