Skip to content

Commit e52205d

Browse files
committed
fix(copilot): include a section overview in either layout when scoping search
A directory scope matched only `<section>/%`, which covers an overview stored as `<section>/index.mdx` but not one stored as a sibling `<section>.mdx`. Fumadocs accepts both layouts and page scope already handles both via docsSourceCandidates, so a scoped section search could silently omit the overview chunks — and the doc comment claimed it did not. Every section in the tree currently uses the index.mdx layout, so nothing is broken today; this closes the gap before someone adds a sibling overview and gets quietly incomplete results.
1 parent 06f3a37 commit e52205d

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

apps/sim/lib/copilot/docs/docs-search.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ describe('searchDocs path scoping', () => {
8989
expect(whereText()).toContain('workflows/%')
9090
})
9191

92+
it('includes a section overview stored in either on-disk layout', async () => {
93+
await searchDocs('cron', { path: 'docs/workflows' })
94+
const text = whereText()
95+
// `workflows/index.mdx` is inside the subtree; a sibling `workflows.mdx` is not,
96+
// and fumadocs accepts either, so the scope must name it explicitly.
97+
expect(text).toContain('workflows/%')
98+
expect(text).toContain('workflows.mdx')
99+
})
100+
92101
it('rejects a path outside the docs corpus', async () => {
93102
await expect(searchDocs('cron', { path: 'files/report.pdf' })).rejects.toThrow(
94103
DocsSearchScopeError

apps/sim/lib/copilot/docs/docs-search.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class DocsSearchScopeError extends Error {
5656
* `source_document` stores the en-relative mdx file path, while VFS paths mirror
5757
* the public URL — so a section overview is `docs/workflows.mdx` in the VFS but
5858
* `workflows/index.mdx` (or `workflows.mdx`) on disk. A directory scope covers
59-
* the whole subtree, including that overview page.
59+
* the whole subtree plus the overview in either layout.
6060
*
6161
* Returns undefined for an unscoped search, which excludes `academy/` and
6262
* `api-reference/`: both are indexed but neither is mounted in the VFS, so a hit
@@ -89,7 +89,14 @@ function scopeCondition(path?: string) {
8989
}
9090

9191
if (isDocsDir(normalized)) {
92-
return like(docsEmbeddings.sourceDocument, `${escapeLikePattern(tail)}/%`)
92+
// Everything under the directory, PLUS a sibling `<tail>.mdx`. Fumadocs
93+
// accepts either layout for a section overview and only `<tail>/index.mdx`
94+
// is inside the subtree, so matching the prefix alone would silently omit
95+
// the overview for the sibling layout — page scope already covers both.
96+
return or(
97+
like(docsEmbeddings.sourceDocument, `${escapeLikePattern(tail)}/%`),
98+
eq(docsEmbeddings.sourceDocument, `${tail}.mdx`)
99+
)
93100
}
94101

95102
throw new DocsSearchScopeError(

0 commit comments

Comments
 (0)