Files
msd-core/tests/codebuddy-install.test.cjs
Jakub Zych a9a7a328e6 refactor: hard-fork GSD -> MSD (Make Software Done)
Mechanical rename produced by scripts/msd-rename.cjs: gsd/Gsd/GSD -> msd/Msd/MSD
across contents and paths, upstream package/repo coordinates -> @golem15/msd-core
and golem15com/msd-core. Deep links into upstream history, sibling upstream
packages, the GSD-2 import feature, CHANGELOG.md and .changeset/ are kept as-is.

Hand edits on top: MSD block-letter banner and logos, LICENSE copyright line,
package/plugin identity, regenerated lockfile, install-tree fixtures, derived
registries and benchmark baseline; migration checksum baseline re-locked
(MSD keeps its own install state, so no install had applied the old sums);
sort-order and regex-escaped expectations in tests adjusted.
2026-10-06 01:47:40 +02:00

271 lines
9.9 KiB
JavaScript

// allow-test-rule: source-text-is-the-product
// Workflow .md / agent .md / command .md / reference .md files — their text
// IS what the runtime loads. Testing text content tests the deployed contract.
// Per CONTRIBUTING.md exception matrix.
process.env.MSD_TEST_MODE = '1';
const { test, describe, beforeEach, afterEach } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const os = require('node:os');
const { createTempDir, cleanup } = require('./helpers.cjs');
const {
getConfigDirFromHome,
convertClaudeToCodebuddyMarkdown,
convertClaudeCommandToCodebuddySkill,
convertClaudeAgentToCodebuddyAgent,
install,
uninstall,
writeManifest,
} = require('../bin/install.js');
const { installRuntimeArtifacts } = require('../msd-core/bin/lib/install-engine.cjs');
const { getDirName } = require('../msd-core/bin/lib/runtime-name-policy.cjs');
const { getGlobalConfigDir } = require('../msd-core/bin/lib/runtime-homes.cjs');
// ─── Profile resolution for installRuntimeArtifacts tests ────────────────────
const _msdLibDir = path.join(__dirname, '..', 'msd-core', 'bin', 'lib');
const { loadSkillsManifest, resolveProfile } = require(path.join(_msdLibDir, 'install-profiles.cjs'));
const _manifest = loadSkillsManifest();
const resolvedProfileFull = resolveProfile({ modes: [], manifest: _manifest });
describe('CodeBuddy runtime directory mapping', () => {
test('maps CodeBuddy to .codebuddy for local installs', () => {
assert.strictEqual(getDirName('codebuddy'), '.codebuddy');
});
test('maps CodeBuddy to ~/.codebuddy for global installs', () => {
assert.strictEqual(getGlobalConfigDir('codebuddy'), path.join(os.homedir(), '.codebuddy'));
});
test('returns .codebuddy config fragments for local and global installs', () => {
assert.strictEqual(getConfigDirFromHome('codebuddy', false), "'.codebuddy'");
assert.strictEqual(getConfigDirFromHome('codebuddy', true), "'.codebuddy'");
});
});
describe('getGlobalConfigDir (CodeBuddy)', () => {
let originalCodebuddyConfigDir;
beforeEach(() => {
originalCodebuddyConfigDir = process.env.CODEBUDDY_CONFIG_DIR;
});
afterEach(() => {
if (originalCodebuddyConfigDir !== undefined) {
process.env.CODEBUDDY_CONFIG_DIR = originalCodebuddyConfigDir;
} else {
delete process.env.CODEBUDDY_CONFIG_DIR;
}
});
test('returns ~/.codebuddy with no env var or explicit dir', () => {
delete process.env.CODEBUDDY_CONFIG_DIR;
const result = getGlobalConfigDir('codebuddy');
assert.strictEqual(result, path.join(os.homedir(), '.codebuddy'));
});
test('returns explicit dir when provided', () => {
const result = getGlobalConfigDir('codebuddy', '/custom/codebuddy-path');
assert.strictEqual(result, '/custom/codebuddy-path');
});
test('respects CODEBUDDY_CONFIG_DIR env var', () => {
process.env.CODEBUDDY_CONFIG_DIR = '~/custom-codebuddy';
const result = getGlobalConfigDir('codebuddy');
assert.strictEqual(result, path.join(os.homedir(), 'custom-codebuddy'));
});
test('explicit dir takes priority over CODEBUDDY_CONFIG_DIR', () => {
process.env.CODEBUDDY_CONFIG_DIR = '~/from-env';
const result = getGlobalConfigDir('codebuddy', '/explicit/path');
assert.strictEqual(result, '/explicit/path');
});
test('does not break other runtimes', () => {
assert.strictEqual(getGlobalConfigDir('claude'), path.join(os.homedir(), '.claude'));
assert.strictEqual(getGlobalConfigDir('codex'), path.join(os.homedir(), '.codex'));
});
});
describe('CodeBuddy markdown conversion', () => {
test('converts Claude-specific references to CodeBuddy equivalents', () => {
const input = [
'Claude Code reads CLAUDE.md before using .claude/skills/.',
'Run /msd:plan-phase with $ARGUMENTS.',
'Use Bash(command) and Edit(file).',
].join('\n');
const result = convertClaudeToCodebuddyMarkdown(input);
assert.ok(result.includes('CodeBuddy reads CODEBUDDY.md before using .codebuddy/skills/.'), result);
assert.ok(result.includes('/msd-plan-phase'), result);
assert.ok(result.includes('{{MSD_ARGS}}'), result);
// CodeBuddy uses the same tool names as Claude Code — no conversion needed
assert.ok(result.includes('Bash('), result);
assert.ok(result.includes('Edit('), result);
});
test('converts commands and agents to CodeBuddy frontmatter', () => {
const command = `---
name: msd:new-project
description: Initialize a project
---
Use .claude/skills/ and /msd:help.
`;
const agent = `---
name: msd-planner
description: Planner agent
tools: Read, Write
color: blue
---
Read CLAUDE.md before acting.
`;
const convertedCommand = convertClaudeCommandToCodebuddySkill(command, 'msd-new-project');
const convertedAgent = convertClaudeAgentToCodebuddyAgent(agent);
assert.ok(convertedCommand.includes('name: msd-new-project'), convertedCommand);
assert.ok(convertedCommand.includes('.codebuddy/skills/'), convertedCommand);
assert.ok(convertedCommand.includes('/msd-help'), convertedCommand);
assert.ok(convertedAgent.includes('name: msd-planner'), convertedAgent);
assert.ok(!convertedAgent.includes('color:'), convertedAgent);
assert.ok(convertedAgent.includes('CODEBUDDY.md'), convertedAgent);
});
});
describe('installRuntimeArtifacts (codebuddy integration)', () => {
// Pivoted from copyCommandsAsCodebuddySkills(srcDir, skillsDir, 'msd', '$HOME/.codebuddy/', 'codebuddy')
// shim to installRuntimeArtifacts('codebuddy', configDir, 'local', resolvedProfileFull).
// Output layout: <configDir>/skills/msd-<stem>/SKILL.md (destSubpath='skills', prefix='msd-').
let configDir;
beforeEach(() => {
configDir = createTempDir('msd-codebuddy-copy-');
});
afterEach(() => {
cleanup(configDir);
});
test('creates one skill directory per MSD command', () => {
installRuntimeArtifacts('codebuddy', configDir, 'local', resolvedProfileFull);
const generated = path.join(configDir, 'skills', 'msd-help', 'SKILL.md');
assert.ok(fs.existsSync(generated), generated);
const content = fs.readFileSync(generated, 'utf8');
assert.ok(content.includes('name: msd-help'), content);
});
});
describe('CodeBuddy local install/uninstall', () => {
let tmpDir;
let previousCwd;
beforeEach(() => {
tmpDir = createTempDir('msd-codebuddy-install-');
previousCwd = process.cwd();
process.chdir(tmpDir);
});
afterEach(() => {
process.chdir(previousCwd);
cleanup(tmpDir);
});
test('installs MSD into ./.codebuddy and removes it cleanly', () => {
const result = install(false, 'codebuddy');
const targetDir = path.join(tmpDir, '.codebuddy');
// CodeBuddy supports settings.json hooks (Claude Code compatible)
assert.strictEqual(result.runtime, 'codebuddy');
assert.ok(result.settingsPath, 'should have settingsPath (CodeBuddy supports hooks)');
assert.ok(fs.existsSync(path.join(targetDir, 'skills', 'msd-help', 'SKILL.md')));
assert.ok(fs.existsSync(path.join(targetDir, 'msd-core', 'VERSION')));
assert.ok(fs.existsSync(path.join(targetDir, 'agents')));
const manifest = writeManifest(targetDir, 'codebuddy');
assert.ok(Object.keys(manifest.files).some(file => file.startsWith('skills/msd-help/')), JSON.stringify(manifest));
uninstall(false, 'codebuddy');
assert.ok(!fs.existsSync(path.join(targetDir, 'skills', 'msd-help')), 'CodeBuddy skill directory removed');
assert.ok(!fs.existsSync(path.join(targetDir, 'msd-core')), 'msd-core removed');
});
});
describe('E2E: CodeBuddy uninstall skills cleanup', () => {
let tmpDir;
let previousCwd;
beforeEach(() => {
tmpDir = createTempDir('msd-codebuddy-uninstall-');
previousCwd = process.cwd();
process.chdir(tmpDir);
});
afterEach(() => {
process.chdir(previousCwd);
cleanup(tmpDir);
});
test('removes all msd-* skill directories on --codebuddy --uninstall', () => {
const targetDir = path.join(tmpDir, '.codebuddy');
install(false, 'codebuddy');
const skillsDir = path.join(targetDir, 'skills');
assert.ok(fs.existsSync(skillsDir), 'skills dir exists after install');
const installedSkills = fs.readdirSync(skillsDir, { withFileTypes: true })
.filter(e => e.isDirectory() && e.name.startsWith('msd-'));
assert.ok(installedSkills.length > 0, `found ${installedSkills.length} msd-* skill dirs before uninstall`);
uninstall(false, 'codebuddy');
if (fs.existsSync(skillsDir)) {
const remainingMsd = fs.readdirSync(skillsDir, { withFileTypes: true })
.filter(e => e.isDirectory() && e.name.startsWith('msd-'));
assert.strictEqual(remainingMsd.length, 0,
`Expected 0 msd-* skill dirs after uninstall, found: ${remainingMsd.map(e => e.name).join(', ')}`);
}
});
test('preserves non-MSD skill directories during --codebuddy --uninstall', () => {
const targetDir = path.join(tmpDir, '.codebuddy');
install(false, 'codebuddy');
const customSkillDir = path.join(targetDir, 'skills', 'my-custom-skill');
fs.mkdirSync(customSkillDir, { recursive: true });
fs.writeFileSync(path.join(customSkillDir, 'SKILL.md'), '# My Custom Skill\n');
assert.ok(fs.existsSync(path.join(customSkillDir, 'SKILL.md')), 'custom skill exists before uninstall');
uninstall(false, 'codebuddy');
assert.ok(fs.existsSync(path.join(customSkillDir, 'SKILL.md')),
'Non-MSD skill directory should be preserved after CodeBuddy uninstall');
});
test('removes engine directory on --codebuddy --uninstall', () => {
const targetDir = path.join(tmpDir, '.codebuddy');
install(false, 'codebuddy');
assert.ok(fs.existsSync(path.join(targetDir, 'msd-core', 'VERSION')),
'engine exists before uninstall');
uninstall(false, 'codebuddy');
assert.ok(!fs.existsSync(path.join(targetDir, 'msd-core')),
'msd-core engine should be removed after CodeBuddy uninstall');
});
});