mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-10-09 00:16:32 +08:00
test: 测试用例
This commit is contained in:
@@ -217,6 +217,33 @@ export function useSearchHistory({
|
|||||||
onNotice('已恢复这条历史问题的最近结果')
|
onNotice('已恢复这条历史问题的最近结果')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const readCachedResult = (cacheKey: string): AISearchCacheRecord | null => {
|
||||||
|
const exact = readSearchCache(cacheKey)
|
||||||
|
if (exact) return exact
|
||||||
|
try {
|
||||||
|
const requested = parseSearchCacheKey(cacheKey)
|
||||||
|
if (!requested) return null
|
||||||
|
const records = JSON.parse(localStorage.getItem(SEARCH_CACHE_KEY) || '[]') as AISearchCacheRecord[]
|
||||||
|
return records
|
||||||
|
.filter((record) => {
|
||||||
|
try {
|
||||||
|
const raw = JSON.parse(record.key) as unknown[]
|
||||||
|
const location = parseSearchCacheKey(record.key)
|
||||||
|
// Only legacy four-part keys may use compatibility lookup, and
|
||||||
|
// all base dimensions must still match the active request.
|
||||||
|
return raw.length === 4 && location?.scope === requested.scope &&
|
||||||
|
location.contactMd5 === requested.contactMd5 && location.range === requested.range &&
|
||||||
|
location.query === requested.query
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.sort((a, b) => b.createdAt - a.createdAt)[0] || null
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const persistSearchResult = (input: PersistSearchResultInput): AISearchCacheRecord => {
|
const persistSearchResult = (input: PersistSearchResultInput): AISearchCacheRecord => {
|
||||||
const record = createSearchCacheRecord({
|
const record = createSearchCacheRecord({
|
||||||
...input,
|
...input,
|
||||||
@@ -288,7 +315,7 @@ export function useSearchHistory({
|
|||||||
removeHistoryQuery,
|
removeHistoryQuery,
|
||||||
restoreHistoryQuery,
|
restoreHistoryQuery,
|
||||||
applyCachedResult,
|
applyCachedResult,
|
||||||
readCachedResult: readSearchCache,
|
readCachedResult,
|
||||||
persistSearchResult,
|
persistSearchResult,
|
||||||
clearActiveResult,
|
clearActiveResult,
|
||||||
skipNextCache,
|
skipNextCache,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
SEARCH_CACHE_KEY,
|
SEARCH_CACHE_KEY,
|
||||||
buildSearchCacheKey
|
buildSearchCacheKey
|
||||||
} from '../../src/renderer/src/components/search/searchUtils'
|
} from '../../src/renderer/src/components/search/searchUtils'
|
||||||
import { makeSearchResult } from './support/ai-search-fixtures'
|
import { makePipelineEvidence, makeSearchResult } from './support/ai-search-fixtures'
|
||||||
|
|
||||||
const api = {
|
const api = {
|
||||||
getSettings: vi.fn(),
|
getSettings: vi.fn(),
|
||||||
@@ -224,7 +224,7 @@ describe('AISearchWorkspace cache privacy boundary', () => {
|
|||||||
value: scrollIntoView
|
value: scrollIntoView
|
||||||
})
|
})
|
||||||
api.getAiSearchProviderStatus.mockResolvedValue({ configured: true, requiresConsent: false })
|
api.getAiSearchProviderStatus.mockResolvedValue({ configured: true, requiresConsent: false })
|
||||||
api.runAiSearch.mockResolvedValue({
|
api.runAiSearch.mockResolvedValue(makeSearchResult({
|
||||||
requestId: 'evidence-navigation',
|
requestId: 'evidence-navigation',
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
answer: '请查看这条证据 [E7]。',
|
answer: '请查看这条证据 [E7]。',
|
||||||
@@ -264,7 +264,7 @@ describe('AISearchWorkspace cache privacy boundary', () => {
|
|||||||
agent: { mode: 'agent', toolCalls: 1, trace: [] },
|
agent: { mode: 'agent', toolCalls: 1, trace: [] },
|
||||||
timings: {},
|
timings: {},
|
||||||
elapsedMs: 1
|
elapsedMs: 1
|
||||||
} as never)
|
}) as never)
|
||||||
render(
|
render(
|
||||||
<AISearchWorkspace
|
<AISearchWorkspace
|
||||||
contacts={[]}
|
contacts={[]}
|
||||||
@@ -300,7 +300,7 @@ describe('AISearchWorkspace cache privacy boundary', () => {
|
|||||||
|
|
||||||
it('keeps the submitted result title stable while drafting a new question and clears it from 新问题', async () => {
|
it('keeps the submitted result title stable while drafting a new question and clears it from 新问题', async () => {
|
||||||
api.getAiSearchProviderStatus.mockResolvedValue({ configured: true, requiresConsent: false })
|
api.getAiSearchProviderStatus.mockResolvedValue({ configured: true, requiresConsent: false })
|
||||||
api.runAiSearch.mockResolvedValue({
|
api.runAiSearch.mockResolvedValue(makeSearchResult({
|
||||||
requestId: 'new-question',
|
requestId: 'new-question',
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
answer: 'first answer',
|
answer: 'first answer',
|
||||||
@@ -319,7 +319,7 @@ describe('AISearchWorkspace cache privacy boundary', () => {
|
|||||||
agent: { mode: 'agent', toolCalls: 1, trace: [] },
|
agent: { mode: 'agent', toolCalls: 1, trace: [] },
|
||||||
timings: {},
|
timings: {},
|
||||||
elapsedMs: 1
|
elapsedMs: 1
|
||||||
} as never)
|
}) as never)
|
||||||
render(
|
render(
|
||||||
<AISearchWorkspace
|
<AISearchWorkspace
|
||||||
contacts={[]}
|
contacts={[]}
|
||||||
|
|||||||
Reference in New Issue
Block a user