Skip to content

Commit 0593356

Browse files
fix(objectql,runtime)!: a package-less action is kept on its own owner key, and a route serves the one on its key (#33821)
Clause-②: no (narrowing) 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. ## 维护者速读 - 改了什么:注册表为无包 action 按「归属对象」各留一格:平台绑定 `lead` 的 action 与环境的无对象 action 同名时两者都保留,不论注册先后;`/actions/lead/NAME` 读绑定 `lead` 的那条,其它路由读环境的无对象那条。 - 为什么改:action 的身份是(归属方、归属对象、名称),同名不同键是两条 action;路由判定所用的声明和派发执行的处理器必须来自同一条。 - 风险与回滚:只动 `action` 类型的无包槽位与 action 路由的选取,单条无包 action 的存储与读法不变(有对照测试);回滚即 revert 本 PR。 - 先看:`packages/objectql/src/registry.ts`(`keepPackagelessActionOwnerKeys` 与移除时的 `packagelessActionEntryToRetire`)、`packages/runtime/src/action-execution.ts`(`packagelessActionOnRouteBeside`)、`packages/runtime/src/action-package-addressing.test.ts` 末尾的新 describe。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run src/action-package-addressing.test.ts -t "own key"`,预期 12 个测试全绿。 - 需要你做的:无,席位落地。 ## What changes 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. Binding first, then owner: `/actions/lead/NAME` serves the platform's item bound to `lead`; the environment's object-less item serves every other route; ADR-0150 D3's environment-first applies within one key, so the environment changes `lead` by authoring `NAME` bound to `lead`. On every route the declaration the gates judge and the handler the dispatch runs are one item's. - `packages/objectql/src/registry.ts`: a package-less action registered over the bare slot keeps the slot's present item when its owner key is another, in that key's own slot (`keepPackagelessActionOwnerKeys`). One key keeps one item, the later registration; a stored row replaces the name's stored row on any key (the environment's store holds one row of a name). The bare-slot readers (`bareSlotEntriesOf`, `boundServedActions`) see each key's item; the removal of a stored row retires that row, never the platform's item of another key, and the next key's item takes the bare slot. New `getEnvironmentScopedActions(name)`: the environment-scoped action items of a name, one per owner key. - `packages/objectql/src/action-package-addressing.ts`, `package-scoped-resolver.ts`: the owner-key view (`actionOwnerScopedRegistry`) reads the environment-scoped action on its own key; `PackageScopedRegistry` gains the optional `getEnvironmentScopedActions`. - `packages/runtime/src/action-execution.ts`: the bare route takes the package-less action on its own key, bound first, then object-less (`packagelessActionOnRouteBeside`), where the by-name read answered another key's; beside one package holder the platform's item alone on the bound rung is served (`platformItemOnBoundRung`); the environment address `/actions/_env/OBJECT/NAME` answers `404` where another package-less action of the name is bound to `OBJECT`. - Not changed: one package-less action of a name (stored and read as before); beside two package holders elsewhere, `/actions/lead/NAME` answers what the platform's `lead`-bound item alone answers there (no declaration); the caller-package route; the stored-row (`sys_metadata`) model. ## Tests - `packages/objectql/src/action-package-addressing.test.ts`, new top-level describe "the registry keeps one package-less action per owner key": 6 cases (4 pins, 1 one-key pin that holds on main, 1 control). - `packages/runtime/src/action-package-addressing.test.ts`, new top-level describe "a route serves the package-less action on its own key, and runs that item's handler": 12 cases — `lead` serves the platform's item and runs its handler, and its `requiredPermissions` gate `lead` (`403 PERMISSION_DENIED`), each in both registration orders beside 0 and 1 package holders; the environment's object-less item serves every other route in both orders beside 0, 1 and 2 holders (the 0-holder case a control); beside 2 holders `lead` answers no declaration; the environment address; controls: one key keeps one item, each package-less item alone. ## Acceptance notes - Ablations, one per guard, each through `scripts/ablation-replace.mjs` (anchor 1 to 0, blob changed), restored to the HEAD blob with `git diff HEAD` empty: - registry keep (objectql rebuilt; `ablation-dist-preflight` marker absent from 8 built files, present in 4 after the restore build): objectql 4 red / 2 green (the one-key pin and the control), runtime 8 red / 4 green (the controls and the one-key pin). - the bare route's own-key pick: runtime 2 red (`lead`, 0 holders), 10 green. - the bound-rung platform pick: runtime 2 red (`lead`, 1 holder), 10 green. - the environment address: runtime 1 red, 11 green. - Two existing pins on the two-holder route (`[#32751]`, and `case 2` of `[#32365]`) keep their answers; the change is scoped so they hold. - Overlap: PR #33621 edited `packages/objectql/src/registry.ts` in the object-extension follow area; it has merged and this branch carries it; no hunk is shared. None of the 55 open pull requests read before the open touches the seven files of this diff. ## Verification All readings on head `8f2c22d91d` (after merging `origin/main`) unless named. <details><summary>Package suites and typechecks</summary> ```text @objectstack/objectql test Test Files 596 passed (596) · Tests 13142 passed (13142) @objectstack/runtime test Test Files 603 passed (603) · Tests 10918 passed | 19 skipped (10937) objectql + runtime typecheck tsc --noEmit clean · check:test-typecheck OK for both @objectstack/spec check:generated All 14 generated artifacts are up to date before the merge (1f51a01) objectql 596/596 · 13116 passed; runtime 603/603 · 10886 passed | 19 skipped ``` </details> <details><summary>Derived gate families (dispatch-gates --commands, reconciled with --ran)</summary> ```text head 8f2c22d · 73 derived, 72 exit 0, 1 NOT MEASURED NOT MEASURED: pnpm check:dual-build-cjs-loads, reason: exit 3 PREREQUISITE NOT MET (reads every package's dist/; this tree built the runtime closure only); CI's Lint & Repo Gates run measures it dispatch-gates --ran: 73 derived famil(ies) accounted for — 72 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3) ``` </details> <details><summary>Dogfood battery</summary> ```text 8f2c22d · os-verify-lock VERDICT command-exit 0 pnpm --workspace-concurrency=2 --filter '@objectstack/dogfood^...' build && pnpm --filter @objectstack/dogfood test Test Files 467 passed | 3 skipped (470) Tests 3958 passed | 42 skipped (4000) no failures ``` </details> --- _Generated by [Claude Code](https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f)_ <!-- signed: security#1 · sunhaolin · session_017xRBcT1w3zpekijraHJE4f --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent b8ac0e2 commit 0593356

7 files changed

Lines changed: 550 additions & 9 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
'@objectstack/objectql': patch
3+
'@objectstack/runtime': patch
4+
---
5+
6+
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)
7+
8+
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.
9+
Metadata-protocol: none
10+
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.
11+
12+
<!-- adr-0087: not-required (no-migration-prescription) No key of any authorable schema is added, removed, renamed or re-shaped and no stored row changes: what moves is which of two registered items a route reads, so there is nothing for `objectstack migrate meta` to rewrite. -->
13+
14+
**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:
15+
16+
- 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.
17+
- 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`.
18+
- On every route, the declaration the gates judge and the handler the dispatch runs are one item's.
19+
20+
`@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.
21+
22+
**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.
23+
24+
The fix, for an environment that meant its object-less `NAME` to answer `OBJECT` too:
25+
26+
- 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.

‎packages/objectql/src/action-package-addressing.test.ts‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,90 @@ describe('ADR-0150 D4 — a package-less action customizes only the holder whose
323323
expect(registry.getEnvironmentScopedItem('mapping', 'feed')).toBeUndefined();
324324
});
325325
});
326+
327+
/**
328+
* [ADR-0150 D4] An action is identified by `(owner, owning object, name)`: the
329+
* platform's package-less action bound to `lead` and the environment's
330+
* object-less action of the same name are two items under two keys. The
331+
* registry keeps both, in either registration order, and each owner key reads
332+
* its own; one key keeps one item, the later registration.
333+
*/
334+
describe('ADR-0150 D4 — the registry keeps one package-less action per owner key', () => {
335+
/** Code the host or a plugin registers with no package. */
336+
const platform = (name: string, objectName?: string) =>
337+
registry.registerItem('action', {
338+
name, label: `platform ${objectName ?? 'global'}`, type: 'script',
339+
body: { language: 'js', source: 'return 1;', capabilities: [] },
340+
...(objectName ? { objectName } : {}),
341+
}, 'name' as never);
342+
const fresh = () => {
343+
registry = new SchemaRegistry();
344+
registry.logLevel = 'silent';
345+
};
346+
const bothOrders = (first: () => unknown, second: () => unknown): Array<[string, () => void]> => [
347+
['registered in order', () => { first(); second(); }],
348+
['registered in reverse', () => { second(); first(); }],
349+
];
350+
const labels = (items: unknown[]) => items.map((i) => (i as { label?: string }).label).sort();
351+
const onKey = (objectName: string) => label(resolve(objectName, 'approve'));
352+
353+
it('the platform\'s action bound to `lead` and the environment\'s object-less one are both kept, each on its own key', () => {
354+
for (const [order, register] of bothOrders(() => platform('approve', 'lead'), () => authored('approve'))) {
355+
fresh();
356+
register();
357+
expect(labels(registry.listItems('action')), order).toEqual(['env global', 'platform lead']);
358+
expect(labels(registry.getEnvironmentScopedActions('approve')), order).toEqual(['env global', 'platform lead']);
359+
expect([onKey('lead'), onKey('contact'), onKey('global')], order).toEqual(['platform lead', 'env global', 'env global']);
360+
}
361+
});
362+
363+
it('beside a package holder on another object, each package-less action still reads on its own key', () => {
364+
for (const [order, register] of bothOrders(() => platform('approve', 'lead'), () => authored('approve'))) {
365+
fresh();
366+
install(A);
367+
ship('approve', A, 'account');
368+
register();
369+
expect([onKey('lead'), onKey('account'), onKey('contact')], order).toEqual(['platform lead', 'alpha account', 'env global']);
370+
}
371+
});
372+
373+
it('the environment\'s item bound to `lead` registered after the platform\'s on `lead` takes that key', () => {
374+
fresh();
375+
platform('approve', 'lead');
376+
authored('approve', 'lead');
377+
expect(labels(registry.listItems('action'))).toEqual(['env lead']);
378+
expect(onKey('lead')).toBe('env lead');
379+
});
380+
381+
it('a stored row saved again on another key replaces the name\'s stored row and keeps the platform\'s item', () => {
382+
fresh();
383+
platform('approve', 'lead');
384+
authored('approve', 'contact');
385+
authored('approve');
386+
expect(labels(registry.listItems('action'))).toEqual(['env global', 'platform lead']);
387+
});
388+
389+
it('the stored row\'s removal retires the stored row, never the platform\'s item, in either registration order', () => {
390+
for (const [order, register] of bothOrders(() => platform('approve', 'lead'), () => authored('approve'))) {
391+
fresh();
392+
register();
393+
expect(registry.removeOverlayEntry('action', 'approve'), order).toBe(true);
394+
expect(labels(registry.listItems('action')), order).toEqual(['platform lead']);
395+
expect(registry.getItem<{ label?: string }>('action', 'approve')?.label, order).toBe('platform lead');
396+
}
397+
});
398+
399+
it('CONTROL — one package-less action is one item, and re-registering its key replaces it', () => {
400+
fresh();
401+
platform('approve', 'lead');
402+
platform('approve', 'lead');
403+
expect(labels(registry.listItems('action'))).toEqual(['platform lead']);
404+
expect([onKey('lead'), onKey('contact')]).toEqual(['platform lead', undefined]);
405+
fresh();
406+
authored('approve');
407+
expect(labels(registry.listItems('action'))).toEqual(['env global']);
408+
expect([onKey('lead'), onKey('contact')]).toEqual(['env global', 'env global']);
409+
expect(registry.removeOverlayEntry('action', 'approve')).toBe(true);
410+
expect(registry.listItems('action')).toEqual([]);
411+
});
412+
});

‎packages/objectql/src/action-package-addressing.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,20 @@ export function actionOwnerScopedRegistry(registry: PackageScopedRegistry, owner
6262
const item = registry.getPackageScopedItem<T>(type, name, packageId, member);
6363
return type !== 'action' || owns(item) ? item : undefined;
6464
},
65+
// [ADR-0150 D4] The environment-scoped action ON this owner key: a
66+
// registry that keeps one package-less action per owner key
67+
// (`getEnvironmentScopedActions`) is asked for every one of them, never
68+
// only the bare slot's, which may sit on another key.
6569
getEnvironmentScopedItem: <T>(type: string, name: string, member?: string) => {
70+
if (type === 'action' && typeof registry.getEnvironmentScopedActions === 'function') {
71+
return registry.getEnvironmentScopedActions<T>(name).find(owns);
72+
}
6673
const item = registry.getEnvironmentScopedItem<T>(type, name, member);
6774
return type !== 'action' || owns(item) ? item : undefined;
6875
},
76+
...(typeof registry.getEnvironmentScopedActions === 'function'
77+
? { getEnvironmentScopedActions: <T>(name: string) => registry.getEnvironmentScopedActions!<T>(name).filter(owns) }
78+
: {}),
6979
};
7080
}
7181

‎packages/objectql/src/package-scoped-resolver.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,16 @@ export interface PackageScopedQuery extends PackageScopedHoldersQuery {
118118
readonly includeDisabledPackages?: boolean;
119119
}
120120

121-
/** The registry slice the registry adapter reads — every member of it, and no other. */
121+
/**
122+
* The registry slice the registry adapter reads — every member of it, and no other.
123+
* [ADR-0150 D4] `getEnvironmentScopedActions`, where a registry has it, is the
124+
* environment-scoped `action` items of a name, one per owner key: the
125+
* owner-key view (`actionOwnerScopedRegistry`) reads the item on its own key.
126+
*/
122127
export type PackageScopedRegistry = Pick<
123128
SchemaRegistry,
124129
'getPackage' | 'getAllPackages' | 'packageScopedHoldersOf' | 'getPackageScopedItem' | 'getEnvironmentScopedItem'
125-
>;
130+
> & Partial<Pick<SchemaRegistry, 'getEnvironmentScopedActions'>>;
126131

127132
/**
128133
* Resolve a bare name by ADR-0150 D3 over the registry's holders: the rule

0 commit comments

Comments
 (0)