-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add Dojo as a source in cairo-coder #90
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
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bda5b1c
version with the ingester of dojo and the agent add with template gen…
0xhijo 397cbfb
version working with docker just got error with starknet js so commented
0xhijo 49de3ba
version with test working but need to bes changed to more specific do…
0xhijo 8a2677a
upadte py test to handle the new agent and add some test for the new …
0xhijo 499acde
prettier
0xhijo 7fb42dc
version with updated test
0xhijo b385842
version with updated test
0xhijo fcb195b
p7utting back ingester factory
0xhijo ccb1277
version with updated docs
0xhijo d131aa0
version without an specific dojo agent
0xhijo 8734ff2
version with all updated
0xhijo 54b382c
fix test
0xhijo 35c23f8
add dojo datasets
0xhijo 21246e7
remove space
0xhijo e1786cf
puttinh back starknet js
0xhijo 6bde5f3
Merge branch 'main' of https://github.com/KasarLabs/cairo-coder into …
0xhijo 9187fce
version with eni requested changment
0xhijo b4fc060
fix naming path
0xhijo 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,156 @@ | ||
| import { describe, it, expect } from 'bun:test'; | ||
| import { DojoDocsIngester } from '../src/ingesters/DojoDocsIngester'; | ||
| import { DocumentSource } from '../src/types'; | ||
|
|
||
| describe('DojoDocsIngester', () => { | ||
| it('should be configured correctly for Dojo documentation', () => { | ||
| const ingester = new DojoDocsIngester(); | ||
|
|
||
| // Check that it has the correct configuration | ||
| expect(ingester).toBeDefined(); | ||
| // @ts-ignore - accessing config for testing purposes | ||
| expect(ingester.config).toEqual({ | ||
| repoOwner: 'dojoengine', | ||
| repoName: 'book', | ||
| fileExtension: '.md', | ||
| chunkSize: 4096, | ||
| chunkOverlap: 512, | ||
| baseUrl: 'https://book.dojoengine.org', | ||
| urlSuffix: '', | ||
| useUrlMapping: true, | ||
| }); | ||
| // @ts-ignore - accessing source for testing purposes | ||
| expect(ingester.source).toBe(DocumentSource.DOJO_DOCS); | ||
| }); | ||
|
|
||
| it('should have correct extract directory', () => { | ||
| const ingester = new DojoDocsIngester(); | ||
|
|
||
| // @ts-ignore - accessing private method for testing | ||
| const extractDir = ingester.getExtractDir(); | ||
|
|
||
| expect(extractDir).toBeDefined(); | ||
| expect(extractDir).toContain('dojo-docs'); | ||
| }); | ||
|
|
||
| it('should process markdown content correctly', () => { | ||
| const ingester = new DojoDocsIngester(); | ||
|
|
||
| // Test markdown content | ||
| const testContent = `## Getting Started | ||
|
|
||
| Dojo is a provable game engine and toolchain for building onchain games. | ||
|
|
||
| \`\`\`bash | ||
| $ sozo init my-game | ||
| \`\`\` | ||
|
|
||
| This command creates a new Dojo project. | ||
|
|
||
| ## Installation | ||
|
|
||
| Install the required dependencies.`; | ||
|
|
||
| // @ts-ignore - accessing private method for testing | ||
| const chunks = ingester.createChunkFromPage('getting-started', testContent); | ||
|
|
||
| expect(chunks).toBeDefined(); | ||
| expect(chunks.length).toBeGreaterThan(0); | ||
|
|
||
| // Check that chunks have correct metadata | ||
| const firstChunk = chunks[0]; | ||
| expect(firstChunk).toBeDefined(); | ||
| expect(firstChunk!.metadata.name).toBe('getting-started'); | ||
| expect(firstChunk!.metadata.source).toBe(DocumentSource.DOJO_DOCS); | ||
| expect(firstChunk!.metadata.sourceLink).toContain( | ||
| 'https://book.dojoengine.org', | ||
| ); | ||
| }); | ||
|
|
||
| it('should split content into multiple sections based on headers', () => { | ||
| const ingester = new DojoDocsIngester(); | ||
|
|
||
| // Test content with multiple headers | ||
| const processedContent = `## Introduction | ||
|
|
||
| Dojo is a provable game engine and toolchain for building onchain games. | ||
|
|
||
| ## Installation | ||
|
|
||
| Install Dojo using the following command: | ||
|
|
||
| \`\`\`bash | ||
| $ curl -L https://install.dojoengine.org | bash | ||
| \`\`\` | ||
|
|
||
| ## Configuration | ||
|
|
||
| Configure your Dojo project settings in the Scarb.toml file.`; | ||
|
|
||
| // @ts-ignore - accessing private method for testing | ||
| const chunks = ingester.createChunkFromPage( | ||
| 'getting-started', | ||
| processedContent, | ||
| ); | ||
|
|
||
| expect(chunks).toBeDefined(); | ||
| expect(chunks.length).toBeGreaterThanOrEqual(3); | ||
|
|
||
| // Check that we have chunks for each section | ||
| const titles = chunks.map((chunk) => chunk.metadata.title); | ||
| expect(titles).toContain('Introduction'); | ||
| expect(titles).toContain('Installation'); | ||
| expect(titles).toContain('Configuration'); | ||
| }); | ||
|
|
||
| it('should sanitize code blocks correctly', () => { | ||
| const ingester = new DojoDocsIngester(); | ||
|
|
||
| // Test content with code blocks | ||
| const testContent = `## Example | ||
|
|
||
| Here's an example: | ||
|
|
||
| \`\`\`cairo | ||
| # This is a comment in code | ||
| fn main() { | ||
| println!("Hello"); | ||
| } | ||
| \`\`\` | ||
|
|
||
| That was the example.`; | ||
|
|
||
| // @ts-ignore - accessing private method for testing | ||
| const sanitized = ingester.sanitizeCodeBlocks(testContent); | ||
|
|
||
| expect(sanitized).toBeDefined(); | ||
| expect(sanitized).toContain('```cairo'); | ||
| expect(sanitized).toContain('fn main()'); | ||
| }); | ||
|
|
||
| it('should generate correct URLs with useUrlMapping', () => { | ||
| const ingester = new DojoDocsIngester(); | ||
|
|
||
| const testContent = `## Components | ||
|
|
||
| Components are the building blocks of your Dojo entities.`; | ||
|
|
||
| // @ts-ignore - accessing private method for testing | ||
| const chunks = ingester.createChunkFromPage( | ||
| 'core-concepts/entities', | ||
| testContent, | ||
| ); | ||
|
|
||
| expect(chunks).toBeDefined(); | ||
| expect(chunks.length).toBeGreaterThan(0); | ||
|
|
||
| // All chunks should have the correct source link format | ||
| chunks.forEach((chunk) => { | ||
| expect(chunk.metadata.sourceLink).toContain( | ||
| 'https://book.dojoengine.org', | ||
| ); | ||
| expect(chunk.metadata.sourceLink).toContain('core-concepts/entities'); | ||
| expect(chunk.metadata.source).toBe(DocumentSource.DOJO_DOCS); | ||
| }); | ||
| }); | ||
| }); | ||
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.