d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
167 lines
5.1 KiB
TypeScript
167 lines
5.1 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import type { DAG, DAGNode } from '@/executor/dag/builder'
|
|
import { EdgeManager } from '@/executor/execution/edge-manager'
|
|
import { serializePauseSnapshot } from '@/executor/execution/snapshot-serializer'
|
|
import type { ExecutionContext } from '@/executor/types'
|
|
|
|
function createContext(overrides: Partial<ExecutionContext> = {}): ExecutionContext {
|
|
return {
|
|
workflowId: 'workflow-1',
|
|
workspaceId: 'workspace-1',
|
|
executionId: 'execution-1',
|
|
userId: 'user-1',
|
|
blockStates: new Map(),
|
|
executedBlocks: new Set(),
|
|
blockLogs: [],
|
|
metadata: {
|
|
requestId: 'request-1',
|
|
executionId: 'execution-1',
|
|
workflowId: 'workflow-1',
|
|
workspaceId: 'workspace-1',
|
|
userId: 'user-1',
|
|
triggerType: 'manual',
|
|
useDraftState: true,
|
|
startTime: '2026-01-01T00:00:00.000Z',
|
|
},
|
|
environmentVariables: {},
|
|
decisions: {
|
|
router: new Map(),
|
|
condition: new Map(),
|
|
},
|
|
completedLoops: new Set(),
|
|
activeExecutionPath: new Set(),
|
|
...overrides,
|
|
} as ExecutionContext
|
|
}
|
|
|
|
describe('serializePauseSnapshot', () => {
|
|
it('serializes batched parallel accumulated outputs for cross-process resume', () => {
|
|
const context = createContext({
|
|
parallelExecutions: new Map([
|
|
[
|
|
'parallel-1',
|
|
{
|
|
parallelId: 'parallel-1',
|
|
totalBranches: 3,
|
|
branchOutputs: new Map([[2, [{ output: 'current-batch' }]]]),
|
|
accumulatedOutputs: new Map([
|
|
[0, [{ output: 'batch-0' }]],
|
|
[1, [{ output: 'batch-1' }]],
|
|
]),
|
|
},
|
|
],
|
|
]),
|
|
})
|
|
|
|
const snapshot = serializePauseSnapshot(context, ['next-block'])
|
|
const serialized = JSON.parse(snapshot.snapshot)
|
|
|
|
expect(serialized.state.parallelExecutions?.['parallel-1']).toMatchObject({
|
|
branchOutputs: {
|
|
2: [{ output: 'current-batch' }],
|
|
},
|
|
accumulatedOutputs: {
|
|
0: [{ output: 'batch-0' }],
|
|
1: [{ output: 'batch-1' }],
|
|
},
|
|
})
|
|
})
|
|
|
|
it('serializes deactivated edge state for resume', () => {
|
|
const context = createContext()
|
|
const sourceNode = {
|
|
id: 'condition',
|
|
block: {} as DAGNode['block'],
|
|
incomingEdges: new Set<string>(),
|
|
outgoingEdges: new Map([['if-edge', { target: 'target', sourceHandle: 'condition-if' }]]),
|
|
metadata: {},
|
|
}
|
|
const targetNode = {
|
|
id: 'target',
|
|
block: {} as DAGNode['block'],
|
|
incomingEdges: new Set(['condition']),
|
|
outgoingEdges: new Map(),
|
|
metadata: {},
|
|
}
|
|
const activeSourceNode = {
|
|
id: 'active-source',
|
|
block: {} as DAGNode['block'],
|
|
incomingEdges: new Set<string>(),
|
|
outgoingEdges: new Map([['active-edge', { target: 'active-target' }]]),
|
|
metadata: {},
|
|
}
|
|
const activeTargetNode = {
|
|
id: 'active-target',
|
|
block: {} as DAGNode['block'],
|
|
incomingEdges: new Set(['active-source']),
|
|
outgoingEdges: new Map(),
|
|
metadata: {},
|
|
}
|
|
const dag: DAG = {
|
|
nodes: new Map([
|
|
[sourceNode.id, sourceNode],
|
|
[targetNode.id, targetNode],
|
|
[activeSourceNode.id, activeSourceNode],
|
|
[activeTargetNode.id, activeTargetNode],
|
|
]),
|
|
loopConfigs: new Map(),
|
|
parallelConfigs: new Map(),
|
|
}
|
|
const edgeManager = new EdgeManager(dag)
|
|
edgeManager.processOutgoingEdges(sourceNode, { selectedOption: 'else' })
|
|
edgeManager.processOutgoingEdges(activeSourceNode, { result: true })
|
|
|
|
const snapshot = serializePauseSnapshot(context, ['next-block'], dag, edgeManager)
|
|
const serialized = JSON.parse(snapshot.snapshot)
|
|
|
|
expect(serialized.state.deactivatedEdges).toHaveLength(1)
|
|
expect(serialized.state.nodesWithActivatedEdge).toEqual(['active-target'])
|
|
})
|
|
|
|
it('rejects oversized snapshot values without full JSON serialization', () => {
|
|
const stringifySpy = vi.spyOn(JSON, 'stringify').mockImplementation(() => {
|
|
throw new Error('full stringify should not be used for compactness checks')
|
|
})
|
|
const context = createContext({
|
|
workflowVariables: {
|
|
oversized: {
|
|
type: 'string',
|
|
value: 'x'.repeat(9 * 1024 * 1024),
|
|
},
|
|
},
|
|
})
|
|
|
|
try {
|
|
expect(() => serializePauseSnapshot(context, ['next-block'])).toThrow(
|
|
'Cannot serialize pause snapshot with oversized workflow variables'
|
|
)
|
|
} finally {
|
|
stringifySpy.mockRestore()
|
|
}
|
|
})
|
|
|
|
it('preserves an explicit useDraftState=true even when the context is a deployed (server-side) context', () => {
|
|
const context = createContext({
|
|
isDeployedContext: true,
|
|
metadata: {
|
|
requestId: 'request-1',
|
|
executionId: 'execution-1',
|
|
workflowId: 'workflow-1',
|
|
workspaceId: 'workspace-1',
|
|
userId: 'user-1',
|
|
triggerType: 'manual',
|
|
useDraftState: true,
|
|
startTime: '2026-01-01T00:00:00.000Z',
|
|
},
|
|
})
|
|
|
|
const snapshot = serializePauseSnapshot(context, ['next-block'])
|
|
const serialized = JSON.parse(snapshot.snapshot)
|
|
|
|
expect(serialized.metadata.useDraftState).toBe(true)
|
|
})
|
|
})
|