From 472e79a28ba802a1dd2b5ea57a1039c8442103f7 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sat, 25 Apr 2026 21:01:46 -0700 Subject: [PATCH] test(brain-sync): GSTACK_HOME isolation test compares mtime, not content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pre-existing flaky test: the GSTACK_HOME-overrides-real-config test asserted the real ~/.gstack/config.yaml does NOT contain "gbrain_sync_mode: full" after the test. That fails for any user whose real config legitimately has that key set from prior usage — the test's invariant is "the command did not modify the real file," not "the real file lacks any specific value." Switch to mtime + content snapshot: capture both BEFORE running the command, then verify both are unchanged after. Also add a positive assertion that the tmpHome config DID get the new key. Co-Authored-By: Claude Opus 4.7 (1M context) --- test/brain-sync.test.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/brain-sync.test.ts b/test/brain-sync.test.ts index 6ba8e95c..6d992230 100644 --- a/test/brain-sync.test.ts +++ b/test/brain-sync.test.ts @@ -97,11 +97,26 @@ describe('gstack-config gbrain keys', () => { }); test('GSTACK_HOME overrides real config dir', () => { - run(['gstack-config', 'set', 'gbrain_sync_mode', 'full']); - // Real ~/.gstack/config.yaml must NOT have been touched. + // Snapshot the real config's mtime + content BEFORE we run the command. + // Comparing snapshots beats checking final content: the real config may + // already contain "gbrain_sync_mode: full" from prior real usage, which + // would create a false positive. We're testing that the command did NOT + // modify the real file, not that the real file lacks any specific value. const realConfig = path.join(os.homedir(), '.gstack', 'config.yaml'); - const real = fs.existsSync(realConfig) ? fs.readFileSync(realConfig, 'utf-8') : ''; - expect(real).not.toContain('gbrain_sync_mode: full'); + const before = fs.existsSync(realConfig) + ? { mtime: fs.statSync(realConfig).mtimeMs, content: fs.readFileSync(realConfig, 'utf-8') } + : null; + run(['gstack-config', 'set', 'gbrain_sync_mode', 'full']); + if (before) { + const after = fs.statSync(realConfig); + expect(after.mtimeMs).toBe(before.mtime); + expect(fs.readFileSync(realConfig, 'utf-8')).toBe(before.content); + } else { + expect(fs.existsSync(realConfig)).toBe(false); + } + // The tmpHome config DID get written. + const tmpConfig = fs.readFileSync(path.join(tmpHome, 'config.yaml'), 'utf-8'); + expect(tmpConfig).toContain('gbrain_sync_mode: full'); }); });