diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index 63c34400dbd..71a11ad430e 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -1,5 +1,5 @@ /** @file Orchestration facade */ -import { assertAllDefined } from '@agoric/internal'; +import { assertAllDefined, deepMapObject } from '@agoric/internal'; /** * @import {AsyncFlowTools, GuestInterface, HostArgs, HostOf} from '@agoric/async-flow'; @@ -109,26 +109,19 @@ export const makeOrchestrationFacade = ({ * @returns {{ [N in keyof GFM]: HostForGuest }} */ const orchestrateAll = (guestFns, hostCtx) => { - const getMappedFlows = () => { - return Object.fromEntries( - Object.keys(guestFns).map(name => [ - name, - // eslint-disable-next-line no-use-before-define - (...args) => orcFns[name](...args), - ]), - ); - }; - - const mappedContext = Object.fromEntries( - Object.entries(hostCtx).map(([key, value]) => [ - key, - // TODO: support matching individual guest functions anywhere in the context - // instead of matching the record as a whole - // https://github.com/Agoric/agoric-sdk/issues/9823 - value === guestFns ? getMappedFlows() : value, + const mappedFlows = new Map( + Object.entries(guestFns).map(([name, guestFn]) => [ + guestFn, + // eslint-disable-next-line no-use-before-define + (...args) => orcFns[name](...args), ]), ); + const mappedContext = deepMapObject( + hostCtx, + val => mappedFlows.get(val) || val, + ); + const orcFns = /** @type {{ [N in keyof GFM]: HostForGuest }} */ ( Object.fromEntries( Object.entries(guestFns).map(([name, guestFn]) => [ diff --git a/packages/orchestration/test/facade.test.ts b/packages/orchestration/test/facade.test.ts index 07a214cd4c8..8ee3e4aaa45 100644 --- a/packages/orchestration/test/facade.test.ts +++ b/packages/orchestration/test/facade.test.ts @@ -56,8 +56,7 @@ test('calls between flows', async t => { t.deepEqual(await vt.when(outer('a', 'b', 'c')), 'Hello a b c'); }); -// UNTIL https://github.com/Agoric/agoric-sdk/issues/9823 -test('context mapping limits', async t => { +test('context mapping individual flows', async t => { const { vt, orchestrateAll, zcf } = t.context; const flows = { @@ -70,12 +69,9 @@ test('context mapping limits', async t => { } as Record>; const { outer } = orchestrateAll(flows, { - peerFlows: { ...flows }, + peerFlows: { inner: flows.inner }, zcf, }); - // `peerFlows` did not have the same identity as `guestFns` - await t.throwsAsync(vt.when(outer('a', 'b', 'c')), { - message: 'converting apply result: vow expected "[Promise]"', - }); + t.deepEqual(await vt.when(outer('a', 'b', 'c')), 'Hello a b c'); });