Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(doctor-pglite-datadir): the stale postmaster.pid case writes a provably dead PID, not a fixed 99999 that a busy VM can have live

garrytan0d35726bca71
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c8c2f5c583..2e49a20d48 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,13 @@ identifiers and attribution are available in the pre-removal Git revision
- **New doctor check `provider_consent`** (filesystem lane, also in `--fast`): reports a decline as "skipped by consent", names the provider variables present (names only) and gives `gbrain setup <harness> --providers` as the user's choice; `not_applicable` without a setup receipt.
- **Tests:** `test/hook-session-start-serve-wait.serial.test.ts` (an IPC server bound 800 ms after SessionStart over in-memory PGLite; PGLite, Postgres keying, resume, a project receipt, a server that never comes, and no-wait controls) and `test/doctor-provider-consent.serial.test.ts` (a request counter behind `OPENAI_BASE_URL`: zero requests under a decline for `doctor --json` and `doctor --probe --yes`, 4 of 5 cases fail on master), plus a unit case in `test/openai-latest.serial.test.ts` and the doctor goldens.
+## [Unreleased]
+
+### Itemized changes
+
+- **Flake fix: `test/doctor-pglite-datadir.test.ts` case (c) stages its stale `postmaster.pid` with a provably dead PID.** The case wrote the fixed PID 99999; on a busy gate VM (`pid_max` 4194304) that number can belong to a live process, and the live-postmaster guard in `validatePgliteLayout` then refuses the directory, so the verdict read `unsupported-layout` instead of `wal-corruption-likely` (GBRA-89's finding). The PID now comes from a child that was spawned and reaped (`test/helpers/dead-pid.ts`, the helper four other tests already carried inline). Forced probe (the case writes a live PID, which is what CI saw): 3/3 fail before with exactly that verdict, 16/16 after. The assertion is unchanged.
+- **Diagnostic: `test/cli-exit-drain.test.ts` failure messages carry each stream's end state and event order.** One run (38352625321) read 0 of 100 stdout bytes while the exit code and the sibling cases were fine, and the message could not tell a stream closed under its reader from one that ended cleanly empty; it now records `readableEnded`/`destroyed`/`errored` for both streams and the order of `end`, `close` and `exit` events. No assertion changed; the three cases still assert the same bytes.
+
## [0.60.196.0] - 2026-10-13
### Itemized changes
diff --git a/test/doctor-pglite-datadir.test.ts b/test/doctor-pglite-datadir.test.ts
index e43adca8c5..a12da49aca 100644
--- a/test/doctor-pglite-datadir.test.ts
+++ b/test/doctor-pglite-datadir.test.ts
@@ -22,6 +22,7 @@ import { computePgliteDataDirCheck } from '../src/commands/doctor.ts';
import { OPS_CHECK_NAMES } from '../src/core/doctor-categories.ts';
import { inspectPgliteDataDir } from '../src/core/pglite-repair.ts';
import type { PgliteDirDiagnosis } from '../src/core/pglite-repair.ts';
+import { deadPid } from './helpers/dead-pid.ts';
function tmp(prefix: string): string {
return mkdtempSync(join(tmpdir(), prefix));
@@ -190,7 +191,7 @@ describe('inspectPgliteDataDir — synthetic on-disk layouts', () => {
test('(c) full fake layout + stale postmaster.pid → wal-corruption-likely', () => {
const dir = join(tmp('gbrain-inspect-c-'), 'brain.pglite');
makeFakeLayout(dir);
- writeFileSync(join(dir, 'postmaster.pid'), '99999\n');
+ writeFileSync(join(dir, 'postmaster.pid'), `${deadPid()}\n`); // a fixed 99999 can be a live process on a busy VM
const diagnosis = inspectPgliteDataDir(dir);
expect(diagnosis.verdict).toBe('wal-corruption-likely');
expect(diagnosis.postmasterPid).toBe(true);
diff --git a/test/helpers/dead-pid.ts b/test/helpers/dead-pid.ts
new file mode 100644
index 0000000000..6269a04b3b
--- /dev/null
+++ b/test/helpers/dead-pid.ts
@@ -0,0 +1,17 @@
+/**
+ * A PID that is provably not running: a child spawned and already reaped, re-checked with
+ * `kill -0` so a reused number is retried. Tests that stage a "stale" postmaster.pid or lock
+ * must not write a fixed number such as 99999: on a busy gate VM (pid_max 4194304) it can
+ * name a live process, and the live-process guards then refuse the directory.
+ */
+export function deadPid(): number {
+ for (let attempt = 0; attempt < 5; attempt++) {
+ const pid = Bun.spawnSync(['bash', '-c', 'exit 0']).pid;
+ try {
+ process.kill(pid, 0);
+ } catch {
+ return pid;
+ }
+ }
+ throw new Error('could not obtain a provably-dead PID after 5 spawns');
+}