diff --git a/tests/docs-contract.test.mjs b/tests/docs-contract.test.mjs index 489e3ad5..aee8dc7d 100644 --- a/tests/docs-contract.test.mjs +++ b/tests/docs-contract.test.mjs @@ -9,8 +9,19 @@ const docsRoot = join(repoRoot, 'docs'); // Directories sidebars.js renders as `{type: 'autogenerated', dirName: ...}`. // Every doc in one of these becomes a sidebar entry, which is labelled from -// frontmatter `title` when present. -const AUTOGENERATED_SIDEBAR_DIRS = ['architectures', 'community']; +// frontmatter `title` when present. The list is derived from sidebars.js +// rather than restated here so a sidebar added there cannot silently escape +// the title contract. +const sidebars = (await import('../sidebars.js')).default; + +const AUTOGENERATED_SIDEBAR_DIRS = [ + ...new Set( + Object.values(sidebars) + .flat() + .filter((entry) => entry?.type === 'autogenerated') + .map((entry) => entry.dirName), + ), +].sort(); function walk(dir) { return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { @@ -158,6 +169,10 @@ test('frontmatter keys are parseable key: value pairs', () => { }); test('docs in autogenerated sidebar directories declare a title', () => { + assert.ok( + AUTOGENERATED_SIDEBAR_DIRS.length > 0, + 'sidebars.js must declare at least one autogenerated sidebar, otherwise this contract asserts nothing', + ); const untitled = []; for (const dir of AUTOGENERATED_SIDEBAR_DIRS) { const dirDocs = docs.filter((file) =>