Files
WeHub Mirror 6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (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 / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
WeHub snapshot of cb28d14c6f2c081de7a0d8729a8c816c9adef67a
2026-08-10 11:17:50 +08:00

140 lines
4.5 KiB
TypeScript

/**
* @vitest-environment node
*/
import { describe, expect, it } from 'vitest'
import { HttpError } from '@/lib/core/utils/http-error'
import { buildBlockExecutionError, getExecutionErrorStatus } from '@/executor/utils/errors'
import type { SerializedBlock } from '@/serializer/types'
class TestRateLimitedError extends HttpError {
readonly statusCode = 429
}
class TestUnavailableError extends HttpError {
readonly statusCode = 503
}
class TestBadGatewayError extends HttpError {
readonly statusCode = 502
}
const block = {
id: 'block-1',
position: { x: 0, y: 0 },
config: { tool: 'test_tool', params: {} },
inputs: {},
outputs: {},
metadata: { id: 'generic', name: 'My Block' },
enabled: true,
} as SerializedBlock
describe('getExecutionErrorStatus', () => {
it('forwards a 4xx from a typed HTTP error', () => {
expect(getExecutionErrorStatus(new TestRateLimitedError('slow down'))).toBe(429)
})
it("forwards 503 because it describes Sim's own capacity", () => {
expect(getExecutionErrorStatus(new TestUnavailableError('no keys'))).toBe(503)
})
it('does not forward an upstream 502 as the workflow API status', () => {
expect(getExecutionErrorStatus(new TestBadGatewayError('upstream down'))).toBe(500)
})
it('falls back to 500 for an untyped error', () => {
expect(getExecutionErrorStatus(new Error('boom'))).toBe(500)
})
it("never adopts an upstream target's duck-typed status as our own", () => {
// `api-handler` copies the remote response's status onto the thrown error.
// Adopting it would make a remote 404 the workflow API's 404.
const error = Object.assign(new Error('HTTP 404'), { status: 404 })
expect(getExecutionErrorStatus(error)).toBe(500)
})
it('still reads a Sim-owned statusCode re-attached from a ToolResponse', () => {
const error = Object.assign(new Error('rate limited'), { statusCode: 429 })
expect(getExecutionErrorStatus(error)).toBe(429)
})
it('finds a status carried further down the cause chain', () => {
const wrapped = buildBlockExecutionError({
block,
error: new TestRateLimitedError('slow down'),
})
expect(getExecutionErrorStatus(wrapped)).toBe(429)
})
it('survives a cyclic cause chain', () => {
const a = new Error('a')
const b = new Error('b')
Object.assign(a, { cause: b })
Object.assign(b, { cause: a })
expect(getExecutionErrorStatus(a)).toBe(500)
})
})
describe('buildBlockExecutionError', () => {
it('prefixes the block name and preserves the original as cause', () => {
const original = new Error('inner failure')
const wrapped = buildBlockExecutionError({ block, error: original })
expect(wrapped.message).toBe('My Block: inner failure')
expect(wrapped.cause).toBe(original)
})
it('leaves cause unset for a non-Error throw', () => {
const wrapped = buildBlockExecutionError({ block, error: 'plain string' })
expect(wrapped.message).toBe('My Block: plain string')
expect(wrapped.cause).toBeUndefined()
})
})
describe('hosted-key status survives the ToolResponse flattening', () => {
/**
* `executeTool` catches a thrown error and returns a `ToolResponse`, so the
* status has to ride `ToolResponse.statusCode` and be re-attached by
* `generic-handler`. This reproduces that hand-off end to end.
*/
function errorFromFailedToolResponse(response: {
error: string
output: Record<string, unknown>
statusCode?: number
}): Error {
const error = new Error(response.error)
Object.assign(error, {
output: response.output,
...(typeof response.statusCode === 'number' ? { statusCode: response.statusCode } : {}),
})
return buildBlockExecutionError({ block, error })
}
it('forwards a hosted-key 429 to the API caller', () => {
const wrapped = errorFromFailedToolResponse({
error: 'Rate limit exceeded',
output: {},
statusCode: 429,
})
expect(getExecutionErrorStatus(wrapped)).toBe(429)
})
it('forwards a hosted-key 503 to the API caller', () => {
const wrapped = errorFromFailedToolResponse({
error: 'No hosted keys configured',
output: {},
statusCode: 503,
})
expect(getExecutionErrorStatus(wrapped)).toBe(503)
})
it("never adopts an upstream provider's status as our own", () => {
// A provider 404 rides `output`, never `statusCode`, so it must not surface.
const wrapped = errorFromFailedToolResponse({
error: 'HTTP 404: Not Found',
output: { status: 404, statusText: 'Not Found' },
})
expect(getExecutionErrorStatus(wrapped)).toBe(500)
})
})