feat(#2182): scaffold community capability + EoS registry (tests + stubbed core)

Adds the discoverability-registry surface for issue #2182: JSON-sourced
capability/eos catalogs, a pure schema/vocab module (registry-schema.cjs)
with the ADR-857 loop points + ADR-1239 axes, thin validate/gen CLIs,
the registry-entry PR template, README spec, and CONTEXT.md glossary terms.

The three pure functions (isValidGsdRange/validateEntries/renderMarkdown)
are stubbed here so the comprehensive test suite fails first (red), per the
feature-implementation red-first directive; the next commit implements them.

Refs #2182

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-07-11 14:13:02 -04:00
parent 30feeaa8be
commit 60e3c4988a
13 changed files with 1352 additions and 2 deletions

117
tests/gen-registry.test.cjs Normal file
View File

@@ -0,0 +1,117 @@
'use strict';
process.env.GSD_TEST_MODE = '1';
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const { cleanup } = require('./helpers.cjs');
const SCRIPT_PATH = path.join(__dirname, '..', 'scripts', 'gen-registry.cjs');
const { renderMarkdown } = require(path.join(__dirname, '..', 'scripts', 'registry-schema.cjs'));
// gen-registry.cjs resolves docs/registries/ from process.cwd() (mirrors
// validate-registry.cjs), so tests drive it as a subprocess with `cwd`
// pointed at an isolated temp fixture directory.
function validCapabilityEntry() {
return {
id: 'my-capability',
name: 'My Capability',
type: 'capability',
repo: 'octocat/my-capability',
description: 'Does a useful thing for GSD users.',
author: 'Octocat',
license: 'MIT',
enginesGsd: '>=1.6.0 <3.0.0',
install: 'gsd capability install https://github.com/octocat/my-capability.git#v1.0.0',
uninstall: 'gsd capability remove my-capability',
interactions: {
loopExtensionPoints: ['execute:pre'],
hookKinds: ['step'],
configKeys: [],
requires: [],
runtimeCompat: ['all'],
produces: [],
consumes: [],
},
discussion: 'https://github.com/octocat/my-capability/discussions/1',
};
}
function withFixture(entries, fn) {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-gen-registry-'));
try {
const registriesDir = path.join(tmp, 'docs', 'registries');
fs.mkdirSync(registriesDir, { recursive: true });
fs.writeFileSync(path.join(registriesDir, 'capabilities.json'), JSON.stringify(entries, null, 2) + '\n');
fn(tmp, registriesDir);
} finally {
cleanup(tmp);
}
}
function runGen(cwd, args = []) {
return spawnSync(process.execPath, [SCRIPT_PATH, ...args], { cwd, encoding: 'utf8' });
}
describe('gen-registry CLI (subprocess)', () => {
test('--write then --check is clean (no drift) for a populated registry', () => {
withFixture([validCapabilityEntry()], (tmp, registriesDir) => {
const write = runGen(tmp, ['--write']);
assert.equal(write.status, 0, `stderr: ${write.stderr}`);
assert.ok(fs.existsSync(path.join(registriesDir, 'capability-registry.md')));
const check = runGen(tmp, ['--check']);
assert.equal(check.status, 0, `stderr: ${check.stderr}`);
});
});
test('hand-mutating the generated md then --check fails (drift detected)', () => {
withFixture([validCapabilityEntry()], (tmp, registriesDir) => {
const write = runGen(tmp, ['--write']);
assert.equal(write.status, 0, `stderr: ${write.stderr}`);
const mdPath = path.join(registriesDir, 'capability-registry.md');
fs.appendFileSync(mdPath, '\nhand-edited drift line\n');
const check = runGen(tmp, ['--check']);
assert.notEqual(check.status, 0);
});
});
test('--write on an empty registry ([]) produces md containing the empty-state text', () => {
withFixture([], (tmp, registriesDir) => {
const write = runGen(tmp, ['--write']);
assert.equal(write.status, 0, `stderr: ${write.stderr}`);
const mdPath = path.join(registriesDir, 'capability-registry.md');
const content = fs.readFileSync(mdPath, 'utf8');
assert.match(content, /No entries yet/);
});
});
test('default (no flag) prints rendered markdown to stdout', () => {
withFixture([validCapabilityEntry()], (tmp) => {
const result = runGen(tmp, []);
assert.equal(result.status, 0, `stderr: ${result.stderr}`);
assert.ok(result.stdout.length > 0);
});
});
});
describe('gen-registry: renderMarkdown (direct, via registry-schema)', () => {
test('renders empty-state text for an empty capability registry', () => {
const rendered = renderMarkdown([], { type: 'capability', sourceFile: 'capabilities.json' });
assert.match(rendered, /No entries yet/);
});
test('renders the shields.io badge + discussion link for a populated capability registry', () => {
const entry = validCapabilityEntry();
const rendered = renderMarkdown([entry], { type: 'capability', sourceFile: 'capabilities.json' });
assert.match(rendered, /img\.shields\.io\/github\/v\/release/);
assert.ok(rendered.includes(entry.discussion));
});
});

View File

@@ -0,0 +1,388 @@
'use strict';
process.env.GSD_TEST_MODE = '1';
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const path = require('node:path');
const fc = require('fast-check');
const {
LOOP_POINTS,
HOOK_KINDS,
INTERFACE_POINTS,
PROFILES,
AXES,
AXES_FREE_STRING,
CAPABILITY_REQUIRED,
EOS_REQUIRED,
isValidGsdRange,
validateEntries,
renderMarkdown,
} = require(path.join(__dirname, '..', 'scripts', 'registry-schema.cjs'));
// ─── Fixtures ─────────────────────────────────────────────────────────────
function validCapabilityEntry() {
return {
id: 'my-capability',
name: 'My Capability',
type: 'capability',
repo: 'octocat/my-capability',
description: 'Does a useful thing for GSD users.',
author: 'Octocat',
license: 'MIT',
enginesGsd: '>=1.6.0 <3.0.0',
install: 'gsd capability install https://github.com/octocat/my-capability.git#v1.0.0',
uninstall: 'gsd capability remove my-capability',
interactions: {
loopExtensionPoints: ['execute:pre'],
hookKinds: ['step'],
configKeys: ['myCapability.enabled'],
requires: [],
runtimeCompat: ['all'],
produces: [],
consumes: [],
},
discussion: 'https://github.com/octocat/my-capability/discussions/1',
};
}
function validEosEntry() {
return {
id: 'my-host-plugin',
name: 'My Host Plugin',
type: 'eos',
repo: 'octocat/my-host-plugin',
description: 'Embeds GSD as an orchestration engine in My Host.',
author: 'Octocat',
license: 'MIT',
enginesGsd: '>=1.6.0 <3.0.0',
install: 'See the My Host plugin marketplace listing.',
uninstall: 'Uninstall via the My Host plugin manager.',
protocolVersion: 1,
interactions: {
interfacePoints: ['command', 'state'],
profile: 'programmatic-cli',
axes: {
embeddingMode: 'imperative',
commandSurface: 'slash-file',
dispatch: 'Supports nested background dispatch up to depth 3.',
modelMode: 'active',
hookBus: 'host',
stateIO: 'filesystem',
transport: 'mcp',
runtime: 'node',
},
},
discussion: 'https://github.com/octocat/my-host-plugin/discussions/2',
};
}
// ─── Vocabulary constants ───────────────────────────────────────────────────
describe('registry-schema: closed vocabulary constants', () => {
test('LOOP_POINTS is the 12 canonical loop points (ADR-857), in order', () => {
assert.deepEqual(LOOP_POINTS, [
'discuss:pre',
'discuss:post',
'plan:pre',
'plan:post',
'execute:pre',
'execute:wave:pre',
'execute:wave:post',
'execute:post',
'verify:pre',
'verify:post',
'ship:pre',
'ship:post',
]);
});
test('HOOK_KINDS is step/contribution/gate (ADR-857 Decision 4)', () => {
assert.deepEqual(HOOK_KINDS, ['step', 'contribution', 'gate']);
});
test('INTERFACE_POINTS is the six ADR-1239 interface points', () => {
assert.deepEqual(INTERFACE_POINTS, ['command', 'dispatch', 'model', 'hooks', 'state', 'artifact']);
});
test('PROFILES is the three ADR-1239 negotiation profiles', () => {
assert.deepEqual(PROFILES, ['programmatic-cli', 'declarative-cli', 'ide']);
});
test('AXES has exactly the eight ADR-1239 negotiated axis keys', () => {
assert.deepEqual(
Object.keys(AXES).sort(),
['commandSurface', 'dispatch', 'embeddingMode', 'hookBus', 'modelMode', 'runtime', 'stateIO', 'transport'].sort(),
);
});
test('AXES.dispatch carries the free-string sentinel, not an enum array', () => {
assert.equal(AXES.dispatch, AXES_FREE_STRING);
assert.equal(Array.isArray(AXES.dispatch), false);
});
test('every non-dispatch AXES entry is a non-empty enum array', () => {
for (const [key, value] of Object.entries(AXES)) {
if (key === 'dispatch') continue;
assert.ok(Array.isArray(value), `AXES.${key} should be an array`);
assert.ok(value.length > 0, `AXES.${key} should be non-empty`);
}
});
test('CAPABILITY_REQUIRED lists the 12 required capability entry fields', () => {
assert.deepEqual(CAPABILITY_REQUIRED, [
'id', 'name', 'type', 'repo', 'description', 'author', 'license',
'enginesGsd', 'install', 'uninstall', 'interactions', 'discussion',
]);
});
test('EOS_REQUIRED lists the 13 required eos entry fields (adds protocolVersion)', () => {
assert.deepEqual(EOS_REQUIRED, [
'id', 'name', 'type', 'repo', 'description', 'author', 'license',
'enginesGsd', 'install', 'uninstall', 'interactions', 'discussion', 'protocolVersion',
]);
});
});
// ─── validateEntries: capability ───────────────────────────────────────────
describe('validateEntries: capability — happy path', () => {
test('a fully-valid capability entry passes', () => {
const verdict = validateEntries([validCapabilityEntry()], { type: 'capability' });
assert.equal(verdict.ok, true);
assert.deepEqual(verdict.errors, []);
});
});
describe('validateEntries: capability — required fields', () => {
for (const field of CAPABILITY_REQUIRED) {
test(`missing required field "${field}" fails`, () => {
const entry = validCapabilityEntry();
delete entry[field];
const verdict = validateEntries([entry], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.length > 0, 'expected at least one error');
assert.ok(
verdict.errors.some((e) => e.field === field),
`expected an error referencing field "${field}", got: ${JSON.stringify(verdict.errors)}`,
);
});
}
});
describe('validateEntries: capability — field shape violations', () => {
test('bad id (not kebab-case) fails', () => {
const entry = validCapabilityEntry();
entry.id = 'Not_Kebab_Case';
const verdict = validateEntries([entry], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'id'));
});
test('bad repo (not owner/repo form) fails', () => {
const entry = validCapabilityEntry();
entry.repo = 'not-a-valid-repo';
const verdict = validateEntries([entry], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'repo'));
});
test('bad enginesGsd (malformed range) fails', () => {
const entry = validCapabilityEntry();
entry.enginesGsd = 'not-a-semver-range';
const verdict = validateEntries([entry], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'enginesGsd'));
});
test('bad discussion URL fails', () => {
const entry = validCapabilityEntry();
entry.discussion = 'https://example.com/not-a-discussion';
const verdict = validateEntries([entry], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'discussion'));
});
test('bad license fails', () => {
const entry = validCapabilityEntry();
entry.license = 'Not A Valid License!!';
const verdict = validateEntries([entry], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'license'));
});
test('unknown top-level key fails (strict schema)', () => {
const entry = validCapabilityEntry();
entry.extraUnknownField = 'nope';
const verdict = validateEntries([entry], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'extraUnknownField'));
});
test('duplicate id across two entries fails', () => {
const a = validCapabilityEntry();
const b = validCapabilityEntry();
b.name = 'A Different Name';
b.repo = 'octocat/another-capability';
b.discussion = 'https://github.com/octocat/another-capability/discussions/2';
// b.id intentionally left the same as a.id
const verdict = validateEntries([a, b], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'id' && /duplicate/i.test(e.reason)));
});
test('empty loopExtensionPoints fails (AC3 — must be non-empty)', () => {
const entry = validCapabilityEntry();
entry.interactions.loopExtensionPoints = [];
const verdict = validateEntries([entry], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'interactions.loopExtensionPoints'));
});
test('invalid loop point fails', () => {
const entry = validCapabilityEntry();
entry.interactions.loopExtensionPoints = ['not:a:real:point'];
const verdict = validateEntries([entry], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'interactions.loopExtensionPoints'));
});
test('invalid hook kind fails', () => {
const entry = validCapabilityEntry();
entry.interactions.hookKinds = ['not-a-real-kind'];
const verdict = validateEntries([entry], { type: 'capability' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'interactions.hookKinds'));
});
});
// ─── validateEntries: eos ───────────────────────────────────────────────────
describe('validateEntries: eos — happy path', () => {
test('a fully-valid eos entry passes', () => {
const verdict = validateEntries([validEosEntry()], { type: 'eos' });
assert.equal(verdict.ok, true);
assert.deepEqual(verdict.errors, []);
});
});
describe('validateEntries: eos — field shape violations', () => {
test('bad interfacePoint fails', () => {
const entry = validEosEntry();
entry.interactions.interfacePoints = ['not-a-real-point'];
const verdict = validateEntries([entry], { type: 'eos' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'interactions.interfacePoints'));
});
test('bad profile fails', () => {
const entry = validEosEntry();
entry.interactions.profile = 'not-a-real-profile';
const verdict = validateEntries([entry], { type: 'eos' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'interactions.profile'));
});
test('bad axis value fails', () => {
const entry = validEosEntry();
entry.interactions.axes.embeddingMode = 'not-a-real-value';
const verdict = validateEntries([entry], { type: 'eos' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'interactions.axes.embeddingMode'));
});
test('protocolVersion < 1 fails', () => {
const entry = validEosEntry();
entry.protocolVersion = 0;
const verdict = validateEntries([entry], { type: 'eos' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'protocolVersion'));
});
test('missing axis key fails', () => {
const entry = validEosEntry();
delete entry.interactions.axes.runtime;
const verdict = validateEntries([entry], { type: 'eos' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'interactions.axes'));
});
test('extra axis key fails', () => {
const entry = validEosEntry();
entry.interactions.axes.notARealAxis = 'x';
const verdict = validateEntries([entry], { type: 'eos' });
assert.equal(verdict.ok, false);
assert.ok(verdict.errors.some((e) => e.field === 'interactions.axes'));
});
});
// ─── renderMarkdown ─────────────────────────────────────────────────────────
describe('renderMarkdown', () => {
test('is deterministic across two calls regardless of input entry order', () => {
const a = validCapabilityEntry();
const b = { ...validCapabilityEntry(), id: 'zzz-capability', name: 'ZZZ Capability' };
const first = renderMarkdown([a, b], { type: 'capability', sourceFile: 'capabilities.json' });
const second = renderMarkdown([b, a], { type: 'capability', sourceFile: 'capabilities.json' });
assert.equal(first, second);
});
test('contains the shields.io release badge for a populated registry', () => {
const rendered = renderMarkdown([validCapabilityEntry()], { type: 'capability', sourceFile: 'capabilities.json' });
assert.match(rendered, /img\.shields\.io\/github\/v\/release/);
});
test('contains the entry discussion URL for a populated registry', () => {
const entry = validCapabilityEntry();
const rendered = renderMarkdown([entry], { type: 'capability', sourceFile: 'capabilities.json' });
assert.ok(rendered.includes(entry.discussion), 'expected rendered output to include the discussion URL');
});
test('contains the empty-state text for zero entries', () => {
const rendered = renderMarkdown([], { type: 'capability', sourceFile: 'capabilities.json' });
assert.match(rendered, /No entries yet/);
});
});
// ─── isValidGsdRange ────────────────────────────────────────────────────────
describe('isValidGsdRange', () => {
test('fast-check property: well-formed operator+M.N.P ranges are valid', () => {
fc.assert(
fc.property(
fc.constantFrom('', '>=', '>', '<=', '<', '=', '^', '~'),
fc.integer({ min: 0, max: 999 }),
fc.integer({ min: 0, max: 999 }),
fc.integer({ min: 0, max: 999 }),
(op, major, minor, patch) => {
const range = `${op}${major}.${minor}.${patch}`;
assert.equal(isValidGsdRange(range), true, range);
},
),
);
});
test('fast-check property: strings with letters where digits are expected are invalid', () => {
fc.assert(
fc.property(
fc.string({ minLength: 1, maxLength: 8 }).filter((s) => /[A-Za-z]/.test(s) && !/^\s*$/.test(s)),
(garbage) => {
assert.equal(isValidGsdRange(`>=${garbage}.0.0`), false, garbage);
},
),
);
});
test('boundary: valid range strings', () => {
for (const good of ['1.0.0', '>=1.0.0', '^1.0.0 <2.0.0', '*']) {
assert.equal(isValidGsdRange(good), true, good);
}
});
test('boundary: invalid range strings', () => {
for (const bad of ['1.0', '>=abc', '']) {
assert.equal(isValidGsdRange(bad), false, bad);
}
});
});

View File

@@ -0,0 +1,117 @@
'use strict';
process.env.GSD_TEST_MODE = '1';
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const { cleanup } = require('./helpers.cjs');
const SCRIPT_PATH = path.join(__dirname, '..', 'scripts', 'validate-registry.cjs');
// validate-registry.cjs resolves docs/registries/ from process.cwd(), so
// tests drive it as a subprocess with `cwd` pointed at an isolated temp
// fixture directory — this covers main() end-to-end without touching the
// real repo's docs/registries/capabilities.json.
function validCapabilityEntry() {
return {
id: 'my-capability',
name: 'My Capability',
type: 'capability',
repo: 'octocat/my-capability',
description: 'Does a useful thing for GSD users.',
author: 'Octocat',
license: 'MIT',
enginesGsd: '>=1.6.0 <3.0.0',
install: 'gsd capability install https://github.com/octocat/my-capability.git#v1.0.0',
uninstall: 'gsd capability remove my-capability',
interactions: {
loopExtensionPoints: ['execute:pre'],
hookKinds: ['step'],
configKeys: [],
requires: [],
runtimeCompat: ['all'],
produces: [],
consumes: [],
},
discussion: 'https://github.com/octocat/my-capability/discussions/1',
};
}
function withFixture(entries, fn) {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-validate-registry-'));
try {
const registriesDir = path.join(tmp, 'docs', 'registries');
fs.mkdirSync(registriesDir, { recursive: true });
fs.writeFileSync(path.join(registriesDir, 'capabilities.json'), JSON.stringify(entries, null, 2) + '\n');
fn(tmp);
} finally {
cleanup(tmp);
}
}
function runValidate(cwd, args = []) {
return spawnSync(process.execPath, [SCRIPT_PATH, ...args], { cwd, encoding: 'utf8' });
}
describe('validate-registry CLI (subprocess)', () => {
test('a good capabilities.json fixture exits 0', () => {
withFixture([validCapabilityEntry()], (tmp) => {
const result = runValidate(tmp);
assert.equal(result.status, 0, `stderr: ${result.stderr}`);
});
});
test('a bad capabilities.json fixture (missing required field) exits non-zero', () => {
const bad = validCapabilityEntry();
delete bad.discussion;
withFixture([bad], (tmp) => {
const result = runValidate(tmp);
assert.notEqual(result.status, 0);
});
});
test('a bad capabilities.json fixture (bad id) exits non-zero', () => {
const bad = validCapabilityEntry();
bad.id = 'Not_Kebab_Case';
withFixture([bad], (tmp) => {
const result = runValidate(tmp);
assert.notEqual(result.status, 0);
});
});
test('--json prints a parseable verdict for a good fixture', () => {
withFixture([validCapabilityEntry()], (tmp) => {
const result = runValidate(tmp, ['--json']);
const parsed = JSON.parse(result.stdout);
assert.equal(typeof parsed.ok, 'boolean');
assert.ok(Array.isArray(parsed.results));
assert.ok(parsed.results.some((r) => r.file === 'capabilities.json'));
});
});
test('--json prints a parseable verdict for a bad fixture', () => {
const bad = validCapabilityEntry();
delete bad.license;
withFixture([bad], (tmp) => {
const result = runValidate(tmp, ['--json']);
const parsed = JSON.parse(result.stdout);
assert.equal(typeof parsed.ok, 'boolean');
assert.equal(parsed.ok, false);
});
});
test('missing capabilities.json entirely exits non-zero', () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-validate-registry-empty-'));
try {
fs.mkdirSync(path.join(tmp, 'docs', 'registries'), { recursive: true });
const result = runValidate(tmp);
assert.notEqual(result.status, 0);
} finally {
cleanup(tmp);
}
});
});