Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(backup): stale-socket fixtures model the macOS socket path and run on macOS again (#6573)
time-attack64e4f6139218
diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex 2c6a966d5e..ccef1299ad 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -225,11 +225,11 @@ jobs:run: bun test --timeout 120000 test/postgres-disconnect-bounded.test.ts- name: Backup archive round trip on this host (#5312)run: bun test --timeout 60000 test/backup-archive-roundtrip-5312.test.ts- # The stale-socket sweep's native AF_UNIX reparse-point path exists only on Windows; the POSIX cases run in the- # Linux unit shards. On macOS the PGLite socket lives at a shortened /private/tmp path (the 104-byte AF_UNIX limit),- # which this file's data-dir fixtures do not model: wave 16 follow-up, not covered here.- - name: Stale AF_UNIX socket sweep through the native tag check (#5312)- if: runner.os == 'Windows'+ # The stale-socket sweep's native AF_UNIX reparse-point path exists only on Windows; macOS runs the POSIX cases+ # here (#6573: the fixture root is under /private/tmp, so the data-dir socket stays under gbrain's 103-byte limit+ # instead of moving to the shortened fallback path); Linux runs them in the unit shards.+ - name: Stale AF_UNIX socket sweep (native tag check on Windows, POSIX cases on macOS) (#5312, #6573)+ if: runner.os == 'Windows' || runner.os == 'macOS'run: bun test --timeout 60000 test/backup-stale-socket-5312.test.ts- name: Hidden console windows from detached processes (#4992)run: bun test --timeout 300000 test/windows-hidden-console.test.ts test/spawn-windows-hide.test.ts test/scripts/windows-hide-guard.test.tsdiff --git a/test/backup-stale-socket-5312.test.ts b/test/backup-stale-socket-5312.test.tsindex c15e01dcc8..a584449805 100644--- a/test/backup-stale-socket-5312.test.ts+++ b/test/backup-stale-socket-5312.test.ts@@ -32,6 +32,7 @@ import { createPgliteBackup } from '../src/core/backup/snapshot.ts';import { sweepStaleRuntimeArtefacts } from '../src/core/backup/runtime-artefacts.ts';import { PGLiteEngine } from '../src/core/pglite-engine.ts';import { resolveSocketPathForConfig } from '../src/core/context/resolve-ipc.ts';+import { UNIX_SOCKET_PATH_MAX_BYTES } from '../src/core/context/ipc-path.ts';const posix = process.platform !== 'win32';const windows = process.platform === 'win32';@@ -102,19 +103,21 @@ async function backupFailure(): Promise<{ code: string; message: string }> {throw new Error('backup unexpectedly succeeded');}-// sockaddr_un.sun_path is 108 bytes on Linux and Windows (afunix.sys) and 104 on Darwin. On Windows the socket is-// bound at the data-dir path itself (no shortened fallback), and the runner's TEMP (`C:\Users\RUNNER~1\AppData\Local\Temp`)-// plus the old 19-character prefix put `<dataDir>\.gbrain-persistence.sock` at 114 bytes, so every listen failed-// before the sweep ran. The prefix is short and the fixture refuses up front when the path would not fit.-const SUN_PATH_LIMIT = process.platform === 'darwin' ? 104 : 108;+// On Windows the socket is bound at the data-dir path itself (no shortened fallback) and afunix.sys's sun_path is 108+// bytes; the runner's TEMP (`C:\Users\RUNNER~1\AppData\Local\Temp`) plus the old 19-character prefix put+// `<dataDir>\.gbrain-persistence.sock` at 114 bytes, so every listen failed before the sweep ran. On POSIX gbrain keeps+// the data-dir socket only up to UNIX_SOCKET_PATH_MAX_BYTES and otherwise binds a shortened /tmp path the sweep never+// sees (#6573: macOS's TMPDIR always crossed it, so the planted sockets sat where nothing looked). So the POSIX fixture+// root is under /tmp (realpath'd: /private/tmp on macOS), and the fixture refuses up front when the path would not fit.+const SOCKET_PATH_LIMIT = windows ? 107 : UNIX_SOCKET_PATH_MAX_BYTES;beforeAll(async () => {- temporary = realpathSync(mkdtempSync(join(tmpdir(), 'g5312-')));+ temporary = realpathSync(mkdtempSync(join(windows ? tmpdir() : '/tmp', 'g5312-')));root = join(temporary, 'brain');mkdirSync(join(root, '.gbrain'), { recursive: true, mode: 0o700 });dataDir = join(root, '.gbrain', 'brain.pglite');const longest = join(dataDir, '.gbrain-persistence.sock');- if (Buffer.byteLength(longest) >= SUN_PATH_LIMIT) throw new Error(`fixture socket path is ${Buffer.byteLength(longest)} bytes, at or over the ${SUN_PATH_LIMIT}-byte AF_UNIX limit: ${longest}`);+ if (Buffer.byteLength(longest) > SOCKET_PATH_LIMIT) throw new Error(`fixture socket path is ${Buffer.byteLength(longest)} bytes, over the ${SOCKET_PATH_LIMIT}-byte data-dir socket limit: ${longest}`);privateWrite(join(root, '.gbrain', 'config.json'), JSON.stringify({ engine: 'pglite', database_path: dataDir, embedding_disabled: true }));const engine = new PGLiteEngine();await engine.connect({ engine: 'pglite', database_path: dataDir });