* refactor(#1734): extract install engine from bin/install.js (ADR-1239 Phase B deep move) Relocate the runtime-artifact install cluster out of the 12,490-line bin/install.js into a dedicated src/install-engine.cts -> install-engine.cjs: installRuntimeArtifacts, uninstallRuntimeArtifacts, installOpencodeFamilySkills, and their cluster helpers (_copyStaged, snapshot/restore, legacy migration, GSD-entry pruning, preserve/restoreUserArtifacts, OpenCode-family converters, USER_OWNED_ARTIFACTS). - bin/install.js imports the engine and re-exports the moved symbols for back-compat; getCommitAttribution STAYS in install.js (impure config I/O + argv explicitConfigDir global) and is injected via a resolveAttribution param. - 17 test files migrated to import the moved symbols from the engine. - Bookkeeping: eslint built-artifact ignore, .gitignore, INVENTORY manifest+row, CONTEXT.md Install Engine Module glossary seam. Behaviour-preserving: install output is byte-identical for all 16 runtimes (golden-parity harness #1730) — the only delta is the new install-engine.cjs file shipping in the installed gsd-core/bin/lib/ tree. Closes #1734 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore(#1734): backfill changeset PR number (#1735) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: review-bot <review-bot@gsd>
318 lines
11 KiB
JavaScript
318 lines
11 KiB
JavaScript
// allow-test-rule: source-text-is-the-product
|
|
// Reads .md/.json/.yml product files whose deployed text IS what the
|
|
// runtime loads — testing text content tests the deployed contract.
|
|
|
|
/**
|
|
* GSD Tools Tests - Qwen Code Skills Migration
|
|
*
|
|
* Tests for installing GSD for Qwen Code using the standard
|
|
* skills/gsd-xxx/SKILL.md format (same open standard as Claude Code 2.1.88+).
|
|
*
|
|
* Uses node:test and node:assert (NOT Jest).
|
|
*/
|
|
|
|
process.env.GSD_TEST_MODE = '1';
|
|
|
|
const { test, describe, beforeEach, afterEach } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const fs = require('fs');
|
|
|
|
const {
|
|
convertClaudeCommandToClaudeSkill,
|
|
} = require('../bin/install.js');
|
|
|
|
const { installRuntimeArtifacts } = require('../gsd-core/bin/lib/install-engine.cjs');
|
|
|
|
const {
|
|
loadSkillsManifest,
|
|
resolveProfile,
|
|
} = require('../gsd-core/bin/lib/install-profiles.cjs');
|
|
|
|
const { cleanup } = require('./helpers.cjs');
|
|
|
|
const manifest = loadSkillsManifest();
|
|
const resolvedProfileFull = resolveProfile({ modes: [], manifest });
|
|
|
|
// ─── convertClaudeCommandToClaudeSkill (used by Qwen via copyCommandsAsClaudeSkills) ──
|
|
|
|
describe('Qwen Code: convertClaudeCommandToClaudeSkill', () => {
|
|
test('preserves allowed-tools multiline YAML list', () => {
|
|
const input = [
|
|
'---',
|
|
'name: gsd:next',
|
|
'description: Advance to the next step',
|
|
'allowed-tools:',
|
|
' - Read',
|
|
' - Bash',
|
|
' - Grep',
|
|
'---',
|
|
'',
|
|
'Body content here.',
|
|
].join('\n');
|
|
|
|
const result = convertClaudeCommandToClaudeSkill(input, 'gsd-next');
|
|
assert.ok(result.includes('allowed-tools:'), 'allowed-tools field is present');
|
|
assert.ok(result.includes('Read'), 'Read tool preserved');
|
|
assert.ok(result.includes('Bash'), 'Bash tool preserved');
|
|
assert.ok(result.includes('Grep'), 'Grep tool preserved');
|
|
});
|
|
|
|
test('preserves argument-hint', () => {
|
|
const input = [
|
|
'---',
|
|
'name: gsd:debug',
|
|
'description: Debug issues',
|
|
'argument-hint: "[issue description]"',
|
|
'allowed-tools:',
|
|
' - Read',
|
|
' - Bash',
|
|
'---',
|
|
'',
|
|
'Debug body.',
|
|
].join('\n');
|
|
|
|
const result = convertClaudeCommandToClaudeSkill(input, 'gsd-debug');
|
|
assert.ok(result.includes('argument-hint:'), 'argument-hint field is present');
|
|
assert.ok(
|
|
result.includes('[issue description]'),
|
|
'argument-hint value preserved'
|
|
);
|
|
});
|
|
|
|
test('emits hyphen-form name (gsd-<cmd>) from hyphen-form dir (#2808)', () => {
|
|
const input = [
|
|
'---',
|
|
'name: gsd:next',
|
|
'description: Advance workflow',
|
|
'---',
|
|
'',
|
|
'Body.',
|
|
].join('\n');
|
|
|
|
// Directory name is gsd-next (hyphen, Windows-safe), frontmatter name is
|
|
// gsd-next (hyphen, #2808 — canonical invocation form for Claude Code autocomplete).
|
|
const result = convertClaudeCommandToClaudeSkill(input, 'gsd-next');
|
|
assert.ok(result.includes('name: gsd-next'), 'frontmatter name uses hyphen form (#2808)');
|
|
});
|
|
|
|
test('preserves body content unchanged', () => {
|
|
const body = '\n<objective>\nDo the thing.\n</objective>\r?\n\n<process>\nStep 1.\nStep 2.\n</process>\n';
|
|
const input = [
|
|
'---',
|
|
'name: gsd:test',
|
|
'description: Test command',
|
|
'---',
|
|
body,
|
|
].join('');
|
|
|
|
const result = convertClaudeCommandToClaudeSkill(input, 'gsd-test');
|
|
assert.ok(result.includes('<objective>'), 'objective tag preserved');
|
|
assert.ok(result.includes('Do the thing.'), 'body text preserved');
|
|
assert.ok(result.includes('<process>'), 'process tag preserved');
|
|
});
|
|
|
|
test('produces valid SKILL.md frontmatter starting with ---', () => {
|
|
const input = [
|
|
'---',
|
|
'name: gsd:plan',
|
|
'description: Plan a phase',
|
|
'---',
|
|
'',
|
|
'Plan body.',
|
|
].join('\n');
|
|
|
|
const result = convertClaudeCommandToClaudeSkill(input, 'gsd-plan');
|
|
assert.ok(result.startsWith('---\n'), 'frontmatter starts with ---');
|
|
assert.ok(result.includes('\n---\n'), 'frontmatter closes with ---');
|
|
});
|
|
});
|
|
|
|
// ─── installRuntimeArtifacts (used for Qwen skills install) ─────────────────
|
|
|
|
describe('Qwen Code: installRuntimeArtifacts', () => {
|
|
let tmpDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-qwen-test-'));
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('creates skills/gsd-xxx/SKILL.md directory structure', () => {
|
|
// Create source command files
|
|
const srcDir = path.join(tmpDir, 'src', 'commands', 'gsd');
|
|
fs.mkdirSync(srcDir, { recursive: true });
|
|
fs.writeFileSync(path.join(srcDir, 'quick.md'), [
|
|
'---',
|
|
'name: gsd:quick',
|
|
'description: Execute a quick task',
|
|
'allowed-tools:',
|
|
' - Read',
|
|
' - Bash',
|
|
'---',
|
|
'',
|
|
'<objective>Quick task body</objective>',
|
|
].join('\n'));
|
|
|
|
const configDir = path.join(tmpDir, 'dest');
|
|
fs.mkdirSync(configDir, { recursive: true });
|
|
// Redirect findInstallSourceRoot to the test's custom srcDir
|
|
fs.writeFileSync(path.join(configDir, '.gsd-source'), srcDir);
|
|
|
|
installRuntimeArtifacts('qwen', configDir, 'global', resolvedProfileFull);
|
|
|
|
// Qwen layout: skills/gsd-<stem>/SKILL.md (destSubpath='skills', prefix='gsd-')
|
|
const skillPath = path.join(configDir, 'skills', 'gsd-quick', 'SKILL.md');
|
|
assert.ok(fs.existsSync(skillPath), 'gsd-quick/SKILL.md exists');
|
|
|
|
// Verify content
|
|
const content = fs.readFileSync(skillPath, 'utf8');
|
|
assert.ok(content.includes('name: gsd-quick'), 'frontmatter name uses hyphen form (#2808)');
|
|
assert.ok(content.includes('description:'), 'description present');
|
|
assert.ok(content.includes('allowed-tools:'), 'allowed-tools preserved');
|
|
assert.ok(content.includes('<objective>'), 'body content preserved');
|
|
});
|
|
|
|
test('replaces ~/.claude/ paths via applyRuntimeContentRewritesInPlace', () => {
|
|
const srcDir = path.join(tmpDir, 'src', 'commands', 'gsd');
|
|
fs.mkdirSync(srcDir, { recursive: true });
|
|
fs.writeFileSync(path.join(srcDir, 'next.md'), [
|
|
'---',
|
|
'name: gsd:next',
|
|
'description: Next step',
|
|
'---',
|
|
'',
|
|
'Reference: @~/.claude/gsd-core/workflows/next.md',
|
|
].join('\n'));
|
|
|
|
const configDir = path.join(tmpDir, 'dest');
|
|
fs.mkdirSync(configDir, { recursive: true });
|
|
fs.writeFileSync(path.join(configDir, '.gsd-source'), srcDir);
|
|
|
|
installRuntimeArtifacts('qwen', configDir, 'global', resolvedProfileFull);
|
|
|
|
const content = fs.readFileSync(path.join(configDir, 'skills', 'gsd-next', 'SKILL.md'), 'utf8');
|
|
assert.ok(!content.includes('~/.claude/'), 'old claude tilde-path removed');
|
|
assert.ok(!content.includes('$HOME/.claude/'), 'old claude $HOME-path not present');
|
|
});
|
|
|
|
test('replaces $HOME/.claude/ paths via applyRuntimeContentRewritesInPlace', () => {
|
|
const srcDir = path.join(tmpDir, 'src', 'commands', 'gsd');
|
|
fs.mkdirSync(srcDir, { recursive: true });
|
|
fs.writeFileSync(path.join(srcDir, 'plan.md'), [
|
|
'---',
|
|
'name: gsd:plan',
|
|
'description: Plan phase',
|
|
'---',
|
|
'',
|
|
'Reference: $HOME/.claude/gsd-core/workflows/plan.md',
|
|
].join('\n'));
|
|
|
|
const configDir = path.join(tmpDir, 'dest');
|
|
fs.mkdirSync(configDir, { recursive: true });
|
|
fs.writeFileSync(path.join(configDir, '.gsd-source'), srcDir);
|
|
|
|
installRuntimeArtifacts('qwen', configDir, 'global', resolvedProfileFull);
|
|
|
|
const content = fs.readFileSync(path.join(configDir, 'skills', 'gsd-plan', 'SKILL.md'), 'utf8');
|
|
assert.ok(!content.includes('$HOME/.claude/'), 'old claude $HOME-path removed');
|
|
assert.ok(!content.includes('~/.claude/'), 'old claude tilde-path not present');
|
|
});
|
|
|
|
test('removes stale gsd- skills before installing new ones', () => {
|
|
const srcDir = path.join(tmpDir, 'src', 'commands', 'gsd');
|
|
fs.mkdirSync(srcDir, { recursive: true });
|
|
fs.writeFileSync(path.join(srcDir, 'quick.md'), [
|
|
'---',
|
|
'name: gsd:quick',
|
|
'description: Quick task',
|
|
'---',
|
|
'',
|
|
'Body',
|
|
].join('\n'));
|
|
|
|
const configDir = path.join(tmpDir, 'dest');
|
|
fs.mkdirSync(configDir, { recursive: true });
|
|
fs.writeFileSync(path.join(configDir, '.gsd-source'), srcDir);
|
|
|
|
// Pre-create a stale skill at the new layout location
|
|
const staleSkillDir = path.join(configDir, 'skills', 'gsd-old-skill');
|
|
fs.mkdirSync(staleSkillDir, { recursive: true });
|
|
fs.writeFileSync(path.join(staleSkillDir, 'SKILL.md'), 'old');
|
|
|
|
installRuntimeArtifacts('qwen', configDir, 'global', resolvedProfileFull);
|
|
|
|
assert.ok(!fs.existsSync(staleSkillDir), 'stale skill removed');
|
|
assert.ok(fs.existsSync(path.join(configDir, 'skills', 'gsd-quick', 'SKILL.md')), 'new skill installed');
|
|
});
|
|
|
|
test('preserves agent field in frontmatter', () => {
|
|
const srcDir = path.join(tmpDir, 'src', 'commands', 'gsd');
|
|
fs.mkdirSync(srcDir, { recursive: true });
|
|
fs.writeFileSync(path.join(srcDir, 'execute.md'), [
|
|
'---',
|
|
'name: gsd:execute',
|
|
'description: Execute phase',
|
|
'agent: gsd-executor',
|
|
'allowed-tools:',
|
|
' - Read',
|
|
' - Bash',
|
|
' - Task',
|
|
'---',
|
|
'',
|
|
'Execute body',
|
|
].join('\n'));
|
|
|
|
const configDir = path.join(tmpDir, 'dest');
|
|
fs.mkdirSync(configDir, { recursive: true });
|
|
fs.writeFileSync(path.join(configDir, '.gsd-source'), srcDir);
|
|
|
|
installRuntimeArtifacts('qwen', configDir, 'global', resolvedProfileFull);
|
|
|
|
const content = fs.readFileSync(path.join(configDir, 'skills', 'gsd-execute', 'SKILL.md'), 'utf8');
|
|
assert.ok(content.includes('agent: gsd-executor'), 'agent field preserved');
|
|
});
|
|
});
|
|
|
|
// ─── Integration: SKILL.md format validation ────────────────────────────────
|
|
|
|
describe('Qwen Code: SKILL.md format validation', () => {
|
|
test('SKILL.md frontmatter is valid YAML structure', () => {
|
|
const input = [
|
|
'---',
|
|
'name: gsd:review',
|
|
'description: Code review with quality checks',
|
|
'argument-hint: "[PR number or branch]"',
|
|
'agent: gsd-code-reviewer',
|
|
'allowed-tools:',
|
|
' - Read',
|
|
' - Grep',
|
|
' - Bash',
|
|
'---',
|
|
'',
|
|
'<objective>Review code</objective>',
|
|
].join('\n');
|
|
|
|
const result = convertClaudeCommandToClaudeSkill(input, 'gsd-review');
|
|
|
|
// Parse the frontmatter
|
|
const fmMatch = result.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
assert.ok(fmMatch, 'has frontmatter block');
|
|
|
|
const fmLines = fmMatch[1].split(/\r?\n/);
|
|
const hasName = fmLines.some(l => l.startsWith('name: gsd-review'));
|
|
const hasDesc = fmLines.some(l => l.startsWith('description:'));
|
|
const hasAgent = fmLines.some(l => l.startsWith('agent:'));
|
|
const hasTools = fmLines.some(l => l.startsWith('allowed-tools:'));
|
|
|
|
assert.ok(hasName, 'name field correct');
|
|
assert.ok(hasDesc, 'description field present');
|
|
assert.ok(hasAgent, 'agent field present');
|
|
assert.ok(hasTools, 'allowed-tools field present');
|
|
});
|
|
});
|