refactor(3664): migrate bin/install.js install/uninstall to Runtime Artifact Layout Module (#3674)
Phase 2 of #3660 / ADR-3660. Routes both lifecycle verbs through the Runtime Artifact Layout Module landed in Phase 1 (#3663): - Add installRuntimeArtifacts(runtime, configDir, scope, resolvedProfile) and uninstallRuntimeArtifacts(runtime, configDir, scope) as the public orchestrators. Both pre-prune stale gsd-* entries before staged copy; installRuntimeArtifacts brackets the prune+copy with preserveUserArtifacts / restoreUserArtifacts so user-owned content (e.g. gsd-dev-preferences) survives wipe-and-replace for claude/qwen/hermes runtimes. - Add applyRuntimeContentRewritesInPlace as the per-runtime path/branding post-stage step (preserves byte-output equivalence with the legacy copyCommandsAs* pipeline, including Qwen/Hermes branding rewrites). - Add _copyStaged, _removeGsdEntries kind-aware filesystem helpers. - Add _runLegacyInstallMigrations, _runLegacyUninstallCleanup as thin dispatchers over existing ADR-0008 legacy migrations (Hermes flat->nested per #2841, dev-preferences-as-skill per #2973). For Hermes, also clean up the intermediate skills/gsd/gsd-*/ layout that pre-Phase-2 installs left on disk. - Delete the 9 copyCommandsAs*Skills functions (Codex / Cursor / Windsurf / Trae / CodeBuddy / Copilot / Claude / Antigravity / Augment) and the _copyCommandsAsSkillsViaConverter helper. All test entry points migrated to call installRuntimeArtifacts directly through the unified seam. - Collapse the 9-branch uninstall ladder to one uninstallRuntimeArtifacts call plus preserved non-layout side-effects (Codex TOML, Copilot instructions, hooks). - Unify install dispatcher: a single _isSkillsRuntime gate routes all 11 skills runtimes through installRuntimeArtifacts for both full and core/ minimal profiles. Removes 11 per-runtime if-else branches (3 minimal-mode shim branches + 8 dead after-the-gate branches). Net delta on bin/install.js: 11,495 -> 11,174 (-321 LOC). New tests: - tests/install-uninstall-layout-loop.test.cjs (34 tests) - per-runtime fixture assertions on install/uninstall/legacy-migration ordering. - tests/install-hermes-regressions.test.cjs (6 tests) - covers the six defects surfaced by iterative review: Hermes upgrade leaves stale dirs, --hermes --profile=core fall-through, --qwen --profile=core fall-through, minimal-mode dev-preferences migration skipped (Hermes/Qwen/Claude-global), and ordering bug in _runLegacyInstallMigrations. Existing tests (10,038 prior + 40 new) all green: 10,078/10,078 pass. Refs #3664 Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -153,58 +153,89 @@ describe('Bug #2973: installer migrates existing legacy dev-preferences.md to sk
|
||||
});
|
||||
});
|
||||
|
||||
// ─── #3003 CR follow-up: copyCommandsAsClaudeSkills preserves user-owned skills ──
|
||||
// ─── #3003 CR follow-up: installRuntimeArtifacts preserves user-owned skills ──
|
||||
//
|
||||
// Production install() calls installRuntimeArtifacts() without a prior
|
||||
// uninstallRuntimeArtifacts(). This means _copyStaged overlays new skills
|
||||
// on top of the existing skills/ directory — it does NOT wipe first.
|
||||
// As a result, user-owned gsd-dev-preferences/SKILL.md is preserved across
|
||||
// a plain install because _copyStaged only cpSync's newly staged skill dirs.
|
||||
//
|
||||
// NOTE: If callers run uninstallRuntimeArtifacts() before installRuntimeArtifacts()
|
||||
// (e.g. full reinstall), gsd-dev-preferences IS wiped by uninstall and NOT
|
||||
// restored by install (#3664 production gap — tracked separately).
|
||||
|
||||
describe('Bug #2973 (#3003 CR): copyCommandsAsClaudeSkills snapshots gsd-dev-preferences across the wipe', () => {
|
||||
test('user-customized skills/gsd-dev-preferences/SKILL.md survives a wipe-and-replace install', () => {
|
||||
describe('Bug #2973 (#3003 CR): installRuntimeArtifacts preserves user-owned gsd-dev-preferences across install', () => {
|
||||
test('user-customized skills/gsd-dev-preferences/SKILL.md survives a plain install (no pre-uninstall)', () => {
|
||||
// Production install() does NOT call uninstallRuntimeArtifacts() first.
|
||||
// installRuntimeArtifacts → _copyStaged overlays only staged skill dirs;
|
||||
// gsd-dev-preferences (not in source) is left untouched.
|
||||
const inst = require(INSTALL);
|
||||
const { loadSkillsManifest, resolveProfile } = require(path.join(ROOT, 'get-shit-done', 'bin', 'lib', 'install-profiles.cjs'));
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-2973-wipe-'));
|
||||
try {
|
||||
const skillsDir = path.join(tmp, 'skills');
|
||||
const configDir = path.join(tmp, 'config');
|
||||
fs.mkdirSync(configDir, { recursive: true });
|
||||
|
||||
// Set up a minimal source dir (plan-phase only; no dev-preferences).
|
||||
const srcDir = path.join(tmp, 'src-commands');
|
||||
fs.mkdirSync(srcDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(srcDir, 'plan-phase.md'), '---\nname: gsd:plan-phase\ndescription: Plan\n---\n\nPlan body.\n');
|
||||
fs.writeFileSync(path.join(configDir, '.gsd-source'), srcDir + '\n');
|
||||
|
||||
const skillsDir = path.join(configDir, 'skills');
|
||||
const userSkillDir = path.join(skillsDir, 'gsd-dev-preferences');
|
||||
fs.mkdirSync(userSkillDir, { recursive: true });
|
||||
const userContent = '# my customized dev preferences\n\nstack: rust\n';
|
||||
fs.writeFileSync(path.join(userSkillDir, 'SKILL.md'), userContent);
|
||||
|
||||
// Source dir mimicking commands/gsd/ — does NOT contain dev-preferences
|
||||
// because dev-preferences is user-generated, not shipped.
|
||||
const srcDir = path.join(tmp, 'src-commands');
|
||||
fs.mkdirSync(srcDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(srcDir, 'plan-phase.md'), '# plan-phase\n');
|
||||
|
||||
// Without the CR fix, the wipe loop deletes gsd-dev-preferences/
|
||||
// and the user's content is lost (no source to restore from).
|
||||
inst.copyCommandsAsClaudeSkills(srcDir, skillsDir, 'gsd', '$HOME/.claude/', 'claude', true);
|
||||
// Plain install (matching production install() call site).
|
||||
const manifest = loadSkillsManifest();
|
||||
const resolvedProfile = resolveProfile({ modes: [], manifest });
|
||||
inst.installRuntimeArtifacts('claude', configDir, 'global', resolvedProfile);
|
||||
|
||||
const skillFile = path.join(userSkillDir, 'SKILL.md');
|
||||
assert.equal(fs.existsSync(skillFile), true,
|
||||
'gsd-dev-preferences/SKILL.md must survive the wipe (#3003 CR)');
|
||||
'gsd-dev-preferences/SKILL.md must survive a plain install (#3003 CR)');
|
||||
assert.equal(fs.readFileSync(skillFile, 'utf-8'), userContent,
|
||||
'user content must be byte-identical after the wipe-restore cycle');
|
||||
'user content must be byte-identical after the install');
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('non-user-owned gsd-* skills are still wiped and recreated from source', () => {
|
||||
// The existing wipe behavior must still work for skills the package
|
||||
// owns. Otherwise the preservation list could grow stale by accident.
|
||||
test('non-user-owned gsd-* skills are wiped and recreated via uninstall+install cycle', () => {
|
||||
// Stale artifacts (e.g. STALE-MARKER.txt left from a previous version)
|
||||
// are removed when the caller runs uninstallRuntimeArtifacts() before
|
||||
// installRuntimeArtifacts() — the full uninstall+reinstall cycle.
|
||||
// uninstallRuntimeArtifacts removes all gsd-* entries; installRuntimeArtifacts
|
||||
// then writes fresh ones from source.
|
||||
const inst = require(INSTALL);
|
||||
const { loadSkillsManifest, resolveProfile } = require(path.join(ROOT, 'get-shit-done', 'bin', 'lib', 'install-profiles.cjs'));
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-2973-wipe-shipped-'));
|
||||
try {
|
||||
const skillsDir = path.join(tmp, 'skills');
|
||||
const configDir = path.join(tmp, 'config');
|
||||
fs.mkdirSync(configDir, { recursive: true });
|
||||
|
||||
const srcDir = path.join(tmp, 'src-commands');
|
||||
fs.mkdirSync(srcDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(srcDir, 'plan-phase.md'), '---\nname: gsd:plan-phase\ndescription: Plan fresh\n---\n\nFresh body.\n');
|
||||
fs.writeFileSync(path.join(configDir, '.gsd-source'), srcDir + '\n');
|
||||
|
||||
const skillsDir = path.join(configDir, 'skills');
|
||||
const staleSkillDir = path.join(skillsDir, 'gsd-plan-phase');
|
||||
fs.mkdirSync(staleSkillDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(staleSkillDir, 'STALE-MARKER.txt'), 'wipe me');
|
||||
|
||||
const srcDir = path.join(tmp, 'src-commands');
|
||||
fs.mkdirSync(srcDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(srcDir, 'plan-phase.md'), '# plan-phase fresh\n');
|
||||
const manifest = loadSkillsManifest();
|
||||
const resolvedProfile = resolveProfile({ modes: [], manifest });
|
||||
|
||||
inst.copyCommandsAsClaudeSkills(srcDir, skillsDir, 'gsd', '$HOME/.claude/', 'claude', true);
|
||||
// Full uninstall+install cycle (e.g. --reinstall flow)
|
||||
inst.uninstallRuntimeArtifacts('claude', configDir, 'global');
|
||||
inst.installRuntimeArtifacts('claude', configDir, 'global', resolvedProfile);
|
||||
|
||||
assert.equal(fs.existsSync(path.join(staleSkillDir, 'STALE-MARKER.txt')), false,
|
||||
'stale shipped-skill content must be wiped (preservation is opt-in by name)');
|
||||
'stale shipped-skill content must be wiped by uninstall (preservation is opt-in by name)');
|
||||
assert.equal(fs.existsSync(path.join(staleSkillDir, 'SKILL.md')), true,
|
||||
'fresh SKILL.md from source must be installed after wipe');
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user