gstack-upgrade works again after you disable skills (#4704) (#4743)

If you turned off skills with `gstack-config set disabled_skills ...`,
every `gstack-upgrade` stopped with "tracked files changed: SKILL.md".
It now upgrades, and your skills stay off afterwards.

Why: gstack has to keep itself up to date without a person cleaning up
after its own setup.

Nothing to do.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p1/specialist-batched#2 reader=testing
Review-Finding: p1/outside-voice#1 reader=outside-voice
Review-Finding: p1/outside-voice#2 reader=outside-voice
Review-Finding: p1/outside-voice#3 reader=outside-voice
Review-Finding: p1/outside-voice#4 reader=outside-voice
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-23 15:29:30 +00:00
1 parent a3ecfd530d
commit c4cfe6d1c9
4 files changed
+258 -4

No files matched your search

+50 -3
View File
@@ -19,7 +19,8 @@
#
# Refuses with exit 3 and changes nothing (UPGRADE_REFUSED) when the directory
# is not a gstack checkout, HEAD is detached or not on the remote default
# branch (a pin), any tracked byte is dirty, a local commit diverged, the
# branch (a pin), any tracked byte is dirty (the root SKILL.md exactly as
# gstack-relink renders it for this install is not, #4704), a local commit diverged, the
# incoming release's Bun floor holds, or another updater holds the setup
# lock, unless the caller holds it and names its pid in GSTACK_SETUP_LOCK_OWNER;
# never stashes, never resets. Before any fetch it also refuses when
@@ -43,6 +44,7 @@
# Bash 3.2 plus git; the fetch is bounded by `timeout` when present.
set -u
BASH_COMPAT=50
GSTACK_BUN_CONFIG=/dev/null; case "${OSTYPE:-}" in msys*|cygwin*) if command -v cygpath >/dev/null 2>&1; then GSTACK_BUN_CONFIG=NUL; fi ;; esac
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
CALLER=$(pwd -P)
@@ -53,7 +55,7 @@ case "${1:-}" in
--check) CHECK=1 ;;
--ff-only-no-reinstall) REINSTALL=0 ;;
'') ;;
-h|--help) sed -n '2,42p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
-h|--help) sed -n '2,43p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
*) echo "gstack-upgrade: unknown argument '$1'" >&2; exit 2 ;;
esac
@@ -222,7 +224,41 @@ if [ "$CHECK" -eq 1 ]; then
exit 1
fi
# The root SKILL.md gstack-relink renders in place for disabled_skills or
# plan_mode_preamble=off (#3018, #3168) is gstack's own install state, not a
# local edit (#4704). It is left out of the dirty check only when every other
# tracked path is clean and its mode and bytes equal a fresh render of this
# checkout's router for the current config, so a staged, edited or stale router
# still refuses. The bytes are checked again under the setup lock, the
# committed bytes go back just before the fast-forward, and the router is
# rendered again right after it (a failed render leaves a pending reinstall,
# whose setup renders it).
# render_router DEST: gstack-relink's router render (same generator, flags and config).
render_router() {
_rr_dir=$(mktemp -d "${TMPDIR:-/tmp}/gstack-upgrade-router.XXXXXX") || return 1
_rr_config="$ROOT/bin/gstack-config"
_rr_off=$(. "$ROOT/bin/gstack-install-registry.sh" 2>/dev/null && gstack_disabled_normalize "$("$_rr_config" get disabled_skills 2>/dev/null || true)" | xargs | tr ' ' ',')
_rr_pm=""
[ "$("$_rr_config" get plan_mode_preamble 2>/dev/null || true)" != off ] || _rr_pm="--plan-mode=off"
(cd "$ROOT" && bun --no-env-file --config="${GSTACK_BUN_CONFIG:-/dev/null}" run scripts/gen-skill-docs.ts --host claude --out-dir "$_rr_dir" ${_rr_off:+"--disabled-skills=$_rr_off"} ${_rr_pm:+"$_rr_pm"} >/dev/null 2>&1) \
&& [ -s "$_rr_dir/SKILL.md" ] && cp "$_rr_dir/SKILL.md" "$1.tmp.$$" && mv "$1.tmp.$$" "$1"
_rr_rc=$?
rm -rf "$_rr_dir" "$1.tmp.$$"
return "$_rr_rc"
}
# router_is_rendered: SKILL.md is modified only in the work tree, mode unchanged, with exactly the bytes render_router writes.
router_is_rendered() {
[ "$(git -C "$ROOT" status --porcelain --untracked-files=no -- SKILL.md 2>/dev/null)" = " M SKILL.md" ] || return 1
[ -z "$(git -C "$ROOT" diff --summary -- SKILL.md 2>/dev/null)" ] || return 1
_rr_fresh=$(mktemp "${TMPDIR:-/tmp}/gstack-upgrade-router.XXXXXX") || return 1
render_router "$_rr_fresh" && cmp -s "$_rr_fresh" "$ROOT/SKILL.md"
_rr_rc=$?
rm -f "$_rr_fresh"
return "$_rr_rc"
}
DIRTY=$(git -C "$ROOT" status --porcelain --untracked-files=no 2>/dev/null | cut -c4- | tr '\n' ' ' | sed 's/ $//')
ROUTER_RENDERED=0
[ "$DIRTY" = SKILL.md ] && router_is_rendered && ROUTER_RENDERED=1 DIRTY=""
[ -z "$DIRTY" ] || refuse "tracked files changed: $DIRTY" "commit or move those changes (git -C $ROOT status --short), then re-run"
if ! git -C "$ROOT" merge-base --is-ancestor HEAD FETCH_HEAD 2>/dev/null; then
_receipted_git open gstack-upgrade "${HOST:-unknown}" gstack-self-update-pull "$R" git -C "$ROOT" fetch --quiet --unshallow origin "$FOLLOW" 2>/dev/null || true
@@ -275,7 +311,18 @@ else
trap '[ "$(cat "$LOCK_DIR/pid" 2>/dev/null)" = "$$" ] && rm -rf "$LOCK_DIR" 2>/dev/null' EXIT
fi
git -C "$ROOT" merge --ff-only -q FETCH_HEAD 2>/dev/null || refuse "git merge --ff-only FETCH_HEAD failed" "git -C $ROOT status, then re-run"
if [ "$ROUTER_RENDERED" -eq 1 ]; then
router_is_rendered || refuse "tracked files changed: SKILL.md" "commit or move those changes (git -C $ROOT status --short), then re-run"
git -C "$ROOT" checkout -q -- SKILL.md
fi
git -C "$ROOT" merge --ff-only -q FETCH_HEAD 2>/dev/null || {
[ "$ROUTER_RENDERED" -eq 0 ] || ! git -C "$ROOT" diff --quiet -- SKILL.md || render_router "$ROOT/SKILL.md"
refuse "git merge --ff-only FETCH_HEAD failed" "git -C $ROOT status, then re-run"
}
if [ "$ROUTER_RENDERED" -eq 1 ] && ! render_router "$ROOT/SKILL.md"; then
printf '%s\n' "$INSTALLED" > "$PENDING"
echo "gstack-upgrade: could not render the router for disabled_skills again (bun missing or generation failed), so $ROOT/SKILL.md routes to every skill until it is; fix: $ROOT/bin/gstack-relink (the reinstall left pending renders it too)" >&2
fi
NEW=$(head -1 "$ROOT/VERSION")
echo "gstack-upgrade: upgraded $INSTALLED -> $NEW"
[ "$LOCK_HANDED" -eq 1 ] || { rm -rf "$LOCK_DIR"; trap - EXIT; }
@@ -0,0 +1,4 @@
---
important: blocker
---
**`gstack-upgrade` no longer refuses to run after you disable skills.** With `gstack-config set disabled_skills ...` (or `plan_mode_preamble off`), setup rewrites the router `SKILL.md` in the checkout, and the upgrade read that rewrite as your own edit and stopped with "tracked files changed: SKILL.md". The upgrade now accepts the router when its bytes are exactly what gstack renders for your current settings, puts back the committed file for the update, and renders it again afterwards, so your disabled skills stay off. Any other edit to `SKILL.md` or another tracked file still stops the upgrade as before. (#4704, GST-3542)
+4 -1
View File
@@ -1967,7 +1967,10 @@ fix before the next workflow, as for any `behind=` of 1 or more.
**Meaning.** `bin/gstack-upgrade` moves a checkout only by fast-forward to the
tip of its remote default branch. It refused before changing anything: the
directory is not a gstack checkout, HEAD is detached or on another branch (a
pin), a tracked file is modified, a local commit is not on the remote branch,
pin), a tracked file is modified (the root `SKILL.md` that setup renders for
`disabled_skills` or `plan_mode_preamble off` doesn't count while its bytes
match a fresh render for your current settings), a local commit is not on the
remote branch,
the incoming release's Bun floor is above the Bun on PATH, or another updater
holds `<state root>/.setup-lock`. It never stashes, resets or discards.
A `tracked-by-project` or `version-reverted` cause has its own section:
+200
View File
@@ -0,0 +1,200 @@
/**
* #4704: gstack-relink renders the tracked root SKILL.md in place when
* disabled_skills is set (C8, #3018), so the router's generated bytes are
* gstack's own install state, not a local edit. gstack-upgrade must not refuse
* over them, must still refuse over any real edit to SKILL.md or another
* tracked file (nothing changed on refusal), and must leave the router
* rendered for the same disabled list after it moves the checkout.
* Fixture: a bare remote with A (1.0.0) and B (1.0.1, which also changes the
* committed router), a depth-1 clone at A under the simulated Capy host's temp
* root, the real gstack-config and gstack-relink, and an untracked `scripts`
* link to this checkout's generator, which reads templates there and writes
* only to its own temp out-dir.
*/
import { afterEach, describe, expect, test } from 'bun:test';
import { spawnSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import { capyHost, type CapyHost } from './helpers/capy-host';
const REPO = path.resolve(import.meta.dir, '..');
const DEPS = [
'bin/gstack-upgrade', 'bin/gstack-bun-version.sh', 'bin/gstack-paths', 'bin/gstack-state-root.sh', 'bin/gstack-lock.sh',
'bin/gstack-egress-lib.sh', 'bin/gstack-egress-receipt', 'lib/egress-receipt.ts', 'lib/state-root.ts',
'bin/gstack-lease', 'bin/gstack-harness-pid.sh', 'bin/gstack-install-verdict.sh', 'bin/gstack-ff-update',
'bin/gstack-config', 'bin/gstack-relink', 'bin/gstack-patch-names', 'bin/gstack-skill-name.sh', 'bin/gstack-install-registry.sh',
];
const DISABLED_LINE = 'Disabled on this install (never invoke or suggest them): `/qa-only`, `/careful`.';
const hosts: CapyHost[] = [];
afterEach(() => { for (const h of hosts.splice(0)) h.cleanup(); });
function fixture() {
const host = capyHost({ systemBun: '1.4.2' });
hosts.push(host);
const env = { ...host.env, UPGRADE_LOG: path.join(host.base, 'calls.log'), GSTACK_SETUP_RUNNING: '' };
const git = (args: string[], cwd: string) => {
const r = spawnSync('git', args, { cwd, encoding: 'utf8', env, timeout: 30_000 });
if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
return r.stdout.trim();
};
const write = (file: string, text: string, mode = 0o644) => {
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, text, { mode });
};
const seed = path.join(host.base, 'seed');
const bare = path.join(host.base, 'remote.git');
fs.mkdirSync(seed, { recursive: true });
git(['init', '-q', '-b', 'main'], seed);
for (const rel of DEPS) {
fs.mkdirSync(path.dirname(path.join(seed, rel)), { recursive: true });
fs.copyFileSync(path.join(REPO, rel), path.join(seed, rel));
fs.chmodSync(path.join(seed, rel), fs.statSync(path.join(REPO, rel)).mode);
}
const committed = fs.readFileSync(path.join(REPO, 'SKILL.md'), 'utf8');
write(path.join(seed, 'SKILL.md'), committed);
write(path.join(seed, 'VERSION'), '1.0.0\n');
write(path.join(seed, 'README.md'), 'gstack fixture\n');
write(path.join(seed, 'setup'), '#!/usr/bin/env bash\necho "setup $*" >> "$UPGRADE_LOG"\n', 0o755);
for (const skill of ['qa', 'qa-only', 'careful', 'guard']) write(path.join(seed, skill, 'SKILL.md'), `---\nname: ${skill}\ndescription: test\n---\n`);
git(['add', '-A'], seed);
git(['commit', '-qm', 'A'], seed);
git(['init', '-q', '--bare', '-b', 'main', bare], host.base);
git(['push', '-q', bare, 'main'], seed);
const skills = path.join(host.base, 'skills');
const root = path.join(skills, 'gstack');
fs.mkdirSync(skills, { recursive: true });
git(['clone', '-q', '--single-branch', '--depth', '1', `file://${bare}`, root], host.base);
fs.symlinkSync(path.join(REPO, 'scripts'), path.join(root, 'scripts'));
write(path.join(seed, 'VERSION'), '1.0.1\n');
write(path.join(seed, 'NEW-IN-B.md'), 'added in B\n');
write(path.join(seed, 'SKILL.md'), committed.replace('\n## Route first\n', '\n## Route first\n\n<!-- release B -->\n'));
git(['add', '-A'], seed);
git(['commit', '-qm', 'B'], seed);
const b = git(['rev-parse', 'HEAD'], seed);
git(['push', '-q', bare, 'main'], seed);
const routerEnv = { ...env, GSTACK_INSTALL_DIR: root, GSTACK_SKILLS_DIR: skills };
return {
root, b, committed,
git: (args: string[]) => git(args, root),
router: () => fs.readFileSync(path.join(root, 'SKILL.md'), 'utf8'),
config: (key: string, op: string, value: string, extra: Record<string, string> = {}) =>
spawnSync('bash', [path.join(root, 'bin/gstack-config'), key, op, value], { cwd: host.home, encoding: 'utf8', env: { ...routerEnv, ...extra }, timeout: 60_000 }),
relink: () => spawnSync('bash', [path.join(root, 'bin/gstack-relink')], { cwd: host.home, encoding: 'utf8', env: routerEnv, timeout: 60_000 }),
upgrade: (args: string[] = []) => spawnSync('bash', [path.join(root, 'bin/gstack-upgrade'), ...args], { cwd: host.home, encoding: 'utf8', env, timeout: 120_000 }),
};
}
/** disabled_skills set through gstack-config, which runs gstack-relink: the router is rendered in place and shows as modified. */
function disabledFixture() {
const f = fixture();
const set = f.config('set', 'disabled_skills', 'qa-only,careful');
expect(set.status, set.stdout + set.stderr).toBe(0);
expect(f.router()).toContain(DISABLED_LINE);
expect(f.git(['status', '--porcelain', '--untracked-files=no'])).toBe('M SKILL.md');
return f;
}
describe.skipIf(process.platform === 'win32')('#4704: gstack-upgrade and the router gstack-relink renders for disabled_skills', () => {
test('the rendered router does not block the upgrade, and the upgraded router still leaves the disabled skills out', () => {
const f = disabledFixture();
const r = f.upgrade();
expect(r.status, r.stdout + r.stderr).toBe(0);
expect(r.stdout).toContain('gstack-upgrade: upgraded 1.0.0 -> 1.0.1');
expect(f.git(['rev-parse', 'HEAD'])).toBe(f.b);
const router = f.router();
expect(router).toContain(DISABLED_LINE);
expect(router).not.toMatch(/→ invoke `\/qa-only`/);
expect(router).toContain('→ invoke `/guard`');
expect(f.git(['status', '--porcelain', '--untracked-files=no'])).toBe('M SKILL.md');
});
test('--ff-only-no-reinstall also re-renders the router, since no setup runs after it', () => {
const f = disabledFixture();
const r = f.upgrade(['--ff-only-no-reinstall']);
expect(r.status, r.stdout + r.stderr).toBe(0);
expect(f.git(['rev-parse', 'HEAD'])).toBe(f.b);
expect(f.router()).toContain(DISABLED_LINE);
});
test('a router rendered for plan_mode_preamble=off does not block the upgrade and stays rendered', () => {
const f = fixture();
const set = f.config('set', 'plan_mode_preamble', 'off');
expect(set.status, set.stdout + set.stderr).toBe(0);
const relink = f.relink();
expect(relink.status, relink.stdout + relink.stderr).toBe(0);
expect(f.git(['status', '--porcelain', '--untracked-files=no'])).toBe('M SKILL.md');
const rendered = f.router();
expect(rendered).not.toContain('## Plan Mode Safe Operations');
const r = f.upgrade();
expect(r.status, r.stdout + r.stderr).toBe(0);
expect(f.git(['rev-parse', 'HEAD'])).toBe(f.b);
expect(f.router()).toBe(rendered);
});
test('a fast-forward that fails after the router was restored renders it again before refusing', () => {
const f = disabledFixture();
const rendered = f.router();
fs.writeFileSync(path.join(f.root, 'NEW-IN-B.md'), 'untracked local file\n');
const head = f.git(['rev-parse', 'HEAD']);
const r = f.upgrade();
expect(r.status, r.stdout + r.stderr).toBe(3);
expect(r.stderr).toContain('git merge --ff-only FETCH_HEAD failed');
expect(f.git(['rev-parse', 'HEAD'])).toBe(head);
expect(f.router()).toBe(rendered);
});
test('a user edit on top of the rendered router still refuses, and nothing changes', () => {
const f = disabledFixture();
const edited = f.router() + '\nmy own routing note\n';
fs.writeFileSync(path.join(f.root, 'SKILL.md'), edited);
const head = f.git(['rev-parse', 'HEAD']);
const r = f.upgrade();
expect(r.status, r.stdout + r.stderr).toBe(3);
expect(r.stderr).toContain('gstack-upgrade: tracked files changed: SKILL.md; nothing was changed');
expect(f.git(['rev-parse', 'HEAD'])).toBe(head);
expect(f.router()).toBe(edited);
});
test('a mode change on the rendered router still refuses', () => {
const f = disabledFixture();
fs.chmodSync(path.join(f.root, 'SKILL.md'), 0o755);
const head = f.git(['rev-parse', 'HEAD']);
const r = f.upgrade();
expect(r.status, r.stdout + r.stderr).toBe(3);
expect(r.stderr).toContain('tracked files changed: SKILL.md');
expect(f.git(['rev-parse', 'HEAD'])).toBe(head);
expect(fs.statSync(path.join(f.root, 'SKILL.md')).mode & 0o111).not.toBe(0);
});
test('an edit to SKILL.md with no disabled_skills set still refuses', () => {
const f = fixture();
fs.writeFileSync(path.join(f.root, 'SKILL.md'), f.committed + '\nmy own routing note\n');
const r = f.upgrade();
expect(r.status, r.stdout + r.stderr).toBe(3);
expect(r.stderr).toContain('tracked files changed: SKILL.md');
});
test('another tracked edit beside the rendered router still refuses and leaves the router rendered', () => {
const f = disabledFixture();
const rendered = f.router();
fs.writeFileSync(path.join(f.root, 'README.md'), 'local edit\n');
const head = f.git(['rev-parse', 'HEAD']);
const r = f.upgrade();
expect(r.status, r.stdout + r.stderr).toBe(3);
expect(r.stderr).toContain('tracked files changed: README.md');
expect(f.git(['rev-parse', 'HEAD'])).toBe(head);
expect(f.router()).toBe(rendered);
});
test('a router rendered for an older disabled list (config changed with no relink) still refuses', () => {
const f = disabledFixture();
const rendered = f.router();
const set = f.config('set', 'disabled_skills', 'qa-only', { GSTACK_SETUP_RUNNING: '1' });
expect(set.status, set.stdout + set.stderr).toBe(0);
expect(f.router()).toBe(rendered);
const r = f.upgrade();
expect(r.status, r.stdout + r.stderr).toBe(3);
expect(r.stderr).toContain('tracked files changed: SKILL.md');
expect(f.router()).toBe(rendered);
});
});