mirror of
https://github.com/garrytan/gstack.git
synced 2026-08-31 18:30:39 +02:00
explain-level-config, benchmark-cli, evidence move onto the shared helper; each file's remaining special-case spawnSync sites (raw-buffer probes, env-scrub probes) stay put deliberately. 55/55 green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
99 lines
3.7 KiB
TypeScript
99 lines
3.7 KiB
TypeScript
/**
|
|
* gstack-config explain_level round-trip + validation tests.
|
|
*
|
|
* Coverage:
|
|
* - `set explain_level default` persists, `get` returns "default"
|
|
* - `set explain_level terse` persists, `get` returns "terse"
|
|
* - `set explain_level garbage` warns + writes "default"
|
|
* - `get explain_level` with unset key returns empty (preamble bash defaults)
|
|
* - Annotated config header documents explain_level
|
|
*/
|
|
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import * as os from 'os';
|
|
|
|
import { runBin } from './helpers/run-bin';
|
|
|
|
const ROOT = path.resolve(import.meta.dir, '..');
|
|
const BIN_CONFIG = path.join(ROOT, 'bin', 'gstack-config');
|
|
|
|
let tmpHome: string;
|
|
|
|
beforeEach(() => {
|
|
tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-cfg-test-'));
|
|
});
|
|
|
|
afterEach(() => {
|
|
fs.rmSync(tmpHome, { recursive: true, force: true });
|
|
});
|
|
|
|
function run(...args: string[]): { stdout: string; stderr: string; status: number } {
|
|
// runBin's gstackHome sets GSTACK_HOME + GSTACK_STATE_DIR together — the
|
|
// config-precedence isolation this file used to document by hand.
|
|
return runBin(BIN_CONFIG, args, { gstackHome: tmpHome, cwd: ROOT, trim: true });
|
|
}
|
|
|
|
describe('gstack-config explain_level', () => {
|
|
test('set + get default round-trip', () => {
|
|
expect(run('set', 'explain_level', 'default').status).toBe(0);
|
|
expect(run('get', 'explain_level').stdout).toBe('default');
|
|
});
|
|
|
|
test('set + get terse round-trip', () => {
|
|
expect(run('set', 'explain_level', 'terse').status).toBe(0);
|
|
expect(run('get', 'explain_level').stdout).toBe('terse');
|
|
});
|
|
|
|
test('unknown value warns and defaults to default', () => {
|
|
const result = run('set', 'explain_level', 'garbage');
|
|
expect(result.status).toBe(0);
|
|
expect(result.stderr).toContain('not recognized');
|
|
expect(result.stderr).toContain('default, terse');
|
|
expect(run('get', 'explain_level').stdout).toBe('default');
|
|
});
|
|
|
|
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', () => {
|
|
// Trigger file creation with any set
|
|
run('set', 'explain_level', 'default');
|
|
const cfg = fs.readFileSync(path.join(tmpHome, 'config.yaml'), 'utf-8');
|
|
expect(cfg).toContain('explain_level');
|
|
expect(cfg).toContain('default');
|
|
expect(cfg).toContain('terse');
|
|
});
|
|
|
|
test('set terse, then set garbage restores default', () => {
|
|
run('set', 'explain_level', 'terse');
|
|
expect(run('get', 'explain_level').stdout).toBe('terse');
|
|
const garbage = run('set', 'explain_level', 'nonsense');
|
|
expect(garbage.stderr).toContain('not recognized');
|
|
expect(run('get', 'explain_level').stdout).toBe('default');
|
|
});
|
|
});
|
|
|
|
describe('gstack-config values with spaces', () => {
|
|
test('workspace_root preserves internal spaces on set/get/list', () => {
|
|
const value = path.join(os.tmpdir(), 'Conductor Workspaces');
|
|
expect(run('set', 'workspace_root', value).status).toBe(0);
|
|
|
|
expect(run('get', 'workspace_root').stdout).toBe(value);
|
|
|
|
const listed = run('list');
|
|
expect(listed.status).toBe(0);
|
|
expect(
|
|
listed.stdout
|
|
.split('\n')
|
|
.some((line) => line.includes('workspace_root:') && line.includes(value) && line.includes('(set)')),
|
|
).toBe(true);
|
|
});
|
|
});
|