diff --git a/projects/start-os/container-runtime/src/Adapters/EffectCreator.test.ts b/projects/start-os/container-runtime/src/Adapters/EffectCreator.test.ts new file mode 100644 index 0000000000..caf2ebd7b6 --- /dev/null +++ b/projects/start-os/container-runtime/src/Adapters/EffectCreator.test.ts @@ -0,0 +1,22 @@ +import { effectParams } from './EffectCreator' + +describe('effectParams', () => { + test('tags the call with the calling procedure', () => { + expect(effectParams({ actionId: 'a' }, 'procedure')).toEqual({ + actionId: 'a', + eventId: 'procedure', + }) + }) + + test('keeps the event id an action run names', () => { + expect( + effectParams({ actionId: 'a', eventId: 'form' }, 'procedure'), + ).toEqual({ actionId: 'a', eventId: 'form' }) + }) + + test('sends no event id outside a procedure', () => { + expect(JSON.stringify(effectParams({ actionId: 'a' }, null))).toBe( + '{"actionId":"a"}', + ) + }) +}) diff --git a/projects/start-os/container-runtime/src/Adapters/EffectCreator.ts b/projects/start-os/container-runtime/src/Adapters/EffectCreator.ts index a1e7e19d57..2bbed4e48b 100644 --- a/projects/start-os/container-runtime/src/Adapters/EffectCreator.ts +++ b/projects/start-os/container-runtime/src/Adapters/EffectCreator.ts @@ -46,6 +46,14 @@ export type EffectContext = { constRetry?: () => void } +/** The effect call's params, tagged with the calling procedure's event id. An `eventId` the effect names itself wins. */ +export function effectParams( + params: Record, + eventId: string | null, +): Record { + return { eventId: eventId ?? undefined, ...params } +} + const rpcRoundFor = (eventId: string | null) => ( @@ -58,7 +66,7 @@ const rpcRoundFor = JSON.stringify({ id, method, - params: { ...params, eventId: eventId ?? undefined }, + params: effectParams(params, eventId), }) + '\n', ) })