import assert from 'node:assert/strict' import test from 'node:test' import { fileURLToPath } from 'node:url' import { GUIDE_LIST_COMPONENT, GUIDE_LIST_COMPONENT_PAGES, pageSourceFiles, resolveAllDocsPages, resolveDocsScope, } from './resolve-docs-scope.ts' const repoRoot = fileURLToPath(new URL('../../..', import.meta.url)) test('maps a guide list component change to its sample pages', async () => { const result = await resolveDocsScope({ changedFiles: [GUIDE_LIST_COMPONENT], repoRoot, }) assert.deepEqual(result.pages, [...GUIDE_LIST_COMPONENT_PAGES].sort()) assert.equal(result.skip, false) }) test('ignores unrelated docs component changes', async () => { const result = await resolveDocsScope({ changedFiles: ['apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts'], repoRoot, }) assert.deepEqual(result.pages, []) assert.equal(result.skip, true) }) test('skips a guide that the navigation disables', async () => { const result = await resolveDocsScope({ changedFiles: [ 'apps/docs/content/guides/ai-tools/agent-feedback.mdx', 'apps/docs/content/guides/ai-tools/mcp.mdx', ], repoRoot, }) assert.deepEqual(result.pages, ['/docs/guides/ai-tools/mcp']) }) test('excludes a guide that the navigation disables from the full run', async () => { const pages = await resolveAllDocsPages(repoRoot) assert.ok(pages.includes('/docs/guides/ai-tools/mcp')) assert.ok(!pages.includes('/docs/guides/ai-tools/agent-feedback')) }) test('skips a guide that redirects out of the docs', async () => { const result = await resolveDocsScope({ changedFiles: [ 'apps/docs/content/guides/getting-started/features.mdx', 'apps/docs/content/guides/ai-tools/mcp.mdx', ], repoRoot, }) assert.deepEqual(result.pages, ['/docs/guides/ai-tools/mcp']) }) test('excludes a guide that redirects out of the docs from the full run', async () => { const pages = await resolveAllDocsPages(repoRoot) assert.ok(pages.includes('/docs/guides/ai-tools/mcp')) assert.ok(!pages.includes('/docs/guides/getting-started/features')) }) test('keeps every page in a large change', async () => { const changedFiles = Array.from( { length: 82 }, (_, i) => `apps/docs/content/guides/ai-tools/page-${String(i).padStart(2, '0')}.mdx` ) const result = await resolveDocsScope({ changedFiles, repoRoot }) assert.equal(result.pages.length, 82) assert.deepEqual(result.pages, [...result.pages].sort()) }) test('keeps the pages a guide list component change requires alongside the changed pages', async () => { const result = await resolveDocsScope({ changedFiles: [GUIDE_LIST_COMPONENT, 'apps/docs/content/guides/ai-tools/mcp.mdx'], repoRoot, }) assert.deepEqual( result.pages, [...GUIDE_LIST_COMPONENT_PAGES, '/docs/guides/ai-tools/mcp'].sort() ) }) test('lists a guide and the partials it includes', async () => { const files = await pageSourceFiles(repoRoot, '/docs/guides/auth') assert.equal(files[0], 'apps/docs/content/guides/auth.mdx') assert.ok(files.includes('apps/docs/content/_partials/providers.mdx')) })