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'); }); });