Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
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.
2026-08-01 15:44:40 -07:00

141 lines
5.9 KiB
TypeScript

import { FilterLogicalOperator, PropertyFilterType, PropertyOperator, UniversalFiltersGroup } from '~/types'
import type { TracingLatencyHeatmapData } from './durationBuckets'
import { heatmapBrushToFilters } from './heatmapBrush'
const MS = 1_000_000
const DATA: TracingLatencyHeatmapData = {
timeBuckets: ['t0', 't1', 't2', 't3'],
bucketsNs: [1 * MS, 2 * MS, 5 * MS, 10 * MS],
labels: ['1ms', '2ms', '5ms', '10ms'],
cells: [],
}
const EMPTY_GROUP: UniversalFiltersGroup = {
type: FilterLogicalOperator.And,
values: [{ type: FilterLogicalOperator.And, values: [] }],
}
describe('heatmapBrushToFilters', () => {
it('maps columns to bucket-edge dates and rows to a ms duration chip pair', () => {
const result = heatmapBrushToFilters(
DATA,
{ x: { startIndex: 1, endIndex: 2 }, y: { startIndex: 1, endIndex: 2 } },
EMPTY_GROUP,
'2026-06-02T09:00:00Z'
)
// date_to is the START of the bucket after the last selected column.
expect(result?.dateRange).toEqual({ date_from: 't1', date_to: 't3' })
expect((result?.filterGroup?.values[0] as UniversalFiltersGroup).values).toEqual([
// 2ms..5ms rows cover [2ms, 10ms) — the upper edge is the bucket after the last row.
{ type: PropertyFilterType.Span, key: 'duration', operator: PropertyOperator.GreaterThanOrEqual, value: 2 },
{ type: PropertyFilterType.Span, key: 'duration', operator: PropertyOperator.LessThan, value: 10 },
])
})
it('falls back to the current range end when the selection reaches the last column', () => {
const result = heatmapBrushToFilters(
DATA,
{ x: { startIndex: 2, endIndex: 3 }, y: { startIndex: 0, endIndex: 1 } },
EMPTY_GROUP,
'2026-06-02T09:00:00Z'
)
expect(result?.dateRange).toEqual({ date_from: 't2', date_to: '2026-06-02T09:00:00Z' })
})
it('treats a full-height selection as a time zoom with no duration filters', () => {
const result = heatmapBrushToFilters(
DATA,
{ x: { startIndex: 0, endIndex: 1 }, y: { startIndex: 0, endIndex: 3 } },
EMPTY_GROUP,
null
)
expect(result).toEqual({ dateRange: { date_from: 't0', date_to: 't2' } })
})
it('replaces a prior brush duration pair instead of stacking, keeping other filters', () => {
const groupWithFilters: UniversalFiltersGroup = {
type: FilterLogicalOperator.And,
values: [
{
type: FilterLogicalOperator.And,
values: [
{
type: PropertyFilterType.Span,
key: 'name',
operator: PropertyOperator.Exact,
value: ['GET /api'],
},
{
type: PropertyFilterType.Span,
key: 'duration',
operator: PropertyOperator.GreaterThanOrEqual,
value: 1,
},
{
type: PropertyFilterType.Span,
key: 'duration',
operator: PropertyOperator.LessThan,
value: 2,
},
],
},
],
}
const result = heatmapBrushToFilters(
DATA,
{ x: { startIndex: 0, endIndex: 0 }, y: { startIndex: 2, endIndex: 2 } },
groupWithFilters,
null
)
expect((result?.filterGroup?.values[0] as UniversalFiltersGroup).values).toEqual([
{ type: PropertyFilterType.Span, key: 'name', operator: PropertyOperator.Exact, value: ['GET /api'] },
{ type: PropertyFilterType.Span, key: 'duration', operator: PropertyOperator.GreaterThanOrEqual, value: 5 },
{ type: PropertyFilterType.Span, key: 'duration', operator: PropertyOperator.LessThan, value: 10 },
])
})
it('drops a duration filter with any operator so no stale bound contradicts the brushed range', () => {
const groupWithOtherOperator: UniversalFiltersGroup = {
type: FilterLogicalOperator.And,
values: [
{
type: FilterLogicalOperator.And,
values: [
// A > bound the old >=/< matcher missed — left in place it would AND with
// the brushed pair and could empty the result set.
{
type: PropertyFilterType.Span,
key: 'duration',
operator: PropertyOperator.GreaterThan,
value: 100,
},
],
},
],
}
const result = heatmapBrushToFilters(
DATA,
{ x: { startIndex: 0, endIndex: 0 }, y: { startIndex: 0, endIndex: 1 } },
groupWithOtherOperator,
null
)
expect((result?.filterGroup?.values[0] as UniversalFiltersGroup).values).toEqual([
{ type: PropertyFilterType.Span, key: 'duration', operator: PropertyOperator.GreaterThanOrEqual, value: 1 },
{ type: PropertyFilterType.Span, key: 'duration', operator: PropertyOperator.LessThan, value: 5 },
])
})
it('returns null when the selection resolves to no start bucket', () => {
expect(
heatmapBrushToFilters(
{ timeBuckets: [], bucketsNs: [], labels: [], cells: [] },
{ x: { startIndex: 0, endIndex: 0 }, y: { startIndex: 0, endIndex: 0 } },
EMPTY_GROUP,
null
)
).toBeNull()
})
})