From 7396f048479c627331d905d2a280d30eb1113b18 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sat, 30 May 2026 11:32:28 -0700 Subject: [PATCH] test(plan-tune): de-flake "derive pushes scope_appetite up" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test was ~25-50% flaky (worse on main). gstack-question-log fires a fire-and-forget background `--derive` after every write; the 5 rapid log writes spawned 5 racing background derives that collided with the test's explicit --derive — a late one that only saw 3 entries could clobber developer-profile.json after the explicit one wrote sample_size=5. Set GSTACK_QUESTION_LOG_NO_DERIVE=1 (the flag the binary documents for exactly this case) so the writes don't spawn background derives. The explicit --derive still runs, so real derive behavior is still asserted. 20/20 green after. Co-Authored-By: Claude Opus 4.8 (1M context) --- test/plan-tune.test.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/plan-tune.test.ts b/test/plan-tune.test.ts index 9e83a0b4e..40a1465b6 100644 --- a/test/plan-tune.test.ts +++ b/test/plan-tune.test.ts @@ -535,7 +535,15 @@ describe('end-to-end pipeline (binaries working together)', () => { test('log many expand choices → derive pushes scope_appetite up', () => { const tmpHome = fs.mkdtempSync(path.join(require('os').tmpdir(), 'gstack-e2e-')); try { - const env = { ...process.env, GSTACK_HOME: tmpHome }; + // GSTACK_QUESTION_LOG_NO_DERIVE=1 suppresses gstack-question-log's + // fire-and-forget background `--derive` (it nohups one per write). Without + // it, the 5 rapid log writes spawn 5 racing background derives that collide + // with this test's explicit --derive below — a late background derive that + // only saw 3 entries can clobber developer-profile.json after the explicit + // one wrote sample_size=5, making the test flaky (~25-50% fail). The binary + // documents this flag for exactly this case. The explicit --derive still + // runs (it ignores the flag), so real derive behavior is still asserted. + const env = { ...process.env, GSTACK_HOME: tmpHome, GSTACK_QUESTION_LOG_NO_DERIVE: '1' }; const { spawnSync } = require('child_process'); const logBin = path.join(ROOT, 'bin', 'gstack-question-log'); const devBin = path.join(ROOT, 'bin', 'gstack-developer-profile');