Files
insights/nodejs/jest.setup-env.ts
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

30 lines
1.7 KiB
TypeScript

import { mkdirSync, readFileSync, writeFileSync } from 'fs'
import { join } from 'path'
import { brotliDecompressSync } from 'zlib'
// Jest's CLI only sets NODE_ENV=test when it is unset. When tests are launched
// from an environment where NODE_ENV or DEBUG is already set (IDE test runners,
// debuggers, flox exports DEBUG=1), `determineNodeEnv()` resolves to dev and
// every config default (DATABASE_URL, PERSONS_DATABASE_URL, DATASTORE_DATABASE,
// CYCLOTRON_DATABASE_URL, ...) points at the real dev databases — which
// destructive test helpers would then wipe. Force the test environment so the
// defaults always resolve to their test_* counterparts. Explicitly exported
// *_DATABASE_URL variables still win; tests/helpers/database-guard.ts catches
// those when they point at a non-test database.
process.env.NODE_ENV = 'test'
// Tests must never read the live GeoLite2 database from share/ — it is re-downloaded
// unpinned from mmdbcdn.insights.net and its data changes under us (see the recurring
// postal-code snapshot drift). Point every GeoIPService at MaxMind's frozen test
// database instead, so lookups are deterministic. Use IPs from the test ranges
// (e.g. 89.160.20.129 → Linköping, 216.160.83.56 → Milton) in tests.
const fixturePath = join(__dirname, 'tests', 'assets', 'GeoLite2-City-Test.mmdb.br')
const mmdbPath = join(__dirname, '.tmp', 'GeoLite2-City-Test.mmdb')
mkdirSync(join(__dirname, '.tmp'), { recursive: true })
writeFileSync(mmdbPath, brotliDecompressSync(readFileSync(fixturePath)))
// Sidecar metadata file, so GeoIPService doesn't warn about a missing one on every load
writeFileSync(mmdbPath.replace('.mmdb', '.json'), JSON.stringify({ date: '2025-01-01' }))
process.env.MMDB_FILE_LOCATION = mmdbPath