:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { PipelineResultType } from '~/ingestion/framework/results'
import { LibVersionMonitorStepInput, createLibVersionMonitorStep } from './lib-version-monitor-step'
describe('createLibVersionMonitorStep', () => {
const createInput = (headers: Record<string, string>[] = []): LibVersionMonitorStepInput => ({
message: {
partition: 0,
topic: 'test-topic',
offset: 1,
timestamp: 1234567890,
size: 100,
value: Buffer.from(''),
key: null,
headers: headers.map((h) => {
const result: Record<string, Buffer> = {}
for (const [key, value] of Object.entries(h)) {
result[key] = Buffer.from(value)
}
return result
}),
},
})
it('should emit warning for old lib version (< 1.75.0)', async () => {
const step = createLibVersionMonitorStep()
const input = createInput([{ lib_version: '1.74.0' }])
const result = await step(input)
expect(result.type).toBe(PipelineResultType.OK)
if (result.type === PipelineResultType.OK) {
expect(result.warnings).toHaveLength(1)
expect(result.warnings![0]).toEqual({
type: 'replay_lib_version_too_old',
details: {
libVersion: '1.74.0',
parsedVersion: { major: 1, minor: 74 },
},
key: '1.74.0',
})
}
})
it('should not emit warning for new lib version (>= 1.75.0)', async () => {
const step = createLibVersionMonitorStep()
const input = createInput([{ lib_version: '1.75.0' }])
const result = await step(input)
expect(result.type).toBe(PipelineResultType.OK)
if (result.type === PipelineResultType.OK) {
expect(result.warnings ?? []).toHaveLength(0)
}
})
it('should not emit warning for version 2.x', async () => {
const step = createLibVersionMonitorStep()
const input = createInput([{ lib_version: '2.0.0' }])
const result = await step(input)
expect(result.type).toBe(PipelineResultType.OK)
})
it('should handle invalid lib version gracefully', async () => {
const step = createLibVersionMonitorStep()
const input = createInput([{ lib_version: 'invalid' }])
const result = await step(input)
expect(result.type).toBe(PipelineResultType.OK)
})
it('should handle missing lib version header', async () => {
const step = createLibVersionMonitorStep()
const input = createInput([])
const result = await step(input)
expect(result.type).toBe(PipelineResultType.OK)
})
it('should ignore version with only two parts', async () => {
const step = createLibVersionMonitorStep()
const input = createInput([{ lib_version: '1.74' }])
const result = await step(input)
expect(result.type).toBe(PipelineResultType.OK)
if (result.type === PipelineResultType.OK) {
expect(result.warnings ?? []).toHaveLength(0)
}
})
it('should preserve all input properties (pass-through step)', async () => {
const step = createLibVersionMonitorStep()
const input = createInput([{ lib_version: '1.80.0' }])
const result = await step(input)
expect(result.type).toBe(PipelineResultType.OK)
if (result.type === PipelineResultType.OK) {
expect(result.value.message).toBe(input.message)
}
})
it('should emit warning for edge case version 1.0.0', async () => {
const step = createLibVersionMonitorStep()
const input = createInput([{ lib_version: '1.0.0' }])
const result = await step(input)
expect(result.type).toBe(PipelineResultType.OK)
if (result.type === PipelineResultType.OK) {
expect(result.warnings).toHaveLength(1)
expect(result.warnings![0].details.parsedVersion).toEqual({ major: 1, minor: 0 })
}
})
})