-
Notifications
You must be signed in to change notification settings - Fork 713
docs: add Japanese README translation #2248
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
Open
reckless129
wants to merge
2
commits into
refly-ai:main
Choose a base branch
from
reckless129:feat/add-japanese-readme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 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
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,265 @@ | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import { CachedWebSearcher, WebSearchCacheConfig } from './cached-searcher'; | ||
| import { BaseWebSearcher, WebSearchConfig } from './base'; | ||
| import { RedisService } from '../../modules/common/redis.service'; | ||
| import { WebSearchRequest, WebSearchResult } from '@refly/openapi-schema'; | ||
|
|
||
| /** | ||
| * Mock Redis Service for testing | ||
| */ | ||
| class MockRedisService { | ||
| private store: Map<string, string> = new Map(); | ||
|
|
||
| async get(key: string): Promise<string | null> { | ||
| return this.store.get(key) || null; | ||
| } | ||
|
|
||
| async setex(key: string, seconds: number, value: string): Promise<void> { | ||
| this.store.set(key, value); | ||
| } | ||
|
|
||
| async del(key: string): Promise<void> { | ||
| this.store.delete(key); | ||
| } | ||
|
|
||
| async set( | ||
| key: string, | ||
| value: string, | ||
| mode?: string, | ||
| seconds?: number, | ||
| flag?: string, | ||
| ): Promise<string | null> { | ||
| if (flag === 'NX' && this.store.has(key)) { | ||
| return null; | ||
| } | ||
| this.store.set(key, value); | ||
| return 'OK'; | ||
| } | ||
|
|
||
| async eval( | ||
| script: string, | ||
| numKeys: number, | ||
| ...args: string[] | ||
| ): Promise<unknown> { | ||
| const key = args[0]; | ||
| const token = args[1]; | ||
| const stored = this.store.get(key); | ||
| if (stored === token) { | ||
| this.store.delete(key); | ||
| return 1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| async scan( | ||
| cursor: string, | ||
| ...args: (string | number)[] | ||
| ): Promise<[string, string[]]> { | ||
| const pattern = args[args.indexOf('MATCH') + 1] as string; | ||
| const keys: string[] = []; | ||
|
|
||
| for (const [key] of this.store.entries()) { | ||
| if (key.startsWith(pattern.replace('*', ''))) { | ||
| keys.push(key); | ||
| } | ||
| } | ||
|
|
||
| return ['0', keys]; | ||
| } | ||
|
|
||
| clear(): void { | ||
| this.store.clear(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Mock Web Searcher for testing | ||
| */ | ||
| class MockWebSearcher extends BaseWebSearcher { | ||
| public searchCount = 0; | ||
| private mockResults: WebSearchResult[]; | ||
|
|
||
| constructor( | ||
| config?: WebSearchConfig, | ||
| mockResults?: WebSearchResult[], | ||
| ) { | ||
| super(config); | ||
| this.mockResults = mockResults || [ | ||
| { | ||
| name: 'Test Result', | ||
| url: 'https://example.com', | ||
| snippet: 'Test snippet', | ||
| locale: 'en', | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| async search(): Promise<WebSearchResult[]> { | ||
| this.searchCount++; | ||
| return this.mockResults; | ||
| } | ||
| } | ||
|
|
||
| describe('CachedWebSearcher', () => { | ||
| let cachedSearcher: CachedWebSearcher; | ||
| let mockSearcher: MockWebSearcher; | ||
| let mockRedis: MockRedisService; | ||
|
|
||
| beforeEach(() => { | ||
| mockRedis = new MockRedisService(); | ||
| mockSearcher = new MockWebSearcher(); | ||
| cachedSearcher = new CachedWebSearcher(mockSearcher, mockRedis as any, { | ||
| ttl: 60, | ||
|
reckless129 marked this conversation as resolved.
|
||
| maxCachedResults: 10, | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| mockRedis.clear(); | ||
| }); | ||
|
|
||
| describe('Basic Caching', () => { | ||
| it('should fetch from origin on cache miss', async () => { | ||
| const req: WebSearchRequest = { q: 'nestjs tutorial', limit: 5 }; | ||
|
|
||
| const results = await cachedSearcher.search(req); | ||
|
|
||
| expect(results).toHaveLength(1); | ||
| expect(results[0].name).toBe('Test Result'); | ||
| expect(mockSearcher.searchCount).toBe(1); | ||
| }); | ||
|
|
||
| it('should return cached results on cache hit', async () => { | ||
| const req: WebSearchRequest = { q: 'nestjs tutorial', limit: 5 }; | ||
|
|
||
| // First call - cache miss | ||
| await cachedSearcher.search(req); | ||
| expect(mockSearcher.searchCount).toBe(1); | ||
|
|
||
| // Second call - cache hit | ||
| const results = await cachedSearcher.search(req); | ||
| expect(results).toHaveLength(1); | ||
| expect(mockSearcher.searchCount).toBe(1); // Should not increment | ||
| }); | ||
|
|
||
| it('should generate consistent cache keys for same query', async () => { | ||
| const req1: WebSearchRequest = { q: 'NestJS Tutorial', limit: 5 }; | ||
| const req2: WebSearchRequest = { q: 'nestjs tutorial', limit: 5 }; | ||
|
|
||
| await cachedSearcher.search(req1); | ||
| await cachedSearcher.search(req2); | ||
|
|
||
| // Both should hit the same cache (case insensitive normalization) | ||
| expect(mockSearcher.searchCount).toBe(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Cache Key Normalization', () => { | ||
| it('should normalize batch requests consistently', async () => { | ||
| const req = { | ||
| queries: [ | ||
| { q: 'query B', limit: 5 }, | ||
| { q: 'query A', limit: 5 }, | ||
| ], | ||
| limit: 10, | ||
| }; | ||
|
|
||
| await cachedSearcher.search(req); | ||
|
|
||
| // Same queries in different order should hit cache | ||
| const req2 = { | ||
| queries: [ | ||
| { q: 'query A', limit: 5 }, | ||
| { q: 'query B', limit: 5 }, | ||
| ], | ||
| limit: 10, | ||
| }; | ||
|
|
||
| await cachedSearcher.search(req2); | ||
| expect(mockSearcher.searchCount).toBe(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Cache Configuration', () => { | ||
| it('should respect maxCachedResults limit', async () => { | ||
| mockSearcher = new MockWebSearcher({}, [ | ||
| { name: 'Result 1', url: 'https://1.com', snippet: '1', locale: 'en' }, | ||
| { name: 'Result 2', url: 'https://2.com', snippet: '2', locale: 'en' }, | ||
| { name: 'Result 3', url: 'https://3.com', snippet: '3', locale: 'en' }, | ||
| ]); | ||
|
|
||
| cachedSearcher = new CachedWebSearcher(mockSearcher, mockRedis as any, { | ||
| ttl: 60, | ||
| maxCachedResults: 2, // Only cache 2 results | ||
| }); | ||
|
|
||
| const req: WebSearchRequest = { q: 'test', limit: 10 }; | ||
| await cachedSearcher.search(req); | ||
|
|
||
| // Check cached value | ||
| const keys = Array.from((mockRedis as any).store.keys()); | ||
| const cacheKey = keys.find((k: string) => k.startsWith('websearch:')); | ||
| const cached = JSON.parse((mockRedis as any).store.get(cacheKey)); | ||
|
|
||
| expect(cached).toHaveLength(2); | ||
| }); | ||
|
|
||
| it('should not cache empty results when cacheEmptyResults is false', async () => { | ||
| mockSearcher = new MockWebSearcher({}, []); | ||
|
|
||
| const req: WebSearchRequest = { q: 'test', limit: 10 }; | ||
| await cachedSearcher.search(req); | ||
|
|
||
| // Should not have cached anything | ||
| const keys = Array.from((mockRedis as any).store.keys()); | ||
| const cacheKeys = keys.filter((k: string) => k.startsWith('websearch:') && !k.includes(':lock')); | ||
|
|
||
| expect(cacheKeys).toHaveLength(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Cache Invalidation', () => { | ||
| it('should invalidate cache correctly', async () => { | ||
| const req: WebSearchRequest = { q: 'test', limit: 5 }; | ||
|
|
||
| await cachedSearcher.search(req); | ||
| expect(mockSearcher.searchCount).toBe(1); | ||
|
|
||
| await cachedSearcher.invalidateCache(req); | ||
|
|
||
| // After invalidation, should fetch from origin again | ||
| await cachedSearcher.search(req); | ||
| expect(mockSearcher.searchCount).toBe(2); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Error Handling', () => { | ||
| it('should fallback to origin on Redis error', async () => { | ||
| // Simulate Redis failure | ||
| mockRedis.get = async () => { | ||
| throw new Error('Redis connection failed'); | ||
| }; | ||
|
|
||
| const req: WebSearchRequest = { q: 'test', limit: 5 }; | ||
| const results = await cachedSearcher.search(req); | ||
|
|
||
| expect(results).toHaveLength(1); | ||
| expect(mockSearcher.searchCount).toBe(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Cache Statistics', () => { | ||
| it('should return cache statistics', async () => { | ||
| const req1: WebSearchRequest = { q: 'query1', limit: 5 }; | ||
| const req2: WebSearchRequest = { q: 'query2', limit: 5 }; | ||
|
|
||
| await cachedSearcher.search(req1); | ||
| await cachedSearcher.search(req2); | ||
|
|
||
| const stats = await cachedSearcher.getCacheStats(); | ||
|
|
||
| expect(stats.totalKeys).toBe(2); | ||
| expect(stats.pattern).toBe('websearch:*'); | ||
| }); | ||
| }); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: refly-ai/refly
Length of output: 3115
🏁 Script executed:
Repository: refly-ai/refly
Length of output: 1751
Add ConfigModule to webhook.module.ts imports
ConfigService is properly injected in the service, but the module doesn't import ConfigModule, which is required to provide ConfigService to WebhookService. Without it, dependency injection will fail at runtime.
Update
apps/api/src/modules/webhook/webhook.module.tsto import ConfigModule:Required fix
🤖 Prompt for AI Agents