mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-20 15:13:47 +01:00
Merge origin/main into the Oct 8 triage wave
# Conflicts: # CHANGELOG.md # VERSION # agents-digest/gstack-AGENTS.md # package.json
This commit is contained in:
commit
10d845ab4d
30 files changed
+1079
-131
No files matched your search
@@ -93,7 +93,7 @@ describe.skipIf(process.platform === 'win32')('Codex global install: the freeze
|
||||
const rootDir = path.join(codexHome, 'skills', 'gstack');
|
||||
const project = path.join(sandbox, 'project', 'src');
|
||||
fs.mkdirSync(project, { recursive: true });
|
||||
const functions = ['_link_or_copy', '_link_runtime_dists', '_copy_skill_md', '_gstack_generated_header', 'create_codex_runtime_root']
|
||||
const functions = ['_link_or_copy', '_link_runtime_dists', '_copy_runtime_skill_refs', '_copy_skill_md', '_gstack_generated_header', 'create_codex_runtime_root']
|
||||
.filter(name => SETUP_SRC.includes(`\n${name}() {`)).map(extractFunction).join('\n');
|
||||
const built = spawnSync('bash', ['-c', `IS_WINDOWS=0\n_CODEX_RENDER_ROOT="${renderDir}"\n${functions}\ncreate_codex_runtime_root "${ROOT}" "${rootDir}"`],
|
||||
{ encoding: 'utf8', timeout: 30_000, env: { PATH: process.env.PATH ?? '/usr/bin:/bin', HOME: home } });
|
||||
|
||||
+14
-11
@@ -3665,13 +3665,13 @@ describe('setup script validation', () => {
|
||||
expect(fnBody).toContain('browse/dist');
|
||||
expect(fnBody).toContain('browse/bin');
|
||||
expect(fnBody).toContain('gstack-upgrade/SKILL.md');
|
||||
expect(fnBody).toContain('checklist.md');
|
||||
expect(fnBody).toContain('TODOS-format.md');
|
||||
// Review checklists and the other read-on-demand files come from the shared
|
||||
// helpers, the same set every env-var root gets (#1077 residue): the Cursor
|
||||
// render reads design-checklist.md and review/specialists too.
|
||||
expect(fnBody).toContain('_link_runtime_dists "$gstack_dir" "$cursor_gstack"');
|
||||
expect(fnBody).toContain('_copy_runtime_skill_refs "$cursor_dir" "$cursor_gstack"');
|
||||
// bin scripts import ../lib — the two must travel together.
|
||||
expect(fnBody).toContain('$cursor_gstack/lib');
|
||||
expect(fnBody).not.toContain('design-checklist.md');
|
||||
expect(fnBody).not.toContain('greptile-triage.md');
|
||||
expect(fnBody).not.toContain('review/specialists');
|
||||
expect(fnBody).not.toContain('qa/templates');
|
||||
expect(fnBody).not.toContain('_link_or_copy "$gstack_dir" "$cursor_gstack"');
|
||||
});
|
||||
@@ -3745,19 +3745,22 @@ describe('setup script validation', () => {
|
||||
|
||||
test('create_codex_runtime_root exposes only runtime assets', () => {
|
||||
const fnStart = setupContent.indexOf('create_codex_runtime_root()');
|
||||
const fnEnd = setupContent.indexOf('}', setupContent.indexOf('done', setupContent.indexOf('review/', fnStart)));
|
||||
const fnEnd = setupContent.indexOf('\n}\n', fnStart);
|
||||
const fnBody = setupContent.slice(fnStart, fnEnd);
|
||||
expect(fnBody).toContain('gstack/SKILL.md');
|
||||
expect(fnBody).toContain('$codex_gstack/lib');
|
||||
expect(fnBody).toContain('browse/dist');
|
||||
expect(fnBody).toContain('browse/bin');
|
||||
expect(fnBody).toContain('gstack-upgrade/SKILL.md');
|
||||
// Review runtime assets (individual files, not the whole dir)
|
||||
expect(fnBody).toContain('checklist.md');
|
||||
expect(fnBody).toContain('design-checklist.md');
|
||||
expect(fnBody).toContain('greptile-triage.md');
|
||||
expect(fnBody).toContain('TODOS-format.md');
|
||||
expect(fnBody).toContain('_link_runtime_dists "$gstack_dir" "$codex_gstack"');
|
||||
expect(fnBody).not.toContain('_link_or_copy "$gstack_dir" "$codex_gstack"');
|
||||
// Review runtime assets: individual files from the shared helper, never
|
||||
// the whole review/ dir, which has a SKILL.md.
|
||||
const shared = setupContent.slice(setupContent.indexOf('_link_runtime_dists() {'), setupContent.indexOf('_copy_runtime_skill_refs() {'));
|
||||
for (const f of ['review/checklist.md', 'review/design-checklist.md', 'review/greptile-triage.md', 'review/TODOS-format.md']) {
|
||||
expect(shared).toContain(f);
|
||||
}
|
||||
expect(shared).not.toMatch(/for d in [^;]*\breview(?:\s|;)/);
|
||||
});
|
||||
|
||||
test('create_factory_runtime_root links shared lib modules beside bin', () => {
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* #1694: renders of hosts an install does not serve are pruned safely.
|
||||
*
|
||||
* Every ./setup (and the gstack-upgrade migration) removes the render dirs of
|
||||
* hosts missing from the installed-hosts record with bin/gstack-relink's proof
|
||||
* rules: a symlink into the checkout (STRONG) goes; a file proven generated
|
||||
* (WEAK: gen-skill-docs' banner, the generator's openai.yaml shape, byte
|
||||
* identity) is moved to $GSTACK_STATE_ROOT/backups/host-renders/; anything
|
||||
* else stays; only emptied directories are removed. The legacy layout here is
|
||||
* a real `--host all` render.
|
||||
*/
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { runGeneration } from '../scripts/gen-skill-docs';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, put, runSetup, type Fixture } from './helpers/install-fixture';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const OTHER_DIRS = ['.agents', '.factory', '.kiro', '.opencode', '.cursor', '.copilot', '.slate', '.openclaw', '.hermes', '.gbrain'];
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
const skillFiles = (dir: string): string[] => !fs.existsSync(dir) ? []
|
||||
: (fs.readdirSync(dir, { recursive: true }) as string[]).filter(rel => path.basename(rel) === 'SKILL.md' && fs.statSync(path.join(dir, rel)).isFile());
|
||||
|
||||
async function legacyRender(src: string): Promise<void> {
|
||||
const result = await runGeneration({ host: 'all', outputRoot: src });
|
||||
if (result.exitCode !== 0) throw new Error('legacy render failed');
|
||||
}
|
||||
|
||||
function backups(f: Fixture): string[] {
|
||||
const dir = path.join(f.home, '.gstack/backups/host-renders');
|
||||
return fs.existsSync(dir) ? fs.readdirSync(dir).map(d => path.join(dir, d)) : [];
|
||||
}
|
||||
|
||||
function setupOk(f: Fixture, src: string, args: string[] = []) {
|
||||
const r = runSetup(f, path.join(src, 'setup'), args);
|
||||
expect(r.status, r.stdout + r.stderr).toBe(0);
|
||||
return r;
|
||||
}
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('setup prunes unrecorded host renders without losing a file (#1694)', () => {
|
||||
test('a legacy all-host render inside a Claude install: generated files backed up, user files kept, links handled', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
await legacyRender(src);
|
||||
const before = skillFiles(src).length;
|
||||
expect(before).toBeGreaterThan(600);
|
||||
const customized = path.join(src, '.factory/skills/gstack-qa/SKILL.md');
|
||||
fs.appendFileSync(customized, '\nMy own QA note.\n');
|
||||
put(path.join(src, '.factory/notes.md'), 'my notes, no banner\n');
|
||||
put(path.join(src, '.kiro/skills/my-skill/SKILL.md'), '---\nname: my-skill\n---\nHand-written.\n');
|
||||
fs.mkdirSync(path.join(src, '.cursor/skills/gstack'), { recursive: true });
|
||||
fs.symlinkSync(path.join(src, 'bin'), path.join(src, '.cursor/skills/gstack/bin'));
|
||||
fs.mkdirSync(path.join(f.dir, 'outside'));
|
||||
fs.symlinkSync(path.join(f.dir, 'outside'), path.join(src, '.cursor/skills/gstack/elsewhere'));
|
||||
|
||||
const r = setupOk(f, src);
|
||||
expect(fs.readFileSync(path.join(src, '.gstack-installed-hosts'), 'utf8')).toEndWith('\nclaude\n');
|
||||
// Only the Claude skills and the hand-written look-alike remain.
|
||||
const left = skillFiles(src).filter(rel => rel.startsWith('.'));
|
||||
expect(left).toEqual(['.kiro/skills/my-skill/SKILL.md']);
|
||||
expect(before - skillFiles(src).length).toBeGreaterThan(550);
|
||||
expect(fs.readdirSync(path.join(src, '.factory'), { recursive: true })).toEqual(['notes.md']);
|
||||
expect(fs.lstatSync(path.join(src, '.cursor/skills/gstack/elsewhere')).isSymbolicLink()).toBe(true);
|
||||
expect(fs.existsSync(path.join(f.dir, 'outside'))).toBe(true);
|
||||
expect(fs.existsSync(path.join(src, '.cursor/skills/gstack/bin'))).toBe(false);
|
||||
expect(fs.existsSync(path.join(src, 'bin/gstack-config'))).toBe(true);
|
||||
for (const dir of ['.agents', '.opencode', '.copilot', '.slate', '.openclaw', '.hermes', '.gbrain']) expect(fs.existsSync(path.join(src, dir)), dir).toBe(false);
|
||||
|
||||
expect(r.stdout).toContain('kept .factory/notes.md: not proven generated (no gstack banner or byte match)');
|
||||
expect(r.stdout).toContain('kept .kiro/skills/my-skill/SKILL.md: not proven generated');
|
||||
expect(r.stdout).toContain('kept .cursor/skills/gstack/elsewhere: links outside this checkout');
|
||||
expect(r.stdout).toMatch(/pruned \.factory \(factory is not installed from this checkout\): \d+ generated files backed up, 0 links removed, \d+ empty dirs removed, 1 kept/);
|
||||
const [backup] = backups(f);
|
||||
expect(backups(f)).toHaveLength(1);
|
||||
expect(r.stdout).toContain(`host-render backup: ${backup} (every path: ${backup}/prune.log; restore a file with mv)`);
|
||||
expect(fs.readFileSync(path.join(backup!, '.factory/skills/gstack-qa/SKILL.md'), 'utf8')).toEndWith('\nMy own QA note.\n');
|
||||
const log = fs.readFileSync(path.join(backup!, 'prune.log'), 'utf8');
|
||||
expect(log).toContain('backed up\t.agents/skills/gstack-qa/agents/openai.yaml\tgenerated');
|
||||
expect(log).toContain('backed up\t.hermes/skills/gstack-qa/SKILL.md\tgenerated');
|
||||
expect(log).toContain(`removed link\t.cursor/skills/gstack/bin\t-> ${src}/bin`);
|
||||
expect(log).toContain('kept\t.factory/notes.md\tnot proven generated');
|
||||
expect(log).toContain('removed dir\t.agents\tempty');
|
||||
|
||||
const again = setupOk(f, src);
|
||||
expect(again.stdout).not.toContain('pruned ');
|
||||
expect(again.stdout).not.toContain('host-render backup');
|
||||
expect(backups(f)).toHaveLength(1);
|
||||
}, 240_000);
|
||||
|
||||
test('two installs sharing one state root each end with only their own hosts', async () => {
|
||||
const f = makeFixture();
|
||||
const a = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
const b = makeSource(f, path.join(f.home, 'src-b/gstack'));
|
||||
await legacyRender(a);
|
||||
await legacyRender(b);
|
||||
setupOk(f, a);
|
||||
setupOk(f, b, ['--host', 'codex']);
|
||||
for (const dir of OTHER_DIRS) expect(fs.existsSync(path.join(a, dir)), `a ${dir}`).toBe(false);
|
||||
expect(skillFiles(path.join(b, '.agents')).length).toBeGreaterThan(40);
|
||||
for (const dir of OTHER_DIRS.filter(d => d !== '.agents')) expect(fs.existsSync(path.join(b, dir)), `b ${dir}`).toBe(false);
|
||||
expect(backups(f)).toHaveLength(2);
|
||||
}, 240_000);
|
||||
|
||||
test('a host whose skills link into the render is kept even with no registry row', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
await legacyRender(src);
|
||||
fs.mkdirSync(path.join(f.home, '.factory/skills'), { recursive: true });
|
||||
fs.symlinkSync(path.join(src, '.factory/skills/gstack-qa'), path.join(f.home, '.factory/skills/gstack-qa'));
|
||||
setupOk(f, src);
|
||||
expect(fs.readFileSync(path.join(src, '.gstack-installed-hosts'), 'utf8')).toEndWith('\nclaude\nfactory\n');
|
||||
expect(skillFiles(path.join(src, '.factory')).length).toBeGreaterThan(40);
|
||||
expect(fs.existsSync(path.join(f.home, '.factory/skills/gstack-qa/SKILL.md'))).toBe(true);
|
||||
}, 240_000);
|
||||
});
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('gstack-upgrade migration prunes existing installs (#1694)', () => {
|
||||
const migrations = fs.readdirSync(path.join(ROOT, 'gstack-upgrade/migrations'))
|
||||
.filter(n => fs.readFileSync(path.join(ROOT, 'gstack-upgrade/migrations', n), 'utf8').includes('gstack-host-renders.sh'));
|
||||
|
||||
test('exactly one migration owns the prune, and setup runs it (not newer than VERSION)', () => {
|
||||
expect(migrations).toEqual([expect.stringMatching(/^v\d+\.\d+\.\d+\.\d+\.sh$/)]);
|
||||
const parts = (v: string) => v.split('.').map(Number);
|
||||
const mine = parts(migrations[0]!.slice(1, -3));
|
||||
const version = parts(fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf8').trim());
|
||||
const cmp = mine.map((n, i) => n - version[i]!).find(d => d !== 0) ?? 0;
|
||||
expect(cmp).toBeLessThanOrEqual(0);
|
||||
});
|
||||
|
||||
function migrate(f: Fixture, install: string) {
|
||||
return spawnSync('bash', [path.join(install, 'gstack-upgrade/migrations', migrations[0]!)], {
|
||||
cwd: f.home, encoding: 'utf8', timeout: 60_000, env: { ...f.env, GSTACK_INSTALL_DIR: install },
|
||||
});
|
||||
}
|
||||
|
||||
test('a pre-record Claude install: renders of other hosts are backed up and removed, a look-alike survives, rerun is a no-op', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
await legacyRender(src);
|
||||
put(path.join(src, '.opencode/skills/mine/SKILL.md'), 'no banner\n');
|
||||
const r = migrate(f, src);
|
||||
expect(r.status, r.stdout + r.stderr).toBe(0);
|
||||
expect(fs.readFileSync(path.join(src, '.gstack-installed-hosts'), 'utf8')).toEndWith('\nclaude\n');
|
||||
expect(skillFiles(src).filter(rel => rel.startsWith('.'))).toEqual(['.opencode/skills/mine/SKILL.md']);
|
||||
expect(r.stdout).toContain('kept .opencode/skills/mine/SKILL.md: not proven generated');
|
||||
expect(backups(f)).toHaveLength(1);
|
||||
const again = migrate(f, src);
|
||||
expect(again.status).toBe(0);
|
||||
expect(again.stdout).not.toContain('pruned ');
|
||||
expect(backups(f)).toHaveLength(1);
|
||||
}, 240_000);
|
||||
|
||||
test('a checkout no install points at is left alone', async () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, 'elsewhere/gstack'));
|
||||
await legacyRender(src);
|
||||
const before = skillFiles(src).length;
|
||||
const r = migrate(f, src);
|
||||
expect(r.status).toBe(0);
|
||||
expect(r.stdout).toContain(`host renders: no install from ${src} was found, so its renders were left alone`);
|
||||
expect(skillFiles(src).length).toBe(before);
|
||||
expect(fs.existsSync(path.join(src, '.gstack-installed-hosts'))).toBe(false);
|
||||
}, 240_000);
|
||||
});
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* #1694: an install renders skills only for the hosts installed from it.
|
||||
*
|
||||
* `./setup` used to run `gen:skill-docs --host all` inside the install, so a
|
||||
* global Claude install at ~/.claude/skills/gstack carried 632 SKILL.md files
|
||||
* (34.7 MB): every other host's render, all scanned by Claude Code and
|
||||
* Cursor-agent. setup now keeps an additive record of the hosts it installed
|
||||
* ($ROOT/.gstack-installed-hosts, owned by bin/gstack-host-renders.sh) and
|
||||
* scripts/build.sh renders claude plus those hosts. A checkout with no record
|
||||
* (development) or GSTACK_RENDER_HOSTS=all still renders every host.
|
||||
*/
|
||||
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { ALL_HOST_CONFIGS } from '../hosts';
|
||||
import { cleanupFixtures, cleanupSeed, makeFixture, makeSource, owned, registryRows, runSetup } from './helpers/install-fixture';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const HELPER = path.join(ROOT, 'bin/gstack-host-renders.sh');
|
||||
const BUILD = fs.readFileSync(path.join(ROOT, 'scripts/build.sh'), 'utf8');
|
||||
const RENDER_BLOCK = BUILD.slice(BUILD.indexOf('. "$ROOT/bin/gstack-host-renders.sh"'), BUILD.indexOf('\n"$BUN_CMD" build --compile'));
|
||||
const RENDER_DIRS = ALL_HOST_CONFIGS.filter(h => h.name !== 'claude').map(h => h.hostSubdir);
|
||||
|
||||
afterEach(cleanupFixtures);
|
||||
afterAll(cleanupSeed);
|
||||
|
||||
function tmpRoot(): string {
|
||||
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-host-renders-')));
|
||||
owned.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
function sh(script: string, env: Record<string, string> = {}, cwd?: string) {
|
||||
return spawnSync('bash', ['-c', `set -e\n. "${HELPER}"\n${script}`], {
|
||||
cwd, encoding: 'utf8', timeout: 60_000, env: { PATH: process.env.PATH ?? '/usr/bin:/bin', HOME: os.tmpdir(), ...env },
|
||||
});
|
||||
}
|
||||
|
||||
const skillCount = (dir: string): number => !fs.existsSync(dir) ? 0
|
||||
: fs.readdirSync(dir, { withFileTypes: true, recursive: true }).filter(e => e.isFile() && e.name === 'SKILL.md').length;
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('installed-hosts record (bin/gstack-host-renders.sh)', () => {
|
||||
test('its host -> render dir table matches hostSubdir in hosts/*.ts', () => {
|
||||
const table = sh('printf "%s\\n" $GSTACK_HOST_RENDER_DIRS').stdout.trim().split('\n').sort();
|
||||
expect(table).toEqual(ALL_HOST_CONFIGS.filter(h => h.name !== 'claude').map(h => `${h.name}:${h.hostSubdir}`).sort());
|
||||
});
|
||||
|
||||
test('adding is additive, sorted and ignores unknown names; an unchanged set is not rewritten', () => {
|
||||
const root = tmpRoot();
|
||||
const file = path.join(root, '.gstack-installed-hosts');
|
||||
expect(sh(`gstack_render_hosts_add "${root}" codex claude`).status).toBe(0);
|
||||
expect(sh(`gstack_render_hosts_add "${root}" factory nonsense`).status).toBe(0);
|
||||
expect(sh(`gstack_render_hosts_read "${root}"`).stdout).toBe('claude\ncodex\nfactory\n');
|
||||
expect(fs.readFileSync(file, 'utf8')).toContain('# Hosts installed from this gstack checkout');
|
||||
const stamp = new Date('2001-01-01');
|
||||
fs.utimesSync(file, stamp, stamp);
|
||||
expect(sh(`gstack_render_hosts_add "${root}" codex`).status).toBe(0);
|
||||
expect(fs.statSync(file).mtime.getTime()).toBe(stamp.getTime());
|
||||
fs.appendFileSync(file, 'hermes # rendered by hand\n\nbogus\n');
|
||||
expect(sh(`gstack_render_hosts_read "${root}"`).stdout).toBe('claude\ncodex\nfactory\nhermes\n');
|
||||
});
|
||||
|
||||
test('selection: no record renders every host; a record renders claude plus its hosts; GSTACK_RENDER_HOSTS=all overrides', () => {
|
||||
const root = tmpRoot();
|
||||
const select = (env: Record<string, string> = {}) => sh(`gstack_render_hosts_select "${root}"; echo "$GSTACK_RENDER_HOST_LIST|$GSTACK_RENDER_HOST_REASON"`, env);
|
||||
expect(select().stdout).toBe('all|no installed-hosts record, so this is a development checkout\n');
|
||||
sh(`gstack_render_hosts_add "${root}" codex`);
|
||||
expect(select().stdout).toStartWith('claude codex|recorded in ');
|
||||
expect(select({ GSTACK_RENDER_HOSTS: 'all' }).stdout).toBe('all|GSTACK_RENDER_HOSTS=all\n');
|
||||
const odd = select({ GSTACK_RENDER_HOSTS: 'codex' });
|
||||
expect(odd.stdout).toStartWith('claude codex|');
|
||||
expect(odd.stderr).toContain("GSTACK_RENDER_HOSTS accepts only 'all' (got 'codex'); ignoring it");
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('scripts/build.sh renders the recorded hosts (#1694)', () => {
|
||||
// build.sh's render step with a bun that only records its arguments.
|
||||
function renderCalls(root: string, env: Record<string, string> = {}) {
|
||||
fs.mkdirSync(path.join(root, 'bin'), { recursive: true });
|
||||
fs.copyFileSync(HELPER, path.join(root, 'bin/gstack-host-renders.sh'));
|
||||
const bun = path.join(root, 'fake-bun');
|
||||
fs.writeFileSync(bun, `#!/bin/sh\necho "$*" >> "${root}/bun.log"\n`, { mode: 0o755 });
|
||||
const r = spawnSync('bash', ['-c', `set -e\nROOT="${root}"\nBUN_CMD="${bun}"\n${RENDER_BLOCK}`], {
|
||||
cwd: root, encoding: 'utf8', timeout: 30_000, env: { PATH: process.env.PATH ?? '/usr/bin:/bin', ...env },
|
||||
});
|
||||
const log = fs.existsSync(path.join(root, 'bun.log')) ? fs.readFileSync(path.join(root, 'bun.log'), 'utf8') : '';
|
||||
return { ...r, calls: log.trim().split('\n') };
|
||||
}
|
||||
|
||||
test('a development checkout (no record) renders every host and says why', () => {
|
||||
const r = renderCalls(tmpRoot());
|
||||
expect(r.status, r.stderr).toBe(0);
|
||||
expect(r.calls).toEqual(['run gen:skill-docs --host all']);
|
||||
expect(r.stdout).toContain('Rendering skills for every host: no installed-hosts record, so this is a development checkout');
|
||||
});
|
||||
|
||||
test('an install renders claude, then each recorded host, and prints them', () => {
|
||||
const root = tmpRoot();
|
||||
fs.writeFileSync(path.join(root, '.gstack-installed-hosts'), 'codex\nfactory\n');
|
||||
const r = renderCalls(root);
|
||||
expect(r.status, r.stderr).toBe(0);
|
||||
expect(r.calls).toEqual(['run gen:skill-docs --host claude', 'run gen:skill-docs --host codex', 'run gen:skill-docs --host factory']);
|
||||
expect(r.stdout).toContain(`Rendering skills for: claude codex factory (recorded in ${root}/.gstack-installed-hosts; GSTACK_RENDER_HOSTS=all renders every host)`);
|
||||
});
|
||||
|
||||
test('GSTACK_RENDER_HOSTS=all renders every host inside an install', () => {
|
||||
const root = tmpRoot();
|
||||
fs.writeFileSync(path.join(root, '.gstack-installed-hosts'), 'claude\n');
|
||||
const r = renderCalls(root, { GSTACK_RENDER_HOSTS: 'all' });
|
||||
expect(r.calls).toEqual(['run gen:skill-docs --host all']);
|
||||
expect(r.stdout).toContain('Rendering skills for every host: GSTACK_RENDER_HOSTS=all');
|
||||
});
|
||||
|
||||
test('a real render inside a Claude install leaves no other host SKILL.md; a development checkout still renders all', () => {
|
||||
const f = makeFixture();
|
||||
const install = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
const dev = makeSource(f, path.join(f.home, 'dev/gstack'));
|
||||
fs.writeFileSync(path.join(install, '.gstack-installed-hosts'), 'claude\n');
|
||||
for (const root of [install, dev]) {
|
||||
const r = spawnSync('bash', ['-c', `set -e\nROOT="${root}"\nBUN_CMD=bun\n${RENDER_BLOCK}`], {
|
||||
cwd: root, encoding: 'utf8', timeout: 120_000, env: f.env,
|
||||
});
|
||||
expect(r.status, r.stdout + r.stderr).toBe(0);
|
||||
}
|
||||
for (const dir of RENDER_DIRS) {
|
||||
expect(skillCount(path.join(install, dir)), dir).toBe(0);
|
||||
expect(skillCount(path.join(dev, dir)), dir).toBeGreaterThan(40);
|
||||
}
|
||||
expect(skillCount(install)).toBeLessThan(100);
|
||||
expect(skillCount(dev)).toBeGreaterThan(500);
|
||||
}, 180_000);
|
||||
});
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('setup records each host it installs and never forgets one', () => {
|
||||
test('claude, then codex, then factory: the record grows and each recorded host keeps its render', () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
const setup = (args: string[]) => {
|
||||
const r = runSetup(f, path.join(src, 'setup'), args);
|
||||
expect(r.status, r.stdout + r.stderr).toBe(0);
|
||||
return fs.readFileSync(path.join(src, '.gstack-installed-hosts'), 'utf8').split('\n').filter(l => l && !l.startsWith('#'));
|
||||
};
|
||||
expect(setup([])).toEqual(['claude']);
|
||||
expect(fs.existsSync(path.join(src, '.agents'))).toBe(false);
|
||||
expect(setup(['--host', 'codex'])).toEqual(['claude', 'codex']);
|
||||
expect(skillCount(path.join(src, '.agents'))).toBeGreaterThan(40);
|
||||
expect(setup(['--host', 'factory'])).toEqual(['claude', 'codex', 'factory']);
|
||||
expect(skillCount(path.join(src, '.agents'))).toBeGreaterThan(40);
|
||||
expect(skillCount(path.join(src, '.factory'))).toBeGreaterThan(40);
|
||||
// The updater path (/gstack-upgrade and gstack-session-update) refreshes
|
||||
// every registered install; the record and both renders survive it.
|
||||
const r = runSetup(f, path.join(src, 'setup'), ['--refresh-registered']);
|
||||
expect(r.status, r.stdout + r.stderr).toBe(0);
|
||||
expect(registryRows(f).map(row => row[0]).sort()).toEqual(['claude', 'codex', 'factory']);
|
||||
expect(setup([])).toEqual(['claude', 'codex', 'factory']);
|
||||
expect(skillCount(path.join(src, '.agents'))).toBeGreaterThan(40);
|
||||
expect(skillCount(path.join(src, '.factory'))).toBeGreaterThan(40);
|
||||
for (const dir of RENDER_DIRS.filter(d => d !== '.agents' && d !== '.factory')) expect(fs.existsSync(path.join(src, dir)), dir).toBe(false);
|
||||
}, 240_000);
|
||||
|
||||
test('an install made before the record keeps the hosts the registry says it serves', () => {
|
||||
const f = makeFixture();
|
||||
const src = makeSource(f, path.join(f.home, '.claude/skills/gstack'));
|
||||
expect(runSetup(f, path.join(src, 'setup'), ['--host', 'factory']).status).toBe(0);
|
||||
fs.rmSync(path.join(src, '.gstack-installed-hosts'));
|
||||
const r = runSetup(f, path.join(src, 'setup'), []);
|
||||
expect(r.status, r.stdout + r.stderr).toBe(0);
|
||||
expect(fs.readFileSync(path.join(src, '.gstack-installed-hosts'), 'utf8')).toContain('\nclaude\nfactory\n');
|
||||
}, 120_000);
|
||||
});
|
||||
@@ -529,7 +529,7 @@ describe('installed QA pointers', () => {
|
||||
'_gstack_generated_header', '_claude_entry_owned_strongly', '_claude_entry_is_ours', '_write_owned_marker',
|
||||
'_backup_skill_md', '_cleanup_weak_dir', '_gstack_dir_only_links', '_cleanup_linked_dir',
|
||||
'_owned_for_windows_refresh', '_sidecar_root_user_owned', '_prune_stale_generated', '_skill_source_exists',
|
||||
'_link_runtime_dists', '_copy_skill_md', '_skill_copy_hash', '_skill_copy_unmodified', '_preserve_skill_copy_edits', '_record_skill_copies',
|
||||
'_link_runtime_dists', '_copy_runtime_skill_refs', '_copy_skill_md', '_skill_copy_hash', '_skill_copy_unmodified', '_preserve_skill_copy_edits', '_record_skill_copies',
|
||||
].map(setupFunction).join('\n')
|
||||
// Install-registry rows (setup's _setup_arm_* / _setup_row) are not under test here.
|
||||
+ '\n_setup_arm_begin() { :; }\n_setup_arm_publish() { :; }\n_setup_row() { :; }';
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
* Every file a generated skill reads through $GSTACK_ROOT exists in the
|
||||
* runtime root setup builds for that host (#1077 residue, fix wave C2).
|
||||
*
|
||||
* Env-var hosts reach gstack only through their runtime root
|
||||
* (~/.codex/skills/gstack, ~/.factory/skills/gstack, ...). The roots carried
|
||||
* bin/, lib/ and the compiled tools, but not the files the shared preamble and
|
||||
* several skills read on demand: the jargon list and question registry, the
|
||||
* AskUserQuestion split and CJK docs, the DX Hall of Fame, the test-value bar,
|
||||
* VERSION, design-html's vendored pretext.js and plan-design-review/SKILL.md.
|
||||
* Those reads failed silently on every non-Claude host.
|
||||
*
|
||||
* This test renders every host, builds each runtime root with setup's own
|
||||
* shell functions, then checks every $GSTACK_ROOT/<path> literal in that
|
||||
* host's render (prose and fences) against the staged root on disk.
|
||||
*/
|
||||
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { HOST_CONFIG_MAP } from '../hosts';
|
||||
import { runGeneration } from '../scripts/gen-skill-docs';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const SETUP_SRC = fs.readFileSync(path.join(ROOT, 'setup'), 'utf-8');
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-root-assets-'));
|
||||
const renderDir = path.join(tmp, 'render');
|
||||
const src = path.join(tmp, 'gstack');
|
||||
|
||||
// Host -> the setup function that builds its global runtime root. Kiro builds
|
||||
// its root inline in the Kiro arm and is covered by a source assertion below.
|
||||
const ROOT_BUILDERS: Record<string, string> = {
|
||||
codex: 'create_codex_runtime_root',
|
||||
factory: 'create_factory_runtime_root',
|
||||
opencode: 'create_opencode_runtime_root',
|
||||
cursor: 'create_cursor_runtime_root',
|
||||
copilot: 'create_copilot_runtime_root',
|
||||
};
|
||||
|
||||
// Deferred, with the reason recorded in TODOS.md: /ship's measure loop runs
|
||||
// scripts/ship-measure.ts, which imports gstack's test helpers and eval
|
||||
// harness; a runtime root would need the whole development tree.
|
||||
const DEFERRED = new Set(['scripts/ship-measure.ts']);
|
||||
|
||||
// Compiled outputs: the stub source carries placeholder binaries, so a fresh
|
||||
// checkout without a build still exercises the links to them.
|
||||
const BUILT = ['browse/dist/browse', 'browse/dist/find-browse', 'design/dist/design', 'make-pdf/dist/pdf'];
|
||||
// Compiled into bin/, which every root links whole: checked through that link.
|
||||
const BUILT_IN_BIN = new Set(['bin/gstack-global-discover']);
|
||||
|
||||
function extractFunction(name: string): string {
|
||||
const start = SETUP_SRC.indexOf(`\n${name}() {`);
|
||||
const end = SETUP_SRC.indexOf('\n}\n', start);
|
||||
if (start < 0 || end < 0) throw new Error(`Could not locate ${name}() in setup`);
|
||||
return SETUP_SRC.slice(start + 1, end + 2);
|
||||
}
|
||||
|
||||
function walk(dir: string): string[] {
|
||||
return fs.readdirSync(dir, { withFileTypes: true }).flatMap(e =>
|
||||
e.isDirectory() ? walk(path.join(dir, e.name)) : [path.join(dir, e.name)]);
|
||||
}
|
||||
|
||||
/** Every $GSTACK_ROOT/<path> literal in a host's rendered skills. */
|
||||
function referencedPaths(host: string): Set<string> {
|
||||
const out = new Set<string>();
|
||||
for (const file of walk(path.join(renderDir, HOST_CONFIG_MAP[host]!.hostSubdir, 'skills'))) {
|
||||
for (const m of fs.readFileSync(file, 'utf8').matchAll(/\$\{?GSTACK_ROOT\}?\/([A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*)/g)) {
|
||||
out.add(m[1]!.replace(/\.+$/, ''));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// A source tree that links every tracked top-level entry of this checkout,
|
||||
// with stub compiled binaries and each host's render in its usual place.
|
||||
function makeSource(): void {
|
||||
fs.mkdirSync(src, { recursive: true });
|
||||
const built = new Set(BUILT.map(rel => rel.split('/')[0]!));
|
||||
for (const name of fs.readdirSync(ROOT)) {
|
||||
if (name.startsWith('.') || name === 'node_modules') continue;
|
||||
if (!built.has(name)) { fs.symlinkSync(path.join(ROOT, name), path.join(src, name)); continue; }
|
||||
fs.mkdirSync(path.join(src, name));
|
||||
for (const child of fs.readdirSync(path.join(ROOT, name))) {
|
||||
if (child !== 'dist') fs.symlinkSync(path.join(ROOT, name, child), path.join(src, name, child));
|
||||
}
|
||||
}
|
||||
for (const rel of BUILT) {
|
||||
fs.mkdirSync(path.dirname(path.join(src, rel)), { recursive: true });
|
||||
fs.writeFileSync(path.join(src, rel), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
||||
}
|
||||
for (const host of Object.keys(ROOT_BUILDERS)) {
|
||||
const sub = HOST_CONFIG_MAP[host]!.hostSubdir;
|
||||
fs.symlinkSync(path.join(renderDir, sub), path.join(src, sub));
|
||||
}
|
||||
}
|
||||
|
||||
function buildRoot(host: string): { root: string; stderr: string; status: number | null } {
|
||||
const root = path.join(tmp, 'home', host, 'skills', 'gstack');
|
||||
fs.mkdirSync(path.dirname(root), { recursive: true });
|
||||
const functions = ['_link_or_copy', '_link_runtime_dists', '_copy_runtime_skill_refs', '_copy_skill_md',
|
||||
'_sidecar_root_user_owned', '_gstack_generated_header', ROOT_BUILDERS[host]!]
|
||||
.filter(name => SETUP_SRC.includes(`\n${name}() {`)).map(extractFunction).join('\n');
|
||||
const r = spawnSync('bash', ['-c', `set -e\nIS_WINDOWS=0\n${functions}\n${ROOT_BUILDERS[host]} "${src}" "${root}"`],
|
||||
{ encoding: 'utf8', timeout: 30_000, env: { PATH: process.env.PATH ?? '/usr/bin:/bin', HOME: path.join(tmp, 'home') } });
|
||||
return { root, stderr: r.stderr, status: r.status };
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
const result = await runGeneration({ host: 'all', outputRoot: renderDir });
|
||||
if (result.exitCode !== 0) throw new Error(result.diagnostics.filter(d => d.kind === 'error').map(d => d.message).join('\n'));
|
||||
makeSource();
|
||||
});
|
||||
afterAll(() => fs.rmSync(tmp, { recursive: true, force: true }));
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('runtime roots carry every $GSTACK_ROOT file their skills read', () => {
|
||||
test('the extractor finds the known read-on-demand files in the Codex render', () => {
|
||||
const paths = referencedPaths('codex');
|
||||
for (const rel of ['scripts/jargon-list.json', 'scripts/question-registry.ts', 'docs/askuserquestion-split.md', 'plan-devex-review/dx-hall-of-fame.md']) {
|
||||
expect(paths.has(rel), rel).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
for (const host of Object.keys(ROOT_BUILDERS)) {
|
||||
test(`${host}: every referenced path exists in the staged runtime root`, () => {
|
||||
const { root, stderr, status } = buildRoot(host);
|
||||
expect(stderr).toBe('');
|
||||
expect(status).toBe(0);
|
||||
const missing = [...referencedPaths(host)]
|
||||
.filter(rel => !DEFERRED.has(rel) && !BUILT_IN_BIN.has(rel) && !fs.existsSync(path.join(root, rel))).sort();
|
||||
expect(missing).toEqual([]);
|
||||
// Each one is the same kind of entry as in the source: a file stays a file.
|
||||
const wrongKind = [...referencedPaths(host)].filter(rel => fs.existsSync(path.join(root, rel)) && fs.existsSync(path.join(ROOT, rel))
|
||||
&& fs.statSync(path.join(root, rel)).isFile() !== fs.statSync(path.join(ROOT, rel)).isFile());
|
||||
expect(wrongKind).toEqual([]);
|
||||
expect(fs.realpathSync(path.join(root, 'bin'))).toBe(fs.realpathSync(path.join(ROOT, 'bin')));
|
||||
});
|
||||
}
|
||||
|
||||
test('a runtime root never gains a whole skill directory beside the rendered copies', () => {
|
||||
const { root } = buildRoot('codex');
|
||||
for (const dir of ['plan-design-review', 'office-hours']) {
|
||||
expect(fs.readdirSync(path.join(root, dir))).toEqual(['SKILL.md']);
|
||||
expect(fs.lstatSync(path.join(root, dir, 'SKILL.md')).isSymbolicLink()).toBe(false);
|
||||
expect(fs.readFileSync(path.join(root, dir, 'SKILL.md'), 'utf8')).toContain('$GSTACK_ROOT');
|
||||
}
|
||||
expect(fs.existsSync(path.join(root, 'design-html', 'SKILL.md'))).toBe(false);
|
||||
expect(fs.existsSync(path.join(root, 'plan-devex-review', 'SKILL.md'))).toBe(false);
|
||||
});
|
||||
|
||||
test('the Kiro arm uses the same shared asset helpers as every other root', () => {
|
||||
const arm = SETUP_SRC.slice(SETUP_SRC.indexOf('# 6. Install for Kiro CLI'), SETUP_SRC.indexOf('# 6b. Install for Factory Droid'));
|
||||
expect(arm.includes('_link_runtime_dists "$SOURCE_GSTACK_DIR" "$KIRO_GSTACK"')).toBe(true);
|
||||
expect(arm.includes('_copy_runtime_skill_refs "$KIRO_DIR" "$KIRO_GSTACK"')).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -30,7 +30,7 @@ function fixture(copy: boolean) {
|
||||
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-models', 'gstack-state-root.sh', 'gstack-bun-version.sh', 'gstack-install-registry.sh', 'gstack-render-claude.sh']) {
|
||||
for (const bin of ['gstack-config', 'gstack-patch-names', 'gstack-relink', 'gstack-migrate-claude-code', 'gstack-claude-code', 'gstack-models', 'gstack-state-root.sh', 'gstack-bun-version.sh', 'gstack-install-registry.sh', 'gstack-render-claude.sh', 'gstack-host-renders.sh']) {
|
||||
const target = path.join(root, 'bin', bin);
|
||||
fs.mkdirSync(path.dirname(target), { recursive: true });
|
||||
fs.copyFileSync(path.join(ROOT, 'bin', bin), target);
|
||||
|
||||
@@ -97,7 +97,7 @@ const BUILDERS: Record<string, (sandbox: string, src: string) => Built> = {
|
||||
},
|
||||
};
|
||||
|
||||
const FUNCTIONS = ['_link_or_copy', '_link_runtime_dists', '_copy_skill_md', '_sidecar_root_user_owned', '_gstack_generated_header', 'create_agents_sidecar', 'create_codex_runtime_root']
|
||||
const FUNCTIONS = ['_link_or_copy', '_link_runtime_dists', '_copy_runtime_skill_refs', '_copy_skill_md', '_sidecar_root_user_owned', '_gstack_generated_header', 'create_agents_sidecar', 'create_codex_runtime_root']
|
||||
.filter(name => SETUP_SRC.includes(`\n${name}() {`))
|
||||
.map(extractFunction)
|
||||
.join('\n');
|
||||
|
||||
@@ -17,7 +17,7 @@ const fn = (name: string) => {
|
||||
const blockStart = setup.indexOf('# 6. Install for Kiro CLI');
|
||||
const block = setup.slice(blockStart, setup.indexOf('# 6b.', blockStart));
|
||||
const helpers = [
|
||||
'_link_or_copy', '_link_runtime_dists', '_sidecar_root_user_owned', '_claude_entry_is_ours',
|
||||
'_link_or_copy', '_link_runtime_dists', '_copy_runtime_skill_refs', '_sidecar_root_user_owned', '_claude_entry_is_ours',
|
||||
'_claude_entry_owned_strongly', '_gstack_link_target_abs', '_gstack_target_is_ours',
|
||||
'_gstack_generated_header', '_backup_skill_md', '_prune_stale_generated',
|
||||
'_skill_source_exists', '_owned_for_windows_refresh', '_cleanup_weak_dir',
|
||||
|
||||
@@ -160,6 +160,7 @@ function runInstaller(
|
||||
extraVars,
|
||||
extractFn('_link_or_copy'),
|
||||
extractFn('_link_runtime_dists'),
|
||||
extractFn('_copy_runtime_skill_refs'),
|
||||
// Ownership gates (#2142) — dependencies of every installer under test.
|
||||
extractFn('_owned_for_windows_refresh'),
|
||||
extractFn('_sidecar_root_user_owned'),
|
||||
|
||||
@@ -455,7 +455,7 @@ describe('setup --team / --no-team / -q', () => {
|
||||
try {
|
||||
for (const rel of [
|
||||
'setup', 'VERSION', 'SKILL.md', 'qa/SKILL.md', 'bin/gstack-config', 'bin/gstack-patch-names',
|
||||
'bin/gstack-state-root.sh', 'bin/gstack-bun-version.sh', 'bin/gstack-install-registry.sh', 'bin/gstack-render-claude.sh',
|
||||
'bin/gstack-state-root.sh', 'bin/gstack-bun-version.sh', 'bin/gstack-install-registry.sh', 'bin/gstack-render-claude.sh', 'bin/gstack-host-renders.sh',
|
||||
'scripts/resolve-codex-generation-model.ts', 'scripts/models.ts', 'scripts/preflight-codex-overlap.ts',
|
||||
'scripts/discover-skills.ts', 'scripts/external-skill-names.ts', 'scripts/host-config.ts',
|
||||
'lib/claude-code-migration.ts', 'lib/model-policy.ts', 'lib/model-catalog.ts',
|
||||
|
||||
Reference in new issue
Block a user