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
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:
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* @vitest-environment node
|
||||
*/
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
FALAI_HOSTED_KEY_MARKUP_MULTIPLIER,
|
||||
FALAI_IMAGE_FALLBACK_PROVIDER_COST_DOLLARS,
|
||||
getFalAICostMetadata,
|
||||
} from '@/lib/tools/falai-pricing'
|
||||
import { imageGenerateTool } from '@/tools/image/generate'
|
||||
import { falaiVideoTool } from '@/tools/video/falai'
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('Fal.ai hosted key pricing', () => {
|
||||
it('applies hosted markup to image generation provider cost', () => {
|
||||
const pricing = imageGenerateTool.hosting?.pricing
|
||||
expect(pricing?.type).toBe('custom')
|
||||
if (!pricing || pricing.type !== 'custom') throw new Error('Expected custom pricing')
|
||||
|
||||
const result = pricing.getCost(
|
||||
{},
|
||||
{
|
||||
__falaiCostDollars: 0.1,
|
||||
__falaiBilling: {
|
||||
source: 'billing_events',
|
||||
endpointId: 'fal-ai/nano-banana-2',
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(typeof result).toBe('object')
|
||||
if (typeof result === 'number') throw new Error('Expected structured pricing result')
|
||||
expect(result.cost).toBeCloseTo(0.1 * FALAI_HOSTED_KEY_MARKUP_MULTIPLIER)
|
||||
expect(result.metadata).toMatchObject({
|
||||
providerCostDollars: 0.1,
|
||||
markupMultiplier: FALAI_HOSTED_KEY_MARKUP_MULTIPLIER,
|
||||
source: 'billing_events',
|
||||
})
|
||||
})
|
||||
|
||||
it('applies hosted markup to video generation provider cost', () => {
|
||||
const pricing = falaiVideoTool.hosting?.pricing
|
||||
expect(pricing?.type).toBe('custom')
|
||||
if (!pricing || pricing.type !== 'custom') throw new Error('Expected custom pricing')
|
||||
|
||||
const result = pricing.getCost(
|
||||
{},
|
||||
{
|
||||
__falaiCostDollars: 0.4,
|
||||
__falaiBilling: {
|
||||
source: 'billing_events',
|
||||
endpointId: 'fal-ai/veo3.1',
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(typeof result).toBe('object')
|
||||
if (typeof result === 'number') throw new Error('Expected structured pricing result')
|
||||
expect(result.cost).toBeCloseTo(0.4 * FALAI_HOSTED_KEY_MARKUP_MULTIPLIER)
|
||||
expect(result.metadata).toMatchObject({
|
||||
providerCostDollars: 0.4,
|
||||
markupMultiplier: FALAI_HOSTED_KEY_MARKUP_MULTIPLIER,
|
||||
source: 'billing_events',
|
||||
})
|
||||
})
|
||||
|
||||
it('returns fallback floor cost metadata instead of throwing when billing and estimate fail', async () => {
|
||||
vi.useFakeTimers()
|
||||
|
||||
const mockFetch = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(
|
||||
new Response(JSON.stringify({ billing_events: [] }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
)
|
||||
.mockResolvedValueOnce(
|
||||
new Response(JSON.stringify({ billing_events: [] }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
)
|
||||
.mockResolvedValueOnce(new Response('pricing unavailable', { status: 500 }))
|
||||
vi.stubGlobal('fetch', mockFetch)
|
||||
|
||||
const resultPromise = getFalAICostMetadata({
|
||||
apiKey: 'fal-key',
|
||||
endpointId: 'fal-ai/nano-banana-2',
|
||||
requestId: 'request-1',
|
||||
})
|
||||
|
||||
await vi.advanceTimersByTimeAsync(500)
|
||||
const result = await resultPromise
|
||||
|
||||
expect(result).toMatchObject({
|
||||
endpointId: 'fal-ai/nano-banana-2',
|
||||
requestId: 'request-1',
|
||||
costDollars: FALAI_IMAGE_FALLBACK_PROVIDER_COST_DOLLARS,
|
||||
source: 'fallback_floor',
|
||||
currency: 'USD',
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user