chore: import upstream snapshot with attribution
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
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:20:55 +08:00
commit d25d482dc2
13754 changed files with 4996608 additions and 0 deletions
@@ -0,0 +1,296 @@
/**
* @vitest-environment node
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { clearLargeValueCacheForTests } from '@/lib/execution/payloads/cache'
import { isLargeArrayManifest } from '@/lib/execution/payloads/large-array-manifest-metadata'
import { BlockType } from '@/executor/constants'
import { VariablesBlockHandler } from '@/executor/handlers/variables/variables-handler'
import type { ExecutionContext } from '@/executor/types'
import type { SerializedBlock } from '@/serializer/types'
const { mockUploadFile } = vi.hoisted(() => ({
mockUploadFile: vi.fn(),
}))
vi.mock('@/lib/uploads', () => ({
StorageService: {
uploadFile: mockUploadFile,
},
}))
function createContext(overrides: Partial<ExecutionContext> = {}): ExecutionContext {
return {
workflowId: 'workflow-1',
workspaceId: 'workspace-1',
executionId: 'execution-1',
userId: 'user-1',
blockStates: new Map(),
blockLogs: [],
metadata: { duration: 0 },
environmentVariables: {},
workflowVariables: {
'var-1': { id: 'var-1', name: 'issues', type: 'array', value: [] },
},
decisions: { router: new Map(), condition: new Map() },
loopExecutions: new Map(),
executedBlocks: new Set(),
activeExecutionPath: new Set(),
completedLoops: new Set(),
...overrides,
}
}
function createBlock(): SerializedBlock {
return {
id: 'variables-block-1',
metadata: { id: BlockType.VARIABLES, name: 'Variables' },
position: { x: 0, y: 0 },
config: { tool: BlockType.VARIABLES, params: {} },
inputs: {},
outputs: {},
enabled: true,
}
}
describe('VariablesBlockHandler', () => {
beforeEach(() => {
vi.clearAllMocks()
clearLargeValueCacheForTests()
mockUploadFile.mockImplementation(async ({ customKey }) => ({ key: customKey }))
})
it('preserves small assignments inline', async () => {
const handler = new VariablesBlockHandler()
const ctx = createContext()
const value = [{ key: 'SIM-1', summary: 'Small issue' }]
const output = await handler.execute(ctx, createBlock(), {
variables: [
{
variableId: 'var-1',
variableName: 'issues',
type: 'array',
value,
},
],
})
expect(ctx.workflowVariables?.['var-1'].value).toEqual(value)
expect(output).toEqual({ issues: value })
expect(mockUploadFile).not.toHaveBeenCalled()
})
it('includes unmatched assignments in block output without mutating workflow variables', async () => {
const handler = new VariablesBlockHandler()
const ctx = createContext()
const value = [{ key: 'SIM-1', summary: 'Transient issue' }]
const output = await handler.execute(ctx, createBlock(), {
variables: [
{
variableName: 'transientIssues',
type: 'array',
value,
},
],
})
expect(ctx.workflowVariables).not.toHaveProperty('transientIssues')
expect(output).toEqual({ transientIssues: value })
})
it('keeps special unmatched assignment names as own output fields', async () => {
const handler = new VariablesBlockHandler()
const ctx = createContext()
const value = { polluted: true }
const output = await handler.execute(ctx, createBlock(), {
variables: [
{
variableName: '__proto__',
type: 'object',
value,
},
],
})
expect(Object.hasOwn(output, '__proto__')).toBe(true)
expect(output.__proto__).toEqual(value)
expect(Object.getPrototypeOf(output)).toBe(Object.prototype)
})
it('does not treat inherited prototype keys as existing workflow variable IDs', async () => {
const handler = new VariablesBlockHandler()
const ctx = createContext()
const value = { safe: true }
const originalPrototype = Object.getPrototypeOf(ctx.workflowVariables)
const output = await handler.execute(ctx, createBlock(), {
variables: [
{
variableId: '__proto__',
variableName: 'prototypeAssignment',
type: 'object',
value,
},
],
})
expect(Object.getPrototypeOf(ctx.workflowVariables)).toBe(originalPrototype)
expect(ctx.workflowVariables).not.toHaveProperty('__proto__')
expect(output).toEqual({ prototypeAssignment: value })
})
it('stores oversized array assignments as durable manifests in variables and block output', async () => {
const handler = new VariablesBlockHandler()
const ctx = createContext()
const value = Array.from({ length: 120_000 }, (_, index) => ({
key: `SIM-${index}`,
summary: 'Issue summary that keeps each item small',
}))
const output = await handler.execute(ctx, createBlock(), {
variables: [
{
variableId: 'var-1',
variableName: 'issues',
type: 'array',
value,
},
],
})
const storedValue = ctx.workflowVariables?.['var-1'].value
expect(isLargeArrayManifest(storedValue)).toBe(true)
expect(output.issues).toBe(storedValue)
expect(storedValue).toMatchObject({
__simLargeArrayManifest: true,
kind: 'array',
totalCount: value.length,
})
expect(storedValue.chunkCount).toBeGreaterThan(1)
expect(mockUploadFile).toHaveBeenCalledWith(
expect.objectContaining({
context: 'execution',
preserveKey: true,
customKey: expect.stringContaining('/execution-1/large-value-'),
})
)
})
it('fails clearly when durable context is missing for oversized assignments', async () => {
const handler = new VariablesBlockHandler()
const ctx = createContext({ workspaceId: undefined, executionId: undefined })
const value = Array.from({ length: 120_000 }, (_, index) => ({
key: `SIM-${index}`,
summary: 'Issue summary that keeps each item small',
}))
await expect(
handler.execute(ctx, createBlock(), {
variables: [
{
variableId: 'var-1',
variableName: 'issues',
type: 'array',
value,
},
],
})
).rejects.toThrow(
'Cannot persist large execution value without workspace, workflow, and execution IDs'
)
expect(mockUploadFile).not.toHaveBeenCalled()
})
it('preserves whole large refs before scalar type coercion', async () => {
const handler = new VariablesBlockHandler()
const ref = {
__simLargeValueRef: true,
version: 1,
id: 'lv_ABCDEFGHIJKL',
kind: 'object',
size: 12 * 1024 * 1024,
executionId: 'execution-1',
}
const ctx = createContext({
workflowVariables: {
stringVar: { id: 'stringVar', name: 'stringRef', type: 'string', value: '' },
plainVar: { id: 'plainVar', name: 'plainRef', type: 'plain', value: '' },
numberVar: { id: 'numberVar', name: 'numberRef', type: 'number', value: 0 },
booleanVar: { id: 'booleanVar', name: 'booleanRef', type: 'boolean', value: false },
},
})
await handler.execute(ctx, createBlock(), {
variables: [
{
variableId: 'stringVar',
variableName: 'stringRef',
type: 'string',
value: JSON.stringify(ref),
},
{
variableId: 'plainVar',
variableName: 'plainRef',
type: 'plain',
value: JSON.stringify(ref),
},
{
variableId: 'numberVar',
variableName: 'numberRef',
type: 'number',
value: JSON.stringify(ref),
},
{
variableId: 'booleanVar',
variableName: 'booleanRef',
type: 'boolean',
value: JSON.stringify(ref),
},
],
})
expect(ctx.workflowVariables?.stringVar.value).toEqual(ref)
expect(ctx.workflowVariables?.plainVar.value).toEqual(ref)
expect(ctx.workflowVariables?.numberVar.value).toEqual(ref)
expect(ctx.workflowVariables?.booleanVar.value).toEqual(ref)
})
it('preserves existing variable metadata when compacting reassignment', async () => {
const handler = new VariablesBlockHandler()
const ctx = createContext({
workflowVariables: {
'var-1': {
id: 'var-1',
name: 'issues',
type: 'array',
value: [],
isExisting: true,
},
},
})
const value = [{ key: 'SIM-1', summary: 'Updated' }]
await handler.execute(ctx, createBlock(), {
variables: [
{
variableId: 'var-1',
variableName: 'issues',
type: 'array',
value,
},
],
})
expect(ctx.workflowVariables?.['var-1']).toEqual({
id: 'var-1',
name: 'issues',
type: 'array',
value,
isExisting: true,
})
})
})