From 54ab8a6755524578821a031864de00bdb26b07d7 Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" Date: Sun, 27 Sep 2026 13:33:40 -0400 Subject: [PATCH] test(docs-contract): derive autogenerated sidebar dirs from sidebars.js The sidebar-title contract in tests/docs-contract.test.mjs restated the autogenerated sidebar directories by hand as ['architectures', 'community'], but sidebars.js declares a third one, resourcesSidebar, from docs/resources. The three docs under it were never checked for a frontmatter title, so losing one would silently degrade the sidebar label to the filename. Derive the list from sidebars.js, the way tests/site-config.test.mjs already does for its directory-existence assertion, and assert the derived list is non-empty so the contract cannot become a no-op. Signed-off-by: hivecommons-hive[bot] --- tests/docs-contract.test.mjs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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) =>