mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 16:25:51 +00:00
style: 完成所有文件的lint
This commit is contained in:
@@ -24,7 +24,7 @@ async function main() {
|
||||
const startTime = Date.now()
|
||||
|
||||
const results = await adapter.search(query, {
|
||||
onProgress: (p) => {
|
||||
onProgress: p => {
|
||||
if (p.type === 'query_update') {
|
||||
console.log(` → Query sent: ${p.query}`)
|
||||
}
|
||||
@@ -51,7 +51,9 @@ async function main() {
|
||||
console.log(` ${r.url}`)
|
||||
if (r.snippet) {
|
||||
const snippet = r.snippet.replace(/\n/g, ' ')
|
||||
console.log(` ${snippet.slice(0, 150)}${snippet.length > 150 ? '…' : ''}`)
|
||||
console.log(
|
||||
` ${snippet.slice(0, 150)}${snippet.length > 150 ? '…' : ''}`,
|
||||
)
|
||||
}
|
||||
console.log()
|
||||
}
|
||||
@@ -76,7 +78,7 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
main().catch(e => {
|
||||
console.error('❌ Fatal error:', e)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
@@ -2,9 +2,13 @@ import { describe, expect, mock, test } from 'bun:test'
|
||||
|
||||
const _abortMock = () => ({
|
||||
AbortError: class AbortError extends Error {
|
||||
constructor(message?: string) { super(message); this.name = 'AbortError' }
|
||||
constructor(message?: string) {
|
||||
super(message)
|
||||
this.name = 'AbortError'
|
||||
}
|
||||
},
|
||||
isAbortError: (e: unknown) => e instanceof Error && (e as Error).name === 'AbortError',
|
||||
isAbortError: (e: unknown) =>
|
||||
e instanceof Error && (e as Error).name === 'AbortError',
|
||||
})
|
||||
mock.module('src/utils/errors.js', _abortMock)
|
||||
mock.module('src/utils/errors', _abortMock)
|
||||
@@ -45,7 +49,9 @@ describe('decodeHtmlEntities', () => {
|
||||
})
|
||||
|
||||
test('handles mixed entities in one string', () => {
|
||||
expect(decodeHtmlEntities('<a href="x">')).toBe('<a\u00A0href="x">')
|
||||
expect(decodeHtmlEntities('<a href="x">')).toBe(
|
||||
'<a\u00A0href="x">',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -44,7 +44,11 @@ describe('extractBraveResults', () => {
|
||||
})
|
||||
|
||||
expect(results).toEqual([
|
||||
{ title: 'Generic', url: 'https://example.com/generic', snippet: undefined },
|
||||
{
|
||||
title: 'Generic',
|
||||
url: 'https://example.com/generic',
|
||||
snippet: undefined,
|
||||
},
|
||||
{ title: 'POI', url: 'https://maps.example.com/poi', snippet: undefined },
|
||||
{ title: 'Map', url: 'https://maps.example.com/map', snippet: undefined },
|
||||
])
|
||||
|
||||
@@ -5,9 +5,13 @@ import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test'
|
||||
// import in createAdapter() never needs to resolve the alias at runtime.
|
||||
const _abortMock = () => ({
|
||||
AbortError: class AbortError extends Error {
|
||||
constructor(message?: string) { super(message); this.name = 'AbortError' }
|
||||
constructor(message?: string) {
|
||||
super(message)
|
||||
this.name = 'AbortError'
|
||||
}
|
||||
},
|
||||
isAbortError: (e: unknown) => e instanceof Error && (e as Error).name === 'AbortError',
|
||||
isAbortError: (e: unknown) =>
|
||||
e instanceof Error && (e as Error).name === 'AbortError',
|
||||
})
|
||||
mock.module('src/utils/errors.js', _abortMock)
|
||||
mock.module('src/utils/errors', _abortMock)
|
||||
|
||||
@@ -2,9 +2,13 @@ import { afterEach, describe, expect, mock, test } from 'bun:test'
|
||||
|
||||
const _abortMock = () => ({
|
||||
AbortError: class AbortError extends Error {
|
||||
constructor(message?: string) { super(message); this.name = 'AbortError' }
|
||||
constructor(message?: string) {
|
||||
super(message)
|
||||
this.name = 'AbortError'
|
||||
}
|
||||
},
|
||||
isAbortError: (e: unknown) => e instanceof Error && (e as Error).name === 'AbortError',
|
||||
isAbortError: (e: unknown) =>
|
||||
e instanceof Error && (e as Error).name === 'AbortError',
|
||||
})
|
||||
mock.module('src/utils/errors.js', _abortMock)
|
||||
mock.module('src/utils/errors', _abortMock)
|
||||
@@ -16,7 +20,8 @@ describe('ExaSearchAdapter.search', () => {
|
||||
}
|
||||
|
||||
// Exa MCP returns SSE lines like: data: {"result":{"content":[{"type":"text","text":"..."}]}}
|
||||
const buildSseResponse = (text: string) => `data: ${JSON.stringify({ result: { content: [{ type: 'text', text }] } })}\n`
|
||||
const buildSseResponse = (text: string) =>
|
||||
`data: ${JSON.stringify({ result: { content: [{ type: 'text', text }] } })}\n`
|
||||
|
||||
const STRUCTURED_TEXT = [
|
||||
'Title: Example Result 1',
|
||||
@@ -37,7 +42,9 @@ describe('ExaSearchAdapter.search', () => {
|
||||
test('parses structured Title/URL/Content blocks from SSE response', async () => {
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
post: mock(() => Promise.resolve({ data: buildSseResponse(STRUCTURED_TEXT) })),
|
||||
post: mock(() =>
|
||||
Promise.resolve({ data: buildSseResponse(STRUCTURED_TEXT) }),
|
||||
),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
@@ -59,10 +66,13 @@ describe('ExaSearchAdapter.search', () => {
|
||||
})
|
||||
|
||||
test('parses markdown link fallback when no structured blocks', async () => {
|
||||
const markdownText = '- [React Docs](https://react.dev/docs)\n- [React Hooks](https://react.dev/hooks)'
|
||||
const markdownText =
|
||||
'- [React Docs](https://react.dev/docs)\n- [React Hooks](https://react.dev/hooks)'
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
post: mock(() => Promise.resolve({ data: buildSseResponse(markdownText) })),
|
||||
post: mock(() =>
|
||||
Promise.resolve({ data: buildSseResponse(markdownText) }),
|
||||
),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
@@ -83,7 +93,9 @@ describe('ExaSearchAdapter.search', () => {
|
||||
const plainUrlText = 'https://example.com/page1\nhttps://example.com/page2'
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
post: mock(() => Promise.resolve({ data: buildSseResponse(plainUrlText) })),
|
||||
post: mock(() =>
|
||||
Promise.resolve({ data: buildSseResponse(plainUrlText) }),
|
||||
),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
@@ -130,7 +142,9 @@ describe('ExaSearchAdapter.search', () => {
|
||||
test('calls onProgress with query_update and search_results_received', async () => {
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
post: mock(() => Promise.resolve({ data: buildSseResponse(STRUCTURED_TEXT) })),
|
||||
post: mock(() =>
|
||||
Promise.resolve({ data: buildSseResponse(STRUCTURED_TEXT) }),
|
||||
),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
@@ -161,13 +175,17 @@ describe('ExaSearchAdapter.search', () => {
|
||||
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
post: mock(() => Promise.resolve({ data: buildSseResponse(mixedText) })),
|
||||
post: mock(() =>
|
||||
Promise.resolve({ data: buildSseResponse(mixedText) }),
|
||||
),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
|
||||
const adapter = await createAdapter()
|
||||
const results = await adapter.search('test', { allowedDomains: ['allowed.com'] })
|
||||
const results = await adapter.search('test', {
|
||||
allowedDomains: ['allowed.com'],
|
||||
})
|
||||
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].url).toBe('https://allowed.com/a')
|
||||
@@ -184,13 +202,17 @@ describe('ExaSearchAdapter.search', () => {
|
||||
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
post: mock(() => Promise.resolve({ data: buildSseResponse(mixedText) })),
|
||||
post: mock(() =>
|
||||
Promise.resolve({ data: buildSseResponse(mixedText) }),
|
||||
),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
|
||||
const adapter = await createAdapter()
|
||||
const results = await adapter.search('test', { blockedDomains: ['spam.com'] })
|
||||
const results = await adapter.search('test', {
|
||||
blockedDomains: ['spam.com'],
|
||||
})
|
||||
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].url).toBe('https://good.com/a')
|
||||
@@ -213,7 +235,9 @@ describe('ExaSearchAdapter.search', () => {
|
||||
}))
|
||||
|
||||
const adapter = await createAdapter()
|
||||
const results = await adapter.search('test', { allowedDomains: ['example.com'] })
|
||||
const results = await adapter.search('test', {
|
||||
allowedDomains: ['example.com'],
|
||||
})
|
||||
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].url).toBe('https://docs.example.com/page')
|
||||
@@ -222,7 +246,9 @@ describe('ExaSearchAdapter.search', () => {
|
||||
test('throws AbortError when signal is already aborted', async () => {
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
post: mock(() => Promise.resolve({ data: buildSseResponse(STRUCTURED_TEXT) })),
|
||||
post: mock(() =>
|
||||
Promise.resolve({ data: buildSseResponse(STRUCTURED_TEXT) }),
|
||||
),
|
||||
isCancel: () => false,
|
||||
},
|
||||
}))
|
||||
@@ -251,7 +277,9 @@ describe('ExaSearchAdapter.search', () => {
|
||||
})
|
||||
|
||||
test('sends correct MCP request payload to Exa endpoint', async () => {
|
||||
const axiosPost = mock(() => Promise.resolve({ data: buildSseResponse(STRUCTURED_TEXT) }))
|
||||
const axiosPost = mock(() =>
|
||||
Promise.resolve({ data: buildSseResponse(STRUCTURED_TEXT) }),
|
||||
)
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
post: axiosPost,
|
||||
@@ -277,7 +305,9 @@ describe('ExaSearchAdapter.search', () => {
|
||||
})
|
||||
|
||||
test('passes custom search options to MCP request', async () => {
|
||||
const axiosPost = mock(() => Promise.resolve({ data: buildSseResponse(STRUCTURED_TEXT) }))
|
||||
const axiosPost = mock(() =>
|
||||
Promise.resolve({ data: buildSseResponse(STRUCTURED_TEXT) }),
|
||||
)
|
||||
mock.module('axios', () => ({
|
||||
default: {
|
||||
post: axiosPost,
|
||||
|
||||
Reference in New Issue
Block a user