mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-07 14:06:42 +02:00
merge: incorporate origin/main into community-mode branch
Conflicts resolved: - README.md: merge skill lists — keep /gstack-submit from our branch, add /plan-devex-review, /devex-review, /pair-agent from main. Accept main's team mode step 2 text. - setup: keep both our install ping (step 9) and main's team mode hook registration (step 10) - supabase/functions/telemetry-ingest/index.ts: keep our deletion (dead code removed earlier on this branch, main modified it) Main brought in: team mode (--team flag, auto-update hook, session tracking), /plan-devex-review + /devex-review skills, /pair-agent skill, open-gstack-browser, /checkpoint, /health, /humanizer. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vendored
+2503
File diff suppressed because it is too large
Load Diff
+2503
File diff suppressed because it is too large
Load Diff
+2123
File diff suppressed because it is too large
Load Diff
+2499
File diff suppressed because it is too large
Load Diff
+207
-13
@@ -213,11 +213,20 @@ describe('gen-skill-docs', () => {
|
||||
expect(browseTmpl).toContain('{{PREAMBLE}}');
|
||||
});
|
||||
|
||||
test('generated SKILL.md contains contributor mode check', () => {
|
||||
test('generated SKILL.md contains operational self-improvement (replaced contributor mode)', () => {
|
||||
const content = fs.readFileSync(path.join(ROOT, 'SKILL.md'), 'utf-8');
|
||||
expect(content).toContain('Contributor Mode');
|
||||
expect(content).toContain('gstack_contributor');
|
||||
expect(content).toContain('contributor-logs');
|
||||
expect(content).not.toContain('Contributor Mode');
|
||||
expect(content).not.toContain('gstack_contributor');
|
||||
expect(content).not.toContain('contributor-logs');
|
||||
expect(content).toContain('Operational Self-Improvement');
|
||||
expect(content).toContain('gstack-learnings-log');
|
||||
expect(content).toContain('gstack-learnings-search --limit 3');
|
||||
});
|
||||
|
||||
test('generated SKILL.md with LEARNINGS_LOG contains operational type', () => {
|
||||
// Check a skill that has LEARNINGS_LOG (e.g., review)
|
||||
const content = fs.readFileSync(path.join(ROOT, 'review', 'SKILL.md'), 'utf-8');
|
||||
expect(content).toContain('operational');
|
||||
});
|
||||
|
||||
test('generated SKILL.md contains session awareness', () => {
|
||||
@@ -740,6 +749,22 @@ describe('TEST_COVERAGE_AUDIT placeholders', () => {
|
||||
expect(shipSkill).toContain(phrase);
|
||||
}
|
||||
});
|
||||
|
||||
test('ship SKILL.md contains review army specialist dispatch', () => {
|
||||
expect(shipSkill).toContain('Specialist Dispatch');
|
||||
expect(shipSkill).toContain('Step 3.55');
|
||||
expect(shipSkill).toContain('Step 3.56');
|
||||
});
|
||||
|
||||
test('ship SKILL.md contains cross-review finding dedup', () => {
|
||||
expect(shipSkill).toContain('Cross-review finding dedup');
|
||||
expect(shipSkill).toContain('Step 3.57');
|
||||
});
|
||||
|
||||
test('ship SKILL.md contains re-run idempotency behavior', () => {
|
||||
expect(shipSkill).toContain('Re-run behavior (idempotency)');
|
||||
expect(shipSkill).toContain('Never skip a verification step');
|
||||
});
|
||||
});
|
||||
|
||||
// --- {{TEST_FAILURE_TRIAGE}} resolver tests ---
|
||||
@@ -979,6 +1004,18 @@ describe('Plan status footer in preamble', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// --- Skill invocation during plan mode in preamble ---
|
||||
|
||||
describe('Skill invocation during plan mode in preamble', () => {
|
||||
test('preamble contains skill invocation plan mode section', () => {
|
||||
const content = fs.readFileSync(path.join(ROOT, 'office-hours', 'SKILL.md'), 'utf-8');
|
||||
expect(content).toContain('Skill Invocation During Plan Mode');
|
||||
expect(content).toContain('precedence over generic plan mode behavior');
|
||||
expect(content).toContain('Do not continue the workflow');
|
||||
expect(content).toContain('cancel the skill or leave plan mode');
|
||||
});
|
||||
});
|
||||
|
||||
// --- {{SPEC_REVIEW_LOOP}} resolver tests ---
|
||||
|
||||
describe('SPEC_REVIEW_LOOP resolver', () => {
|
||||
@@ -1718,7 +1755,10 @@ describe('Codex generation (--host codex)', () => {
|
||||
test('Claude output unchanged: all Claude skills have zero Codex paths', () => {
|
||||
for (const skill of ALL_SKILLS) {
|
||||
const content = fs.readFileSync(path.join(ROOT, skill.dir, 'SKILL.md'), 'utf-8');
|
||||
expect(content).not.toContain('~/.codex/');
|
||||
// pair-agent legitimately documents how Codex agents store credentials
|
||||
if (skill.dir !== 'pair-agent') {
|
||||
expect(content).not.toContain('~/.codex/');
|
||||
}
|
||||
// gstack-upgrade legitimately references .agents/skills for cross-platform detection
|
||||
if (skill.dir !== 'gstack-upgrade') {
|
||||
expect(content).not.toContain('.agents/skills');
|
||||
@@ -1877,19 +1917,95 @@ describe('Factory generation (--host factory)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Parameterized host smoke tests (config-driven) ─────────
|
||||
|
||||
import { ALL_HOST_CONFIGS, getExternalHosts } from '../hosts/index';
|
||||
|
||||
describe('Parameterized host smoke tests', () => {
|
||||
for (const hostConfig of getExternalHosts()) {
|
||||
describe(`${hostConfig.displayName} (--host ${hostConfig.name})`, () => {
|
||||
const hostDir = path.join(ROOT, hostConfig.hostSubdir, 'skills');
|
||||
|
||||
test('generates output that exists on disk', () => {
|
||||
// Generated dir should exist (created by earlier bun run gen:skill-docs --host all)
|
||||
if (!fs.existsSync(hostDir)) {
|
||||
// Generate if not already done
|
||||
Bun.spawnSync(['bun', 'run', 'scripts/gen-skill-docs.ts', '--host', hostConfig.name], {
|
||||
cwd: ROOT, stdout: 'pipe', stderr: 'pipe',
|
||||
});
|
||||
}
|
||||
expect(fs.existsSync(hostDir)).toBe(true);
|
||||
const skills = fs.readdirSync(hostDir).filter(d =>
|
||||
fs.existsSync(path.join(hostDir, d, 'SKILL.md'))
|
||||
);
|
||||
expect(skills.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('no .claude/skills path leakage in non-root skills', () => {
|
||||
if (!fs.existsSync(hostDir)) return; // skip if not generated
|
||||
const skills = fs.readdirSync(hostDir);
|
||||
for (const skill of skills) {
|
||||
// Skip root gstack skill — it contains preamble with intentional .claude/skills
|
||||
// fallback paths for binary lookup and skill prefix instructions
|
||||
if (skill === 'gstack') continue;
|
||||
const skillMd = path.join(hostDir, skill, 'SKILL.md');
|
||||
if (!fs.existsSync(skillMd)) continue;
|
||||
const content = fs.readFileSync(skillMd, 'utf-8');
|
||||
// Strip bash blocks (which have legitimate fallback paths)
|
||||
const noBash = content.replace(/```bash\n[\s\S]*?```/g, '');
|
||||
const leaks = noBash.split('\n').filter(l => l.includes('.claude/skills'));
|
||||
if (leaks.length > 0) {
|
||||
throw new Error(`${skill}: .claude/skills leakage:\n${leaks.slice(0, 3).join('\n')}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('frontmatter has name and description', () => {
|
||||
if (!fs.existsSync(hostDir)) return;
|
||||
const skills = fs.readdirSync(hostDir);
|
||||
for (const skill of skills) {
|
||||
const skillMd = path.join(hostDir, skill, 'SKILL.md');
|
||||
if (!fs.existsSync(skillMd)) continue;
|
||||
const content = fs.readFileSync(skillMd, 'utf-8');
|
||||
expect(content).toMatch(/^---\n/);
|
||||
expect(content).toMatch(/^name:\s/m);
|
||||
expect(content).toMatch(/^description:\s/m);
|
||||
}
|
||||
});
|
||||
|
||||
test('--dry-run freshness check passes', () => {
|
||||
const result = Bun.spawnSync(
|
||||
['bun', 'run', 'scripts/gen-skill-docs.ts', '--host', hostConfig.name, '--dry-run'],
|
||||
{ cwd: ROOT, stdout: 'pipe', stderr: 'pipe' }
|
||||
);
|
||||
expect(result.exitCode).toBe(0);
|
||||
const output = result.stdout.toString();
|
||||
expect(output).not.toContain('STALE');
|
||||
});
|
||||
|
||||
if (hostConfig.generation.skipSkills?.includes('codex')) {
|
||||
test('/codex skill excluded', () => {
|
||||
expect(fs.existsSync(path.join(hostDir, 'gstack-codex', 'SKILL.md'))).toBe(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// ─── --host all tests ────────────────────────────────────────
|
||||
|
||||
describe('--host all', () => {
|
||||
test('--host all generates for claude, codex, and factory', () => {
|
||||
test('--host all generates for all registered hosts', () => {
|
||||
const result = Bun.spawnSync(['bun', 'run', 'scripts/gen-skill-docs.ts', '--host', 'all', '--dry-run'], {
|
||||
cwd: ROOT, stdout: 'pipe', stderr: 'pipe',
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
const output = result.stdout.toString();
|
||||
// All three hosts should appear in output
|
||||
// All hosts should appear in output
|
||||
expect(output).toContain('FRESH: SKILL.md'); // claude
|
||||
expect(output).toContain('FRESH: .agents/skills/'); // codex
|
||||
expect(output).toContain('FRESH: .factory/skills/'); // factory
|
||||
for (const hostConfig of getExternalHosts()) {
|
||||
expect(output).toContain(`FRESH: ${hostConfig.hostSubdir}/skills/`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1960,13 +2076,43 @@ describe('setup script validation', () => {
|
||||
expect(fnBody).toContain('gstack*');
|
||||
});
|
||||
|
||||
test('link_claude_skill_dirs creates relative symlinks', () => {
|
||||
// Claude links should be relative: ln -snf "gstack/$dir_name"
|
||||
// Uses dir_name (not skill_name) because symlink target must point to the physical directory
|
||||
test('link_claude_skill_dirs creates real directories with absolute SKILL.md symlinks', () => {
|
||||
// Claude links should be real directories with absolute SKILL.md symlinks
|
||||
// to ensure Claude Code discovers them as top-level skills (not nested under gstack/)
|
||||
const fnStart = setupContent.indexOf('link_claude_skill_dirs()');
|
||||
const fnEnd = setupContent.indexOf('}', setupContent.indexOf('linked[@]}', fnStart));
|
||||
const fnBody = setupContent.slice(fnStart, fnEnd);
|
||||
expect(fnBody).toContain('ln -snf "gstack/$dir_name"');
|
||||
expect(fnBody).toContain('mkdir -p "$target"');
|
||||
expect(fnBody).toContain('ln -snf "$gstack_dir/$dir_name/SKILL.md" "$target/SKILL.md"');
|
||||
});
|
||||
|
||||
// REGRESSION: cleanup functions must handle both old symlinks AND new real-directory pattern
|
||||
test('cleanup functions handle real directories with symlinked SKILL.md', () => {
|
||||
// cleanup_old_claude_symlinks must detect and remove real dirs with SKILL.md symlinks
|
||||
const cleanupOldStart = setupContent.indexOf('cleanup_old_claude_symlinks()');
|
||||
const cleanupOldEnd = setupContent.indexOf('}', setupContent.indexOf('cleaned up old', cleanupOldStart));
|
||||
const cleanupOldBody = setupContent.slice(cleanupOldStart, cleanupOldEnd);
|
||||
expect(cleanupOldBody).toContain('-d "$old_target"');
|
||||
expect(cleanupOldBody).toContain('-L "$old_target/SKILL.md"');
|
||||
expect(cleanupOldBody).toContain('rm -rf "$old_target"');
|
||||
|
||||
// cleanup_prefixed_claude_symlinks must also handle the new pattern
|
||||
const cleanupPrefixedStart = setupContent.indexOf('cleanup_prefixed_claude_symlinks()');
|
||||
const cleanupPrefixedEnd = setupContent.indexOf('}', setupContent.indexOf('cleaned up prefixed', cleanupPrefixedStart));
|
||||
const cleanupPrefixedBody = setupContent.slice(cleanupPrefixedStart, cleanupPrefixedEnd);
|
||||
expect(cleanupPrefixedBody).toContain('-d "$prefixed_target"');
|
||||
expect(cleanupPrefixedBody).toContain('-L "$prefixed_target/SKILL.md"');
|
||||
expect(cleanupPrefixedBody).toContain('rm -rf "$prefixed_target"');
|
||||
});
|
||||
|
||||
// REGRESSION: link function must upgrade old directory symlinks
|
||||
test('link_claude_skill_dirs removes old directory symlinks before creating real dirs', () => {
|
||||
const fnStart = setupContent.indexOf('link_claude_skill_dirs()');
|
||||
const fnEnd = setupContent.indexOf('}', setupContent.indexOf('linked[@]}', fnStart));
|
||||
const fnBody = setupContent.slice(fnStart, fnEnd);
|
||||
// Must check for and remove old symlinks before mkdir
|
||||
expect(fnBody).toContain('if [ -L "$target" ]');
|
||||
expect(fnBody).toContain('rm -f "$target"');
|
||||
});
|
||||
|
||||
test('setup supports --host auto|claude|codex|kiro', () => {
|
||||
@@ -2542,3 +2688,51 @@ describe('gen-skill-docs prefix warning (#620/#578)', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('voice-triggers processing', () => {
|
||||
const { extractVoiceTriggers, processVoiceTriggers } = require('../scripts/gen-skill-docs') as {
|
||||
extractVoiceTriggers: (content: string) => string[];
|
||||
processVoiceTriggers: (content: string) => string;
|
||||
};
|
||||
|
||||
test('extractVoiceTriggers parses valid YAML list', () => {
|
||||
const content = `---\nname: cso\ndescription: |\n Security audit.\nvoice-triggers:\n - "see-so"\n - "security review"\n---\nBody`;
|
||||
const triggers = extractVoiceTriggers(content);
|
||||
expect(triggers).toEqual(['see-so', 'security review']);
|
||||
});
|
||||
|
||||
test('extractVoiceTriggers returns [] when no field present', () => {
|
||||
const content = `---\nname: qa\ndescription: |\n QA testing.\n---\nBody`;
|
||||
expect(extractVoiceTriggers(content)).toEqual([]);
|
||||
});
|
||||
|
||||
test('processVoiceTriggers appends voice triggers to description', () => {
|
||||
const content = `---\nname: cso\ndescription: |\n Security audit. (gstack)\nvoice-triggers:\n - "see-so"\n - "security review"\n---\nBody`;
|
||||
const result = processVoiceTriggers(content);
|
||||
expect(result).toContain('Voice triggers (speech-to-text aliases): "see-so", "security review".');
|
||||
});
|
||||
|
||||
test('processVoiceTriggers strips voice-triggers field from output', () => {
|
||||
const content = `---\nname: cso\ndescription: |\n Security audit. (gstack)\nvoice-triggers:\n - "see-so"\n---\nBody`;
|
||||
const result = processVoiceTriggers(content);
|
||||
expect(result).not.toContain('voice-triggers:');
|
||||
});
|
||||
|
||||
test('processVoiceTriggers returns content unchanged when no voice-triggers', () => {
|
||||
const content = `---\nname: qa\ndescription: |\n QA testing.\n---\nBody`;
|
||||
expect(processVoiceTriggers(content)).toBe(content);
|
||||
});
|
||||
|
||||
test('generated CSO SKILL.md contains voice triggers in description', () => {
|
||||
const content = fs.readFileSync(path.join(ROOT, 'cso', 'SKILL.md'), 'utf-8');
|
||||
expect(content).toContain('"see-so"');
|
||||
expect(content).toContain('Voice triggers (speech-to-text aliases):');
|
||||
});
|
||||
|
||||
test('generated CSO SKILL.md does NOT contain raw voice-triggers field', () => {
|
||||
const content = fs.readFileSync(path.join(ROOT, 'cso', 'SKILL.md'), 'utf-8');
|
||||
const fmEnd = content.indexOf('\n---', 4);
|
||||
const frontmatter = content.slice(0, fmEnd);
|
||||
expect(frontmatter).not.toContain('voice-triggers:');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -131,6 +131,165 @@ describe("gstack-global-discover", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("codex large session_meta parsing", () => {
|
||||
let codexDir: string;
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = mkdtempSync(join(tmpdir(), "gstack-codex-test-"));
|
||||
// Build a realistic ~/.codex/sessions/YYYY/MM/DD structure
|
||||
const now = new Date();
|
||||
const y = now.getFullYear().toString();
|
||||
const m = String(now.getMonth() + 1).padStart(2, "0");
|
||||
const d = String(now.getDate()).padStart(2, "0");
|
||||
codexDir = join(tmpDir, "codex-home", "sessions", y, m, d);
|
||||
mkdirSync(codexDir, { recursive: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function writeCodexSession(
|
||||
dir: string,
|
||||
cwd: string,
|
||||
baseInstructionsSize: number
|
||||
): string {
|
||||
const padding = "x".repeat(baseInstructionsSize);
|
||||
const line = JSON.stringify({
|
||||
timestamp: new Date().toISOString(),
|
||||
type: "session_meta",
|
||||
payload: {
|
||||
id: `test-${Date.now()}`,
|
||||
timestamp: new Date().toISOString(),
|
||||
cwd,
|
||||
originator: "codex_exec",
|
||||
cli_version: "0.118.0",
|
||||
source: "exec",
|
||||
model_provider: "openai",
|
||||
base_instructions: { text: padding },
|
||||
},
|
||||
});
|
||||
const name = `rollout-${new Date().toISOString().replace(/[:.]/g, "-")}-${Math.random().toString(36).slice(2)}.jsonl`;
|
||||
const filePath = join(dir, name);
|
||||
writeFileSync(filePath, line + "\n");
|
||||
return filePath;
|
||||
}
|
||||
|
||||
test("discovers codex sessions with >4KB session_meta via CLI", () => {
|
||||
// Create a git repo as the session target
|
||||
const repoDir = join(tmpDir, "fake-repo");
|
||||
mkdirSync(repoDir);
|
||||
spawnSync("git", ["init"], { cwd: repoDir, stdio: "pipe" });
|
||||
spawnSync("git", ["commit", "--allow-empty", "-m", "init"], {
|
||||
cwd: repoDir,
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
// Write a session with a 20KB first line (simulates Codex v0.117+)
|
||||
writeCodexSession(codexDir, repoDir, 20000);
|
||||
|
||||
// Run discovery with CODEX_SESSIONS_DIR override
|
||||
const result = spawnSync(
|
||||
"bun",
|
||||
["run", scriptPath, "--since", "1h", "--format", "json"],
|
||||
{
|
||||
encoding: "utf-8",
|
||||
timeout: 30000,
|
||||
env: {
|
||||
...process.env,
|
||||
CODEX_SESSIONS_DIR: join(tmpDir, "codex-home", "sessions"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(result.status).toBe(0);
|
||||
const json = JSON.parse(result.stdout);
|
||||
expect(json.tools.codex.total_sessions).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
test("4KB buffer truncates session_meta, 128KB buffer parses it", () => {
|
||||
const padding = "x".repeat(20000);
|
||||
const sessionMeta = JSON.stringify({
|
||||
timestamp: new Date().toISOString(),
|
||||
type: "session_meta",
|
||||
payload: {
|
||||
id: "test-id",
|
||||
timestamp: new Date().toISOString(),
|
||||
cwd: "/tmp/test-repo",
|
||||
originator: "codex_exec",
|
||||
cli_version: "0.118.0",
|
||||
source: "exec",
|
||||
model_provider: "openai",
|
||||
base_instructions: { text: padding },
|
||||
},
|
||||
});
|
||||
|
||||
expect(sessionMeta.length).toBeGreaterThan(4096);
|
||||
|
||||
const filePath = join(codexDir, "test.jsonl");
|
||||
writeFileSync(filePath, sessionMeta + "\n");
|
||||
|
||||
// 4KB buffer: JSON.parse fails (the old bug)
|
||||
const { openSync, readSync, closeSync } = require("fs");
|
||||
const fd4k = openSync(filePath, "r");
|
||||
const buf4k = Buffer.alloc(4096);
|
||||
readSync(fd4k, buf4k, 0, 4096, 0);
|
||||
closeSync(fd4k);
|
||||
expect(() =>
|
||||
JSON.parse(buf4k.toString("utf-8").split("\n")[0])
|
||||
).toThrow();
|
||||
|
||||
// 128KB buffer: JSON.parse succeeds (the fix)
|
||||
const fd128k = openSync(filePath, "r");
|
||||
const buf128k = Buffer.alloc(131072);
|
||||
const bytesRead = readSync(fd128k, buf128k, 0, 131072, 0);
|
||||
closeSync(fd128k);
|
||||
const firstLine = buf128k.toString("utf-8", 0, bytesRead).split("\n")[0];
|
||||
const meta = JSON.parse(firstLine);
|
||||
expect(meta.type).toBe("session_meta");
|
||||
expect(meta.payload.cwd).toBe("/tmp/test-repo");
|
||||
});
|
||||
|
||||
test("regression: session_meta beyond 128KB still needs streaming parse", () => {
|
||||
// This test documents the current limitation: 128KB buffer is a heuristic.
|
||||
// If Codex ever embeds >128KB in session_meta, this test will fail,
|
||||
// signaling that the buffer needs to increase or be replaced with streaming.
|
||||
const padding = "x".repeat(140000); // ~140KB payload
|
||||
const sessionMeta = JSON.stringify({
|
||||
timestamp: new Date().toISOString(),
|
||||
type: "session_meta",
|
||||
payload: {
|
||||
id: "test-large",
|
||||
timestamp: new Date().toISOString(),
|
||||
cwd: "/tmp/large-test",
|
||||
originator: "codex_exec",
|
||||
cli_version: "0.200.0",
|
||||
source: "exec",
|
||||
model_provider: "openai",
|
||||
base_instructions: { text: padding },
|
||||
},
|
||||
});
|
||||
|
||||
expect(sessionMeta.length).toBeGreaterThan(131072);
|
||||
|
||||
const filePath = join(codexDir, "large-test.jsonl");
|
||||
writeFileSync(filePath, sessionMeta + "\n");
|
||||
|
||||
// 128KB buffer: JSON.parse FAILS for >128KB lines (current limitation)
|
||||
const { openSync, readSync, closeSync } = require("fs");
|
||||
const fd = openSync(filePath, "r");
|
||||
const buf = Buffer.alloc(131072);
|
||||
readSync(fd, buf, 0, 131072, 0);
|
||||
closeSync(fd);
|
||||
expect(() =>
|
||||
JSON.parse(buf.toString("utf-8").split("\n")[0])
|
||||
).toThrow();
|
||||
// When this test starts passing (e.g., after implementing streaming parse),
|
||||
// update it to verify correct parsing instead of documenting the limitation.
|
||||
});
|
||||
});
|
||||
|
||||
describe("discovery output structure", () => {
|
||||
test("repos have required fields", () => {
|
||||
const result = spawnSync(
|
||||
|
||||
@@ -309,12 +309,13 @@ export async function runSkillTest(options: {
|
||||
|
||||
// Use resultLine for structured result data
|
||||
if (resultLine) {
|
||||
if (resultLine.is_error) {
|
||||
if (resultLine.subtype === 'success' && resultLine.is_error) {
|
||||
// claude -p can return subtype=success with is_error=true (e.g. API connection failure)
|
||||
exitReason = 'error_api';
|
||||
} else if (resultLine.subtype === 'success') {
|
||||
exitReason = 'success';
|
||||
} else if (resultLine.subtype) {
|
||||
// Preserve known subtypes like error_max_turns even if is_error is set
|
||||
exitReason = resultLine.subtype;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ import { parseSnapshotArgs } from '../../browse/src/snapshot';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
/** CLI-only commands: valid $B invocations that are handled by the CLI, not the server */
|
||||
const CLI_COMMANDS = new Set([
|
||||
'status', 'pair-agent', 'tunnel',
|
||||
]);
|
||||
|
||||
export interface BrowseCommand {
|
||||
command: string;
|
||||
args: string[];
|
||||
@@ -112,7 +117,7 @@ export function validateSkill(skillPath: string): ValidationResult {
|
||||
}
|
||||
|
||||
for (const cmd of commands) {
|
||||
if (!ALL_COMMANDS.has(cmd.command)) {
|
||||
if (!ALL_COMMANDS.has(cmd.command) && !CLI_COMMANDS.has(cmd.command)) {
|
||||
result.invalid.push(cmd);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ export const E2E_TOUCHFILES: Record<string, string[]> = {
|
||||
'skillmd-no-local-binary': ['SKILL.md', 'SKILL.md.tmpl', 'scripts/gen-skill-docs.ts'],
|
||||
'skillmd-outside-git': ['SKILL.md', 'SKILL.md.tmpl', 'scripts/gen-skill-docs.ts'],
|
||||
|
||||
'contributor-mode': ['SKILL.md.tmpl', 'scripts/gen-skill-docs.ts'],
|
||||
'session-awareness': ['SKILL.md', 'SKILL.md.tmpl', 'scripts/gen-skill-docs.ts'],
|
||||
'operational-learning': ['scripts/resolvers/preamble.ts', 'bin/gstack-learnings-log'],
|
||||
|
||||
// QA (+ test-server dependency)
|
||||
'qa-quick': ['qa/**', 'browse/src/**', 'browse/test/test-server.ts'],
|
||||
@@ -107,6 +107,11 @@ export const E2E_TOUCHFILES: Record<string, string[]> = {
|
||||
// Learnings
|
||||
'learnings-show': ['learn/**', 'bin/gstack-learnings-search', 'bin/gstack-learnings-log', 'scripts/resolvers/learnings.ts'],
|
||||
|
||||
// Session Intelligence (timeline, context recovery, checkpoint)
|
||||
'timeline-event-flow': ['bin/gstack-timeline-log', 'bin/gstack-timeline-read'],
|
||||
'context-recovery-artifacts': ['scripts/resolvers/preamble.ts', 'bin/gstack-timeline-log', 'bin/gstack-slug', 'learn/**'],
|
||||
'checkpoint-save-resume': ['checkpoint/**', 'bin/gstack-slug'],
|
||||
|
||||
// Document-release
|
||||
'document-release': ['document-release/**'],
|
||||
|
||||
@@ -193,8 +198,8 @@ export const E2E_TIERS: Record<string, 'gate' | 'periodic'> = {
|
||||
'skillmd-setup-discovery': 'gate',
|
||||
'skillmd-no-local-binary': 'gate',
|
||||
'skillmd-outside-git': 'gate',
|
||||
'contributor-mode': 'gate',
|
||||
'session-awareness': 'gate',
|
||||
'operational-learning': 'gate',
|
||||
|
||||
// QA — gate for functional, periodic for quality/benchmarks
|
||||
'qa-quick': 'gate',
|
||||
@@ -241,6 +246,11 @@ export const E2E_TIERS: Record<string, 'gate' | 'periodic'> = {
|
||||
'codex-offered-design-review': 'gate',
|
||||
'codex-offered-eng-review': 'gate',
|
||||
|
||||
// Session Intelligence — gate for data flow, periodic for agent integration
|
||||
'timeline-event-flow': 'gate', // Binary data flow (no LLM needed)
|
||||
'context-recovery-artifacts': 'gate', // Preamble reads seeded artifacts
|
||||
'checkpoint-save-resume': 'gate', // Checkpoint round-trip
|
||||
|
||||
// Ship — gate (end-to-end ship path)
|
||||
'ship-base-branch': 'gate',
|
||||
'ship-local-workflow': 'gate',
|
||||
|
||||
@@ -0,0 +1,524 @@
|
||||
/**
|
||||
* Host config system tests — 100% coverage of host-config.ts, hosts/index.ts,
|
||||
* host-config-export.ts, and golden-file regression checks.
|
||||
*/
|
||||
|
||||
import { describe, test, expect } from 'bun:test';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { validateHostConfig, validateAllConfigs, type HostConfig } from '../scripts/host-config';
|
||||
import {
|
||||
ALL_HOST_CONFIGS,
|
||||
ALL_HOST_NAMES,
|
||||
HOST_CONFIG_MAP,
|
||||
getHostConfig,
|
||||
resolveHostArg,
|
||||
getExternalHosts,
|
||||
claude,
|
||||
codex,
|
||||
factory,
|
||||
kiro,
|
||||
opencode,
|
||||
slate,
|
||||
cursor,
|
||||
openclaw,
|
||||
} from '../hosts/index';
|
||||
import { HOST_PATHS } from '../scripts/resolvers/types';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
|
||||
// ─── hosts/index.ts ─────────────────────────────────────────
|
||||
|
||||
describe('hosts/index.ts', () => {
|
||||
test('ALL_HOST_CONFIGS has 8 hosts', () => {
|
||||
expect(ALL_HOST_CONFIGS.length).toBe(8);
|
||||
});
|
||||
|
||||
test('ALL_HOST_NAMES matches config names', () => {
|
||||
expect(ALL_HOST_NAMES).toEqual(ALL_HOST_CONFIGS.map(c => c.name));
|
||||
});
|
||||
|
||||
test('HOST_CONFIG_MAP keys match names', () => {
|
||||
for (const config of ALL_HOST_CONFIGS) {
|
||||
expect(HOST_CONFIG_MAP[config.name]).toBe(config);
|
||||
}
|
||||
});
|
||||
|
||||
test('individual config re-exports match registry', () => {
|
||||
expect(claude.name).toBe('claude');
|
||||
expect(codex.name).toBe('codex');
|
||||
expect(factory.name).toBe('factory');
|
||||
expect(kiro.name).toBe('kiro');
|
||||
expect(opencode.name).toBe('opencode');
|
||||
expect(slate.name).toBe('slate');
|
||||
expect(cursor.name).toBe('cursor');
|
||||
expect(openclaw.name).toBe('openclaw');
|
||||
});
|
||||
|
||||
test('getHostConfig returns correct config', () => {
|
||||
const c = getHostConfig('codex');
|
||||
expect(c.name).toBe('codex');
|
||||
expect(c.displayName).toBe('OpenAI Codex CLI');
|
||||
});
|
||||
|
||||
test('getHostConfig throws on unknown host', () => {
|
||||
expect(() => getHostConfig('nonexistent')).toThrow('Unknown host');
|
||||
});
|
||||
|
||||
test('resolveHostArg resolves direct names', () => {
|
||||
for (const name of ALL_HOST_NAMES) {
|
||||
expect(resolveHostArg(name)).toBe(name);
|
||||
}
|
||||
});
|
||||
|
||||
test('resolveHostArg resolves aliases', () => {
|
||||
expect(resolveHostArg('agents')).toBe('codex');
|
||||
expect(resolveHostArg('droid')).toBe('factory');
|
||||
});
|
||||
|
||||
test('resolveHostArg throws on unknown alias', () => {
|
||||
expect(() => resolveHostArg('nonexistent')).toThrow('Unknown host');
|
||||
});
|
||||
|
||||
test('getExternalHosts excludes claude', () => {
|
||||
const external = getExternalHosts();
|
||||
expect(external.find(c => c.name === 'claude')).toBeUndefined();
|
||||
expect(external.length).toBe(ALL_HOST_CONFIGS.length - 1);
|
||||
});
|
||||
|
||||
test('every host has a unique name', () => {
|
||||
const names = new Set(ALL_HOST_NAMES);
|
||||
expect(names.size).toBe(ALL_HOST_NAMES.length);
|
||||
});
|
||||
|
||||
test('every host has a unique hostSubdir', () => {
|
||||
const subdirs = new Set(ALL_HOST_CONFIGS.map(c => c.hostSubdir));
|
||||
expect(subdirs.size).toBe(ALL_HOST_CONFIGS.length);
|
||||
});
|
||||
|
||||
test('every host has a unique globalRoot', () => {
|
||||
const roots = new Set(ALL_HOST_CONFIGS.map(c => c.globalRoot));
|
||||
expect(roots.size).toBe(ALL_HOST_CONFIGS.length);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── validateHostConfig ─────────────────────────────────────
|
||||
|
||||
describe('validateHostConfig', () => {
|
||||
function makeValid(): HostConfig {
|
||||
return {
|
||||
name: 'test-host',
|
||||
displayName: 'Test Host',
|
||||
cliCommand: 'testcli',
|
||||
globalRoot: '.test/skills/gstack',
|
||||
localSkillRoot: '.test/skills/gstack',
|
||||
hostSubdir: '.test',
|
||||
usesEnvVars: true,
|
||||
frontmatter: { mode: 'allowlist', keepFields: ['name', 'description'] },
|
||||
generation: { generateMetadata: false },
|
||||
pathRewrites: [],
|
||||
runtimeRoot: { globalSymlinks: ['bin'] },
|
||||
install: { prefixable: false, linkingStrategy: 'symlink-generated' },
|
||||
};
|
||||
}
|
||||
|
||||
test('valid config passes', () => {
|
||||
expect(validateHostConfig(makeValid())).toEqual([]);
|
||||
});
|
||||
|
||||
test('invalid name is caught', () => {
|
||||
const c = makeValid();
|
||||
c.name = 'UPPER_CASE';
|
||||
const errors = validateHostConfig(c);
|
||||
expect(errors.some(e => e.includes('name'))).toBe(true);
|
||||
});
|
||||
|
||||
test('name with special chars is caught', () => {
|
||||
const c = makeValid();
|
||||
c.name = 'has spaces';
|
||||
expect(validateHostConfig(c).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('empty displayName is caught', () => {
|
||||
const c = makeValid();
|
||||
c.displayName = '';
|
||||
expect(validateHostConfig(c).some(e => e.includes('displayName'))).toBe(true);
|
||||
});
|
||||
|
||||
test('invalid cliCommand is caught', () => {
|
||||
const c = makeValid();
|
||||
c.cliCommand = 'has spaces';
|
||||
expect(validateHostConfig(c).some(e => e.includes('cliCommand'))).toBe(true);
|
||||
});
|
||||
|
||||
test('invalid cliAlias is caught', () => {
|
||||
const c = makeValid();
|
||||
c.cliAliases = ['good', 'BAD!'];
|
||||
expect(validateHostConfig(c).some(e => e.includes('cliAlias'))).toBe(true);
|
||||
});
|
||||
|
||||
test('valid cliAliases pass', () => {
|
||||
const c = makeValid();
|
||||
c.cliAliases = ['alias-one', 'alias-two'];
|
||||
expect(validateHostConfig(c)).toEqual([]);
|
||||
});
|
||||
|
||||
test('invalid globalRoot is caught', () => {
|
||||
const c = makeValid();
|
||||
c.globalRoot = 'path with spaces';
|
||||
expect(validateHostConfig(c).some(e => e.includes('globalRoot'))).toBe(true);
|
||||
});
|
||||
|
||||
test('invalid localSkillRoot is caught', () => {
|
||||
const c = makeValid();
|
||||
c.localSkillRoot = 'invalid<path>';
|
||||
expect(validateHostConfig(c).some(e => e.includes('localSkillRoot'))).toBe(true);
|
||||
});
|
||||
|
||||
test('invalid hostSubdir is caught', () => {
|
||||
const c = makeValid();
|
||||
c.hostSubdir = 'no spaces allowed';
|
||||
expect(validateHostConfig(c).some(e => e.includes('hostSubdir'))).toBe(true);
|
||||
});
|
||||
|
||||
test('invalid frontmatter.mode is caught', () => {
|
||||
const c = makeValid();
|
||||
(c.frontmatter as any).mode = 'invalid';
|
||||
expect(validateHostConfig(c).some(e => e.includes('frontmatter.mode'))).toBe(true);
|
||||
});
|
||||
|
||||
test('invalid linkingStrategy is caught', () => {
|
||||
const c = makeValid();
|
||||
(c.install as any).linkingStrategy = 'invalid';
|
||||
expect(validateHostConfig(c).some(e => e.includes('linkingStrategy'))).toBe(true);
|
||||
});
|
||||
|
||||
test('paths with $ and ~ are valid', () => {
|
||||
const c = makeValid();
|
||||
c.globalRoot = '$HOME/.test/skills/gstack';
|
||||
c.localSkillRoot = '~/.test/skills/gstack';
|
||||
expect(validateHostConfig(c)).toEqual([]);
|
||||
});
|
||||
|
||||
test('shell injection attempt in cliCommand is caught', () => {
|
||||
const c = makeValid();
|
||||
c.cliCommand = 'opencode;rm -rf /';
|
||||
expect(validateHostConfig(c).some(e => e.includes('cliCommand'))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── validateAllConfigs ─────────────────────────────────────
|
||||
|
||||
describe('validateAllConfigs', () => {
|
||||
test('real configs all pass validation', () => {
|
||||
const errors = validateAllConfigs(ALL_HOST_CONFIGS);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
|
||||
test('duplicate name detected', () => {
|
||||
const dup = { ...codex, name: 'claude' } as HostConfig;
|
||||
const errors = validateAllConfigs([claude, dup]);
|
||||
expect(errors.some(e => e.includes('Duplicate name'))).toBe(true);
|
||||
});
|
||||
|
||||
test('duplicate hostSubdir detected', () => {
|
||||
const dup = { ...codex, name: 'dup-host', hostSubdir: '.claude', globalRoot: '.dup/skills/gstack' } as HostConfig;
|
||||
const errors = validateAllConfigs([claude, dup]);
|
||||
expect(errors.some(e => e.includes('Duplicate hostSubdir'))).toBe(true);
|
||||
});
|
||||
|
||||
test('duplicate globalRoot detected', () => {
|
||||
const dup = { ...codex, name: 'dup-host', hostSubdir: '.dup', globalRoot: '.claude/skills/gstack' } as HostConfig;
|
||||
const errors = validateAllConfigs([claude, dup]);
|
||||
expect(errors.some(e => e.includes('Duplicate globalRoot'))).toBe(true);
|
||||
});
|
||||
|
||||
test('per-config validation errors are prefixed with host name', () => {
|
||||
const bad = { ...codex, name: 'BAD', cliCommand: 'also bad' } as HostConfig;
|
||||
const errors = validateAllConfigs([bad]);
|
||||
expect(errors.every(e => e.startsWith('[BAD]'))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── HOST_PATHS derivation ──────────────────────────────────
|
||||
|
||||
describe('HOST_PATHS derivation from configs', () => {
|
||||
test('Claude uses literal home paths (no env vars)', () => {
|
||||
expect(HOST_PATHS.claude.skillRoot).toBe('~/.claude/skills/gstack');
|
||||
expect(HOST_PATHS.claude.binDir).toBe('~/.claude/skills/gstack/bin');
|
||||
expect(HOST_PATHS.claude.browseDir).toBe('~/.claude/skills/gstack/browse/dist');
|
||||
expect(HOST_PATHS.claude.designDir).toBe('~/.claude/skills/gstack/design/dist');
|
||||
});
|
||||
|
||||
test('Codex uses $GSTACK_ROOT env vars', () => {
|
||||
expect(HOST_PATHS.codex.skillRoot).toBe('$GSTACK_ROOT');
|
||||
expect(HOST_PATHS.codex.binDir).toBe('$GSTACK_BIN');
|
||||
expect(HOST_PATHS.codex.browseDir).toBe('$GSTACK_BROWSE');
|
||||
expect(HOST_PATHS.codex.designDir).toBe('$GSTACK_DESIGN');
|
||||
});
|
||||
|
||||
test('every host with usesEnvVars=true gets env var paths', () => {
|
||||
for (const config of ALL_HOST_CONFIGS) {
|
||||
if (config.usesEnvVars) {
|
||||
expect(HOST_PATHS[config.name].skillRoot).toBe('$GSTACK_ROOT');
|
||||
expect(HOST_PATHS[config.name].binDir).toBe('$GSTACK_BIN');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('every host with usesEnvVars=false gets literal paths', () => {
|
||||
for (const config of ALL_HOST_CONFIGS) {
|
||||
if (!config.usesEnvVars) {
|
||||
expect(HOST_PATHS[config.name].skillRoot).toContain('~/');
|
||||
expect(HOST_PATHS[config.name].binDir).toContain('/bin');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('localSkillRoot matches config for every host', () => {
|
||||
for (const config of ALL_HOST_CONFIGS) {
|
||||
expect(HOST_PATHS[config.name].localSkillRoot).toBe(config.localSkillRoot);
|
||||
}
|
||||
});
|
||||
|
||||
test('HOST_PATHS has entry for every registered host', () => {
|
||||
for (const name of ALL_HOST_NAMES) {
|
||||
expect(HOST_PATHS[name]).toBeDefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ─── host-config-export.ts CLI ──────────────────────────────
|
||||
|
||||
describe('host-config-export.ts CLI', () => {
|
||||
const EXPORT_SCRIPT = path.join(ROOT, 'scripts', 'host-config-export.ts');
|
||||
|
||||
function run(...args: string[]): { stdout: string; stderr: string; exitCode: number } {
|
||||
const result = Bun.spawnSync(['bun', 'run', EXPORT_SCRIPT, ...args], {
|
||||
cwd: ROOT, stdout: 'pipe', stderr: 'pipe',
|
||||
});
|
||||
return {
|
||||
stdout: result.stdout.toString().trim(),
|
||||
stderr: result.stderr.toString().trim(),
|
||||
exitCode: result.exitCode,
|
||||
};
|
||||
}
|
||||
|
||||
test('list prints all host names', () => {
|
||||
const { stdout, exitCode } = run('list');
|
||||
expect(exitCode).toBe(0);
|
||||
const names = stdout.split('\n');
|
||||
expect(names).toEqual(ALL_HOST_NAMES);
|
||||
});
|
||||
|
||||
test('get returns string field', () => {
|
||||
const { stdout, exitCode } = run('get', 'codex', 'globalRoot');
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe('.codex/skills/gstack');
|
||||
});
|
||||
|
||||
test('get returns boolean as 1/0', () => {
|
||||
const { stdout: t } = run('get', 'claude', 'usesEnvVars');
|
||||
expect(t).toBe('0');
|
||||
const { stdout: f } = run('get', 'codex', 'usesEnvVars');
|
||||
expect(f).toBe('1');
|
||||
});
|
||||
|
||||
test('get with missing args exits 1', () => {
|
||||
const { exitCode } = run('get', 'codex');
|
||||
expect(exitCode).toBe(1);
|
||||
});
|
||||
|
||||
test('get with unknown field exits 1', () => {
|
||||
const { exitCode } = run('get', 'codex', 'nonexistent');
|
||||
expect(exitCode).toBe(1);
|
||||
});
|
||||
|
||||
test('get with unknown host exits 1', () => {
|
||||
const { exitCode } = run('get', 'nonexistent', 'name');
|
||||
expect(exitCode).not.toBe(0);
|
||||
});
|
||||
|
||||
test('validate passes for real configs', () => {
|
||||
const { stdout, exitCode } = run('validate');
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toContain('configs valid');
|
||||
});
|
||||
|
||||
test('symlinks returns asset list', () => {
|
||||
const { stdout, exitCode } = run('symlinks', 'codex');
|
||||
expect(exitCode).toBe(0);
|
||||
const lines = stdout.split('\n');
|
||||
expect(lines).toContain('bin');
|
||||
expect(lines).toContain('ETHOS.md');
|
||||
expect(lines).toContain('review/checklist.md');
|
||||
});
|
||||
|
||||
test('symlinks with missing host exits 1', () => {
|
||||
const { exitCode } = run('symlinks');
|
||||
expect(exitCode).toBe(1);
|
||||
});
|
||||
|
||||
test('detect finds claude (since we are running in claude)', () => {
|
||||
const { stdout, exitCode } = run('detect');
|
||||
expect(exitCode).toBe(0);
|
||||
// claude binary should be on PATH in this environment
|
||||
expect(stdout).toContain('claude');
|
||||
});
|
||||
|
||||
test('unknown command exits 1', () => {
|
||||
const { exitCode } = run('badcommand');
|
||||
expect(exitCode).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Golden-file regression ─────────────────────────────────
|
||||
|
||||
describe('golden-file regression', () => {
|
||||
const GOLDEN_DIR = path.join(ROOT, 'test', 'fixtures', 'golden');
|
||||
|
||||
test('Claude ship skill matches golden baseline', () => {
|
||||
const golden = fs.readFileSync(path.join(GOLDEN_DIR, 'claude-ship-SKILL.md'), 'utf-8');
|
||||
const current = fs.readFileSync(path.join(ROOT, 'ship', 'SKILL.md'), 'utf-8');
|
||||
expect(current).toBe(golden);
|
||||
});
|
||||
|
||||
test('Codex ship skill matches golden baseline', () => {
|
||||
const golden = fs.readFileSync(path.join(GOLDEN_DIR, 'codex-ship-SKILL.md'), 'utf-8');
|
||||
const current = fs.readFileSync(path.join(ROOT, '.agents', 'skills', 'gstack-ship', 'SKILL.md'), 'utf-8');
|
||||
expect(current).toBe(golden);
|
||||
});
|
||||
|
||||
test('Factory ship skill matches golden baseline', () => {
|
||||
const golden = fs.readFileSync(path.join(GOLDEN_DIR, 'factory-ship-SKILL.md'), 'utf-8');
|
||||
const current = fs.readFileSync(path.join(ROOT, '.factory', 'skills', 'gstack-ship', 'SKILL.md'), 'utf-8');
|
||||
expect(current).toBe(golden);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Individual host config correctness ─────────────────────
|
||||
|
||||
describe('host config correctness', () => {
|
||||
test('claude is the only prefixable host', () => {
|
||||
for (const config of ALL_HOST_CONFIGS) {
|
||||
if (config.name === 'claude') {
|
||||
expect(config.install.prefixable).toBe(true);
|
||||
} else {
|
||||
expect(config.install.prefixable).toBe(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('claude is the only host with real-dir-symlink strategy', () => {
|
||||
for (const config of ALL_HOST_CONFIGS) {
|
||||
if (config.name === 'claude') {
|
||||
expect(config.install.linkingStrategy).toBe('real-dir-symlink');
|
||||
} else {
|
||||
expect(config.install.linkingStrategy).toBe('symlink-generated');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('claude does not use env vars', () => {
|
||||
expect(claude.usesEnvVars).toBe(false);
|
||||
});
|
||||
|
||||
test('all external hosts use env vars', () => {
|
||||
for (const config of getExternalHosts()) {
|
||||
expect(config.usesEnvVars).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
test('codex has 1024-char description limit with error behavior', () => {
|
||||
expect(codex.frontmatter.descriptionLimit).toBe(1024);
|
||||
expect(codex.frontmatter.descriptionLimitBehavior).toBe('error');
|
||||
});
|
||||
|
||||
test('codex generates openai.yaml metadata', () => {
|
||||
expect(codex.generation.generateMetadata).toBe(true);
|
||||
expect(codex.generation.metadataFormat).toBe('openai.yaml');
|
||||
});
|
||||
|
||||
test('codex has sidecar config', () => {
|
||||
expect(codex.sidecar).toBeDefined();
|
||||
expect(codex.sidecar!.path).toBe('.agents/skills/gstack');
|
||||
});
|
||||
|
||||
test('factory has tool rewrites', () => {
|
||||
expect(factory.toolRewrites).toBeDefined();
|
||||
expect(Object.keys(factory.toolRewrites!).length).toBeGreaterThan(0);
|
||||
expect(factory.toolRewrites!['use the Bash tool']).toBe('run this command');
|
||||
});
|
||||
|
||||
test('factory has conditional disable-model-invocation field', () => {
|
||||
expect(factory.frontmatter.conditionalFields).toBeDefined();
|
||||
expect(factory.frontmatter.conditionalFields!.length).toBe(1);
|
||||
expect(factory.frontmatter.conditionalFields![0].if).toEqual({ sensitive: true });
|
||||
expect(factory.frontmatter.conditionalFields![0].add).toEqual({ 'disable-model-invocation': true });
|
||||
});
|
||||
|
||||
test('codex has suppressedResolvers for self-invocation prevention', () => {
|
||||
expect(codex.suppressedResolvers).toBeDefined();
|
||||
expect(codex.suppressedResolvers).toContain('CODEX_SECOND_OPINION');
|
||||
expect(codex.suppressedResolvers).toContain('ADVERSARIAL_STEP');
|
||||
expect(codex.suppressedResolvers).toContain('REVIEW_ARMY');
|
||||
});
|
||||
|
||||
test('codex has boundary instruction', () => {
|
||||
expect(codex.boundaryInstruction).toBeDefined();
|
||||
expect(codex.boundaryInstruction).toContain('Do NOT read');
|
||||
});
|
||||
|
||||
test('openclaw has tool rewrites for exec/read/write', () => {
|
||||
expect(openclaw.toolRewrites).toBeDefined();
|
||||
expect(openclaw.toolRewrites!['use the Bash tool']).toBe('use the exec tool');
|
||||
expect(openclaw.toolRewrites!['use the Read tool']).toBe('use the read tool');
|
||||
});
|
||||
|
||||
test('openclaw has CLAUDE.md→AGENTS.md path rewrite', () => {
|
||||
expect(openclaw.pathRewrites.some(r => r.from === 'CLAUDE.md' && r.to === 'AGENTS.md')).toBe(true);
|
||||
});
|
||||
|
||||
test('openclaw has adapter path', () => {
|
||||
expect(openclaw.adapter).toBeDefined();
|
||||
expect(openclaw.adapter).toContain('openclaw-adapter');
|
||||
});
|
||||
|
||||
test('openclaw has no staticFiles (SOUL.md removed)', () => {
|
||||
expect(openclaw.staticFiles).toBeUndefined();
|
||||
});
|
||||
|
||||
test('openclaw includeSkills is empty (native skills replaced generated ones)', () => {
|
||||
expect(openclaw.generation.includeSkills).toBeDefined();
|
||||
expect(openclaw.generation.includeSkills!.length).toBe(0);
|
||||
});
|
||||
|
||||
test('every host has coAuthorTrailer or undefined', () => {
|
||||
// Claude, Codex, Factory, OpenClaw have explicit trailers
|
||||
expect(claude.coAuthorTrailer).toContain('Claude');
|
||||
expect(codex.coAuthorTrailer).toContain('Codex');
|
||||
expect(factory.coAuthorTrailer).toContain('Factory');
|
||||
expect(openclaw.coAuthorTrailer).toContain('OpenClaw');
|
||||
});
|
||||
|
||||
test('every external host skips the codex skill', () => {
|
||||
for (const config of getExternalHosts()) {
|
||||
expect(config.generation.skipSkills).toContain('codex');
|
||||
}
|
||||
});
|
||||
|
||||
test('every host has at least one pathRewrite (except claude)', () => {
|
||||
for (const config of getExternalHosts()) {
|
||||
expect(config.pathRewrites.length).toBeGreaterThan(0);
|
||||
}
|
||||
expect(claude.pathRewrites.length).toBe(0);
|
||||
});
|
||||
|
||||
test('every host has runtimeRoot.globalSymlinks', () => {
|
||||
for (const config of ALL_HOST_CONFIGS) {
|
||||
expect(config.runtimeRoot.globalSymlinks.length).toBeGreaterThan(0);
|
||||
expect(config.runtimeRoot.globalSymlinks).toContain('bin');
|
||||
expect(config.runtimeRoot.globalSymlinks).toContain('ETHOS.md');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
import { describe, test, expect } from "bun:test";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
const SCRIPT = path.join(import.meta.dir, "..", "bin", "gstack-learnings-search");
|
||||
|
||||
describe("gstack-learnings-search injection prevention", () => {
|
||||
const script = readFileSync(SCRIPT, "utf-8");
|
||||
|
||||
test("no shell interpolation inside bun -e string", () => {
|
||||
// Extract the bun -e block (everything between `bun -e "` and the closing `"`)
|
||||
const bunBlock = script.slice(script.indexOf('bun -e "'));
|
||||
|
||||
// Should NOT contain ${VAR} patterns (shell interpolation)
|
||||
// These are RCE vectors: a malicious learnings entry with '; rm -rf / ;' in the
|
||||
// query field would execute arbitrary commands via shell interpolation.
|
||||
const shellInterpolations = bunBlock.match(/'\$\{[A-Z_]+\}'/g) || [];
|
||||
const bareInterpolations = bunBlock.match(/\$\{[A-Z_]+\}/g) || [];
|
||||
|
||||
// Filter out any that are inside process.env references (those are safe)
|
||||
const unsafeInterpolations = [
|
||||
...shellInterpolations,
|
||||
...bareInterpolations,
|
||||
].filter((m) => !m.includes("process.env"));
|
||||
|
||||
expect(unsafeInterpolations).toEqual([]);
|
||||
});
|
||||
|
||||
test("uses process.env for all user-controlled values", () => {
|
||||
const bunBlock = script.slice(script.indexOf('bun -e "'));
|
||||
|
||||
// Must use process.env for TYPE, QUERY, LIMIT, SLUG, CROSS_PROJECT
|
||||
expect(bunBlock).toContain("process.env.GSTACK_SEARCH_TYPE");
|
||||
expect(bunBlock).toContain("process.env.GSTACK_SEARCH_QUERY");
|
||||
expect(bunBlock).toContain("process.env.GSTACK_SEARCH_LIMIT");
|
||||
expect(bunBlock).toContain("process.env.GSTACK_SEARCH_SLUG");
|
||||
expect(bunBlock).toContain("process.env.GSTACK_SEARCH_CROSS");
|
||||
});
|
||||
|
||||
test("env vars are set on the bun command line", () => {
|
||||
// The env vars must be passed to bun, not just set in the shell
|
||||
expect(script).toContain("GSTACK_SEARCH_TYPE=");
|
||||
expect(script).toContain("GSTACK_SEARCH_QUERY=");
|
||||
expect(script).toContain("GSTACK_SEARCH_LIMIT=");
|
||||
expect(script).toContain("GSTACK_SEARCH_SLUG=");
|
||||
expect(script).toContain("GSTACK_SEARCH_CROSS=");
|
||||
});
|
||||
});
|
||||
+297
-11
@@ -69,8 +69,11 @@ describe('gstack-relink (#578)', () => {
|
||||
// Test 11: prefixed symlinks when skill_prefix=true
|
||||
test('creates gstack-* symlinks when skill_prefix=true', () => {
|
||||
setupMockInstall(['qa', 'ship', 'review']);
|
||||
// Set config to prefix mode
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`);
|
||||
// Set config to prefix mode (pass install/skills env so auto-relink uses mock install)
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
// Run relink with env pointing to the mock install
|
||||
const output = run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
@@ -86,7 +89,10 @@ describe('gstack-relink (#578)', () => {
|
||||
// Test 12: flat symlinks when skill_prefix=false
|
||||
test('creates flat symlinks when skill_prefix=false', () => {
|
||||
setupMockInstall(['qa', 'ship', 'review']);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
const output = run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
@@ -97,11 +103,208 @@ describe('gstack-relink (#578)', () => {
|
||||
expect(output).toContain('flat');
|
||||
});
|
||||
|
||||
// REGRESSION: unprefixed skills must be real directories, not symlinks (#761)
|
||||
// Claude Code auto-prefixes skills nested under a parent dir symlink.
|
||||
// e.g., `qa -> gstack/qa` gets discovered as "gstack-qa", not "qa".
|
||||
// The fix: create real directories with SKILL.md symlinks inside.
|
||||
test('unprefixed skills are real directories with SKILL.md symlinks, not dir symlinks', () => {
|
||||
setupMockInstall(['qa', 'ship', 'review', 'plan-ceo-review']);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
for (const skill of ['qa', 'ship', 'review', 'plan-ceo-review']) {
|
||||
const skillPath = path.join(skillsDir, skill);
|
||||
const skillMdPath = path.join(skillPath, 'SKILL.md');
|
||||
// Must be a real directory, NOT a symlink
|
||||
expect(fs.lstatSync(skillPath).isDirectory()).toBe(true);
|
||||
expect(fs.lstatSync(skillPath).isSymbolicLink()).toBe(false);
|
||||
// Must contain a SKILL.md that IS a symlink
|
||||
expect(fs.existsSync(skillMdPath)).toBe(true);
|
||||
expect(fs.lstatSync(skillMdPath).isSymbolicLink()).toBe(true);
|
||||
// The SKILL.md symlink must point to the source skill's SKILL.md
|
||||
const target = fs.readlinkSync(skillMdPath);
|
||||
expect(target).toContain(skill);
|
||||
expect(target).toEndWith('/SKILL.md');
|
||||
}
|
||||
});
|
||||
|
||||
// Same invariant for prefixed mode
|
||||
test('prefixed skills are real directories with SKILL.md symlinks, not dir symlinks', () => {
|
||||
setupMockInstall(['qa', 'ship']);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
for (const skill of ['gstack-qa', 'gstack-ship']) {
|
||||
const skillPath = path.join(skillsDir, skill);
|
||||
const skillMdPath = path.join(skillPath, 'SKILL.md');
|
||||
expect(fs.lstatSync(skillPath).isDirectory()).toBe(true);
|
||||
expect(fs.lstatSync(skillPath).isSymbolicLink()).toBe(false);
|
||||
expect(fs.lstatSync(skillMdPath).isSymbolicLink()).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
// Upgrade: old directory symlinks get replaced with real directories
|
||||
test('upgrades old directory symlinks to real directories', () => {
|
||||
setupMockInstall(['qa', 'ship']);
|
||||
// Simulate old behavior: create directory symlinks (the old pattern)
|
||||
fs.symlinkSync(path.join(installDir, 'qa'), path.join(skillsDir, 'qa'));
|
||||
fs.symlinkSync(path.join(installDir, 'ship'), path.join(skillsDir, 'ship'));
|
||||
// Verify they start as symlinks
|
||||
expect(fs.lstatSync(path.join(skillsDir, 'qa')).isSymbolicLink()).toBe(true);
|
||||
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
|
||||
// After relink: must be real directories, not symlinks
|
||||
expect(fs.lstatSync(path.join(skillsDir, 'qa')).isSymbolicLink()).toBe(false);
|
||||
expect(fs.lstatSync(path.join(skillsDir, 'qa')).isDirectory()).toBe(true);
|
||||
expect(fs.lstatSync(path.join(skillsDir, 'qa', 'SKILL.md')).isSymbolicLink()).toBe(true);
|
||||
});
|
||||
|
||||
// FIRST INSTALL: --no-prefix must create ONLY flat names, zero gstack-* pollution
|
||||
test('first install --no-prefix: only flat names exist, zero gstack-* entries', () => {
|
||||
setupMockInstall(['qa', 'ship', 'review', 'plan-ceo-review', 'gstack-upgrade']);
|
||||
// Simulate first install: no saved config, pass --no-prefix equivalent
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
// Enumerate everything in skills dir
|
||||
const entries = fs.readdirSync(skillsDir);
|
||||
// Expected: qa, ship, review, plan-ceo-review, gstack-upgrade (its real name)
|
||||
expect(entries.sort()).toEqual(['gstack-upgrade', 'plan-ceo-review', 'qa', 'review', 'ship']);
|
||||
// No gstack-qa, gstack-ship, gstack-review, gstack-plan-ceo-review
|
||||
const leaked = entries.filter(e => e.startsWith('gstack-') && e !== 'gstack-upgrade');
|
||||
expect(leaked).toEqual([]);
|
||||
});
|
||||
|
||||
// FIRST INSTALL: --prefix must create ONLY gstack-* names, zero flat-name pollution
|
||||
test('first install --prefix: only gstack-* entries exist, zero flat names', () => {
|
||||
setupMockInstall(['qa', 'ship', 'review', 'plan-ceo-review', 'gstack-upgrade']);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
const entries = fs.readdirSync(skillsDir);
|
||||
// Expected: gstack-qa, gstack-ship, gstack-review, gstack-plan-ceo-review, gstack-upgrade
|
||||
expect(entries.sort()).toEqual([
|
||||
'gstack-plan-ceo-review', 'gstack-qa', 'gstack-review', 'gstack-ship', 'gstack-upgrade',
|
||||
]);
|
||||
// No unprefixed qa, ship, review, plan-ceo-review
|
||||
const leaked = entries.filter(e => !e.startsWith('gstack-'));
|
||||
expect(leaked).toEqual([]);
|
||||
});
|
||||
|
||||
// FIRST INSTALL: non-TTY (no saved config, piped stdin) defaults to flat names
|
||||
test('non-TTY first install defaults to flat names via relink', () => {
|
||||
setupMockInstall(['qa', 'ship']);
|
||||
// Don't set any config — simulate fresh install
|
||||
// gstack-relink reads config; on fresh install config returns empty → defaults to false
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
const entries = fs.readdirSync(skillsDir);
|
||||
// Should be flat names (relink defaults to false when config returns empty)
|
||||
expect(entries.sort()).toEqual(['qa', 'ship']);
|
||||
});
|
||||
|
||||
// SWITCH: prefix → no-prefix must clean up ALL gstack-* entries
|
||||
test('switching prefix to no-prefix removes all gstack-* entries completely', () => {
|
||||
setupMockInstall(['qa', 'ship', 'review', 'plan-ceo-review', 'gstack-upgrade']);
|
||||
// Start in prefix mode
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
let entries = fs.readdirSync(skillsDir);
|
||||
expect(entries.filter(e => !e.startsWith('gstack-'))).toEqual([]);
|
||||
|
||||
// Switch to no-prefix
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
entries = fs.readdirSync(skillsDir);
|
||||
// Only flat names + gstack-upgrade (its real name)
|
||||
expect(entries.sort()).toEqual(['gstack-upgrade', 'plan-ceo-review', 'qa', 'review', 'ship']);
|
||||
const leaked = entries.filter(e => e.startsWith('gstack-') && e !== 'gstack-upgrade');
|
||||
expect(leaked).toEqual([]);
|
||||
});
|
||||
|
||||
// SWITCH: no-prefix → prefix must clean up ALL flat entries
|
||||
test('switching no-prefix to prefix removes all flat entries completely', () => {
|
||||
setupMockInstall(['qa', 'ship', 'review', 'gstack-upgrade']);
|
||||
// Start in no-prefix mode
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
let entries = fs.readdirSync(skillsDir);
|
||||
expect(entries.filter(e => e.startsWith('gstack-') && e !== 'gstack-upgrade')).toEqual([]);
|
||||
|
||||
// Switch to prefix
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
entries = fs.readdirSync(skillsDir);
|
||||
// Only gstack-* names
|
||||
expect(entries.sort()).toEqual([
|
||||
'gstack-qa', 'gstack-review', 'gstack-ship', 'gstack-upgrade',
|
||||
]);
|
||||
const leaked = entries.filter(e => !e.startsWith('gstack-'));
|
||||
expect(leaked).toEqual([]);
|
||||
});
|
||||
|
||||
// Test 13: cleans stale symlinks from opposite mode
|
||||
test('cleans up stale symlinks from opposite mode', () => {
|
||||
setupMockInstall(['qa', 'ship']);
|
||||
// Create prefixed symlinks first
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
@@ -109,7 +312,10 @@ describe('gstack-relink (#578)', () => {
|
||||
expect(fs.existsSync(path.join(skillsDir, 'gstack-qa'))).toBe(true);
|
||||
|
||||
// Switch to flat mode
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
@@ -132,7 +338,10 @@ describe('gstack-relink (#578)', () => {
|
||||
// Test: gstack-upgrade does NOT get double-prefixed
|
||||
test('does not double-prefix gstack-upgrade directory', () => {
|
||||
setupMockInstall(['qa', 'ship', 'gstack-upgrade']);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
@@ -158,6 +367,68 @@ describe('gstack-relink (#578)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('upgrade migrations', () => {
|
||||
const MIGRATIONS_DIR = path.join(ROOT, 'gstack-upgrade', 'migrations');
|
||||
|
||||
test('migrations directory exists', () => {
|
||||
expect(fs.existsSync(MIGRATIONS_DIR)).toBe(true);
|
||||
});
|
||||
|
||||
test('all migration scripts are executable and parse without syntax errors', () => {
|
||||
const scripts = fs.readdirSync(MIGRATIONS_DIR).filter(f => f.endsWith('.sh'));
|
||||
expect(scripts.length).toBeGreaterThan(0);
|
||||
for (const script of scripts) {
|
||||
const fullPath = path.join(MIGRATIONS_DIR, script);
|
||||
// Must be executable
|
||||
const stat = fs.statSync(fullPath);
|
||||
expect(stat.mode & 0o111).toBeGreaterThan(0);
|
||||
// Must parse without syntax errors (bash -n is a syntax check, doesn't execute)
|
||||
const result = execSync(`bash -n "${fullPath}" 2>&1`, { encoding: 'utf-8', timeout: 5000 });
|
||||
// bash -n outputs nothing on success
|
||||
}
|
||||
});
|
||||
|
||||
test('migration filenames follow v{VERSION}.sh pattern', () => {
|
||||
const scripts = fs.readdirSync(MIGRATIONS_DIR).filter(f => f.endsWith('.sh'));
|
||||
for (const script of scripts) {
|
||||
expect(script).toMatch(/^v\d+\.\d+\.\d+\.\d+\.sh$/);
|
||||
}
|
||||
});
|
||||
|
||||
test('v0.15.2.0 migration runs gstack-relink', () => {
|
||||
const content = fs.readFileSync(path.join(MIGRATIONS_DIR, 'v0.15.2.0.sh'), 'utf-8');
|
||||
expect(content).toContain('gstack-relink');
|
||||
});
|
||||
|
||||
test('v0.15.2.0 migration fixes stale directory symlinks', () => {
|
||||
setupMockInstall(['qa', 'ship', 'review']);
|
||||
// Simulate old state: directory symlinks (pre-v0.15.2.0 pattern)
|
||||
fs.symlinkSync(path.join(installDir, 'qa'), path.join(skillsDir, 'qa'));
|
||||
fs.symlinkSync(path.join(installDir, 'ship'), path.join(skillsDir, 'ship'));
|
||||
fs.symlinkSync(path.join(installDir, 'review'), path.join(skillsDir, 'review'));
|
||||
// Set no-prefix mode (suppress auto-relink so symlinks stay intact for the test)
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`, {
|
||||
GSTACK_SETUP_RUNNING: '1',
|
||||
});
|
||||
// Verify old state: symlinks
|
||||
expect(fs.lstatSync(path.join(skillsDir, 'qa')).isSymbolicLink()).toBe(true);
|
||||
|
||||
// Run the migration (it calls gstack-relink internally)
|
||||
run(`bash ${path.join(MIGRATIONS_DIR, 'v0.15.2.0.sh')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
|
||||
// After migration: real directories with SKILL.md symlinks
|
||||
for (const skill of ['qa', 'ship', 'review']) {
|
||||
const skillPath = path.join(skillsDir, skill);
|
||||
expect(fs.lstatSync(skillPath).isSymbolicLink()).toBe(false);
|
||||
expect(fs.lstatSync(skillPath).isDirectory()).toBe(true);
|
||||
expect(fs.lstatSync(path.join(skillPath, 'SKILL.md')).isSymbolicLink()).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('gstack-patch-names (#620/#578)', () => {
|
||||
// Helper to read name: from SKILL.md frontmatter
|
||||
function readSkillName(skillDir: string): string | null {
|
||||
@@ -168,7 +439,10 @@ describe('gstack-patch-names (#620/#578)', () => {
|
||||
|
||||
test('prefix=true patches name: field in SKILL.md', () => {
|
||||
setupMockInstall(['qa', 'ship', 'review']);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
@@ -182,14 +456,20 @@ describe('gstack-patch-names (#620/#578)', () => {
|
||||
test('prefix=false restores name: field in SKILL.md', () => {
|
||||
setupMockInstall(['qa', 'ship']);
|
||||
// First, prefix them
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
expect(readSkillName(path.join(installDir, 'qa'))).toBe('gstack-qa');
|
||||
// Now switch to flat mode
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix false`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
@@ -201,7 +481,10 @@ describe('gstack-patch-names (#620/#578)', () => {
|
||||
|
||||
test('gstack-upgrade name: not double-prefixed', () => {
|
||||
setupMockInstall(['qa', 'gstack-upgrade']);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
@@ -216,7 +499,10 @@ describe('gstack-patch-names (#620/#578)', () => {
|
||||
setupMockInstall(['qa']);
|
||||
// Overwrite qa SKILL.md with no frontmatter
|
||||
fs.writeFileSync(path.join(installDir, 'qa', 'SKILL.md'), '# qa\nSome content.');
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`);
|
||||
run(`${path.join(installDir, 'bin', 'gstack-config')} set skill_prefix true`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
GSTACK_SKILLS_DIR: skillsDir,
|
||||
});
|
||||
// Should not crash
|
||||
run(`${path.join(installDir, 'bin', 'gstack-relink')}`, {
|
||||
GSTACK_INSTALL_DIR: installDir,
|
||||
|
||||
+78
-30
@@ -20,6 +20,7 @@ let tmpDir: string;
|
||||
describeIfSelected('Skill E2E tests', [
|
||||
'browse-basic', 'browse-snapshot', 'skillmd-setup-discovery',
|
||||
'skillmd-no-local-binary', 'skillmd-outside-git', 'session-awareness',
|
||||
'operational-learning',
|
||||
], () => {
|
||||
beforeAll(() => {
|
||||
testServer = startTestServer();
|
||||
@@ -177,49 +178,96 @@ Report the exact output — either "READY: <path>" or "NEEDS_SETUP".`,
|
||||
try { fs.rmSync(nonGitDir, { recursive: true, force: true }); } catch {}
|
||||
}, 60_000);
|
||||
|
||||
testConcurrentIfSelected('contributor-mode', async () => {
|
||||
const contribDir = fs.mkdtempSync(path.join(os.tmpdir(), 'skill-e2e-contrib-'));
|
||||
const logsDir = path.join(contribDir, 'contributor-logs');
|
||||
fs.mkdirSync(logsDir, { recursive: true });
|
||||
testConcurrentIfSelected('operational-learning', async () => {
|
||||
const opDir = fs.mkdtempSync(path.join(os.tmpdir(), 'skill-e2e-oplearn-'));
|
||||
const gstackHome = path.join(opDir, '.gstack-home');
|
||||
|
||||
// Init git repo
|
||||
const run = (cmd: string, args: string[]) =>
|
||||
spawnSync(cmd, args, { cwd: opDir, stdio: 'pipe', timeout: 5000 });
|
||||
run('git', ['init', '-b', 'main']);
|
||||
run('git', ['config', 'user.email', 'test@test.com']);
|
||||
run('git', ['config', 'user.name', 'Test']);
|
||||
fs.writeFileSync(path.join(opDir, 'app.ts'), 'console.log("hello");\n');
|
||||
run('git', ['add', '.']);
|
||||
run('git', ['commit', '-m', 'initial']);
|
||||
|
||||
// Copy bin scripts
|
||||
const binDir = path.join(opDir, 'bin');
|
||||
fs.mkdirSync(binDir, { recursive: true });
|
||||
for (const script of ['gstack-learnings-log', 'gstack-slug']) {
|
||||
fs.copyFileSync(path.join(ROOT, 'bin', script), path.join(binDir, script));
|
||||
fs.chmodSync(path.join(binDir, script), 0o755);
|
||||
}
|
||||
|
||||
// gstack-learnings-log will create the project dir automatically via gstack-slug
|
||||
|
||||
const result = await runSkillTest({
|
||||
prompt: `You are in contributor mode (gstack_contributor=true). You just ran this browse command and it failed:
|
||||
prompt: `You just ran \`npm test\` in this project and it failed with this error:
|
||||
|
||||
$ /nonexistent/browse goto https://example.com
|
||||
/nonexistent/browse: No such file or directory
|
||||
Error: --experimental-vm-modules flag is required for ESM support in this project.
|
||||
Run: npm test --experimental-vm-modules
|
||||
|
||||
Per the contributor mode instructions, file a field report to ${logsDir}/browse-missing-binary.md using the Write tool. Include all required sections: title, what you tried, what happened, rating, repro steps, raw output, what would make it a 10, and the date/version footer.`,
|
||||
workingDirectory: contribDir,
|
||||
Per the Operational Self-Improvement instructions below, log an operational learning about this failure.
|
||||
|
||||
## Operational Self-Improvement
|
||||
|
||||
Before completing, reflect on this session:
|
||||
- Did any commands fail unexpectedly?
|
||||
|
||||
If yes, log an operational learning for future sessions:
|
||||
|
||||
\`\`\`bash
|
||||
GSTACK_HOME="${gstackHome}" ${binDir}/gstack-learnings-log '{"skill":"qa","type":"operational","key":"SHORT_KEY","insight":"DESCRIPTION","confidence":N,"source":"observed"}'
|
||||
\`\`\`
|
||||
|
||||
Replace SHORT_KEY with a kebab-case key like "esm-vm-modules-flag".
|
||||
Replace DESCRIPTION with a one-sentence description of what you learned.
|
||||
Replace N with a confidence score 1-10.
|
||||
|
||||
Log the operational learning now. Then say what you logged.`,
|
||||
workingDirectory: opDir,
|
||||
maxTurns: 5,
|
||||
timeout: 30_000,
|
||||
testName: 'contributor-mode',
|
||||
testName: 'operational-learning',
|
||||
runId,
|
||||
});
|
||||
|
||||
logCost('contributor mode', result);
|
||||
// Override passed: this test intentionally triggers a browse error (nonexistent binary)
|
||||
// so browseErrors will be non-empty — that's expected, not a failure
|
||||
recordE2E(evalCollector, 'contributor mode report', 'Skill E2E tests', result, {
|
||||
passed: result.exitReason === 'success',
|
||||
logCost('operational learning', result);
|
||||
|
||||
const exitOk = ['success', 'error_max_turns'].includes(result.exitReason);
|
||||
|
||||
// Check if learnings file was created with an operational entry
|
||||
// The slug is derived from the git repo (dirname), so search all project dirs
|
||||
let hasOperational = false;
|
||||
const projectsDir = path.join(gstackHome, 'projects');
|
||||
if (fs.existsSync(projectsDir)) {
|
||||
for (const slug of fs.readdirSync(projectsDir)) {
|
||||
const lPath = path.join(projectsDir, slug, 'learnings.jsonl');
|
||||
if (fs.existsSync(lPath)) {
|
||||
const jsonl = fs.readFileSync(lPath, 'utf-8').trim();
|
||||
if (jsonl) {
|
||||
const entries = jsonl.split('\n').map(l => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
|
||||
const opEntry = entries.find(e => e.type === 'operational');
|
||||
if (opEntry) {
|
||||
hasOperational = true;
|
||||
console.log(`Operational learning logged: key="${opEntry.key}" insight="${opEntry.insight}" (slug: ${slug})`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recordE2E(evalCollector, 'operational learning', 'Skill E2E tests', result, {
|
||||
passed: exitOk && hasOperational,
|
||||
});
|
||||
|
||||
// Verify a contributor log was created with expected format
|
||||
const logFiles = fs.readdirSync(logsDir).filter(f => f.endsWith('.md'));
|
||||
expect(logFiles.length).toBeGreaterThan(0);
|
||||
|
||||
// Verify report has key structural sections (agent may phrase differently)
|
||||
const logContent = fs.readFileSync(path.join(logsDir, logFiles[0]), 'utf-8');
|
||||
// Must have a title (# heading)
|
||||
expect(logContent).toMatch(/^#\s/m);
|
||||
// Must mention the failed command or browse
|
||||
expect(logContent).toMatch(/browse|nonexistent|not found|no such file/i);
|
||||
// Must have some kind of rating
|
||||
expect(logContent).toMatch(/rating|\/10/i);
|
||||
// Must have steps or reproduction info
|
||||
expect(logContent).toMatch(/step|repro|reproduce/i);
|
||||
expect(exitOk).toBe(true);
|
||||
expect(hasOperational).toBe(true);
|
||||
|
||||
// Clean up
|
||||
try { fs.rmSync(contribDir, { recursive: true, force: true }); } catch {}
|
||||
try { fs.rmSync(opDir, { recursive: true, force: true }); } catch {}
|
||||
}, 90_000);
|
||||
|
||||
testConcurrentIfSelected('session-awareness', async () => {
|
||||
|
||||
@@ -44,8 +44,9 @@ describeIfSelected('Learnings E2E', ['learnings-show'], () => {
|
||||
fs.chmodSync(path.join(binDir, script), 0o755);
|
||||
}
|
||||
|
||||
// Seed learnings JSONL with 3 entries of different types
|
||||
const slug = 'test-project';
|
||||
// Seed learnings JSONL — slug must match what gstack-slug computes.
|
||||
// With no git remote, gstack-slug falls back to basename(workDir).
|
||||
const slug = path.basename(workDir).replace(/[^a-zA-Z0-9._-]/g, '');
|
||||
const projectDir = path.join(gstackHome, 'projects', slug);
|
||||
fs.mkdirSync(projectDir, { recursive: true });
|
||||
|
||||
@@ -67,6 +68,11 @@ describeIfSelected('Learnings E2E', ['learnings-show'], () => {
|
||||
insight: 'User wants rubocop to run before every commit, no exceptions.',
|
||||
confidence: 10, source: 'user-stated', ts: new Date().toISOString(),
|
||||
},
|
||||
{
|
||||
skill: 'qa', type: 'operational', key: 'test-timeout-flag',
|
||||
insight: 'bun test requires --timeout 30000 for E2E tests in this project.',
|
||||
confidence: 9, source: 'observed', ts: new Date().toISOString(),
|
||||
},
|
||||
];
|
||||
|
||||
fs.writeFileSync(
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
|
||||
import { runSkillTest } from './helpers/session-runner';
|
||||
import {
|
||||
ROOT, runId, evalsEnabled,
|
||||
describeIfSelected, testConcurrentIfSelected,
|
||||
copyDirSync, logCost, recordE2E,
|
||||
createEvalCollector, finalizeEvalCollector,
|
||||
} from './helpers/e2e-helpers';
|
||||
import { spawnSync } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
|
||||
const evalCollector = createEvalCollector('e2e-session-intelligence');
|
||||
|
||||
// --- Session Intelligence E2E ---
|
||||
// Tests the core contract: timeline events flow in, context recovery flows out,
|
||||
// checkpoints round-trip.
|
||||
|
||||
describeIfSelected('Session Intelligence E2E', [
|
||||
'timeline-event-flow', 'context-recovery-artifacts', 'checkpoint-save-resume',
|
||||
], () => {
|
||||
let workDir: string;
|
||||
let gstackHome: string;
|
||||
let slug: string;
|
||||
|
||||
beforeAll(() => {
|
||||
workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'skill-e2e-session-intel-'));
|
||||
gstackHome = path.join(workDir, '.gstack-home');
|
||||
|
||||
// Init git repo
|
||||
const run = (cmd: string, args: string[]) =>
|
||||
spawnSync(cmd, args, { cwd: workDir, stdio: 'pipe', timeout: 5000 });
|
||||
run('git', ['init', '-b', 'main']);
|
||||
run('git', ['config', 'user.email', 'test@test.com']);
|
||||
run('git', ['config', 'user.name', 'Test']);
|
||||
fs.writeFileSync(path.join(workDir, 'app.ts'), 'console.log("hello");\n');
|
||||
run('git', ['add', '.']);
|
||||
run('git', ['commit', '-m', 'initial']);
|
||||
|
||||
// Copy bin scripts needed by timeline and checkpoint
|
||||
const binDir = path.join(workDir, 'bin');
|
||||
fs.mkdirSync(binDir, { recursive: true });
|
||||
for (const script of [
|
||||
'gstack-timeline-log', 'gstack-timeline-read', 'gstack-slug',
|
||||
'gstack-learnings-log', 'gstack-learnings-search',
|
||||
]) {
|
||||
const src = path.join(ROOT, 'bin', script);
|
||||
if (fs.existsSync(src)) {
|
||||
fs.copyFileSync(src, path.join(binDir, script));
|
||||
fs.chmodSync(path.join(binDir, script), 0o755);
|
||||
}
|
||||
}
|
||||
|
||||
// Compute slug (same logic as gstack-slug without git remote)
|
||||
slug = path.basename(workDir).replace(/[^a-zA-Z0-9._-]/g, '');
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
try { fs.rmSync(workDir, { recursive: true, force: true }); } catch {}
|
||||
finalizeEvalCollector(evalCollector);
|
||||
});
|
||||
|
||||
// --- Test 1: Timeline event flow ---
|
||||
// Write a timeline event via gstack-timeline-log, read it back via gstack-timeline-read.
|
||||
// This is the foundational data flow test: events go in, they come back out.
|
||||
testConcurrentIfSelected('timeline-event-flow', async () => {
|
||||
const projectDir = path.join(gstackHome, 'projects', slug);
|
||||
fs.mkdirSync(projectDir, { recursive: true });
|
||||
|
||||
// Write two events via the binary
|
||||
const logBin = path.join(workDir, 'bin', 'gstack-timeline-log');
|
||||
const readBin = path.join(workDir, 'bin', 'gstack-timeline-read');
|
||||
const env = { ...process.env, GSTACK_HOME: gstackHome };
|
||||
const opts = { cwd: workDir, env, stdio: 'pipe' as const, timeout: 10000 };
|
||||
|
||||
spawnSync(logBin, [JSON.stringify({
|
||||
skill: 'review', event: 'started', branch: 'main', session: 'test-1',
|
||||
})], opts);
|
||||
spawnSync(logBin, [JSON.stringify({
|
||||
skill: 'review', event: 'completed', branch: 'main',
|
||||
outcome: 'success', duration_s: 120, session: 'test-1',
|
||||
})], opts);
|
||||
|
||||
// Read via gstack-timeline-read
|
||||
const readResult = spawnSync(readBin, ['--branch', 'main'], opts);
|
||||
const readOutput = readResult.stdout?.toString() || '';
|
||||
|
||||
// Verify timeline.jsonl exists and has content
|
||||
const timelinePath = path.join(projectDir, 'timeline.jsonl');
|
||||
expect(fs.existsSync(timelinePath)).toBe(true);
|
||||
|
||||
const lines = fs.readFileSync(timelinePath, 'utf-8').trim().split('\n');
|
||||
expect(lines.length).toBe(2);
|
||||
|
||||
// Verify the events are valid JSON with expected fields
|
||||
const event1 = JSON.parse(lines[0]);
|
||||
expect(event1.skill).toBe('review');
|
||||
expect(event1.event).toBe('started');
|
||||
expect(event1.ts).toBeDefined();
|
||||
|
||||
const event2 = JSON.parse(lines[1]);
|
||||
expect(event2.event).toBe('completed');
|
||||
expect(event2.outcome).toBe('success');
|
||||
|
||||
// Verify gstack-timeline-read output includes the events
|
||||
expect(readOutput).toContain('review');
|
||||
|
||||
recordE2E(evalCollector, 'timeline event flow', 'Session Intelligence E2E', {
|
||||
output: readOutput,
|
||||
exitReason: 'success',
|
||||
duration: 0,
|
||||
toolCalls: [],
|
||||
browseErrors: [],
|
||||
costEstimate: { inputChars: 0, outputChars: 0, estimatedTokens: 0, estimatedCost: 0, turnsUsed: 0 },
|
||||
transcript: [],
|
||||
model: 'direct',
|
||||
firstResponseMs: 0,
|
||||
maxInterTurnMs: 0,
|
||||
}, { passed: true });
|
||||
|
||||
console.log(`Timeline flow: ${lines.length} events written, read output ${readOutput.length} chars`);
|
||||
}, 30_000);
|
||||
|
||||
// --- Test 2: Context recovery with seeded artifacts ---
|
||||
// Seed CEO plans and timeline events, then run a skill and verify the preamble
|
||||
// outputs "RECENT ARTIFACTS" and "LAST_SESSION".
|
||||
testConcurrentIfSelected('context-recovery-artifacts', async () => {
|
||||
const projectDir = path.join(gstackHome, 'projects', slug);
|
||||
fs.mkdirSync(path.join(projectDir, 'ceo-plans'), { recursive: true });
|
||||
|
||||
// Seed a CEO plan
|
||||
fs.writeFileSync(
|
||||
path.join(projectDir, 'ceo-plans', '2026-03-31-test-feature.md'),
|
||||
'---\nstatus: ACTIVE\n---\n# CEO Plan: Test Feature\nThis is a test plan.\n',
|
||||
);
|
||||
|
||||
// Seed timeline with a completed event on main branch
|
||||
const timelineEntry = JSON.stringify({
|
||||
ts: new Date().toISOString(),
|
||||
skill: 'ship',
|
||||
event: 'completed',
|
||||
branch: 'main',
|
||||
outcome: 'success',
|
||||
duration_s: 60,
|
||||
session: 'prior-session',
|
||||
});
|
||||
fs.writeFileSync(path.join(projectDir, 'timeline.jsonl'), timelineEntry + '\n');
|
||||
|
||||
// Copy the /learn skill (lightweight, tier-2 skill that runs context recovery)
|
||||
copyDirSync(path.join(ROOT, 'learn'), path.join(workDir, 'learn'));
|
||||
|
||||
const result = await runSkillTest({
|
||||
prompt: `Read the file learn/SKILL.md for instructions.
|
||||
|
||||
Run the context recovery check — the preamble should show recent artifacts.
|
||||
|
||||
IMPORTANT:
|
||||
- Use GSTACK_HOME="${gstackHome}" as an environment variable when running bin scripts.
|
||||
- The bin scripts are at ./bin/ (relative to this directory), not at ~/.claude/skills/gstack/bin/.
|
||||
Replace any references to ~/.claude/skills/gstack/bin/ with ./bin/ when running commands.
|
||||
- Do NOT use AskUserQuestion.
|
||||
- Just run the preamble bash block and report what you see.
|
||||
- Look for "RECENT ARTIFACTS" and "LAST_SESSION" in the output.`,
|
||||
workingDirectory: workDir,
|
||||
maxTurns: 10,
|
||||
allowedTools: ['Bash', 'Read', 'Write', 'Edit', 'Grep', 'Glob'],
|
||||
timeout: 120_000,
|
||||
testName: 'context-recovery-artifacts',
|
||||
runId,
|
||||
});
|
||||
|
||||
logCost('context recovery', result);
|
||||
|
||||
const output = result.output.toLowerCase();
|
||||
|
||||
// The preamble should have found the seeded artifacts
|
||||
const foundArtifacts = output.includes('recent artifacts') || output.includes('ceo-plans');
|
||||
const foundLastSession = output.includes('last_session') || output.includes('ship');
|
||||
const foundTimeline = output.includes('timeline') || output.includes('completed');
|
||||
|
||||
// At least the CEO plan or timeline should be visible
|
||||
const foundCount = [foundArtifacts, foundLastSession, foundTimeline].filter(Boolean).length;
|
||||
|
||||
const exitOk = ['success', 'error_max_turns'].includes(result.exitReason);
|
||||
|
||||
recordE2E(evalCollector, 'context recovery', 'Session Intelligence E2E', result, {
|
||||
passed: exitOk && foundCount >= 1,
|
||||
});
|
||||
|
||||
expect(exitOk).toBe(true);
|
||||
expect(foundCount).toBeGreaterThanOrEqual(1);
|
||||
|
||||
console.log(`Context recovery: artifacts=${foundArtifacts}, lastSession=${foundLastSession}, timeline=${foundTimeline}`);
|
||||
}, 180_000);
|
||||
|
||||
// --- Test 3: Checkpoint save and resume ---
|
||||
// Run /checkpoint save via claude -p, verify file created. Then run /checkpoint resume
|
||||
// and verify it reads the checkpoint back.
|
||||
testConcurrentIfSelected('checkpoint-save-resume', async () => {
|
||||
const projectDir = path.join(gstackHome, 'projects', slug);
|
||||
fs.mkdirSync(path.join(projectDir, 'checkpoints'), { recursive: true });
|
||||
|
||||
// Copy the /checkpoint skill
|
||||
copyDirSync(path.join(ROOT, 'checkpoint'), path.join(workDir, 'checkpoint'));
|
||||
|
||||
// Add a staged change so /checkpoint has something to capture
|
||||
fs.writeFileSync(path.join(workDir, 'feature.ts'), 'export function newFeature() { return true; }\n');
|
||||
spawnSync('git', ['add', 'feature.ts'], { cwd: workDir, stdio: 'pipe', timeout: 5000 });
|
||||
|
||||
// Extract the checkpoint save section from the skill template
|
||||
const full = fs.readFileSync(path.join(ROOT, 'checkpoint', 'SKILL.md'), 'utf-8');
|
||||
const saveStart = full.indexOf('## Save');
|
||||
const resumeStart = full.indexOf('## Resume');
|
||||
const saveSection = full.slice(saveStart, resumeStart > saveStart ? resumeStart : undefined);
|
||||
|
||||
const result = await runSkillTest({
|
||||
prompt: `You are testing the /checkpoint skill. Follow these instructions to save a checkpoint.
|
||||
|
||||
${saveSection.slice(0, 2000)}
|
||||
|
||||
IMPORTANT:
|
||||
- Use GSTACK_HOME="${gstackHome}" as an environment variable when running bin scripts.
|
||||
- The bin scripts are at ./bin/ (relative to this directory), not at ~/.claude/skills/gstack/bin/.
|
||||
Replace any references to ~/.claude/skills/gstack/bin/ with ./bin/ when running commands.
|
||||
- Save the checkpoint to ${projectDir}/checkpoints/ with a filename like "20260401-test-checkpoint.md".
|
||||
- Include YAML frontmatter with status, branch, and timestamp.
|
||||
- Include a summary of what's being worked on (you can see from git status).
|
||||
- Do NOT use AskUserQuestion.`,
|
||||
workingDirectory: workDir,
|
||||
maxTurns: 10,
|
||||
allowedTools: ['Bash', 'Read', 'Write', 'Edit', 'Grep', 'Glob'],
|
||||
timeout: 120_000,
|
||||
testName: 'checkpoint-save-resume',
|
||||
runId,
|
||||
});
|
||||
|
||||
logCost('checkpoint save', result);
|
||||
|
||||
// Check that a checkpoint file was created
|
||||
const checkpointDir = path.join(projectDir, 'checkpoints');
|
||||
const checkpointFiles = fs.existsSync(checkpointDir)
|
||||
? fs.readdirSync(checkpointDir).filter(f => f.endsWith('.md'))
|
||||
: [];
|
||||
|
||||
const exitOk = ['success', 'error_max_turns'].includes(result.exitReason);
|
||||
const checkpointCreated = checkpointFiles.length > 0;
|
||||
|
||||
let checkpointContent = '';
|
||||
if (checkpointCreated) {
|
||||
checkpointContent = fs.readFileSync(path.join(checkpointDir, checkpointFiles[0]), 'utf-8');
|
||||
}
|
||||
|
||||
// Verify checkpoint has expected structure
|
||||
const hasYamlFrontmatter = checkpointContent.includes('---') && checkpointContent.includes('status:');
|
||||
const hasBranch = checkpointContent.includes('branch:') || checkpointContent.includes('main');
|
||||
|
||||
recordE2E(evalCollector, 'checkpoint save-resume', 'Session Intelligence E2E', result, {
|
||||
passed: exitOk && checkpointCreated && hasYamlFrontmatter,
|
||||
});
|
||||
|
||||
expect(exitOk).toBe(true);
|
||||
expect(checkpointCreated).toBe(true);
|
||||
expect(hasYamlFrontmatter).toBe(true);
|
||||
|
||||
console.log(`Checkpoint: ${checkpointFiles.length} files created, YAML frontmatter: ${hasYamlFrontmatter}, branch: ${hasBranch}`);
|
||||
}, 180_000);
|
||||
});
|
||||
@@ -116,9 +116,10 @@ describeIfSelected('Sidebar URL accuracy E2E', ['sidebar-url-accuracy'], () => {
|
||||
}
|
||||
|
||||
expect(lastEntry).not.toBeNull();
|
||||
// Extension URL should be used, not the Playwright fallback
|
||||
// Extension URL should be used, not the Playwright fallback.
|
||||
// The pageUrl field carries the extension URL; the prompt itself
|
||||
// contains only the system prompt + user message (URL is metadata).
|
||||
expect(lastEntry.pageUrl).toBe(extensionUrl);
|
||||
expect(lastEntry.prompt).toContain(extensionUrl);
|
||||
expect(lastEntry.pageUrl).not.toBe('about:blank');
|
||||
|
||||
// Also test: chrome:// URL should be rejected, falling back to about:blank
|
||||
@@ -262,11 +263,12 @@ describeIfSelected('Sidebar CSS interaction E2E', ['sidebar-css-interaction'], (
|
||||
fs.writeFileSync(queueFile, '');
|
||||
const startTime = Date.now();
|
||||
|
||||
// Ask the agent to go to HN, find the most insightful comment, and highlight it
|
||||
// Simple task: go to example.com, read the title, apply a style
|
||||
// (much faster than multi-step HN comment navigation)
|
||||
const resp = await api('/sidebar-command', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
message: 'Go to https://news.ycombinator.com. Find the top story. Click into its comments. Read the comments and find the most insightful one. Highlight that comment with a 4px solid orange outline.',
|
||||
message: 'Go to https://example.com. Read the page title. Add a 4px solid orange outline to the h1 element.',
|
||||
activeTabUrl: 'about:blank',
|
||||
}),
|
||||
});
|
||||
@@ -315,15 +317,15 @@ describeIfSelected('Sidebar CSS interaction E2E', ['sidebar-css-interaction'], (
|
||||
.join(' ')
|
||||
.toLowerCase();
|
||||
|
||||
// Should have navigated to HN (look for ycombinator/HN in any entry text)
|
||||
// Should have navigated to example.com (look for example.com in any entry text)
|
||||
const allEntryText = entries
|
||||
.map((e: any) => `${e.text || ''} ${e.input || ''} ${e.message || ''}`)
|
||||
.join(' ');
|
||||
const navigatedToHN = allEntryText.includes('ycombinator') || allEntryText.includes('Hacker News') || allEntryText.includes('news.ycombinator');
|
||||
if (!navigatedToHN) {
|
||||
const navigatedToTarget = allEntryText.includes('example.com') || allEntryText.includes('Example Domain');
|
||||
if (!navigatedToTarget) {
|
||||
console.log('ALL ENTRY TEXT (first 2000):', allEntryText.slice(0, 2000));
|
||||
}
|
||||
expect(navigatedToHN).toBe(true);
|
||||
expect(navigatedToTarget).toBe(true);
|
||||
|
||||
// Should have applied a style (look for orange/outline in tool commands)
|
||||
const allText = entries.map((e: any) => e.text || '').join(' ');
|
||||
@@ -331,7 +333,7 @@ describeIfSelected('Sidebar CSS interaction E2E', ['sidebar-css-interaction'], (
|
||||
|
||||
evalCollector?.addTest({
|
||||
name: 'sidebar-css-interaction', suite: 'Sidebar CSS interaction E2E', tier: 'e2e',
|
||||
passed: !!doneEntry && navigatedToHN && appliedStyle,
|
||||
passed: !!doneEntry && navigatedToTarget && appliedStyle,
|
||||
duration_ms: duration,
|
||||
cost_usd: 0,
|
||||
exit_reason: doneEntry ? 'success' : 'timeout',
|
||||
|
||||
@@ -467,8 +467,18 @@ describeIfSelected('Codex skill E2E', ['codex-review'], () => {
|
||||
run('git', ['add', 'user_controller.rb']);
|
||||
run('git', ['commit', '-m', 'add vulnerable controller']);
|
||||
|
||||
// Copy the codex skill file
|
||||
fs.copyFileSync(path.join(ROOT, 'codex', 'SKILL.md'), path.join(codexDir, 'codex-SKILL.md'));
|
||||
// Extract only the review-relevant section from codex SKILL.md (~120 lines vs 1075).
|
||||
// Full SKILL.md is 55KB / ~14K tokens — takes 8 Read calls to consume, exhausting turns.
|
||||
const full = fs.readFileSync(path.join(ROOT, 'codex', 'SKILL.md'), 'utf-8');
|
||||
const startMarker = '# /codex — Multi-AI Second Opinion';
|
||||
const endMarker = '## Plan File Review Report';
|
||||
const start = full.indexOf(startMarker);
|
||||
const end = full.indexOf(endMarker, start);
|
||||
const reviewSection = full.slice(
|
||||
start >= 0 ? start : 0,
|
||||
end > start ? end : undefined,
|
||||
);
|
||||
fs.writeFileSync(path.join(codexDir, 'codex-SKILL.md'), reviewSection);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
@@ -485,11 +495,11 @@ describeIfSelected('Codex skill E2E', ['codex-review'], () => {
|
||||
|
||||
const result = await runSkillTest({
|
||||
prompt: `You are in a git repo on branch feature/add-vuln with changes against main.
|
||||
Read codex-SKILL.md for the /codex skill instructions.
|
||||
Run /codex review to review the current diff against main.
|
||||
Read codex-SKILL.md for the /codex review instructions (it's short — ~120 lines).
|
||||
Follow those instructions to run codex review against the diff on this branch.
|
||||
Write the full output (including the GATE verdict) to ${codexDir}/codex-output.md`,
|
||||
workingDirectory: codexDir,
|
||||
maxTurns: 15,
|
||||
maxTurns: 25,
|
||||
timeout: 300_000,
|
||||
testName: 'codex-review',
|
||||
runId,
|
||||
|
||||
@@ -325,62 +325,6 @@ Report the exact output — either "READY: <path>" or "NEEDS_SETUP".`,
|
||||
try { fs.rmSync(nonGitDir, { recursive: true, force: true }); } catch {}
|
||||
}, 60_000);
|
||||
|
||||
testIfSelected('contributor-mode', async () => {
|
||||
const contribDir = fs.mkdtempSync(path.join(os.tmpdir(), 'skill-e2e-contrib-'));
|
||||
const logsDir = path.join(contribDir, 'contributor-logs');
|
||||
fs.mkdirSync(logsDir, { recursive: true });
|
||||
|
||||
// Extract contributor mode instructions from generated SKILL.md
|
||||
const skillMd = fs.readFileSync(path.join(ROOT, 'SKILL.md'), 'utf-8');
|
||||
const contribStart = skillMd.indexOf('## Contributor Mode');
|
||||
const contribEnd = skillMd.indexOf('\n## ', contribStart + 1);
|
||||
const contribBlock = skillMd.slice(contribStart, contribEnd > 0 ? contribEnd : undefined);
|
||||
|
||||
const result = await runSkillTest({
|
||||
prompt: `You are in contributor mode (_CONTRIB=true).
|
||||
|
||||
${contribBlock}
|
||||
|
||||
OVERRIDE: Write contributor logs to ${logsDir}/ instead of ~/.gstack/contributor-logs/
|
||||
|
||||
Now try this browse command (it will fail — there is no binary at this path):
|
||||
/nonexistent/path/browse goto https://example.com
|
||||
|
||||
This is a gstack issue (the browse binary is missing/misconfigured).
|
||||
File a contributor report about this issue. Then tell me what you filed.`,
|
||||
workingDirectory: contribDir,
|
||||
maxTurns: 8,
|
||||
timeout: 60_000,
|
||||
testName: 'contributor-mode',
|
||||
runId,
|
||||
});
|
||||
|
||||
logCost('contributor mode', result);
|
||||
// Override passed: this test intentionally triggers a browse error (nonexistent binary)
|
||||
// so browseErrors will be non-empty — that's expected, not a failure
|
||||
recordE2E('contributor mode report', 'Skill E2E tests', result, {
|
||||
passed: result.exitReason === 'success',
|
||||
});
|
||||
|
||||
// Verify a contributor log was created with expected format
|
||||
const logFiles = fs.readdirSync(logsDir).filter(f => f.endsWith('.md'));
|
||||
expect(logFiles.length).toBeGreaterThan(0);
|
||||
|
||||
// Verify new reflection-based format
|
||||
const logContent = fs.readFileSync(path.join(logsDir, logFiles[0]), 'utf-8');
|
||||
expect(logContent).toContain('Hey gstack team');
|
||||
expect(logContent).toContain('What I was trying to do');
|
||||
expect(logContent).toContain('What happened instead');
|
||||
expect(logContent).toMatch(/rating/i);
|
||||
// Verify report has repro steps (agent may use "Steps to reproduce", "Repro Steps", etc.)
|
||||
expect(logContent).toMatch(/repro|steps to reproduce|how to reproduce/i);
|
||||
// Verify report has date/version footer (agent may format differently)
|
||||
expect(logContent).toMatch(/date.*2026|2026.*date/i);
|
||||
|
||||
// Clean up
|
||||
try { fs.rmSync(contribDir, { recursive: true, force: true }); } catch {}
|
||||
}, 90_000);
|
||||
|
||||
testIfSelected('session-awareness', async () => {
|
||||
const sessionDir = fs.mkdtempSync(path.join(os.tmpdir(), 'skill-e2e-session-'));
|
||||
|
||||
|
||||
@@ -735,45 +735,8 @@ describe('investigate skill structure', () => {
|
||||
}
|
||||
});
|
||||
|
||||
// --- Contributor mode preamble structure validation ---
|
||||
|
||||
describe('Contributor mode preamble structure', () => {
|
||||
const skillsWithPreamble = [
|
||||
'SKILL.md', 'browse/SKILL.md', 'qa/SKILL.md',
|
||||
'qa-only/SKILL.md',
|
||||
'setup-browser-cookies/SKILL.md',
|
||||
'ship/SKILL.md', 'review/SKILL.md',
|
||||
'plan-ceo-review/SKILL.md', 'plan-eng-review/SKILL.md',
|
||||
'retro/SKILL.md',
|
||||
'plan-design-review/SKILL.md',
|
||||
'design-review/SKILL.md',
|
||||
'design-consultation/SKILL.md',
|
||||
'document-release/SKILL.md',
|
||||
'canary/SKILL.md',
|
||||
'benchmark/SKILL.md',
|
||||
'land-and-deploy/SKILL.md',
|
||||
'setup-deploy/SKILL.md',
|
||||
];
|
||||
|
||||
for (const skill of skillsWithPreamble) {
|
||||
test(`${skill} has 0-10 rating in contributor mode`, () => {
|
||||
const content = fs.readFileSync(path.join(ROOT, skill), 'utf-8');
|
||||
expect(content).toContain('0-10');
|
||||
expect(content).toContain('Rating');
|
||||
});
|
||||
|
||||
test(`${skill} has "what would make this a 10" field`, () => {
|
||||
const content = fs.readFileSync(path.join(ROOT, skill), 'utf-8');
|
||||
expect(content).toContain('What would make this a 10');
|
||||
});
|
||||
|
||||
test(`${skill} uses periodic reflection (not per-command)`, () => {
|
||||
const content = fs.readFileSync(path.join(ROOT, skill), 'utf-8');
|
||||
expect(content).toContain('workflow step');
|
||||
expect(content).not.toContain('After you use gstack-provided CLIs');
|
||||
});
|
||||
}
|
||||
});
|
||||
// Contributor mode was removed in v0.13.10.0 — replaced by operational self-improvement.
|
||||
// Tests for contributor mode preamble structure are no longer applicable.
|
||||
|
||||
describe('Enum & Value Completeness in review checklist', () => {
|
||||
const checklist = fs.readFileSync(path.join(ROOT, 'review', 'checklist.md'), 'utf-8');
|
||||
@@ -1559,6 +1522,26 @@ describe('Test failure triage in ship skill', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('no compiled binaries in git', () => {
|
||||
test('git tracks no Mach-O or ELF binaries', () => {
|
||||
const result = require('child_process').execSync(
|
||||
'git ls-files -z | xargs -0 file --mime-type 2>/dev/null | grep -E "application/(x-mach-binary|x-executable|x-pie-executable|x-sharedlib)" || true',
|
||||
{ cwd: ROOT, encoding: 'utf-8' }
|
||||
).trim();
|
||||
const files = result ? result.split('\n').map((l: string) => l.split(':')[0].trim()) : [];
|
||||
expect(files).toEqual([]);
|
||||
});
|
||||
|
||||
test('git tracks no files larger than 2MB', () => {
|
||||
const result = require('child_process').execSync(
|
||||
'git ls-files -z | xargs -0 -I{} sh -c \'size=$(wc -c < "{}" 2>/dev/null | tr -d " "); [ "$size" -gt 2097152 ] 2>/dev/null && echo "{}:${size}"\' || true',
|
||||
{ cwd: ROOT, encoding: 'utf-8' }
|
||||
).trim();
|
||||
const files = result ? result.split('\n').filter(Boolean) : [];
|
||||
expect(files).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sidebar agent (#584)', () => {
|
||||
// #584 — Sidebar Write: sidebar-agent.ts allowedTools includes Write
|
||||
test('sidebar-agent.ts allowedTools includes Write', () => {
|
||||
|
||||
@@ -0,0 +1,339 @@
|
||||
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const SETTINGS_HOOK = path.join(ROOT, 'bin', 'gstack-settings-hook');
|
||||
const SESSION_UPDATE = path.join(ROOT, 'bin', 'gstack-session-update');
|
||||
const TEAM_INIT = path.join(ROOT, 'bin', 'gstack-team-init');
|
||||
|
||||
function mkTmpDir(): string {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-team-test-'));
|
||||
}
|
||||
|
||||
function run(cmd: string, opts: { cwd?: string; env?: Record<string, string> } = {}): { stdout: string; stderr: string; exitCode: number } {
|
||||
try {
|
||||
const stdout = execSync(cmd, {
|
||||
cwd: opts.cwd,
|
||||
env: { ...process.env, ...opts.env },
|
||||
encoding: 'utf-8',
|
||||
timeout: 10000,
|
||||
});
|
||||
return { stdout, stderr: '', exitCode: 0 };
|
||||
} catch (e: any) {
|
||||
return { stdout: e.stdout || '', stderr: e.stderr || '', exitCode: e.status ?? 1 };
|
||||
}
|
||||
}
|
||||
|
||||
describe('gstack-settings-hook', () => {
|
||||
let tmpDir: string;
|
||||
let settingsFile: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = mkTmpDir();
|
||||
settingsFile = path.join(tmpDir, 'settings.json');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('add creates settings.json if missing', () => {
|
||||
const result = run(`${SETTINGS_HOOK} add /path/to/gstack-session-update`, {
|
||||
env: { GSTACK_SETTINGS_FILE: settingsFile },
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
const settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
|
||||
expect(settings.hooks.SessionStart).toHaveLength(1);
|
||||
expect(settings.hooks.SessionStart[0].hooks[0].command).toBe('/path/to/gstack-session-update');
|
||||
});
|
||||
|
||||
test('add preserves existing settings', () => {
|
||||
fs.writeFileSync(settingsFile, JSON.stringify({ effortLevel: 'high', permissions: { defaultMode: 'auto' } }, null, 2));
|
||||
const result = run(`${SETTINGS_HOOK} add /path/to/gstack-session-update`, {
|
||||
env: { GSTACK_SETTINGS_FILE: settingsFile },
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
const settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
|
||||
expect(settings.effortLevel).toBe('high');
|
||||
expect(settings.permissions.defaultMode).toBe('auto');
|
||||
expect(settings.hooks.SessionStart).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('add deduplicates (running twice does not double-add)', () => {
|
||||
run(`${SETTINGS_HOOK} add /path/to/gstack-session-update`, {
|
||||
env: { GSTACK_SETTINGS_FILE: settingsFile },
|
||||
});
|
||||
run(`${SETTINGS_HOOK} add /path/to/gstack-session-update`, {
|
||||
env: { GSTACK_SETTINGS_FILE: settingsFile },
|
||||
});
|
||||
const settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
|
||||
expect(settings.hooks.SessionStart).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('remove removes the hook', () => {
|
||||
run(`${SETTINGS_HOOK} add /path/to/gstack-session-update`, {
|
||||
env: { GSTACK_SETTINGS_FILE: settingsFile },
|
||||
});
|
||||
const result = run(`${SETTINGS_HOOK} remove /path/to/gstack-session-update`, {
|
||||
env: { GSTACK_SETTINGS_FILE: settingsFile },
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
const settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
|
||||
expect(settings.hooks).toBeUndefined();
|
||||
});
|
||||
|
||||
test('remove is safe when settings.json does not exist', () => {
|
||||
const result = run(`${SETTINGS_HOOK} remove /path/to/gstack-session-update`, {
|
||||
env: { GSTACK_SETTINGS_FILE: settingsFile },
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test('remove preserves other hooks', () => {
|
||||
fs.writeFileSync(settingsFile, JSON.stringify({
|
||||
hooks: {
|
||||
SessionStart: [
|
||||
{ hooks: [{ type: 'command', command: '/path/to/gstack-session-update' }] },
|
||||
{ hooks: [{ type: 'command', command: '/other/hook' }] },
|
||||
],
|
||||
},
|
||||
}, null, 2));
|
||||
run(`${SETTINGS_HOOK} remove /path/to/gstack-session-update`, {
|
||||
env: { GSTACK_SETTINGS_FILE: settingsFile },
|
||||
});
|
||||
const settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
|
||||
expect(settings.hooks.SessionStart).toHaveLength(1);
|
||||
expect(settings.hooks.SessionStart[0].hooks[0].command).toBe('/other/hook');
|
||||
});
|
||||
|
||||
test('atomic write (no partial file on success)', () => {
|
||||
run(`${SETTINGS_HOOK} add /path/to/gstack-session-update`, {
|
||||
env: { GSTACK_SETTINGS_FILE: settingsFile },
|
||||
});
|
||||
// .tmp file should not exist after successful write
|
||||
expect(fs.existsSync(settingsFile + '.tmp')).toBe(false);
|
||||
// File should be valid JSON
|
||||
expect(() => JSON.parse(fs.readFileSync(settingsFile, 'utf-8'))).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('gstack-session-update', () => {
|
||||
let tmpDir: string;
|
||||
let gstackDir: string;
|
||||
let stateDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = mkTmpDir();
|
||||
gstackDir = path.join(tmpDir, 'gstack');
|
||||
stateDir = path.join(tmpDir, 'state');
|
||||
fs.mkdirSync(gstackDir, { recursive: true });
|
||||
fs.mkdirSync(stateDir, { recursive: true });
|
||||
|
||||
// Init a git repo to pass the .git guard
|
||||
execSync('git init', { cwd: gstackDir });
|
||||
execSync('git commit --allow-empty -m "init"', { cwd: gstackDir });
|
||||
fs.writeFileSync(path.join(gstackDir, 'VERSION'), '0.1.0');
|
||||
|
||||
// Create a minimal gstack-config that returns auto_upgrade=true
|
||||
const binDir = path.join(gstackDir, 'bin');
|
||||
fs.mkdirSync(binDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(binDir, 'gstack-config'), '#!/bin/bash\necho "true"');
|
||||
fs.chmodSync(path.join(binDir, 'gstack-config'), 0o755);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('exits 0 when .git is missing', () => {
|
||||
fs.rmSync(path.join(gstackDir, '.git'), { recursive: true });
|
||||
const result = run(SESSION_UPDATE, {
|
||||
env: { GSTACK_DIR: gstackDir, GSTACK_STATE_DIR: stateDir },
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test('exits 0 when auto_upgrade is not true', () => {
|
||||
// Override gstack-config to return false
|
||||
fs.writeFileSync(path.join(gstackDir, 'bin', 'gstack-config'), '#!/bin/bash\necho "false"');
|
||||
const result = run(SESSION_UPDATE, {
|
||||
env: { GSTACK_DIR: gstackDir, GSTACK_STATE_DIR: stateDir },
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test('throttle: skips when checked recently', () => {
|
||||
// Write a recent throttle timestamp
|
||||
const throttleFile = path.join(stateDir, '.last-session-update');
|
||||
fs.writeFileSync(throttleFile, String(Math.floor(Date.now() / 1000)));
|
||||
|
||||
const result = run(SESSION_UPDATE, {
|
||||
env: { GSTACK_DIR: gstackDir, GSTACK_STATE_DIR: stateDir },
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
// No log file should be created (throttled before forking)
|
||||
});
|
||||
|
||||
test('always exits 0 (non-fatal)', () => {
|
||||
// Even with a broken setup, should exit 0
|
||||
const result = run(SESSION_UPDATE, {
|
||||
env: { GSTACK_DIR: '/nonexistent/path', GSTACK_STATE_DIR: stateDir },
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gstack-team-init', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = mkTmpDir();
|
||||
execSync('git init', { cwd: tmpDir });
|
||||
execSync('git commit --allow-empty -m "init"', { cwd: tmpDir });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('errors without a mode argument', () => {
|
||||
const result = run(TEAM_INIT, { cwd: tmpDir });
|
||||
expect(result.exitCode).not.toBe(0);
|
||||
expect(result.stderr).toContain('Usage');
|
||||
});
|
||||
|
||||
test('errors outside a git repo', () => {
|
||||
const nonGitDir = mkTmpDir();
|
||||
const result = run(`${TEAM_INIT} optional`, { cwd: nonGitDir });
|
||||
expect(result.exitCode).not.toBe(0);
|
||||
expect(result.stderr).toContain('not in a git repository');
|
||||
fs.rmSync(nonGitDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('optional: creates CLAUDE.md with recommended section', () => {
|
||||
const result = run(`${TEAM_INIT} optional`, { cwd: tmpDir });
|
||||
expect(result.exitCode).toBe(0);
|
||||
const claude = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
|
||||
expect(claude).toContain('## gstack (recommended)');
|
||||
expect(claude).toContain('./setup --team');
|
||||
});
|
||||
|
||||
test('required: creates CLAUDE.md with required section', () => {
|
||||
const result = run(`${TEAM_INIT} required`, { cwd: tmpDir });
|
||||
expect(result.exitCode).toBe(0);
|
||||
const claude = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
|
||||
expect(claude).toContain('## gstack (REQUIRED');
|
||||
expect(claude).toContain('GSTACK_MISSING');
|
||||
});
|
||||
|
||||
test('required: creates enforcement hook', () => {
|
||||
run(`${TEAM_INIT} required`, { cwd: tmpDir });
|
||||
const hookPath = path.join(tmpDir, '.claude', 'hooks', 'check-gstack.sh');
|
||||
expect(fs.existsSync(hookPath)).toBe(true);
|
||||
const hook = fs.readFileSync(hookPath, 'utf-8');
|
||||
expect(hook).toContain('BLOCKED: gstack is not installed');
|
||||
// Should be executable
|
||||
const stat = fs.statSync(hookPath);
|
||||
expect(stat.mode & 0o111).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('required: creates project settings.json with PreToolUse hook', () => {
|
||||
run(`${TEAM_INIT} required`, { cwd: tmpDir });
|
||||
const settingsPath = path.join(tmpDir, '.claude', 'settings.json');
|
||||
expect(fs.existsSync(settingsPath)).toBe(true);
|
||||
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
|
||||
expect(settings.hooks.PreToolUse).toHaveLength(1);
|
||||
expect(settings.hooks.PreToolUse[0].matcher).toBe('Skill');
|
||||
expect(settings.hooks.PreToolUse[0].hooks[0].command).toContain('check-gstack');
|
||||
});
|
||||
|
||||
test('idempotent: running twice does not duplicate CLAUDE.md section', () => {
|
||||
run(`${TEAM_INIT} optional`, { cwd: tmpDir });
|
||||
run(`${TEAM_INIT} optional`, { cwd: tmpDir });
|
||||
const claude = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
|
||||
const matches = claude.match(/## gstack/g);
|
||||
expect(matches).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('removes vendored copy when present', () => {
|
||||
// Create a fake vendored gstack with VERSION file
|
||||
const vendoredDir = path.join(tmpDir, '.claude', 'skills', 'gstack');
|
||||
fs.mkdirSync(vendoredDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(vendoredDir, 'VERSION'), '0.14.0.0');
|
||||
fs.writeFileSync(path.join(vendoredDir, 'README.md'), 'vendored');
|
||||
// Track it in git
|
||||
execSync('git add .claude/skills/gstack/', { cwd: tmpDir });
|
||||
execSync('git commit -m "add vendored gstack"', { cwd: tmpDir });
|
||||
|
||||
const result = run(`${TEAM_INIT} optional`, { cwd: tmpDir });
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Found vendored gstack copy');
|
||||
expect(result.stdout).toContain('Removed vendored copy');
|
||||
// Vendored dir should be gone
|
||||
expect(fs.existsSync(vendoredDir)).toBe(false);
|
||||
// .gitignore should have the entry
|
||||
const gitignore = fs.readFileSync(path.join(tmpDir, '.gitignore'), 'utf-8');
|
||||
expect(gitignore).toContain('.claude/skills/gstack/');
|
||||
});
|
||||
|
||||
test('skips when no vendored copy present', () => {
|
||||
const result = run(`${TEAM_INIT} optional`, { cwd: tmpDir });
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).not.toContain('Found vendored gstack copy');
|
||||
});
|
||||
|
||||
test('skips when .claude/skills/gstack is a symlink', () => {
|
||||
// Create a symlink (not a real vendored copy)
|
||||
const skillsDir = path.join(tmpDir, '.claude', 'skills');
|
||||
fs.mkdirSync(skillsDir, { recursive: true });
|
||||
const targetDir = mkTmpDir();
|
||||
fs.writeFileSync(path.join(targetDir, 'VERSION'), '0.14.0.0');
|
||||
fs.symlinkSync(targetDir, path.join(skillsDir, 'gstack'));
|
||||
|
||||
const result = run(`${TEAM_INIT} optional`, { cwd: tmpDir });
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).not.toContain('Found vendored gstack copy');
|
||||
// Symlink should still exist
|
||||
expect(fs.lstatSync(path.join(skillsDir, 'gstack')).isSymbolicLink()).toBe(true);
|
||||
fs.rmSync(targetDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('does not duplicate .gitignore entry on re-run', () => {
|
||||
// Create vendored copy
|
||||
const vendoredDir = path.join(tmpDir, '.claude', 'skills', 'gstack');
|
||||
fs.mkdirSync(vendoredDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(vendoredDir, 'VERSION'), '0.14.0.0');
|
||||
execSync('git add .claude/skills/gstack/', { cwd: tmpDir });
|
||||
execSync('git commit -m "add vendored"', { cwd: tmpDir });
|
||||
|
||||
run(`${TEAM_INIT} optional`, { cwd: tmpDir });
|
||||
|
||||
// Re-create vendored dir to simulate re-run scenario
|
||||
fs.mkdirSync(vendoredDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(vendoredDir, 'VERSION'), '0.14.0.0');
|
||||
run(`${TEAM_INIT} optional`, { cwd: tmpDir });
|
||||
|
||||
const gitignore = fs.readFileSync(path.join(tmpDir, '.gitignore'), 'utf-8');
|
||||
const matches = gitignore.match(/\.claude\/skills\/gstack\//g);
|
||||
expect(matches).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setup --team / --no-team / -q', () => {
|
||||
test('setup -q produces no stdout', () => {
|
||||
const result = run(`${path.join(ROOT, 'setup')} -q`, { cwd: ROOT });
|
||||
// -q should suppress informational output (may still have some output from build)
|
||||
// The key test is that the "Skill naming:" prompt and "gstack ready" messages are suppressed
|
||||
expect(result.stdout).not.toContain('Skill naming:');
|
||||
expect(result.stdout).not.toContain('gstack ready');
|
||||
});
|
||||
|
||||
test('setup --local prints deprecation warning', () => {
|
||||
// stderr capture: run via bash redirect so we can capture stderr
|
||||
const result = run(`bash -c '${path.join(ROOT, 'setup')} --local -q 2>&1'`, { cwd: ROOT });
|
||||
expect(result.stdout).toContain('deprecated');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,154 @@
|
||||
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
|
||||
import { execSync, ExecSyncOptionsWithStringEncoding } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const BIN = path.join(ROOT, 'bin');
|
||||
|
||||
let tmpDir: string;
|
||||
let slugDir: string;
|
||||
|
||||
function runLog(input: string, opts: { expectFail?: boolean } = {}): { stdout: string; exitCode: number } {
|
||||
const execOpts: ExecSyncOptionsWithStringEncoding = {
|
||||
cwd: ROOT,
|
||||
env: { ...process.env, GSTACK_HOME: tmpDir },
|
||||
encoding: 'utf-8',
|
||||
timeout: 15000,
|
||||
};
|
||||
try {
|
||||
const stdout = execSync(`${BIN}/gstack-timeline-log '${input.replace(/'/g, "'\\''")}'`, execOpts).trim();
|
||||
return { stdout, exitCode: 0 };
|
||||
} catch (e: any) {
|
||||
if (opts.expectFail) {
|
||||
return { stdout: e.stderr?.toString() || '', exitCode: e.status || 1 };
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
function runRead(args: string = ''): string {
|
||||
const execOpts: ExecSyncOptionsWithStringEncoding = {
|
||||
cwd: ROOT,
|
||||
env: { ...process.env, GSTACK_HOME: tmpDir },
|
||||
encoding: 'utf-8',
|
||||
timeout: 15000,
|
||||
};
|
||||
try {
|
||||
return execSync(`${BIN}/gstack-timeline-read ${args}`, execOpts).trim();
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-timeline-'));
|
||||
slugDir = path.join(tmpDir, 'projects');
|
||||
fs.mkdirSync(slugDir, { recursive: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function findTimelineFile(): string | null {
|
||||
const projectDirs = fs.readdirSync(slugDir);
|
||||
if (projectDirs.length === 0) return null;
|
||||
const f = path.join(slugDir, projectDirs[0], 'timeline.jsonl');
|
||||
return fs.existsSync(f) ? f : null;
|
||||
}
|
||||
|
||||
describe('gstack-timeline-log', () => {
|
||||
test('accepts valid JSON and appends to timeline.jsonl', () => {
|
||||
const input = '{"skill":"review","event":"started","branch":"main"}';
|
||||
const result = runLog(input);
|
||||
expect(result.exitCode).toBe(0);
|
||||
|
||||
const f = findTimelineFile();
|
||||
expect(f).not.toBeNull();
|
||||
const content = fs.readFileSync(f!, 'utf-8').trim();
|
||||
const parsed = JSON.parse(content);
|
||||
expect(parsed.skill).toBe('review');
|
||||
expect(parsed.event).toBe('started');
|
||||
expect(parsed.branch).toBe('main');
|
||||
});
|
||||
|
||||
test('rejects invalid JSON with exit 0 (non-blocking)', () => {
|
||||
const result = runLog('not json at all');
|
||||
expect(result.exitCode).toBe(0);
|
||||
|
||||
// No file should be created
|
||||
const f = findTimelineFile();
|
||||
expect(f).toBeNull();
|
||||
});
|
||||
|
||||
test('injects timestamp when ts field is missing', () => {
|
||||
const input = '{"skill":"review","event":"started","branch":"main"}';
|
||||
runLog(input);
|
||||
|
||||
const f = findTimelineFile();
|
||||
expect(f).not.toBeNull();
|
||||
const parsed = JSON.parse(fs.readFileSync(f!, 'utf-8').trim());
|
||||
expect(parsed.ts).toBeDefined();
|
||||
expect(new Date(parsed.ts).getTime()).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('preserves timestamp when ts field is present', () => {
|
||||
const input = '{"skill":"review","event":"completed","branch":"main","ts":"2025-06-15T10:00:00Z"}';
|
||||
runLog(input);
|
||||
|
||||
const f = findTimelineFile();
|
||||
expect(f).not.toBeNull();
|
||||
const parsed = JSON.parse(fs.readFileSync(f!, 'utf-8').trim());
|
||||
expect(parsed.ts).toBe('2025-06-15T10:00:00Z');
|
||||
});
|
||||
|
||||
test('validates required fields (skill, event) - exits 0 if missing skill', () => {
|
||||
const result = runLog('{"event":"started","branch":"main"}');
|
||||
expect(result.exitCode).toBe(0);
|
||||
|
||||
const f = findTimelineFile();
|
||||
expect(f).toBeNull();
|
||||
});
|
||||
|
||||
test('validates required fields (skill, event) - exits 0 if missing event', () => {
|
||||
const result = runLog('{"skill":"review","branch":"main"}');
|
||||
expect(result.exitCode).toBe(0);
|
||||
|
||||
const f = findTimelineFile();
|
||||
expect(f).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('gstack-timeline-read', () => {
|
||||
test('returns empty output for missing file (exit 0)', () => {
|
||||
const output = runRead();
|
||||
expect(output).toBe('');
|
||||
});
|
||||
|
||||
test('filters by --branch', () => {
|
||||
runLog(JSON.stringify({ skill: 'review', event: 'completed', branch: 'feature-a', outcome: 'approved', ts: '2026-03-28T10:00:00Z' }));
|
||||
runLog(JSON.stringify({ skill: 'ship', event: 'completed', branch: 'feature-b', outcome: 'merged', ts: '2026-03-28T11:00:00Z' }));
|
||||
|
||||
const output = runRead('--branch feature-a');
|
||||
expect(output).toContain('review');
|
||||
expect(output).not.toContain('feature-b');
|
||||
});
|
||||
|
||||
test('limits output with --limit', () => {
|
||||
for (let i = 0; i < 5; i++) {
|
||||
runLog(JSON.stringify({ skill: 'review', event: 'completed', branch: 'main', outcome: 'approved', ts: `2026-03-2${i}T10:00:00Z` }));
|
||||
}
|
||||
|
||||
const unlimited = runRead('--limit 20');
|
||||
const limited = runRead('--limit 2');
|
||||
|
||||
// Count event lines (lines starting with "- ")
|
||||
const unlimitedEvents = unlimited.split('\n').filter(l => l.startsWith('- ')).length;
|
||||
const limitedEvents = limited.split('\n').filter(l => l.startsWith('- ')).length;
|
||||
|
||||
expect(unlimitedEvents).toBe(5);
|
||||
expect(limitedEvents).toBe(2);
|
||||
});
|
||||
});
|
||||
@@ -101,7 +101,7 @@ describe('selectTests', () => {
|
||||
expect(result.reason).toBe('diff');
|
||||
// Should include tests that depend on gen-skill-docs.ts
|
||||
expect(result.selected).toContain('skillmd-setup-discovery');
|
||||
expect(result.selected).toContain('contributor-mode');
|
||||
expect(result.selected).toContain('session-awareness');
|
||||
expect(result.selected).toContain('journey-ideation');
|
||||
// Should NOT include tests that don't depend on it
|
||||
expect(result.selected).not.toContain('retro');
|
||||
@@ -144,7 +144,7 @@ describe('selectTests', () => {
|
||||
const result = selectTests(['SKILL.md.tmpl'], E2E_TOUCHFILES);
|
||||
// Should select the 7 tests that depend on root SKILL.md
|
||||
expect(result.selected).toContain('skillmd-setup-discovery');
|
||||
expect(result.selected).toContain('contributor-mode');
|
||||
expect(result.selected).toContain('session-awareness');
|
||||
expect(result.selected).toContain('session-awareness');
|
||||
// Also selects journey routing tests (SKILL.md.tmpl in their touchfiles)
|
||||
expect(result.selected).toContain('journey-ideation');
|
||||
|
||||
@@ -231,6 +231,9 @@ describe('WorktreeManager', () => {
|
||||
spawnSync('git', ['worktree', 'remove', '--force', oldPath], { cwd: repo, stdio: 'pipe' });
|
||||
// Recreate the directory to simulate orphaned state
|
||||
fs.mkdirSync(oldPath, { recursive: true });
|
||||
// Backdate mtime to simulate a stale worktree (> 1 hour old)
|
||||
const staleTime = new Date(Date.now() - 7200_000);
|
||||
fs.utimesSync(oldRunDir, staleTime, staleTime);
|
||||
|
||||
// New manager should prune the old run's directory
|
||||
const newMgr = new WorktreeManager(repo);
|
||||
|
||||
Reference in New Issue
Block a user