import {it,expect} from 'vitest' import {parseGrokBotPage,grokBotDraft,fetchGrokBotPage,GrokBotImportError} from '../../src/shared/grokBotImport' const tradbotHtml=`
` 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('login',{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') })