chore(cleanup): remove web search skill
Remove search_web and uninstall the now-unused cheerio dependency it was the only consumer of. The skill's shared test file also covered document extraction (extractText), so it is removed here; extractText itself is removed in the following document drag-and-drop cleanup. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
c99b01a902
commit
cf92418bad
@@ -1,104 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const tempDir = mkdtempSync(join(tmpdir(), 'forge-avatar-web-documents-test-'))
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: { getPath: () => tempDir }
|
||||
}))
|
||||
vi.mock('../../src/main/windowBridge', () => ({ sendToRenderer: vi.fn() }))
|
||||
|
||||
// pdf-parse/index.js execute du code de demo au chargement quand `module.parent` est absent (cas du
|
||||
// loader de Vitest), ce qui tente de lire un fichier de test inexistant : on le mocke entierement
|
||||
// plutot que de changer le point d'entree importe par le code de production pour contourner ce bug
|
||||
// tiers.
|
||||
vi.mock('pdf-parse', () => ({ default: vi.fn(async () => ({ text: 'Texte extrait du PDF' })) }))
|
||||
vi.mock('mammoth', () => ({
|
||||
default: { extractRawText: vi.fn(async () => ({ value: 'Texte extrait du docx' })) }
|
||||
}))
|
||||
|
||||
const { searchWeb } = await import('../../src/main/skills/web/searchWeb')
|
||||
const { extractText } = await import('../../src/main/skills/documents/extractText')
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('search_web', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('fetch', vi.fn())
|
||||
})
|
||||
|
||||
it('should refuse an empty query', async () => {
|
||||
await expect(searchWeb.execute({ query: '' })).rejects.toThrow(/query manquante/)
|
||||
})
|
||||
|
||||
it('should parse DuckDuckGo HTML results into a readable list', async () => {
|
||||
const html = `
|
||||
<div class="result web-result">
|
||||
<div class="result__body">
|
||||
<a class="result__a" href="//duckduckgo.com/l/?uddg=https%3A%2F%2Fexample.com">Titre du resultat</a>
|
||||
<a class="result__title"><span>Titre du resultat</span></a>
|
||||
<div class="result__snippet">Un extrait pertinent.</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
vi.mocked(fetch).mockResolvedValue({ ok: true, text: () => Promise.resolve(html) } as Response)
|
||||
const result = await searchWeb.execute({ query: 'test' })
|
||||
expect(result).toMatch(/example\.com/)
|
||||
})
|
||||
|
||||
it('should report no results when nothing matches', async () => {
|
||||
vi.mocked(fetch).mockResolvedValue({
|
||||
ok: true,
|
||||
text: () => Promise.resolve('<html></html>')
|
||||
} as Response)
|
||||
const result = await searchWeb.execute({ query: 'test' })
|
||||
expect(result).toMatch(/Aucun resultat/)
|
||||
})
|
||||
|
||||
it('should throw when the request fails', async () => {
|
||||
vi.mocked(fetch).mockResolvedValue({ ok: false, status: 503 } as Response)
|
||||
await expect(searchWeb.execute({ query: 'test' })).rejects.toThrow(/echouee/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('extractText()', () => {
|
||||
it('should read a plain text file as-is', async () => {
|
||||
const filePath = join(tempDir, 'note.txt')
|
||||
writeFileSync(filePath, 'Contenu simple')
|
||||
const doc = await extractText(filePath)
|
||||
expect(doc.text).toBe('Contenu simple')
|
||||
expect(doc.truncated).toBe(false)
|
||||
})
|
||||
|
||||
it('should truncate content longer than the max length', async () => {
|
||||
const filePath = join(tempDir, 'long.txt')
|
||||
writeFileSync(filePath, 'a'.repeat(20000))
|
||||
const doc = await extractText(filePath)
|
||||
expect(doc.truncated).toBe(true)
|
||||
expect(doc.text.length).toBe(12000)
|
||||
})
|
||||
|
||||
it('should throw for an unsupported file extension', async () => {
|
||||
const filePath = join(tempDir, 'image.png')
|
||||
writeFileSync(filePath, 'binaire')
|
||||
await expect(extractText(filePath)).rejects.toThrow(/non supporte/)
|
||||
})
|
||||
|
||||
it('should extract text from a .pdf file via pdf-parse', async () => {
|
||||
const filePath = join(tempDir, 'document.pdf')
|
||||
writeFileSync(filePath, 'contenu-binaire-simule')
|
||||
const doc = await extractText(filePath)
|
||||
expect(doc.text).toBe('Texte extrait du PDF')
|
||||
})
|
||||
|
||||
it('should extract text from a .docx file via mammoth', async () => {
|
||||
const filePath = join(tempDir, 'document.docx')
|
||||
writeFileSync(filePath, 'contenu-binaire-simule')
|
||||
const doc = await extractText(filePath)
|
||||
expect(doc.text).toBe('Texte extrait du docx')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user