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

86 lines
3.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { AlertConditionType, InsightThresholdType } from '~/queries/schema/schema-general'
import {
fractionToPercentInput,
inputToStoredBound,
rescaleThresholdBound,
thresholdForConditionChange,
thresholdForUnitChange,
} from './thresholdPercent'
describe('thresholdPercent', () => {
it.each([
[undefined, InsightThresholdType.ABSOLUTE, undefined],
[NaN, InsightThresholdType.ABSOLUTE, undefined],
[100, InsightThresholdType.ABSOLUTE, 100],
[100, InsightThresholdType.PERCENTAGE, 1],
])('stores input %p with %s units as %p', (value, type, expected) => {
expect(inputToStoredBound(value, type)).toBe(expected)
})
// Stored 0–1 fractions render as percentage inputs without float noise — guards the ×100
// round-trip surfacing values like 7.000000000000001 (regresses if the rounding is dropped).
it.each([
[undefined, undefined],
[0.99, 99],
[0.077, 7.7],
[0.3333, 33.33],
[1, 100],
])('fractionToPercentInput(%p) === %p', (fraction, expected) => {
expect(fractionToPercentInput(fraction)).toBe(expected)
})
// Flipping a funnel's condition flips the threshold unit; the bound must rescale so the on-screen
// number is preserved (regresses to a ×100 blowup — 99 → 9900 — if the rescale is dropped).
it.each([
[99, InsightThresholdType.PERCENTAGE, 0.99],
[0.99, InsightThresholdType.ABSOLUTE, 99],
[7, InsightThresholdType.PERCENTAGE, 0.07],
[undefined, InsightThresholdType.PERCENTAGE, undefined],
])('rescaleThresholdBound(%p, %s) === %p', (value, toType, expected) => {
expect(rescaleThresholdBound(value as number | undefined, toType)).toBe(expected)
})
it('preserves the displayed number across a unit switch instead of ×100-ing it', () => {
// Entered as "99%" under a has-value (ABSOLUTE) condition, then switched to relative.
const asFraction = rescaleThresholdBound(99, InsightThresholdType.PERCENTAGE)
expect(fractionToPercentInput(asFraction)).toBe(99) // was 9900 before the fix
})
it.each([
[
InsightThresholdType.PERCENTAGE,
{ lower: 0.1, upper: 0.25 },
InsightThresholdType.ABSOLUTE,
{ lower: 10, upper: 25 },
],
[
InsightThresholdType.ABSOLUTE,
{ lower: 10, upper: 25 },
InsightThresholdType.PERCENTAGE,
{ lower: 0.1, upper: 0.25 },
],
])('preserves displayed bounds when switching from %s to %s', (fromType, bounds, toType, expectedBounds) => {
expect(thresholdForUnitChange({ type: fromType, bounds }, toType)).toEqual({
type: toType,
bounds: expectedBounds,
})
})
it('preserves displayed percentage values when switching to an absolute condition', () => {
expect(
thresholdForConditionChange(
{
type: InsightThresholdType.PERCENTAGE,
bounds: { lower: 0.2, upper: 3 },
},
AlertConditionType.ABSOLUTE_VALUE,
false
)
).toEqual({
type: InsightThresholdType.ABSOLUTE,
bounds: { lower: 20, upper: 300 },
})
})
})