From f5b1867268222f02c56154bb6cd72a7db174ef45 Mon Sep 17 00:00:00 2001 From: huangpz6 Date: Wed, 4 Nov 2026 11:21:21 +0800 Subject: [PATCH] fix(skills-health): explain a missing scripts/lib instead of a module stack (#3259) A managed plugin install can lack scripts/lib/skill-evolution, which made skills-health fail on the first require with Cannot find module. Catch that specific resolution failure and print the install-apply remedy; other errors still propagate. Co-Authored-By: TRAE --- scripts/skills-health.js | 22 +++++++- .../scripts/skills-health-missing-lib.test.js | 51 +++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 tests/scripts/skills-health-missing-lib.test.js diff --git a/scripts/skills-health.js b/scripts/skills-health.js index 4cea9ec50..d3144644a 100644 --- a/scripts/skills-health.js +++ b/scripts/skills-health.js @@ -1,8 +1,26 @@ #!/usr/bin/env node 'use strict'; -const { collectSkillHealth, formatHealthReport } = require('./lib/skill-evolution/health'); -const { renderDashboard } = require('./lib/skill-evolution/dashboard'); +let collectSkillHealth; +let formatHealthReport; +let renderDashboard; +try { + ({ collectSkillHealth, formatHealthReport } = require('./lib/skill-evolution/health')); + ({ renderDashboard } = require('./lib/skill-evolution/dashboard')); +} catch (error) { + // The Claude Code plugin marketplace clones the repo but does not run + // npm/install-apply, so scripts/lib can be missing from a managed install. + // Fail with the remedy instead of a bare module-resolution stack (#3259). + if (error && error.code === 'MODULE_NOT_FOUND' && /skill-evolution/.test(error.message)) { + console.error( + 'skills-health requires scripts/lib/skill-evolution, which is missing from this installation.\n' + + 'Reinstall ECC with the commands-core module (node scripts/install-apply.js --target ) ' + + 'or run this script from a full checkout of the repository.' + ); + process.exit(1); + } + throw error; +} function showHelp() { console.log(` diff --git a/tests/scripts/skills-health-missing-lib.test.js b/tests/scripts/skills-health-missing-lib.test.js new file mode 100644 index 000000000..104f63dbf --- /dev/null +++ b/tests/scripts/skills-health-missing-lib.test.js @@ -0,0 +1,51 @@ +/** + * A managed install without scripts/lib must get the remedy, not a stack trace + * (#3259). + */ + +const assert = require('assert'); +const fs = require('fs'); +const os = require('os'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const script = path.join(__dirname, '..', '..', 'scripts', 'skills-health.js'); + +function test(name, fn) { + try { + fn(); + console.log(` ✓ ${name}`); + return true; + } catch (error) { + console.log(` ✗ ${name}`); + console.log(` Error: ${error.message}`); + return false; + } +} + +let passed = 0; +let failed = 0; + +const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-health-missing-lib-')); +fs.mkdirSync(path.join(tmp, 'scripts'), { recursive: true }); +fs.copyFileSync(script, path.join(tmp, 'scripts', 'skills-health.js')); + +if ( + test('missing scripts/lib prints the install remedy instead of a stack trace', () => { + const result = spawnSync('node', [path.join(tmp, 'scripts', 'skills-health.js')], { + encoding: 'utf8', + timeout: 15000 + }); + assert.strictEqual(result.status, 1); + assert.match(result.stderr, /missing from this installation/i); + assert.match(result.stderr, /install-apply\.js/); + assert.doesNotMatch(result.stderr, /Cannot find module/); + }) +) + passed++; +else failed++; + +fs.rmSync(tmp, { recursive: true, force: true }); + +console.log(`\n ${passed} passed, ${failed} failed\n`); +process.exit(failed > 0 ? 1 : 0);