test(brain-sync): GSTACK_HOME isolation test compares mtime, not content

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) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-04-25 21:01:46 -07:00
parent c72c56dde9
commit 472e79a28b
+19 -4
View File
@@ -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');
});
});