mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
147 lines
5.8 KiB
TypeScript
147 lines
5.8 KiB
TypeScript
import { PropertyFilterType, PropertyOperator } from '~/types'
|
|
|
|
import {
|
|
FilterIdentifier,
|
|
PersonData,
|
|
createPersonFilter,
|
|
getFilterIdentifier,
|
|
getTracesUrlWithPersonFilter,
|
|
} from './aiObservabilityColumnRenderers'
|
|
|
|
describe('aiObservabilityColumnRenderers', () => {
|
|
describe('getFilterIdentifier', () => {
|
|
it.each<[string, PersonData | null | undefined, FilterIdentifier | null]>([
|
|
['returns null when person is null', null, null],
|
|
['returns null when person is undefined', undefined, null],
|
|
[
|
|
'returns null when person has no identifiable properties',
|
|
{ distinct_id: undefined, properties: {} },
|
|
null,
|
|
],
|
|
[
|
|
'returns email when person has email property',
|
|
{ distinct_id: 'user-123', properties: { email: '[email protected]', username: 'testuser' } },
|
|
{ type: 'email', value: '[email protected]' },
|
|
],
|
|
[
|
|
'returns username when person has username but no email',
|
|
{ distinct_id: 'user-123', properties: { username: 'testuser' } },
|
|
{ type: 'username', value: 'testuser' },
|
|
],
|
|
[
|
|
'returns distinct_id when person has only distinct_id',
|
|
{ distinct_id: 'user-123', properties: {} },
|
|
{ type: 'distinct_id', value: 'user-123' },
|
|
],
|
|
[
|
|
'returns distinct_id when properties is undefined',
|
|
{ distinct_id: 'user-123' },
|
|
{ type: 'distinct_id', value: 'user-123' },
|
|
],
|
|
[
|
|
'prioritizes email over username and distinct_id',
|
|
{ distinct_id: 'user-123', properties: { email: '[email protected]', username: 'testuser' } },
|
|
{ type: 'email', value: '[email protected]' },
|
|
],
|
|
[
|
|
'prioritizes username over distinct_id when no email',
|
|
{ distinct_id: 'user-123', properties: { username: 'testuser' } },
|
|
{ type: 'username', value: 'testuser' },
|
|
],
|
|
[
|
|
'ignores non-string email property',
|
|
{ distinct_id: 'user-123', properties: { email: 123 } },
|
|
{ type: 'distinct_id', value: 'user-123' },
|
|
],
|
|
[
|
|
'ignores non-string username property',
|
|
{ distinct_id: 'user-123', properties: { username: ['array'] } },
|
|
{ type: 'distinct_id', value: 'user-123' },
|
|
],
|
|
])('%s', (_description, person, expected) => {
|
|
expect(getFilterIdentifier(person)).toEqual(expected)
|
|
})
|
|
})
|
|
|
|
describe('createPersonFilter', () => {
|
|
it.each<[string, FilterIdentifier, ReturnType<typeof createPersonFilter>]>([
|
|
[
|
|
'creates InsightsQL filter for distinct_id type',
|
|
{ type: 'distinct_id', value: 'user-123' },
|
|
{ type: PropertyFilterType.InsightsQL, key: "distinct_id == 'user-123'" },
|
|
],
|
|
[
|
|
'creates Person property filter for email type',
|
|
{ type: 'email', value: '[email protected]' },
|
|
{
|
|
type: PropertyFilterType.Person,
|
|
key: 'email',
|
|
operator: PropertyOperator.Exact,
|
|
value: '[email protected]',
|
|
},
|
|
],
|
|
[
|
|
'creates Person property filter for username type',
|
|
{ type: 'username', value: 'testuser' },
|
|
{
|
|
type: PropertyFilterType.Person,
|
|
key: 'username',
|
|
operator: PropertyOperator.Exact,
|
|
value: 'testuser',
|
|
},
|
|
],
|
|
])('%s', (_description, filterIdentifier, expected) => {
|
|
expect(createPersonFilter(filterIdentifier)).toEqual(expected)
|
|
})
|
|
})
|
|
|
|
describe('getTracesUrlWithPersonFilter', () => {
|
|
it('generates URL with email filter', () => {
|
|
const url = getTracesUrlWithPersonFilter({ type: 'email', value: '[email protected]' })
|
|
|
|
expect(url).toContain('/ai-observability/traces')
|
|
expect(url).toContain('filters')
|
|
expect(url).toContain('email')
|
|
expect(url).toContain('test%40example.com')
|
|
})
|
|
|
|
it('generates URL with distinct_id filter', () => {
|
|
const url = getTracesUrlWithPersonFilter({ type: 'distinct_id', value: 'user-123' })
|
|
|
|
expect(url).toContain('/ai-observability/traces')
|
|
expect(url).toContain('filters')
|
|
expect(url).toContain("distinct_id%20%3D%3D%20'user-123'")
|
|
})
|
|
|
|
it('includes date range params when provided', () => {
|
|
const url = getTracesUrlWithPersonFilter(
|
|
{ type: 'email', value: '[email protected]' },
|
|
{ dateFrom: '2024-01-01', dateTo: '2024-01-31' }
|
|
)
|
|
|
|
expect(url).toContain('date_from=2024-01-01')
|
|
expect(url).toContain('date_to=2024-01-31')
|
|
})
|
|
|
|
it('omits date params when they are null', () => {
|
|
const url = getTracesUrlWithPersonFilter(
|
|
{ type: 'email', value: '[email protected]' },
|
|
{ dateFrom: null, dateTo: null }
|
|
)
|
|
|
|
expect(url).not.toContain('date_from')
|
|
expect(url).not.toContain('date_to')
|
|
})
|
|
|
|
it('handles partial date range', () => {
|
|
const url = getTracesUrlWithPersonFilter(
|
|
{ type: 'email', value: '[email protected]' },
|
|
{ dateFrom: '2024-01-01', dateTo: null }
|
|
)
|
|
|
|
expect(url).toContain('date_from=2024-01-01')
|
|
expect(url).not.toContain('date_to')
|
|
})
|
|
})
|
|
})
|