* chore(#604): rename get-shit-done/ runtime directory to gsd-core/ Renames the installed runtime directory `get-shit-done/` to `gsd-core/` so the on-disk name matches the package (`@opengsd/gsd-core`), repo, and binary (`gsd-tools`). The npm package name and binary are unchanged; npx/npm consumers are unaffected. Mechanical (bulk, ~90% of the diff): - `git mv get-shit-done gsd-core` - Swept path/identifier references across the repo via `perl -pe 's/get-shit-done(?!-\w)/gsd-core/g'`. The negative lookahead preserves the five legitimate slug variants that are NOT the directory: get-shit-done-{OLD,cc,classic,cli,redux} (old package/repo names). - Build/manifest wiring: package.json (bin, files, coverage globs), tsconfig.build.json (outDir), ~86 .gitignore build-output entries, stryker.config.mjs, scan-ignore files, install.js path strings. - Frozen (not rewritten): CHANGELOG.md history; translated docs (README.<locale>.md and docs/{ja-JP,ko-KR,pt-BR,zh-CN}/). New logic (review here): - src/installer-migrations/003-rename-get-shit-done-to-gsd-core.cts: a proper ADR-0008 installer migration. On upgrade it walks the legacy `~/.claude/get-shit-done/` tree, classifies each file via the prior install manifest, and emits remove-managed / backup-and-remove for managed files while PRESERVING unknown user-added files. Symlink-safe (skips a symlinked root and symlinked entries; bounds-checks every path under configDir). The framework rolls back on install failure. Emptied dirs may remain (framework has no recursive dir-removal primitive) — documented. - scripts/lint-legacy-dir-name.cjs: CI regression guard forbidding the bare `get-shit-done` directory token (split token to avoid self-match; case- insensitive; `(?!-\w)` lookahead allows the slug variants; allowlists CHANGELOG, translated docs, and `gsd-allow-legacy-name` marker lines). Wired into the lint-tests CI job. - Restored scripts/lint-package-identity-drift.cjs detection regexes (the mechanical sweep had wrongly rewritten the old-name patterns it exists to detect) and marked them as intentional legacy references. - TDD tests for the migration and the guard; do.md slash-command guard regex tightened so a `/gsd-core/bin` path segment is not mistaken for a command; changeset + docs/installer-migrations.md row added. Breaking: the installed runtime path moves `~/.claude/get-shit-done/` -> `~/.claude/gsd-core/`. Migration 003 removes the stale legacy dir's managed files (preserving user files) on upgrade. Users with custom hooks/configs hardcoding the old path must update them. Closes #604 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): unsweep pending changesets + allowlist injection-example docs CI fixes for the rename PR: - Do not sweep pending .changeset/*.md (ephemeral release-note fragments, like CHANGELOG); reverted those body edits so 5 pre-existing malformed fragments (missing type/pr) no longer enter the PR diff and trip docs-lint. Allowlisted .changeset/ in the legacy-name guard accordingly. - Allowlisted TEST-EXAMPLES.md and docs/explanation/security-model.md in prompt-injection-scan.sh: they contain intentional injection examples / security-model prose; the path-reference rewrites are kept. CodeQL alerts on this PR are pre-existing (alert lines unchanged by this PR; none in the new migration/guard) and are out of scope for the rename. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): resolve CodeQL alerts surfaced on this PR The rename diff touched files carrying pre-existing CodeQL findings; per the no-pre-existing-dismissal rule, fixing every surfaced alert rather than waving them off. All behavior-preserving: - scripts/ci-test-scope.cjs: build the config-path match from string .includes() instead of a RegExp over an arg-derived value (js/regex-injection). - src/profile-output.cts: escape backslashes before pipe-escaping desc/safeName so the table-cell escape is complete (js/incomplete-sanitization). - tests/{bug-2643,bug-2808,docs-parity-live-registry}: two-pass HTML-comment strip so a bare/unclosed `<!--` cannot survive (js/incomplete-multi-character-sanitization). - tests/inline-plan-threshold: drop the no-op `\s`->`\s` identity replace, keep the meaningful POSIX-class conversion (js/identity-replacement). Verified: build:lib green; the touched test files + ci-test-scope + profile-output suites pass; lint:legacy-name clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): correctly resolve remaining CodeQL alerts (regex-injection + sanitization) The prior commit's fixes for two alerts were ineffective: - ci-test-scope.cjs js/regex-injection: the alert is the CLI-arg-derived `file` reaching static regex `.test(file)` calls (not the config rule). Removed ALL regex over file/t — startsWith/includes/=== string checks + an isWindowsHint helper — so there is no regex sink for the tainted value. - js/incomplete-multi-character-sanitization (3 test files): a single `.replace(/<!--...-->/g,'')` can let `<!--` re-form. Replaced with a fixpoint loop (replace until stable) plus a final bare-opener strip. Verified: no regex over file/t remains; ci-test-scope + the 3 test suites pass; lint:legacy-name clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): make ci-test-scope + comment-strippers regex-free to clear CodeQL CodeQL flags the regex PATTERNS syntactically (regex-injection on the --files arg split; incomplete-multi-character-sanitization on the <!--...--> replace), so loop fixes do not satisfy it. Made these paths regex-free: - ci-test-scope.cjs splitFiles: char-by-char separator tokenizer (no /[,\\s]+/). - 3 test files: indexOf/slice HTML-comment stripper (no .replace(/<!--/)). Behavior preserved; ci-test-scope + the 3 suites pass; guard clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): unblock security base64 scan on the large rename diff The security job hit its 10m timeout: base64-scan.sh choked on the binary test fixture tests/feat-3594-parser-property-style.test.cjs (embedded NUL/ non-UTF8 bytes -> thousands of bogus blobs + "ignored null byte" warnings), and the ~800-file rename diff is slow to scan regardless. - scripts/base64-scan.sh: skip binary-by-content files (grep -Iq .) — they can't carry base64-obfuscated *text* and feeding NUL bytes through the per-line scanner is pathologically slow. collect_files already filtered binary *extensions*; this catches binary *content* in text extensions. - .github/workflows/security-scan.yml: raise the security job timeout 10m->30m to accommodate very large diffs (the scan itself is unchanged). Verified locally: scan skips the fixture, 0 "ignored null byte" warnings, 0 findings, exit 0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): sweep get-shit-done refs introduced by merging next The branch was updated with next (#614/#384/#618 etc.), which reference the get-shit-done/ dir (still named that on next). Swept the stale references in the merged files to gsd-core so the rename stays consistent and lint:legacy-name passes: - commands/gsd/discuss-phase.md (runtime-launcher shim paths) - src/core.cts (getAgentsDir layout comments) - tests/bug-384-agents-runtime-aware.test.cjs (require path to runtime lib) Verified: guard 0 violations; build green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): exclude gsd-core/ path segments from bug-3683 command cross-ref invariant The #614 runtime-launcher shim added to discuss-phase.md references `${_GSD_RUNTIME_ROOT}/gsd-core/bin/...`. bug-3683's REF_PATTERN excluded path-y refs only via lookbehind, but `}` precedes `/gsd-core/` in the shim, so it mis-read the directory path as a dangling `/gsd-core` command ref (same class as the #604 bug-2954 fix). Added a trailing `(?![\w-]*\/)` so `/gsd-<x>/...` path segments are not treated as slash-command references. Verified locally on BOTH platforms before pushing: - mac (node 26) full suite: 0 failures - gsd-test-runner (linux, node22 image) full suite: 0 failures - bug-3683 + bug-2954 pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): lazily resolve findProjectRoot in gsd-tools (harden flaky CI) CI intermittently failed state.test's gsd-tools subprocess with "findProjectRoot is not a function" (flip-flopping across legs; not reproducible on mac full suite, gsd-test linux full suite, test:unit, or state.test x8). findProjectRoot is a re-export from core.cjs (sourced from project-root.cjs); binding it via destructure at module-load can be undefined under a load-ordering edge. Resolve it lazily at call time via a small wrapper so the lookup happens after core.cjs is fully initialized. Verified green on BOTH platforms before pushing: - mac (node 26) full suite: 0 failures - gsd-test-runner (linux, node22) full suite: 0 failures - state.test.cjs: 106/106; gsd-tools loads cleanly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): allowlist verification-patterns.md placeholder examples in secret scan The rename git-mv'd references/verification-patterns.md into gsd-core/, pulling it into the secret-scan diff. It documents stub/placeholder RED-FLAG env-var examples (illustrative Stripe test-key / database-URL / API-key placeholders) — not real credentials. Added it to .secretscanignore with the strict annotation, mirroring the existing gsd-core/workflows/plan-phase.md exception. Verified locally: secret-scan-lint --strict OK; secret-scan --diff origin/next exits 0 with 0 findings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
662 lines
25 KiB
JavaScript
662 lines
25 KiB
JavaScript
'use strict';
|
|
/**
|
|
* Consolidated tests for the Runtime Artifact Layout Module — install-profiles parity (ADR-3660).
|
|
*
|
|
* Covers:
|
|
* - stageSkillsForProfile / stageAgentsForProfile / stageSkillsForRuntimeAsSkills
|
|
* - resolveProfile — transitive closure + PROFILES map
|
|
* - loadSkillsManifest — frontmatter parsing
|
|
* - readActiveProfile / writeActiveProfile — marker persistence
|
|
*
|
|
* Sources consolidated (4 files deleted):
|
|
* tests/install-profiles-stage.test.cjs
|
|
* tests/install-profiles-resolve.test.cjs
|
|
* tests/install-profiles-manifest.test.cjs
|
|
* tests/install-profiles-marker.test.cjs
|
|
*/
|
|
|
|
const { test, describe } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
|
|
const {
|
|
stageSkillsForProfile,
|
|
stageAgentsForProfile,
|
|
stageSkillsForRuntimeAsSkills,
|
|
cleanupStagedSkills,
|
|
resolveProfile,
|
|
loadSkillsManifest,
|
|
readActiveProfile,
|
|
writeActiveProfile,
|
|
PROFILES,
|
|
STAGED_DIRS,
|
|
} = require('../gsd-core/bin/lib/install-profiles.cjs');
|
|
const { createTempDir, cleanup } = require('./helpers.cjs');
|
|
|
|
const REAL_COMMANDS_DIR = path.join(__dirname, '..', 'commands', 'gsd');
|
|
const REAL_AGENTS_DIR = path.join(__dirname, '..', 'agents');
|
|
|
|
// ─── helpers ────────────────────────────────────────────────────────────────
|
|
|
|
function tmpDir(prefix) {
|
|
return fs.mkdtempSync(path.join(os.tmpdir(), prefix || 'gsd-ip-'));
|
|
}
|
|
|
|
function createFixtureSkillsDir() {
|
|
const tmp = createTempDir('gsd-stage-profile-');
|
|
for (const name of ['plan-phase', 'execute-phase', 'autonomous', 'progress', 'help', 'phase']) {
|
|
fs.writeFileSync(path.join(tmp, `${name}.md`), `# ${name}\n`);
|
|
}
|
|
return tmp;
|
|
}
|
|
|
|
function createFixtureAgentsDir() {
|
|
const tmp = createTempDir('gsd-agents-profile-');
|
|
for (const name of ['gsd-planner', 'gsd-executor', 'gsd-code-reviewer']) {
|
|
fs.writeFileSync(path.join(tmp, `${name}.md`), `# ${name}\n`);
|
|
}
|
|
return tmp;
|
|
}
|
|
|
|
function writeSkill(dir, stem, frontmatter) {
|
|
const content = `---\n${frontmatter}\n---\n\n# body\n`;
|
|
fs.writeFileSync(path.join(dir, `${stem}.md`), content);
|
|
}
|
|
|
|
// ─── stageSkillsForRuntimeAsSkills ──────────────────────────────────────────
|
|
|
|
describe('stageSkillsForRuntimeAsSkills', () => {
|
|
test('is exported as a function', () => {
|
|
assert.strictEqual(typeof stageSkillsForRuntimeAsSkills, 'function');
|
|
});
|
|
|
|
test('registers stagedDir in STAGED_DIRS after staging', (t) => {
|
|
const src = createTempDir('gsd-rta-src-');
|
|
let stagedDir;
|
|
t.after(() => {
|
|
cleanup(src);
|
|
if (stagedDir) cleanupStagedSkills();
|
|
});
|
|
fs.writeFileSync(path.join(src, 'alpha.md'), '# alpha\n');
|
|
cleanupStagedSkills();
|
|
const converter = (content, _skillName) => content;
|
|
stagedDir = stageSkillsForRuntimeAsSkills(src, { skills: '*' }, converter, 'gsd-');
|
|
assert.ok(STAGED_DIRS.has(stagedDir), 'stagedDir must be in STAGED_DIRS');
|
|
});
|
|
|
|
test('non-existent srcCommandsDir returns srcCommandsDir unchanged', () => {
|
|
const ghost = path.join(os.tmpdir(), 'gsd-rta-no-exist-' + Date.now());
|
|
const converter = (content, _skillName) => content;
|
|
const result = stageSkillsForRuntimeAsSkills(ghost, { skills: '*' }, converter, 'gsd-');
|
|
assert.strictEqual(result, ghost);
|
|
});
|
|
|
|
test('empty prefix produces <stem>/SKILL.md without prefix segment', (t) => {
|
|
const src = createTempDir('gsd-rta-src-');
|
|
let stagedDir;
|
|
t.after(() => {
|
|
cleanup(src);
|
|
if (stagedDir) cleanupStagedSkills();
|
|
});
|
|
fs.writeFileSync(path.join(src, 'phase.md'), '# phase\n');
|
|
const converter = (content, _skillName) => content;
|
|
stagedDir = stageSkillsForRuntimeAsSkills(src, { skills: '*' }, converter, '');
|
|
const entries = fs.readdirSync(stagedDir);
|
|
assert.deepStrictEqual(entries, ['phase']);
|
|
const content = fs.readFileSync(path.join(stagedDir, 'phase', 'SKILL.md'), 'utf8');
|
|
assert.strictEqual(content, '# phase\n');
|
|
});
|
|
|
|
test('converter is called with (content, skillName) for each kept skill', (t) => {
|
|
const src = createTempDir('gsd-rta-src-');
|
|
let stagedDir;
|
|
t.after(() => {
|
|
cleanup(src);
|
|
if (stagedDir) cleanupStagedSkills();
|
|
});
|
|
fs.writeFileSync(path.join(src, 'alpha.md'), '# alpha\n');
|
|
fs.writeFileSync(path.join(src, 'beta.md'), '# beta\n');
|
|
const calls = [];
|
|
const converter = (content, skillName) => {
|
|
calls.push([content, skillName]);
|
|
return content;
|
|
};
|
|
stagedDir = stageSkillsForRuntimeAsSkills(src, { skills: '*' }, converter, 'x-');
|
|
assert.strictEqual(calls.length, 2);
|
|
const callMap = Object.fromEntries(calls.map(([c, n]) => [n, c]));
|
|
assert.strictEqual(callMap['x-alpha'], '# alpha\n');
|
|
assert.strictEqual(callMap['x-beta'], '# beta\n');
|
|
});
|
|
|
|
test('skills Set filters: only matching stems land in stagedDir', (t) => {
|
|
const src = createTempDir('gsd-rta-src-');
|
|
let stagedDir;
|
|
t.after(() => {
|
|
cleanup(src);
|
|
if (stagedDir) cleanupStagedSkills();
|
|
});
|
|
for (const name of ['alpha', 'beta', 'phase']) {
|
|
fs.writeFileSync(path.join(src, `${name}.md`), `# ${name}\n`);
|
|
}
|
|
const converter = (content, _skillName) => content;
|
|
stagedDir = stageSkillsForRuntimeAsSkills(src, { skills: new Set(['phase']) }, converter, 'gsd-');
|
|
const entries = fs.readdirSync(stagedDir).sort();
|
|
assert.deepStrictEqual(entries, ['gsd-phase']);
|
|
});
|
|
|
|
test('skills === "*" stages all md files as <prefix><stem>/SKILL.md', (t) => {
|
|
const src = createTempDir('gsd-rta-src-');
|
|
let stagedDir;
|
|
t.after(() => {
|
|
cleanup(src);
|
|
if (stagedDir) cleanupStagedSkills();
|
|
});
|
|
for (const name of ['alpha', 'beta', 'gamma']) {
|
|
fs.writeFileSync(path.join(src, `${name}.md`), `# ${name}\n`);
|
|
}
|
|
const converter = (content, _skillName) => content;
|
|
stagedDir = stageSkillsForRuntimeAsSkills(src, { skills: '*' }, converter, 'gsd-');
|
|
const entries = fs.readdirSync(stagedDir).sort();
|
|
assert.deepStrictEqual(entries, ['gsd-alpha', 'gsd-beta', 'gsd-gamma']);
|
|
for (const name of ['alpha', 'beta', 'gamma']) {
|
|
const content = fs.readFileSync(path.join(stagedDir, `gsd-${name}`, 'SKILL.md'), 'utf8');
|
|
assert.strictEqual(content, `# ${name}\n`);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── stageSkillsForProfile ───────────────────────────────────────────────────
|
|
|
|
describe('stageSkillsForProfile', () => {
|
|
test('full profile (skills === "*") returns srcDir unchanged', (t) => {
|
|
const src = createFixtureSkillsDir();
|
|
t.after(() => cleanup(src));
|
|
const result = stageSkillsForProfile(src, { skills: '*', agents: new Set() });
|
|
assert.strictEqual(result, src);
|
|
});
|
|
|
|
test('profile with Set copies only member files', (t) => {
|
|
const src = createFixtureSkillsDir();
|
|
let staged;
|
|
t.after(() => {
|
|
cleanup(src);
|
|
if (staged) cleanupStagedSkills();
|
|
});
|
|
const skills = new Set(['plan-phase', 'help', 'phase']);
|
|
staged = stageSkillsForProfile(src, { skills, agents: new Set() });
|
|
assert.notStrictEqual(staged, src);
|
|
const files = fs.readdirSync(staged).sort();
|
|
assert.deepStrictEqual(files, ['help.md', 'phase.md', 'plan-phase.md']);
|
|
});
|
|
|
|
test('preserves file content byte-for-byte', (t) => {
|
|
const src = createFixtureSkillsDir();
|
|
const content = '# plan-phase special content\n\nsome body\n';
|
|
fs.writeFileSync(path.join(src, 'plan-phase.md'), content);
|
|
let staged;
|
|
t.after(() => {
|
|
cleanup(src);
|
|
if (staged) cleanupStagedSkills();
|
|
});
|
|
const skills = new Set(['plan-phase']);
|
|
staged = stageSkillsForProfile(src, { skills, agents: new Set() });
|
|
const copied = fs.readFileSync(path.join(staged, 'plan-phase.md'), 'utf8');
|
|
assert.strictEqual(copied, content);
|
|
});
|
|
|
|
test('non-existent srcDir returns srcDir unchanged', () => {
|
|
const ghost = path.join(os.tmpdir(), 'gsd-no-exist-' + Date.now());
|
|
const result = stageSkillsForProfile(ghost, { skills: new Set(['help']), agents: new Set() });
|
|
assert.strictEqual(result, ghost);
|
|
});
|
|
|
|
test('empty skills Set produces empty staged dir', (t) => {
|
|
const src = createFixtureSkillsDir();
|
|
let staged;
|
|
t.after(() => {
|
|
cleanup(src);
|
|
if (staged) cleanupStagedSkills();
|
|
});
|
|
staged = stageSkillsForProfile(src, { skills: new Set(), agents: new Set() });
|
|
const files = fs.readdirSync(staged);
|
|
assert.deepStrictEqual(files, []);
|
|
});
|
|
});
|
|
|
|
// ─── stageAgentsForProfile ───────────────────────────────────────────────────
|
|
|
|
describe('stageAgentsForProfile', () => {
|
|
test('full profile (skills === "*") returns srcDir unchanged', (t) => {
|
|
const src = createFixtureAgentsDir();
|
|
t.after(() => cleanup(src));
|
|
const result = stageAgentsForProfile(src, { skills: '*', agents: new Set() });
|
|
assert.strictEqual(result, src);
|
|
});
|
|
|
|
test('non-full profile with empty agents Set produces empty staged dir', (t) => {
|
|
const src = createFixtureAgentsDir();
|
|
let staged;
|
|
t.after(() => {
|
|
cleanup(src);
|
|
if (staged) cleanupStagedSkills();
|
|
});
|
|
staged = stageAgentsForProfile(src, { skills: new Set(['help']), agents: new Set() });
|
|
const files = fs.readdirSync(staged);
|
|
assert.deepStrictEqual(files, [], 'no agents for non-full profile by default');
|
|
});
|
|
|
|
test('non-full profile with agents Set copies only member agent files', (t) => {
|
|
const src = createFixtureAgentsDir();
|
|
let staged;
|
|
t.after(() => {
|
|
cleanup(src);
|
|
if (staged) cleanupStagedSkills();
|
|
});
|
|
const agents = new Set(['gsd-planner']);
|
|
staged = stageAgentsForProfile(src, { skills: new Set(['plan-phase']), agents });
|
|
const files = fs.readdirSync(staged).sort();
|
|
assert.deepStrictEqual(files, ['gsd-planner.md']);
|
|
});
|
|
|
|
test('non-existent srcAgentsDir returns srcAgentsDir unchanged', () => {
|
|
const ghost = path.join(os.tmpdir(), 'gsd-agents-no-exist-' + Date.now());
|
|
const result = stageAgentsForProfile(ghost, { skills: new Set(), agents: new Set() });
|
|
assert.strictEqual(result, ghost);
|
|
});
|
|
|
|
test('standard profile — stageAgentsForProfile copies exactly the agents in resolvedProfile.agents', (t) => {
|
|
if (!fs.existsSync(REAL_AGENTS_DIR) || !fs.existsSync(REAL_COMMANDS_DIR)) return;
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const resolved = resolveProfile({ modes: ['standard'], manifest });
|
|
assert.ok(resolved.agents instanceof Set && resolved.agents.size > 0,
|
|
'standard profile must have >0 agents (plan-phase calls gsd-planner etc)');
|
|
let staged;
|
|
t.after(() => {
|
|
if (staged) cleanupStagedSkills();
|
|
});
|
|
staged = stageAgentsForProfile(REAL_AGENTS_DIR, resolved);
|
|
const stagedFiles = new Set(
|
|
fs.readdirSync(staged).filter(f => f.endsWith('.md')).map(f => f.slice(0, -3))
|
|
);
|
|
for (const stem of stagedFiles) {
|
|
assert.ok(resolved.agents.has(stem), `staged agent ${stem} not in resolved.agents`);
|
|
}
|
|
for (const agentStem of resolved.agents) {
|
|
const exists = fs.existsSync(path.join(REAL_AGENTS_DIR, `${agentStem}.md`));
|
|
if (exists) {
|
|
assert.ok(stagedFiles.has(agentStem), `resolved agent ${agentStem} missing from staged dir`);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('full profile staging returns real agents dir unchanged', () => {
|
|
if (!fs.existsSync(REAL_AGENTS_DIR)) return;
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const resolved = resolveProfile({ modes: ['full'], manifest });
|
|
const result = stageAgentsForProfile(REAL_AGENTS_DIR, resolved);
|
|
assert.strictEqual(result, REAL_AGENTS_DIR);
|
|
});
|
|
});
|
|
|
|
// ─── PROFILES map + resolveProfile ──────────────────────────────────────────
|
|
|
|
describe('PROFILES map', () => {
|
|
test('PROFILES is frozen', () => {
|
|
assert.ok(Object.isFrozen(PROFILES));
|
|
});
|
|
|
|
test('PROFILES has core, standard, full keys', () => {
|
|
assert.ok('core' in PROFILES, 'PROFILES.core missing');
|
|
assert.ok('standard' in PROFILES, 'PROFILES.standard missing');
|
|
assert.ok('full' in PROFILES, 'PROFILES.full missing');
|
|
});
|
|
|
|
test('PROFILES.core contains the 8 main-loop skills (including phase and surface)', () => {
|
|
const core = PROFILES.core;
|
|
assert.ok(Array.isArray(core), 'core should be an array');
|
|
const sorted = [...core].sort();
|
|
assert.deepStrictEqual(sorted, [
|
|
'discuss-phase',
|
|
'execute-phase',
|
|
'help',
|
|
'new-project',
|
|
'phase',
|
|
'plan-phase',
|
|
'surface',
|
|
'update',
|
|
]);
|
|
});
|
|
|
|
test('PROFILES.full is the sentinel "*"', () => {
|
|
assert.strictEqual(PROFILES.full, '*');
|
|
});
|
|
|
|
test('PROFILES.standard contains at least the core skills', () => {
|
|
const core = new Set(PROFILES.core);
|
|
const standard = PROFILES.standard;
|
|
assert.ok(Array.isArray(standard), 'standard should be an array');
|
|
for (const s of core) {
|
|
assert.ok(standard.includes(s), `standard should include core skill: ${s}`);
|
|
}
|
|
});
|
|
|
|
test('PROFILES.standard has at least 10 skills', () => {
|
|
assert.ok(PROFILES.standard.length >= 10, `standard should have >=10 skills, got ${PROFILES.standard.length}`);
|
|
});
|
|
});
|
|
|
|
describe('resolveProfile', () => {
|
|
test('defaults to full when called with no modes arg', () => {
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const result = resolveProfile({ manifest });
|
|
assert.strictEqual(result.name, 'full');
|
|
assert.strictEqual(result.skills, '*');
|
|
});
|
|
|
|
test('resolves core profile — returns 8+ skills, all base stems present', () => {
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const result = resolveProfile({ modes: ['core'], manifest });
|
|
assert.strictEqual(result.name, 'core');
|
|
assert.ok(result.skills instanceof Set, 'skills should be a Set');
|
|
// core has 8 base skills (includes surface as of #3735).
|
|
assert.ok(result.skills.size >= 8, `core closure should have >=8 skills, got ${result.skills.size}`);
|
|
for (const s of PROFILES.core) {
|
|
assert.ok(result.skills.has(s), `core closure should include ${s}`);
|
|
}
|
|
assert.ok(result.skills.has('phase'), 'core closure must include phase');
|
|
});
|
|
|
|
test('resolves standard profile — superset of core', () => {
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const coreResult = resolveProfile({ modes: ['core'], manifest });
|
|
const stdResult = resolveProfile({ modes: ['standard'], manifest });
|
|
assert.strictEqual(stdResult.name, 'standard');
|
|
assert.ok(stdResult.skills instanceof Set);
|
|
assert.ok(stdResult.skills.size >= coreResult.skills.size, 'standard should have >= skills than core');
|
|
for (const s of coreResult.skills) {
|
|
assert.ok(stdResult.skills.has(s), `standard must include core skill: ${s}`);
|
|
}
|
|
});
|
|
|
|
test('resolves full profile — returns sentinel', () => {
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const result = resolveProfile({ modes: ['full'], manifest });
|
|
assert.strictEqual(result.name, 'full');
|
|
assert.strictEqual(result.skills, '*');
|
|
});
|
|
|
|
test('composable profiles — core,standard union is same as standard', () => {
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const stdResult = resolveProfile({ modes: ['standard'], manifest });
|
|
const composed = resolveProfile({ modes: ['core', 'standard'], manifest });
|
|
assert.ok(composed.name.includes('core') && composed.name.includes('standard'),
|
|
`composed name should include both, got: ${composed.name}`);
|
|
for (const s of stdResult.skills) {
|
|
assert.ok(composed.skills.has(s), `composed should include standard skill: ${s}`);
|
|
}
|
|
});
|
|
|
|
test('transitive closure: skill that requires phase pulls in phase', () => {
|
|
const manifest = new Map([
|
|
['discuss-phase', ['phase']],
|
|
['phase', []],
|
|
['help', []],
|
|
]);
|
|
const miniProfiles = { core: ['discuss-phase', 'help'], full: '*', standard: ['discuss-phase', 'help'] };
|
|
const result = resolveProfile({ modes: ['core'], manifest, _profilesOverride: miniProfiles });
|
|
assert.ok(result.skills.has('phase'), 'phase should be pulled in via closure from discuss-phase');
|
|
assert.ok(result.skills.has('discuss-phase'));
|
|
assert.ok(result.skills.has('help'));
|
|
});
|
|
|
|
test('deep transitive closure works (A→B→C pulls in C)', () => {
|
|
const manifest = new Map([
|
|
['a', ['b']],
|
|
['b', ['c']],
|
|
['c', []],
|
|
]);
|
|
const miniProfiles = { core: ['a'], full: '*', standard: ['a'] };
|
|
const result = resolveProfile({ modes: ['core'], manifest, _profilesOverride: miniProfiles });
|
|
assert.ok(result.skills.has('a'));
|
|
assert.ok(result.skills.has('b'));
|
|
assert.ok(result.skills.has('c'));
|
|
});
|
|
|
|
test('result has agents Set', () => {
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const result = resolveProfile({ modes: ['core'], manifest });
|
|
assert.ok(result.agents instanceof Set, 'result should have agents Set');
|
|
});
|
|
|
|
test('standard — agents Set is non-empty; gsd-planner and gsd-plan-checker present', () => {
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const result = resolveProfile({ modes: ['standard'], manifest });
|
|
assert.ok(result.agents instanceof Set, 'agents should be a Set');
|
|
assert.ok(result.agents.size > 0, `standard profile should have >0 agents, got ${result.agents.size}`);
|
|
assert.ok(result.agents.has('gsd-planner'), 'standard should include gsd-planner');
|
|
assert.ok(result.agents.has('gsd-plan-checker'), 'standard should include gsd-plan-checker');
|
|
});
|
|
|
|
test('full — agents is a Set (full staging uses srcDir directly)', () => {
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const result = resolveProfile({ modes: ['full'], manifest });
|
|
assert.strictEqual(result.skills, '*');
|
|
assert.ok(result.agents instanceof Set, 'agents should still be a Set for full');
|
|
});
|
|
|
|
test('agents are derived from real manifest body text (gsd-planner from plan-phase)', () => {
|
|
const realManifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const result = resolveProfile({ modes: ['standard'], manifest: realManifest });
|
|
assert.ok(result.agents.has('gsd-planner'), 'gsd-planner should be derived from plan-phase body');
|
|
});
|
|
|
|
test('agents transitively closed — plan-phase in standard brings its agents', () => {
|
|
const manifest = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
const result = resolveProfile({ modes: ['standard'], manifest });
|
|
assert.ok(result.agents.has('gsd-planner'));
|
|
});
|
|
});
|
|
|
|
// ─── loadSkillsManifest ──────────────────────────────────────────────────────
|
|
|
|
describe('loadSkillsManifest', () => {
|
|
test('returns a Map', () => {
|
|
const dir = tmpDir('gsd-manifest-fixture-');
|
|
try {
|
|
const m = loadSkillsManifest(dir);
|
|
assert.ok(m instanceof Map, 'should return a Map');
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('skill with no requires: frontmatter maps to empty array', () => {
|
|
const dir = tmpDir('gsd-manifest-fixture-');
|
|
try {
|
|
writeSkill(dir, 'help', 'name: gsd:help\ndescription: Help text');
|
|
const m = loadSkillsManifest(dir);
|
|
assert.ok(m.has('help'), 'help should be in manifest');
|
|
assert.deepStrictEqual(m.get('help'), []);
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('skill with requires: single value maps to array of one', () => {
|
|
const dir = tmpDir('gsd-manifest-fixture-');
|
|
try {
|
|
writeSkill(dir, 'add-tests', 'name: gsd:add-tests\ndescription: Add tests\nrequires: [phase]');
|
|
const m = loadSkillsManifest(dir);
|
|
assert.ok(m.has('add-tests'));
|
|
assert.deepStrictEqual(m.get('add-tests'), ['phase']);
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('skill with requires: multiple values maps to full array', () => {
|
|
const dir = tmpDir('gsd-manifest-fixture-');
|
|
try {
|
|
writeSkill(dir, 'plan-phase', 'name: gsd:plan-phase\ndescription: Plan\nrequires: [discuss-phase, phase, review, update]');
|
|
const m = loadSkillsManifest(dir);
|
|
assert.deepStrictEqual(m.get('plan-phase'), ['discuss-phase', 'phase', 'review', 'update']);
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('ignores non-.md files in the dir', () => {
|
|
const dir = tmpDir('gsd-manifest-fixture-');
|
|
try {
|
|
writeSkill(dir, 'help', 'name: gsd:help\ndescription: Help');
|
|
fs.writeFileSync(path.join(dir, 'README.txt'), 'not a skill');
|
|
fs.writeFileSync(path.join(dir, 'notes.json'), '{}');
|
|
const m = loadSkillsManifest(dir);
|
|
assert.ok(m.has('help'));
|
|
assert.ok(!m.has('README'));
|
|
assert.ok(!m.has('notes'));
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('empty dir returns empty Map', () => {
|
|
const dir = tmpDir('gsd-manifest-fixture-');
|
|
try {
|
|
const m = loadSkillsManifest(dir);
|
|
assert.strictEqual(m.size, 0);
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('skill with requires: empty array maps to empty array', () => {
|
|
const dir = tmpDir('gsd-manifest-fixture-');
|
|
try {
|
|
writeSkill(dir, 'explore', 'name: gsd:explore\ndescription: Explore\nrequires: []');
|
|
const m = loadSkillsManifest(dir);
|
|
assert.deepStrictEqual(m.get('explore'), []);
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('loads real commands/gsd/ directory: >=60 skills, discuss-phase deps correct, help has no requires', () => {
|
|
const m = loadSkillsManifest(REAL_COMMANDS_DIR);
|
|
// Use prefix/set assertion, not a hardcoded count — avoids stale-count anti-pattern
|
|
assert.ok(m.size >= 60, `expected >=60 skills, got ${m.size}`);
|
|
const depsDP = m.get('discuss-phase');
|
|
assert.ok(Array.isArray(depsDP), 'discuss-phase should be in manifest');
|
|
assert.ok(depsDP.includes('phase'), 'discuss-phase should require phase');
|
|
assert.ok(depsDP.includes('config'), 'discuss-phase should require config');
|
|
assert.deepStrictEqual(m.get('help'), []);
|
|
});
|
|
});
|
|
|
|
// ─── readActiveProfile / writeActiveProfile ──────────────────────────────────
|
|
|
|
describe('readActiveProfile / writeActiveProfile', () => {
|
|
test('write then read round-trips the profile name', () => {
|
|
const dir = tmpDir('gsd-marker-');
|
|
try {
|
|
writeActiveProfile(dir, 'standard');
|
|
assert.strictEqual(readActiveProfile(dir), 'standard');
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('round-trips "core" profile', () => {
|
|
const dir = tmpDir('gsd-marker-');
|
|
try {
|
|
writeActiveProfile(dir, 'core');
|
|
assert.strictEqual(readActiveProfile(dir), 'core');
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('round-trips composed profiles "core,audit"', () => {
|
|
const dir = tmpDir('gsd-marker-');
|
|
try {
|
|
writeActiveProfile(dir, 'core,audit');
|
|
assert.strictEqual(readActiveProfile(dir), 'core,audit');
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('round-trips "full"', () => {
|
|
const dir = tmpDir('gsd-marker-');
|
|
try {
|
|
writeActiveProfile(dir, 'full');
|
|
assert.strictEqual(readActiveProfile(dir), 'full');
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('missing marker file returns null (not throws)', () => {
|
|
const dir = tmpDir('gsd-marker-');
|
|
try {
|
|
const result = readActiveProfile(dir);
|
|
assert.strictEqual(result, null);
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('non-existent directory returns null (not throws)', () => {
|
|
const ghost = path.join(os.tmpdir(), 'gsd-marker-no-exist-' + Date.now());
|
|
const result = readActiveProfile(ghost);
|
|
assert.strictEqual(result, null);
|
|
});
|
|
|
|
test('corrupt marker content (invalid chars) returns null', () => {
|
|
const dir = tmpDir('gsd-marker-');
|
|
try {
|
|
fs.writeFileSync(path.join(dir, '.gsd-profile'), 'profile with spaces and !!!\n');
|
|
const result = readActiveProfile(dir);
|
|
assert.strictEqual(result, null);
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('empty marker file returns null', () => {
|
|
const dir = tmpDir('gsd-marker-');
|
|
try {
|
|
fs.writeFileSync(path.join(dir, '.gsd-profile'), '');
|
|
const result = readActiveProfile(dir);
|
|
assert.strictEqual(result, null);
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('writeActiveProfile creates the directory if it does not exist', () => {
|
|
const base = tmpDir('gsd-marker-base-');
|
|
const nested = path.join(base, 'skills', '.claude');
|
|
try {
|
|
writeActiveProfile(nested, 'standard');
|
|
assert.ok(fs.existsSync(nested), 'directory should be created');
|
|
assert.strictEqual(readActiveProfile(nested), 'standard');
|
|
} finally {
|
|
cleanup(base);
|
|
}
|
|
});
|
|
|
|
test('overwrites a previously written profile', () => {
|
|
const dir = tmpDir('gsd-marker-');
|
|
try {
|
|
writeActiveProfile(dir, 'core');
|
|
writeActiveProfile(dir, 'full');
|
|
assert.strictEqual(readActiveProfile(dir), 'full');
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
});
|