Files
simstudioai--sim/apps/sim/tools/leadmagic-hosting.test.ts
T
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

130 lines
5.2 KiB
TypeScript

/**
* @vitest-environment node
*/
import { describe, expect, it } from 'vitest'
import { companySearchTool } from '@/tools/leadmagic/company_search'
import { emailToProfileTool } from '@/tools/leadmagic/email_to_profile'
import { findEmailTool } from '@/tools/leadmagic/find_email'
import { findMobileTool } from '@/tools/leadmagic/find_mobile'
import { getCreditsTool } from '@/tools/leadmagic/get_credits'
import { LEADMAGIC_CREDIT_USD } from '@/tools/leadmagic/hosting'
import { profileSearchTool } from '@/tools/leadmagic/profile_search'
import { profileToEmailTool } from '@/tools/leadmagic/profile_to_email'
import { roleFinderTool } from '@/tools/leadmagic/role_finder'
import { validateEmailTool } from '@/tools/leadmagic/validate_email'
import type { ToolConfig } from '@/tools/types'
function cost(tool: ToolConfig<any, any>, params: any, output: Record<string, unknown>) {
const pricing = tool.hosting?.pricing
if (!pricing || pricing.type !== 'custom') throw new Error('Expected custom pricing')
const result = pricing.getCost(params, output)
return typeof result === 'number' ? { cost: result } : result
}
describe('LeadMagic hosted key config', () => {
it('declares the correct env prefix and BYOK provider for all credit-consuming tools', () => {
const tools = [
validateEmailTool,
findEmailTool,
findMobileTool,
profileSearchTool,
profileToEmailTool,
emailToProfileTool,
companySearchTool,
roleFinderTool,
]
for (const tool of tools) {
expect(tool.hosting?.envKeyPrefix).toBe('LEADMAGIC_API_KEY')
expect(tool.hosting?.byokProviderId).toBe('leadmagic')
}
})
it('get_credits has no hosting config (free endpoint)', () => {
expect(getCreditsTool.hosting).toBeUndefined()
})
})
describe('LeadMagic hosted key pricing', () => {
it('validate_email: uses API-reported credits_consumed', () => {
expect(cost(validateEmailTool, {}, { credits_consumed: 0.25 }).cost).toBeCloseTo(
0.25 * LEADMAGIC_CREDIT_USD
)
expect(cost(validateEmailTool, {}, { credits_consumed: 0 }).cost).toBe(0)
})
it('find_email: 1 credit when email found, 0 otherwise', () => {
expect(cost(findEmailTool, {}, { credits_consumed: 1 }).cost).toBeCloseTo(LEADMAGIC_CREDIT_USD)
expect(cost(findEmailTool, {}, { credits_consumed: 0, email: null }).cost).toBe(0)
// fallback path when credits_consumed missing
expect(cost(findEmailTool, {}, { email: 'a@b.com' }).cost).toBeCloseTo(LEADMAGIC_CREDIT_USD)
expect(cost(findEmailTool, {}, { email: null }).cost).toBe(0)
})
it('find_mobile: 5 credits when mobile found, 0 otherwise', () => {
expect(cost(findMobileTool, {}, { credits_consumed: 5 }).cost).toBeCloseTo(
5 * LEADMAGIC_CREDIT_USD
)
expect(cost(findMobileTool, {}, { credits_consumed: 0 }).cost).toBe(0)
// fallback path
expect(cost(findMobileTool, {}, { mobile_number: '+15551234567' }).cost).toBeCloseTo(
5 * LEADMAGIC_CREDIT_USD
)
expect(cost(findMobileTool, {}, { mobile_number: null }).cost).toBe(0)
})
it('profile_search: 1 credit when profile found, 0 otherwise', () => {
expect(cost(profileSearchTool, {}, { credits_consumed: 1 }).cost).toBeCloseTo(
LEADMAGIC_CREDIT_USD
)
expect(cost(profileSearchTool, {}, { credits_consumed: 0 }).cost).toBe(0)
})
it('profile_to_email: 5 credits when email found, 0 otherwise', () => {
expect(cost(profileToEmailTool, {}, { credits_consumed: 5 }).cost).toBeCloseTo(
5 * LEADMAGIC_CREDIT_USD
)
expect(cost(profileToEmailTool, {}, { credits_consumed: 0 }).cost).toBe(0)
// fallback path
expect(cost(profileToEmailTool, {}, { email: 'a@b.com' }).cost).toBeCloseTo(
5 * LEADMAGIC_CREDIT_USD
)
expect(cost(profileToEmailTool, {}, { email: null }).cost).toBe(0)
})
it('email_to_profile: 10 credits when profile found, 0 otherwise', () => {
expect(cost(emailToProfileTool, {}, { credits_consumed: 10 }).cost).toBeCloseTo(
10 * LEADMAGIC_CREDIT_USD
)
expect(cost(emailToProfileTool, {}, { credits_consumed: 0 }).cost).toBe(0)
// fallback path
expect(
cost(emailToProfileTool, {}, { profile_url: 'https://linkedin.com/in/johndoe' }).cost
).toBeCloseTo(10 * LEADMAGIC_CREDIT_USD)
expect(cost(emailToProfileTool, {}, { profile_url: null }).cost).toBe(0)
})
it('company_search: 1 credit when company found, 0 otherwise', () => {
expect(cost(companySearchTool, {}, { credits_consumed: 1 }).cost).toBeCloseTo(
LEADMAGIC_CREDIT_USD
)
expect(cost(companySearchTool, {}, { credits_consumed: 0 }).cost).toBe(0)
// fallback path
expect(cost(companySearchTool, {}, { companyName: 'Stripe' }).cost).toBeCloseTo(
LEADMAGIC_CREDIT_USD
)
expect(cost(companySearchTool, {}, { companyName: null }).cost).toBe(0)
})
it('role_finder: 2 credits when person found, 0 otherwise', () => {
expect(cost(roleFinderTool, {}, { credits_consumed: 2 }).cost).toBeCloseTo(
2 * LEADMAGIC_CREDIT_USD
)
expect(cost(roleFinderTool, {}, { credits_consumed: 0 }).cost).toBe(0)
// fallback path
expect(cost(roleFinderTool, {}, { full_name: 'John Doe' }).cost).toBeCloseTo(
2 * LEADMAGIC_CREDIT_USD
)
expect(cost(roleFinderTool, {}, { full_name: null }).cost).toBe(0)
})
})