@aria-cli/tools 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/package.json +9 -5
  2. package/src/__tests__/web-fetch-download.test.ts +0 -433
  3. package/src/__tests__/web-tools.test.ts +0 -619
  4. package/src/ask-user-interaction.ts +0 -33
  5. package/src/cache/web-cache.ts +0 -110
  6. package/src/definitions/arion.ts +0 -118
  7. package/src/definitions/browser/browser.ts +0 -502
  8. package/src/definitions/browser/index.ts +0 -5
  9. package/src/definitions/browser/pw-downloads.ts +0 -142
  10. package/src/definitions/browser/pw-interactions.ts +0 -282
  11. package/src/definitions/browser/pw-responses.ts +0 -98
  12. package/src/definitions/browser/pw-session.ts +0 -405
  13. package/src/definitions/browser/pw-shared.ts +0 -85
  14. package/src/definitions/browser/pw-snapshot.ts +0 -383
  15. package/src/definitions/browser/pw-state.ts +0 -101
  16. package/src/definitions/browser/types.ts +0 -203
  17. package/src/definitions/code-intelligence.ts +0 -526
  18. package/src/definitions/core.ts +0 -118
  19. package/src/definitions/delegation.ts +0 -567
  20. package/src/definitions/deploy.ts +0 -73
  21. package/src/definitions/filesystem.ts +0 -217
  22. package/src/definitions/frg.ts +0 -67
  23. package/src/definitions/index.ts +0 -28
  24. package/src/definitions/memory.ts +0 -150
  25. package/src/definitions/messaging.ts +0 -734
  26. package/src/definitions/meta.ts +0 -392
  27. package/src/definitions/network.ts +0 -179
  28. package/src/definitions/outlook.ts +0 -318
  29. package/src/definitions/patch/apply-patch.ts +0 -235
  30. package/src/definitions/patch/fuzzy-match.ts +0 -217
  31. package/src/definitions/patch/index.ts +0 -1
  32. package/src/definitions/patch/patch-parser.ts +0 -297
  33. package/src/definitions/patch/sandbox-paths.ts +0 -129
  34. package/src/definitions/process/index.ts +0 -5
  35. package/src/definitions/process/process-registry.ts +0 -303
  36. package/src/definitions/process/process.ts +0 -456
  37. package/src/definitions/process/pty-keys.ts +0 -298
  38. package/src/definitions/process/session-slug.ts +0 -147
  39. package/src/definitions/quip.ts +0 -225
  40. package/src/definitions/search.ts +0 -67
  41. package/src/definitions/session-history.ts +0 -79
  42. package/src/definitions/shell.ts +0 -202
  43. package/src/definitions/slack.ts +0 -211
  44. package/src/definitions/web.ts +0 -119
  45. package/src/executors/apply-patch.ts +0 -1035
  46. package/src/executors/arion.ts +0 -199
  47. package/src/executors/code-intelligence.ts +0 -1179
  48. package/src/executors/deploy.ts +0 -1066
  49. package/src/executors/filesystem.ts +0 -1428
  50. package/src/executors/frg-freshness.ts +0 -743
  51. package/src/executors/frg.ts +0 -394
  52. package/src/executors/index.ts +0 -280
  53. package/src/executors/learning-meta.ts +0 -1367
  54. package/src/executors/lsp-client.ts +0 -355
  55. package/src/executors/memory.ts +0 -978
  56. package/src/executors/meta.ts +0 -293
  57. package/src/executors/process-registry.ts +0 -570
  58. package/src/executors/pty-session-store.ts +0 -43
  59. package/src/executors/pty.ts +0 -342
  60. package/src/executors/restart.ts +0 -133
  61. package/src/executors/search-freshness.ts +0 -249
  62. package/src/executors/search-types.ts +0 -98
  63. package/src/executors/search.ts +0 -89
  64. package/src/executors/self-diagnose.ts +0 -552
  65. package/src/executors/session-history.ts +0 -435
  66. package/src/executors/shell-safety.ts +0 -519
  67. package/src/executors/shell.ts +0 -1243
  68. package/src/executors/utils.ts +0 -40
  69. package/src/executors/web.ts +0 -786
  70. package/src/extraction/content-extraction.ts +0 -281
  71. package/src/extraction/index.ts +0 -5
  72. package/src/headless-control-contract.ts +0 -1149
  73. package/src/index.ts +0 -788
  74. package/src/local-control-http-auth.ts +0 -2
  75. package/src/mcp/client.ts +0 -218
  76. package/src/mcp/connection.ts +0 -568
  77. package/src/mcp/index.ts +0 -11
  78. package/src/mcp/jsonrpc.ts +0 -195
  79. package/src/mcp/types.ts +0 -199
  80. package/src/network-control-adapter.ts +0 -88
  81. package/src/network-runtime/address-types.ts +0 -218
  82. package/src/network-runtime/db-owner-fencing.ts +0 -91
  83. package/src/network-runtime/delivery-receipts.ts +0 -372
  84. package/src/network-runtime/direct-endpoint-authority.ts +0 -35
  85. package/src/network-runtime/index.ts +0 -316
  86. package/src/network-runtime/local-control-contract.ts +0 -784
  87. package/src/network-runtime/node-store-contract.ts +0 -46
  88. package/src/network-runtime/pair-route-contract.ts +0 -97
  89. package/src/network-runtime/peer-capabilities.ts +0 -48
  90. package/src/network-runtime/peer-principal-ref.ts +0 -20
  91. package/src/network-runtime/peer-state-machine.ts +0 -160
  92. package/src/network-runtime/protocol-schemas.ts +0 -265
  93. package/src/network-runtime/runtime-bootstrap-contract.ts +0 -83
  94. package/src/outlook/desktop-session.ts +0 -409
  95. package/src/policy.ts +0 -171
  96. package/src/providers/brave.ts +0 -80
  97. package/src/providers/duckduckgo.ts +0 -199
  98. package/src/providers/exa.ts +0 -85
  99. package/src/providers/firecrawl.ts +0 -77
  100. package/src/providers/index.ts +0 -8
  101. package/src/providers/jina.ts +0 -70
  102. package/src/providers/router.ts +0 -121
  103. package/src/providers/search-provider.ts +0 -74
  104. package/src/providers/tavily.ts +0 -74
  105. package/src/quip/desktop-session.ts +0 -435
  106. package/src/registry/index.ts +0 -1
  107. package/src/registry/registry.ts +0 -905
  108. package/src/runtime-socket-local-control-client.ts +0 -632
  109. package/src/security/dns-normalization.ts +0 -34
  110. package/src/security/dns-pinning.ts +0 -138
  111. package/src/security/external-content.ts +0 -129
  112. package/src/security/ssrf.ts +0 -207
  113. package/src/slack/desktop-session.ts +0 -493
  114. package/src/tool-factory.ts +0 -91
  115. package/src/types.ts +0 -1341
  116. package/src/utils/retry.ts +0 -163
  117. package/src/utils/safe-parse-json.ts +0 -176
  118. package/src/utils/url.ts +0 -20
  119. package/tests/benchmarks/registry.bench.ts +0 -57
  120. package/tests/cache/web-cache.test.ts +0 -147
  121. package/tests/critical-integration.test.ts +0 -1465
  122. package/tests/definitions/apply-patch.test.ts +0 -586
  123. package/tests/definitions/browser.test.ts +0 -495
  124. package/tests/definitions/delegation-pause-resume.test.ts +0 -758
  125. package/tests/definitions/execution.test.ts +0 -671
  126. package/tests/definitions/messaging-inbox-scope.test.ts +0 -229
  127. package/tests/definitions/messaging.test.ts +0 -1468
  128. package/tests/definitions/outlook.test.ts +0 -30
  129. package/tests/definitions/process.test.ts +0 -469
  130. package/tests/definitions/slack.test.ts +0 -28
  131. package/tests/definitions/tool-inventory.test.ts +0 -218
  132. package/tests/e2e/delegation-quest-orchestration.e2e.test.ts +0 -433
  133. package/tests/e2e/memory-tool-discovery-contract.e2e.test.ts +0 -81
  134. package/tests/executors/apply-patch.test.ts +0 -538
  135. package/tests/executors/arion.test.ts +0 -309
  136. package/tests/executors/conversation-primitives.test.ts +0 -250
  137. package/tests/executors/deploy.test.ts +0 -746
  138. package/tests/executors/filesystem-tools.test.ts +0 -357
  139. package/tests/executors/filesystem.test.ts +0 -959
  140. package/tests/executors/frg-freshness.test.ts +0 -136
  141. package/tests/executors/frg-merge.test.ts +0 -70
  142. package/tests/executors/frg-session-content.test.ts +0 -40
  143. package/tests/executors/frg.test.ts +0 -56
  144. package/tests/executors/memory-bugfixes.test.ts +0 -257
  145. package/tests/executors/memory-real-memoria.integration.test.ts +0 -316
  146. package/tests/executors/memory.test.ts +0 -853
  147. package/tests/executors/meta-tools.test.ts +0 -411
  148. package/tests/executors/meta.test.ts +0 -683
  149. package/tests/executors/path-containment.test.ts +0 -51
  150. package/tests/executors/process-registry.test.ts +0 -505
  151. package/tests/executors/pty.test.ts +0 -664
  152. package/tests/executors/quest-security.test.ts +0 -249
  153. package/tests/executors/read-file-media.test.ts +0 -230
  154. package/tests/executors/recall-knowledge-schema.test.ts +0 -209
  155. package/tests/executors/recall-tags.test.ts +0 -278
  156. package/tests/executors/remember-null-safety.contract.test.ts +0 -41
  157. package/tests/executors/restart.test.ts +0 -67
  158. package/tests/executors/search-unified.test.ts +0 -381
  159. package/tests/executors/session-history.test.ts +0 -340
  160. package/tests/executors/session-transcript.test.ts +0 -561
  161. package/tests/executors/shell-abort.test.ts +0 -416
  162. package/tests/executors/shell-env-blocklist.test.ts +0 -648
  163. package/tests/executors/shell-env-process.test.ts +0 -245
  164. package/tests/executors/shell-process-registry.test.ts +0 -334
  165. package/tests/executors/shell-tools.test.ts +0 -393
  166. package/tests/executors/shell.test.ts +0 -690
  167. package/tests/executors/web-abort-vs-timeout.test.ts +0 -213
  168. package/tests/executors/web-integration.test.ts +0 -633
  169. package/tests/executors/web-symlink.test.ts +0 -18
  170. package/tests/executors/web.test.ts +0 -1400
  171. package/tests/executors/write-stdin.test.ts +0 -145
  172. package/tests/extraction/content-extraction.test.ts +0 -153
  173. package/tests/guards/tools-default-test-lane.integration.test.ts +0 -21
  174. package/tests/guards/tools-package-test-commands.e2e.test.ts +0 -43
  175. package/tests/guards/tools-test-lane-manifest.contract.test.ts +0 -76
  176. package/tests/guards/tools-vitest-workspace-alias.contract.test.ts +0 -63
  177. package/tests/helpers/async-waits.ts +0 -53
  178. package/tests/integration/headless-control-contract.integration.test.ts +0 -153
  179. package/tests/integration/memory-tool-schema-parity.integration.test.ts +0 -67
  180. package/tests/integration/meta-tools-round-trip.integration.test.ts +0 -506
  181. package/tests/integration/quest-round-trip.test.ts +0 -303
  182. package/tests/integration/registry-executor-flow.test.ts +0 -85
  183. package/tests/integration.test.ts +0 -177
  184. package/tests/loading-tier.test.ts +0 -126
  185. package/tests/mcp/client-reconnect.test.ts +0 -267
  186. package/tests/mcp/connection.test.ts +0 -846
  187. package/tests/mcp/injectable-logger.test.ts +0 -83
  188. package/tests/mcp/jsonrpc.test.ts +0 -109
  189. package/tests/mcp/lifecycle.test.ts +0 -879
  190. package/tests/network-runtime/address-types.contract.test.ts +0 -143
  191. package/tests/network-runtime/continuity-bind-schema.contract.test.ts +0 -203
  192. package/tests/network-runtime/local-control-contract.test.ts +0 -869
  193. package/tests/network-runtime/local-control-invite-token.contract.test.ts +0 -146
  194. package/tests/network-runtime/node-store-contract.test.ts +0 -11
  195. package/tests/network-runtime/pair-protocol-nodeid.contract.test.ts +0 -15
  196. package/tests/network-runtime/peer-state-machine.contract.test.ts +0 -148
  197. package/tests/network-runtime/protocol-schemas.contract.test.ts +0 -512
  198. package/tests/network-runtime/relay-pending-nodeid.contract.test.ts +0 -62
  199. package/tests/network-runtime/runtime-bootstrap-contract.test.ts +0 -227
  200. package/tests/network-runtime/runtime-socket-local-control-client.test.ts +0 -621
  201. package/tests/network-runtime/wait-for-message-script.test.ts +0 -288
  202. package/tests/parallel.test.ts +0 -71
  203. package/tests/policy.test.ts +0 -184
  204. package/tests/print-default-test-lane.ts +0 -14
  205. package/tests/print-test-lane-manifest.ts +0 -22
  206. package/tests/providers/brave.test.ts +0 -159
  207. package/tests/providers/duckduckgo.test.ts +0 -207
  208. package/tests/providers/exa.test.ts +0 -175
  209. package/tests/providers/firecrawl.test.ts +0 -168
  210. package/tests/providers/jina.test.ts +0 -144
  211. package/tests/providers/router.test.ts +0 -328
  212. package/tests/providers/tavily.test.ts +0 -165
  213. package/tests/registry/discovery.test.ts +0 -154
  214. package/tests/registry/injectable-logger.test.ts +0 -230
  215. package/tests/registry/input-validation.test.ts +0 -361
  216. package/tests/registry/interface-completeness.test.ts +0 -85
  217. package/tests/registry/mcp-integration.test.ts +0 -103
  218. package/tests/registry/mcp-read-only-hint.test.ts +0 -60
  219. package/tests/registry/memoria-discovery.test.ts +0 -390
  220. package/tests/registry/nested-validation.test.ts +0 -283
  221. package/tests/registry/pseudo-tool-filtering.test.ts +0 -258
  222. package/tests/registry/registration-lifecycle.test.ts +0 -133
  223. package/tests/registry-validation.test.ts +0 -424
  224. package/tests/registry.test.ts +0 -460
  225. package/tests/security/dns-pinning.test.ts +0 -162
  226. package/tests/security/external-content.test.ts +0 -144
  227. package/tests/security/ssrf.test.ts +0 -118
  228. package/tests/shell-safety-integration.test.ts +0 -32
  229. package/tests/shell-safety.test.ts +0 -365
  230. package/tests/slack/desktop-session.test.ts +0 -50
  231. package/tests/test-lane-manifest.ts +0 -440
  232. package/tests/test-utils.ts +0 -27
  233. package/tests/tool-factory.test.ts +0 -188
  234. package/tests/utils/retry.test.ts +0 -231
  235. package/tests/utils/url.test.ts +0 -63
  236. package/tsconfig.cjs.json +0 -24
  237. package/tsconfig.json +0 -12
  238. package/vitest.config.ts +0 -55
  239. package/vitest.e2e.config.ts +0 -24
  240. package/vitest.integration.config.ts +0 -24
  241. package/vitest.native.config.ts +0 -24
@@ -1,144 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
- import { JinaSearchProvider } from "../../src/providers/jina.js";
3
- import type { SearchResult } from "../../src/providers/search-provider.js";
4
-
5
- describe("JinaSearchProvider", () => {
6
- let provider: JinaSearchProvider;
7
-
8
- beforeEach(() => {
9
- provider = new JinaSearchProvider();
10
- });
11
-
12
- afterEach(() => {
13
- vi.restoreAllMocks();
14
- });
15
-
16
- it("has correct provider metadata", () => {
17
- expect(provider.name).toBe("jina");
18
- expect(provider.requiresApiKey).toBe(false);
19
- expect(provider.priority).toBe(5);
20
- });
21
-
22
- it("isAvailable returns true (no API key required)", () => {
23
- // Jina's free tier doesn't require an API key
24
- const available = provider.isAvailable();
25
- expect(available).toBe(true);
26
- });
27
-
28
- it("returns SearchResult[] on success", async () => {
29
- const mockResults: SearchResult[] = [
30
- {
31
- title: "TypeScript Handbook",
32
- url: "https://www.typescriptlang.org/docs/handbook",
33
- content: "The TypeScript Handbook is a comprehensive guide to the TypeScript language.",
34
- score: 0.95,
35
- },
36
- {
37
- title: "TypeScript GitHub",
38
- url: "https://github.com/microsoft/TypeScript",
39
- content: "TypeScript is a superset of JavaScript that compiles to clean JavaScript output.",
40
- score: 0.88,
41
- },
42
- ];
43
-
44
- // Mock global fetch to simulate Jina API response
45
- vi.stubGlobal(
46
- "fetch",
47
- vi.fn().mockResolvedValue({
48
- ok: true,
49
- status: 200,
50
- json: async () => ({
51
- data: mockResults.map((r) => ({
52
- title: r.title,
53
- url: r.url,
54
- content: r.content,
55
- score: r.score,
56
- })),
57
- }),
58
- }),
59
- );
60
-
61
- const results = await provider.search("TypeScript");
62
- expect(results).toBeInstanceOf(Array);
63
- expect(results.length).toBeGreaterThan(0);
64
- for (const result of results) {
65
- expect(result).toHaveProperty("title");
66
- expect(result).toHaveProperty("url");
67
- expect(result).toHaveProperty("content");
68
- expect(typeof result.title).toBe("string");
69
- expect(typeof result.url).toBe("string");
70
- expect(typeof result.content).toBe("string");
71
- }
72
- });
73
-
74
- it("respects limit option", async () => {
75
- vi.stubGlobal(
76
- "fetch",
77
- vi.fn().mockResolvedValue({
78
- ok: true,
79
- status: 200,
80
- json: async () => ({
81
- data: [{ title: "Result 1", url: "https://example.com/1", content: "Content 1" }],
82
- }),
83
- }),
84
- );
85
-
86
- const results = await provider.search("TypeScript", { limit: 1 });
87
- expect(results.length).toBeLessThanOrEqual(1);
88
- });
89
-
90
- it("handles API errors (4xx/5xx)", async () => {
91
- vi.stubGlobal(
92
- "fetch",
93
- vi.fn().mockResolvedValue({
94
- ok: false,
95
- status: 500,
96
- statusText: "Internal Server Error",
97
- }),
98
- );
99
-
100
- await expect(provider.search("test query")).rejects.toThrow();
101
- });
102
-
103
- it("handles 429 rate limit errors", async () => {
104
- vi.stubGlobal(
105
- "fetch",
106
- vi.fn().mockResolvedValue({
107
- ok: false,
108
- status: 429,
109
- statusText: "Too Many Requests",
110
- }),
111
- );
112
-
113
- await expect(provider.search("test query")).rejects.toThrow();
114
- });
115
-
116
- it("returns empty array for no results", async () => {
117
- vi.stubGlobal(
118
- "fetch",
119
- vi.fn().mockResolvedValue({
120
- ok: true,
121
- status: 200,
122
- json: async () => ({ data: [] }),
123
- }),
124
- );
125
-
126
- const results = await provider.search("xyzzy_nonexistent_query_12345");
127
- expect(results).toEqual([]);
128
- });
129
-
130
- it("handles network timeout", async () => {
131
- vi.stubGlobal(
132
- "fetch",
133
- vi.fn().mockRejectedValue(new DOMException("The operation was aborted", "AbortError")),
134
- );
135
-
136
- await expect(provider.search("test query")).rejects.toThrow();
137
- });
138
-
139
- it("handles fetch network failure", async () => {
140
- vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new TypeError("Failed to fetch")));
141
-
142
- await expect(provider.search("test query")).rejects.toThrow();
143
- });
144
- });
@@ -1,328 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
- import { SearchProviderRouter } from "../../src/providers/router.js";
3
- import { JinaSearchProvider } from "../../src/providers/jina.js";
4
- import { DuckDuckGoSearchProvider } from "../../src/providers/duckduckgo.js";
5
- import { TavilySearchProvider } from "../../src/providers/tavily.js";
6
- import { BraveSearchProvider } from "../../src/providers/brave.js";
7
- import { ExaSearchProvider } from "../../src/providers/exa.js";
8
- import { FirecrawlSearchProvider } from "../../src/providers/firecrawl.js";
9
- import type { SearchProvider, SearchResult } from "../../src/providers/search-provider.js";
10
-
11
- /**
12
- * Helper to create a mock provider with controllable availability and search behavior.
13
- */
14
- function createMockProvider(
15
- overrides: Partial<SearchProvider> & { name: string; priority: number },
16
- ): SearchProvider {
17
- return {
18
- requiresApiKey: false,
19
- isAvailable: () => true,
20
- search: vi.fn().mockResolvedValue([]),
21
- ...overrides,
22
- };
23
- }
24
-
25
- describe("SearchProviderRouter", () => {
26
- afterEach(() => {
27
- vi.restoreAllMocks();
28
- vi.unstubAllEnvs();
29
- });
30
-
31
- describe("resolve()", () => {
32
- it("selects highest-priority available provider", () => {
33
- // Lower priority number = higher priority
34
- const brave = createMockProvider({ name: "brave", priority: 1, isAvailable: () => true });
35
- const firecrawl = createMockProvider({
36
- name: "firecrawl",
37
- priority: 2,
38
- isAvailable: () => true,
39
- });
40
- const jina = createMockProvider({ name: "jina", priority: 5, isAvailable: () => true });
41
-
42
- const router = new SearchProviderRouter([jina, brave, firecrawl]);
43
- const selected = router.resolve();
44
-
45
- expect(selected.name).toBe("brave");
46
- });
47
-
48
- it("skips unavailable providers", () => {
49
- const brave = createMockProvider({ name: "brave", priority: 1, isAvailable: () => false });
50
- const firecrawl = createMockProvider({
51
- name: "firecrawl",
52
- priority: 2,
53
- isAvailable: () => true,
54
- });
55
- const jina = createMockProvider({ name: "jina", priority: 5, isAvailable: () => true });
56
-
57
- const router = new SearchProviderRouter([brave, firecrawl, jina]);
58
- const selected = router.resolve();
59
-
60
- expect(selected.name).toBe("firecrawl");
61
- });
62
-
63
- it("respects ARIA_SEARCH_PROVIDER override", () => {
64
- vi.stubEnv("ARIA_SEARCH_PROVIDER", "jina");
65
-
66
- const brave = createMockProvider({ name: "brave", priority: 1, isAvailable: () => true });
67
- const jina = createMockProvider({ name: "jina", priority: 5, isAvailable: () => true });
68
-
69
- const router = new SearchProviderRouter([brave, jina]);
70
- const selected = router.resolve();
71
-
72
- expect(selected.name).toBe("jina");
73
- });
74
-
75
- it("throws if ARIA_SEARCH_PROVIDER override names unavailable provider", () => {
76
- vi.stubEnv("ARIA_SEARCH_PROVIDER", "nonexistent");
77
-
78
- const jina = createMockProvider({ name: "jina", priority: 5, isAvailable: () => true });
79
- const router = new SearchProviderRouter([jina]);
80
-
81
- expect(() => router.resolve()).toThrow();
82
- });
83
-
84
- it("falls back to Jina when no API keys set", () => {
85
- // All API-key providers are unavailable; Jina (no key required) should be selected
86
- const brave = createMockProvider({
87
- name: "brave",
88
- priority: 1,
89
- requiresApiKey: true,
90
- isAvailable: () => false,
91
- });
92
- const tavily = createMockProvider({
93
- name: "tavily",
94
- priority: 4,
95
- requiresApiKey: true,
96
- isAvailable: () => false,
97
- });
98
- const jina = createMockProvider({
99
- name: "jina",
100
- priority: 5,
101
- requiresApiKey: false,
102
- isAvailable: () => true,
103
- });
104
- const duckduckgo = createMockProvider({
105
- name: "duckduckgo",
106
- priority: 6,
107
- requiresApiKey: false,
108
- isAvailable: () => true,
109
- });
110
-
111
- const router = new SearchProviderRouter([brave, tavily, jina, duckduckgo]);
112
- const selected = router.resolve();
113
-
114
- // Jina has higher priority (5) than DuckDuckGo (6), so it should be selected
115
- expect(selected.name).toBe("jina");
116
- });
117
-
118
- it("throws when no providers are available", () => {
119
- const unavailable = createMockProvider({
120
- name: "dead",
121
- priority: 1,
122
- isAvailable: () => false,
123
- });
124
-
125
- const router = new SearchProviderRouter([unavailable]);
126
-
127
- expect(() => router.resolve()).toThrow();
128
- });
129
- });
130
-
131
- describe("search()", () => {
132
- it("delegates search to resolved provider", async () => {
133
- const mockResults: SearchResult[] = [
134
- { title: "Test", url: "https://test.com", content: "Test content" },
135
- ];
136
- const provider = createMockProvider({
137
- name: "mock",
138
- priority: 1,
139
- search: vi.fn().mockResolvedValue(mockResults),
140
- });
141
-
142
- const router = new SearchProviderRouter([provider]);
143
- const results = await router.search("test query");
144
-
145
- expect(results).toEqual(mockResults);
146
- expect(provider.search).toHaveBeenCalledWith("test query", undefined);
147
- });
148
-
149
- it("passes options through to the provider", async () => {
150
- const searchFn = vi.fn().mockResolvedValue([]);
151
- const provider = createMockProvider({
152
- name: "mock",
153
- priority: 1,
154
- search: searchFn,
155
- });
156
-
157
- const router = new SearchProviderRouter([provider]);
158
- await router.search("test", { limit: 5, topic: "news" });
159
-
160
- expect(searchFn).toHaveBeenCalledWith("test", { limit: 5, topic: "news" });
161
- });
162
-
163
- it("passes abort signal through to providers", async () => {
164
- const searchFn = vi.fn().mockResolvedValue([]);
165
- const provider = createMockProvider({
166
- name: "mock",
167
- priority: 1,
168
- search: searchFn,
169
- });
170
- const signal = new AbortController().signal;
171
-
172
- const router = new SearchProviderRouter([provider]);
173
- await router.search("test", { limit: 5, signal });
174
-
175
- expect(searchFn).toHaveBeenCalledWith("test", { limit: 5, signal });
176
- });
177
-
178
- it("short-circuits when abort signal is already aborted", async () => {
179
- const searchFn = vi.fn().mockResolvedValue([]);
180
- const provider = createMockProvider({
181
- name: "mock",
182
- priority: 1,
183
- search: searchFn,
184
- });
185
- const controller = new AbortController();
186
- controller.abort();
187
-
188
- const router = new SearchProviderRouter([provider]);
189
- await expect(router.search("test", { signal: controller.signal })).rejects.toThrow(
190
- "Search aborted",
191
- );
192
- expect(searchFn).not.toHaveBeenCalled();
193
- });
194
-
195
- it("falls back to DuckDuckGo when Jina fails", async () => {
196
- const jinaSearch = vi.fn().mockRejectedValue(new Error("Jina API error"));
197
- const ddgResults: SearchResult[] = [
198
- { title: "DDG Result", url: "https://ddg.com", content: "Fallback content" },
199
- ];
200
- const ddgSearch = vi.fn().mockResolvedValue(ddgResults);
201
-
202
- const jina = createMockProvider({
203
- name: "jina",
204
- priority: 5,
205
- search: jinaSearch,
206
- });
207
- const ddg = createMockProvider({
208
- name: "duckduckgo",
209
- priority: 6,
210
- search: ddgSearch,
211
- });
212
-
213
- // Only these two free providers available
214
- const router = new SearchProviderRouter([jina, ddg]);
215
- const results = await router.search("test query");
216
-
217
- expect(results).toEqual(ddgResults);
218
- });
219
-
220
- it("circuit breaker: tries in priority order, skips failing providers", async () => {
221
- const braveSearch = vi.fn().mockRejectedValue(new Error("Brave down"));
222
- const firecrawlSearch = vi.fn().mockRejectedValue(new Error("Firecrawl down"));
223
- const exaResults: SearchResult[] = [
224
- { title: "Exa Result", url: "https://exa.ai/r", content: "Found via Exa" },
225
- ];
226
- const exaSearch = vi.fn().mockResolvedValue(exaResults);
227
-
228
- const brave = createMockProvider({ name: "brave", priority: 1, search: braveSearch });
229
- const firecrawl = createMockProvider({
230
- name: "firecrawl",
231
- priority: 2,
232
- search: firecrawlSearch,
233
- });
234
- const exa = createMockProvider({ name: "exa", priority: 3, search: exaSearch });
235
-
236
- const router = new SearchProviderRouter([brave, firecrawl, exa]);
237
- const results = await router.search("important query");
238
-
239
- // Should have tried brave first, then firecrawl, then exa
240
- expect(braveSearch).toHaveBeenCalledTimes(1);
241
- expect(firecrawlSearch).toHaveBeenCalledTimes(1);
242
- expect(exaSearch).toHaveBeenCalledTimes(1);
243
- expect(results).toEqual(exaResults);
244
- });
245
-
246
- it("all providers unavailable throws AggregateError", async () => {
247
- const provider1 = createMockProvider({
248
- name: "p1",
249
- priority: 1,
250
- search: vi.fn().mockRejectedValue(new Error("p1 failed")),
251
- });
252
- const provider2 = createMockProvider({
253
- name: "p2",
254
- priority: 2,
255
- search: vi.fn().mockRejectedValue(new Error("p2 failed")),
256
- });
257
-
258
- const router = new SearchProviderRouter([provider1, provider2]);
259
-
260
- try {
261
- await router.search("doomed query");
262
- expect.unreachable("Should have thrown");
263
- } catch (err) {
264
- // Should aggregate all provider errors
265
- expect(err).toBeInstanceOf(AggregateError);
266
- const aggErr = err as AggregateError;
267
- expect(aggErr.errors).toHaveLength(2);
268
- expect(aggErr.errors[0]).toBeInstanceOf(Error);
269
- expect(aggErr.errors[1]).toBeInstanceOf(Error);
270
- }
271
- });
272
-
273
- it("does not retry a provider that already failed in this search", async () => {
274
- const failingSearch = vi.fn().mockRejectedValue(new Error("always fails"));
275
- const successSearch = vi
276
- .fn()
277
- .mockResolvedValue([{ title: "OK", url: "https://ok.com", content: "Success" }]);
278
-
279
- const failing = createMockProvider({ name: "failing", priority: 1, search: failingSearch });
280
- const success = createMockProvider({ name: "success", priority: 2, search: successSearch });
281
-
282
- const router = new SearchProviderRouter([failing, success]);
283
- await router.search("test");
284
-
285
- // Failing provider should only be called once, not retried
286
- expect(failingSearch).toHaveBeenCalledTimes(1);
287
- expect(successSearch).toHaveBeenCalledTimes(1);
288
- });
289
- });
290
-
291
- describe("integration with real provider classes", () => {
292
- it("can instantiate router with all real provider classes", () => {
293
- const router = new SearchProviderRouter([
294
- new BraveSearchProvider(),
295
- new FirecrawlSearchProvider(),
296
- new ExaSearchProvider(),
297
- new TavilySearchProvider(),
298
- new JinaSearchProvider(),
299
- new DuckDuckGoSearchProvider(),
300
- ]);
301
-
302
- // Just verify construction doesn't throw
303
- expect(router).toBeDefined();
304
- });
305
-
306
- it("resolve() with real providers picks based on availability", () => {
307
- // Without any API keys set, only keyless providers are available
308
- vi.stubEnv("BRAVE_API_KEY", "");
309
- vi.stubEnv("FIRECRAWL_API_KEY", "");
310
- vi.stubEnv("EXA_API_KEY", "");
311
- vi.stubEnv("TAVILY_API_KEY", "");
312
-
313
- const router = new SearchProviderRouter([
314
- new BraveSearchProvider(),
315
- new FirecrawlSearchProvider(),
316
- new ExaSearchProvider(),
317
- new TavilySearchProvider(),
318
- new JinaSearchProvider(),
319
- new DuckDuckGoSearchProvider(),
320
- ]);
321
-
322
- const selected = router.resolve();
323
-
324
- // Should select Jina (priority 5) or DuckDuckGo (priority 6) — both keyless
325
- expect(["jina", "duckduckgo"]).toContain(selected.name);
326
- });
327
- });
328
- });
@@ -1,165 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
- import { TavilySearchProvider } from "../../src/providers/tavily.js";
3
- import type { SearchResult } from "../../src/providers/search-provider.js";
4
-
5
- describe("TavilySearchProvider", () => {
6
- let provider: TavilySearchProvider;
7
-
8
- beforeEach(() => {
9
- provider = new TavilySearchProvider();
10
- // Simulate TAVILY_API_KEY being set for tests that need it
11
- vi.stubEnv("TAVILY_API_KEY", "tvly-test-key-12345");
12
- });
13
-
14
- afterEach(() => {
15
- vi.restoreAllMocks();
16
- vi.unstubAllEnvs();
17
- });
18
-
19
- it("has correct provider metadata", () => {
20
- expect(provider.name).toBe("tavily");
21
- expect(provider.requiresApiKey).toBe(true);
22
- expect(provider.priority).toBe(4);
23
- });
24
-
25
- it("isAvailable returns true when TAVILY_API_KEY is set", () => {
26
- const available = provider.isAvailable();
27
- expect(available).toBe(true);
28
- });
29
-
30
- it("isAvailable returns false when TAVILY_API_KEY is missing", () => {
31
- vi.stubEnv("TAVILY_API_KEY", "");
32
- const freshProvider = new TavilySearchProvider();
33
- expect(freshProvider.isAvailable()).toBe(false);
34
- });
35
-
36
- it("returns SearchResult[] on success", async () => {
37
- const mockResults: SearchResult[] = [
38
- {
39
- title: "Tavily AI Search",
40
- url: "https://tavily.com",
41
- content: "Tavily is an AI-native search engine optimized for LLMs and AI agents.",
42
- score: 0.98,
43
- },
44
- {
45
- title: "Tavily API Documentation",
46
- url: "https://docs.tavily.com",
47
- content: "Complete API reference for Tavily search endpoints.",
48
- score: 0.91,
49
- },
50
- ];
51
-
52
- vi.stubGlobal(
53
- "fetch",
54
- vi.fn().mockResolvedValue({
55
- ok: true,
56
- status: 200,
57
- json: async () => ({
58
- results: mockResults.map((r) => ({
59
- title: r.title,
60
- url: r.url,
61
- content: r.content,
62
- score: r.score,
63
- })),
64
- }),
65
- }),
66
- );
67
-
68
- const results = await provider.search("AI search engine");
69
- expect(results).toBeInstanceOf(Array);
70
- expect(results.length).toBeGreaterThan(0);
71
- for (const result of results) {
72
- expect(result).toHaveProperty("title");
73
- expect(result).toHaveProperty("url");
74
- expect(result).toHaveProperty("content");
75
- expect(typeof result.title).toBe("string");
76
- expect(typeof result.url).toBe("string");
77
- expect(typeof result.content).toBe("string");
78
- }
79
- });
80
-
81
- it("includes score in results when available", async () => {
82
- vi.stubGlobal(
83
- "fetch",
84
- vi.fn().mockResolvedValue({
85
- ok: true,
86
- status: 200,
87
- json: async () => ({
88
- results: [
89
- { title: "Result", url: "https://example.com", content: "Content", score: 0.95 },
90
- ],
91
- }),
92
- }),
93
- );
94
-
95
- const results = await provider.search("test");
96
- expect(results[0].score).toBe(0.95);
97
- });
98
-
99
- it("passes topic option to API", async () => {
100
- const fetchMock = vi.fn().mockResolvedValue({
101
- ok: true,
102
- status: 200,
103
- json: async () => ({ results: [] }),
104
- });
105
- vi.stubGlobal("fetch", fetchMock);
106
-
107
- await provider.search("latest news", { topic: "news" });
108
-
109
- // Verify the fetch call included the topic parameter
110
- expect(fetchMock).toHaveBeenCalledTimes(1);
111
- const callArgs = fetchMock.mock.calls[0];
112
- const body = JSON.parse(callArgs[1]?.body as string);
113
- expect(body.topic).toBe("news");
114
- });
115
-
116
- it("handles API errors (4xx/5xx)", async () => {
117
- vi.stubGlobal(
118
- "fetch",
119
- vi.fn().mockResolvedValue({
120
- ok: false,
121
- status: 401,
122
- statusText: "Unauthorized",
123
- }),
124
- );
125
-
126
- await expect(provider.search("test query")).rejects.toThrow();
127
- });
128
-
129
- it("returns empty array for no results", async () => {
130
- vi.stubGlobal(
131
- "fetch",
132
- vi.fn().mockResolvedValue({
133
- ok: true,
134
- status: 200,
135
- json: async () => ({ results: [] }),
136
- }),
137
- );
138
-
139
- const results = await provider.search("xyzzy_nonexistent_query_12345");
140
- expect(results).toEqual([]);
141
- });
142
-
143
- it("handles network timeout", async () => {
144
- vi.stubGlobal(
145
- "fetch",
146
- vi.fn().mockRejectedValue(new DOMException("The operation was aborted", "AbortError")),
147
- );
148
-
149
- await expect(provider.search("test query")).rejects.toThrow();
150
- });
151
-
152
- it("handles 422 validation error from API", async () => {
153
- vi.stubGlobal(
154
- "fetch",
155
- vi.fn().mockResolvedValue({
156
- ok: false,
157
- status: 422,
158
- statusText: "Unprocessable Entity",
159
- json: async () => ({ detail: "Invalid query parameter" }),
160
- }),
161
- );
162
-
163
- await expect(provider.search("")).rejects.toThrow();
164
- });
165
- });