|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + * |
| 4 | + * AgentMail's `DELETE /v0/inboxes/{inbox_id}/threads/{thread_id}` declares exactly three |
| 5 | + * parameters — `inbox_id`, `thread_id`, `Authorization` — and its description reads |
| 6 | + * "Permanently deletes a thread and all of its messages." |
| 7 | + * |
| 8 | + * There is no `permanent` query parameter, so a `?permanent=` we appended was inert and the |
| 9 | + * block's "No (move to trash)" default told the user the opposite of what the request did. |
| 10 | + * These pin that no delete request carries a phantom parameter and that the editor no longer |
| 11 | + * offers a non-permanent choice. |
| 12 | + */ |
| 13 | +import { describe, expect, it } from 'vitest' |
| 14 | +import { AgentMailBlock } from '@/blocks/blocks/agentmail' |
| 15 | +import { agentmailDeleteDraftTool } from '@/tools/agentmail/delete_draft' |
| 16 | +import { agentmailDeleteInboxTool } from '@/tools/agentmail/delete_inbox' |
| 17 | +import { agentmailDeleteThreadTool } from '@/tools/agentmail/delete_thread' |
| 18 | +import type { ToolConfig } from '@/tools/types' |
| 19 | + |
| 20 | +function buildUrl(tool: ToolConfig<any, any>, params: Record<string, unknown>): string { |
| 21 | + const url = tool.request.url |
| 22 | + return typeof url === 'function' ? url(params as never) : url |
| 23 | +} |
| 24 | + |
| 25 | +const INBOX = 'yourinbox@agentmail.to' |
| 26 | +const THREAD = 'thread_01HQ8ZK4N2XW9V' |
| 27 | + |
| 28 | +describe('agentmail delete tools carry no phantom parameters', () => { |
| 29 | + it('never appends a `permanent` query parameter, whatever the caller passes', () => { |
| 30 | + for (const extra of [{}, { permanent: true }, { permanent: false }, { permanent: 'true' }]) { |
| 31 | + const url = new URL( |
| 32 | + buildUrl(agentmailDeleteThreadTool, { inboxId: INBOX, threadId: THREAD, ...extra }) |
| 33 | + ) |
| 34 | + expect(url.searchParams.has('permanent')).toBe(false) |
| 35 | + expect(url.search).toBe('') |
| 36 | + } |
| 37 | + }) |
| 38 | + |
| 39 | + it('produces the byte-identical URL today`s legitimate call produced, minus the phantom param', () => { |
| 40 | + expect(buildUrl(agentmailDeleteThreadTool, { inboxId: INBOX, threadId: THREAD })).toBe( |
| 41 | + `https://api.agentmail.to/v0/inboxes/${encodeURIComponent(INBOX)}/threads/${THREAD}` |
| 42 | + ) |
| 43 | + }) |
| 44 | + |
| 45 | + it('does not declare a `permanent` tool param', () => { |
| 46 | + expect(Object.keys(agentmailDeleteThreadTool.params)).not.toContain('permanent') |
| 47 | + }) |
| 48 | + |
| 49 | + it('leaves the sibling delete tools query-free', () => { |
| 50 | + expect( |
| 51 | + new URL(buildUrl(agentmailDeleteDraftTool, { inboxId: INBOX, draftId: 'd_1' })).search |
| 52 | + ).toBe('') |
| 53 | + expect(new URL(buildUrl(agentmailDeleteInboxTool, { inboxId: INBOX })).search).toBe('') |
| 54 | + }) |
| 55 | + |
| 56 | + it('describes thread deletion as permanent and irreversible', () => { |
| 57 | + expect(agentmailDeleteThreadTool.description.toLowerCase()).toContain('permanent') |
| 58 | + expect(agentmailDeleteThreadTool.description.toLowerCase()).not.toContain('trash') |
| 59 | + }) |
| 60 | +}) |
| 61 | + |
| 62 | +describe('the AgentMail block offers no non-permanent delete option', () => { |
| 63 | + const permanentSubBlock = AgentMailBlock.subBlocks.find((sub) => sub.id === 'permanent') |
| 64 | + |
| 65 | + it('no longer renders a selectable control for `permanent`', () => { |
| 66 | + if (!permanentSubBlock) return |
| 67 | + expect(permanentSubBlock.type).toBe('text') |
| 68 | + expect(permanentSubBlock).not.toHaveProperty('options') |
| 69 | + }) |
| 70 | + |
| 71 | + it('states plainly that the deletion cannot be undone', () => { |
| 72 | + if (!permanentSubBlock) return |
| 73 | + const content = String(permanentSubBlock.defaultValue ?? '').toLowerCase() |
| 74 | + expect(content).toContain('permanent') |
| 75 | + expect(content).toContain('cannot be undone') |
| 76 | + }) |
| 77 | + |
| 78 | + it('never forwards a `permanent` value to the tool', () => { |
| 79 | + const transform = AgentMailBlock.tools.config!.params! |
| 80 | + const resolved = transform({ |
| 81 | + operation: 'delete_thread', |
| 82 | + inboxId: INBOX, |
| 83 | + threadId: THREAD, |
| 84 | + permanent: 'false', |
| 85 | + } as never) as Record<string, unknown> |
| 86 | + |
| 87 | + expect(resolved).not.toHaveProperty('permanent') |
| 88 | + }) |
| 89 | + |
| 90 | + it('does not declare `permanent` as a block input', () => { |
| 91 | + expect(Object.keys(AgentMailBlock.inputs)).not.toContain('permanent') |
| 92 | + }) |
| 93 | +}) |
0 commit comments