Skip to content

Commit f7b2d02

Browse files
feat(automation): IAutomationService.dryRun runs an unpublished flow once, unarmed, as a named user (#34477)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XTThuYNZSKyejbiF4WXQyHm)_ Fixes #33661 Clause-②: yes (widening) — `AutomationEngine.dryRun` admits a `runAs: 'system'` self-triggered draft for the named user (ruling B); `@objectstack/core` exports the shared flow-start rules (`aiAccountElevatedStartRefusal`, `requiredPermissionsStartRefusal`, `requiredPermissionsRefusal`, `missingCapabilities`, `isAiServiceAccount`, `AI_ACCOUNT_ELEVATED_START_REFUSAL`, `FlowStartPermissionRefusal`); plugin-security's registered `security` service serves `canWriteObject` Metadata-protocol: none ## 维护者速读 - **改了什么**:自动化服务新增「试跑」:把一份未发布的流程定义,以指定用户的身份、针对一条给定记录跑一次;写记录只模拟不落库,外发(HTTP、邮件等)只展示载荷不发送,遇到审批、等待、屏幕节点就停下并说明原因。 - **为什么改**:让作者在发布前看到流程每一步会做什么、会写哪些值、会不会被权限拒绝,而不必真的触发或改数据;同时落实维护者裁决 B(以 `runAs: 'system'` 声明的自触发草稿可以试跑,但只按试跑人的权限,绝不提权)。 - **风险与回滚**:风险集中在试跑把写操作拦在门外这一层,漏拦就会真写数据;测试逐类断言了「零写入」。准入规则从 runtime 下沉到 core 共用一份,按名启动的行为不变(runtime 609 个测试文件全绿)。回滚即 revert 本 PR,无数据迁移。 - **先看**:`packages/services/service-automation/src/dry-run.ts`(写拦截的数据引擎代理 `dryRunDataEngine` 与 `dryRun` 准入顺序);`packages/core/src/security/flow-start-rules.ts`(两条共用准入规则);`packages/plugins/plugin-security/src/security-plugin-security-service.ts`(security 服务新暴露 `canWriteObject`)。 - **两分钟验证**:`pnpm --filter @objectstack/service-automation exec vitest run src/dry-run.test.ts`,预期 30 个测试全过,其中包括「审批节点停下且从未被调用」和「零写入」的断言。 - **需要你做的**:批准本 PR 里的契约改动(`packages/spec/src/contracts/automation-service.ts` 中 dryRun 准入那一条,按裁决 B 改写)。裁决记录 6917953931 写明契约改动在实现落地前欠契约评审和你的批准;L1 与契约评审在同一 head 通过后,席位会请你批准,批准后由席位落地。 ## What changes **`AutomationEngine.dryRun(definition, options)`** implements the `IAutomationService.dryRun` contract. The run is unarmed and unregistered. It runs as the named user against the supplied record, and it writes, sends and pauses nothing. - **Admission, in the contract's order.** 1. A missing `userId` throws a `TypeError`. 2. The definition goes through `registerFlow`'s own checks, now one private `judgeFlowRegistration` that both call, so a dry run throws exactly what `registerFlow` throws. 3. Tenant membership comes from the grants resolver's `accessible_org_ids`. 4. The by-name start rules: the AI service account rule, then the flow's `requiredPermissions`. 5. The start condition: `condition_not_met`, or `failed` with the fault. 6. The input schema. - **Ruling B (record 6917953931).** A self-triggered `runAs: 'system'` draft is admitted for the named user, and its run context always resolves as `runAs: 'user'`, so it is never elevated. The contract bullet now says so, and its pin test holds the new sentences and the absence of the old one. - **One spelling of the shared rules.** The AI service account rule and the `requiredPermissions` rule moved down to `@objectstack/core` (`security/flow-start-rules.ts`), because service-automation does not depend on runtime. `flowStartRefusal` in runtime and `dryRun` both call `aiAccountElevatedStartRefusal` and `requiredPermissionsStartRefusal`. Runtime re-exports every moved symbol under its old name (`AI_ACCOUNT_ELEVATED_START_REFUSAL`, `isAiServiceAccount`, `requiredPermissionsRefusal`, `FlowStartPermissionRefusal`, `missingCapabilities`). The elevated self-triggered rule stays in runtime, since only the by-name doors ask it. - **Traversal** reuses the engine's own `executeNode` and `traverseNext` bodies on a dry host, so routing and compute nodes run on the real executors: assignment, decision, gateways, loop, parallel and try/catch. Region bodies (loop, parallel, try/catch) are diverted into the dry run through `activeDryRunExecuteNode()`, so a write inside a loop is simulated too. - **Writes.** The CRUD nodes' data engine is wrapped by `dryRunDataEngine` while a dry run is active. - Insert, update and delete are simulated. A new record gets a `dry-run:UUID:N` placeholder id. - An update or delete targets exactly the rows the engine's own dispatch picks: the one id it names (from the filter, or an update's own `id` value), the filter's rows under `multi`, or none when it refuses the call (the engine's own error). - A read by id sees the simulated row laid over the live one. A filtered read answers the live rows only, as the contract says. - An insert or update is judged by `canWriteObject` for the named user (`allowed` or `refused`). A delete, or a kernel with no check installed, answers `not_judged`. - A check that throws is a denial (`refused`). An update or delete by predicate without `multi` fails with the engine's own error and targets no row. - A refused write's step carries `PERMISSION_DENIED`. The run goes on along a `fault` edge or out of a `try_catch` region that contains it, and otherwise ends `failed` with that write as the last step. - **Outbound nodes** never execute and bind no output. Their step reports the payload, built from the spec's expression and text-slot ledgers. - **Stops.** A node whose descriptor `supportsPause` stops the run with a class: `approval`, `wait`, `screen` (its ScreenSpec is built by the real screen executor), `starts_flow` or `suspends`. A type no class covers stops the run as `not_simulated`. - **`security` service.** The registered service now serves `canWriteObject`, so the dry run can judge a write without performing it. ## Tests - `packages/services/service-automation/src/dry-run.test.ts`, 30 tests: - Each node class the in-app v2-narrow tier offers: `create_record` (placeholder id, computed values, zero writes, a read by id sees the simulated row), `update_record` (live target, overlay read, the write check asked with the non-system named user), `assignment`, `decision` (branch, expressions, `next`; also a gateway decision), and `approval` (stops, and the executor is never called). - Admission refusals: the `requiredPermissions` refusal equals `requiredPermissionsRefusal` from core, the AI account refusal equals `AI_ACCOUNT_ELEVATED_START_REFUSAL`, a non-member organization is refused, ruling B admits without elevating, plus the TypeError, the `registerFlow` throw, `condition_not_met` and a faulted condition. - Also: a refused write, `not_simulated`, a write inside a loop, and an outbound `http` payload with nothing sent. - Review round: a `save_notice` payload and a refusing `end` node in zh-CN through their translation keys; a refused write going on along its `fault` edge; a write check that throws is refused; unread grants (a failed read, an empty answer, no resolver) refuse a `runAs: 'system'` draft; an update or delete by predicate without `multi` fails with the engine's own message, with a `multi` control; an update whose fields name the id, with no filter, targets that one row, with a `multi` control targeting every readable row. - The `automation-dry-run.pin.test.ts` contract pin was updated for ruling B. - `registered-security-service-members.pin.test.ts` ledgers `canWriteObject` with its reason (see Acceptance notes). ## Acceptance notes - **`canWriteObject` stays off `ISecurityService`: settled by the published contract.** The dryRun contract of #33757 (`FlowDryRunWritePermission`, contract-reviewed) names it "a method of `@objectstack/plugin-security`'s service, not of `ISecurityService`". On `main` the registered service did not serve it; this PR serves it and ledgers it in `SERVED_NOT_DECLARED`, citing that contract. That pin's header now states the exception: a member a published contract places off `ISecurityService` stays off it, and its entry cites that contract. Declaring it on `ISecurityService` would be a separate contract change and is not part of this PR. - **Surface beyond the claim.** The claim named service-automation and spec. This PR also touches: - `@objectstack/core`: the shared rules. - `@objectstack/runtime`: re-exports only. - `@objectstack/plugin-security`: `canWriteObject` on the service. - `scripts/engine-double-contract.pinned.json`: the gate's own `--write` for the new pinned test double. - **Text slots** in an outbound payload render as their live executor renders them, in `options.locale`. `save_notice`'s message reads its `flows.FLOW.notices.NODE.message` translation through that executor's own renderer; a refusing `end` node's message reads its translation too. `notify` and `http` render the authored text, as their live executors do. - **Known approximations, each inside the contract's words:** - Approvers are omitted from an approval stop ("when the run can resolve them"). - An unconditional fan-out still runs its branches concurrently. Its steps are grouped per branch, depth-first. - A grants resolver that throws, answers nothing, or is not wired fails closed: refused for a tenant, for a declared `requiredPermissions`, and for a `runAs: 'system'` definition, because the AI service account rule cannot be asked without the grants. That last refusal carries the dry run's own message. - An update or delete by predicate with `multi` lists every row it targets, uncapped, since `FlowDryRunWriteStep.recordIds` is defined as the rows the write targets. - Not touched: cloud's `test_flow`, every HTTP or MCP door, the #33935 retry clause, `docs/adr/**`, `skills/**`. ## Verification Readings are on head `3392bc4f0` for service-automation and the dry-run suite, and on `4889de397` for spec, plugin-security, core and runtime, which the last round did not touch. The first ablation below was run on `2e47ef291`. - **Tests** (under `os-verify-lock`, VERDICT command-exit 0 for each): - `@objectstack/service-automation`: 286/286 files, 4082/4082 tests (`3392bc4f0`). - `@objectstack/runtime`: 609/609 files, 11271 passed, 19 skipped. - `@objectstack/core`: 149/149 files, 3595/3595 tests. - `@objectstack/spec`: 845/845 files, 27059 passed, 1 todo. - `@objectstack/plugin-security`: 273/273 files, 6824 passed, 45 skipped. - `dry-run.test.ts` 30/30 (`3392bc4f0`); the member pin 4/4 and the spec dry-run pin 5/5 (`4889de397`). - **Typecheck:** `core`, `runtime`, `plugin-security` and `service-automation` are green, `check:test-typecheck` included. Runtime's first attempt was red only because `@objectstack/driver-turso` had no dist. Building the dependency closure fixed it. - **Ablations.** On `2e47ef291`, the dry run's admission call was replaced with `null` through `scripts/ablation-replace.mjs`. - Mutation landed: anchor count 1 to 0, blob `bd40dedf94bb` to `ced6b2f7de22`. - `dry-run.test.ts` went to 2 failed, 16 passed: the `requiredPermissions` refusal and the AI account refusal. - Restore proven: blob equals HEAD and `git diff HEAD` is empty. The tests import the engine from source, so no dist was involved. - On `4889de397`, one each for the translation read, the unread-grants refusal and the throwing write check, through `scripts/ablation-replace.mjs`: each turned exactly its own pin red (1 failed, 25 passed) and was restored to a blob equal to HEAD with an empty `git diff HEAD`. - On `3392bc4f0`, the by-id targeting branch disabled: exactly the id-targeting pin went red (1 failed, 29 passed), restored to a blob equal to HEAD. - **Gates:** `node scripts/pm/dispatch-gates.mjs --commands` derived 108 for this diff. - On `4889de397`: 108 derived, 108 ran, all exit 0, `check:i18n` and `check:dual-build-cjs-loads` included. `--ran` reconciliation: 108 derived, 108 run, 0 NOT-MEASURED, 0 UNRUN. On `3392bc4f0`, for the two files that round touched: 60 derived, 60 ran, all exit 0. - `node scripts/check-platform-checklist.mjs --changed-from origin/main`: OK, 29 anchors judged, 0 lost. <details><summary>The ablation run</summary> ```text ablation-replace: ok mutation landed: anchor 1 -> 0, blob bd40ded -> ced6b2f7de22 × refuses a named user missing a capability requiredPermissions names, with the by-name message, and runs nothing × refuses an AI service account a runAs system definition with the account rule's message Tests 2 failed | 16 passed (18) ablation-replace: ok restored: blob == HEAD (bd40ded) and `git diff HEAD` is empty ``` </details> <details><summary>Suite totals</summary> ```text packages/services/service-automation test: Test Files 286 passed (286) packages/services/service-automation test: Tests 4082 passed (4082) packages/runtime test: Test Files 609 passed (609) packages/runtime test: Tests 11271 passed | 19 skipped (11290) packages/core test: Test Files 149 passed (149) packages/core test: Tests 3595 passed (3595) packages/spec test: Test Files 845 passed (845) packages/spec test: Tests 27059 passed | 1 todo (27060) ``` </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FEkQ5kYk6G1CvandwWbbhe <!-- signed: repo:objectstack#1 · os-project-manager · session_01FEkQ5kYk6G1CvandwWbbhe --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 96c800a commit f7b2d02

17 files changed

Lines changed: 1845 additions & 124 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/core': patch
4+
'@objectstack/runtime': patch
5+
'@objectstack/plugin-security': patch
6+
'@objectstack/service-automation': patch
7+
---
8+
9+
feat(automation): `IAutomationService.dryRun` runs an unpublished flow definition once, unarmed, as a named user
10+
11+
Clause-②: yes (widening) — `AutomationEngine.dryRun` admits a `runAs: 'system'` self-triggered draft for the named user (ruling B); `@objectstack/core` exports the shared flow-start rules (`aiAccountElevatedStartRefusal`, `requiredPermissionsStartRefusal`, `requiredPermissionsRefusal`, `missingCapabilities`, `isAiServiceAccount`, `AI_ACCOUNT_ELEVATED_START_REFUSAL`, `FlowStartPermissionRefusal`); plugin-security's registered `security` service serves `canWriteObject`
12+
Metadata-protocol: none
13+
14+
The automation service now implements `dryRun(definition, { userId, record, … })`, the method the `IAutomationService` contract declares. A dry run admits the definition by the checks `registerFlow` asks, then by the rules that admit a start by name, and then runs it once against the supplied record as the named user. It registers nothing and arms no trigger, and it writes, sends and pauses nothing:
15+
16+
- Record writes (`create_record`, `update_record`, `delete_record`) are simulated. The step shows the values the run would write and a placeholder id for a new record. The named user's object-level write permission is judged as allowed, refused or not judged. A later read by id in the same run sees the simulated row.
17+
- Routing and computing nodes (`assignment`, `decision`, gateways, loops, parallel branches, try/catch) run on the engine's own executors. A decision step shows the branch taken and the expressions it evaluated.
18+
- Outbound nodes (`http`, email and the like) are never executed. The step shows the payload they would send.
19+
- The run stops at a node that pauses (`approval`, `wait`, `screen`, a subflow) and names why. A node type the dry run cannot simulate stops it as `not_simulated`.
20+
21+
Under maintainer ruling B (record 6917953931), a draft declaring `runAs: 'system'` whose type starts on its own trigger is admitted to a dry run for the named user, and the run is never elevated. The contract's admission text says so. A by-name start of a published flow keeps refusing such a flow.
22+
23+
The AI service account rule and the flow's own `requiredPermissions` rule now live in `@objectstack/core`. The by-name start doors and the dry run both ask that one copy. `@objectstack/runtime` re-exports every symbol under the name it had. The registered `security` service now also exposes `canWriteObject`, so a dry run can judge a write without performing it.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The flow start rules two different askers share — ONE spelling, asked by
5+
* both:
6+
*
7+
* - every door that starts a published flow by name
8+
* (`flowStartRefusal`, `@objectstack/runtime`'s `flow-start-admission.ts`,
9+
* whose header is the authority on the rules and their order there);
10+
* - a dry run of an unpublished definition
11+
* (`IAutomationService.dryRun`, `@objectstack/service-automation`), which
12+
* the contract admits by "the rules that admit a start by name".
13+
*
14+
* They live here, below both, because `@objectstack/service-automation` does
15+
* not depend on `@objectstack/runtime`, and a rule each asker spelled for
16+
* itself is a rule that drifts: the account reading, the capability
17+
* arithmetic, the refusals' code and status, and their words are written here
18+
* once. `flow-start-admission.ts` re-exports every one of them under the name
19+
* it always had.
20+
*
21+
* Two rules are here, and only two:
22+
*
23+
* - **The AI service account rule** ({@link aiAccountElevatedStartRefusal};
24+
* ADR-0151 D3 and Non-goals, ruling record 6812617393, letter C): an AI
25+
* service account starts a flow declared `runAs: 'system'` only through
26+
* an action its author opted into AI.
27+
* - **The flow's own `requiredPermissions`**
28+
* ({@link requiredPermissionsStartRefusal}; ruling record 6377848497,
29+
* letter A): a caller must hold every capability the flow names.
30+
*
31+
* The elevated self-triggered rule stays in `flow-start-admission.ts`: only
32+
* the by-name doors ask it. A dry run admits such a draft for the named user,
33+
* never elevated (ruling record 6917953931, letter B), so it is not shared.
34+
*
35+
* The system principal is NOT decided here: each asker reads
36+
* `isSystem` itself, before it asks (a dry run never runs as it).
37+
*/
38+
39+
/** The ADR-0112 `403` a start the rules here do not admit answers. */
40+
export interface FlowStartPermissionRefusal {
41+
code: 'PERMISSION_DENIED';
42+
status: 403;
43+
message: string;
44+
}
45+
46+
/**
47+
* [ADR-0066 D4] The capabilities in `required` the caller does not hold, in
48+
* declaration order — the arithmetic behind every declared
49+
* `requiredPermissions` gate that admits a caller to an execution surface,
50+
* asked by the action gate (`actionPermissionError`, `action-execution.ts`),
51+
* the flow start gate and a dry run's admission. A declaration is a list of
52+
* capability names; the caller holds the capabilities its permission sets
53+
* grant (`ExecutionContext.systemPermissions`). Empty when nothing is declared
54+
* (an ungated surface) or when the caller holds all of them. A value that is
55+
* not an array declares nothing.
56+
*/
57+
export function missingCapabilities(
58+
required: unknown,
59+
executionContext: { systemPermissions?: readonly string[] } | null | undefined,
60+
): string[] {
61+
if (!Array.isArray(required) || required.length === 0) return [];
62+
const held = new Set<string>(executionContext?.systemPermissions ?? []);
63+
return (required as string[]).filter((perm) => !held.has(perm));
64+
}
65+
66+
/**
67+
* The refusal answered when the caller lacks a capability the flow's
68+
* `requiredPermissions` names — the same code and status as the action
69+
* gate's 403 (ADR-0112). ⛔ No new code is minted here.
70+
*
71+
* The message names the declared and the missing capabilities, as the action
72+
* gate's does — the remedy is a grant, and a caller cannot ask for one it
73+
* cannot name — and nothing else about the flow: not its name, its type or its
74+
* run-as declaration.
75+
*/
76+
export function requiredPermissionsRefusal(required: readonly string[], missing: readonly string[]): FlowStartPermissionRefusal {
77+
return {
78+
code: 'PERMISSION_DENIED',
79+
status: 403,
80+
message:
81+
`Starting this flow requires capability [${required.join(', ')}] — `
82+
+ `caller is missing [${missing.join(', ')}]`,
83+
};
84+
}
85+
86+
/**
87+
* The refusal answered when an AI service account starts a flow declared
88+
* `runAs: 'system'` and what starts the flow carries no AI opt-in — the same
89+
* code and status as the refusal beside it (ADR-0112). ⛔ No new code is
90+
* minted here.
91+
*
92+
* The message names the rule and the opt-in the author adds, and nothing else
93+
* about THIS flow: not its name, its type or its definition, and not the
94+
* door, so it reads the same wherever it is answered. It names the action
95+
* route and the MCP tool because those are the doors where the opt-in can
96+
* stand.
97+
*/
98+
export const AI_ACCOUNT_ELEVATED_START_REFUSAL = Object.freeze({
99+
code: 'PERMISSION_DENIED',
100+
status: 403,
101+
message:
102+
'An AI service account starts a flow that runs as the system only through an action its author opted '
103+
+ "into AI. Declare `ai: { exposed: true, description: … }` on an action of type 'flow' that targets the "
104+
+ 'flow, and have the account run that action (the REST actions route or the MCP `run_action` tool).',
105+
} as const);
106+
107+
/**
108+
* Whether `executionContext` is an AI service account's (ADR-0151 D3): the
109+
* agent principal that is its own subject, `principalKind: 'agent'` with no
110+
* `onBehalfOf`. An OAuth-delegated agent names the person it acts for and is
111+
* not one; neither is a person, the guest or the system principal.
112+
*
113+
* ONE reading, asked by the AI service account rule and by the builders that
114+
* forward the account's kind onto the run it starts, so the caller judged as
115+
* an account is the caller whose run carries the kind.
116+
*/
117+
export function isAiServiceAccount(
118+
executionContext: { principalKind?: unknown; onBehalfOf?: unknown } | null | undefined,
119+
): boolean {
120+
return executionContext?.principalKind === 'agent' && !executionContext?.onBehalfOf;
121+
}
122+
123+
/**
124+
* The AI service account rule: {@link AI_ACCOUNT_ELEVATED_START_REFUSAL} when
125+
* `executionContext` is an AI service account, the flow declares
126+
* `runAs: 'system'`, and what starts it carries no `ai.exposed: true` opt-in
127+
* (`aiExposed`); else `null`. A dry run starts with no action in hand, so it
128+
* asks with `aiExposed: false`.
129+
*/
130+
export function aiAccountElevatedStartRefusal(
131+
flow: { runAs?: unknown },
132+
executionContext: { principalKind?: unknown; onBehalfOf?: unknown } | null | undefined,
133+
aiExposed: boolean,
134+
): FlowStartPermissionRefusal | null {
135+
if (flow.runAs === 'system' && isAiServiceAccount(executionContext) && aiExposed !== true) {
136+
return AI_ACCOUNT_ELEVATED_START_REFUSAL;
137+
}
138+
return null;
139+
}
140+
141+
/**
142+
* The flow's own `requiredPermissions` rule: {@link requiredPermissionsRefusal}
143+
* naming what the caller is missing, or `null` when it holds every capability
144+
* the flow names (or the flow names none).
145+
*/
146+
export function requiredPermissionsStartRefusal(
147+
flow: { requiredPermissions?: unknown },
148+
executionContext: { systemPermissions?: readonly string[] } | null | undefined,
149+
): FlowStartPermissionRefusal | null {
150+
const missing = missingCapabilities(flow.requiredPermissions, executionContext);
151+
if (missing.length === 0) return null;
152+
return requiredPermissionsRefusal(flow.requiredPermissions as string[], missing);
153+
}

‎packages/core/src/security/index.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,16 @@ export {
717717
type CallerMailSenderSource,
718718
type CallerMailBoundsResult,
719719
} from './caller-mail-bounds.js';
720+
721+
// The flow start rules a by-name start of a published flow
722+
// (`flowStartRefusal`, runtime) and a dry run of an unpublished definition
723+
// (`IAutomationService.dryRun`, service-automation) both ask — one spelling.
724+
export {
725+
missingCapabilities,
726+
requiredPermissionsRefusal,
727+
AI_ACCOUNT_ELEVATED_START_REFUSAL,
728+
isAiServiceAccount,
729+
aiAccountElevatedStartRefusal,
730+
requiredPermissionsStartRefusal,
731+
type FlowStartPermissionRefusal,
732+
} from './flow-start-rules.js';

‎packages/plugins/plugin-security/src/registered-security-service-members.pin.test.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,21 @@ const DECLARED_MEMBERS = {
9090
/**
9191
* Members the registered service serves that are deliberately NOT part of the
9292
* contract — plugin-internal, no caller outside this package — each with the
93-
* reason. Empty: every served member is declared. An entry here is a decision
94-
* that a member stays off the contract; a member another package calls is a
95-
* contract, and belongs on `ISecurityService` instead.
93+
* reason. An entry here is a decision that a member stays off the contract; a
94+
* member another package calls is a contract, and belongs on
95+
* `ISecurityService` instead — except where a published contract places it
96+
* off `ISecurityService`, and the entry cites that contract. One such entry:
97+
* `canWriteObject`, which the `IAutomationService.dryRun` contract's
98+
* `FlowDryRunWritePermission` text names a method of this plugin's service
99+
* and not of `ISecurityService`.
96100
*/
97-
const SERVED_NOT_DECLARED: Readonly<Record<string, string>> = {};
101+
const SERVED_NOT_DECLARED: Readonly<Record<string, string>> = {
102+
canWriteObject:
103+
'the object-level write check a flow dry run asks (`@objectstack/service-automation`). The ' +
104+
'`IAutomationService.dryRun` contract (`FlowDryRunWritePermission`, packages/spec/src/contracts/' +
105+
'automation-service.ts) names it a method of this plugin\'s service and NOT of ISecurityService, so a ' +
106+
'kernel without this plugin has none and every write step answers `not_judged`',
107+
};
98108

99109
/**
100110
* OPTIONAL members this plugin must SERVE, each with the reason its absence is

‎packages/plugins/plugin-security/src/security-plugin-security-service.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export interface SecurityServiceHost {
108108
readonly tenancyPosture: SecurityPlugin['tenancyPosture'];
109109
canExport: SecurityPlugin['canExport'];
110110
canReadObject: SecurityPlugin['canReadObject'];
111+
canWriteObject: SecurityPlugin['canWriteObject'];
111112
checkAuthoredRowWrite: SecurityPlugin['checkAuthoredRowWrite'];
112113
checkControlledByParentWrite: SecurityPlugin['checkControlledByParentWrite'];
113114
declareEveryone: SecurityPlugin['declareEveryone'];
@@ -127,7 +128,7 @@ export interface SecurityServiceHost {
127128

128129
/** The `security` service registration `SecurityPlugin#start` runs; the comment above its call there is its contract. */
129130
export function registerSecurityService(
130-
this: Pick<SecurityServiceHost, 'acceptedDefaultPermissionSets' | 'baselinePermissionSets' | 'bootstrapPermissionSets' | 'canExport' | 'canReadObject' | 'checkAuthoredRowWrite' | 'checkControlledByParentWrite' | 'declareEveryone' | 'delegatedAdminGate' | 'describeEffectiveAccess' | 'describePositionGrants' | 'epoch' | 'explainAccessForCaller' | 'getEffectiveObjectPermissions' | 'getMetadataReadableFields' | 'getObjectSecurityMeta' | 'getQueryableFields' | 'getReadFilter' | 'getReadableFields' | 'getRecordFieldAccess' | 'getWritableFields' | 'logger' | 'ownershipFloorAlternates' | 'permissionEvaluator' | 'platformBaselineSets' | 'ql' | 'resolvePermissionSetsForContext' | 'tenancyPosture'>,
131+
this: Pick<SecurityServiceHost, 'acceptedDefaultPermissionSets' | 'baselinePermissionSets' | 'bootstrapPermissionSets' | 'canExport' | 'canReadObject' | 'canWriteObject' | 'checkAuthoredRowWrite' | 'checkControlledByParentWrite' | 'declareEveryone' | 'delegatedAdminGate' | 'describeEffectiveAccess' | 'describePositionGrants' | 'epoch' | 'explainAccessForCaller' | 'getEffectiveObjectPermissions' | 'getMetadataReadableFields' | 'getObjectSecurityMeta' | 'getQueryableFields' | 'getReadFilter' | 'getReadableFields' | 'getRecordFieldAccess' | 'getWritableFields' | 'logger' | 'ownershipFloorAlternates' | 'permissionEvaluator' | 'platformBaselineSets' | 'ql' | 'resolvePermissionSetsForContext' | 'tenancyPosture'>,
131132
ctx: PluginContext,
132133
ql: IObjectQLEngine,
133134
metadata: IMetadataService,
@@ -407,6 +408,12 @@ export function registerSecurityService(
407408
const registeredSecurityService = Object.assign(securityService, {
408409
getMetadataReadableFields: (object: string, context?: any) =>
409410
this.getMetadataReadableFields(object, context),
411+
// [#33661] The object-level write check (insert or update) a flow dry
412+
// run asks for each simulated write (`IAutomationService.dryRun`,
413+
// "canWriteObject is a method of plugin-security's service"). The same
414+
// method the engine's write-gate probe calls; ⛔ not a second decision.
415+
canWriteObject: (object: string, operation: 'insert' | 'update', context?: any, data?: unknown) =>
416+
this.canWriteObject(object, operation, context, data),
410417
// [#21729] The ownership-floor alternate seam — how a plugin that
411418
// installs a tighter row gate stops the platform's `created_by` floor
412419
// pre-empting it, registered beside that gate and nowhere else. Same

‎packages/plugins/plugin-security/src/security-plugin.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,12 +2328,13 @@ export class SecurityPlugin implements Plugin {
23282328
const readQl = () => this.ql;
23292329
const readTenancyPosture = () => this.tenancyPosture;
23302330
const readEpoch = () => this.epoch;
2331-
const host: Pick<SecurityServiceHost, 'acceptedDefaultPermissionSets' | 'baselinePermissionSets' | 'bootstrapPermissionSets' | 'canExport' | 'canReadObject' | 'checkAuthoredRowWrite' | 'checkControlledByParentWrite' | 'declareEveryone' | 'delegatedAdminGate' | 'describeEffectiveAccess' | 'describePositionGrants' | 'epoch' | 'explainAccessForCaller' | 'getEffectiveObjectPermissions' | 'getMetadataReadableFields' | 'getObjectSecurityMeta' | 'getQueryableFields' | 'getReadFilter' | 'getReadableFields' | 'getRecordFieldAccess' | 'getWritableFields' | 'logger' | 'ownershipFloorAlternates' | 'permissionEvaluator' | 'platformBaselineSets' | 'ql' | 'resolvePermissionSetsForContext' | 'tenancyPosture'> = {
2331+
const host: Pick<SecurityServiceHost, 'acceptedDefaultPermissionSets' | 'baselinePermissionSets' | 'bootstrapPermissionSets' | 'canExport' | 'canReadObject' | 'canWriteObject' | 'checkAuthoredRowWrite' | 'checkControlledByParentWrite' | 'declareEveryone' | 'delegatedAdminGate' | 'describeEffectiveAccess' | 'describePositionGrants' | 'epoch' | 'explainAccessForCaller' | 'getEffectiveObjectPermissions' | 'getMetadataReadableFields' | 'getObjectSecurityMeta' | 'getQueryableFields' | 'getReadFilter' | 'getReadableFields' | 'getRecordFieldAccess' | 'getWritableFields' | 'logger' | 'ownershipFloorAlternates' | 'permissionEvaluator' | 'platformBaselineSets' | 'ql' | 'resolvePermissionSetsForContext' | 'tenancyPosture'> = {
23322332
acceptedDefaultPermissionSets: this.acceptedDefaultPermissionSets,
23332333
baselinePermissionSets: this.baselinePermissionSets,
23342334
bootstrapPermissionSets: this.bootstrapPermissionSets,
23352335
canExport: (...a) => this.canExport(...a),
23362336
canReadObject: (...a) => this.canReadObject(...a),
2337+
canWriteObject: (...a) => this.canWriteObject(...a),
23372338
checkAuthoredRowWrite: (...a) => this.checkAuthoredRowWrite(...a),
23382339
checkControlledByParentWrite: (...a) => this.checkControlledByParentWrite(...a),
23392340
declareEveryone: (...a) => this.declareEveryone(...a),

0 commit comments

Comments
 (0)