Skip to content

Commit a752057

Browse files
fix(runtime)!: an action authored in the environment on a packaged object is the environment's, so MCP list_actions lists it once and its face runs (#33071)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DSjp6ipSHAQH44qGrSqV3mJ)_ Fixes #33029 Clause-②: yes (narrowing) Metadata-protocol: none Skills-docs: none — the docs already state the rule this change makes true: `content/docs/api/client-sdk.mdx` (Addressing an item by its package) says a namespace names the holding package and `'_env'` names an item authored in the environment, which no package holds; no skill teaches calling an environment action under a package's namespace. ## 维护者速读 - **改了什么**:管理员在环境里(不带 `?package=`)给某个包自带的对象写的动作,现在算「环境自己的动作」。AI 助手(MCP)的动作列表只列它一次、不挂包的命名空间,按列表给的名字(`对象-动作`)就能运行。 - **为什么改**:之前同一个动作被列两次,其中一次错挂在 showcase 包名下;列表给的运行名被判「两个动作共用」而拒绝,AI 按列表去运行会 404。 - **风险与回滚**:三处收窄(席位已按方向 A 裁定):① ② 用「那个包的命名空间」去点名这个环境动作,MCP 和 REST 带命名空间的地址现在回 404,以前能跑,改用列表名、裸名或 `/actions/_env/...` 即可;③ 这种环境动作如果是流程动作、目标流程名又被两个包同时持有,现在回 409 并列出两个包,以前默认跑对象所在包的那个流程,改法是用 `?package=` 把动作绑到一个可写包(该包自己的流程,或它唯一依赖的那个包的流程就是想要的那个),或换一个只有一个包持有的流程名。回滚就是 revert 这个 PR,运行时只改一个文件。 - **先看**:`packages/runtime/src/action-execution.ts` 的 `embeddedActionPackageOf`(新函数,6 行)及它在 `collectActionDeclarations`、`actionDeclaringPackage` 的两处调用;再看 `packages/qa/dogfood/test/mcp-list-actions-environment-authored-holder.dogfood.test.ts` 的收窄钉子(两个 404、一个 409)。 - **两分钟验证**:`pnpm --filter @objectstack/dogfood exec vitest run test/mcp-list-actions-environment-authored-holder.dogfood.test.ts`,预期 8 条全过;「naming `showcase` … answer 404」和「… refused 409 naming both」两条就是收窄面。 - **需要你做的**:确认这处收窄可以随下一个版本发出(带 BREAKING 说明),然后由席位落地。 ## What changes The protocol's merged listings, which the MCP bridge reads, serve an action an administrator saved with no `?package=` twice: once in the `action` listing, with no package, and once inside the served object's `actions` in the `object` listing, where the registry attaches it (`attachBoundActions`, #28356) by reference, unstamped and tenant-authored (`_provenance: 'org'`). `collectActionDeclarations` filed every unstamped embedded action under the object's package, so the ADR-0150 D4 dedupe, keyed on the holder, kept both copies. `embeddedActionPackageOf` (new, `packages/runtime/src/action-execution.ts`) is the one rule for an embedded action's holder: its own stamp; else, when it is tenant-authored (`isTenantAuthored`, `@objectstack/metadata-core`, the registry's own test), no package; else the object's. The collector and `actionDeclaringPackage` both read it. Narrowing, measured and ruled by the seat (direction A, the holder fixed in resolution, not a list-only dedupe), in three places: 1. MCP `run_action` with `namespace` set to the object's package answers `RESOURCE_NOT_FOUND` (404) for such an action. It ran it before, because the embedded copy was filed under that package. 2. `POST /actions/NAMESPACE/OBJECT/NAME` with that namespace answers the same 404. 3. (Contract review 6847350544, M1.) A flow action of that kind whose `target` flow name two packages hold answers `RESOURCE_CONFLICT` (409) naming both, on its face, its bare name and `_env`. The action has no package (ADR-0150 D3), so `actionDeclaringPackage` gives the flow arm no caller package and the target is read by the no-package rule. Before, it ran the object's package's flow. The caller's fix: bind the action with `?package=` to a writable package whose own flow, or whose one dependency's flow, is meant, or target a flow name one package holds. `list_actions` lists that row without `params`, and `resume_run` no longer admits it for a paused run of either package's flow, by the same reading. A flow target ONE package holds is unchanged (pinned). The changeset carries the BREAKING banner, the FROM → TO for all three, and the ADR-0087 disposition. ## Tests `packages/qa/dogfood/test/mcp-list-actions-environment-authored-holder.dogfood.test.ts` (new, isolated): the stock showcase with `MCPServerPlugin`, an admin session, the live MCP transport and the REST actions door. - The card's shape: one row, no namespace, face `showcase_task-qa_env_authored_action`, no refused face; `run_action` runs it by that face. - The narrowing: `namespace: 'showcase'` on MCP and `/actions/showcase/...` on REST answer 404. - CONTROL: the bare name and `/actions/_env/...` still run it. - CONTROL: an environment-authored flow action whose `target` names a showcase-shipped flow (`showcase_recalc_task_estimate`, one holder) by bare name runs on REST and MCP, before and after (measured by the ablation below: at base it failed only at the listing assertion, after both runs passed). - The third narrowing: the derived showcase also ships `qa_shared_flow`, and a second code package (`com.example.qatwin`, namespace `qatwin`, booted with `AppPlugin`) ships the same name. An environment-authored flow action targeting it is refused 409 `RESOURCE_CONFLICT` naming both packages on the bare REST route, `/actions/_env/...` and the MCP face. (A Studio-created package cannot author that twin: the metadata door seals a name a managed package holds, 403.) - CONTROL: a package-shipped action on the same object (`showcase_mark_done`, made AI-exposed in a derived configuration) lists once under `showcase` and runs by its face. - CONTROL: an action authored with `?package=` (a Studio-created package that depends on the showcase) lists once under its namespace and runs by it. ## Acceptance notes - Measured how each kind arrives (reading before the fix, stock showcase at 64c426a): the package-shipped action arrives embedded unstamped and standalone stamped `com.example.showcase`; the `?package=` action arrives stamped with its package in both places; the environment's action arrives standalone with no package and embedded unstamped with `_provenance: 'org'`. Nothing is dropped: the embedded copy of every kind is still collected. - `?package=com.example.showcase` is refused 422 (`WRITABLE_PACKAGE_REQUIRED`, the package is read-only), so the `?package=` control uses a Studio-created package. - Not measured: an action an administrator writes INLINE in an overlay of a packaged object's body (`PUT /meta/object/...` with `actions`). Such an action carries no per-action provenance, so it is still filed under the object's package. Noted, not filed. - `packagelessOriginOf` classes the surviving embedded row by the store's `embedded` set (actions of package-less OBJECT rows), so beside another holder it reads as the platform's; on an object-bound key the first declaration still answers, so nothing moves today (contract review nit). Left as is: no answer depends on it. - The `#32437` one-row-per-bound-object pin (`packages/mcp/src/mcp-action-tools.test.ts`) stays green: 25/25. ## Verification Package tests, lint and the full dogfood run read head `a5bdc1d4` (origin/main `64c426ab` merged). Head `dc67e074` adds the third narrowing's pin, two docblocks and the changeset text, and changes no executed runtime line. Head `c4c1aa31` changes text only (the caller's fix for the third narrowing, delta review S2). On it: the new dogfood file 8/8, both ablations above, and the derived gates re-run. <details><summary>Package tests and typecheck</summary> - `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2`: Test Files 600 passed (600), Tests 11916 passed, 19 skipped. Lock verdict `command-exit 0`. - `pnpm --filter @objectstack/runtime typecheck`: exit 0. - `pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2 src/mcp-action-tools.test.ts` (the #32437 pins): 25 passed. - The new dogfood file: 8 passed at `dc67e074`. </details> <details><summary>Ablations (two, each committed first, each rebuilt and proven in dist)</summary> Each leg: `scripts/ablation-replace.mjs` (anchor hit, blob moved), `pnpm --filter @objectstack/runtime build`, `ablation-dist-preflight.mjs` found the marker in `dist/index.js` and `dist/index.cjs`; restored to HEAD (`git diff HEAD` empty), rebuilt, `--absent` preflight clean. 1. The whole rule (`embeddedActionPackageOf` back to the object's package, marker `ABLATE_33029`, head `dc67e074`): 5 failed, 3 passed. Red: the one-row listing, the face run, the two 404s, the one-holder flow control (at its listing assertion, after both of its runs passed, so that target runs at base too), and the two-holder 409. Green, as controls should be: the bare and `_env` runs, the package-shipped action, the `?package=` action. 2. The `actionDeclaringPackage` hunk ALONE (its call back to the object's package, collector fix kept, marker `ABLATE_ADP_33029`): 1 failed, 7 passed. Red: the two-holder 409 pin; the bare REST route answered 200 running `showcase shared flow`, the object's package's flow, which is the BASE behaviour of the third narrowing. </details> <details><summary>Derived gates and lint</summary> - `node scripts/pm/dispatch-gates.mjs --commands` at `dc67e074`: 70 families, all run with exit codes recorded; `--ran` reconciliation: 68 run, 2 NOT MEASURED (exit 3, prerequisite): `check-plugin-teardown-shape --self-test` (needs an unshallow clone) and `check:dual-build-cjs-loads` (needs a whole-tree build). CI runs both. (At `a5bdc1d4`: 67 run, `check:type-check-debt` also exit 3 then, waiting on the verify lock; exit 0 now.) - `check-adr-0087-registration --base origin/main`: exit 0. `check-changeset-no-major --base origin/main`: exit 0. - `pnpm lint`: exit 0. </details> <details><summary>Full dogfood (owed by the narrowing arm)</summary> `pnpm --filter @objectstack/dogfood test` at head `a5bdc1d4`, under the verify lock: Test Files 459 passed, 3 skipped (462); Tests 3851 passed, 42 skipped (3893); lock verdict `command-exit 0`. Not re-run at `dc67e074`, whose runtime change is docblocks only. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4czLj1eeZBYHELaRH6v)_ <!-- signed: domain:server#8 · os-elon-musk · session_016WV4czLj1eeZBYHELaRH6v --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 181ad7d commit a752057

3 files changed

Lines changed: 279 additions & 6 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime)!: an action authored in the environment and bound to an object a package ships is the environment's action, listed once by MCP `list_actions` with no namespace and run by its face
6+
7+
Clause-②: yes (narrowing)
8+
Metadata-protocol: none
9+
10+
BREAKING, in three places, for an action the environment authored (no `?package=`) on an object a package ships:
11+
12+
1. MCP `run_action` with that package's `namespace` answers `RESOURCE_NOT_FOUND` (404) for such an action, as it does for any name that package does not hold. Before, it ran it.
13+
2. `POST /actions/NAMESPACE/OBJECT/NAME` with that package's namespace answers the same 404. Before, it ran it.
14+
3. A flow action of that kind whose `target` flow name TWO packages hold answers `RESOURCE_CONFLICT` (409) naming both holders, on its face, its bare name and `/actions/_env/OBJECT/NAME`. The action has no package (ADR-0150 D3), so its target is read by the no-package rule. Before, it was the object's package's action and ran that package's flow.
15+
16+
- FROM (1, 2): `run_action { actionName: NAME, objectName: OBJECT, namespace: PACKAGE_NAMESPACE }`, or `POST /actions/PACKAGE_NAMESPACE/OBJECT/NAME`.
17+
- TO (1, 2): the face `list_actions` lists for it (`OBJECT-NAME`), the bare name with its `objectName`, or `POST /actions/_env/OBJECT/NAME`.
18+
- FROM (3): an environment-authored flow action on a packaged object whose `target` names a flow two packages hold.
19+
- TO (3): bind the action with `?package=` to a writable package whose own flow, or whose one dependency's flow, is meant, or point its `target` at a flow name one package holds.
20+
21+
The protocol's merged listings serve an action an administrator saved with no `?package=` twice: on its own in the `action` listing, and inside the served object's `actions` in the `object` listing, where the registry attaches it. Neither copy carries a package. The action collector filed it under the package that ships the object, so the ADR-0150 D4 dedupe, which keys on the holder, kept both copies. `list_actions` then listed the action twice, once under a namespace that never shipped it, and refused its face `OBJECT-NAME` as derived for two actions, so `run_action` on that face answered 404.
22+
23+
A copy found inside an object's `actions` that carries no package stamp and is tenant-authored (`_provenance: 'org'`) is now filed under no package, in the collector and in `actionDeclaringPackage`. It lists once, with no namespace, and its face runs it. Unchanged: an action a package ships on its own object lists once under that package's namespace; an action authored with `?package=` lists once under that package's namespace; the environment's action still runs by its bare name and at `/actions/_env/OBJECT/NAME`; a flow action of that kind whose target flow name ONE package holds still runs that flow.
24+
25+
<!-- adr-0087: not-required (no-migration-prescription) no key, export, field or stored body changes; the refusals are of an address that named a package which never held the action, and of a flow target two packages hold read for a caller with no package; the caller's fix is to call the environment's action by its face, its bare name or the _env address, or to bind the action or its target to one package, which no conversion can choose for them -->
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// [#33029] An action an administrator authors in the environment (no
4+
// `?package=`) bound to an object a package ships is the ENVIRONMENT's action:
5+
// MCP `list_actions` lists it once, with no namespace, and `run_action` runs
6+
// it by the face that row carries.
7+
//
8+
// ## What was measured (stock showcase, admin session, live MCP transport)
9+
//
10+
// The registry serves the stored action INSIDE `showcase_task.actions`
11+
// (`attachBoundActions`, #28356) — by reference, unstamped, carrying the
12+
// tenant provenance `_provenance: 'org'` — and the standalone listing serves it
13+
// once more with no package. The action collector filed the embedded copy
14+
// under the OBJECT's package (`com.example.showcase`), so the ADR-0150 D4
15+
// dedupe, keyed on the holder, kept both: two rows (one under `showcase`), the
16+
// face `showcase_task-qa_env_authored_action` refused as derived for two
17+
// actions, and a run by that face answered 404. Naming `showcase` — a package
18+
// that never shipped the action — ran it, on MCP and on the addressed REST
19+
// door; it is now refused there, the narrowing this change declares.
20+
//
21+
// ## The controls
22+
//
23+
// - A package-shipped action on the same object (`showcase_mark_done`, made
24+
// AI-exposed in a derived configuration) arrives embedded AND standalone
25+
// stamped with its package: listed once, under `showcase`.
26+
// - An action authored with `?package=` (a Studio-created package that
27+
// depends on the showcase; the showcase itself is read-only) arrives
28+
// stamped with that package: listed once, under its namespace.
29+
// - An environment-authored FLOW action whose `target` names a flow the
30+
// showcase ships, by bare name, runs on both doors: a name ONE package
31+
// holds resolves the same for every caller.
32+
//
33+
// ## The third narrowed place (contract review 6847350544, M1)
34+
//
35+
// The environment's action has no package (ADR-0150 D3), so the flow its
36+
// `target` names is read by the no-package rule. Where TWO packages hold that
37+
// flow name — the showcase (a derived configuration ships `qa_shared_flow`)
38+
// and a second code package in its own namespace (`qatwin`) — the call is
39+
// refused 409 naming both, on the face, the bare name and `_env`. Before, the
40+
// action was the object's package's, and ran that package's flow. The fix for
41+
// a caller: bind the action with `?package=` to a writable package whose own
42+
// flow, or whose one dependency's flow, is meant (a code package is read-only,
43+
// 422), or target a flow name one package holds.
44+
//
45+
// The file is ISOLATED: it writes `/meta` and creates a package.
46+
47+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
48+
import { type VerifyStack } from '@objectstack/verify';
49+
import { MCPServerPlugin } from '@objectstack/mcp';
50+
import { AppPlugin } from '@objectstack/runtime';
51+
import { defineStack } from '@objectstack/spec';
52+
import showcaseStack from '@objectstack/example-showcase';
53+
import { bootShowcase } from './showcase-boot.js';
54+
55+
const OBJECT = 'showcase_task';
56+
const ENV_ACTION = 'qa_env_authored_action';
57+
const ENV_FLOW_ACTION = 'qa_env_authored_flow_action';
58+
const SHIPPED_FLOW = 'showcase_recalc_task_estimate';
59+
const PKG_ACTION = 'qa_package_authored_action';
60+
const SHARED_FLOW = 'qa_shared_flow';
61+
const ENV_SHARED_FLOW_ACTION = 'qa_env_shared_flow_action';
62+
const SHIPPED = 'showcase_mark_done';
63+
const QA_PACKAGE = 'com.example.qaholder';
64+
const QA_NAMESPACE = 'qaholder';
65+
/** A second code package, in its own namespace, shipping a flow of the name the derived showcase ships. */
66+
const TWIN_PACKAGE = 'com.example.qatwin';
67+
68+
/** The showcase with its shipped `showcase_mark_done` exposed to AI, in both places a stack carries it. */
69+
const SHIPPED_AI = { exposed: true, description: 'Mark the task done and its progress complete, for the listing pins.' };
70+
const exposeShipped = (a: any) => (a?.name === SHIPPED ? { ...a, ai: SHIPPED_AI } : a);
71+
const sharedFlow = (holder: string) => ({
72+
name: SHARED_FLOW, label: `${holder} shared flow`, type: 'autolaunched', status: 'active',
73+
nodes: [{ id: 'start', type: 'start', label: `${holder} start` }, { id: 'end', type: 'end', label: 'End' }],
74+
edges: [{ id: 'e1', source: 'start', target: 'end' }],
75+
});
76+
const twinStack = defineStack({
77+
manifest: { id: TWIN_PACKAGE, namespace: 'qatwin', name: 'qa_twin', version: '1.0.0', type: 'app' },
78+
flows: [sharedFlow('qatwin')],
79+
} as never);
80+
const base: any = showcaseStack;
81+
const derived = {
82+
...base,
83+
flows: [...(base.flows ?? []), sharedFlow('showcase')],
84+
actions: (base.actions ?? []).map(exposeShipped),
85+
objects: (base.objects ?? []).map((o: any) => (o?.name === OBJECT ? { ...o, actions: (o.actions ?? []).map(exposeShipped) } : o)),
86+
};
87+
88+
const ai = (what: string) => ({ exposed: true, description: `${what}, for the listing pins of the environment-authored action card.` });
89+
const authored = (name: string, progress: number) => ({
90+
name, label: name, objectName: OBJECT, operation: 'update', patch: { progress }, execution: 'perRecord',
91+
ai: ai(`Set the task progress to ${progress} percent`),
92+
});
93+
94+
describe('[#33029] list_actions files an environment-authored action on a packaged object under the environment', () => {
95+
let stack: VerifyStack;
96+
let admin: string;
97+
let recordId: string;
98+
let rows: any[];
99+
let refusedFaces: Array<{ face: string }>;
100+
101+
const tool = async (name: string, args: Record<string, unknown>) => {
102+
const res = await stack.api('/mcp', {
103+
method: 'POST',
104+
headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/event-stream', Authorization: `Bearer ${admin}` },
105+
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name, arguments: args } }),
106+
});
107+
expect(res.status).toBe(200);
108+
const rpc: any = await res.json();
109+
expect(rpc.error, JSON.stringify(rpc.error)).toBeUndefined();
110+
const text = String(rpc.result?.content?.[0]?.text ?? '');
111+
let payload: any;
112+
try { payload = JSON.parse(text); } catch { payload = { message: text }; }
113+
return { isError: rpc.result?.isError === true, payload, text };
114+
};
115+
const rowsNamed = (name: string) => rows.filter((a) => a.objectName === OBJECT && a.name === name);
116+
117+
beforeAll(async () => {
118+
stack = await bootShowcase({ extraPlugins: [new AppPlugin(twinStack as never), new MCPServerPlugin()] }, derived);
119+
admin = await stack.signIn();
120+
const ql: any = await stack.kernel.getServiceAsync('objectql');
121+
const found: any = await ql.find(OBJECT, { limit: 1 }, { context: { isSystem: true } });
122+
recordId = (Array.isArray(found) ? found : found?.records ?? [])[0]?.id;
123+
expect(recordId, 'the showcase seeds a task').toBeTruthy();
124+
125+
const env = await stack.apiAs(admin, 'PUT', `/meta/action/${ENV_ACTION}`, authored(ENV_ACTION, 50));
126+
expect(env.status, await env.clone().text()).toBe(200);
127+
const flow = await stack.apiAs(admin, 'PUT', `/meta/action/${ENV_FLOW_ACTION}`, {
128+
name: ENV_FLOW_ACTION, label: ENV_FLOW_ACTION, objectName: OBJECT, type: 'flow', target: SHIPPED_FLOW,
129+
ai: ai('Recalculate the task estimate through the showcase flow'),
130+
});
131+
expect(flow.status, await flow.clone().text()).toBe(200);
132+
const created = await stack.apiAs(admin, 'POST', '/packages', {
133+
manifest: {
134+
id: QA_PACKAGE, name: 'QA holder', version: '0.1.0', type: 'app', namespace: QA_NAMESPACE,
135+
dependencies: { 'com.example.showcase': '*' },
136+
},
137+
});
138+
expect(created.status, await created.clone().text()).toBe(201);
139+
const pkg = await stack.apiAs(admin, 'PUT', `/meta/action/${PKG_ACTION}?package=${QA_PACKAGE}`, authored(PKG_ACTION, 40));
140+
expect(pkg.status, await pkg.clone().text()).toBe(200);
141+
const shared = await stack.apiAs(admin, 'PUT', `/meta/action/${ENV_SHARED_FLOW_ACTION}`, {
142+
name: ENV_SHARED_FLOW_ACTION, label: ENV_SHARED_FLOW_ACTION, objectName: OBJECT, type: 'flow', target: SHARED_FLOW,
143+
ai: ai('Run the flow of the shared name'),
144+
});
145+
expect(shared.status, await shared.clone().text()).toBe(200);
146+
147+
const listed = await tool('list_actions', {});
148+
expect(listed.isError, listed.text).toBe(false);
149+
rows = listed.payload.actions ?? [];
150+
refusedFaces = listed.payload.refusedFaces ?? [];
151+
}, 120_000);
152+
153+
afterAll(async () => { await stack?.stop(); });
154+
155+
it('lists the environment-authored action ONCE, with no namespace, under its face (BASE: a second row under `showcase` and the face refused)', () => {
156+
const own = rowsNamed(ENV_ACTION);
157+
expect(own.map((a) => [a.namespace, a.face]), JSON.stringify(own)).toEqual([[undefined, `${OBJECT}-${ENV_ACTION}`]]);
158+
expect(refusedFaces.map((r) => r.face)).not.toContain(`${OBJECT}-${ENV_ACTION}`);
159+
});
160+
161+
it('run_action runs it by its listed face (BASE: 404 "names no one action")', async () => {
162+
const ran = await tool('run_action', { actionName: `${OBJECT}-${ENV_ACTION}`, recordId });
163+
expect(ran.isError, ran.text).toBe(false);
164+
expect([ran.payload.ok, ran.payload.action, ran.payload.objectName]).toEqual([true, ENV_ACTION, OBJECT]);
165+
});
166+
167+
it('naming `showcase`, a package that never shipped it, no longer reaches it: MCP and the addressed REST door answer 404 (BASE: both ran it)', async () => {
168+
const mcp = await tool('run_action', { actionName: ENV_ACTION, objectName: OBJECT, namespace: 'showcase', recordId });
169+
expect([mcp.isError, mcp.payload.error?.code, mcp.payload.error?.status], mcp.text).toEqual([true, 'RESOURCE_NOT_FOUND', 404]);
170+
const rest = await stack.apiAs(admin, 'POST', `/actions/showcase/${OBJECT}/${ENV_ACTION}`, { recordId });
171+
const body: any = await rest.json();
172+
expect([rest.status, body?.error?.code], JSON.stringify(body)).toEqual([404, 'RESOURCE_NOT_FOUND']);
173+
});
174+
175+
it('CONTROL: it still runs as the environment\'s, by its bare name and at `/actions/_env/...`', async () => {
176+
const bare = await tool('run_action', { actionName: ENV_ACTION, objectName: OBJECT, recordId });
177+
expect(bare.isError, bare.text).toBe(false);
178+
const env = await stack.apiAs(admin, 'POST', `/actions/_env/${OBJECT}/${ENV_ACTION}`, { recordId });
179+
expect(env.status, await env.clone().text()).toBe(200);
180+
});
181+
182+
it('CONTROL: an environment-authored flow action targeting a showcase-shipped flow by bare name runs on REST and MCP, as before, and lists once under its face', async () => {
183+
// The flow is read by the no-package rule now, not inside the showcase's
184+
// package (BASE: the same two runs answered the same).
185+
const rest = await stack.apiAs(admin, 'POST', `/actions/${OBJECT}/${ENV_FLOW_ACTION}`, { recordId });
186+
const restText = await rest.text();
187+
expect(rest.status, restText).toBe(200);
188+
const bare = await tool('run_action', { actionName: ENV_FLOW_ACTION, objectName: OBJECT, recordId });
189+
expect([bare.isError, bare.payload.action], bare.text).toEqual([false, ENV_FLOW_ACTION]);
190+
const own = rowsNamed(ENV_FLOW_ACTION);
191+
expect(own.map((a) => [a.namespace, a.face]), JSON.stringify(own)).toEqual([[undefined, `${OBJECT}-${ENV_FLOW_ACTION}`]]);
192+
const faced = await tool('run_action', { actionName: `${OBJECT}-${ENV_FLOW_ACTION}`, recordId });
193+
expect([faced.isError, faced.payload.action], faced.text).toEqual([false, ENV_FLOW_ACTION]);
194+
});
195+
196+
it('an environment-authored flow action whose target flow name two packages hold is refused 409 naming both, on the bare REST route, the face and `_env` (BASE: it ran the object\'s package\'s flow)', async () => {
197+
const expectRefusedNamingBoth = (status: number, body: any) => {
198+
const code = body?.error?.code ?? body?.code;
199+
const message = String(body?.error?.message ?? body?.message ?? '');
200+
expect([status, code], JSON.stringify(body)).toEqual([409, 'RESOURCE_CONFLICT']);
201+
for (const holder of ['com.example.showcase', TWIN_PACKAGE]) expect(message, JSON.stringify(body)).toContain(holder);
202+
};
203+
const rest = await stack.apiAs(admin, 'POST', `/actions/${OBJECT}/${ENV_SHARED_FLOW_ACTION}`, { recordId });
204+
expectRefusedNamingBoth(rest.status, await rest.json());
205+
const env = await stack.apiAs(admin, 'POST', `/actions/_env/${OBJECT}/${ENV_SHARED_FLOW_ACTION}`, { recordId });
206+
expectRefusedNamingBoth(env.status, await env.json());
207+
const faced = await tool('run_action', { actionName: `${OBJECT}-${ENV_SHARED_FLOW_ACTION}`, recordId });
208+
expect(faced.isError, faced.text).toBe(true);
209+
expectRefusedNamingBoth(faced.payload.error?.status, faced.payload);
210+
});
211+
212+
it('CONTROL: a package-shipped action on the same object lists once, under its namespace, and runs by its face', async () => {
213+
const shipped = rowsNamed(SHIPPED);
214+
expect(shipped.map((a) => [a.namespace, a.face]), JSON.stringify(shipped)).toEqual([['showcase', `${OBJECT}-${SHIPPED}`]]);
215+
const ran = await tool('run_action', { actionName: `${OBJECT}-${SHIPPED}`, recordId });
216+
expect([ran.isError, ran.payload.action], ran.text).toEqual([false, SHIPPED]);
217+
});
218+
219+
it('CONTROL: an action authored with `?package=` lists once, under that package\'s namespace, and runs by it', async () => {
220+
const own = rowsNamed(PKG_ACTION);
221+
expect(own.map((a) => [a.namespace, a.face]), JSON.stringify(own)).toEqual([[QA_NAMESPACE, `${OBJECT}-${PKG_ACTION}`]]);
222+
const ran = await tool('run_action', { actionName: PKG_ACTION, objectName: OBJECT, namespace: QA_NAMESPACE, recordId });
223+
expect([ran.isError, ran.payload.action], ran.text).toEqual([false, PKG_ACTION]);
224+
});
225+
});

0 commit comments

Comments
 (0)