From 2ebfed600bfc589fd95f4f1f92b8ffbbca156d99 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sun, 24 May 2026 00:37:55 -0700 Subject: [PATCH] fix(tests): explain_level unset returns the documented default, not empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pre-existing failure on main — the test expected gstack-config to return "" for an unset explain_level (with the comment "preamble default takes over"), but the script at bin/gstack-config:103 explicitly returns "default" inline for that key. Earlier versions of the script may have relied on shell-substitution fallback, but the current contract is inline-default-on-get so callers always receive a usable value without bash gymnastics. Updated the test to match the actual contract. Also added GSTACK_HOME override alongside GSTACK_STATE_DIR in the spawn env so developer-machine config doesn't bleed into the test. Co-Authored-By: Claude Opus 4.7 (1M context) --- test/explain-level-config.test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/explain-level-config.test.ts b/test/explain-level-config.test.ts index 24cb644d2..9a48a9f6b 100644 --- a/test/explain-level-config.test.ts +++ b/test/explain-level-config.test.ts @@ -28,8 +28,11 @@ afterEach(() => { }); function run(...args: string[]): { stdout: string; stderr: string; status: number } { + // gstack-config precedence is `${GSTACK_HOME:-${GSTACK_STATE_DIR:-$HOME/.gstack}}`, + // so GSTACK_HOME from the developer's parent env wins over the test's + // GSTACK_STATE_DIR. Override both to isolate from the real ~/.gstack. const res = spawnSync(BIN_CONFIG, args, { - env: { ...process.env, GSTACK_STATE_DIR: tmpHome }, + env: { ...process.env, GSTACK_STATE_DIR: tmpHome, GSTACK_HOME: tmpHome }, encoding: 'utf-8', cwd: ROOT, }); @@ -59,9 +62,13 @@ describe('gstack-config explain_level', () => { expect(run('get', 'explain_level').stdout).toBe('default'); }); - test('get with unset explain_level returns empty (preamble default takes over)', () => { - // No prior set → no config file → empty output - expect(run('get', 'explain_level').stdout).toBe(''); + test('get with unset explain_level returns the documented default', () => { + // gstack-config returns the documented default ("default") when the + // key is absent from config.yaml — see bin/gstack-config:103. Earlier + // versions of this test expected "" (preamble shell substitution), + // but the script ships defaults inline so callers always get a + // usable value without bash fallback gymnastics. + expect(run('get', 'explain_level').stdout).toBe('default'); }); test('config header documents explain_level', () => {