mirror of
https://github.com/garrytan/gstack.git
synced 2026-06-19 00:00:13 +02:00
test(gbrain-sync): regression for #1611 timeouts + resume
19 tests across three surfaces:
- resolveStageTimeoutMs (10 tests): undefined/empty → default; non-numeric,
zero, negative, below-floor, above-ceiling → warn + default; at-floor,
at-ceiling, valid mid-range → accepted as-is.
- decideResume (6 tests): no checkpoint, corrupt JSON, checkpoint + staging
ok, checkpoint + staging missing, checkpoint with no dir, checkpoint with
empty dir.
- SIGTERM staging preservation (3 static invariants): memory-ingest signal
handler must check stagingDirIsCheckpointed BEFORE cleanup; preserve
branch must come before cleanup branch (ordering); orchestrator must
pass GSTACK_INGEST_RESUME_DIR to the grandchild on resume.
Also threads process.env.HOME through readGbrainCheckpoint and
stagingDirIsCheckpointed so tests can redirect home. os.homedir() caches
at process start and ignores later mutation, so the env override is the
only reliable test injection point.
Failing build if the timeout bounds are removed, the resume detection
short-circuits incorrectly, or the SIGTERM handler regresses to
unconditional cleanup.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -137,7 +137,11 @@ interface GbrainCheckpoint {
|
||||
}
|
||||
|
||||
export function readGbrainCheckpoint(): GbrainCheckpoint | null {
|
||||
const cpPath = join(homedir(), ".gbrain", "import-checkpoint.json");
|
||||
// Read HOME from env so tests can redirect via process.env.HOME = ...
|
||||
// (Node/Bun's os.homedir() caches at process start and ignores later
|
||||
// mutations.)
|
||||
const home = process.env.HOME || homedir();
|
||||
const cpPath = join(home, ".gbrain", "import-checkpoint.json");
|
||||
if (!existsSync(cpPath)) return null;
|
||||
try {
|
||||
const raw = readFileSync(cpPath, "utf-8");
|
||||
|
||||
@@ -1293,7 +1293,9 @@ let _signalHandlersInstalled = false;
|
||||
*/
|
||||
function stagingDirIsCheckpointed(stagingDir: string): boolean {
|
||||
try {
|
||||
const cpPath = join(homedir(), ".gbrain", "import-checkpoint.json");
|
||||
// Read HOME from env so tests can redirect; homedir() caches.
|
||||
const home = process.env.HOME || homedir();
|
||||
const cpPath = join(home, ".gbrain", "import-checkpoint.json");
|
||||
if (!existsSync(cpPath)) return false;
|
||||
const raw = readFileSync(cpPath, "utf-8");
|
||||
const cp = JSON.parse(raw) as { dir?: string };
|
||||
|
||||
Reference in New Issue
Block a user