Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions bin/gstack-config
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# Docs: https://github.com/garrytan/gstack/blob/main/docs/state-root.md
set -euo pipefail

. "$(dirname "$0")/gstack-state-root.sh" 2>/dev/null || { echo "$0: cannot resolve the gstack state root: $(dirname "$0")/gstack-state-root.sh is missing. fix: reinstall with ./setup or /gstack-upgrade (docs/state-root.md)" >&2; exit 1; }
[ -r "$(dirname "$0")/gstack-state-root.sh" ] && . "$(dirname "$0")/gstack-state-root.sh" 2>/dev/null || { echo "$0: cannot resolve the gstack state root: $(dirname "$0")/gstack-state-root.sh is missing. fix: reinstall with ./setup or /gstack-upgrade (docs/state-root.md)" >&2; exit 1; }
gstack_state_root_select
STATE_DIR="$_gstack_sr_root"
CONFIG_FILE="$STATE_DIR/config.yaml"
Expand Down Expand Up @@ -621,15 +621,14 @@ _SELF="$(cd "$(dirname "$0")" && pwd)/gstack-config"

# One line when the root-selecting variables name different directories.
report_root_disagreement() {
local _v _val _set="" _distinct=""
local _v _val _set="" _first="" _disagrees=0
for _v in GSTACK_STATE_ROOT GSTACK_HOME GSTACK_STATE_DIR; do
eval "_val=\${$_v:-}"
[ -n "$_val" ] || continue
_set="$_set $_v=$_val"
case " $_distinct " in *" $_val "*) ;; *) _distinct="$_distinct $_val" ;; esac
if [ -z "$_first" ]; then _first="$_val"; elif [ "$_val" != "$_first" ]; then _disagrees=1; fi
done
set -- $_distinct
[ "$#" -gt 1 ] || return 0
[ "$_disagrees" -eq 1 ] || return 0
echo "# note: root-selecting variables disagree:$_set; using $STATE_DIR ($_gstack_sr_var wins). Explain: $(dirname "$_SELF")/gstack-paths --explain ($_STATE_DOC)"
}

Expand Down Expand Up @@ -971,7 +970,7 @@ $_gstack_legacy_root"
gstack_config_select "$KEY"
if [ -n "$_gstack_cfg_root" ] && [ "$_gstack_cfg_root" != "$STATE_DIR" ] && [ "$_gstack_cfg_value" != "$SAFE_VALUE" ]; then
echo "gstack-config: set $KEY in $CONFIG_FILE, but $KEY is still '$_gstack_cfg_value': $_gstack_cfg_root/config.yaml sets that more restrictive value, and for privacy keys the most restrictive value across state roots wins." >&2
echo "fix: GSTACK_STATE_ROOT='$_gstack_cfg_root' $_SELF set $KEY $SAFE_VALUE ($_STATE_DOC)" >&2
printf 'fix: GSTACK_STATE_ROOT=%q %q set %q %q (%s)\n' "$_gstack_cfg_root" "$_SELF" "$KEY" "$SAFE_VALUE" "$_STATE_DOC" >&2
fi
# Auto-relink skills when prefix setting changes (skip during setup to avoid recursive call)
if { [ "$KEY" = "skill_prefix" ] || [ "$KEY" = "disabled_skills" ]; } && [ -z "${GSTACK_SETUP_RUNNING:-}" ]; then
Expand Down
8 changes: 5 additions & 3 deletions test/state-root-config-merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const POLICY = path.join(ROOT, 'bin', 'gstack-gbrain-repo-policy');
let tmp: string, home: string, legacy: string, resolved: string, env: Record<string, string>;

beforeEach(() => {
tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-merge-'));
tmp = fs.mkdtempSync(path.join(os.tmpdir(), "gstack merge's-"));
home = path.join(tmp, 'home');
legacy = path.join(home, '.gstack');
resolved = path.join(tmp, 'custom');
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('merged config keys', () => {
expect(r.stderr).toContain(`gstack-config: set codex_reviews in ${resolved}/config.yaml, but codex_reviews is still 'disabled': ${legacy}/config.yaml sets that more restrictive value`);
expect(r.stderr).toContain('docs/state-root.md');
const fix = r.stderr.split('\n').find((l) => l.startsWith('fix: '))!;
expect(fix).toContain(`GSTACK_STATE_ROOT='${legacy}'`);
expect(fix).toStartWith('fix: GSTACK_STATE_ROOT=');
const command = fix.slice('fix: '.length).replace(/ \(https:.*\)$/, '');
expect(spawnSync('bash', ['-c', command], { env, encoding: 'utf-8', timeout: 20_000 }).status).toBe(0);
expect(config(['get', 'codex_reviews']).stdout).toBe('enabled');
Expand All @@ -83,13 +83,15 @@ describe('merged config keys', () => {
expect(r.stderr).toBe('');
});

test('list shows the winning root for merged keys and a disagreement line when root variables differ', () => {
test('list shows the winning root for merged keys and a disagreement line only when root variables name different directories', () => {
fs.writeFileSync(path.join(legacy, 'config.yaml'), 'telemetry: off\n');
fs.writeFileSync(path.join(resolved, 'config.yaml'), 'telemetry: community\nproactive: false\n');
const plain = config(['list']).stdout;
expect(plain).toContain(`telemetry: off (set, ${legacy})`);
expect(plain).toContain('proactive: false (set)');
expect(plain).not.toContain('root-selecting variables disagree');
// Two variables naming the same directory agree, even when the path contains spaces.
expect(config(['list'], { GSTACK_STATE_ROOT: resolved }).stdout).not.toContain('root-selecting variables disagree');
const other = path.join(tmp, 'other');
const disagree = config(['list'], { GSTACK_STATE_DIR: other }).stdout;
expect(disagree).toContain(`# note: root-selecting variables disagree: GSTACK_HOME=${resolved} GSTACK_STATE_DIR=${other}; using ${resolved} (GSTACK_HOME wins).`);
Expand Down