-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(chunkers): preserve FAQ prose in docs chunks #6383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+173
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
|
|
||
| vi.mock('@/lib/knowledge/embeddings', () => ({ | ||
| generateEmbeddings: vi.fn(async () => ({ embeddings: [] })), | ||
| getConfiguredEmbeddingModel: vi.fn(() => 'test-model'), | ||
| })) | ||
|
|
||
| import { DocsChunker } from '@/lib/chunkers/docs-chunker' | ||
|
|
||
| function cleanContent(content: string): string { | ||
| const chunker = new DocsChunker() | ||
| return (chunker as unknown as { cleanContent(content: string): string }).cleanContent.call( | ||
| chunker, | ||
| content | ||
| ) | ||
| } | ||
|
|
||
| describe('cleanContent FAQ extraction', () => { | ||
| it('keeps FAQ question/answer prose that the tag and brace strips would otherwise delete', () => { | ||
| const cleaned = cleanContent( | ||
| [ | ||
| 'Some intro prose.', | ||
| '', | ||
| 'import { FAQ } from "@/components/ui/faq"', | ||
| '', | ||
| '<FAQ items={[', | ||
| ' { question: "What is the maximum file size for uploads?", answer: "The maximum file size for files processed during a workflow run is 20 MB." },', | ||
| ' { question: "How are files passed between blocks internally?", answer: "Files are represented as standardized UserFile objects." },', | ||
| ']} />', | ||
| ].join('\n') | ||
| ) | ||
|
|
||
| expect(cleaned).toContain('What is the maximum file size for uploads?') | ||
| expect(cleaned).toContain('20 MB') | ||
| expect(cleaned).toContain('standardized UserFile objects') | ||
| expect(cleaned).toContain('Some intro prose.') | ||
| expect(cleaned).not.toContain('items=') | ||
| expect(cleaned).not.toContain('question:') | ||
| }) | ||
|
|
||
| it('survives braces and angle-bracket tokens inside answer strings', () => { | ||
| const cleaned = cleanContent( | ||
| [ | ||
| '<FAQ items={[', | ||
| ` { question: "What input formats work?", answer: "Use a data URI with the format 'data:{mime};base64,{data}' or a URL." },`, | ||
| ' { question: "Do I extract base64 manually?", answer: "No. Pass the entire file reference (e.g., <gmail.attachments[0]>) and the block extracts what it needs." },', | ||
| ']} />', | ||
| ].join('\n') | ||
| ) | ||
|
|
||
| // Brace placeholders keep their token text; the wrapper chars are dropped | ||
| // so the later brace strip cannot punch holes in the sentence. | ||
| expect(cleaned).toContain("'data:mime;base64,data'") | ||
| // Angle brackets are dropped so the tag strip cannot re-eat the sentence. | ||
| expect(cleaned).toContain('(e.g., gmail.attachments[0]) and the block extracts') | ||
| }) | ||
|
|
||
| it('extracts items formatted across multiple lines', () => { | ||
| const cleaned = cleanContent( | ||
| [ | ||
| '<FAQ items={[', | ||
| ' {', | ||
| ' question: "Is SSO supported?",', | ||
| ' answer: "Yes, on enterprise plans."', | ||
| ' },', | ||
| ']} />', | ||
| ].join('\n') | ||
| ) | ||
|
|
||
| expect(cleaned).toContain('Is SSO supported?') | ||
| expect(cleaned).toContain('Yes, on enterprise plans.') | ||
| }) | ||
|
|
||
| it('extracts single-quoted multiline items with trailing commas (session-policies shape)', () => { | ||
| const cleaned = cleanContent( | ||
| [ | ||
| '<FAQ', | ||
| ' items={[', | ||
| ' {', | ||
| " question: 'Do session policies apply to SSO sign-ins?',", | ||
| ' answer:', | ||
| " 'Yes. Sessions created through SSO follow the same limits.',", | ||
| ' },', | ||
| ' {', | ||
| ' question: \'Does "Sign out all members" affect API keys?\',', | ||
| " answer: 'No. API keys are unaffected.',", | ||
| ' },', | ||
| ' ]}', | ||
| '/>', | ||
| ].join('\n') | ||
| ) | ||
|
|
||
| expect(cleaned).toContain('Do session policies apply to SSO sign-ins?') | ||
| expect(cleaned).toContain('Yes. Sessions created through SSO follow the same limits.') | ||
| expect(cleaned).toContain('Does "Sign out all members" affect API keys?') | ||
| expect(cleaned).toContain('No. API keys are unaffected.') | ||
| expect(cleaned).not.toContain('items=') | ||
| }) | ||
|
|
||
| it('unescapes escaped quotes in extracted strings', () => { | ||
| const cleaned = cleanContent( | ||
| '<FAQ items={[ { question: "What does \\"draft\\" mean?", answer: "An unsaved workflow." } ]} />' | ||
| ) | ||
|
|
||
| expect(cleaned).toContain('What does "draft" mean?') | ||
| }) | ||
| }) | ||
|
|
||
| describe('cleanContent scaffolding strips', () => { | ||
| it('still strips imports, exports, comments, and code-ish brace expressions', () => { | ||
| const cleaned = cleanContent( | ||
| [ | ||
| 'import { Callout } from "fumadocs-ui/components/callout"', | ||
| 'export const dynamic = "force-static"', | ||
| '{/* editorial note */}', | ||
| 'Visible prose {props.title} continues here.', | ||
| '<Callout>Inside text stays</Callout>', | ||
| ].join('\n') | ||
| ) | ||
|
|
||
| expect(cleaned).not.toContain('import') | ||
| expect(cleaned).not.toContain('force-static') | ||
| expect(cleaned).not.toContain('editorial note') | ||
| expect(cleaned).not.toContain('props.title') | ||
| expect(cleaned).toContain('Visible prose') | ||
| expect(cleaned).toContain('Inside text stays') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.