fix(git-sync): git-http stream error handlers + close test gaps (#119 review)
Addresses the stability + test-coverage warnings from the #119 review: - git-http-backend.service.ts: add `'error'` handlers to child.stdout/stderr. An EventEmitter 'error' with no listener (e.g. EPIPE when the client aborts mid-response) is rethrown by Node as an uncaught exception and crashes the process; now swallowed + logged (never echoed to the client). - TEST INFRA: a jest setupFile shims `navigator`/`MessageChannel` for the `node` testEnvironment. react-dom@18 reads `navigator` at module-init (pulled in via @docmost/editor-ext -> @tiptap/react), so every spec transitively importing the conversion engine — including git-http.service.spec.ts — previously FAILED TO LOAD ("navigator is not defined") and ran ZERO tests. With the shim those specs now run (git-sync integration: 11 suites / 133 tests green). - git-http.service.spec.ts: cover the 503 lock-held push path — `ingestExternalPush` rejecting `GitSyncLockHeldError` -> 503 + Retry-After + "git-sync busy, retry", no double header write (+ the already-headers-sent no-rewrite path). - git-http-backend.service.spec.ts: unit-test run() — child 'error'/'close' before headers -> 500; normal CGI parse+stream; stdout/stderr 'error' (EPIPE) swallowed; synchronous spawn throw -> 500. - page-change.listener.ts: implement OnModuleDestroy to clearTimeout all pending debounce timers on shutdown (+ test). - .env.example: vaults are non-bare working repos, not "bare repos". (Docs deleted by the stray commit were restored in 9cdbce54.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
29
apps/server/test/jest.setup.ts
Normal file
29
apps/server/test/jest.setup.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
// Jest global setup (runs before each test module loads).
|
||||
//
|
||||
// react-dom@18 (pulled in transitively via @docmost/editor-ext -> @tiptap/react
|
||||
// -> react-dom, e.g. through the math node) reads `navigator` at MODULE-INIT
|
||||
// time. The server jest config uses `testEnvironment: "node"`, which has no
|
||||
// `navigator`, so ANY spec that transitively imports the editor schema/engine
|
||||
// (e.g. the git-sync HTTP service specs, which reach the conversion engine)
|
||||
// fails to LOAD with "ReferenceError: navigator is not defined". These specs
|
||||
// never exercise the DOM — they just can't survive the import. Provide the
|
||||
// minimal browser globals those modules touch at import so the specs run.
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
const g = globalThis as any;
|
||||
|
||||
if (typeof g.navigator === "undefined") {
|
||||
// react-dom only reads navigator.userAgent at init; keep it minimal.
|
||||
Object.defineProperty(g, "navigator", {
|
||||
value: { userAgent: "node", platform: "node" },
|
||||
configurable: true,
|
||||
writable: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof g.MessageChannel === "undefined") {
|
||||
// react-dom's scheduler references MessageChannel at init in some builds.
|
||||
g.MessageChannel = class {
|
||||
port1 = { postMessage() {}, close() {}, onmessage: null };
|
||||
port2 = { postMessage() {}, close() {}, onmessage: null };
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user