Files
zeekay 10e6fec4c0 debrand: the brand token is INSIGHTS_, and a wrong one stops the container
The rule table mapped HOG_ -> FN_ ahead of any POSTHOG rule, so POSTHOG_FOO
split into POST + HOG_ and came out POSTFN_FOO. Nothing sets that. The live
pods set INSIGHTS_SKIP_MIGRATION_CHECKS, which bin/migrate-check reads on the
container entrypoint, so the misspelling does not degrade a feature -- it runs
migrate --check against a database whose history this tree does not share and
the container never starts.

Both replacements are measured against the shipped tree rather than chosen:
every HOG_ name with a counterpart there is spelled INSIGHTS_ (HOG_QL ->
INSIGHTS_QL, HOG_FUNCTION_TEMPLATES -> INSIGHTS_FUNCTION_TEMPLATES, 12 of 12
determinate cases), and FN_ appears in it nowhere. Upstream carries 95 HOG_
tokens and zero FN_ ones, so repairing FN_ back out is exactly the inverse of
the bad rule and cannot collide with an upstream name.

The rule is fixed for the next convergence, and the tree it already produced is
repaired in the same commit -- the codemod is idempotent against its own output,
so it cannot undo this itself.
2026-08-01 17:42:28 -07:00

121 lines
4.5 KiB
TypeScript

import { buildIntegerMatcher, buildStringMatcher, getDefaultConfig, overrideWithEnv } from '~/common/config/config'
describe('config', () => {
test('overrideWithEnv 1', () => {
const defaultConfig = getDefaultConfig()
const env = {
INSTRUMENT_THREAD_PERFORMANCE: 'false',
TASK_TIMEOUT: '3008',
REDIS_URL: '0.0.0.0',
BASE_DIR: undefined,
}
const config = overrideWithEnv(getDefaultConfig(), env)
expect(config.INSTRUMENT_THREAD_PERFORMANCE).toEqual(false)
expect(config.TASK_TIMEOUT).toEqual(3008)
expect(config.REDIS_URL).toEqual('0.0.0.0')
expect(config.BASE_DIR).toEqual(defaultConfig.BASE_DIR)
})
test('overrideWithEnv 2', () => {
const env = {
INSTRUMENT_THREAD_PERFORMANCE: '1',
TASK_TIMEOUT: '3008.12',
}
const config = overrideWithEnv(getDefaultConfig(), env)
expect(config.INSTRUMENT_THREAD_PERFORMANCE).toEqual(true)
expect(config.TASK_TIMEOUT).toEqual(3008.12)
})
describe('DATABASE_URL', () => {
test('Error if DATABASE_URL is not set AND INSIGHTS_DB_NAME is not set', () => {
const env = {
DATABASE_URL: '',
INSIGHTS_DB_NAME: '',
}
expect(() => overrideWithEnv(getDefaultConfig(), env)).toThrow(
'You must specify either DATABASE_URL or the database options INSIGHTS_DB_NAME, INSIGHTS_DB_USER, INSIGHTS_DB_PASSWORD, INSIGHTS_POSTGRES_HOST, INSIGHTS_POSTGRES_PORT!'
)
})
test('Set DATABASE_URL to a string composed of URL-encoded connection options if DATABASE_URL is not explictly set', () => {
const env = {
DATABASE_URL: '',
INSIGHTS_DB_NAME: 'mydb',
INSIGHTS_DB_USER: 'user1@domain',
INSIGHTS_DB_PASSWORD: 'strong?password',
INSIGHTS_POSTGRES_HOST: 'my.host',
}
const config = overrideWithEnv(getDefaultConfig(), env)
expect(config.DATABASE_URL).toEqual('postgres://user1%40domain:strong%[email protected]:5432/mydb')
})
test('DATABASE_URL takes precedence to individual config options', () => {
const env = {
DATABASE_URL: 'my_db_url',
INSIGHTS_DB_NAME: 'mydb',
INSIGHTS_DB_USER: 'user1',
INSIGHTS_DB_PASSWORD: 'strongpassword',
INSIGHTS_POSTGRES_HOST: 'my.host',
}
const config = overrideWithEnv(getDefaultConfig(), env)
expect(config.DATABASE_URL).toEqual('my_db_url')
})
})
})
describe('buildIntegerMatcher', () => {
test('empty input', () => {
const matcher = buildIntegerMatcher('', false)
expect(matcher(2)).toBe(false)
})
test('ignores star star when not allowed', () => {
const matcher = buildIntegerMatcher('*', false)
expect(matcher(2)).toBe(false)
})
test('matches star when allowed', () => {
const matcher = buildIntegerMatcher('*', true)
expect(matcher(2)).toBe(true)
})
test('can match on a single value', () => {
const matcher = buildIntegerMatcher('2', true)
expect(matcher(2)).toBe(true)
expect(matcher(3)).toBe(false)
})
test('can match on several values', () => {
const matcher = buildIntegerMatcher('2,3,4', true)
expect(matcher(2)).toBe(true)
expect(matcher(3)).toBe(true)
expect(matcher(4)).toBe(true)
expect(matcher(5)).toBe(false)
})
})
describe('buildStringMatcher', () => {
test('empty input', () => {
const matcher = buildStringMatcher('', false)
expect(matcher('b')).toBe(false)
})
test('ignores star star when not allowed', () => {
const matcher = buildStringMatcher('*', false)
expect(matcher('b')).toBe(false)
})
test('matches star when allowed', () => {
const matcher = buildStringMatcher('*', true)
expect(matcher('b')).toBe(true)
})
test('can match on a single value', () => {
const matcher = buildStringMatcher('b', true)
expect(matcher('b')).toBe(true)
expect(matcher('a')).toBe(false)
})
test('can match on several values', () => {
const matcher = buildStringMatcher('b,c,d', true)
expect(matcher('b')).toBe(true)
expect(matcher('c')).toBe(true)
expect(matcher('d')).toBe(true)
expect(matcher('e')).toBe(false)
})
})