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

84 lines
3.4 KiB
JavaScript

// MSW v2 intercepts requests via spec-compliant fetch primitives that jsdom does
// not provide. Source them from undici (jsdom otherwise clobbers the Node globals)
// and assign before the test framework boots, so this must run first in setupFiles.
/* eslint-disable @typescript-eslint/no-require-imports */
const { TextEncoder, TextDecoder } = require('node:util')
const { ReadableStream, WritableStream, TransformStream } = require('node:stream/web')
const { Blob, File } = require('node:buffer')
const { BroadcastChannel, MessageChannel, MessagePort } = require('node:worker_threads')
// configurable so @mswjs/interceptors can wrap Request/Response when the server starts.
const define = (props) =>
Object.defineProperties(
globalThis,
Object.fromEntries(
Object.entries(props).map(([key, value]) => [key, { value, writable: true, configurable: true }])
)
)
// undici references TextEncoder/streams at module-eval time, so define these first.
define({
TextEncoder,
TextDecoder,
ReadableStream,
WritableStream,
TransformStream,
Blob,
File,
BroadcastChannel,
MessageChannel,
MessagePort,
})
// jsdom's setTimeout returns a number, but undici's internal fast-timer calls `.refresh()`/`.unref()`
// on the returned handle. Wrap jsdom's timer (so it still tears down with the window — Node's would
// leak past teardown) and expose a refreshable handle. Jest fake timers override these per-test.
const jsdomSetTimeout = globalThis.setTimeout
const jsdomClearTimeout = globalThis.clearTimeout
const handleId = (handle) => (handle && typeof handle === 'object' ? handle.__id : handle)
define({
setTimeout: (callback, delay, ...args) => {
const handle = {
refresh() {
jsdomClearTimeout(this.__id)
this.__id = jsdomSetTimeout(callback, delay, ...args)
return this
},
unref() {
return this
},
ref() {
return this
},
[Symbol.toPrimitive]() {
return this.__id
},
}
handle.__id = jsdomSetTimeout(callback, delay, ...args)
return handle
},
clearTimeout: (handle) => jsdomClearTimeout(handleId(handle)),
})
// jsdom lacks setImmediate/clearImmediate, which undici needs. Node's setImmediate fires on the
// libuv check phase, which keeps running after jsdom tears down the window — and React 18's
// scheduler prefers setImmediate for performWorkUntilDeadline, so its render work lands
// post-teardown and throws "The `document` global ... is not defined anymore", crashing the whole
// file. Route it through the jsdom-bound setTimeout above so it tears down with the window instead.
define({
setImmediate: (callback, ...args) => globalThis.setTimeout(callback, 0, ...args),
clearImmediate: (handle) => globalThis.clearTimeout(handle),
})
// undici's fetch calls performance.markResourceTiming, which jsdom's performance lacks.
if (typeof globalThis.performance?.markResourceTiming !== 'function') {
if (!globalThis.performance) {
globalThis.performance = require('node:perf_hooks').performance
}
globalThis.performance.markResourceTiming = () => {}
}
const { fetch, Request, Response, Headers, FormData } = require('undici')
define({ fetch, Request, Response, Headers, FormData })