refactor(#887): consolidate duplicated CHILD_ROUTER test maps into shared helper (#889)

Three test files copy-pasted the concrete-skill->namespace-router CHILD_ROUTER
map verbatim, and two more duplicated an identical local parseRouterRequires
regex. Introduce tests/helpers/nested-layout.cjs that derives the child->router
map from the authoritative commands/gsd/ns-*.md requires: lists once, reusing
the production parseRequires (now exported from install-profiles) plus a
nestedSkillPath(skillsRoot, prefix, stem) helper. Refactor all five test files
to import from it.

Test-only + a single internal export addition; no production behavior change.

Closes #887

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-06-08 16:05:59 -04:00
committed by GitHub
parent a74e71b049
commit b6199460ed
7 changed files with 90 additions and 184 deletions

View File

@@ -14,9 +14,6 @@ const fs = require('node:fs');
const path = require('node:path');
const os = require('node:os');
const ROOT = path.join(__dirname, '..');
const COMMANDS_GSD = path.join(ROOT, 'commands', 'gsd');
const {
installRuntimeArtifacts,
} = require('../bin/install.js');
@@ -28,6 +25,8 @@ const {
resolveProfile,
} = require('../gsd-core/bin/lib/install-profiles.cjs');
const { COMMANDS_GSD, ROUTER_STEMS, routerChildren } = require('./helpers/nested-layout.cjs');
// ---------------------------------------------------------------------------
// Runtime parity decision matrix (#69)
// ---------------------------------------------------------------------------
@@ -52,31 +51,10 @@ const FLAT = [
{ runtime: 'kilo', scope: 'global', skillsSub: 'skills' },
];
const ROUTER_STEMS = ['ns-context', 'ns-ideate', 'ns-manage', 'ns-project', 'ns-review', 'ns-workflow'];
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
/**
* Parse the `requires:` flow-style array from a router file's raw content.
* Matches `requires: [a, b, c]` (inline array form).
*/
function parseRouterRequires(content) {
const m = content.match(/^requires:\s*\[([^\]]*)\]/m);
if (!m) return [];
return m[1].split(',').map((s) => s.trim()).filter(Boolean);
}
/**
* Read the requires list for a router stem from the source commands/gsd dir.
*/
function routerChildren(routerStem) {
const srcFile = path.join(COMMANDS_GSD, `${routerStem}.md`);
const content = fs.readFileSync(srcFile, 'utf-8');
return parseRouterRequires(content);
}
/**
* Create a fresh temp dir, run installRuntimeArtifacts into it, and return
* the tmpDir path. Caller must cleanup in finally.