Files
msd-core/tests/helpers/agent-roster.cjs
Behruz Nassre Esfahani fc5ca178a2 test(#1178): consolidate duplicated agent-roster helper into tests/helpers (#1420)
* test(#1178): consolidate duplicated agent-roster helper into tests/helpers

The "list gsd-*.md agent files, strip .md, sort" derivation was hand-duplicated
across the suite (two listAgentFiles(), an identical agentFilesOnDisk(), and
inline readdir blocks). Add tests/helpers/agent-roster.cjs exporting
listAgentFiles(agentsDir?) and route the genuinely-identical source-roster sites
through it. Semantically-different sites (installed-dest dirs, absolute-path
returns, .toml-inclusive Codex rosters, full-.md-filename readers, the uniform
multi-family inventory table) are left intact, each with a one-line comment.

Test-only; no production code touched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(#1178): note AGENTS_DIR export is for future call sites

Review nit: clarify that the currently-unused AGENTS_DIR export is intentional
— available for future tests needing the canonical source agents path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
2026-06-23 19:34:08 -04:00

43 lines
1.5 KiB
JavaScript

'use strict';
/**
* Shared helper for the canonical shipped-agent roster.
*
* Several tests derive "the set of agents we ship" from the source `agents/`
* directory via `fs.readdirSync(...).filter(/^gsd-.*\.md$/)`. This consolidates
* that hand-duplicated logic into one canonical SOURCE-roster derivation.
*
* NOTE: This returns the SOURCE roster (basenames without `.md`, sorted). Sites
* with different semantics — installed-destination dirs, absolute-path returns,
* or `.toml`-inclusive Codex rosters — must NOT use this helper.
*/
const fs = require('node:fs');
const path = require('node:path');
// Canonical source agents directory: <repo-root>/agents, relative to this
// helper at tests/helpers/. Matches the path the consolidated call sites used.
const AGENTS_DIR = path.join(__dirname, '..', '..', 'agents');
/**
* List shipped agent basenames (without the `.md` extension), sorted.
*
* @param {string} [agentsDir] Override for the source agents directory.
* Defaults to the canonical `<repo-root>/agents`.
* @returns {string[]} Sorted `gsd-*` basenames with `.md` stripped.
*/
function listAgentFiles(agentsDir = AGENTS_DIR) {
return fs
.readdirSync(agentsDir)
.filter((f) => /^gsd-.*\.md$/.test(f))
.map((f) => f.replace(/\.md$/, ''))
.sort();
}
module.exports = {
// AGENTS_DIR is exported (not yet consumed by a call site) so future tests that
// need the canonical source agents path can reuse it instead of rediscovering it.
AGENTS_DIR,
listAgentFiles,
};