promptfoo 0.72.1 → 0.73.0

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 (470) hide show
  1. package/README.md +5 -5
  2. package/dist/package.json +14 -8
  3. package/dist/src/accounts.d.ts.map +1 -1
  4. package/dist/src/accounts.js +2 -1
  5. package/dist/src/accounts.js.map +1 -1
  6. package/dist/src/assertions/validateAssertions.d.ts +1 -1
  7. package/dist/src/assertions/validateAssertions.d.ts.map +1 -1
  8. package/dist/src/assertions/validateAssertions.js +7 -7
  9. package/dist/src/assertions/validateAssertions.js.map +1 -1
  10. package/dist/src/assertions.d.ts.map +1 -1
  11. package/dist/src/assertions.js +2 -1
  12. package/dist/src/assertions.js.map +1 -1
  13. package/dist/src/cache.js +2 -2
  14. package/dist/src/cache.js.map +1 -1
  15. package/dist/src/commands/eval.d.ts.map +1 -1
  16. package/dist/src/commands/eval.js +10 -0
  17. package/dist/src/commands/eval.js.map +1 -1
  18. package/dist/src/commands/export.d.ts.map +1 -1
  19. package/dist/src/commands/export.js +15 -14
  20. package/dist/src/commands/export.js.map +1 -1
  21. package/dist/src/commands/generate/redteam.d.ts +1 -46
  22. package/dist/src/commands/generate/redteam.d.ts.map +1 -1
  23. package/dist/src/commands/generate/redteam.js +70 -26
  24. package/dist/src/commands/generate/redteam.js.map +1 -1
  25. package/dist/src/commands/import.d.ts.map +1 -1
  26. package/dist/src/commands/import.js +2 -1
  27. package/dist/src/commands/import.js.map +1 -1
  28. package/dist/src/commands/init.d.ts.map +1 -1
  29. package/dist/src/commands/init.js +12 -0
  30. package/dist/src/commands/init.js.map +1 -1
  31. package/dist/src/commands/redteam.d.ts.map +1 -1
  32. package/dist/src/commands/redteam.js +72 -18
  33. package/dist/src/commands/redteam.js.map +1 -1
  34. package/dist/src/commands/view.d.ts.map +1 -1
  35. package/dist/src/commands/view.js +2 -1
  36. package/dist/src/commands/view.js.map +1 -1
  37. package/dist/src/config.d.ts.map +1 -1
  38. package/dist/src/config.js +2 -20
  39. package/dist/src/config.js.map +1 -1
  40. package/dist/src/configTypes.d.ts +7 -0
  41. package/dist/src/configTypes.d.ts.map +1 -0
  42. package/dist/src/configTypes.js +3 -0
  43. package/dist/src/configTypes.js.map +1 -0
  44. package/dist/src/database/index.d.ts +4 -0
  45. package/dist/src/database/index.d.ts.map +1 -0
  46. package/dist/src/database/index.js +50 -0
  47. package/dist/src/database/index.js.map +1 -0
  48. package/dist/src/{database.d.ts → database/operations.d.ts} +173 -115
  49. package/dist/src/{database.d.ts.map → database/operations.d.ts.map} +1 -1
  50. package/dist/src/{database.js → database/operations.js} +1 -25
  51. package/dist/src/database/operations.js.map +1 -0
  52. package/dist/src/evaluator.js +2 -2
  53. package/dist/src/evaluator.js.map +1 -1
  54. package/dist/src/globalConfig.d.ts +1 -7
  55. package/dist/src/globalConfig.d.ts.map +1 -1
  56. package/dist/src/globalConfig.js +3 -3
  57. package/dist/src/globalConfig.js.map +1 -1
  58. package/dist/src/matchers.d.ts.map +1 -1
  59. package/dist/src/matchers.js +6 -2
  60. package/dist/src/matchers.js.map +1 -1
  61. package/dist/src/prompts/grading.js +2 -2
  62. package/dist/src/prompts/processors/python.js +4 -4
  63. package/dist/src/prompts/processors/python.js.map +1 -1
  64. package/dist/src/providers/anthropic.d.ts +1 -1
  65. package/dist/src/providers/anthropic.d.ts.map +1 -1
  66. package/dist/src/providers/bam.d.ts +1 -1
  67. package/dist/src/providers/bam.d.ts.map +1 -1
  68. package/dist/src/providers/bedrock.d.ts +1 -1
  69. package/dist/src/providers/bedrock.d.ts.map +1 -1
  70. package/dist/src/providers/cohere.d.ts.map +1 -1
  71. package/dist/src/providers/cohere.js +4 -1
  72. package/dist/src/providers/cohere.js.map +1 -1
  73. package/dist/src/providers/http.d.ts +1 -1
  74. package/dist/src/providers/http.d.ts.map +1 -1
  75. package/dist/src/providers/http.js +3 -3
  76. package/dist/src/providers/http.js.map +1 -1
  77. package/dist/src/providers/llama.d.ts +1 -1
  78. package/dist/src/providers/llama.d.ts.map +1 -1
  79. package/dist/src/providers/localai.d.ts +1 -1
  80. package/dist/src/providers/localai.d.ts.map +1 -1
  81. package/dist/src/providers/ollama.d.ts +1 -1
  82. package/dist/src/providers/ollama.d.ts.map +1 -1
  83. package/dist/src/providers/openai.d.ts +1 -1
  84. package/dist/src/providers/openai.d.ts.map +1 -1
  85. package/dist/src/providers/openai.js +48 -50
  86. package/dist/src/providers/openai.js.map +1 -1
  87. package/dist/src/providers/palm.d.ts +1 -1
  88. package/dist/src/providers/palm.d.ts.map +1 -1
  89. package/dist/src/providers/pythonCompletion.d.ts.map +1 -1
  90. package/dist/src/providers/pythonCompletion.js +6 -5
  91. package/dist/src/providers/pythonCompletion.js.map +1 -1
  92. package/dist/src/providers/replicate.js +2 -2
  93. package/dist/src/providers/replicate.js.map +1 -1
  94. package/dist/src/providers/scriptCompletion.js +3 -3
  95. package/dist/src/providers/scriptCompletion.js.map +1 -1
  96. package/dist/src/providers/vertex.d.ts +1 -1
  97. package/dist/src/providers/vertex.d.ts.map +1 -1
  98. package/dist/src/providers/vertex.js +23 -10
  99. package/dist/src/providers/vertex.js.map +1 -1
  100. package/dist/src/providers/vertexUtil.d.ts +2 -1
  101. package/dist/src/providers/vertexUtil.d.ts.map +1 -1
  102. package/dist/src/providers/vertexUtil.js.map +1 -1
  103. package/dist/src/providers/webhook.d.ts +1 -1
  104. package/dist/src/providers/webhook.d.ts.map +1 -1
  105. package/dist/src/providers.d.ts.map +1 -1
  106. package/dist/src/providers.js +5 -2
  107. package/dist/src/providers.js.map +1 -1
  108. package/dist/src/python/pythonUtils.d.ts +4 -0
  109. package/dist/src/python/pythonUtils.d.ts.map +1 -0
  110. package/dist/src/python/pythonUtils.js +51 -0
  111. package/dist/src/python/pythonUtils.js.map +1 -0
  112. package/dist/src/python/wrapper.d.ts +0 -10
  113. package/dist/src/python/wrapper.d.ts.map +1 -1
  114. package/dist/src/python/wrapper.js +2 -49
  115. package/dist/src/python/wrapper.js.map +1 -1
  116. package/dist/src/redteam/constants.d.ts +60 -3
  117. package/dist/src/redteam/constants.d.ts.map +1 -1
  118. package/dist/src/redteam/constants.js +71 -10
  119. package/dist/src/redteam/constants.js.map +1 -1
  120. package/dist/src/redteam/index.d.ts +15 -4
  121. package/dist/src/redteam/index.d.ts.map +1 -1
  122. package/dist/src/redteam/index.js +110 -33
  123. package/dist/src/redteam/index.js.map +1 -1
  124. package/dist/src/redteam/plugins/base.d.ts +10 -13
  125. package/dist/src/redteam/plugins/base.d.ts.map +1 -1
  126. package/dist/src/redteam/plugins/base.js +36 -20
  127. package/dist/src/redteam/plugins/base.js.map +1 -1
  128. package/dist/src/redteam/plugins/debugInterface.d.ts +7 -0
  129. package/dist/src/redteam/plugins/debugInterface.d.ts.map +1 -0
  130. package/dist/src/redteam/plugins/debugInterface.js +49 -0
  131. package/dist/src/redteam/plugins/debugInterface.js.map +1 -0
  132. package/dist/src/redteam/plugins/harmful.d.ts +1 -54
  133. package/dist/src/redteam/plugins/harmful.d.ts.map +1 -1
  134. package/dist/src/redteam/plugins/harmful.js +8 -51
  135. package/dist/src/redteam/plugins/harmful.js.map +1 -1
  136. package/dist/src/redteam/plugins/pii.d.ts +9 -10
  137. package/dist/src/redteam/plugins/pii.d.ts.map +1 -1
  138. package/dist/src/redteam/plugins/pii.js +33 -53
  139. package/dist/src/redteam/plugins/pii.js.map +1 -1
  140. package/dist/src/redteam/plugins/rbac.d.ts +7 -0
  141. package/dist/src/redteam/plugins/rbac.d.ts.map +1 -0
  142. package/dist/src/redteam/plugins/rbac.js +49 -0
  143. package/dist/src/redteam/plugins/rbac.js.map +1 -0
  144. package/dist/src/redteam/plugins/shellInjection.d.ts +7 -0
  145. package/dist/src/redteam/plugins/shellInjection.d.ts.map +1 -0
  146. package/dist/src/redteam/plugins/shellInjection.js +54 -0
  147. package/dist/src/redteam/plugins/shellInjection.js.map +1 -0
  148. package/dist/src/redteam/plugins/sqlInjection.d.ts +7 -0
  149. package/dist/src/redteam/plugins/sqlInjection.d.ts.map +1 -0
  150. package/dist/src/redteam/plugins/sqlInjection.js +44 -0
  151. package/dist/src/redteam/plugins/sqlInjection.js.map +1 -0
  152. package/dist/src/redteam/providers/iterative.d.ts.map +1 -1
  153. package/dist/src/redteam/providers/iterative.js +2 -1
  154. package/dist/src/redteam/providers/iterative.js.map +1 -1
  155. package/dist/src/redteam/strategies/injections.d.ts.map +1 -0
  156. package/dist/src/redteam/{methods → strategies}/injections.js +0 -12
  157. package/dist/src/redteam/strategies/injections.js.map +1 -0
  158. package/dist/src/redteam/strategies/iterative.d.ts.map +1 -0
  159. package/dist/src/redteam/strategies/iterative.js.map +1 -0
  160. package/dist/src/redteam/types.d.ts +196 -0
  161. package/dist/src/redteam/types.d.ts.map +1 -0
  162. package/dist/src/redteam/types.js +124 -0
  163. package/dist/src/redteam/types.js.map +1 -0
  164. package/dist/src/redteam/util.d.ts +22 -0
  165. package/dist/src/redteam/util.d.ts.map +1 -0
  166. package/dist/src/redteam/util.js +56 -0
  167. package/dist/src/redteam/util.js.map +1 -0
  168. package/dist/src/testCases.d.ts +1 -2
  169. package/dist/src/testCases.d.ts.map +1 -1
  170. package/dist/src/testCases.js.map +1 -1
  171. package/dist/src/types/databaseTypes.d.ts +17 -0
  172. package/dist/src/types/databaseTypes.d.ts.map +1 -0
  173. package/dist/src/types/databaseTypes.js +3 -0
  174. package/dist/src/types/databaseTypes.js.map +1 -0
  175. package/dist/src/{types.d.ts → types/index.d.ts} +4296 -1425
  176. package/dist/src/{types.d.ts.map → types/index.d.ts.map} +1 -1
  177. package/dist/src/{types.js → types/index.js} +38 -9
  178. package/dist/src/types/index.js.map +1 -0
  179. package/dist/src/util/config.d.ts +3 -0
  180. package/dist/src/util/config.d.ts.map +1 -0
  181. package/dist/src/util/config.js +42 -0
  182. package/dist/src/util/config.js.map +1 -0
  183. package/dist/src/util/index.d.ts +41 -25
  184. package/dist/src/util/index.d.ts.map +1 -1
  185. package/dist/src/util/index.js +81 -119
  186. package/dist/src/util/index.js.map +1 -1
  187. package/dist/src/util/json.d.ts +3 -0
  188. package/dist/src/util/json.d.ts.map +1 -0
  189. package/dist/src/util/json.js +27 -0
  190. package/dist/src/util/json.js.map +1 -0
  191. package/dist/src/web/nextui/404/index.html +1 -1
  192. package/dist/src/web/nextui/404.html +1 -1
  193. package/dist/src/web/nextui/_next/static/chunks/155-4e319e68476266ee.js +1 -0
  194. package/dist/src/web/nextui/_next/static/chunks/163-93bab94bc04ae71b.js +6 -0
  195. package/dist/src/web/nextui/_next/static/chunks/{258-4acb452fe85cff6f.js → 258-b6257e5de9d0e2c7.js} +1 -1
  196. package/dist/src/web/nextui/_next/static/chunks/281-64d9f1415a301ee5.js +1 -0
  197. package/dist/src/web/nextui/_next/static/chunks/304-cf667fe8f06238b4.js +1 -0
  198. package/dist/src/web/nextui/_next/static/chunks/322-b47b6cc3f5b5fdb8.js +1 -0
  199. package/dist/src/web/nextui/_next/static/chunks/325-0d36870ade5e5263.js +1 -0
  200. package/dist/src/web/nextui/_next/static/chunks/339-79124d204fa988a3.js +1 -0
  201. package/dist/src/web/nextui/_next/static/chunks/378-c135e497df1864cb.js +1 -0
  202. package/dist/src/web/nextui/_next/static/chunks/476-0afb5eb266c57b7f.js +17 -0
  203. package/dist/src/web/nextui/_next/static/chunks/493-ebd12f00541c4969.js +2 -0
  204. package/dist/src/web/nextui/_next/static/chunks/497-e280a5610a3d7d42.js +32 -0
  205. package/dist/src/web/nextui/_next/static/chunks/515-e06d044f12d8a1bd.js +1 -0
  206. package/dist/src/web/nextui/_next/static/chunks/69-5e4d5e60859a86d2.js +1 -0
  207. package/dist/src/web/nextui/_next/static/chunks/737-32d5472455807d7a.js +1 -0
  208. package/dist/src/web/nextui/_next/static/chunks/903-7cc440d9f9e9f95d.js +97 -0
  209. package/dist/src/web/nextui/_next/static/chunks/905-78cd666f27891ee6.js +28 -0
  210. package/dist/src/web/nextui/_next/static/chunks/916-b92fea2ab6136411.js +1 -0
  211. package/dist/src/web/nextui/_next/static/chunks/969-6ab6c8f4158da970.js +1 -0
  212. package/dist/src/web/nextui/_next/static/chunks/app/auth/login/page-7247b17e8f179a46.js +1 -0
  213. package/dist/src/web/nextui/_next/static/chunks/app/auth/signup/page-8560afaf494f9882.js +1 -0
  214. package/dist/src/web/nextui/_next/static/chunks/app/datasets/page-6e6ec3c778ccd110.js +1 -0
  215. package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/not-found-fe10d5df88bc44ef.js +1 -0
  216. package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/{page-0a39d3450aa09dda.js → page-057e5eb83e0f614b.js} +1 -1
  217. package/dist/src/web/nextui/_next/static/chunks/app/eval/page-88fa70fc5bf755bc.js +1 -0
  218. package/dist/src/web/nextui/_next/static/chunks/app/layout-15abf0d1049cb47c.js +1 -0
  219. package/dist/src/web/nextui/_next/static/chunks/app/{page-5650318e57510b6c.js → page-122e9cfa52eb218a.js} +1 -1
  220. package/dist/src/web/nextui/_next/static/chunks/app/progress/page-a62ca531a4bb4149.js +1 -0
  221. package/dist/src/web/nextui/_next/static/chunks/app/prompts/page-10bb2e571670139c.js +1 -0
  222. package/dist/src/web/nextui/_next/static/chunks/app/report/page-a8b83960f08e2bb2.js +1 -0
  223. package/dist/src/web/nextui/_next/static/chunks/app/setup/page-6ea3e180c3116fb2.js +1 -0
  224. package/dist/src/web/nextui/_next/static/chunks/{main-app-929a26b3c8cd3f7a.js → main-app-7a1376166cb8b72e.js} +1 -1
  225. package/dist/src/web/nextui/_next/static/chunks/{webpack-c9f728822666f852.js → webpack-ee33d95b3e219985.js} +1 -1
  226. package/dist/src/web/nextui/_next/static/css/13f881e4290b6d59.css +1 -0
  227. package/dist/src/web/nextui/_next/static/css/87b5e6e04efd27e5.css +1 -0
  228. package/dist/src/web/nextui/_next/static/css/e17fdafd8599f69b.css +1 -0
  229. package/dist/src/web/nextui/_next/static/css/eb523daddb89dfc1.css +1 -0
  230. package/dist/src/web/nextui/auth/login/index.html +1 -1
  231. package/dist/src/web/nextui/auth/login/index.txt +6 -6
  232. package/dist/src/web/nextui/auth/signup/index.html +1 -1
  233. package/dist/src/web/nextui/auth/signup/index.txt +6 -6
  234. package/dist/src/web/nextui/datasets/index.html +1 -1
  235. package/dist/src/web/nextui/datasets/index.txt +6 -6
  236. package/dist/src/web/nextui/eval/index.html +1 -1
  237. package/dist/src/web/nextui/eval/index.txt +8 -8
  238. package/dist/src/web/nextui/index.html +1 -1
  239. package/dist/src/web/nextui/index.txt +5 -5
  240. package/dist/src/web/nextui/logo-panda.svg +91 -0
  241. package/dist/src/web/nextui/progress/index.html +1 -1
  242. package/dist/src/web/nextui/progress/index.txt +6 -6
  243. package/dist/src/web/nextui/prompts/index.html +1 -1
  244. package/dist/src/web/nextui/prompts/index.txt +6 -6
  245. package/dist/src/web/nextui/report/index.html +1 -1
  246. package/dist/src/web/nextui/report/index.txt +8 -8
  247. package/dist/src/web/nextui/setup/index.html +1 -1
  248. package/dist/src/web/nextui/setup/index.txt +7 -7
  249. package/dist/test/__mocks__/tempCustomModule.d.ts +13 -0
  250. package/dist/test/__mocks__/tempCustomModule.d.ts.map +1 -0
  251. package/dist/test/__mocks__/tempCustomModule.js +15 -0
  252. package/dist/test/__mocks__/tempCustomModule.js.map +1 -0
  253. package/dist/test/account.test.d.ts +2 -0
  254. package/dist/test/account.test.d.ts.map +1 -0
  255. package/dist/test/account.test.js +46 -0
  256. package/dist/test/account.test.js.map +1 -0
  257. package/dist/test/assertions/AssertionResult.test.d.ts +2 -0
  258. package/dist/test/assertions/AssertionResult.test.d.ts.map +1 -0
  259. package/dist/test/assertions/AssertionResult.test.js +184 -0
  260. package/dist/test/assertions/AssertionResult.test.js.map +1 -0
  261. package/dist/test/assertions/validateAssertions.test.d.ts +2 -0
  262. package/dist/test/assertions/validateAssertions.test.d.ts.map +1 -0
  263. package/dist/test/assertions/validateAssertions.test.js +40 -0
  264. package/dist/test/assertions/validateAssertions.test.js.map +1 -0
  265. package/dist/test/assertions.test.d.ts +2 -0
  266. package/dist/test/assertions.test.d.ts.map +1 -0
  267. package/dist/test/assertions.test.js +3162 -0
  268. package/dist/test/assertions.test.js.map +1 -0
  269. package/dist/test/cache.test.d.ts +2 -0
  270. package/dist/test/cache.test.d.ts.map +1 -0
  271. package/dist/test/cache.test.js +90 -0
  272. package/dist/test/cache.test.js.map +1 -0
  273. package/dist/test/checkNodeVersion.test.d.ts +2 -0
  274. package/dist/test/checkNodeVersion.test.d.ts.map +1 -0
  275. package/dist/test/checkNodeVersion.test.js +85 -0
  276. package/dist/test/checkNodeVersion.test.js.map +1 -0
  277. package/dist/test/commands/eval/filterFailingTests.test.d.ts +2 -0
  278. package/dist/test/commands/eval/filterFailingTests.test.d.ts.map +1 -0
  279. package/dist/test/commands/eval/filterFailingTests.test.js +84 -0
  280. package/dist/test/commands/eval/filterFailingTests.test.js.map +1 -0
  281. package/dist/test/commands/eval/filterProviders.test.d.ts +2 -0
  282. package/dist/test/commands/eval/filterProviders.test.d.ts.map +1 -0
  283. package/dist/test/commands/eval/filterProviders.test.js +50 -0
  284. package/dist/test/commands/eval/filterProviders.test.js.map +1 -0
  285. package/dist/test/commands/eval/filterTests.test.d.ts +2 -0
  286. package/dist/test/commands/eval/filterTests.test.d.ts.map +1 -0
  287. package/dist/test/commands/eval/filterTests.test.js +51 -0
  288. package/dist/test/commands/eval/filterTests.test.js.map +1 -0
  289. package/dist/test/config.test.d.ts +2 -0
  290. package/dist/test/config.test.d.ts.map +1 -0
  291. package/dist/test/config.test.js +404 -0
  292. package/dist/test/config.test.js.map +1 -0
  293. package/dist/test/csv.test.d.ts +2 -0
  294. package/dist/test/csv.test.d.ts.map +1 -0
  295. package/dist/test/csv.test.js +239 -0
  296. package/dist/test/csv.test.js.map +1 -0
  297. package/dist/test/evaluator.test.d.ts +2 -0
  298. package/dist/test/evaluator.test.d.ts.map +1 -0
  299. package/dist/test/evaluator.test.js +922 -0
  300. package/dist/test/evaluator.test.js.map +1 -0
  301. package/dist/test/globalConfig.test.d.ts +2 -0
  302. package/dist/test/globalConfig.test.d.ts.map +1 -0
  303. package/dist/test/globalConfig.test.js +91 -0
  304. package/dist/test/globalConfig.test.js.map +1 -0
  305. package/dist/test/is-sql-tests/node-sql-parser.test.d.ts +2 -0
  306. package/dist/test/is-sql-tests/node-sql-parser.test.d.ts.map +1 -0
  307. package/dist/test/is-sql-tests/node-sql-parser.test.js +179 -0
  308. package/dist/test/is-sql-tests/node-sql-parser.test.js.map +1 -0
  309. package/dist/test/matchers.test.d.ts +2 -0
  310. package/dist/test/matchers.test.d.ts.map +1 -0
  311. package/dist/test/matchers.test.js +807 -0
  312. package/dist/test/matchers.test.js.map +1 -0
  313. package/dist/test/prompts.processors.javascript.test.d.ts +2 -0
  314. package/dist/test/prompts.processors.javascript.test.d.ts.map +1 -0
  315. package/dist/test/prompts.processors.javascript.test.js +93 -0
  316. package/dist/test/prompts.processors.javascript.test.js.map +1 -0
  317. package/dist/test/prompts.processors.json.test.d.ts +2 -0
  318. package/dist/test/prompts.processors.json.test.d.ts.map +1 -0
  319. package/dist/test/prompts.processors.json.test.js +67 -0
  320. package/dist/test/prompts.processors.json.test.js.map +1 -0
  321. package/dist/test/prompts.processors.jsonl.test.d.ts +2 -0
  322. package/dist/test/prompts.processors.jsonl.test.d.ts.map +1 -0
  323. package/dist/test/prompts.processors.jsonl.test.js +99 -0
  324. package/dist/test/prompts.processors.jsonl.test.js.map +1 -0
  325. package/dist/test/prompts.processors.python.test.d.ts +2 -0
  326. package/dist/test/prompts.processors.python.test.d.ts.map +1 -0
  327. package/dist/test/prompts.processors.python.test.js +100 -0
  328. package/dist/test/prompts.processors.python.test.js.map +1 -0
  329. package/dist/test/prompts.processors.python.utils.test.d.ts +2 -0
  330. package/dist/test/prompts.processors.python.utils.test.d.ts.map +1 -0
  331. package/dist/test/prompts.processors.python.utils.test.js +68 -0
  332. package/dist/test/prompts.processors.python.utils.test.js.map +1 -0
  333. package/dist/test/prompts.processors.string.test.d.ts +2 -0
  334. package/dist/test/prompts.processors.string.test.d.ts.map +1 -0
  335. package/dist/test/prompts.processors.string.test.js +24 -0
  336. package/dist/test/prompts.processors.string.test.js.map +1 -0
  337. package/dist/test/prompts.processors.text.test.d.ts +2 -0
  338. package/dist/test/prompts.processors.text.test.d.ts.map +1 -0
  339. package/dist/test/prompts.processors.text.test.js +109 -0
  340. package/dist/test/prompts.processors.text.test.js.map +1 -0
  341. package/dist/test/prompts.processors.yaml.test.d.ts +2 -0
  342. package/dist/test/prompts.processors.yaml.test.d.ts.map +1 -0
  343. package/dist/test/prompts.processors.yaml.test.js +76 -0
  344. package/dist/test/prompts.processors.yaml.test.js.map +1 -0
  345. package/dist/test/prompts.test.d.ts +2 -0
  346. package/dist/test/prompts.test.d.ts.map +1 -0
  347. package/dist/test/prompts.test.js +562 -0
  348. package/dist/test/prompts.test.js.map +1 -0
  349. package/dist/test/prompts.utils.test.d.ts +2 -0
  350. package/dist/test/prompts.utils.test.d.ts.map +1 -0
  351. package/dist/test/prompts.utils.test.js +123 -0
  352. package/dist/test/prompts.utils.test.js.map +1 -0
  353. package/dist/test/providers.anthropic.test.d.ts +2 -0
  354. package/dist/test/providers.anthropic.test.d.ts.map +1 -0
  355. package/dist/test/providers.anthropic.test.js +520 -0
  356. package/dist/test/providers.anthropic.test.js.map +1 -0
  357. package/dist/test/providers.azure.test.d.ts +2 -0
  358. package/dist/test/providers.azure.test.d.ts.map +1 -0
  359. package/dist/test/providers.azure.test.js +96 -0
  360. package/dist/test/providers.azure.test.js.map +1 -0
  361. package/dist/test/providers.bedrock.test.d.ts +2 -0
  362. package/dist/test/providers.bedrock.test.d.ts.map +1 -0
  363. package/dist/test/providers.bedrock.test.js +349 -0
  364. package/dist/test/providers.bedrock.test.js.map +1 -0
  365. package/dist/test/providers.http.test.d.ts +2 -0
  366. package/dist/test/providers.http.test.d.ts.map +1 -0
  367. package/dist/test/providers.http.test.js +130 -0
  368. package/dist/test/providers.http.test.js.map +1 -0
  369. package/dist/test/providers.llama.test.d.ts +2 -0
  370. package/dist/test/providers.llama.test.d.ts.map +1 -0
  371. package/dist/test/providers.llama.test.js +101 -0
  372. package/dist/test/providers.llama.test.js.map +1 -0
  373. package/dist/test/providers.pythonCompletion.test.d.ts +2 -0
  374. package/dist/test/providers.pythonCompletion.test.d.ts.map +1 -0
  375. package/dist/test/providers.pythonCompletion.test.js +149 -0
  376. package/dist/test/providers.pythonCompletion.test.js.map +1 -0
  377. package/dist/test/providers.test.d.ts +2 -0
  378. package/dist/test/providers.test.d.ts.map +1 -0
  379. package/dist/test/providers.test.js +883 -0
  380. package/dist/test/providers.test.js.map +1 -0
  381. package/dist/test/providers.vertex.test.d.ts +2 -0
  382. package/dist/test/providers.vertex.test.d.ts.map +1 -0
  383. package/dist/test/providers.vertex.test.js +153 -0
  384. package/dist/test/providers.vertex.test.js.map +1 -0
  385. package/dist/test/pythonWrapper.test.d.ts +2 -0
  386. package/dist/test/pythonWrapper.test.d.ts.map +1 -0
  387. package/dist/test/pythonWrapper.test.js +65 -0
  388. package/dist/test/pythonWrapper.test.js.map +1 -0
  389. package/dist/test/redteam/plugins/base.test.d.ts +2 -0
  390. package/dist/test/redteam/plugins/base.test.d.ts.map +1 -0
  391. package/dist/test/redteam/plugins/base.test.js +149 -0
  392. package/dist/test/redteam/plugins/base.test.js.map +1 -0
  393. package/dist/test/redteam/purpose.test.d.ts +2 -0
  394. package/dist/test/redteam/purpose.test.d.ts.map +1 -0
  395. package/dist/test/redteam/purpose.test.js +37 -0
  396. package/dist/test/redteam/purpose.test.js.map +1 -0
  397. package/dist/test/redteam/types.test.d.ts +2 -0
  398. package/dist/test/redteam/types.test.d.ts.map +1 -0
  399. package/dist/test/redteam/types.test.js +325 -0
  400. package/dist/test/redteam/types.test.js.map +1 -0
  401. package/dist/test/redteam/util.test.d.ts +2 -0
  402. package/dist/test/redteam/util.test.d.ts.map +1 -0
  403. package/dist/test/redteam/util.test.js +99 -0
  404. package/dist/test/redteam/util.test.js.map +1 -0
  405. package/dist/test/telemetry.test.d.ts +2 -0
  406. package/dist/test/telemetry.test.d.ts.map +1 -0
  407. package/dist/test/telemetry.test.js +68 -0
  408. package/dist/test/telemetry.test.js.map +1 -0
  409. package/dist/test/testCases.test.d.ts +2 -0
  410. package/dist/test/testCases.test.d.ts.map +1 -0
  411. package/dist/test/testCases.test.js +362 -0
  412. package/dist/test/testCases.test.js.map +1 -0
  413. package/dist/test/updates.test.d.ts +2 -0
  414. package/dist/test/updates.test.d.ts.map +1 -0
  415. package/dist/test/updates.test.js +63 -0
  416. package/dist/test/updates.test.js.map +1 -0
  417. package/dist/test/util.templates.test.d.ts +2 -0
  418. package/dist/test/util.templates.test.d.ts.map +1 -0
  419. package/dist/test/util.templates.test.js +75 -0
  420. package/dist/test/util.templates.test.js.map +1 -0
  421. package/dist/test/util.test.d.ts +2 -0
  422. package/dist/test/util.test.d.ts.map +1 -0
  423. package/dist/test/util.test.js +661 -0
  424. package/dist/test/util.test.js.map +1 -0
  425. package/dist/test/utils.d.ts +6 -0
  426. package/dist/test/utils.d.ts.map +1 -0
  427. package/dist/test/utils.js +16 -0
  428. package/dist/test/utils.js.map +1 -0
  429. package/package.json +14 -8
  430. package/dist/src/database.js.map +0 -1
  431. package/dist/src/redteam/methods/injections.d.ts.map +0 -1
  432. package/dist/src/redteam/methods/injections.js.map +0 -1
  433. package/dist/src/redteam/methods/iterative.d.ts.map +0 -1
  434. package/dist/src/redteam/methods/iterative.js.map +0 -1
  435. package/dist/src/types.js.map +0 -1
  436. package/dist/src/web/nextui/_next/static/chunks/163-e65e0f7f442a0c72.js +0 -6
  437. package/dist/src/web/nextui/_next/static/chunks/180-46db19289d856800.js +0 -1
  438. package/dist/src/web/nextui/_next/static/chunks/304-9d57a2251034b801.js +0 -1
  439. package/dist/src/web/nextui/_next/static/chunks/322-4a0fc9b0508f47e8.js +0 -1
  440. package/dist/src/web/nextui/_next/static/chunks/339-db5bd05e24dde905.js +0 -1
  441. package/dist/src/web/nextui/_next/static/chunks/374-d40afe599198abd3.js +0 -1
  442. package/dist/src/web/nextui/_next/static/chunks/378-e22c8aeb8e031fad.js +0 -1
  443. package/dist/src/web/nextui/_next/static/chunks/448-4da3bf74eae4996a.js +0 -97
  444. package/dist/src/web/nextui/_next/static/chunks/53-fae6e50ace6c83a1.js +0 -1
  445. package/dist/src/web/nextui/_next/static/chunks/578-8efe57f906f7573c.js +0 -44
  446. package/dist/src/web/nextui/_next/static/chunks/620-7a5a7bf6e1fe49e5.js +0 -1
  447. package/dist/src/web/nextui/_next/static/chunks/737-538f50dc31cc8c49.js +0 -1
  448. package/dist/src/web/nextui/_next/static/chunks/905-0da344cee75690e7.js +0 -32
  449. package/dist/src/web/nextui/_next/static/chunks/932-75585b3be8ce494d.js +0 -1
  450. package/dist/src/web/nextui/_next/static/chunks/973-ffe3726c956d08ef.js +0 -2
  451. package/dist/src/web/nextui/_next/static/chunks/995-803c74b81e7bf6cd.js +0 -1
  452. package/dist/src/web/nextui/_next/static/chunks/app/auth/login/page-2e2c0c725127ea2d.js +0 -1
  453. package/dist/src/web/nextui/_next/static/chunks/app/auth/signup/page-ccdb1f6890601666.js +0 -1
  454. package/dist/src/web/nextui/_next/static/chunks/app/datasets/page-642db4f4a8e8ba40.js +0 -1
  455. package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/not-found-ce320e6d1e6d1d23.js +0 -1
  456. package/dist/src/web/nextui/_next/static/chunks/app/eval/page-32eaa14d2384c5b0.js +0 -1
  457. package/dist/src/web/nextui/_next/static/chunks/app/layout-4282b1d33566e258.js +0 -1
  458. package/dist/src/web/nextui/_next/static/chunks/app/progress/page-462526776efd6fd6.js +0 -1
  459. package/dist/src/web/nextui/_next/static/chunks/app/prompts/page-0ae78bc0bf7c56bc.js +0 -1
  460. package/dist/src/web/nextui/_next/static/chunks/app/report/page-e4f7851d41eb0f92.js +0 -1
  461. package/dist/src/web/nextui/_next/static/chunks/app/setup/page-6cde750ec428cd75.js +0 -1
  462. package/dist/src/web/nextui/_next/static/css/35ab7ce8025438b0.css +0 -1
  463. package/dist/src/web/nextui/_next/static/css/5bd2f45de1f3ba83.css +0 -1
  464. package/dist/src/web/nextui/_next/static/css/94b771e23fc5d5f5.css +0 -1
  465. package/dist/src/web/nextui/_next/static/css/dab5d695b3657d59.css +0 -1
  466. /package/dist/src/redteam/{methods → strategies}/injections.d.ts +0 -0
  467. /package/dist/src/redteam/{methods → strategies}/iterative.d.ts +0 -0
  468. /package/dist/src/redteam/{methods → strategies}/iterative.js +0 -0
  469. /package/dist/src/web/nextui/_next/static/{8E4q0Tmu22G1wENZyXEq0 → L-tpppAe26U-euPv62afH}/_buildManifest.js +0 -0
  470. /package/dist/src/web/nextui/_next/static/{8E4q0Tmu22G1wENZyXEq0 → L-tpppAe26U-euPv62afH}/_ssgManifest.js +0 -0
@@ -0,0 +1,661 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const fs = __importStar(require("fs"));
27
+ const glob_1 = require("glob");
28
+ const path = __importStar(require("path"));
29
+ const util_1 = require("../src/util");
30
+ jest.mock('proxy-agent', () => ({
31
+ ProxyAgent: jest.fn().mockImplementation(() => ({})),
32
+ }));
33
+ jest.mock('glob', () => ({
34
+ globSync: jest.fn(),
35
+ }));
36
+ jest.mock('fs', () => ({
37
+ readFileSync: jest.fn(),
38
+ writeFileSync: jest.fn(),
39
+ statSync: jest.fn(),
40
+ readdirSync: jest.fn(),
41
+ existsSync: jest.fn(),
42
+ mkdirSync: jest.fn(),
43
+ }));
44
+ jest.mock('../src/esm');
45
+ jest.mock('../src/database', () => ({
46
+ getDb: jest.fn(),
47
+ }));
48
+ describe('util', () => {
49
+ beforeEach(() => {
50
+ jest.clearAllMocks();
51
+ });
52
+ describe('writeOutput', () => {
53
+ it('writeOutput with CSV output', () => {
54
+ const outputPath = 'output.csv';
55
+ const results = [
56
+ {
57
+ success: true,
58
+ score: 1.0,
59
+ namedScores: {},
60
+ latencyMs: 1000,
61
+ provider: {
62
+ id: 'foo',
63
+ },
64
+ prompt: {
65
+ raw: 'Test prompt',
66
+ label: '[display] Test prompt',
67
+ },
68
+ response: {
69
+ output: 'Test output',
70
+ },
71
+ vars: {
72
+ var1: 'value1',
73
+ var2: 'value2',
74
+ },
75
+ },
76
+ ];
77
+ const table = {
78
+ head: {
79
+ prompts: [{ raw: 'Test prompt', label: '[display] Test prompt', provider: 'foo' }],
80
+ vars: ['var1', 'var2'],
81
+ },
82
+ body: [
83
+ {
84
+ outputs: [
85
+ {
86
+ pass: true,
87
+ score: 1.0,
88
+ namedScores: {},
89
+ text: 'Test output',
90
+ prompt: 'Test prompt',
91
+ latencyMs: 1000,
92
+ cost: 0,
93
+ },
94
+ ],
95
+ vars: ['value1', 'value2'],
96
+ test: {},
97
+ },
98
+ ],
99
+ };
100
+ const summary = {
101
+ version: 2,
102
+ timestamp: '2024-01-01T00:00:00.000Z',
103
+ stats: {
104
+ successes: 1,
105
+ failures: 1,
106
+ tokenUsage: {
107
+ total: 10,
108
+ prompt: 5,
109
+ completion: 5,
110
+ cached: 0,
111
+ },
112
+ },
113
+ results,
114
+ table,
115
+ };
116
+ const config = {
117
+ description: 'test',
118
+ };
119
+ const shareableUrl = null;
120
+ (0, util_1.writeOutput)(outputPath, null, summary, config, shareableUrl);
121
+ expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
122
+ });
123
+ it('writeOutput with JSON output', () => {
124
+ const outputPath = 'output.json';
125
+ const results = [
126
+ {
127
+ success: true,
128
+ score: 1.0,
129
+ namedScores: {},
130
+ latencyMs: 1000,
131
+ provider: {
132
+ id: 'foo',
133
+ },
134
+ prompt: {
135
+ raw: 'Test prompt',
136
+ label: '[display] Test prompt',
137
+ },
138
+ response: {
139
+ output: 'Test output',
140
+ },
141
+ vars: {
142
+ var1: 'value1',
143
+ var2: 'value2',
144
+ },
145
+ },
146
+ ];
147
+ const table = {
148
+ head: {
149
+ prompts: [{ raw: 'Test prompt', label: '[display] Test prompt', provider: 'foo' }],
150
+ vars: ['var1', 'var2'],
151
+ },
152
+ body: [
153
+ {
154
+ outputs: [
155
+ {
156
+ pass: true,
157
+ score: 1.0,
158
+ namedScores: {},
159
+ text: 'Test output',
160
+ prompt: 'Test prompt',
161
+ latencyMs: 1000,
162
+ cost: 0,
163
+ },
164
+ ],
165
+ vars: ['value1', 'value2'],
166
+ test: {},
167
+ },
168
+ ],
169
+ };
170
+ const summary = {
171
+ version: 2,
172
+ timestamp: '2024-01-01T00:00:00.000Z',
173
+ stats: {
174
+ successes: 1,
175
+ failures: 1,
176
+ tokenUsage: {
177
+ total: 10,
178
+ prompt: 5,
179
+ completion: 5,
180
+ cached: 0,
181
+ },
182
+ },
183
+ results,
184
+ table,
185
+ };
186
+ const config = {
187
+ description: 'test',
188
+ };
189
+ const shareableUrl = null;
190
+ (0, util_1.writeOutput)(outputPath, null, summary, config, shareableUrl);
191
+ expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
192
+ });
193
+ it('writeOutput with YAML output', () => {
194
+ const outputPath = 'output.yaml';
195
+ const results = [
196
+ {
197
+ success: true,
198
+ score: 1.0,
199
+ namedScores: {},
200
+ latencyMs: 1000,
201
+ provider: {
202
+ id: 'foo',
203
+ },
204
+ prompt: {
205
+ raw: 'Test prompt',
206
+ label: '[display] Test prompt',
207
+ },
208
+ response: {
209
+ output: 'Test output',
210
+ },
211
+ vars: {
212
+ var1: 'value1',
213
+ var2: 'value2',
214
+ },
215
+ },
216
+ ];
217
+ const table = {
218
+ head: {
219
+ prompts: [{ raw: 'Test prompt', label: '[display] Test prompt', provider: 'foo' }],
220
+ vars: ['var1', 'var2'],
221
+ },
222
+ body: [
223
+ {
224
+ outputs: [
225
+ {
226
+ pass: true,
227
+ score: 1.0,
228
+ namedScores: {},
229
+ text: 'Test output',
230
+ prompt: 'Test prompt',
231
+ latencyMs: 1000,
232
+ cost: 0,
233
+ },
234
+ ],
235
+ vars: ['value1', 'value2'],
236
+ test: {},
237
+ },
238
+ ],
239
+ };
240
+ const summary = {
241
+ version: 2,
242
+ timestamp: '2024-01-01T00:00:00.000Z',
243
+ stats: {
244
+ successes: 1,
245
+ failures: 1,
246
+ tokenUsage: {
247
+ total: 10,
248
+ prompt: 5,
249
+ completion: 5,
250
+ cached: 0,
251
+ },
252
+ },
253
+ results,
254
+ table,
255
+ };
256
+ const config = {
257
+ description: 'test',
258
+ };
259
+ const shareableUrl = null;
260
+ (0, util_1.writeOutput)(outputPath, null, summary, config, shareableUrl);
261
+ expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
262
+ });
263
+ it('writeOutput with json and txt output', () => {
264
+ const outputPath = ['output.json', 'output.txt'];
265
+ const results = [
266
+ {
267
+ success: true,
268
+ score: 1.0,
269
+ namedScores: {},
270
+ latencyMs: 1000,
271
+ provider: {
272
+ id: 'foo',
273
+ },
274
+ prompt: {
275
+ raw: 'Test prompt',
276
+ label: '[display] Test prompt',
277
+ },
278
+ response: {
279
+ output: 'Test output',
280
+ },
281
+ vars: {
282
+ var1: 'value1',
283
+ var2: 'value2',
284
+ },
285
+ },
286
+ ];
287
+ const table = {
288
+ head: {
289
+ prompts: [{ raw: 'Test prompt', label: '[display] Test prompt', provider: 'foo' }],
290
+ vars: ['var1', 'var2'],
291
+ },
292
+ body: [
293
+ {
294
+ outputs: [
295
+ {
296
+ pass: true,
297
+ score: 1.0,
298
+ namedScores: {},
299
+ text: 'Test output',
300
+ prompt: 'Test prompt',
301
+ latencyMs: 1000,
302
+ cost: 0,
303
+ },
304
+ ],
305
+ vars: ['value1', 'value2'],
306
+ test: {},
307
+ },
308
+ ],
309
+ };
310
+ const summary = {
311
+ version: 2,
312
+ timestamp: '2024-01-01T00:00:00.000Z',
313
+ stats: {
314
+ successes: 1,
315
+ failures: 1,
316
+ tokenUsage: {
317
+ total: 10,
318
+ prompt: 5,
319
+ completion: 5,
320
+ cached: 0,
321
+ },
322
+ },
323
+ results,
324
+ table,
325
+ };
326
+ const config = {
327
+ description: 'test',
328
+ };
329
+ const shareableUrl = null;
330
+ (0, util_1.writeMultipleOutputs)(outputPath, null, summary, config, shareableUrl);
331
+ expect(fs.writeFileSync).toHaveBeenCalledTimes(2);
332
+ });
333
+ });
334
+ describe('readOutput', () => {
335
+ it('reads JSON output', async () => {
336
+ const outputPath = 'output.json';
337
+ jest.mocked(fs.readFileSync).mockReturnValue('{}');
338
+ const output = await (0, util_1.readOutput)(outputPath);
339
+ expect(output).toEqual({});
340
+ });
341
+ it('fails for csv output', async () => {
342
+ await expect((0, util_1.readOutput)('output.csv')).rejects.toThrow('Unsupported output file format: csv currently only supports json');
343
+ });
344
+ it('fails for yaml output', async () => {
345
+ await expect((0, util_1.readOutput)('output.yaml')).rejects.toThrow('Unsupported output file format: yaml currently only supports json');
346
+ await expect((0, util_1.readOutput)('output.yml')).rejects.toThrow('Unsupported output file format: yml currently only supports json');
347
+ });
348
+ });
349
+ it('readFilters', async () => {
350
+ const mockFilter = jest.fn();
351
+ jest.doMock(path.resolve('filter.js'), () => mockFilter, { virtual: true });
352
+ jest.mocked(glob_1.globSync).mockImplementation((pathOrGlob) => [pathOrGlob].flat());
353
+ const filters = await (0, util_1.readFilters)({ testFilter: 'filter.js' });
354
+ expect(filters.testFilter).toBe(mockFilter);
355
+ });
356
+ describe('transformOutput', () => {
357
+ afterEach(() => {
358
+ jest.clearAllMocks();
359
+ jest.resetModules();
360
+ });
361
+ it('transforms output using a direct function', async () => {
362
+ const output = 'original output';
363
+ const context = { vars: { key: 'value' }, prompt: { id: '123' } };
364
+ const transformFunction = 'output.toUpperCase()';
365
+ const transformedOutput = await (0, util_1.transformOutput)(transformFunction, output, context);
366
+ expect(transformedOutput).toBe('ORIGINAL OUTPUT');
367
+ });
368
+ it('transforms output using an imported function from a file', async () => {
369
+ const output = 'hello';
370
+ const context = { vars: { key: 'value' }, prompt: { id: '123' } };
371
+ jest.doMock(path.resolve('transform.js'), () => (output) => output.toUpperCase(), {
372
+ virtual: true,
373
+ });
374
+ const transformFunctionPath = 'file://transform.js';
375
+ const transformedOutput = await (0, util_1.transformOutput)(transformFunctionPath, output, context);
376
+ expect(transformedOutput).toBe('HELLO');
377
+ });
378
+ it('throws error if transform function does not return a value', async () => {
379
+ const output = 'test';
380
+ const context = { vars: {}, prompt: {} };
381
+ const transformFunction = ''; // Empty function, returns undefined
382
+ await expect((0, util_1.transformOutput)(transformFunction, output, context)).rejects.toThrow('Transform function did not return a value');
383
+ });
384
+ it('throws error if file does not export a function', async () => {
385
+ const output = 'test';
386
+ const context = { vars: {}, prompt: {} };
387
+ jest.doMock(path.resolve('transform.js'), () => 'banana', { virtual: true });
388
+ const transformFunctionPath = 'file://transform.js';
389
+ await expect((0, util_1.transformOutput)(transformFunctionPath, output, context)).rejects.toThrow('Transform transform.js must export a function or have a default export as a function');
390
+ });
391
+ });
392
+ describe('providerToIdentifier', () => {
393
+ it('works with string', () => {
394
+ const provider = 'openai:gpt-4';
395
+ expect((0, util_1.providerToIdentifier)(provider)).toStrictEqual(provider);
396
+ });
397
+ it('works with provider id undefined', () => {
398
+ expect((0, util_1.providerToIdentifier)(undefined)).toBeUndefined();
399
+ });
400
+ it('works with ApiProvider', () => {
401
+ const providerId = 'custom';
402
+ const apiProvider = {
403
+ id() {
404
+ return providerId;
405
+ },
406
+ };
407
+ expect((0, util_1.providerToIdentifier)(apiProvider)).toStrictEqual(providerId);
408
+ });
409
+ it('works with ProviderOptions', () => {
410
+ const providerId = 'custom';
411
+ const providerOptions = {
412
+ id: providerId,
413
+ };
414
+ expect((0, util_1.providerToIdentifier)(providerOptions)).toStrictEqual(providerId);
415
+ });
416
+ });
417
+ describe('varsMatch', () => {
418
+ it('true with both undefined', () => {
419
+ expect((0, util_1.varsMatch)(undefined, undefined)).toBe(true);
420
+ });
421
+ it('false with one undefined', () => {
422
+ expect((0, util_1.varsMatch)(undefined, {})).toBe(false);
423
+ expect((0, util_1.varsMatch)({}, undefined)).toBe(false);
424
+ });
425
+ });
426
+ describe('resultIsForTestCase', () => {
427
+ const testCase = {
428
+ provider: 'provider',
429
+ vars: {
430
+ key: 'value',
431
+ },
432
+ };
433
+ const result = {
434
+ provider: 'provider',
435
+ vars: {
436
+ key: 'value',
437
+ },
438
+ };
439
+ it('is true', () => {
440
+ expect((0, util_1.resultIsForTestCase)(result, testCase)).toBe(true);
441
+ });
442
+ it('is false if provider is different', () => {
443
+ const nonMatchTestCase = {
444
+ provider: 'different',
445
+ vars: {
446
+ key: 'value',
447
+ },
448
+ };
449
+ expect((0, util_1.resultIsForTestCase)(result, nonMatchTestCase)).toBe(false);
450
+ });
451
+ it('is false if vars are different', () => {
452
+ const nonMatchTestCase = {
453
+ provider: 'provider',
454
+ vars: {
455
+ key: 'different',
456
+ },
457
+ };
458
+ expect((0, util_1.resultIsForTestCase)(result, nonMatchTestCase)).toBe(false);
459
+ });
460
+ });
461
+ });
462
+ describe('extractJsonObjects', () => {
463
+ it('should extract a single JSON object from a string', () => {
464
+ const input = '{"key": "value"}';
465
+ const expectedOutput = [{ key: 'value' }];
466
+ expect((0, util_1.extractJsonObjects)(input)).toEqual(expectedOutput);
467
+ });
468
+ it('should extract multiple JSON objects from a string', () => {
469
+ const input = 'yolo {"key1": "value1"} some text {"key2": "value2"} fomo';
470
+ const expectedOutput = [{ key1: 'value1' }, { key2: 'value2' }];
471
+ expect((0, util_1.extractJsonObjects)(input)).toEqual(expectedOutput);
472
+ });
473
+ it('should return an empty array if no JSON objects are found', () => {
474
+ const input = 'no json here';
475
+ const expectedOutput = [];
476
+ expect((0, util_1.extractJsonObjects)(input)).toEqual(expectedOutput);
477
+ });
478
+ it('should handle nested JSON objects', () => {
479
+ const input = 'wassup {"outer": {"inner": "value"}, "foo": [1,2,3,4]}';
480
+ const expectedOutput = [{ outer: { inner: 'value' }, foo: [1, 2, 3, 4] }];
481
+ expect((0, util_1.extractJsonObjects)(input)).toEqual(expectedOutput);
482
+ });
483
+ it('should handle invalid JSON gracefully', () => {
484
+ const input = '{"key": "value" some text {"key2": "value2"}';
485
+ const expectedOutput = [{ key2: 'value2' }];
486
+ expect((0, util_1.extractJsonObjects)(input)).toEqual(expectedOutput);
487
+ });
488
+ });
489
+ describe('parsePathOrGlob', () => {
490
+ afterEach(() => {
491
+ jest.clearAllMocks();
492
+ });
493
+ it('should parse a simple file path with extension', () => {
494
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
495
+ expect((0, util_1.parsePathOrGlob)('/base', 'file.txt')).toEqual({
496
+ extension: '.txt',
497
+ functionName: undefined,
498
+ isPathPattern: false,
499
+ filePath: path.join('/base', 'file.txt'),
500
+ });
501
+ });
502
+ it('should parse a file path with function name', () => {
503
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
504
+ expect((0, util_1.parsePathOrGlob)('/base', 'file.py:myFunction')).toEqual({
505
+ extension: '.py',
506
+ functionName: 'myFunction',
507
+ isPathPattern: false,
508
+ filePath: path.join('/base', 'file.py'),
509
+ });
510
+ });
511
+ it('should parse a directory path', () => {
512
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => true });
513
+ expect((0, util_1.parsePathOrGlob)('/base', 'dir')).toEqual({
514
+ extension: undefined,
515
+ functionName: undefined,
516
+ isPathPattern: true,
517
+ filePath: path.join('/base', 'dir'),
518
+ });
519
+ });
520
+ it('should handle non-existent file path gracefully when PROMPTFOO_STRICT_FILES is false', () => {
521
+ jest.spyOn(fs, 'statSync').mockImplementation(() => {
522
+ throw new Error('File does not exist');
523
+ });
524
+ expect((0, util_1.parsePathOrGlob)('/base', 'nonexistent.js')).toEqual({
525
+ extension: '.js',
526
+ functionName: undefined,
527
+ isPathPattern: false,
528
+ filePath: path.join('/base', 'nonexistent.js'),
529
+ });
530
+ });
531
+ it('should throw an error for non-existent file path when PROMPTFOO_STRICT_FILES is true', () => {
532
+ process.env.PROMPTFOO_STRICT_FILES = 'true';
533
+ jest.spyOn(fs, 'statSync').mockImplementation(() => {
534
+ throw new Error('File does not exist');
535
+ });
536
+ expect(() => (0, util_1.parsePathOrGlob)('/base', 'nonexistent.js')).toThrow('File does not exist');
537
+ delete process.env.PROMPTFOO_STRICT_FILES;
538
+ });
539
+ it('should return empty extension for files without extension', () => {
540
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
541
+ expect((0, util_1.parsePathOrGlob)('/base', 'file')).toEqual({
542
+ extension: '',
543
+ functionName: undefined,
544
+ isPathPattern: false,
545
+ filePath: path.join('/base', 'file'),
546
+ });
547
+ });
548
+ it('should handle relative paths', () => {
549
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
550
+ expect((0, util_1.parsePathOrGlob)('./base', 'file.txt')).toEqual({
551
+ extension: '.txt',
552
+ functionName: undefined,
553
+ isPathPattern: false,
554
+ filePath: path.join('./base', 'file.txt'),
555
+ });
556
+ });
557
+ it('should handle paths with environment variables', () => {
558
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
559
+ process.env.FILE_PATH = 'file.txt';
560
+ expect((0, util_1.parsePathOrGlob)('/base', process.env.FILE_PATH)).toEqual({
561
+ extension: '.txt',
562
+ functionName: undefined,
563
+ isPathPattern: false,
564
+ filePath: path.join('/base', 'file.txt'),
565
+ });
566
+ delete process.env.FILE_PATH;
567
+ });
568
+ it('should handle glob patterns in file path', () => {
569
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
570
+ expect((0, util_1.parsePathOrGlob)('/base', '*.js')).toEqual({
571
+ extension: undefined,
572
+ functionName: undefined,
573
+ isPathPattern: true,
574
+ filePath: path.join('/base', '*.js'),
575
+ });
576
+ });
577
+ it('should handle complex file paths', () => {
578
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
579
+ expect((0, util_1.parsePathOrGlob)('/base', 'dir/subdir/file.py:func')).toEqual({
580
+ extension: '.py',
581
+ functionName: 'func',
582
+ isPathPattern: false,
583
+ filePath: path.join('/base', 'dir/subdir/file.py'),
584
+ });
585
+ });
586
+ it('should handle non-standard file extensions', () => {
587
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
588
+ expect((0, util_1.parsePathOrGlob)('/base', 'file.customext')).toEqual({
589
+ extension: '.customext',
590
+ functionName: undefined,
591
+ isPathPattern: false,
592
+ filePath: path.join('/base', 'file.customext'),
593
+ });
594
+ });
595
+ it('should handle deeply nested file paths', () => {
596
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
597
+ expect((0, util_1.parsePathOrGlob)('/base', 'a/b/c/d/e/f/g/file.py:func')).toEqual({
598
+ extension: '.py',
599
+ functionName: 'func',
600
+ isPathPattern: false,
601
+ filePath: path.join('/base', 'a/b/c/d/e/f/g/file.py'),
602
+ });
603
+ });
604
+ it('should handle complex directory paths', () => {
605
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => true });
606
+ expect((0, util_1.parsePathOrGlob)('/base', 'a/b/c/d/e/f/g')).toEqual({
607
+ extension: undefined,
608
+ functionName: undefined,
609
+ isPathPattern: true,
610
+ filePath: path.join('/base', 'a/b/c/d/e/f/g'),
611
+ });
612
+ });
613
+ it('should join basePath and safeFilename correctly', () => {
614
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
615
+ const basePath = 'base';
616
+ const relativePath = 'relative/path/to/file.txt';
617
+ expect((0, util_1.parsePathOrGlob)(basePath, relativePath)).toEqual({
618
+ extension: '.txt',
619
+ functionName: undefined,
620
+ isPathPattern: false,
621
+ filePath: expect.stringMatching(/base[\\\/]relative[\\\/]path[\\\/]to[\\\/]file.txt/),
622
+ });
623
+ });
624
+ it('should handle empty basePath', () => {
625
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
626
+ expect((0, util_1.parsePathOrGlob)('', 'file.txt')).toEqual({
627
+ extension: '.txt',
628
+ functionName: undefined,
629
+ isPathPattern: false,
630
+ filePath: 'file.txt',
631
+ });
632
+ });
633
+ it('should handle file:// prefix', () => {
634
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
635
+ expect((0, util_1.parsePathOrGlob)('', 'file://file.txt')).toEqual({
636
+ extension: '.txt',
637
+ functionName: undefined,
638
+ isPathPattern: false,
639
+ filePath: 'file.txt',
640
+ });
641
+ });
642
+ it('should handle file://./... with absolute base path', () => {
643
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
644
+ expect((0, util_1.parsePathOrGlob)('/absolute/base', 'file://./prompts/file.txt')).toEqual({
645
+ extension: '.txt',
646
+ functionName: undefined,
647
+ isPathPattern: false,
648
+ filePath: expect.stringMatching(/^[/\\]absolute[/\\]base[/\\]prompts[/\\]file\.txt$/),
649
+ });
650
+ });
651
+ it('should handle file://./... with relative base path', () => {
652
+ jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => false });
653
+ expect((0, util_1.parsePathOrGlob)('relative/base', 'file://file.txt')).toEqual({
654
+ extension: '.txt',
655
+ functionName: undefined,
656
+ isPathPattern: false,
657
+ filePath: expect.stringMatching(/^relative[/\\]base[/\\]file\.txt$/),
658
+ });
659
+ });
660
+ });
661
+ //# sourceMappingURL=util.test.js.map