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
82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import { logfireGetTraceTool } from '@/tools/logfire/get_trace'
|
|
|
|
/**
|
|
* Build a synthetic read token for a region. Assembled from a template rather
|
|
* than written out as a literal so no credential-shaped string sits in the
|
|
* source; only the `pylf_v{n}_{region}_` prefix is meaningful to the code here.
|
|
*/
|
|
const readToken = (region: string) => `pylf_v1_${region}_fixture`
|
|
|
|
const baseParams = {
|
|
apiKey: readToken('eu'),
|
|
traceId: '0123456789abcdef0123456789abcdef',
|
|
}
|
|
|
|
describe('logfireGetTraceTool request', () => {
|
|
it('routes EU tokens to the EU host', () => {
|
|
expect(logfireGetTraceTool.request.url(baseParams)).toBe(
|
|
'https://logfire-eu.pydantic.dev/v2/query'
|
|
)
|
|
})
|
|
|
|
it('filters on the trace id and orders spans chronologically', () => {
|
|
const body = logfireGetTraceTool.request.body?.({
|
|
...baseParams,
|
|
traceId: ' 0123456789abcdef0123456789abcdef ',
|
|
}) as Record<string, unknown>
|
|
|
|
expect(String(body.sql)).toContain("trace_id = '0123456789abcdef0123456789abcdef'")
|
|
expect(String(body.sql)).toContain('ORDER BY start_timestamp ASC')
|
|
})
|
|
|
|
it('escapes a trace id so it cannot break out of the literal', () => {
|
|
const body = logfireGetTraceTool.request.body?.({
|
|
...baseParams,
|
|
traceId: "abc' OR 1=1 --",
|
|
}) as Record<string, unknown>
|
|
|
|
expect(String(body.sql)).toContain("trace_id = 'abc'' OR 1=1 --'")
|
|
expect(String(body.sql)).not.toContain("'abc' OR 1=1")
|
|
})
|
|
})
|
|
|
|
describe('logfireGetTraceTool transformResponse', () => {
|
|
it('normalizes every span in the trace from the wire payload', async () => {
|
|
const response = new Response(
|
|
JSON.stringify({
|
|
schema: {
|
|
fields: [{ name: 'span_id', data_type: 'Utf8', nullable: false }],
|
|
metadata: {},
|
|
},
|
|
data: [
|
|
{ span_id: 'root', parent_span_id: null, span_name: 'GET /orders', duration: 1.5 },
|
|
{ span_id: 'child', parent_span_id: 'root', span_name: 'db.query', duration: 0.4 },
|
|
],
|
|
}),
|
|
{ status: 200 }
|
|
)
|
|
|
|
const result = await logfireGetTraceTool.transformResponse?.(response, baseParams)
|
|
|
|
expect(result?.success).toBe(true)
|
|
expect(result?.output.rowCount).toBe(2)
|
|
expect(result?.output.rows[0]).toMatchObject({ spanId: 'root', parentSpanId: null })
|
|
expect(result?.output.rows[1]).toMatchObject({ spanId: 'child', parentSpanId: 'root' })
|
|
expect(result?.output.sql).toContain('trace_id =')
|
|
})
|
|
|
|
it('returns an empty result set for an unknown trace id', async () => {
|
|
const response = new Response(JSON.stringify({ schema: { fields: [] }, data: [] }), {
|
|
status: 200,
|
|
})
|
|
const result = await logfireGetTraceTool.transformResponse?.(response, baseParams)
|
|
|
|
expect(result?.output.rows).toEqual([])
|
|
expect(result?.output.rowCount).toBe(0)
|
|
})
|
|
})
|