mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-20 20:00:45 +02:00
fix(browse): write self-contained .gstack/.gitignore unconditionally
ensureStateDir only appended .gstack/ to the project .gitignore when that file already existed, skipped silently on ENOENT, and swallowed other append failures. With BROWSE_PERSIST_STATE=1, session-state.json (live cookies + localStorage/sessionStorage tokens) and browse-network.log / browse-audit.jsonl (request headers) then sat git-add-able under <git-root>/.gstack/. Write a self-contained <stateDir>/.gitignore containing "*" unconditionally, before return, so the state dir's contents can never be committed regardless of the project .gitignore. The project-.gitignore append is kept as redundant safety. The no-import-side-effects guard is relaxed to allow exactly this lone .gitignore guard file (still fails on browse.json / session-state.json / logs / listener binds) — the guard is written eagerly by ensureStateDir at import and is not leaked state. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
57a1d957f4
commit
4992a48c57
@@ -61,6 +61,21 @@ describe('config', () => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('writes a self-contained .gstack/.gitignore with * unconditionally', () => {
|
||||
// Even with NO project .gitignore, the state dir must carry its own
|
||||
// ignore so persisted cookies / network+audit logs can never be git-added.
|
||||
const tmpDir = path.join(os.tmpdir(), `browse-selfignore-test-${Date.now()}`);
|
||||
fs.mkdirSync(tmpDir, { recursive: true });
|
||||
const config = resolveConfig({ BROWSE_STATE_FILE: path.join(tmpDir, '.gstack', 'browse.json') });
|
||||
ensureStateDir(config);
|
||||
const selfIgnore = path.join(config.stateDir, '.gitignore');
|
||||
expect(fs.existsSync(selfIgnore)).toBe(true);
|
||||
expect(fs.readFileSync(selfIgnore, 'utf-8')).toBe('*\n');
|
||||
// No nesting: the ignore is directly inside the state dir, not .gstack/.gstack/.
|
||||
expect(fs.existsSync(path.join(config.stateDir, '.gstack'))).toBe(false);
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('adds .gstack/ to .gitignore if not present', () => {
|
||||
const tmpDir = path.join(os.tmpdir(), `browse-gitignore-test-${Date.now()}`);
|
||||
fs.mkdirSync(tmpDir, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user