diff --git a/.changeset/33386-flow-doors-served-holders.md b/.changeset/33386-flow-doors-served-holders.md new file mode 100644 index 00000000000..63cb818a4a2 --- /dev/null +++ b/.changeset/33386-flow-doors-served-holders.md @@ -0,0 +1,30 @@ +--- +'@objectstack/runtime': patch +'@objectstack/service-automation': patch +--- + +fix(runtime,service-automation)!: the flow doors and the connector address judge the served holders of a name two packages hold, so a disabled holder's slot answers no bare name (ADR-0150 D3, #33386) + +Clause-②: yes (narrowing) +Metadata-protocol: none + + + +**BREAKING** for a caller of a flow or connector name that two packages hold while one of them is disabled. A disabled package holds no name (ADR-0150 D3). Until now the `/automation` by-name doors, the flow action and endpoint, the start admission's record-read walk and the engine's bare entries still counted a disabled holder for such a name. They now count only the packages that serve it. With no holder disabled, every answer is unchanged. Measured over a real `SchemaRegistry` (its `disablePackage`), in both registration orders. Packages CRM and HR each hold the flow `convert` and the connector `mail`, one engine slot or instance each, and CRM is disabled: + +- A bare name with no package (`POST /automation/convert/trigger`, `GET /automation/convert`, the run doors, `GET /automation/connectors/mail/connection`, the engine's `execute`, `getFlow` and `toggleFlow`) was refused 409 naming CRM and HR. It is now served from HR's slot or instance. +- A flow action, a subflow call or a walk read from a package whose closure holds both was refused 409 naming both. It now reaches HR's flow (widening). +- CRM's own flow action, or a subflow call from CRM's own flow, ran CRM's flow. It now gets no flow (not found), and never HR's. +- A package that reaches the name only through CRM ran CRM's flow. It is now refused 409 `outside-closure` naming HR. A package that reaches neither holder is refused naming HR only (before: both). +- An address naming CRM (`/automation/crm/convert/…`, `/automation/trigger/crm/convert`) ran CRM's slot. It is now refused 409 `not-held-by-qualifier` naming HR. `/automation/connectors/crm/mail/connection` reached the service, which answered 404; it is now refused 409 naming HR, and the service is not asked. +- `_env` or another namespace (`/automation/_env/convert/…`, `/automation/connectors/ops/mail/connection`) was refused 409 naming both. It is now refused naming HR only. +- The definition writes (`PUT`, `DELETE`, clone) at an address naming CRM, at `_env` or at a third namespace were refused 409 naming both. They are now refused 409 naming HR only. With both disabled, such a write at an address answers 404. +- With CRM and HR both disabled, no door and no run reaches a flow. An address answers 404. The bare name and `_env` answer as for a flow the engine does not hold. + +**Not moved.** HR's own address and HR's own callers answer as before. The durable coordinates stay judged over every holder, served or not: the engine's slot keys, a run's key, the schedule dispatch key (`flowDispatchHolder`), the credential channel's scoping, the subflow guards' arming verdicts, and which slot a run row is filed under. A disable is reversible, so it re-points no slot. A run filed under CRM's slot key is no served holder's: the run doors answer it as a run nobody holds, and it is never read or acted on as HR's. A definition write (`PUT`, `DELETE`, clone) at HR's own address keeps its 409 naming every holder; a bare definition write is refused by the metadata store over its stored rows, as before. A name only one package holds is judged as before. + +**Deferred:** amendment 3's trigger binding (a runtime-disabled holder's trigger still fires its slot, as on main) → #33748. + +**No migration.** No schema key, stored row, slot key, run key or dispatch key changes, so there is nothing to rewrite: the answers that move follow a reversible package state. + +The fix for a caller: re-enable the package, or address the served holder by its namespace. diff --git a/packages/runtime/src/domains/automation-address.ts b/packages/runtime/src/domains/automation-address.ts index 8774bf04c12..5269b173f68 100644 --- a/packages/runtime/src/domains/automation-address.ts +++ b/packages/runtime/src/domains/automation-address.ts @@ -73,6 +73,27 @@ * {@link bareNameRefusal} is the same resolution for a bare address: a bare * name the resolver refuses is answered `409` naming every candidate (D5), on * the doors whose own answer was no such `409`. + * + * [ADR-0150 D3, #33386; seat ruling 6884403301] A name two or more packages + * hold, one of them disabled, is judged over the SERVED holders at the doors + * (a disabled package holds no name), the shape the email send took + * (plugin-email `template-loader.ts`): + * + * - a bare name ({@link bareNameAdmission}): one served holder is that + * holder's slot, two or more are refused naming the served holders only, + * and none is no item (the door's own `404`). A slot is `(package, name)` + * and is never re-pointed: a disable only moves which slot the bare name + * reaches; + * - an address naming the disabled holder's namespace is never another + * package's item: `not-held-by-qualifier` naming the served holders, or + * `404` when none remains; `_env` and any other namespace name the served + * holders only. + * + * The durable coordinates stay judged over EVERY holder (amendment 7): the + * engine's slot keys, a run's key, and {@link bareNameRefusal}, which the MCP + * resume door reads to tell a run row's slot. So does the refusal a slot + * carries for the doors that cannot serve from the slot (the definition + * writes): a write targets the name every holder holds. */ import { @@ -259,6 +280,33 @@ export function bareNameRefusal( return resolution.status === 'refused' ? resolution : undefined; } +/** + * [ADR-0150 D3, #33386] A BARE by-name door's admission (see the module note): + * the bare name's `409` naming the served holders when two or more serve it, + * the slot of its one served holder when the name is held by two or more + * packages over every holder (each holder's item is then its own slot), and + * `undefined` otherwise — the bare path, as before, which answers its own + * `404` when no served holder remains. A name held by one package or none is + * judged as {@link bareNameRefusal} judges it, unchanged. Read-only. + */ +export function bareNameAdmission( + registry: AutomationAddressRegistry | undefined, + type: 'flow' | 'connector', + name: string, +): AutomationAddressRefusal | AutomationAddressSlot | undefined { + if (!registry || !canResolve(registry)) return undefined; + const every = resolvePackageScopedName(registry, { type, name, callerPackageId: null, includeDisabledPackages: true }); + if (every.status !== 'refused' || holdersOf(registry, type, name, { includeDisabledPackages: true }).length < 2) { + return every.status === 'refused' ? { status: 409, refusal: every } : undefined; + } + const served = resolvePackageScopedName(registry, { type, name, callerPackageId: null }); + if (served.status === 'refused') return { status: 409, refusal: served }; + if (served.status === 'resolved' && served.holder.kind === 'package') { + return { status: 'slot', packageId: served.holder.packageId, refusal: every }; + } + return undefined; +} + /** * Judge an addressed path's qualifier (see the module note). `undefined` * admits it: the path is then served as its bare path, whose item is the @@ -279,14 +327,16 @@ export function admitAutomationAddress( ? undefined : { status: 404, message: `${noun} '${name}' not found in namespace '${qualifier.namespace}'` }; } - // [#32183, R4-G] A name two or more packages hold over every holder (the - // state #31696 opened for a flow, each holder's flow in its own engine - // slot) is judged over every holder, a disabled package's included, so a - // disable moves no address of it (`main`'s answer). A one-holder name is - // judged over the served holders, as every by-name door is. + // [ADR-0150 D3, #33386] Judged over the served holders, as every by-name + // door is: a disabled package holds no name, so an address naming it is + // never another package's item, and a refusal names the served holders + // only (seat ruling 6884403301, amendments 2 and 6). A name two or more + // packages hold over EVERY holder (the state #31696 opened, each holder's + // item in its own engine slot) is still served from the addressed + // holder's slot: the slots are keyed over every holder (amendment 7). const everyHolder = holdersOf(registry, type, name, { includeDisabledPackages: true }); const shared = everyHolder.length > 1; - const holders = shared ? everyHolder : holdersOf(registry, type, name); + const holders = holdersOf(registry, type, name); let holder: PackageScopedHolder; if (qualifier.kind === 'environment') { if (registry.getEnvironmentScopedItem(type, name) !== undefined || holders.length === 0) return undefined; @@ -313,7 +363,9 @@ export function admitAutomationAddress( // [#31696] A flow name two packages hold: each holder's flow is its own // slot, and the address names one holder of it. [ADR-0150 D9, #31699] // So is a connector name: each holder's instance is its own, and the - // connection door connects the addressed one. + // connection door connects the addressed one. [#33386] The addressed + // holder is a served one (above); the slot's refusal, for the doors + // that cannot serve from it, stays the name's over every holder. return (type === 'flow' || type === 'connector') && holder.kind === 'package' ? { status: 'slot', packageId: holder.packageId, refusal: bare } : { status: 409, refusal: bare }; diff --git a/packages/runtime/src/domains/automation-addressed-route.test.ts b/packages/runtime/src/domains/automation-addressed-route.test.ts index 67d5ae388b3..65b7251a8cd 100644 --- a/packages/runtime/src/domains/automation-addressed-route.test.ts +++ b/packages/runtime/src/domains/automation-addressed-route.test.ts @@ -21,6 +21,7 @@ import { describe, it, expect, vi } from 'vitest'; import '@objectstack/metadata'; import { HttpDispatcher } from '../http-dispatcher.js'; +import { SchemaRegistry } from '@objectstack/objectql'; const CRM = 'com.crm.pkg'; const HR = 'com.hr.pkg'; @@ -492,3 +493,146 @@ describe('/automation/connectors/:ns/:name/connection — a connector instance b expect(automation.getConnectorConnection).not.toHaveBeenCalled(); }); }); + +/** + * [ADR-0150 D3, #33386; seat rulings 6884403301 and Q2 6888807772] A name two + * packages hold, one of them disabled, through the real dispatcher over a real + * `SchemaRegistry` (its `disablePackage`, its served filter), in both + * registration orders. The doors judge the SERVED holders: the bare name is the + * one served holder's slot or instance; an address naming the disabled holder + * is refused naming the served holder only; `_env` and a third namespace name + * the served holder only; with both disabled, nothing is reached. + */ +describe('[#33386] the by-name doors judge the served holders of a name two packages hold', () => { + const OPS = 'com.ops.pkg'; + const ORDERS = [[CRM, HR], [HR, CRM]]; + + function registryOf(order: readonly string[], disabled: readonly string[]) { + const registry = new SchemaRegistry(); + registry.logLevel = 'silent'; + for (const [id, namespace] of [[CRM, 'crm'], [HR, 'hr'], [OPS, 'ops']]) { + registry.installPackage({ id, name: id, version: '1.0.0', type: 'app', namespace } as never, 'code'); + } + for (const holder of order) { + registry.registerItem('flow', { name: 'convert', _packageId: holder }, 'name' as never, holder); + registry.registerItem('connector', { name: 'mail', _packageId: holder }, 'name' as never, holder); + } + for (const id of disabled) registry.disablePackage(id); + return registry; + } + + function dispatcherOver(registry: SchemaRegistry) { + const slotOf = (pkg: string | null, name: string) => (name === 'convert' && pkg !== null && [CRM, HR].includes(pkg) ? `${pkg}/convert` : undefined); + const automation = { + handlerReady: true, + getFlow: vi.fn(async () => null), + execute: vi.fn(async (name: string) => ({ success: false, error: `Flow '${name}' not found` })), + toggleFlow: vi.fn(async () => {}), + listRunsPage: vi.fn(async () => ({ runs: [] as unknown[], hasMore: false })), + getConnectorConnection: vi.fn(async (request: { connector: string }) => ({ connector: request.connector, status: 'not_connected' })), + getActionDescriptors: vi.fn(() => []), + getFlowRuntimeStates: vi.fn(() => []), + flowSlotKey: vi.fn(slotOf), + getFlowSlot: vi.fn((pkg: string | null, name: string) => (slotOf(pkg, name) ? { name, label: `${pkg} flow` } : null)), + executeSlot: vi.fn(async (pkg: string | null) => ({ success: true, output: { ran: pkg } })), + toggleFlowSlot: vi.fn(async () => {}), + }; + const services: Record = { automation, objectql: { registry } }; + const resolve = (name: string) => services[name]; + const kernel: any = { getService: resolve, getServiceAsync: async (name: string) => resolve(name), context: { getService: resolve } }; + const dispatcher = new HttpDispatcher(kernel); + const call = async (path: string, method: string, body: unknown = {}) => { + const answered = await dispatcher.handleAutomation(path, method, body, { request: {}, executionContext: ADMIN } as any, {}); + return { status: answered.response?.status ?? 200, body: answered.response?.body as any }; + }; + return { call, automation }; + } + + const packagesOf = (a: { body?: any }) => (candidatesOf(a) ?? []).map((c: { packageId?: string }) => c.packageId); + + describe.each(ORDERS.map((order) => [order.join(' then '), order] as const))('registered %s', (_o, order) => { + it('CONTROL — nothing disabled: the bare doors refuse naming both; each address is its own slot or instance', async () => { + const { call, automation } = dispatcherOver(registryOf(order, [])); + const bare = await call('/convert/trigger', 'POST'); + expect([bare.status, packagesOf(bare)]).toEqual([409, [...order]]); + const mail = await call('/connectors/mail/connection', 'GET'); + expect([mail.status, packagesOf(mail)]).toEqual([409, [...order]]); + expect((await call('/crm/convert/trigger', 'POST')).status).toBe(200); + expect(automation.executeSlot.mock.calls.map((c) => c[0])).toEqual([CRM]); + expect((await call('/connectors/hr/mail/connection', 'GET')).status).toBe(200); + expect(automation.getConnectorConnection.mock.calls.at(-1)?.[0]).toMatchObject({ connector: 'mail', package: HR }); + }); + + it('CRM disabled — flow: the bare door runs HR\'s slot (FROM 409 naming both); CRM\'s address is refused naming HR (FROM CRM\'s slot ran); HR\'s address is HR\'s slot', async () => { + const { call, automation } = dispatcherOver(registryOf(order, [CRM])); + expect((await call('/convert/trigger', 'POST')).status).toBe(200); + expect(automation.executeSlot.mock.calls.map((c) => c[0])).toEqual([HR]); + const off = await call('/crm/convert/trigger', 'POST'); + expect([off.status, codeOf(off), packagesOf(off)]).toEqual([409, 'RESOURCE_CONFLICT', [HR]]); + expect((await call('/hr/convert/trigger', 'POST')).status).toBe(200); + for (const path of ['/_env/convert/trigger', '/ops/convert/trigger']) { + const other = await call(path, 'POST'); + expect([path, other.status, packagesOf(other)]).toEqual([path, 409, [HR]]); + } + expect(automation.executeSlot.mock.calls.map((c) => c[0])).toEqual([HR, HR]); + expect(automation.execute).not.toHaveBeenCalled(); + }); + + it('CRM disabled — connector (Q2 rows): the address naming CRM is refused naming HR (FROM 404 from the service); HR\'s address and the bare name connect HR\'s instance (bare FROM 409 naming both); `_env` and a third namespace name HR only (FROM naming both)', async () => { + const { call, automation } = dispatcherOver(registryOf(order, [CRM])); + const off = await call('/connectors/crm/mail/connection', 'GET'); + expect([off.status, codeOf(off), packagesOf(off)]).toEqual([409, 'RESOURCE_CONFLICT', [HR]]); + expect(automation.getConnectorConnection).not.toHaveBeenCalled(); + for (const path of ['/connectors/hr/mail/connection', '/connectors/mail/connection']) { + expect((await call(path, 'GET')).status, path).toBe(200); + expect(automation.getConnectorConnection.mock.calls.at(-1)?.[0], path).toMatchObject({ connector: 'mail', package: HR }); + } + for (const path of ['/connectors/_env/mail/connection', '/connectors/ops/mail/connection']) { + const other = await call(path, 'GET'); + expect([path, other.status, packagesOf(other)]).toEqual([path, 409, [HR]]); + } + expect(automation.getConnectorConnection).toHaveBeenCalledTimes(2); + }); + + it('the definition writes (PUT, DELETE, clone) under a disable: an address naming CRM, `_env` or a third namespace is refused naming HR only (FROM: naming both); HR\'s address still names both; both disabled, an address answers 404 (FROM: 409)', async () => { + const writes = (prefix: string) => [ + [`${prefix}/convert`, 'PUT', { name: 'convert', type: 'autolaunched' }], + [`${prefix}/convert`, 'DELETE', {}], + [`${prefix}/convert/clone`, 'POST', { name: 'convert_copy' }], + ] as const; + const oneOff = dispatcherOver(registryOf(order, [CRM])); + for (const prefix of ['/crm', '/_env', '/ops']) { + for (const [path, method, body] of writes(prefix)) { + const answer = await oneOff.call(path, method, body); + expect([path, method, answer.status, codeOf(answer), packagesOf(answer)]).toEqual([path, method, 409, 'RESOURCE_CONFLICT', [HR]]); + } + } + // Not moved: HR's own address keeps the 409 naming every holder. + for (const prefix of ['/hr']) { + for (const [path, method, body] of writes(prefix)) { + const answer = await oneOff.call(path, method, body); + expect([path, method, answer.status, packagesOf(answer).sort()]).toEqual([path, method, 409, [CRM, HR].sort()]); + } + } + const bothOff = dispatcherOver(registryOf(order, [CRM, HR])); + for (const prefix of ['/crm', '/hr']) { + for (const [path, method, body] of writes(prefix)) { + expect([path, method, (await bothOff.call(path, method, body)).status]).toEqual([path, method, 404]); + } + } + for (const h of [oneOff, bothOff]) expect(h.automation.executeSlot).not.toHaveBeenCalled(); + }); + + it('both disabled: no address reaches a flow or an instance (404); the bare door and `_env` reach no slot, and the service answers them with no package', async () => { + const { call, automation } = dispatcherOver(registryOf(order, [CRM, HR])); + for (const path of ['/crm/convert/trigger', '/hr/convert/trigger']) expect((await call(path, 'POST')).status, path).toBe(404); + for (const path of ['/connectors/crm/mail/connection', '/connectors/hr/mail/connection']) expect((await call(path, 'GET')).status, path).toBe(404); + expect((await call('/convert/trigger', 'POST')).status).toBe(404); + expect(automation.executeSlot).not.toHaveBeenCalled(); + for (const path of ['/connectors/mail/connection', '/connectors/_env/mail/connection']) { + await call(path, 'GET'); + expect(automation.getConnectorConnection.mock.calls.at(-1)?.[0], path).not.toHaveProperty('package'); + } + }); + }); +}); diff --git a/packages/runtime/src/domains/automation-run-doors-per-slot.test.ts b/packages/runtime/src/domains/automation-run-doors-per-slot.test.ts index 56f33216114..0dd0854b4c4 100644 --- a/packages/runtime/src/domains/automation-run-doors-per-slot.test.ts +++ b/packages/runtime/src/domains/automation-run-doors-per-slot.test.ts @@ -50,6 +50,8 @@ interface HarnessOptions { bareKeys?: boolean; /** `getRun` answers `null` for every run: only the suspended-run list names it. */ getRunBlind?: boolean; + /** [#33386] Packages disabled in the registry: the served holder read leaves them out (the caller's own holding stays). */ + disabled?: string[]; } function harness(options: HarnessOptions = {}) { @@ -88,10 +90,14 @@ function harness(options: HarnessOptions = {}) { }); } const namespaces: Record = { [CRM]: 'crm', [HR]: 'hr' }; - const holdersOf = (type: string, name: string) => (type === 'flow' && name === NAME ? [CRM, HR] : []); + const disabled = new Set(options.disabled ?? []); + const holdersOf = (type: string, name: string, caller?: string | null, read?: { includeDisabledPackages?: boolean }) => + (type === 'flow' && name === NAME ? [CRM, HR] : []) + .filter((id) => read?.includeDisabledPackages === true || id === caller || !disabled.has(id)); const registry = { getNamespaceOwners: (ns: string) => Object.keys(namespaces).filter((id) => namespaces[id] === ns), packageScopedHoldersOf: holdersOf, + isPackageDisabled: (id: string) => disabled.has(id), getPackageScopedItem: (type: string, name: string, packageId: string) => (holdersOf(type, name).includes(packageId) ? { name, _packageId: packageId } : undefined), getEnvironmentScopedItem: () => undefined, @@ -266,3 +272,48 @@ describe('[ADR-0150 D4, #31696] a bare run door on a shared name acts on the run expect(answer.body?.data?.flowName ?? answer.body?.flowName).toBe(NAME); }); }); + +/** + * [ADR-0150 D3, #33386; seat ruling 6884403301, amendments 2 and 3] The run + * doors while a holder is disabled: a run carries its slot key, and a run of + * the disabled holder's slot is no served holder's — never read or acted on + * as another package's, at the bare door or under any address. The served + * holder's run is served at the bare door and under its own address. + */ +/** {@link expectAnsweredAsNobodys} in the same disabled state: the answer the door gives a run nobody holds there. */ +async function expectNobodysWhile(disabled: string[], door: Door, prefix: string, runId: string) { + const answer = await send(harness({ disabled }), door, prefix, runId); + const nobody = await send(harness({ disabled }), door, prefix, 'r-nobody'); + expect(JSON.stringify(answer).split(runId).join('RUNID'), `${prefix} ${runId}`).toBe(JSON.stringify(nobody).split('r-nobody').join('RUNID')); +} + +describe('[#33386] the run doors while a holder is disabled', () => { + for (const door of DOORS) { + describe(door.label, () => { + it('CRM disabled: HR\'s run is served bare and under `hr`; CRM\'s run is nobody\'s at the bare door, and its verb is never called', async () => { + const h = harness({ disabled: [CRM] }); + for (const prefix of ['/send_digest', '/hr/send_digest']) { + const answer = await send(h, door, prefix, 'r-hr'); + expect(answer.status, `${prefix} ${JSON.stringify(answer.body)}`).toBe(200); + } + expect(verbRunIds(h, door.verb).filter((id: string) => id === 'r-hr').length).toBeGreaterThanOrEqual(door.verb === 'getRun' ? 1 : 2); + await expectNobodysWhile([CRM], door, '/send_digest', 'r-crm'); + if (WRITES.has(door.verb)) expect(verbRunIds(h, door.verb)).not.toContain('r-crm'); + }); + + it('CRM disabled: CRM\'s address is refused 409 naming HR only (FROM: CRM\'s run served), nothing acted on', async () => { + const h = harness({ disabled: [CRM] }); + const answer = await send(h, door, '/crm/send_digest', 'r-crm'); + expect([answer.status, codeOf(answer), candidatesOf(answer)]).toEqual([409, 'RESOURCE_CONFLICT', [{ kind: 'package', packageId: HR }]]); + if (WRITES.has(door.verb)) expect(h.automation[door.verb]).not.toHaveBeenCalled(); + }); + + it('both disabled: either address answers 404; at the bare door each run is nobody\'s', async () => { + const h = harness({ disabled: [CRM, HR] }); + for (const prefix of ['/crm/send_digest', '/hr/send_digest']) expect((await send(h, door, prefix, 'r-crm')).status, prefix).toBe(404); + for (const runId of ['r-crm', 'r-hr']) await expectNobodysWhile([CRM, HR], door, '/send_digest', runId); + if (WRITES.has(door.verb)) expect(h.automation[door.verb]).not.toHaveBeenCalled(); + }); + }); + } +}); diff --git a/packages/runtime/src/domains/automation.ts b/packages/runtime/src/domains/automation.ts index cb06136162b..2ff2dc9a289 100644 --- a/packages/runtime/src/domains/automation.ts +++ b/packages/runtime/src/domains/automation.ts @@ -20,12 +20,13 @@ import { buildApiError } from '../error-envelope.js'; import { admitAutomationAddress, automationAddressRegistryOf, - bareNameRefusal, + bareNameAdmission, readAutomationAddress, automationRouteAllow, AUTOMATION_DOOR_LITERALS, type AutomationAddressRefusal, type AutomationAddressRegistry, + type AutomationAddressSlot, } from './automation-address.js'; // [#31696] One holder's flow of a shared name, served from its own slot; a // start's admission walks callees from the calling flow's package. @@ -1255,7 +1256,7 @@ async function automationRegistryOf(deps: DomainHandlerDeps, context: HttpProtoc /** * [ADR-0150 D5, child G1] The item a BARE by-name run or read names, for the - * bare name's `409` (`bareNameRefusal`): the flow of the trigger, toggle, read + * bare name's `409` (`bareNameAdmission`): the flow of the trigger, toggle, read * and run doors, and the connector instance of the connection door. The * definition writes (`PUT` / `DELETE /:name`, the clone) are absent: they * answer their own `409` with its remedy (`flowWriteRefusal`). @@ -1279,15 +1280,19 @@ function bareByNameItem(parts: readonly string[], method: string): { type: 'flow return undefined; } -/** [ADR-0150 D5, child G1] A bare by-name door's `409`, when the resolver refuses its name. */ -function bareByNameRefusal( +/** + * [ADR-0150 D5, child G1] A bare by-name door's `409`, when the resolver + * refuses its name. [ADR-0150 D3, #33386] Judged over the served holders + * (`bareNameAdmission`): a name two packages hold whose one served holder + * remains is that holder's slot, never a `409` naming a disabled package. + */ +function bareByNameAdmission( registry: AutomationAddressRegistry | undefined, parts: readonly string[], method: string, -): AutomationAddressRefusal | undefined { +): AutomationAddressRefusal | AutomationAddressSlot | undefined { const item = bareByNameItem(parts, method); - const refusal = item ? bareNameRefusal(registry, item.type, item.name) : undefined; - return refusal ? { status: 409, refusal } : undefined; + return item ? bareNameAdmission(registry, item.type, item.name) : undefined; } /** @@ -3861,19 +3866,31 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str // [ADR-0150 D9, #31699] A connector name two packages hold, addressed by // the namespace of one of them: the connection door connects, reads and // revokes that holder's instance (`ConnectorConnectionRequest.package`). + // + // [ADR-0150 D3, #33386] Every admission here is judged over the served + // holders: a bare name two packages hold whose one served holder remains + // is served from that holder's slot, as its address is (seat ruling + // 6884403301). `item` is the address's item, else the bare door's own. let connectorPackage: string | undefined; { + const door = bareByNameItem(parts, m); + const item = address.qualifier ? address.item : door; const admission = address.qualifier && address.item ? admitAutomationAddress(addressRegistry, address.qualifier, address.item) - : bareByNameRefusal(addressRegistry, parts, m); - if (admission?.status === 'slot' && address.item?.type === 'connector' && bareByNameItem(parts, m)?.type === 'connector') { + : bareByNameAdmission(addressRegistry, parts, m); + if (admission?.status === 'slot' && item?.type === 'connector' && door?.type === 'connector') { connectorPackage = admission.packageId; } else if (admission?.status === 'slot') { - const slotted = bareByNameItem(parts, m)?.type === 'flow' && address.item - ? flowSlotView(automationService, admission.packageId, address.item.name) + const slotted = door?.type === 'flow' && item + ? flowSlotView(automationService, admission.packageId, item.name) : undefined; - if (!slotted) return { handled: true, response: automationAddressRefusalResponse(deps, { status: 409, refusal: admission.refusal }) }; - automationService = slotted; + if (slotted) { + automationService = slotted; + } else if (address.qualifier || door?.type !== 'flow') { + return { handled: true, response: automationAddressRefusalResponse(deps, { status: 409, refusal: admission.refusal }) }; + } + // [#33386] Else a bare flow name and no slot entries: the bare + // service, whose bare entries judge the served holders themselves. } else if (admission) { const byRun = !address.qualifier && admission.status === 409 && parts[1] === 'runs' && parts[2] ? await runSlotView(automationService, parts[0], parts[2], admission.refusal.candidates.flatMap((c) => (c.kind === 'package' ? [c.packageId] : []))) diff --git a/packages/runtime/src/flow-caller-package.test.ts b/packages/runtime/src/flow-caller-package.test.ts index 362df24af21..caa9cbf820d 100644 --- a/packages/runtime/src/flow-caller-package.test.ts +++ b/packages/runtime/src/flow-caller-package.test.ts @@ -32,7 +32,7 @@ import { HttpDispatcher } from './http-dispatcher.js'; import { executeEndpointTarget, type EndpointExecutionContext } from './endpoint-executor.js'; import { endpointPackageOf, flowHolderForCaller, flowServiceForCaller, flowSlotView, flowWalkReads } from './flow-slot-view.js'; import { SchemaRegistry, type PackageScopedRegistry } from '@objectstack/objectql'; -import { admitAutomationAddress, bareNameRefusal } from './domains/automation-address.js'; +import { admitAutomationAddress, bareNameAdmission, bareNameRefusal } from './domains/automation-address.js'; const CRM = 'com.crm.pkg'; const HR = 'com.hr.pkg'; @@ -418,22 +418,19 @@ describe('a start\'s record-read walk reads each callee from the calling flow\'s }); /** - * [#32183, ADR-0150 D3; epic ruling R4-G] The flow doors #31696 opened read - * every holder of a flow name, a disabled package's included, so a disable - * moves none of their answers: each answers as `main` does, where the - * registry's holder read did not yet leave a disabled package out. - * - * Read only through the served holders, a disable would move them. With CRM - * disabled, HR's own flow action would reach the bare service (the bare read - * no longer refuses), whose bare entries still refuse the name two engine - * slots hold; a package whose closure holds both would run HR's flow. Both - * moves wait for #32670, the served judgment at the send and run doors. + * [ADR-0150 D3, #33386; seat ruling 6884403301] The flow doors #31696 opened + * judge the SERVED holders of a name two packages hold: a disabled package + * holds no name. Its slot stays armed and keyed in the engine (amendment 7), + * so a disable never re-points a slot; it only moves which slot a door + * reaches. Replaces the R4-G parity pin (`main` held these doors over every + * holder, a disabled package's included). * * Over a real `SchemaRegistry` (its `disablePackage`, its served filter) and - * an engine double holding one slot per holder, as the engine holds them after - * a runtime disable. Pinned as parity: for every non-empty set of disabled - * holders, in both registration orders, every door answers what it answers - * with nothing disabled. The CONTROLs say what that answer is. + * an engine double holding one slot per holder whose BARE entries judge the + * served holders, as the engine's do after this change (service-automation + * `engine.ts` `resolveFlowKey`, pinned there): one served holder runs that + * slot, two refuse naming them, none is no flow. Every row of the PR's + * Clause-② table for these doors is asserted per registration order. */ /** Depends on both holders. */ @@ -465,13 +462,25 @@ function registryOf(order: readonly string[], disabled: readonly string[]): Sche return registry; } -/** One slot per holder, the bare entries refusing the shared name, as the engine's do. */ -function engineWithBothSlots() { - const refusal = () => Object.assign(new Error(`Flow '${FLOW}' is held by several packages`), { code: 'RESOURCE_CONFLICT', status: 409 }); +/** One slot per holder; the bare entries judge the served holders, as the engine's do. */ +function engineWithBothSlots(registry: SchemaRegistry) { + const served = () => registry.packageScopedHoldersOf('flow', FLOW, null); + const refusal = (holders: string[]) => Object.assign(new Error(`Flow '${FLOW}' is held by ${holders.join(' and ')}`), { + code: 'RESOURCE_CONFLICT', status: 409, refusal: { candidates: holders.map((packageId) => ({ kind: 'package', packageId })) }, + }); + const bareSlot = (name: string): string | null => { + if (name !== FLOW) return null; + const holders = served(); + if (holders.length > 1) throw refusal(holders); + return holders[0] ?? null; + }; return { handlerReady: true, - getFlow: vi.fn(async (name: string) => { if (name === FLOW) throw refusal(); return null; }), - execute: vi.fn(async (name: string) => { if (name === FLOW) throw refusal(); return { success: true }; }), + getFlow: vi.fn(async (name: string) => { const pkg = bareSlot(name); return pkg ? { name, label: `${pkg} flow` } : null; }), + execute: vi.fn(async (name: string) => { + const pkg = bareSlot(name); + return pkg ? { success: true, output: { ran: pkg } } : { success: false, error: `Flow '${name}' not found` }; + }), flowSlotKey: vi.fn((pkg: string | null, name: string) => (name === FLOW && pkg !== null && HOLDERS.includes(pkg) ? `${pkg}/${FLOW}` : undefined)), getFlowSlot: vi.fn((pkg: string | null, name: string) => (name === FLOW && pkg !== null && HOLDERS.includes(pkg) ? { name, label: `${pkg} flow` } : null)), executeSlot: vi.fn(async (pkg: string | null) => ({ success: true, output: { ran: pkg } })), @@ -482,35 +491,38 @@ function engineWithBothSlots() { /** What a thrown refusal names, or its message. */ const refusalOf = (err: any) => ['refused', err?.refusal?.candidates?.map((c: any) => c.packageId ?? c.kind) ?? String(err?.message)]; +/** A run's answer: the slot it ran, or no flow. */ +const ranOf = (result: any) => (result?.success ? ['ran', result.output.ran] : ['no flow']); + /** Every door's answer, per caller and per namespace. */ async function answersOf(registry: SchemaRegistry) { const out: Record = {}; for (const caller of CALLERS) { - const engine = engineWithBothSlots(); + const engine = engineWithBothSlots(registry); try { const service = flowServiceForCaller(engine, registry, FLOW, caller); - await service.execute(FLOW); - out[`action ${caller}`] = ['ran', engine.executeSlot.mock.calls.map((c) => c[0])]; + out[`action ${caller}`] = ranOf(await service.execute(FLOW)); } catch (err) { out[`action ${caller}`] = refusalOf(err); } out[`holder ${caller}`] = flowHolderForCaller(registry, FLOW, caller); - const walk = flowWalkReads(engineWithBothSlots(), async () => registry); + const walk = flowWalkReads(engineWithBothSlots(registry), async () => registry); try { const callee = await walk.callee(FLOW, caller ?? null); - out[`callee ${caller}`] = ['read', callee.packageId, (callee.flow as { label?: string } | null)?.label]; + out[`callee ${caller}`] = callee.flow === null ? ['no flow'] : ['read', callee.packageId, (callee.flow as { label?: string } | null)?.label]; } catch (err) { out[`callee ${caller}`] = refusalOf(err); } } - out.root = await flowWalkReads(engineWithBothSlots(), async () => registry).rootPackage(FLOW); + out.root = await flowWalkReads(engineWithBothSlots(registry), async () => registry).rootPackage(FLOW); out.endpoint = endpointPackageOf(registry, API); - out.bare = bareNameRefusal(registry, 'flow', FLOW)?.candidates.map((c: any) => c.packageId ?? c.kind); + out.durable = bareNameRefusal(registry, 'flow', FLOW)?.candidates.map((c: any) => c.packageId ?? c.kind); const addressOf = (admitted: ReturnType) => { if (admitted === undefined) return 'bare path'; if ('packageId' in admitted) return ['slot', admitted.packageId]; return [admitted.status, 'refusal' in admitted ? admitted.refusal.candidates.map((c: any) => c.packageId ?? c.kind) : undefined]; }; + out.bare = addressOf(bareNameAdmission(registry, 'flow', FLOW)); for (const namespace of NAMESPACES) { out[`address ${namespace}`] = addressOf(admitAutomationAddress(registry, { kind: 'namespace', namespace }, { type: 'flow', name: FLOW })); } @@ -519,27 +531,101 @@ async function answersOf(registry: SchemaRegistry) { } const ORDERS = [HOLDERS, [...HOLDERS].reverse()]; -const DISABLED_SETS = [[CRM], [HR], [CRM, HR]]; -describe('the #31696 flow doors read every holder: a disable moves no answer (ADR-0150 D3, R4-G, #32183)', () => { - it.each(ORDERS.flatMap((order) => DISABLED_SETS.map((disabled) => [order.join(' then '), disabled.join(' and '), order, disabled] as const)))( - 'registered %s, %s disabled: every door answers as with nothing disabled', - async (_o, _d, order, disabled) => { - expect(await answersOf(registryOf(order, disabled))).toEqual(await answersOf(registryOf(order, []))); - }, - ); - - it.each(ORDERS.map((order) => [order.join(' then '), order] as const))('CONTROL — registered %s, nothing disabled: what `main` answers', async (_o, order) => { - const answers = await answersOf(registryOf(order, [])); - expect(answers[`action ${HR}`]).toEqual(['ran', [HR]]); - expect(answers[`action ${OPS}`]).toEqual(['ran', [CRM]]); - expect(answers[`action ${BOTH}`]).toEqual(['refused', [...order]]); - expect(answers['action undefined']).toEqual(['refused', `Flow '${FLOW}' is held by several packages`]); - expect(answers[`callee ${HR}`]).toEqual(['read', HR, `${HR} flow`]); - expect(answers[`holder ${BOTH}`]).toBeUndefined(); - expect(answers.bare).toEqual([...order]); - expect(answers.endpoint).toBeUndefined(); - expect(answers['address crm']).toEqual(['slot', CRM]); - expect(answers['address hr']).toEqual(['slot', HR]); +/** The answers with `off` disabled and `on` the one served holder. */ +function oneServed(off: string, on: string, order: readonly string[]) { + return { + // the bare caller and the caller whose closure holds both: the served holder's slot (amendments 1, 5) + 'action undefined': ['ran', on], + [`action ${BOTH}`]: ['ran', on], + // caller-first (amendment 4): the disabled holder's own action gets no flow, never the closure holder's + [`action ${off}`]: ['no flow'], + [`action ${on}`]: ['ran', on], + // reached only through the disabled holder, or reaching neither: refused naming the served holder only (amendment 6) + [`action ${OPS}`]: off === CRM ? ['refused', [on]] : ['ran', CRM], + [`action ${NONE}`]: ['refused', [on]], + 'holder undefined': on, + [`holder ${BOTH}`]: on, + [`holder ${off}`]: undefined, + [`holder ${on}`]: on, + [`holder ${OPS}`]: off === CRM ? undefined : CRM, + [`holder ${NONE}`]: undefined, + // the walk reads the slot the run executes (amendment 8) + 'callee undefined': ['read', on, `${on} flow`], + [`callee ${BOTH}`]: ['read', on, `${on} flow`], + [`callee ${off}`]: ['no flow'], + [`callee ${on}`]: ['read', on, `${on} flow`], + [`callee ${OPS}`]: off === CRM ? ['refused', [on]] : ['read', CRM, `${CRM} flow`], + [`callee ${NONE}`]: ['refused', [on]], + root: on, + // durable coordinates stay judged over every holder (amendment 7) + endpoint: undefined, + durable: [...order], + bare: ['slot', on], + // an address naming the disabled holder is never another package's flow (amendment 2) + [`address ${off === CRM ? 'crm' : 'hr'}`]: [409, [on]], + [`address ${on === CRM ? 'crm' : 'hr'}`]: ['slot', on], + 'address ops': [409, [on]], + 'address none': [409, [on]], + 'address _env': [409, [on]], + }; +} + +describe('the #31696 flow doors judge the served holders (ADR-0150 D3, #33386)', () => { + describe.each(ORDERS.map((order) => [order.join(' then '), order] as const))('registered %s', (_o, order) => { + it('CONTROL — nothing disabled: what `main` answers', async () => { + const answers = await answersOf(registryOf(order, [])); + expect(answers[`action ${HR}`]).toEqual(['ran', HR]); + expect(answers[`action ${OPS}`]).toEqual(['ran', CRM]); + expect(answers[`action ${BOTH}`]).toEqual(['refused', [...order]]); + expect(answers['action undefined']).toEqual(['refused', [...order]]); + expect(answers[`action ${NONE}`]).toEqual(['refused', [...order]]); + expect(answers[`callee ${HR}`]).toEqual(['read', HR, `${HR} flow`]); + expect(answers['callee undefined']).toEqual(['refused', [...order]]); + expect(answers[`holder ${BOTH}`]).toBeUndefined(); + expect(answers.root).toBeNull(); + expect(answers.durable).toEqual([...order]); + expect(answers.bare).toEqual([409, [...order]]); + expect(answers.endpoint).toBeUndefined(); + expect(answers['address crm']).toEqual(['slot', CRM]); + expect(answers['address hr']).toEqual(['slot', HR]); + expect(answers['address ops']).toEqual([409, [...order]]); + expect(answers['address _env']).toEqual([409, [...order]]); + }); + + it.each([[CRM, HR], [HR, CRM]])('%s disabled: every door answers the one served holder\'s slot, or no flow, or a refusal naming it', async (off, on) => { + expect(await answersOf(registryOf(order, [off]))).toEqual(oneServed(off, on, order)); + }); + + it('both disabled: no door reaches a flow; the durable coordinates still name both', async () => { + const answers = await answersOf(registryOf(order, [CRM, HR])); + for (const caller of CALLERS) { + expect(answers[`action ${caller}`], `action ${caller}`).toEqual(['no flow']); + expect(answers[`holder ${caller}`], `holder ${caller}`).toBeUndefined(); + expect(answers[`callee ${caller}`], `callee ${caller}`).toEqual(['no flow']); + } + expect(answers.root).toBeNull(); + expect(answers.durable).toEqual([...order]); + expect(answers.bare).toBe('bare path'); + for (const namespace of NAMESPACES) expect(answers[`address ${namespace}`], namespace).toEqual([404, undefined]); + expect(answers['address _env']).toBe('bare path'); + }); + + it('CONTROL — one holder, disabled: judged as `main` judges it (not a name two packages hold)', async () => { + const registry = registryOf([CRM], [CRM]); + const engine = engineWithBothSlots(registry); + expect(flowServiceForCaller(engine, registry, FLOW, CRM)).toBe(engine); + expect(bareNameAdmission(registry, 'flow', FLOW)).toBeUndefined(); + expect(addressOrNone(admitAutomationAddress(registry, { kind: 'namespace', namespace: 'crm' }, { type: 'flow', name: FLOW }))).toBe(404); + }); + + it('CONTROL — no holder: no admission, no flow', async () => { + const registry = new SchemaRegistry(); + registry.logLevel = 'silent'; + expect(bareNameAdmission(registry, 'flow', FLOW)).toBeUndefined(); + expect(flowHolderForCaller(registry, FLOW, undefined)).toBeUndefined(); + }); }); }); + +const addressOrNone = (admitted: ReturnType) => (admitted && 'status' in admitted ? admitted.status : admitted); diff --git a/packages/runtime/src/flow-slot-view.ts b/packages/runtime/src/flow-slot-view.ts index 997e0ffc638..0fa71c777aa 100644 --- a/packages/runtime/src/flow-slot-view.ts +++ b/packages/runtime/src/flow-slot-view.ts @@ -30,15 +30,19 @@ * ⛔ No slot entries, no view: a door then keeps the bare service, whose bare * entries refuse the shared name. Never a guess at which holder was meant. * - * [#32183, ADR-0150 D3; epic ruling R4-G] Every answer here is judged over - * EVERY holder of the name, a disabled package's included, so each is the - * answer `main` gives: a disable moves none of them. The engine keeps a - * disabled package's slot armed (a runtime disable unregisters nothing from - * it), so a read over the served holders alone would move these doors both - * ways: an enabled holder's own flow action would reach the bare entries, - * which still refuse the name two slots hold, and a closure holding both - * would run the enabled holder's flow. The served judgment of the send and - * run doors is #32670's. + * [ADR-0150 D3, #33386; seat ruling 6884403301] A name two packages hold is + * judged over the SERVED holders (a disabled package holds no name), as the + * engine's bare entries judge it: a caller reaches its own flow, else the one + * served holder in its closure (two or more: refused naming the served + * holders only, `ambiguous-in-closure`); a caller with no package reaches the + * name's one served holder. A caller whose own holding is the disabled one + * gets no flow ({@link absentFlowView}), never a closure holder's + * (amendment 4). A slot is `(package, name)` and is never re-pointed: the + * engine keeps a disabled package's slot armed and keyed (amendment 7), and + * a disable only moves which slot a caller reaches. A name one package holds, + * or none, is judged over every holder, unchanged. {@link endpointPackageOf} + * stays judged over every holder: it names the package an endpoint item + * belongs to, the caller the flow is then resolved for. */ import { PackageScopedNameRefusedError } from '@objectstack/core'; @@ -46,11 +50,32 @@ import { resolvePackageScopedName, type PackageScopedRegistry } from '@objectsta import type { FlowWalkReads } from './flow-start-admission.js'; /** - * [#32183, R4-G] Every resolution in this module reads every holder, a - * disabled package's included (see the module note). + * [#32183] The read over every holder, a disabled package's included: whether + * a name is held by two packages at all (the engine's slot table reads the + * same), and the endpoint's package (see the module note). */ const EVERY_HOLDER = { includeDisabledPackages: true } as const; +/** + * [ADR-0150 D3, #33386] The flow `name` resolves to for `callerPackageId` + * (`null`: none) over the served holders. The served holder read keeps a + * caller's own holding even when its package is disabled; such a caller + * reaches no flow (amendment 4): `not-found`, never a closure holder's. + */ +function servedFlowResolution(registry: PackageScopedRegistry, name: string, callerPackageId: string | null): ReturnType { + const resolution = resolvePackageScopedName(registry, { type: 'flow', name, callerPackageId }); + if (callerPackageId !== null && resolution.status === 'resolved' && resolution.via === 'own') { + const disabled = (registry as { isPackageDisabled?: (id: string) => boolean }).isPackageDisabled; + if (typeof disabled === 'function' && disabled.call(registry, callerPackageId) === true) return { status: 'not-found' }; + } + return resolution; +} + +/** Is `name` held by two or more packages over every holder (each holder's flow is then its own engine slot)? */ +function heldByMany(registry: PackageScopedRegistry, name: string): boolean { + return resolvePackageScopedName(registry, { type: 'flow', name, callerPackageId: null, ...EVERY_HOLDER }).status === 'refused'; +} + /** The engine-local slot entries (service-automation's `AutomationEngine`). */ interface FlowSlotEntries { executeSlot(packageId: string | null, name: string, context?: unknown): Promise; @@ -88,7 +113,30 @@ function slotEntriesOf(service: unknown): FlowSlotEntries | undefined { */ export function flowSlotView(service: T, packageId: string, name: string): T | undefined { const slots = slotEntriesOf(service); - if (!slots) return undefined; + return slots ? boundView(service, slots, { packageId, name }) : undefined; +} + +/** + * [ADR-0150 D3, #33386] `service` with its by-name members for `name` bound to + * NO flow: the answer a name gets that no served holder reaches for its + * caller (seat ruling 6884403301: no flow). It reads as a flow the engine + * does not hold — `getFlow` `null`, `execute` not found, no runs — and never + * as another slot's. `undefined` when the service has no slot entries. + */ +export function absentFlowView(service: T, name: string): T | undefined { + if (!slotEntriesOf(service)) return undefined; + const none: FlowSlotEntries = { + executeSlot: async () => ({ success: false, error: `Flow '${name}' not found` }), + getFlowSlot: () => null, + toggleFlowSlot: async () => { throw new Error(`Flow '${name}' not found`); }, + flowSlotKey: () => undefined, + }; + return boundView(service, none, { name }); +} + +function boundView(service: T, slots: FlowSlotEntries, slot: { packageId?: string; name: string }): T { + const { name } = slot; + const packageId = slot.packageId ?? ''; const target = service as Record; const key = (): string | undefined => slots.flowSlotKey(packageId, name); // A run of this slot reads as a run of the name the door addressed. A run @@ -128,7 +176,7 @@ export function flowSlotView(service: T, packageId: string, na }; return new Proxy(service, { get(held, prop) { - if (prop === BOUND_SLOT) return { packageId, name }; + if (prop === BOUND_SLOT) return slot.packageId === undefined ? undefined : { packageId, name }; const value = Reflect.get(held, prop, held); if (typeof value !== 'function') return value; return typeof prop === 'string' && Object.prototype.hasOwnProperty.call(bound, prop) ? bound[prop] : value.bind(held); @@ -154,12 +202,13 @@ function canResolveForCaller(registry: Partial): registry * * - A name a caller with no package reaches (one holder, or none) is the * service itself, as before: its bare entries serve it. - * - A name two packages hold, which the bare entries refuse, resolves for the - * caller's package: its own flow, else the one holder in its closure, - * served from that holder's slot ({@link flowSlotView}). A name the - * resolver refuses for that package throws its refusal - * (`PackageScopedNameRefusedError`, 409, every candidate named), before - * anything is read or run. + * - A name two packages hold resolves for the caller's package over the + * served holders (#33386): its own flow, else the one served holder in its + * closure, served from that holder's slot ({@link flowSlotView}). A name + * the resolver refuses for that package throws its refusal + * (`PackageScopedNameRefusedError`, 409, every served candidate named), + * before anything is read or run. A caller whose own holding is disabled, + * or that no served holder answers, gets no flow ({@link absentFlowView}). * - No caller package, a registry that cannot answer, or an engine with no * slot entries: the service itself, whose bare entries refuse the shared * name, naming both (fail closed). @@ -171,10 +220,10 @@ export function flowServiceForCaller( callerPackageId: string | undefined, ): T { if (!callerPackageId || typeof name !== 'string' || name === '' || !registry || !canResolveForCaller(registry)) return service; - const bare = resolvePackageScopedName(registry, { type: 'flow', name, callerPackageId: null, ...EVERY_HOLDER }); - if (bare.status !== 'refused') return service; - const own = resolvePackageScopedName(registry, { type: 'flow', name, callerPackageId, ...EVERY_HOLDER }); + if (!heldByMany(registry, name)) return service; + const own = servedFlowResolution(registry, name, callerPackageId); if (own.status === 'refused') throw new PackageScopedNameRefusedError(own); + if (own.status === 'not-found') return absentFlowView(service, name) ?? service; if (own.status !== 'resolved' || own.holder.kind !== 'package') return service; return flowSlotView(service, own.holder.packageId, name) ?? service; } @@ -199,12 +248,15 @@ export function endpointPackageOf(registry: Partial | und * - the started flow's package: the slot `service` is bound to when it is a * {@link flowSlotView} of that flow, else the one holder the bare name * resolves to (`null` for the environment's own flow, or none); - * - a `subflow` / `map` callee: a name a caller with no package reaches is - * the bare read, as before; a name two packages hold resolves from the - * CALLING flow's package (its own flow, else the one holder in its - * closure), read from that holder's slot, and a name that resolver refuses - * throws its refusal (`409`, every candidate named), as the run's call - * would answer. + * - a `subflow` / `map` callee: a name one package holds, or none, is the + * bare read, as before; a name two packages hold resolves from the CALLING + * flow's package over the served holders (#33386; its own flow, else the + * one served holder in its closure; no package: the one served holder), + * read from that holder's slot, and a name that resolver refuses throws + * its refusal (`409`, every served candidate named), as the run's call + * would answer. No served holder for the caller, or a caller whose own + * holding is disabled: no flow (`null`), never another slot's + * (amendments 4 and 8: the walk reads the slot the run executes). * * ⛔ A registry that cannot answer, or an engine with no slot entries, reads * every callee bare, whose read refuses a shared name (fail closed). @@ -226,7 +278,9 @@ export function flowWalkReads( const bound = boundSlotOf(service); if (bound && bound.name === flowName) return bound.packageId; const table = await resolver(); - return table ? packageOf(resolvePackageScopedName(table, { type: 'flow', name: flowName, callerPackageId: null, ...EVERY_HOLDER })) : null; + if (!table) return null; + const every = resolvePackageScopedName(table, { type: 'flow', name: flowName, callerPackageId: null, ...EVERY_HOLDER }); + return packageOf(every.status === 'refused' ? servedFlowResolution(table, flowName, null) : every); }, async callee(name, callerPackageId) { const table = await resolver(); @@ -234,8 +288,9 @@ export function flowWalkReads( if (!table || !slots) return { flow: await bareRead(name), packageId: null }; const bare = resolvePackageScopedName(table, { type: 'flow', name, callerPackageId: null, ...EVERY_HOLDER }); if (bare.status !== 'refused') return { flow: await bareRead(name), packageId: packageOf(bare) }; - const own = resolvePackageScopedName(table, { type: 'flow', name, callerPackageId, ...EVERY_HOLDER }); + const own = servedFlowResolution(table, name, callerPackageId); if (own.status === 'refused') throw new PackageScopedNameRefusedError(own); + if (own.status === 'not-found') return { flow: null, packageId: null }; const holder = packageOf(own); if (holder === null) return { flow: await bareRead(name), packageId: null }; return { flow: slots.getFlowSlot(holder, name) ?? null, packageId: holder }; @@ -271,22 +326,29 @@ export function flowHolderForCaller( callerPackageId: string | undefined, ): string | undefined { if (!registry || !canResolveForCaller(registry)) return undefined; - const resolution = resolvePackageScopedName(registry, { type: 'flow', name, callerPackageId: callerPackageId ?? null, ...EVERY_HOLDER }); + const every = resolvePackageScopedName(registry, { type: 'flow', name, callerPackageId: callerPackageId ?? null, ...EVERY_HOLDER }); + // [#33386] A name two packages hold: over the served holders, as the run does. + const resolution = heldByMany(registry, name) ? servedFlowResolution(registry, name, callerPackageId ?? null) : every; return resolution.status === 'resolved' && resolution.holder.kind === 'package' ? resolution.holder.packageId : undefined; } /** * [ADR-0150 D4, #31696] The package whose slot of `name` the engine files * under the run key `key`: the key's own package for `PACKAGE/name`; for any - * other key, the one package of `holders` (every holder the registry names) - * whose slot is filed under it. `undefined` when no holder's is, or two or + * other key, the one package of `holders` (the holders the caller judges by) + * whose slot is filed under it; a key's own package outside `holders` is no + * answer (#33386). `undefined` when no holder's is, or two or * more are: the run is then no one holder's. */ export function runSlotPackage(service: unknown, name: string, key: unknown, holders: readonly string[]): string | undefined { const slots = slotEntriesOf(service); const flow = runFlowOf(key); if (!slots || !flow || flow.name !== name) return undefined; - const filed = (flow.packageId === undefined ? holders : [flow.packageId]).filter((packageId) => slots.flowSlotKey(packageId, name) === key); + // [#33386] A key's own package counts only while it is one of `holders`: + // a run of a disabled holder's slot is no served holder's (seat ruling + // 6884403301, amendment 3), never substituted. + const filed = (flow.packageId === undefined ? holders : [flow.packageId]) + .filter((packageId) => holders.includes(packageId) && slots.flowSlotKey(packageId, name) === key); return filed.length === 1 ? filed[0] : undefined; } diff --git a/packages/runtime/src/mcp-resume-run.test.ts b/packages/runtime/src/mcp-resume-run.test.ts index eaf8e18bde6..00b93e678bc 100644 --- a/packages/runtime/src/mcp-resume-run.test.ts +++ b/packages/runtime/src/mcp-resume-run.test.ts @@ -863,6 +863,57 @@ describe('MCP resumeRun — a run of a flow name two namespaces hold (ADR-0150 D expect(hr.engine.resume).not.toHaveBeenCalled(); }); + /** + * [ADR-0150 D3, #33386; seat ruling 6884403301, amendments 3 and 4] CRM + * disabled: a run filed under CRM's slot key is no served holder's. CRM's + * own action reaches no flow (a disabled caller's own holding answers + * none), so it cannot resume CRM's run; HR's action reaches HR's flow, + * never CRM's run. HR's run is still resumed through HR's own action. + */ + const withCrmDisabled = { + ...registry, + isPackageDisabled: (id: string) => id === CRM, + // The registry's served read: a disabled package holds no name, but the caller's own holding stays. + packageScopedHoldersOf: (type: string, name: string, caller?: string | null, read?: { includeDisabledPackages?: boolean }) => + registry.packageScopedHoldersOf(type, name).filter((id) => read?.includeDisabledPackages === true || id === caller || id !== CRM), + }; + it('[#33386] CRM disabled: CRM\'s paused run is resumed by no action (FROM: CRM\'s own action resumed it), and stays parked', async () => { + for (const objectPackage of [CRM, HR]) { + const h = makeHarness({ actions: [SCHEDULE], objectPackage, registry: withCrmDisabled }); + const runId = parkedRunOf(h, CRM); + const refusal = await refusalOf(h.bridgeFor('u1').resumeRun(runId, { values: { subject: 'Call back' } })); + expect(refusal.status, objectPackage).toBe(403); + expect([h.engine.resume.mock.calls.length, h.engine.runs.get(runId)?.status], objectPackage).toEqual([0, 'paused']); + } + }); + + it('[#33386] CONTROL — CRM disabled: HR\'s paused run is resumed through HR\'s own action, as before', async () => { + const h = makeHarness({ actions: [SCHEDULE], objectPackage: HR, registry: withCrmDisabled }); + const runId = parkedRunOf(h, HR); + const resumed = await h.bridgeFor('u1').resumeRun(runId, { values: { subject: 'Call back' } }); + expect(resumed).toMatchObject({ ok: true, action: SCHEDULE.name }); + expect(h.engine.resume.mock.calls.map((c: unknown[]) => c[0])).toEqual([runId]); + }); + + it('[#33386] CRM disabled: HR\'s paused run is resumed through a package-less action and through BOTH\'s (depends on CRM and HR) (FROM: 403, the name answered two holders)', async () => { + const BOTH = 'com.both.pkg'; + const manifestOf = (id: string) => (id === BOTH + ? { id, namespace: 'both', dependencies: { [CRM]: '^1.0.0', [HR]: '^1.0.0' } } + : { id, namespace: id === CRM ? 'crm' : 'hr' }); + const withBoth = { + ...withCrmDisabled, + getPackage: (id: string) => ({ manifest: manifestOf(id), source: 'code' }), + getAllPackages: () => [CRM, HR, BOTH].map((id) => ({ manifest: manifestOf(id), source: 'code' })), + }; + for (const objectPackage of [undefined, BOTH]) { + const h = makeHarness({ actions: [SCHEDULE], ...(objectPackage ? { objectPackage } : {}), registry: withBoth }); + const runId = parkedRunOf(h, HR); + const resumed = await h.bridgeFor('u1').resumeRun(runId, { values: { subject: 'Call back' } }); + expect(resumed, String(objectPackage)).toMatchObject({ ok: true, action: SCHEDULE.name }); + expect(h.engine.resume.mock.calls.map((c: unknown[]) => c[0]), String(objectPackage)).toEqual([runId]); + } + }); + for (const [filed, what] of [[[], 'no holder\'s slot'], [[CRM, HR], 'both holders\' slots (CONTROL)']] as const) { it(`[R3-B] a run under a key ${what} is filed under is refused 409 naming every holder, and stays parked`, async () => { const h = makeHarness({ actions: [SCHEDULE], objectPackage: CRM, registry }); diff --git a/packages/services/service-automation/src/connector-connection-door.test.ts b/packages/services/service-automation/src/connector-connection-door.test.ts index 5a557b2af1f..a05eb39b35b 100644 --- a/packages/services/service-automation/src/connector-connection-door.test.ts +++ b/packages/services/service-automation/src/connector-connection-door.test.ts @@ -1074,6 +1074,22 @@ describe('ADR-0150 D4 [#31699] — the connection door connects one instance, by expect(await rowsOf(ql)).toHaveLength(1); }); + it('[#33386] the same state read through the served holder\'s package (what the runtime door now passes for the bare name, and passed already for that holder\'s address): the same 409, and the row stays', async () => { + const registry = registryHolding('com.example.crm'); + const { engine, ql } = await boot([crm()], { registry }); + await packagelessRow(ql, 'conn_a', 'org_a'); + hold(registry, OTHER); + registry.disablePackage(OTHER); + for (const leg of [ + () => engine.getConnectorConnection({ connector: 'crm', package: 'com.example.crm', context: ADMIN_A as never }), + () => engine.revokeConnectorConnection({ connector: 'crm', package: 'com.example.crm', context: ADMIN_A as never }), + ]) { + const err = (await leg().catch((e: unknown) => e)) as Record; + expect(err).toMatchObject({ status: 409, message: expect.stringContaining('stored-references bind') }); + } + expect(await rowsOf(ql)).toHaveLength(1); + }); + it('an entry with no package stamp, or the compatibility default, is the instance of the package the name resolves to: its row stays its own once the backfill binds it', async () => { for (const stamp of [undefined, '__runtime__']) { const { connect, call, engine, ql } = await boot([crm({ _packageId: stamp })], { registry: registryHolding('com.example.crm') }); diff --git a/packages/services/service-automation/src/engine.ts b/packages/services/service-automation/src/engine.ts index 3c5396f23dc..f1d40265eb1 100644 --- a/packages/services/service-automation/src/engine.ts +++ b/packages/services/service-automation/src/engine.ts @@ -2739,11 +2739,18 @@ export type PackagedFlowSource = (name: string, packageId?: string) => string | * [#32183] It judges the served holders: a disabled package holds no name. * `options.includeDisabledPackages` asks it over every holder instead, the * question a durable judgment asks ({@link AutomationEngine.durableFlowHolder}). + * + * [ADR-0150 D3, #33386] `options.servedCaller` asks the run's question: the + * served holders, and a caller whose OWN holding answers is answered only + * while its package is served. The served holder read keeps a disabled + * caller's own holding (so the activation ledger's `stillHolds` still finds + * it); a run of that caller gets no flow from it, and never a closure + * holder's (seat ruling 6884403301, amendment 4): `not-found`. */ export type FlowNameResolver = ( name: string, callerPackageId: string | null, - options?: { readonly includeDisabledPackages?: boolean }, + options?: { readonly includeDisabledPackages?: boolean; readonly servedCaller?: boolean }, ) => PackageScopedResolution | undefined; /** @@ -5206,27 +5213,43 @@ export class AutomationEngine implements IAutomationService { /** * [ADR-0150 D3, #31696] The key the bare flow name `name` means for a * caller of package `callerPackageId` (`null`: a caller with no package), - * or the refusal. A name one slot holds is its own key, refused only by - * the resolver, as before slots. A name two slots hold resolves through - * the resolver to the holder it reaches; the caller's own slot, when no - * resolver is attached; else it is refused, naming every holder. - */ - private resolveFlowKey(name: string, callerPackageId: string | null): { key: string } | { refusal: PackageScopedRefusal } { + * the refusal, or `absent`. A name one slot holds is its own key, refused + * only by the resolver, as before slots. A name two slots hold resolves + * through the resolver to the holder it reaches; the caller's own slot, + * when no resolver is attached; else it is refused, naming every holder. + * + * [ADR-0150 D3, #33386; seat ruling 6884403301] A name two slots hold is + * resolved over the SERVED holders (a disabled package holds no name): + * one served holder is that holder's slot, two or more are refused naming + * the served holders only, and none is `absent` (no flow). A caller whose + * own holding is the disabled one is `absent`, never a closure holder's + * (`servedCaller`, amendment 4). The slots themselves stay keyed over every + * holder ({@link flowSlots}, amendment 7): a disable re-points no slot, it + * only moves which slot a bare name reaches. `durable` asks over every + * holder instead, as `main` did: the subflow guards' recorded arming + * verdicts ({@link flowCallKey}), which a reversible disable re-judges + * nowhere. + */ + private resolveFlowKey( + name: string, + callerPackageId: string | null, + options?: { readonly durable?: boolean }, + ): { key: string } | { refusal: PackageScopedRefusal } | { absent: true } { // [#31696] A slot key is no flow's name: it names no flow here. if (isSlotKeySpelling(name)) return { key: unfiledFlowKey(name) }; if (!this.flowSlots.isShared(name)) { const refusal = this.flowNameRefusal(name, callerPackageId); return refusal ? { refusal } : { key: name }; } - // [#32183, R4-G] A name two slots hold resolves over every holder, a - // disabled package's included: a disable keeps its slot armed and - // moves no caller's answer (`main`'s). The served judgment is #32670's. - const resolution = this.flowNameResolver?.(name, callerPackageId, { includeDisabledPackages: true }); + const resolution = this.flowNameResolver?.(name, callerPackageId, + options?.durable === true ? { includeDisabledPackages: true } : { servedCaller: true }); if (resolution?.status === 'refused') return { refusal: resolution }; if (resolution?.status === 'resolved' && resolution.holder.kind === 'package') { const key = this.flowSlots.keyOf(name, resolution.holder.packageId); if (key !== undefined) return { key }; } + // [#33386] No served holder reaches the name: no flow, never another slot. + if (resolution?.status === 'not-found' && options?.durable !== true) return { absent: true }; if (resolution === undefined && callerPackageId !== null) { const own = this.flowSlots.keyOf(name, callerPackageId); if (own !== undefined) return { key: own }; @@ -5239,6 +5262,8 @@ export class AutomationEngine implements IAutomationService { * package, the refusal thrown (409, every holder named). `undefined` for a * slot-key spelling (`PACKAGE/NAME`): no flow is named so, so the door * answers as for a flow it does not hold ({@link getFlowSlot} takes one). + * The removal and history entries read it: a shared name stays refused + * there over every holder, served or not. */ private bareFlowKey(name: string): string | undefined { if (isSlotKeySpelling(name)) return undefined; @@ -5246,6 +5271,23 @@ export class AutomationEngine implements IAutomationService { throw new PackageScopedNameRefusedError(this.sharedFlowNameRefusal(name, null)); } + /** + * [ADR-0150 D3, #33386] The key the bare entries that READ or RUN a flow + * ({@link execute}'s caller-less twin, {@link getFlow}, {@link toggleFlow}) + * serve for `name`, judged over the served holders ({@link resolveFlowKey}): + * a name two slots hold is its one served holder's slot, refused naming + * the served holders when two or more serve it, and `undefined` (no flow) + * when none does. Seat ruling 6884403301, amendment 9: these entries move + * with the doors. + */ + private servedBareFlowKey(name: string): string | undefined { + if (isSlotKeySpelling(name)) return undefined; + if (!this.flowSlots.isShared(name)) return name; + const resolved = this.resolveFlowKey(name, null); + if ('refusal' in resolved) throw new PackageScopedNameRefusedError(resolved.refusal); + return 'key' in resolved ? resolved.key : undefined; + } + /** [#31696] The package of the slot `key` files, or `undefined` (a package-less slot, or none). */ private flowSlotPackage(key: string): string | undefined { return this.flowSlots.slot(key)?.packageId ?? undefined; @@ -5727,9 +5769,13 @@ export class AutomationEngine implements IAutomationService { return [...this.flows.keys()].map((key) => this.flowSlotName(key)); } - /** [#31696] Refused (409, naming both) for a name two packages hold: see {@link getFlowSlot}. */ + /** + * [#31696] Refused (409, naming both) for a name two packages serve: see + * {@link getFlowSlot}. [#33386] Judged over the served holders + * ({@link servedBareFlowKey}): one served holder's flow, `null` when none. + */ async getFlow(name: string): Promise { - const key = this.bareFlowKey(name); + const key = this.servedBareFlowKey(name); return key === undefined ? null : this.flows.get(key) ?? null; } @@ -6575,7 +6621,8 @@ export class AutomationEngine implements IAutomationService { * run's node reads the refusal. */ private resolvedFlowCallKey(name: string, callerPackageId: string | null): string { - const resolved = this.resolveFlowKey(name, callerPackageId); + // [#33386] Over every holder: the guards record an arming verdict. + const resolved = this.resolveFlowKey(name, callerPackageId, { durable: true }); return 'key' in resolved ? resolved.key : unfiledFlowKey(name); } @@ -7159,10 +7206,12 @@ export class AutomationEngine implements IAutomationService { */ toggleFlow(name: string, enabled: boolean, caller?: Pick): Promise { // [#31696] A name two packages hold is refused (409, naming both): - // {@link toggleFlowSlot} switches one package's flow. + // {@link toggleFlowSlot} switches one package's flow. [#33386] Over + // the served holders: one served holder's flow is switched, none is + // not found ({@link servedBareFlowKey}). let key: string | undefined; try { - key = this.bareFlowKey(name); + key = this.servedBareFlowKey(name); } catch (err) { return Promise.reject(err); } @@ -7548,6 +7597,8 @@ export class AutomationEngine implements IAutomationService { if (isSlotKeySpelling(flowName)) return { success: false, error: `Flow '${flowName}' not found` }; const resolved = this.resolveFlowKey(flowName, this.flowCallerPackage(context)); if ('refusal' in resolved) return { success: false, error: resolved.refusal.message }; + // [#33386] No served holder reaches the name: as for a flow this engine does not hold. + if ('absent' in resolved) return { success: false, error: `Flow '${flowName}' not found` }; return this.executeKey(resolved.key, context, startTime); } diff --git a/packages/services/service-automation/src/flow-slots-per-package.test.ts b/packages/services/service-automation/src/flow-slots-per-package.test.ts index 7ca8d93d7ee..6a4e7fd9b3f 100644 --- a/packages/services/service-automation/src/flow-slots-per-package.test.ts +++ b/packages/services/service-automation/src/flow-slots-per-package.test.ts @@ -933,22 +933,21 @@ describe('#31696 [R3] every record of a run follows its key when the name become }); /** - * [#32183, ADR-0150 D3; epic ruling R4-G] The engine reads every holder of a - * name two slots hold, a disabled package's included, so a disable moves no - * run's answer: the slot table's `heldByMany`, the shared name's refusal and - * the shared branch of `resolveFlowKey` answer as `main` does, where the - * registry's holder read did not yet leave a disabled package out. The - * served judgment of the run doors is #32670's. + * [ADR-0150 D3, #33386; seat ruling 6884403301] The engine's bare entries and + * a run's calls judge the SERVED holders of a name two slots hold: a disabled + * package holds no name. The slot table stays keyed over every holder + * (`heldByMany`, amendment 7): a disable re-points no slot, it only moves + * which slot a bare name or a call reaches — the one served holder's; two + * served holders are refused naming them only; none is no flow. A caller + * flow whose own package holds the name and is disabled gets no flow, never + * a closure holder's (amendment 4). Replaces the R4-G parity pin. * * Two states, as a disable reaches the engine: a runtime disable (both slots * stay armed: `disablePackage` unregisters nothing from the engine), and a * boot disable (only the enabled holder's flows are armed, the registry holds - * both). Pinned as parity: for every non-empty disabled set, in both - * registration orders, the bare execute and a subflow call from a caller flow - * of each package answer what they answer with the same flows armed and - * nothing disabled. The CONTROL says what that answer is. + * both). */ -describe('[#32183] a disable moves no run of a name two slots hold: the engine reads every holder (R4-G)', () => { +describe('[#33386] a run of a name two slots hold judges the served holders', () => { const OPS = 'com.acme.ops'; const BOTH = 'com.acme.both'; const NONE = 'com.acme.none'; @@ -989,8 +988,8 @@ describe('[#32183] a disable moves no run of a name two slots hold: the engine r } /** The bare execute's answer, and each armed caller flow's. */ - async function answersOf(unarmed: readonly string[]): Promise> { - const out: Record = {}; + async function answersOf(unarmed: readonly string[]): Promise> { + const out: Record = {}; const run = async (name: string) => { ran = []; const result = await engine.execute(name); @@ -1002,28 +1001,51 @@ describe('[#32183] a disable moves no run of a name two slots hold: the engine r } const ORDERS = [[P1, P2], [P2, P1]]; - const cases = (sets: readonly (readonly string[])[]) => - ORDERS.flatMap((order) => sets.map((disabled) => [order.join(' then '), disabled.join(' and '), order, disabled] as const)); - - it.each(cases([[P1], [P2], [P1, P2]]))( - 'runtime disable, registered %s, %s disabled: every run answers as with nothing disabled', - async (_o, _d, order, disabled) => { - setUp(order, [], []); - const before = await answersOf([]); - setUp(order, [], disabled); - expect(await answersOf([])).toEqual(before); - }, - ); - - it.each(cases([[P1], [P2]]))( - 'boot disable, registered %s, %s disabled (its flows not armed): every run answers as with the same flows armed and nothing disabled', - async (_o, _d, order, disabled) => { - setUp(order, disabled, []); - const before = await answersOf(disabled); - setUp(order, disabled, disabled); - expect(await answersOf(disabled)).toEqual(before); - }, - ); + const ranOnly = (tag: string) => ({ success: true, ran: [tag] }); + const refusedNaming = (answer: { success: boolean; error?: string; ran: string[] }, served: string, off: string) => { + expect(answer).toMatchObject({ success: false, ran: [] }); + expect(String(answer.error)).toContain(served); + expect(String(answer.error)).not.toContain(off); + }; + + describe.each(ORDERS.map((order) => [order.join(' then '), order] as const))('registered %s', (_o, order) => { + it.each([[P1, P2], [P2, P1]])('runtime disable, %s disabled: the bare name and a closure holding both run the served holder; the disabled holder\'s own call gets no flow', async (off, on) => { + setUp(order, [], [off]); + const answers = await answersOf([]); + expect(answers.bare).toMatchObject(ranOnly(tagOf(on))); + expect(answers[goOf(BOTH)]).toMatchObject(ranOnly(tagOf(on))); + expect(answers[goOf(on)]).toMatchObject(ranOnly(tagOf(on))); + expect(answers[goOf(off)]).toMatchObject({ success: false, ran: [] }); + if (off === P1) refusedNaming(answers[goOf(OPS)], P2, P1); + else expect(answers[goOf(OPS)]).toMatchObject(ranOnly('alpha')); + refusedNaming(answers[goOf(NONE)], on, off); + // The engine's other bare entries move with execute (amendment 9); the slots do not move (amendment 7). + expect((await engine.getFlow('f'))?.nodes?.find((n: any) => n.type === 'mark')?.config?.tag).toBe(tagOf(on)); + expect(engine.flowSlotKey(off, 'f')).toBe(`${off}/f`); + expect(engine.flowSlotKey(on, 'f')).toBe(`${on}/f`); + expect(engine.flowDispatchHolder('f')).toMatchObject({ claimBare: false }); + }); + + it('runtime disable, both disabled: no run reaches a flow, and the slots stay keyed', async () => { + setUp(order, [], [P1, P2]); + const answers = await answersOf([]); + expect(answers.bare).toEqual({ success: false, error: "Flow 'f' not found", ran: [] }); + for (const id of CALLERS) expect(answers[goOf(id)], goOf(id)).toMatchObject({ success: false, ran: [] }); + expect(await engine.getFlow('f')).toBeNull(); + await expect(engine.toggleFlow('f', false)).rejects.toThrow("Flow 'f' not found"); + expect(engine.flowSlotKey(P1, 'f')).toBe(`${P1}/f`); + expect(engine.flowDispatchHolder('f')).toMatchObject({ claimBare: false }); + }); + + it.each([[P1, P2], [P2, P1]])('boot disable, %s disabled (its flows not armed): the bare name runs the served holder', async (off, on) => { + setUp(order, [off], [off]); + const answers = await answersOf([off]); + expect(answers.bare).toMatchObject(ranOnly(tagOf(on))); + expect(answers[goOf(on)]).toMatchObject(ranOnly(tagOf(on))); + expect(answers[goOf(BOTH)]).toMatchObject(ranOnly(tagOf(on))); + refusedNaming(answers[goOf(NONE)], on, off); + }); + }); it('CONTROL — both slots armed, nothing disabled: what `main` answers', async () => { setUp([P1, P2], [], []); diff --git a/packages/services/service-automation/src/plugin.ts b/packages/services/service-automation/src/plugin.ts index f4a6dc3fa75..e9fa1e6b0a0 100644 --- a/packages/services/service-automation/src/plugin.ts +++ b/packages/services/service-automation/src/plugin.ts @@ -1477,13 +1477,28 @@ export function flowNameResolver(ctx: Pick): FlowNa return undefined; } if (!registry) return undefined; - return resolvePackageScopedName(registry, { + const resolution = resolvePackageScopedName(registry, { type: 'flow', name, callerPackageId, ...(options?.includeDisabledPackages === true ? { includeDisabledPackages: true } : {}), }); + // [ADR-0150 D3, #33386] The run's question (`servedCaller`): a caller + // whose own holding answers, inside a disabled package, gets no flow, + // never a closure holder's (seat ruling 6884403301, amendment 4). + if (options?.servedCaller === true && options.includeDisabledPackages !== true + && callerPackageId !== null && resolution.status === 'resolved' && resolution.via === 'own' + && isRegistryPackageDisabled(registry, callerPackageId)) { + return { status: 'not-found' }; + } + return resolution; }; } +/** [#33386] The registry's `isPackageDisabled`, `false` for a registry that has none (it disables nothing). */ +function isRegistryPackageDisabled(registry: unknown, packageId: string): boolean { + const probe = (registry as { isPackageDisabled?: (id: string) => boolean } | null | undefined)?.isPackageDisabled; + return typeof probe === 'function' && probe.call(registry, packageId) === true; +} + /** * [#28405, ADR-0009 §2.1] The engine's reader of a flow's stored versions by * content identity: the metadata repository's `getByHash` over