-
Notifications
You must be signed in to change notification settings - Fork 0
test: add testcases and coverage #4
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 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75c05ef
test: add testcases and coverage
hustcc cbb65b6
docs: add HF_ENDPOINT tip
hustcc 413302f
Update test/storage/store.test.ts
hustcc 6a7e6a9
Update README.md
hustcc 9a6ac15
Update test/utils/sample.test.ts
hustcc 7ef68a6
fix: tmp file leak
hustcc a7f8d8a
fix: increase test timeouts and prevent concurrent model downloads in CI
Copilot 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
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 |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| export { pathToId } from './doc'; | ||
| export { computeContentHash } from './hash'; | ||
| export { safeJsonParse } from './common'; | ||
| export { loadSampleText } from './sample'; | ||
| export { isCJK, detectLanguage, tokenizerForLanguage, detectTokenizer } from './tokenizer'; | ||
| export type { LanguageHint } from './tokenizer'; | ||
| export { containsCJK } from './str'; | ||
| export { loadSampleText, selectSampleFiles } from './sample'; | ||
| export { isCJK, containsCJK, detectLanguage, tokenizerForLanguage, detectTokenizer } from './tokenizer'; | ||
| export type { LanguageHint } from './tokenizer'; |
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
This file was deleted.
Oops, something went wrong.
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
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
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,18 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { Embedder } from '../../src/embedder/embedder'; | ||
|
|
||
| describe('Embedder', () => { | ||
| it('should have default dimensions of 512', () => { | ||
| const embedder = new Embedder(); | ||
| expect(embedder.dimensions).toBe(512); | ||
| }); | ||
|
|
||
| it('should have static pipeline property', () => { | ||
| expect(Embedder.pipeline).toBeNull(); | ||
| }); | ||
|
|
||
| it('should be instantiable', () => { | ||
| const embedder = new Embedder(); | ||
| expect(embedder).toBeInstanceOf(Embedder); | ||
| }); | ||
| }); |
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,135 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { expand } from '../../src/expander'; | ||
|
|
||
| describe('expand', () => { | ||
| const queryExpansion = { | ||
| synonyms: { | ||
| '折线图': ['line chart', '折线'], | ||
| 'tooltip': ['提示框', '提示', 'hover'], | ||
| 'animation': ['动效', 'animate', 'transition'], | ||
| 'config': ['配置', 'configuration', '设置'], | ||
| }, | ||
| }; | ||
|
|
||
| it('should expand CN chart type to EN equivalent', () => { | ||
| const result = expand('折线图', queryExpansion); | ||
| expect(result).toContain('line chart'); | ||
| }); | ||
|
|
||
| it('should expand EN term to CN equivalent', () => { | ||
| const result = expand('tooltip', queryExpansion); | ||
| expect(result).toContain('提示框'); | ||
| }); | ||
|
|
||
| it('should not duplicate terms already in query', () => { | ||
| const result = expand('tooltip 提示框', queryExpansion); | ||
| const promptCount = result.split('提示框').length - 1; | ||
| expect(promptCount).toBe(1); | ||
| }); | ||
|
|
||
| it('should expand multiple terms in one query', () => { | ||
| const result = expand('tooltip config', queryExpansion); | ||
| expect(result).toContain('提示框'); | ||
| expect(result).toContain('配置'); | ||
| }); | ||
|
|
||
| it('should preserve original query text', () => { | ||
| const result = expand('animation settings', queryExpansion); | ||
| expect(result.startsWith('animation settings')).toBe(true); | ||
| }); | ||
|
|
||
| it('should return original query when no synonyms match', () => { | ||
| const result = expand('random unrelated terms', queryExpansion); | ||
| expect(result).toBe('random unrelated terms'); | ||
| }); | ||
|
|
||
| it('should handle empty query', () => { | ||
| const result = expand('', queryExpansion); | ||
| expect(result).toBe(''); | ||
| }); | ||
|
|
||
| it('should return original query with no synonyms', () => { | ||
| const result = expand('tooltip configuration'); | ||
| expect(result).toBe('tooltip configuration'); | ||
| }); | ||
|
|
||
| it('should return original query with empty synonyms', () => { | ||
| const result = expand('tooltip configuration', {}); | ||
| expect(result).toBe('tooltip configuration'); | ||
| }); | ||
|
|
||
| it('should return query unchanged when queryExpansion is false', () => { | ||
| const result = expand('折线图配置', false); | ||
| expect(result).toBe('折线图配置'); | ||
| }); | ||
|
|
||
| it('should handle CJK terms with substring match', () => { | ||
| // Line 14: containsCJK(term) returns true, so substring match is used | ||
| const result = expand('折线图', queryExpansion); | ||
| expect(result).toContain('折线'); | ||
| }); | ||
|
|
||
| it('should handle term at start of query', () => { | ||
| // Line 18-28: while loop with word boundary at start | ||
| const result = expand('tooltip chart', queryExpansion); | ||
| expect(result).toContain('提示框'); | ||
| }); | ||
|
|
||
| it('should handle term at end of query', () => { | ||
| // Test term matching at end of query | ||
| const result = expand('chart tooltip', queryExpansion); | ||
| expect(result).toContain('提示框'); | ||
| }); | ||
|
|
||
| it('should handle term in middle of query', () => { | ||
| const result = expand('show tooltip here', queryExpansion); | ||
| expect(result).toContain('提示框'); | ||
| }); | ||
|
|
||
| it('should not add synonym already in query', () => { | ||
| // Line 45: containsTerm check prevents duplication | ||
| const result = expand('tooltip 提示框', queryExpansion); | ||
| const parts = result.split(' '); | ||
| const promptCount = parts.filter(p => p === '提示框').length; | ||
| expect(promptCount).toBe(1); | ||
| }); | ||
|
|
||
| it('should handle synonyms with already added terms', () => { | ||
| // Multiple terms matching same synonym | ||
| const result = expand('折线图 折线', queryExpansion); | ||
| expect(result).toContain('line chart'); | ||
| }); | ||
|
|
||
| it('should handle term at word boundary returning true immediately', () => { | ||
| // This tests the path where containsTerm finds a match and returns true (line 26) | ||
| // Direct term at word boundary | ||
| const result = expand('test tooltip config', queryExpansion); | ||
| expect(result).toContain('提示'); | ||
| }); | ||
|
|
||
| it('should not match partial Latin substring in word', () => { | ||
| // This tests the path where term is found but not at word boundaries (lines 27-29) | ||
| // Searching for "config" in "configured" - gets past include check but not boundary check | ||
| const testExpansion = { | ||
| synonyms: { 'config': ['setting'] } | ||
| }; | ||
| const result = expand('configured', testExpansion); | ||
| // "config" is part of "configured", not a standalone word - should not match | ||
| expect(result).toBe('configured'); | ||
| }); | ||
|
|
||
| it('should handle term found but never at word boundary', () => { | ||
| // This tests line 29-30: term found but all occurrences fail boundary check | ||
| // Using a term that appears only as part of a longer word | ||
| const testExpansion = { | ||
| synonyms: { 'abc': ['xyz'] } | ||
| }; | ||
| // "abc" does NOT appear in this text at all - so line 11 returns false early | ||
| // Need text that contains "abc" but never as a standalone word | ||
| const result = expand('xabcy', testExpansion); | ||
| // "abc" is in "xabcy" but not at word boundary (surrounded by letters) | ||
| // This will go through the loop, never find a boundary match, then return false | ||
| // This triggers lines 29-30 | ||
| expect(result).toBe('xabcy'); | ||
| }); | ||
| }); |
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 @@ | ||
| "This is a JSON string value" |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.