| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import {it,expect} from 'vitest'
- import {parseGrokBotPage,grokBotDraft,fetchGrokBotPage,GrokBotImportError} from '../../src/shared/grokBotImport'
- const tradbotHtml=`<!doctype html><html><head>
- <meta property="og:title" content="Tradbot">
- <meta property="og:description" content="Watches your personal email and calendar so school forms, bills, and RSVPs don't slip. Drafts the reply, catches the pickup clash, and never sends without you.">
- <meta property="og:image" content="https://x.ai/og/tradbot.png">
- </head><body></body></html>`
- const managerHtml=tradbotHtml.replace('Tradbot','Projects Manager').replace(/content="Watches[^"]*"/,'content="Runs your team\'s projects from Notion: one row per project, a channel per project, and tasks your specialist bots claim."')
- it('parses og metadata from a bot page',()=>{
- const meta=parseGrokBotPage(tradbotHtml)!
- expect(meta.name).toBe('Tradbot')
- expect(meta.description).toContain('never sends without you')
- expect(meta.imageUrl).toBe('https://x.ai/og/tradbot.png')
- })
- it('maps a housekeeper description onto the adapted template',()=>{
- const draft=grokBotDraft(parseGrokBotPage(tradbotHtml)!)
- expect(draft.kind).toBe('housekeeper')
- expect(draft.antiJobs).toContain('绝不直接发送邮件或回复邀请')
- expect(draft.instructions).toContain('desktop_shell')
- expect(draft.instructions).toContain('Tradbot')
- expect(draft.suggestions.join()).toContain('定时任务')
- })
- it('maps a manager description onto the team template',()=>{
- const draft=grokBotDraft(parseGrokBotPage(managerHtml)!)
- expect(draft.kind).toBe('manager')
- expect(draft.canManageTeam).toBe(true)
- expect(draft.job).toContain('任务计划')
- expect(draft.antiJobs).toContain('绝不替专家 Bot 完成具体工作')
- })
- it('validates the x.ai bot URL before fetching',async()=>{
- await expect(fetchGrokBotPage('https://example.com/bot/x')).rejects.toMatchObject({code:'invalid_grok_bot_url'})
- })
- it('rejects pages without bot metadata',async()=>{
- const fake=(async()=>new Response('<html><body>login</body></html>',{status:200})) as unknown as typeof fetch
- await expect(fetchGrokBotPage('https://x.ai/bot/_abc',fake)).rejects.toBeInstanceOf(GrokBotImportError)
- })
- it('fetches and parses through an injected fetch implementation',async()=>{
- const fake=(async()=>new Response(tradbotHtml,{status:200,headers:{'content-type':'text/html'}})) as unknown as typeof fetch
- const html=await fetchGrokBotPage('https://x.ai/bot/_abc',fake)
- expect(parseGrokBotPage(html)!.name).toBe('Tradbot')
- })
|