Skip to content

Commit 5d17aa6

Browse files
feat(service-automation): a connector_action names its connector from the calling flow's package (#31863)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9B9qYj7GTyDGfaMgXwXx7rZ)_ Fixes #31677 Clause-②: no Metadata-protocol: none Narrowing: a `connector_action` in a packaged flow whose `connectorConfig.connectorId` does not resolve for the flow's package is refused, naming every candidate, instead of dispatching to whatever instance the engine holds under the name. Three sub-cases: the only holder is outside the flow package's declared closure (the closure-outside sub-case of #31527 comment 6728487836, a sibling package in the same artifact included); the only instance is environment-authored (ADR-0150 D3 (a)); two packages in the closure hold the name. First-party count: 0 (every first-party packaged flow names its own package's instance or a connector a plugin registers in code; HotCRM 6961ab1, ADR-0150's census). This closes card #31677 (ADR-0150 child E5, epic #31527): it is the card's last PR. Connectors landed in #31725, webhooks in #31744, email templates in #31825. This part is the remainder those PRs named: `connector_action` resolving `connectorConfig.connectorId` from the calling flow's package (seat answer 6728849524, Q3), now that E1 #31738 gives a run its flow's package. **Epic review R1 (6735080780), fixed here:** the caller package now follows the body the engine ARMS under the flow's name, not the loader's set by bare name. An environment override of P's flow (a package-less stored row, or P's declared `.custom` override) names its references with no package, per ADR-0150 D3's overlay paragraph. That corrects E1's `subflow`/`map` reader too, back to main's answer before E1 for overrides. It is a loosening, not a new narrowing. Names were accepted by seat 3 (6735158321). Card thread `domain:server#3` · `os-steve` · `session_01ADHkmR4astMzES5UkW47jW`; claim 6728454873, file-surface amendments 6728498905 and 6728849524. ## 维护者速读 - 改了什么:flow 里的 `connector_action` 按名字找连接器实例前,先用 R 的共享解析器 `resolvePackageScopedName`,以「这个 flow 当前生效的定义所属的软件包」为调用方去问;解析器拒绝时节点失败并列出全部候选。引擎在每次注册 flow 时记下生效定义的来源(包本身、`.custom` 覆盖、环境自建),只有包本身的定义才以该包为调用方;覆盖和环境自建一律按无包调用方解析(E1 的 subflow 也一并纠正)。 - 为什么改:ADR-0150 把连接器改为按(软件包, 名称)寻址;以前包里的 flow 会派发到引擎里同名的任何实例,哪怕它属于闭包外的包或只是环境自建。 - 风险与回滚:只影响「包内 flow 指向自己够不着的已声明连接器」的部署:只有闭包外的包持有、只有环境自建、或闭包内两个包同名。第一方计数 0。环境自建的 flow、代码注册的连接器(slack、rest 等)照常派发。回滚即还原本 PR。 - 先看:`engine.ts` 的 `armedFlowPackage` 和 `registerFlow` 的 `armedFrom`,`flow-precedence.ts` 里识别协议视图下发的覆盖文档那一段,再看 `connectorNameRefusal`。 - 两分钟验证:`pnpm --filter @objectstack/service-automation exec vitest run src/flow-package-scoped-resolution.test.ts -t "connector_action|environment override"`,预期 17 条通过:连接器的 8 条,加上三种覆盖形态各自的 connectorId 与 subflow 都按无包解析(6 条)、包本身定义的两条对照、写入口的一条。 - 需要你做的:无,席位落地。本 PR 合并后 #31677 关闭。 ## Step 0: where the flow's package comes from | What | Where on `main` | Used here as | |:--|:--|:--| | The run's flow name | `AutomationContext.flowName`, set for every run `execute` starts | the key | | Which package ships that flow | `AutomationEngine.packagedFlowOwner(name)`, fed by `setPackagedFlowSource(packagedFlowReader(ctx))` (E1 #31738; the protocol's `packagedArtifactOwner`) | the caller package | | Both together | private `flowCallerPackage(context)` (E1): `context.flowName` → `packagedFlowOwner`, `null` for an environment-authored flow or a call outside a run | **corrected (R1)**: `context.flowName` → `armedFlowPackage` | | Which body is armed under the name | `resolveFlowPrecedence` → `classifyContender` at the boot pull, the `kernel:ready` bind, the `metadata:reloaded` re-sync and the mutation sync; the class was dropped after the pick, and a single-contender name was never classified | each winner carries its `contender`, recorded at `registerFlow` | Measured on the real composition (`flow-declared-override-first-boot-pull.integration.test.ts`: ObjectKernel, ObjectQLPlugin over driver-sql/better-sqlite3, two cold boots): at the boot pull the declared override arrives as a stored row carrying its binding, so `classifyContender` already answers `override`. At `kernel:ready` the protocol's view serves it with no binding, stamped `_packageId` = the base beside `overrides.package` = the base, and `isCodeArtifactBody` answered **`package`**. That is the stamp trap; the classifier now recognises that shape. ## What changes - `engine.ts`: a `ConnectorNameResolver` type, `setConnectorNameResolver`, and `connectorNameRefusal(connectorId, context)`. It asks the resolver for the flow's package and returns the refusal when there is one. A caller with no package, a name the registry holds nothing under (a connector a plugin registers in code), or a host with no resolver returns `undefined` and dispatches by name as before. - `builtin/connector-nodes.ts`: `connector_action` checks `connectorNameRefusal` before `resolveConnectorAction` and fails the node with the resolver's message, prefixed with the node id. - `connector-package-scope.ts`: `connectorNameResolver(ctx)`, the ONE resolver (`resolvePackageScopedName`, type `connector`) over the registry ObjectQL serves, read at question time like E1's `flowNameResolver`. - `plugin.ts`: attaches it at `init()`, beside `setFlowNameResolver`. R1, the shared reader: - `engine.ts`: `registerFlow(name, definition, armedFrom?: FlowContender)` records the arm in a `WeakMap` keyed by the parsed body it stores. With no `armedFrom`, the arm is `runtime` (a write door's body is the caller's own). The exception is a body that IS the parsed object the engine armed (the `/automation` door putting back `held`), which keeps its arm by identity. `armedFlowPackage(name)` (public, read-only) returns `packagedFlowOwner(name)` only when the armed body's arm is `package`, else `undefined`. `flowCallerPackage` reads it. - `flow-precedence.ts`: every winner carries `contender`, single-contender names included. `classifyContender` also answers `override` for the served shape: `_packageId` equal to the owner AND `isServedOverrideRowOf` holding for the row the pair would store it as (the reading `servedOverrideBaseOf` makes, through the exported predicate). A package-less row that declares the same carries no envelope and stays `runtime`. - `plugin.ts`: the four arming steps pass `entry.contender`. Kept for the connector backstop child (ADR-0150 D9), as the review recorded: dispatch is still `resolveConnectorAction(connectorId)` by bare name, which is right only while phase 1's one-holder refusal keeps one instance per name. Why a refusal is the only answer that needs acting on: the engine holds one instance per name, materialized for the no-package answer (the declared-connector reconcile from #31725 already refuses a name two packages hold). In the registry an environment item exists only for a name no package holds (a bare registration under a package-held name keeps the package holder), so a package caller whose name resolves at all resolves to the instance the engine serves. No second resolver, no first-registered fallback. | Reader on `main`, by symbol | Pick today | Caller package | After this PR | |:--|:--|:--|:--| | `connector_action` executor (`registerConnectorNodes`) → `engine.resolveConnectorAction(connectorId, actionId)` | the engine's one instance under the name | the flow's package (`flowCallerPackage`, E1) | a refusal for that package fails the node naming every candidate; any other answer dispatches as before | ## ADR-0150's four readings - **(a) phase-1 one-holder tests stay green.** The four `bare-name-one-holder*` dogfood files are in the full run below. - **(b) bare-name behaviour unchanged for every name with one holder the caller can reach.** Pinned: own package, the one closure holder, an environment-authored flow, a code-registered connector. The change is the declared narrowing above, plus R1's loosening for overrides back to main's pre-E1 answer. No URL, MCP or SDK surface moves. - **(c) no migration.** Nothing stored is read or written differently. - **(d)** `Clause-②: no`, `Metadata-protocol: none`; no ADR-0087 entry. ## Tests `service-automation/src/flow-package-scoped-resolution.test.ts`, new describe "ADR-0150 D3 — a connector_action names its connector from the calling flow's package (epic #31527 child E5)", over a real `SchemaRegistry` with E1's install/ship/author helpers. 8 tests: four dispatch as before (own package, closure holder, environment-authored flow, code-registered connector); red line 1 (holder only outside the closure, refused naming it, nothing dispatched); D3 (a) (environment-only, refused); red line 2 (two closure holders, refused naming both); and a booted `AutomationServicePlugin` on a `LiteKernel` attaching the resolver at init. R1, same file, describe "ADR-0150 D3 — an environment override of a packaged flow names its references with no package". Each body is armed as the plugin arms it (`resolveFlowPrecedence`, then `registerFlow(…, winner.contender)`). There are three override shapes: a package-less row, the `.custom` override as a stored row, and the `.custom` override as the served envelope. Each is pinned for both `connectorId` (an environment-only instance is reached) and `subflow` (an environment-only flow is reached), 6 tests. Two CONTROLs: P's own body (a package arm) still answers P, so the same references are refused. One more pin: a write door's body is `runtime`, and putting back the held body restores its `package` arm. `flow-declared-override-first-boot-pull.integration.test.ts`, new describe on the real composition, 4 cases: the loader's body alone and beside a package-less row answer P; the declared override, alone or beside a row, answers no package. Each is checked at the boot pull and after `kernel:ready`. Changed existing test code: `flow-precedence-loader-set.test.ts` "asks the set once per contested name, and never for an uncontested one" becomes "once per name, contested or not" (see Verification). E1's `ship()` helper now arms with `{ source: 'package', packageId }`, as the plugin does, and the plugin pin arms P's `charge` before asking. Ablations (`scripts/ablation-replace.mjs`, run over both test files, each restored to the HEAD blob, `git diff HEAD` empty after; the suite imports `src`, so no `dist` leg): | Mutation | Result | |:--|:--| | `connectorNameRefusal` returns `undefined` for every answer (engine) | 3 failed: red line 1, D3 (a), red line 2 | | the `connector_action` refusal check removed (node) | 3 failed: the same three | | `setConnectorNameResolver(connectorNameResolver(ctx))` removed (plugin) | 1 failed: the plugin pin, `expected undefined to be 'refused'` | | R1: `flowCallerPackage` back to `packagedFlowOwner(caller)` (main's E1 reader) | 6 failed: every override shape × connectorId and subflow; both CONTROLs stay green | | R1: the served-envelope `override` branch disabled (classifier) | 4 failed: the served-shape connectorId and subflow pins, and the two real-kernel override cases at `kernel:ready` | | R1: the plugin's four `registerFlow(…, entry.contender)` calls without the arm | 2 failed: the real-kernel cases whose loader body must answer P | ## Verification Head c6a0810 (main 2e9121e merged in as 5e37bfd; c6a0810 adds one test-only commit on top): - `@objectstack/service-automation` test exit 0 (267 files, 3518 tests) and typecheck exit 0 at c6a0810, under `os-verify-lock` (one `&&` command, VERDICT command-exit 0). Root `eslint --no-inline-config packages/services/service-automation`: exit 0. - The first local run, at 5e37bfd, had 1 red: `flow-precedence-loader-set.test.ts` pinned "never asks the loader's set for an uncontested name". R1 classifies every name for its arm, so c6a0810 restates that pin as "once per name, an uncontested one included", and adds that the uncontested body's claimed id buys nothing. CI's Test Core 5/8 showed the same 1 red at 5e37bfd. - `turbo run build --filter='@objectstack/dogfood^...'`: 70/70. - Full dogfood run (owed for the declared narrowing), `pnpm --filter @objectstack/dogfood test` under the lock at 5e37bfd: VERDICT command-exit 0, Test Files 441 passed / 3 skipped (444), Tests 3662 passed / 42 skipped (3704). The only change since is that test file. - Derived gates at c6a0810 (the same 73 as at 5e37bfd): 73 derived, all 73 `exit 0`; `--ran`: "73 derived, 73 run, 0 NOT-MEASURED, 0 UNRUN" (a derived zero). - `test:repo` not run locally (CI's `Test Core`); this diff touches no repo-project test. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmR4astMzES5UkW47jW <!-- signed: domain:server#3 · os-steve · session_01ADHkmR4astMzES5UkW47jW --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a57a007 commit 5d17aa6

9 files changed

Lines changed: 531 additions & 20 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/service-automation': patch
3+
---
4+
5+
feat: a `connector_action` names its connector from the calling flow's package (ADR-0150 D3/D4)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A flow's `connectorConfig.connectorId` is now resolved through `resolvePackageScopedName` from `@objectstack/objectql`, as the package that ships the flow: its own declared connector instance, else the one holder in its declared dependency closure, else a refusal naming every candidate. An environment-authored flow names it with no package, as before.
11+
12+
Who is affected: a packaged flow whose `connector_action` names a declared connector instance its package can't reach: one held only by a package outside its declared dependencies, one only the environment authored (ADR-0150 D3 (a)), or one two packages in its closure both declare. That node was dispatched to whatever instance the engine held under the name; it is now refused, and the error names every candidate. Declare the dependency, or ship the instance in the flow's own package. First-party count: 0. Every first-party packaged flow names its own package's instance or a connector a plugin registers in code, which is no registry item and dispatches as before.
13+
14+
Corrected beside it: which package a flow run names its references from. It is the package only while that package's OWN body is armed under the flow's name (`AutomationEngine.armedFlowPackage`; the engine records where each armed body came from at every `registerFlow`). An environment override of a packaged flow, whether a package-less stored row or the shipping package's declared `.custom` override, names its `connector_action` connector and its `subflow`/`map` flow with no package, as ADR-0150 D3 says an overlay's references do. Before this, E1's subflow reader read the package that ships the flow name, so an override's subflow name resolved from that package; it now resolves as it did on main before E1. That is a loosening back to the earlier answer, not a new narrowing.

‎packages/services/service-automation/src/builtin/connector-nodes.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ export function registerConnectorNodes(engine: AutomationEngine, ctx: PluginCont
6262
);
6363
}
6464

65+
// [ADR-0150 D3, epic #31527 child E5] A packaged flow names its
66+
// connector from its package: refused (every candidate named) when
67+
// the name does not resolve for that package — never dispatched on
68+
// a guess.
69+
const nameRefusal = engine.connectorNameRefusal(cfg.connectorId, context);
70+
if (nameRefusal) {
71+
return refuseNode(`connector_action '${node.id}': ${nameRefusal.message}`);
72+
}
73+
6574
const handler = engine.resolveConnectorAction(cfg.connectorId, cfg.actionId);
6675
if (!handler) {
6776
// A degraded declarative instance (#3017) is registered but has no

‎packages/services/service-automation/src/connector-package-scope.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
resolvePackageScopedName,
3030
type PackageScopedRefusal,
3131
type PackageScopedRegistry,
32+
type PackageScopedResolution,
3233
} from '@objectstack/objectql';
3334

3435
/** The registry, when it carries the slice the package-scoped resolver reads. */
@@ -59,3 +60,29 @@ export function refusedConnectorNames(
5960
}
6061
return refused;
6162
}
63+
64+
/**
65+
* [ADR-0150 D3] The engine's reader over the one package-scoped resolver for
66+
* the `connector` type (`AutomationEngine.setConnectorNameResolver`): which
67+
* declared connector instance a bare `connectorConfig.connectorId` means for a
68+
* caller of package `callerPackageId` (`null`: no package).
69+
*
70+
* Resolved at QUESTION time, never at boot, like the flow reader. A
71+
* composition with no ObjectQL, or whose registry offers none of the
72+
* package-scoped reads, has no registry to ask: the answer is `undefined` and
73+
* `connector_action` dispatches by name as before.
74+
*/
75+
export function connectorNameResolver(
76+
ctx: { getService<T>(name: string): T },
77+
): (name: string, callerPackageId: string | null) => PackageScopedResolution | undefined {
78+
return (name, callerPackageId) => {
79+
let registry: PackageScopedRegistry | undefined;
80+
try {
81+
registry = packageScopedRegistryOf(ctx.getService<{ registry?: unknown }>('objectql')?.registry);
82+
} catch {
83+
return undefined;
84+
}
85+
if (!registry) return undefined;
86+
return resolvePackageScopedName(registry, { type: 'connector', name, callerPackageId });
87+
};
88+
}

‎packages/services/service-automation/src/engine.ts‎

Lines changed: 108 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,17 @@ export type PackagedFlowSource = (name: string) => string | undefined;
25832583
*/
25842584
export type FlowNameResolver = (name: string, callerPackageId: string | null) => PackageScopedResolution | undefined;
25852585

2586+
/**
2587+
* [ADR-0150 D3, epic #31527 child E5] The same reader for the `connector` type:
2588+
* which declared connector instance the bare name `name` means for a caller of
2589+
* package `callerPackageId` (`null` for a caller with no package). The
2590+
* automation plugin attaches `resolvePackageScopedName` over the ObjectQL
2591+
* registry ({@link AutomationEngine.setConnectorNameResolver}); `undefined`
2592+
* means the host serves no registry to ask. ⛔ Never a second implementation
2593+
* of the rule.
2594+
*/
2595+
export type ConnectorNameResolver = (name: string, callerPackageId: string | null) => PackageScopedResolution | undefined;
2596+
25862597
/**
25872598
* [#28405] The stored body of flow `name` whose content identity is
25882599
* `checksum` ({@link SuspendedRun.flowChecksum}), as the metadata history
@@ -2823,6 +2834,19 @@ export class AutomationEngine implements IAutomationService {
28232834
* knows, as before.
28242835
*/
28252836
private flowNameResolver?: FlowNameResolver;
2837+
/**
2838+
* [ADR-0150 D3, epic #31527 child E5] Where each armed body came from, keyed
2839+
* by the parsed body {@link registerFlow} stores — so {@link armedFlowPackage}
2840+
* reads the arm of exactly what `flows` holds under a name, and a withdrawn
2841+
* or replaced body takes its arm with it. Written at EVERY registration:
2842+
* the caller's classification when it hands one, else `runtime`.
2843+
*/
2844+
private readonly flowArms = new WeakMap<object, FlowContender>();
2845+
/**
2846+
* [ADR-0150 D3] The reader that answers which declared connector instance a
2847+
* bare name means for a caller — see {@link setConnectorNameResolver}.
2848+
*/
2849+
private connectorNameResolver?: ConnectorNameResolver;
28262850
/** [#20790] The write-only flow credential channel — see {@link setFlowCredentialSource}. */
28272851
private flowCredentialSource?: FlowCredentialSource;
28282852
/** [#20281 stage ③] The connector sync executor — see {@link setConnectorPullSource}. */
@@ -4556,7 +4580,21 @@ export class AutomationEngine implements IAutomationService {
45564580
return canonicalizeFlow.call(host, name, definition, options);
45574581
}
45584582

4559-
registerFlow(name: string, definition: unknown): FlowParsed {
4583+
/**
4584+
* @param armedFrom [ADR-0150 D3, epic #31527 child E5] Where `definition`
4585+
* comes from: the automation plugin's arming steps hand the precedence
4586+
* winner's classification (`resolveFlowPrecedence`) — `package` for the
4587+
* loader's own body, `override` for the shipping package's declared
4588+
* `.custom` override, `runtime` for an environment-authored row. Absent,
4589+
* the body is the caller's own — a write door's request body — and arms
4590+
* as `runtime`, unless it IS the parsed body this engine armed (a door
4591+
* putting back the definition it held), which keeps the arm it had.
4592+
* {@link armedFlowPackage} reads it.
4593+
*/
4594+
registerFlow(name: string, definition: unknown, armedFrom?: FlowContender): FlowParsed {
4595+
const arm: FlowContender = armedFrom
4596+
?? (definition !== null && typeof definition === 'object' ? this.flowArms.get(definition) : undefined)
4597+
?? { source: 'runtime' };
45604598
// One canonicalization policy, shared with the stored-row migration so
45614599
// the two can never disagree about what "canonical" means (#4454).
45624600
// Execution takes the parsed shape (schema defaults materialized).
@@ -4601,6 +4639,7 @@ export class AutomationEngine implements IAutomationService {
46014639
// history keys this version by. See {@link SuspendedRun.flowChecksum}.
46024640
const checksum = flowContentChecksum(definition);
46034641
if (checksum !== undefined) this.flowChecksums.set(parsed, checksum);
4642+
this.flowArms.set(parsed, arm);
46044643
this.flows.set(name, parsed);
46054644
// [#23316] Held now, so no longer refused — see {@link flowRefusals}.
46064645
this.flowRefusals.delete(name);
@@ -5021,19 +5060,83 @@ export class AutomationEngine implements IAutomationService {
50215060
return resolution?.status === 'refused' ? resolution : undefined;
50225061
}
50235062

5063+
/**
5064+
* [ADR-0150 D3, epic #31527 child E5] Attach the reader that answers which
5065+
* declared connector instance a bare `connectorConfig.connectorId` means for
5066+
* the flow that names it ({@link connectorNameRefusal}). The automation
5067+
* plugin calls this at `init()`; with none attached, `connector_action`
5068+
* dispatches by name as before.
5069+
*/
5070+
setConnectorNameResolver(resolver: ConnectorNameResolver | undefined): void {
5071+
this.connectorNameResolver = resolver;
5072+
}
5073+
5074+
/**
5075+
* [ADR-0150 D3, epic #31527 child E5] Why a `connector_action` in a run of
5076+
* `context`'s flow may not dispatch to the connector instance named
5077+
* `connectorId`, or `undefined` when it may.
5078+
*
5079+
* The name is resolved for the package that ships the calling flow
5080+
* ({@link flowCallerPackage}: a packaged flow names it from its package; an
5081+
* environment-authored flow, or a call outside a run, names it with no
5082+
* package). The engine holds ONE instance per name, materialized for the
5083+
* answer a caller with no package gets (the declared-connector reconcile,
5084+
* which already refuses a name two packages hold). So a package caller
5085+
* whose answer is a refusal — two holders in its closure, or holders only
5086+
* outside it, an environment-only instance included (ADR-0150 D3 (a)) — is
5087+
* refused with the resolver's own message, naming every candidate. Any
5088+
* other answer is the instance the engine serves: an environment item
5089+
* exists only for a name no package holds, so a package caller that
5090+
* resolves at all resolves to the one package holder the reconcile
5091+
* materialized. A name the registry holds nothing under (a connector a
5092+
* plugin registers in code), or a host with no resolver, dispatches by name
5093+
* as before. Read-only.
5094+
*/
5095+
connectorNameRefusal(connectorId: string, context: AutomationContext | undefined): PackageScopedRefusal | undefined {
5096+
const callerPackageId = this.flowCallerPackage(context);
5097+
if (callerPackageId === null) return undefined;
5098+
const meant = this.connectorNameResolver?.(connectorId, callerPackageId);
5099+
return meant?.status === 'refused' ? meant : undefined;
5100+
}
5101+
50245102
/**
50255103
* [ADR-0150 D3] The package a call of {@link execute} comes from: the
50265104
* package that ships the flow whose run made the call — `context.flowName`,
50275105
* which the engine stamps on every run's context
50285106
* (`resolveRunContext`), so a `subflow` or `map` child carries its parent's
5029-
* name — or `null` for a caller outside a run, and for a run of a flow no
5030-
* package ships (an environment-authored flow resolves as a caller with no
5031-
* package, ADR-0150 D3).
5107+
* name — or `null` for a caller outside a run, and for a run whose armed
5108+
* body is not the package's own ({@link armedFlowPackage}): an
5109+
* environment-authored flow, or an environment override of a packaged
5110+
* flow, resolves as a caller with no package (ADR-0150 D3).
50325111
*/
50335112
private flowCallerPackage(context: AutomationContext | undefined): string | null {
50345113
const caller = context?.flowName;
50355114
if (typeof caller !== 'string' || caller === '') return null;
5036-
return this.packagedFlowOwner(caller) ?? null;
5115+
return this.armedFlowPackage(caller) ?? null;
5116+
}
5117+
5118+
/**
5119+
* [ADR-0150 D3, epic #31527 child E5] The package whose OWN body is armed
5120+
* under the flow name `name`: the loader's package
5121+
* ({@link packagedFlowOwner}) when the registration the engine holds was
5122+
* armed from the loader's body (`package`, {@link registerFlow}'s
5123+
* `armedFrom`), else `undefined` — for the shipping package's declared
5124+
* `.custom` override, for an environment-authored (`runtime`) body, and
5125+
* for a name the engine does not hold.
5126+
*
5127+
* This is the package a reference written in the armed body resolves
5128+
* from. ADR-0150 D3: "A reference written in an environment-authored
5129+
* overlay (ADR-0005) is the environment's reference. It resolves as a
5130+
* caller with no package … It never resolves from the package the overlay
5131+
* customizes." So the loader's set alone (which answers by bare name, for
5132+
* whichever body is armed) is never this answer, and neither is a stamp
5133+
* on the body: the boot hydration and the protocol's served override
5134+
* both carry the base's `_packageId`. Read-only.
5135+
*/
5136+
armedFlowPackage(name: string): string | undefined {
5137+
const armed = this.flows.get(name);
5138+
if (!armed || this.flowArms.get(armed)?.source !== 'package') return undefined;
5139+
return this.packagedFlowOwner(name);
50375140
}
50385141

50395142
/**

‎packages/services/service-automation/src/flow-declared-override-first-boot-pull.integration.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,46 @@ describe('[#28717] a declared .custom flow override is armed from the first boot
296296
});
297297
});
298298

299+
/**
300+
* [ADR-0150 D3, epic #31527 child E5] Which package a reference written in the
301+
* armed body resolves from (`AutomationEngine.armedFlowPackage`, the caller
302+
* package of a `subflow` / `map` name and of a `connector_action`'s
303+
* `connectorId`). The loader's package only while the loader's OWN body is
304+
* armed; the shipping package's declared `.custom` override is an
305+
* environment-authored overlay, whose references resolve with no package
306+
* (ADR-0150 D3: "It never resolves from the package the overlay customizes").
307+
*
308+
* Read on the real composition at both arming steps: the boot pull arms from
309+
* the registry's list (the override as a stored row, with its binding), and
310+
* `kernel:ready` re-arms from the protocol's view (the override served in the
311+
* base's slot, stamped with the base's `_packageId`), so a stamp-reading
312+
* answer would read the base at one step or the other.
313+
*/
314+
describe('[ADR-0150 D3, #31677] the armed body\'s package is the loader\'s only while the loader\'s own body is armed', () => {
315+
const CASES: ReadonlyArray<readonly [string, readonly Row[], string | undefined]> = [
316+
['the loader\'s body alone', [], BASE],
317+
['a package-less stored row beside it (shadowed, the loader\'s body armed)', ['legacy'], BASE],
318+
['the declared .custom override', ['override'], undefined],
319+
['the declared override and a package-less row', ['override', 'legacy'], undefined],
320+
];
321+
for (const [shape, rows, expected] of CASES) {
322+
it(`${shape}: ${expected ?? 'no package'} at the boot pull and after kernel:ready`, async () => {
323+
let atPull: { label?: string; pkg?: string } = {};
324+
const { automation } = await measuredBoot(rows, async (_ql, engine) => {
325+
atPull = {
326+
label: ((await engine.getFlow(FLOW)) as { label?: string } | null)?.label,
327+
pkg: engine.armedFlowPackage(FLOW),
328+
};
329+
});
330+
const armedLabel = expected === undefined ? 'OVERRIDE' : 'BASE';
331+
expect(automation.packagedFlowOwner(FLOW), 'control: the loader\'s set holds the name').toBe(BASE);
332+
expect(atPull).toEqual({ label: armedLabel, pkg: expected });
333+
expect(((await automation.getFlow(FLOW)) as { label?: string } | null)?.label).toBe(armedLabel);
334+
expect(automation.armedFlowPackage(FLOW)).toBe(expected);
335+
});
336+
}
337+
});
338+
299339
/**
300340
* [#31754, ADR-0150 D3] The collision line agrees with the engine on a real
301341
* cold boot. A second package shipping FLOW's bare name (a clash sealed before

0 commit comments

Comments
 (0)