Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions packages/core/src/lib/runtime.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

import { describe, expect, it } from 'vitest';
import type { EventEnvelope, WorkflowDefinition } from '@pulsestack/contracts';
import type {
EventEnvelope,
ExecutionSnapshot,
TraceSpan,
WorkflowDefinition,
} from '@pulsestack/contracts';
import type { PulseInfra } from './infra.js';
import { WorkflowRuntime } from './runtime.js';

class RuntimeInfraMock {
Expand Down Expand Up @@ -43,15 +49,8 @@ describe('WorkflowRuntime', () => {
);
expect(tenantEvents.length).toBeGreaterThan(0);
expect(tenantEvents.every((event) => event.tenantId === workflow.tenantId)).toBe(true);

import type {
EventEnvelope,
ExecutionSnapshot,
TraceSpan,
} from '@pulsestack/contracts';
import { describe, expect, it } from 'vitest';
import type { PulseInfra } from './infra.js';
import { WorkflowRuntime } from './runtime.js';
});
});

function createRuntimeHarness() {
const events: EventEnvelope[] = [];
Expand Down
38 changes: 2 additions & 36 deletions packages/core/src/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,6 @@ export class WorkflowRuntime {
input: request.input,
});

const state: Record<string, unknown> = { ...request.input };
const results: StepResult[] = [];

for (const [index, step] of request.workflow.steps.entries()) {
const span = await this.startSpan({
traceId,
executionId,
workflowId: request.workflow.id,
tenantId: request.workflow.tenantId,
step,
state,
});

const result = await this.runStep(step, state, request.workflow.tenantId, request.workflow.correlationId);
Object.assign(state, { [step.id]: result.output });
results.push(result);

await this.snapshot({
id: createId('snap'),
executionId,
workflowId: request.workflow.id,
sequence: index,
state: structuredClone(state),
sideEffects: [
{
type: step.kind,
key: step.id,
response: result.output,
},
],
createdAt: new Date().toISOString(),
});

await publishEvent(
this.infra,
createEvent({
Expand Down Expand Up @@ -157,6 +124,7 @@ export class WorkflowRuntime {
traceId,
executionId,
workflowId: request.workflow.id,
tenantId: request.workflow.tenantId,
parentSpanId: workflowSpanId,
step,
state,
Expand Down Expand Up @@ -303,6 +271,7 @@ export class WorkflowRuntime {
const result = await this.runStep(
args.step,
args.state,
args.tenantId,
args.correlationId,
attempt,
);
Expand Down Expand Up @@ -368,9 +337,6 @@ export class WorkflowRuntime {

tenantId: string,
correlationId: string,
): Promise<StepResult> {

correlationId: string,
attempt: number,
): Promise<Omit<StepResult, 'attempts' | 'retry'>> {

Expand Down