Files
gstack/test/setup-claude-code-migration.test.ts
T
ac20ef1e13 v1.91.16.0 fix: safe installs and upgrades, skills start everywhere, truthful completion (parallel wave) (#3014)
* fix(make-pdf,design): real TOC page numbers and anchors; design models move to gpt-5.5 + gpt-image-2 (#2903, #2807)

* ci: pin every action to a SHA, Scorecard, checksummed Bun, scoped Codex CLI in the CI image, macOS named-regressions job (#1948, #1706, #1997)

* fix(cso,browse): Windows/macOS lease identity, retention skips bad runs, truthful 'not assessed' reports, env.kv false positive, Windows browse spawn fixes (#2894, #2912, #2048, #2637, #2805)

* fix(outside-voice): one Codex model precedence for probe and dispatch, bounded timeouts with KILL escalation, probe cache identity, guarded mktemp, skills hidden in nested Codex (#2776, #2914, #2787, #2881, #2847)

* feat(setup): install registry, ./setup --status, staged activation, per-scope migrations, host tiers and conformance kit, OpenCode/Hermes fixes, Copilot CLI (experimental), disabled_skills, slimmer CLAUDE.md (#1925, #2879, #2347, #2338, #2626, #2629, #2825, #2015, #393, #1206, #2096)

Co-authored-by: Andrey Esipov <61357035+andrey-esipov@users.noreply.github.com>
Co-authored-by: Matthew Williams <5863886+ridermw@users.noreply.github.com>
Co-authored-by: Rocky Wu <92764750+lolisaigao1234@users.noreply.github.com>

* fix(preamble): skills start in worktree-isolated Claude Code sessions — one literal skill-start line, context-recovery helper, no eval in skill blocks, $N token tripwire, honest plan-mode precedence (#2763, #2896, #2851)

* fix(setup): per-install renders for renamed, vendored and custom-config installs, space-safe alias roots, per-host /cso launcher path (#1882, #2906)

* test: free tests never write the real HOME (home-write tripwire), no orphaned browse daemons, symlinked-TMPDIR (macOS) fixes, gbrain-on-PATH isolation (#2895, #2816, #2829, #2841, #2982, #2911, #2909, #2908, #2910)

* chore: integrate wave follow-ups — regenerate all hosts, README model docs, TODOS, touchfiles, duration seeds, Bun 1.3 telemetry test fix, replay fixtures pinned to their recorded bytes

* v1.91.14.0: release metadata

* test(browse): group-kill cleanup falls back to the leader when macOS returns EPERM for a live group

* ci: Codex login steps run under bash (the CI container's default sh rejects pipefail)

* fix: full-suite repairs — private state roots for 7 real-HOME writers, truthful home-guard attribution with --attribute-home, gstack-paths shim in ship-hook fixtures, Copilot in team-init probes, test-of-test detector, cookie review fixture pinned to the approved excerpt

* fix(windows): LF for Dockerfiles, normalized home-guard exclusions, path.relative fixture containment, ship push test spawn timeouts

* test(design-detect): widen the whole-scan budget test's timing margins so a loaded macOS runner can't time out the single-batch call

* fix(evals): qa protocol names defined for the judge, async PTY judge so overlapping sessions keep their cleanup deadline, bws setup cases use the standard JUDGE_MS tier

* test(pty): the non-blocking judge case is POSIX-only (its fake judge is a shebang script, like the PTY harness it covers)

* test(evals): ship-coverage-audit names absolute skill paths, uses Read, and skips the Step 7 artifact nothing consumes (removes the mechanism behind 3 of 4 historical timeouts)

* test: deflake terminal-agent concurrent startup (write the placeholder record before spawning, like the product) and qa-evidence resumed pipe (barrier on a full high-water mark instead of a sleep)

* fix(design): daemon log stream handles open errors instead of crashing the daemon; shutdown test awaits the stubbed exit

* test(evals): skillify checks the product's resolved state root (no GSTACK_HOME bypass), negative cases check every root; tpa shims live outside the agent's cwd and answer consistently

* test(evals): coverage-audit detector splits parallel columns at │ rails and [+] groups; coverage prompts name absolute skill paths; TODOs from the gate eval census

* fix(plan-eng-review): scope gate always sends the menu (no headless 'Scope pending' exit); PTY harness ends idle turn-ends and API-error panels promptly with a precise diagnostic

* test(evals): one position-bound coverage-read rule credits read-only && chains (labels, context ranges, git displays in either order) and still rejects forged output

* fix(ship): documentation section has one saved source inserted by cat (never retyped); spawned-marker evidence is the child output; refreshed codex/factory ship goldens

* test(docsync): the byte-exact insert positive is POSIX-only (the bash-command observer refuses backslash paths by design)

* test(evals): plan-design-with-ui focus-title rule accepts the comma-less 'dimensions or focus' wording (replayed on the captured CI run, negative controls kept)

* fix(qa-callers): exploratory preflight says the scope/method Reads come after exploratory.md; design-review scan check credits an executed scan proven by one engine run over the changed files

---------

Co-authored-by: Andrey Esipov <61357035+andrey-esipov@users.noreply.github.com>
Co-authored-by: Matthew Williams <5863886+ridermw@users.noreply.github.com>
Co-authored-by: Rocky Wu <92764750+lolisaigao1234@users.noreply.github.com>
2026-10-03 07:54:09 -07:00

168 lines
11 KiB
TypeScript

/** Full setup ordering: repair another installed host before build/link/prune. */
import { describe, expect, test } from 'bun:test';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { spawnSync } from 'node:child_process';
const ROOT = path.resolve(import.meta.dir, '..');
const BANNER = '<!-- AUTO-GENERATED from SKILL.md.tmpl — do not edit directly -->\n<!-- Regenerate: bun run gen:skill-docs -->';
const oldSkill = (name: string) => `---\nname: ${name}\n---\n${BANNER}\nold working installation\n`;
function put(file: string, text: string, mode = 0o644) {
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, text, { mode });
}
function fixture(copy: boolean) {
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-setup-rename-'));
const root = path.join(temp, 'checkout');
const home = path.join(temp, 'home');
const codexHome = path.join(home, '.codex');
const skills = path.join(codexHome, 'skills');
const events = path.join(temp, 'events.log');
const shims = path.join(temp, 'shims');
// Real setup, generator, resolver and migration code; only dependency
// installation and binary compilation are stubbed to keep this test free.
for (const dir of ['scripts', 'hosts', 'lib', 'model-overlays', 'browse/src', 'design/src', 'openclaw/templates', 'qa']) {
fs.cpSync(path.join(ROOT, dir), path.join(root, dir), { recursive: true });
}
fs.copyFileSync(path.join(ROOT, 'setup'), path.join(root, 'setup'));
put(path.join(root, 'VERSION'), '2.0.0.0\n');
put(path.join(root, 'ETHOS.md'), 'Fixture ethos\n');
put(path.join(root, 'package.json'), JSON.stringify({ type: 'module', scripts: { 'gen:skill-docs': 'bun run scripts/gen-skill-docs.ts' } }));
for (const bin of ['gstack-config', 'gstack-patch-names', 'gstack-relink', 'gstack-migrate-claude-code', 'gstack-claude-code', 'gstack-state-root.sh', 'gstack-install-registry.sh']) {
const target = path.join(root, 'bin', bin);
fs.mkdirSync(path.dirname(target), { recursive: true });
fs.copyFileSync(path.join(ROOT, 'bin', bin), target);
}
// Include the required versioned hook too: it runs after host linking and
// must be idempotent with the early setup repair, including failed retries.
const migrationDir = path.join(ROOT, 'gstack-upgrade/migrations');
for (const file of fs.readdirSync(migrationDir).filter(name => name.endsWith('.sh'))) {
const content = fs.readFileSync(path.join(migrationDir, file), 'utf8');
if (content.includes('gstack-migrate-claude-code')) put(path.join(root, 'gstack-upgrade/migrations', file), content, 0o755);
}
put(path.join(home, '.gstack/.last-setup-version'), '1.0.0.0\n');
// Limit the fixture's skills, retaining real resolver calls and real native
// lazy sections without copying unrelated skills' runtime data.
put(path.join(root, 'SKILL.md.tmpl'), '---\nname: gstack\ndescription: Fixture router.\n---\n{{OUTSIDE_VOICE_ROUTING}}\n');
for (const skill of ['review', 'claude-code', 'codex']) {
fs.mkdirSync(path.join(root, skill), { recursive: true });
fs.copyFileSync(path.join(ROOT, skill, 'SKILL.md.tmpl'), path.join(root, skill, 'SKILL.md.tmpl'));
const sections = path.join(ROOT, skill, 'sections');
if (fs.existsSync(sections)) {
for (const file of fs.readdirSync(sections).filter(name => name.endsWith('.tmpl') || name === 'manifest.json')) {
put(path.join(root, skill, 'sections', file), fs.readFileSync(path.join(sections, file), 'utf8'));
}
}
}
put(path.join(root, 'open-gstack-browser/SKILL.md.tmpl'), '---\nname: open-gstack-browser\ndescription: Fixture browser.\n---\nBrowser fixture.\n');
// Observe actual isolated/live generation and inject only an isolated
// generation failure. Later setup generation still runs the real generator.
const generator = path.join(root, 'scripts/gen-skill-docs.ts');
const source = fs.readFileSync(generator, 'utf8').replace(/^#![^\n]*\n/, '');
fs.writeFileSync(generator, `const fixtureIsolated = process.argv.includes('--out-dir');
(await import('node:fs')).appendFileSync(process.env.FIXTURE_EVENTS!, 'generate:' + (fixtureIsolated ? 'isolated' : 'live') + ':defer=' + (process.env.GSTACK_DEFER_CLAUDE_RENAME_PRUNE ?? '0') + '\\n');
if (fixtureIsolated && process.env.FIXTURE_RENAME_FAIL === '1') { console.error('fixture isolated generation failure'); process.exit(70); }
${source}`);
put(path.join(shims, 'bun'), `#!/usr/bin/env bash
set -e
case "$1" in
install) exit 0 ;;
esac
if [ "$1" = run ] && [ "$2" = build ]; then
printf 'build\\n' >> "$FIXTURE_EVENTS"
"$FIXTURE_REAL_BUN" run scripts/gen-skill-docs.ts --host all
for target in browse/dist/browse design/dist/design make-pdf/dist/pdf bin/gstack-cso-core bin/gstack-cso-launcher bin/gstack-cso-watchdog; do
mkdir -p "$(dirname "$target")"
printf '#!/usr/bin/env bash\\nexit 0\\n' > "$target"
chmod +x "$target"
done
printf '%064d\\n' 0 > bin/.gstack-cso-generation
printf 'complete\\n' > browse/dist/.build-complete
exit 0
fi
if [ "$1" = run ] && [ "$2" = gen:skill-docs ]; then
shift 2
exec "$FIXTURE_REAL_BUN" run scripts/gen-skill-docs.ts "$@"
fi
exec "$FIXTURE_REAL_BUN" "$@"
`, 0o755);
const oldRender = path.join(root, '.agents/skills/gstack-claude');
put(path.join(oldRender, 'SKILL.md'), oldSkill('gstack-claude'));
fs.mkdirSync(skills, { recursive: true });
if (copy) put(path.join(skills, 'gstack-claude/SKILL.md'), oldSkill('gstack-claude'));
else fs.symlinkSync(oldRender, path.join(skills, 'gstack-claude'));
put(path.join(skills, 'gstack-review/SKILL.md'), oldSkill('gstack-review'));
put(path.join(skills, 'gstack-review/notes.md'), 'user notes\n');
put(path.join(codexHome, 'config.toml'), 'model = "gpt-5.6-sol"\n');
const env = { ...process.env, HOME: home, CODEX_HOME: codexHome,
GSTACK_HOME: path.join(home, '.gstack'), GSTACK_STATE_ROOT: path.join(home, '.gstack'),
GSTACK_SKIP_PLAYWRIGHT: '1', GSTACK_SKIP_FONTS: '1', GSTACK_SKIP_COREUTILS: '1', GSTACK_SKIP_ASIDE: '1',
GSTACK_SKIP_GBRAIN_REGEN: '1', GSTACK_PLAN_TUNE_HOOKS: 'no', GSTACK_TIMELINE_STOP_HOOK: 'no',
PATH: `${shims}${path.delimiter}${process.env.PATH}`, FIXTURE_REAL_BUN: process.execPath, FIXTURE_EVENTS: events,
};
const run = (failure = false) => spawnSync('bash', [path.join(root, 'setup'), '--host', 'claude', '--no-prefix', '--no-team'], {
cwd: root, env: { ...env, FIXTURE_RENAME_FAIL: failure ? '1' : '0' }, encoding: 'utf8', timeout: 30_000,
});
return { temp, root, home, skills, events, oldRender, run };
}
describe.skipIf(process.platform === 'win32')('full setup repairs the installed Claude wrapper through another host', () => {
for (const copy of [false, true]) {
test(`Claude-only setup migrates existing Codex, survives later generation/linking, and repeats safely (copy=${copy})`, () => {
const f = fixture(copy);
try {
// The real generator runs before the stubbed dependency-install step.
// Exercise that ordering with no node_modules in the source checkout.
expect(fs.existsSync(path.join(f.root, 'node_modules'))).toBe(false);
const result = f.run();
expect({ code: result.status, stderr: result.stderr }).toMatchObject({ code: 0 });
expect(result.stdout).toContain('gstack ready (claude)');
expect(result.stderr).toContain('/claude is now /claude-code');
const next = path.join(f.skills, 'gstack-claude-code/SKILL.md');
expect(fs.readFileSync(next, 'utf8')).toContain('name: claude-code');
expect(fs.existsSync(path.join(f.skills, 'gstack-claude/SKILL.md'))).toBe(false);
expect(fs.existsSync(f.oldRender)).toBe(false);
expect(fs.readFileSync(path.join(f.skills, 'gstack-review/SKILL.md'), 'utf8')).toContain('gstack-claude-code');
expect(fs.readFileSync(path.join(f.skills, 'gstack-review/notes.md'), 'utf8')).toBe('user notes\n');
expect(fs.readFileSync(path.join(f.root, '.agents/skills/gstack-review/SKILL.md'), 'utf8')).toContain('Model-Specific Behavioral Patch (gpt-5.6-sol)');
expect(fs.existsSync(path.join(f.skills, 'gstack/bin/gstack-claude-code'))).toBe(true);
expect(fs.existsSync(path.join(f.skills, 'gstack/lib/outside-review-result.ts'))).toBe(true);
const fakeCli = path.join(f.temp, 'fake-reviewer.ts');
put(fakeCli, "await Bun.stdin.text(); console.log(JSON.stringify({result:'NO_FINDINGS',session_id:'installed-session'}));\n");
const installed = spawnSync(process.execPath, [path.join(f.skills, 'gstack/bin/gstack-claude-code'),
'--cwd', f.root, '--access', 'none', '--timeout-ms', '3000'], {
env: { ...process.env, GSTACK_CLAUDE_BIN: process.execPath, GSTACK_CLAUDE_BIN_ARGS: JSON.stringify([fakeCli]) },
input: 'Review through the migrated runtime.', encoding: 'utf8', timeout: 5000,
});
expect({ code: installed.status, stderr: installed.stderr }).toMatchObject({ code: 0 });
expect(JSON.parse(installed.stdout)).toMatchObject({ status: 'completed', provider: 'claude-code', session_id: 'installed-session' });
expect(fs.existsSync(path.join(f.home, '.claude/skills/review/SKILL.md'))).toBe(true);
expect(fs.existsSync(path.join(f.home, '.claude/skills/claude-code/SKILL.md'))).toBe(false);
expect(fs.readFileSync(f.events, 'utf8')).toMatch(/generate:isolated:defer=1\nbuild\ngenerate:live:defer=0/);
const repeated = f.run();
expect(repeated.status).toBe(0);
expect(repeated.stderr).not.toContain('/claude is now');
expect(fs.readFileSync(next, 'utf8')).toContain('name: claude-code');
} finally { fs.rmSync(f.temp, { recursive: true, force: true }); }
}, 60_000);
}
test('failed rename keeps the working Codex entry through later build/prune and succeeds on retry', () => {
const f = fixture(false);
try {
const failed = f.run(true);
expect({ code: failed.status, stderr: failed.stderr }).toMatchObject({ code: 0 });
expect(failed.stdout).toContain('gstack ready (claude)');
expect(failed.stderr).toContain('fixture isolated generation failure');
expect(fs.readFileSync(path.join(f.skills, 'gstack-claude/SKILL.md'), 'utf8')).toContain('old working installation');
expect(fs.readFileSync(f.events, 'utf8')).toMatch(/generate:isolated:defer=1\nbuild\ngenerate:live:defer=1/);
const retry = f.run();
expect(retry.status).toBe(0);
expect(fs.existsSync(path.join(f.skills, 'gstack-claude/SKILL.md'))).toBe(false);
expect(fs.readFileSync(path.join(f.skills, 'gstack-claude-code/SKILL.md'), 'utf8')).toContain('name: claude-code');
} finally { fs.rmSync(f.temp, { recursive: true, force: true }); }
}, 60_000);
});