mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 00:21:14 +01:00
Garry, 2026-11-15: people rely on /plan-eng-review, so it returns as its own command on every host that had it before GST-1698 (#4108). /autoplan's eng phase is unchanged: external hosts still ship the same methodology beside gstack-autoplan/SKILL.md, now rendered from the same pass as the standalone skill, and the Kiro sibling copy and ownership guards from #4108 stay. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
105 lines
5.9 KiB
TypeScript
105 lines
5.9 KiB
TypeScript
import { afterEach, describe, expect, test } from 'bun:test';
|
|
import { spawnSync } from 'node:child_process';
|
|
import { chmodSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join, resolve } from 'node:path';
|
|
import { createSnapshot, prepareMethodology } from '../bin/gstack-autoplan-snapshot';
|
|
import { AUTOPLAN_SIBLING_METHODOLOGIES } from '../scripts/discover-skills';
|
|
|
|
const ROOT = resolve(import.meta.dir, '..');
|
|
const owned: string[] = [];
|
|
const phases = ['ceo', 'design', 'dx', 'eng'];
|
|
afterEach(() => { for (const dir of owned.splice(0)) rmSync(dir, { recursive: true, force: true }); });
|
|
|
|
function fixture(phase: string, layout: string) {
|
|
const dir = mkdtempSync(join(tmpdir(), 'gstack-method-names-'));
|
|
owned.push(dir);
|
|
const skill = `plan-${phase === 'dx' ? 'devex' : phase}-review`;
|
|
if (layout === 'inlineCodex') {
|
|
const home = join(dir, 'home');
|
|
mkdirSync(home);
|
|
const generated = spawnSync(process.execPath, ['run', 'scripts/gen-skill-docs.ts', '--host', 'codex', '--out-dir', dir], {
|
|
cwd: ROOT, env: { PATH: process.env.PATH, HOME: home, GSTACK_HOME: join(home, '.gstack') }, encoding: 'utf8', timeout: 30_000,
|
|
});
|
|
expect(generated.status, generated.stderr).toBe(0);
|
|
}
|
|
// /autoplan reads a sibling methodology file beside its own SKILL.md on external hosts.
|
|
const siblingInline = layout === 'inlineCodex' && AUTOPLAN_SIBLING_METHODOLOGIES.includes(skill);
|
|
const source = layout === 'inlineCodex' ? join(dir, '.agents/skills', siblingInline ? 'gstack-autoplan' : `gstack-${skill}`) : join(ROOT, skill);
|
|
const fileName = siblingInline ? `${skill}.md` : 'SKILL.md';
|
|
const target = join(dir, siblingInline ? 'gstack-autoplan' : skill);
|
|
mkdirSync(target);
|
|
cpSync(join(source, fileName), join(target, fileName));
|
|
// C4: Codex carves plan-ceo-review too, so an install that has sections/ copies it.
|
|
// Every tier 2+ skill ships sections/preamble.md; carving is the review section.
|
|
const carved = !siblingInline && existsSync(join(source, 'sections', 'review-sections.md'));
|
|
if (existsSync(join(source, 'sections'))) cpSync(join(source, 'sections'), join(target, 'sections'), { recursive: true });
|
|
if (layout === 'patchedClaude') {
|
|
const result = spawnSync('bash', [join(ROOT, 'bin/gstack-patch-names'), dir, 'true'], { encoding: 'utf8', timeout: 10_000 });
|
|
expect(result.status, result.stderr).toBe(0);
|
|
expect(readFileSync(join(target, 'SKILL.md'), 'utf8')).toContain(`name: gstack-${skill}\n`);
|
|
}
|
|
const active = join(dir, 'plan.md');
|
|
const restore = join(dir, 'restore.md');
|
|
writeFileSync(active, '## Implementation plan\nBuild the widget.\n## Review record\n');
|
|
writeFileSync(restore, 'Restore point.\n');
|
|
return { dir, file: join(target, fileName), active, restore, skill, carved };
|
|
}
|
|
|
|
describe('installed methodology identities', () => {
|
|
for (const phase of phases) for (const layout of ['flatClaude', 'patchedClaude', 'inlineCodex']) {
|
|
test(`${phase}: ${layout} prepares and consumes exact installed bytes`, () => {
|
|
const f = fixture(phase, layout);
|
|
const bundle = prepareMethodology(phase, f.file, f.restore);
|
|
expect(bundle.sources).toHaveLength(f.carved ? 2 : 1);
|
|
if (layout !== 'inlineCodex') expect(f.carved).toBe(true);
|
|
const bytes = readFileSync(bundle.methodologyPath);
|
|
for (const source of bundle.sources) expect(bytes.subarray(source.startByte, source.endByte)).toEqual(readFileSync(source.path));
|
|
expect(readFileSync(createSnapshot(phase, f.active, f.restore, bundle.methodologyPath).snapshotPath, 'utf8')).toBe('Build the widget.\n');
|
|
});
|
|
}
|
|
|
|
for (const phase of phases) {
|
|
test(`${phase}: wrong-phase and near-match aliases remain invalid`, () => {
|
|
const f = fixture(phase, 'flatClaude');
|
|
const source = readFileSync(f.file, 'utf8');
|
|
const other = phase === 'ceo' ? 'eng' : 'ceo';
|
|
for (const name of [`plan-${other}-review`, `gstack-plan-${other}-review`, `x-${f.skill}`, `gstack-${f.skill}-extra`, `gstack-gstack-${f.skill}`]) {
|
|
writeFileSync(f.file, source.replace(`name: ${f.skill}\n`, `name: ${name}\n`));
|
|
expect(() => prepareMethodology(phase, f.file, f.restore)).toThrow('identity does not match');
|
|
}
|
|
});
|
|
|
|
test(`${phase}: duplicate methodology identities remain invalid`, () => {
|
|
const f = fixture(phase, 'flatClaude');
|
|
const source = readFileSync(f.file, 'utf8');
|
|
const other = phase === 'ceo' ? 'eng' : 'ceo';
|
|
for (const names of [
|
|
`name: ${f.skill}\nname: plan-${other}-review\n`,
|
|
`name: gstack-${f.skill}\nname: gstack-plan-${other}-review\n`,
|
|
`name: plan-${other}-review\nname: ${f.skill}\n`,
|
|
`name: ${f.skill}\nname: gstack-${f.skill}\n`,
|
|
]) {
|
|
writeFileSync(f.file, source.replace(`name: ${f.skill}\n`, names));
|
|
expect(() => prepareMethodology(phase, f.file, f.restore)).toThrow('identity does not match');
|
|
}
|
|
});
|
|
|
|
test(`${phase}: invalid UTF-8 and changed installed source stay rejected`, () => {
|
|
const f = fixture(phase, 'flatClaude');
|
|
const source = readFileSync(f.file);
|
|
writeFileSync(f.file, Buffer.concat([source, Buffer.from([0xff])]));
|
|
expect(() => prepareMethodology(phase, f.file, f.restore)).toThrow('valid UTF-8');
|
|
writeFileSync(f.file, source);
|
|
const bundle = prepareMethodology(phase, f.file, f.restore);
|
|
writeFileSync(f.file, Buffer.concat([source, Buffer.from('\nChanged source.\n')]));
|
|
expect(() => createSnapshot(phase, f.active, f.restore, bundle.methodologyPath)).toThrow('source or artifact changed');
|
|
writeFileSync(f.file, source);
|
|
chmodSync(bundle.methodologyPath, 0o644);
|
|
writeFileSync(bundle.methodologyPath, 'Tampered bundle.\n');
|
|
chmodSync(bundle.methodologyPath, 0o444);
|
|
expect(() => createSnapshot(phase, f.active, f.restore, bundle.methodologyPath)).toThrow('source or artifact changed');
|
|
});
|
|
}
|
|
});
|