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.
- package/README.md +5 -5
- package/dist/package.json +14 -8
- package/dist/src/accounts.d.ts.map +1 -1
- package/dist/src/accounts.js +2 -1
- package/dist/src/accounts.js.map +1 -1
- package/dist/src/assertions/validateAssertions.d.ts +1 -1
- package/dist/src/assertions/validateAssertions.d.ts.map +1 -1
- package/dist/src/assertions/validateAssertions.js +7 -7
- package/dist/src/assertions/validateAssertions.js.map +1 -1
- package/dist/src/assertions.d.ts.map +1 -1
- package/dist/src/assertions.js +2 -1
- package/dist/src/assertions.js.map +1 -1
- package/dist/src/cache.js +2 -2
- package/dist/src/cache.js.map +1 -1
- package/dist/src/commands/eval.d.ts.map +1 -1
- package/dist/src/commands/eval.js +10 -0
- package/dist/src/commands/eval.js.map +1 -1
- package/dist/src/commands/export.d.ts.map +1 -1
- package/dist/src/commands/export.js +15 -14
- package/dist/src/commands/export.js.map +1 -1
- package/dist/src/commands/generate/redteam.d.ts +1 -46
- package/dist/src/commands/generate/redteam.d.ts.map +1 -1
- package/dist/src/commands/generate/redteam.js +70 -26
- package/dist/src/commands/generate/redteam.js.map +1 -1
- package/dist/src/commands/import.d.ts.map +1 -1
- package/dist/src/commands/import.js +2 -1
- package/dist/src/commands/import.js.map +1 -1
- package/dist/src/commands/init.d.ts.map +1 -1
- package/dist/src/commands/init.js +12 -0
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/redteam.d.ts.map +1 -1
- package/dist/src/commands/redteam.js +72 -18
- package/dist/src/commands/redteam.js.map +1 -1
- package/dist/src/commands/view.d.ts.map +1 -1
- package/dist/src/commands/view.js +2 -1
- package/dist/src/commands/view.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +2 -20
- package/dist/src/config.js.map +1 -1
- package/dist/src/configTypes.d.ts +7 -0
- package/dist/src/configTypes.d.ts.map +1 -0
- package/dist/src/configTypes.js +3 -0
- package/dist/src/configTypes.js.map +1 -0
- package/dist/src/database/index.d.ts +4 -0
- package/dist/src/database/index.d.ts.map +1 -0
- package/dist/src/database/index.js +50 -0
- package/dist/src/database/index.js.map +1 -0
- package/dist/src/{database.d.ts → database/operations.d.ts} +173 -115
- package/dist/src/{database.d.ts.map → database/operations.d.ts.map} +1 -1
- package/dist/src/{database.js → database/operations.js} +1 -25
- package/dist/src/database/operations.js.map +1 -0
- package/dist/src/evaluator.js +2 -2
- package/dist/src/evaluator.js.map +1 -1
- package/dist/src/globalConfig.d.ts +1 -7
- package/dist/src/globalConfig.d.ts.map +1 -1
- package/dist/src/globalConfig.js +3 -3
- package/dist/src/globalConfig.js.map +1 -1
- package/dist/src/matchers.d.ts.map +1 -1
- package/dist/src/matchers.js +6 -2
- package/dist/src/matchers.js.map +1 -1
- package/dist/src/prompts/grading.js +2 -2
- package/dist/src/prompts/processors/python.js +4 -4
- package/dist/src/prompts/processors/python.js.map +1 -1
- package/dist/src/providers/anthropic.d.ts +1 -1
- package/dist/src/providers/anthropic.d.ts.map +1 -1
- package/dist/src/providers/bam.d.ts +1 -1
- package/dist/src/providers/bam.d.ts.map +1 -1
- package/dist/src/providers/bedrock.d.ts +1 -1
- package/dist/src/providers/bedrock.d.ts.map +1 -1
- package/dist/src/providers/cohere.d.ts.map +1 -1
- package/dist/src/providers/cohere.js +4 -1
- package/dist/src/providers/cohere.js.map +1 -1
- package/dist/src/providers/http.d.ts +1 -1
- package/dist/src/providers/http.d.ts.map +1 -1
- package/dist/src/providers/http.js +3 -3
- package/dist/src/providers/http.js.map +1 -1
- package/dist/src/providers/llama.d.ts +1 -1
- package/dist/src/providers/llama.d.ts.map +1 -1
- package/dist/src/providers/localai.d.ts +1 -1
- package/dist/src/providers/localai.d.ts.map +1 -1
- package/dist/src/providers/ollama.d.ts +1 -1
- package/dist/src/providers/ollama.d.ts.map +1 -1
- package/dist/src/providers/openai.d.ts +1 -1
- package/dist/src/providers/openai.d.ts.map +1 -1
- package/dist/src/providers/openai.js +48 -50
- package/dist/src/providers/openai.js.map +1 -1
- package/dist/src/providers/palm.d.ts +1 -1
- package/dist/src/providers/palm.d.ts.map +1 -1
- package/dist/src/providers/pythonCompletion.d.ts.map +1 -1
- package/dist/src/providers/pythonCompletion.js +6 -5
- package/dist/src/providers/pythonCompletion.js.map +1 -1
- package/dist/src/providers/replicate.js +2 -2
- package/dist/src/providers/replicate.js.map +1 -1
- package/dist/src/providers/scriptCompletion.js +3 -3
- package/dist/src/providers/scriptCompletion.js.map +1 -1
- package/dist/src/providers/vertex.d.ts +1 -1
- package/dist/src/providers/vertex.d.ts.map +1 -1
- package/dist/src/providers/vertex.js +23 -10
- package/dist/src/providers/vertex.js.map +1 -1
- package/dist/src/providers/vertexUtil.d.ts +2 -1
- package/dist/src/providers/vertexUtil.d.ts.map +1 -1
- package/dist/src/providers/vertexUtil.js.map +1 -1
- package/dist/src/providers/webhook.d.ts +1 -1
- package/dist/src/providers/webhook.d.ts.map +1 -1
- package/dist/src/providers.d.ts.map +1 -1
- package/dist/src/providers.js +5 -2
- package/dist/src/providers.js.map +1 -1
- package/dist/src/python/pythonUtils.d.ts +4 -0
- package/dist/src/python/pythonUtils.d.ts.map +1 -0
- package/dist/src/python/pythonUtils.js +51 -0
- package/dist/src/python/pythonUtils.js.map +1 -0
- package/dist/src/python/wrapper.d.ts +0 -10
- package/dist/src/python/wrapper.d.ts.map +1 -1
- package/dist/src/python/wrapper.js +2 -49
- package/dist/src/python/wrapper.js.map +1 -1
- package/dist/src/redteam/constants.d.ts +60 -3
- package/dist/src/redteam/constants.d.ts.map +1 -1
- package/dist/src/redteam/constants.js +71 -10
- package/dist/src/redteam/constants.js.map +1 -1
- package/dist/src/redteam/index.d.ts +15 -4
- package/dist/src/redteam/index.d.ts.map +1 -1
- package/dist/src/redteam/index.js +110 -33
- package/dist/src/redteam/index.js.map +1 -1
- package/dist/src/redteam/plugins/base.d.ts +10 -13
- package/dist/src/redteam/plugins/base.d.ts.map +1 -1
- package/dist/src/redteam/plugins/base.js +36 -20
- package/dist/src/redteam/plugins/base.js.map +1 -1
- package/dist/src/redteam/plugins/debugInterface.d.ts +7 -0
- package/dist/src/redteam/plugins/debugInterface.d.ts.map +1 -0
- package/dist/src/redteam/plugins/debugInterface.js +49 -0
- package/dist/src/redteam/plugins/debugInterface.js.map +1 -0
- package/dist/src/redteam/plugins/harmful.d.ts +1 -54
- package/dist/src/redteam/plugins/harmful.d.ts.map +1 -1
- package/dist/src/redteam/plugins/harmful.js +8 -51
- package/dist/src/redteam/plugins/harmful.js.map +1 -1
- package/dist/src/redteam/plugins/pii.d.ts +9 -10
- package/dist/src/redteam/plugins/pii.d.ts.map +1 -1
- package/dist/src/redteam/plugins/pii.js +33 -53
- package/dist/src/redteam/plugins/pii.js.map +1 -1
- package/dist/src/redteam/plugins/rbac.d.ts +7 -0
- package/dist/src/redteam/plugins/rbac.d.ts.map +1 -0
- package/dist/src/redteam/plugins/rbac.js +49 -0
- package/dist/src/redteam/plugins/rbac.js.map +1 -0
- package/dist/src/redteam/plugins/shellInjection.d.ts +7 -0
- package/dist/src/redteam/plugins/shellInjection.d.ts.map +1 -0
- package/dist/src/redteam/plugins/shellInjection.js +54 -0
- package/dist/src/redteam/plugins/shellInjection.js.map +1 -0
- package/dist/src/redteam/plugins/sqlInjection.d.ts +7 -0
- package/dist/src/redteam/plugins/sqlInjection.d.ts.map +1 -0
- package/dist/src/redteam/plugins/sqlInjection.js +44 -0
- package/dist/src/redteam/plugins/sqlInjection.js.map +1 -0
- package/dist/src/redteam/providers/iterative.d.ts.map +1 -1
- package/dist/src/redteam/providers/iterative.js +2 -1
- package/dist/src/redteam/providers/iterative.js.map +1 -1
- package/dist/src/redteam/strategies/injections.d.ts.map +1 -0
- package/dist/src/redteam/{methods → strategies}/injections.js +0 -12
- package/dist/src/redteam/strategies/injections.js.map +1 -0
- package/dist/src/redteam/strategies/iterative.d.ts.map +1 -0
- package/dist/src/redteam/strategies/iterative.js.map +1 -0
- package/dist/src/redteam/types.d.ts +196 -0
- package/dist/src/redteam/types.d.ts.map +1 -0
- package/dist/src/redteam/types.js +124 -0
- package/dist/src/redteam/types.js.map +1 -0
- package/dist/src/redteam/util.d.ts +22 -0
- package/dist/src/redteam/util.d.ts.map +1 -0
- package/dist/src/redteam/util.js +56 -0
- package/dist/src/redteam/util.js.map +1 -0
- package/dist/src/testCases.d.ts +1 -2
- package/dist/src/testCases.d.ts.map +1 -1
- package/dist/src/testCases.js.map +1 -1
- package/dist/src/types/databaseTypes.d.ts +17 -0
- package/dist/src/types/databaseTypes.d.ts.map +1 -0
- package/dist/src/types/databaseTypes.js +3 -0
- package/dist/src/types/databaseTypes.js.map +1 -0
- package/dist/src/{types.d.ts → types/index.d.ts} +4296 -1425
- package/dist/src/{types.d.ts.map → types/index.d.ts.map} +1 -1
- package/dist/src/{types.js → types/index.js} +38 -9
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/util/config.d.ts +3 -0
- package/dist/src/util/config.d.ts.map +1 -0
- package/dist/src/util/config.js +42 -0
- package/dist/src/util/config.js.map +1 -0
- package/dist/src/util/index.d.ts +41 -25
- package/dist/src/util/index.d.ts.map +1 -1
- package/dist/src/util/index.js +81 -119
- package/dist/src/util/index.js.map +1 -1
- package/dist/src/util/json.d.ts +3 -0
- package/dist/src/util/json.d.ts.map +1 -0
- package/dist/src/util/json.js +27 -0
- package/dist/src/util/json.js.map +1 -0
- package/dist/src/web/nextui/404/index.html +1 -1
- package/dist/src/web/nextui/404.html +1 -1
- package/dist/src/web/nextui/_next/static/chunks/155-4e319e68476266ee.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/163-93bab94bc04ae71b.js +6 -0
- package/dist/src/web/nextui/_next/static/chunks/{258-4acb452fe85cff6f.js → 258-b6257e5de9d0e2c7.js} +1 -1
- package/dist/src/web/nextui/_next/static/chunks/281-64d9f1415a301ee5.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/304-cf667fe8f06238b4.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/322-b47b6cc3f5b5fdb8.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/325-0d36870ade5e5263.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/339-79124d204fa988a3.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/378-c135e497df1864cb.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/476-0afb5eb266c57b7f.js +17 -0
- package/dist/src/web/nextui/_next/static/chunks/493-ebd12f00541c4969.js +2 -0
- package/dist/src/web/nextui/_next/static/chunks/497-e280a5610a3d7d42.js +32 -0
- package/dist/src/web/nextui/_next/static/chunks/515-e06d044f12d8a1bd.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/69-5e4d5e60859a86d2.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/737-32d5472455807d7a.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/903-7cc440d9f9e9f95d.js +97 -0
- package/dist/src/web/nextui/_next/static/chunks/905-78cd666f27891ee6.js +28 -0
- package/dist/src/web/nextui/_next/static/chunks/916-b92fea2ab6136411.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/969-6ab6c8f4158da970.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/auth/login/page-7247b17e8f179a46.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/auth/signup/page-8560afaf494f9882.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/datasets/page-6e6ec3c778ccd110.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/not-found-fe10d5df88bc44ef.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/{page-0a39d3450aa09dda.js → page-057e5eb83e0f614b.js} +1 -1
- package/dist/src/web/nextui/_next/static/chunks/app/eval/page-88fa70fc5bf755bc.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/layout-15abf0d1049cb47c.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/{page-5650318e57510b6c.js → page-122e9cfa52eb218a.js} +1 -1
- package/dist/src/web/nextui/_next/static/chunks/app/progress/page-a62ca531a4bb4149.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/prompts/page-10bb2e571670139c.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/report/page-a8b83960f08e2bb2.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/app/setup/page-6ea3e180c3116fb2.js +1 -0
- package/dist/src/web/nextui/_next/static/chunks/{main-app-929a26b3c8cd3f7a.js → main-app-7a1376166cb8b72e.js} +1 -1
- package/dist/src/web/nextui/_next/static/chunks/{webpack-c9f728822666f852.js → webpack-ee33d95b3e219985.js} +1 -1
- package/dist/src/web/nextui/_next/static/css/13f881e4290b6d59.css +1 -0
- package/dist/src/web/nextui/_next/static/css/87b5e6e04efd27e5.css +1 -0
- package/dist/src/web/nextui/_next/static/css/e17fdafd8599f69b.css +1 -0
- package/dist/src/web/nextui/_next/static/css/eb523daddb89dfc1.css +1 -0
- package/dist/src/web/nextui/auth/login/index.html +1 -1
- package/dist/src/web/nextui/auth/login/index.txt +6 -6
- package/dist/src/web/nextui/auth/signup/index.html +1 -1
- package/dist/src/web/nextui/auth/signup/index.txt +6 -6
- package/dist/src/web/nextui/datasets/index.html +1 -1
- package/dist/src/web/nextui/datasets/index.txt +6 -6
- package/dist/src/web/nextui/eval/index.html +1 -1
- package/dist/src/web/nextui/eval/index.txt +8 -8
- package/dist/src/web/nextui/index.html +1 -1
- package/dist/src/web/nextui/index.txt +5 -5
- package/dist/src/web/nextui/logo-panda.svg +91 -0
- package/dist/src/web/nextui/progress/index.html +1 -1
- package/dist/src/web/nextui/progress/index.txt +6 -6
- package/dist/src/web/nextui/prompts/index.html +1 -1
- package/dist/src/web/nextui/prompts/index.txt +6 -6
- package/dist/src/web/nextui/report/index.html +1 -1
- package/dist/src/web/nextui/report/index.txt +8 -8
- package/dist/src/web/nextui/setup/index.html +1 -1
- package/dist/src/web/nextui/setup/index.txt +7 -7
- package/dist/test/__mocks__/tempCustomModule.d.ts +13 -0
- package/dist/test/__mocks__/tempCustomModule.d.ts.map +1 -0
- package/dist/test/__mocks__/tempCustomModule.js +15 -0
- package/dist/test/__mocks__/tempCustomModule.js.map +1 -0
- package/dist/test/account.test.d.ts +2 -0
- package/dist/test/account.test.d.ts.map +1 -0
- package/dist/test/account.test.js +46 -0
- package/dist/test/account.test.js.map +1 -0
- package/dist/test/assertions/AssertionResult.test.d.ts +2 -0
- package/dist/test/assertions/AssertionResult.test.d.ts.map +1 -0
- package/dist/test/assertions/AssertionResult.test.js +184 -0
- package/dist/test/assertions/AssertionResult.test.js.map +1 -0
- package/dist/test/assertions/validateAssertions.test.d.ts +2 -0
- package/dist/test/assertions/validateAssertions.test.d.ts.map +1 -0
- package/dist/test/assertions/validateAssertions.test.js +40 -0
- package/dist/test/assertions/validateAssertions.test.js.map +1 -0
- package/dist/test/assertions.test.d.ts +2 -0
- package/dist/test/assertions.test.d.ts.map +1 -0
- package/dist/test/assertions.test.js +3162 -0
- package/dist/test/assertions.test.js.map +1 -0
- package/dist/test/cache.test.d.ts +2 -0
- package/dist/test/cache.test.d.ts.map +1 -0
- package/dist/test/cache.test.js +90 -0
- package/dist/test/cache.test.js.map +1 -0
- package/dist/test/checkNodeVersion.test.d.ts +2 -0
- package/dist/test/checkNodeVersion.test.d.ts.map +1 -0
- package/dist/test/checkNodeVersion.test.js +85 -0
- package/dist/test/checkNodeVersion.test.js.map +1 -0
- package/dist/test/commands/eval/filterFailingTests.test.d.ts +2 -0
- package/dist/test/commands/eval/filterFailingTests.test.d.ts.map +1 -0
- package/dist/test/commands/eval/filterFailingTests.test.js +84 -0
- package/dist/test/commands/eval/filterFailingTests.test.js.map +1 -0
- package/dist/test/commands/eval/filterProviders.test.d.ts +2 -0
- package/dist/test/commands/eval/filterProviders.test.d.ts.map +1 -0
- package/dist/test/commands/eval/filterProviders.test.js +50 -0
- package/dist/test/commands/eval/filterProviders.test.js.map +1 -0
- package/dist/test/commands/eval/filterTests.test.d.ts +2 -0
- package/dist/test/commands/eval/filterTests.test.d.ts.map +1 -0
- package/dist/test/commands/eval/filterTests.test.js +51 -0
- package/dist/test/commands/eval/filterTests.test.js.map +1 -0
- package/dist/test/config.test.d.ts +2 -0
- package/dist/test/config.test.d.ts.map +1 -0
- package/dist/test/config.test.js +404 -0
- package/dist/test/config.test.js.map +1 -0
- package/dist/test/csv.test.d.ts +2 -0
- package/dist/test/csv.test.d.ts.map +1 -0
- package/dist/test/csv.test.js +239 -0
- package/dist/test/csv.test.js.map +1 -0
- package/dist/test/evaluator.test.d.ts +2 -0
- package/dist/test/evaluator.test.d.ts.map +1 -0
- package/dist/test/evaluator.test.js +922 -0
- package/dist/test/evaluator.test.js.map +1 -0
- package/dist/test/globalConfig.test.d.ts +2 -0
- package/dist/test/globalConfig.test.d.ts.map +1 -0
- package/dist/test/globalConfig.test.js +91 -0
- package/dist/test/globalConfig.test.js.map +1 -0
- package/dist/test/is-sql-tests/node-sql-parser.test.d.ts +2 -0
- package/dist/test/is-sql-tests/node-sql-parser.test.d.ts.map +1 -0
- package/dist/test/is-sql-tests/node-sql-parser.test.js +179 -0
- package/dist/test/is-sql-tests/node-sql-parser.test.js.map +1 -0
- package/dist/test/matchers.test.d.ts +2 -0
- package/dist/test/matchers.test.d.ts.map +1 -0
- package/dist/test/matchers.test.js +807 -0
- package/dist/test/matchers.test.js.map +1 -0
- package/dist/test/prompts.processors.javascript.test.d.ts +2 -0
- package/dist/test/prompts.processors.javascript.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.javascript.test.js +93 -0
- package/dist/test/prompts.processors.javascript.test.js.map +1 -0
- package/dist/test/prompts.processors.json.test.d.ts +2 -0
- package/dist/test/prompts.processors.json.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.json.test.js +67 -0
- package/dist/test/prompts.processors.json.test.js.map +1 -0
- package/dist/test/prompts.processors.jsonl.test.d.ts +2 -0
- package/dist/test/prompts.processors.jsonl.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.jsonl.test.js +99 -0
- package/dist/test/prompts.processors.jsonl.test.js.map +1 -0
- package/dist/test/prompts.processors.python.test.d.ts +2 -0
- package/dist/test/prompts.processors.python.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.python.test.js +100 -0
- package/dist/test/prompts.processors.python.test.js.map +1 -0
- package/dist/test/prompts.processors.python.utils.test.d.ts +2 -0
- package/dist/test/prompts.processors.python.utils.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.python.utils.test.js +68 -0
- package/dist/test/prompts.processors.python.utils.test.js.map +1 -0
- package/dist/test/prompts.processors.string.test.d.ts +2 -0
- package/dist/test/prompts.processors.string.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.string.test.js +24 -0
- package/dist/test/prompts.processors.string.test.js.map +1 -0
- package/dist/test/prompts.processors.text.test.d.ts +2 -0
- package/dist/test/prompts.processors.text.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.text.test.js +109 -0
- package/dist/test/prompts.processors.text.test.js.map +1 -0
- package/dist/test/prompts.processors.yaml.test.d.ts +2 -0
- package/dist/test/prompts.processors.yaml.test.d.ts.map +1 -0
- package/dist/test/prompts.processors.yaml.test.js +76 -0
- package/dist/test/prompts.processors.yaml.test.js.map +1 -0
- package/dist/test/prompts.test.d.ts +2 -0
- package/dist/test/prompts.test.d.ts.map +1 -0
- package/dist/test/prompts.test.js +562 -0
- package/dist/test/prompts.test.js.map +1 -0
- package/dist/test/prompts.utils.test.d.ts +2 -0
- package/dist/test/prompts.utils.test.d.ts.map +1 -0
- package/dist/test/prompts.utils.test.js +123 -0
- package/dist/test/prompts.utils.test.js.map +1 -0
- package/dist/test/providers.anthropic.test.d.ts +2 -0
- package/dist/test/providers.anthropic.test.d.ts.map +1 -0
- package/dist/test/providers.anthropic.test.js +520 -0
- package/dist/test/providers.anthropic.test.js.map +1 -0
- package/dist/test/providers.azure.test.d.ts +2 -0
- package/dist/test/providers.azure.test.d.ts.map +1 -0
- package/dist/test/providers.azure.test.js +96 -0
- package/dist/test/providers.azure.test.js.map +1 -0
- package/dist/test/providers.bedrock.test.d.ts +2 -0
- package/dist/test/providers.bedrock.test.d.ts.map +1 -0
- package/dist/test/providers.bedrock.test.js +349 -0
- package/dist/test/providers.bedrock.test.js.map +1 -0
- package/dist/test/providers.http.test.d.ts +2 -0
- package/dist/test/providers.http.test.d.ts.map +1 -0
- package/dist/test/providers.http.test.js +130 -0
- package/dist/test/providers.http.test.js.map +1 -0
- package/dist/test/providers.llama.test.d.ts +2 -0
- package/dist/test/providers.llama.test.d.ts.map +1 -0
- package/dist/test/providers.llama.test.js +101 -0
- package/dist/test/providers.llama.test.js.map +1 -0
- package/dist/test/providers.pythonCompletion.test.d.ts +2 -0
- package/dist/test/providers.pythonCompletion.test.d.ts.map +1 -0
- package/dist/test/providers.pythonCompletion.test.js +149 -0
- package/dist/test/providers.pythonCompletion.test.js.map +1 -0
- package/dist/test/providers.test.d.ts +2 -0
- package/dist/test/providers.test.d.ts.map +1 -0
- package/dist/test/providers.test.js +883 -0
- package/dist/test/providers.test.js.map +1 -0
- package/dist/test/providers.vertex.test.d.ts +2 -0
- package/dist/test/providers.vertex.test.d.ts.map +1 -0
- package/dist/test/providers.vertex.test.js +153 -0
- package/dist/test/providers.vertex.test.js.map +1 -0
- package/dist/test/pythonWrapper.test.d.ts +2 -0
- package/dist/test/pythonWrapper.test.d.ts.map +1 -0
- package/dist/test/pythonWrapper.test.js +65 -0
- package/dist/test/pythonWrapper.test.js.map +1 -0
- package/dist/test/redteam/plugins/base.test.d.ts +2 -0
- package/dist/test/redteam/plugins/base.test.d.ts.map +1 -0
- package/dist/test/redteam/plugins/base.test.js +149 -0
- package/dist/test/redteam/plugins/base.test.js.map +1 -0
- package/dist/test/redteam/purpose.test.d.ts +2 -0
- package/dist/test/redteam/purpose.test.d.ts.map +1 -0
- package/dist/test/redteam/purpose.test.js +37 -0
- package/dist/test/redteam/purpose.test.js.map +1 -0
- package/dist/test/redteam/types.test.d.ts +2 -0
- package/dist/test/redteam/types.test.d.ts.map +1 -0
- package/dist/test/redteam/types.test.js +325 -0
- package/dist/test/redteam/types.test.js.map +1 -0
- package/dist/test/redteam/util.test.d.ts +2 -0
- package/dist/test/redteam/util.test.d.ts.map +1 -0
- package/dist/test/redteam/util.test.js +99 -0
- package/dist/test/redteam/util.test.js.map +1 -0
- package/dist/test/telemetry.test.d.ts +2 -0
- package/dist/test/telemetry.test.d.ts.map +1 -0
- package/dist/test/telemetry.test.js +68 -0
- package/dist/test/telemetry.test.js.map +1 -0
- package/dist/test/testCases.test.d.ts +2 -0
- package/dist/test/testCases.test.d.ts.map +1 -0
- package/dist/test/testCases.test.js +362 -0
- package/dist/test/testCases.test.js.map +1 -0
- package/dist/test/updates.test.d.ts +2 -0
- package/dist/test/updates.test.d.ts.map +1 -0
- package/dist/test/updates.test.js +63 -0
- package/dist/test/updates.test.js.map +1 -0
- package/dist/test/util.templates.test.d.ts +2 -0
- package/dist/test/util.templates.test.d.ts.map +1 -0
- package/dist/test/util.templates.test.js +75 -0
- package/dist/test/util.templates.test.js.map +1 -0
- package/dist/test/util.test.d.ts +2 -0
- package/dist/test/util.test.d.ts.map +1 -0
- package/dist/test/util.test.js +661 -0
- package/dist/test/util.test.js.map +1 -0
- package/dist/test/utils.d.ts +6 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/utils.js +16 -0
- package/dist/test/utils.js.map +1 -0
- package/package.json +14 -8
- package/dist/src/database.js.map +0 -1
- package/dist/src/redteam/methods/injections.d.ts.map +0 -1
- package/dist/src/redteam/methods/injections.js.map +0 -1
- package/dist/src/redteam/methods/iterative.d.ts.map +0 -1
- package/dist/src/redteam/methods/iterative.js.map +0 -1
- package/dist/src/types.js.map +0 -1
- package/dist/src/web/nextui/_next/static/chunks/163-e65e0f7f442a0c72.js +0 -6
- package/dist/src/web/nextui/_next/static/chunks/180-46db19289d856800.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/304-9d57a2251034b801.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/322-4a0fc9b0508f47e8.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/339-db5bd05e24dde905.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/374-d40afe599198abd3.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/378-e22c8aeb8e031fad.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/448-4da3bf74eae4996a.js +0 -97
- package/dist/src/web/nextui/_next/static/chunks/53-fae6e50ace6c83a1.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/578-8efe57f906f7573c.js +0 -44
- package/dist/src/web/nextui/_next/static/chunks/620-7a5a7bf6e1fe49e5.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/737-538f50dc31cc8c49.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/905-0da344cee75690e7.js +0 -32
- package/dist/src/web/nextui/_next/static/chunks/932-75585b3be8ce494d.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/973-ffe3726c956d08ef.js +0 -2
- package/dist/src/web/nextui/_next/static/chunks/995-803c74b81e7bf6cd.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/auth/login/page-2e2c0c725127ea2d.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/auth/signup/page-ccdb1f6890601666.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/datasets/page-642db4f4a8e8ba40.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/eval/[id]/not-found-ce320e6d1e6d1d23.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/eval/page-32eaa14d2384c5b0.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/layout-4282b1d33566e258.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/progress/page-462526776efd6fd6.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/prompts/page-0ae78bc0bf7c56bc.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/report/page-e4f7851d41eb0f92.js +0 -1
- package/dist/src/web/nextui/_next/static/chunks/app/setup/page-6cde750ec428cd75.js +0 -1
- package/dist/src/web/nextui/_next/static/css/35ab7ce8025438b0.css +0 -1
- package/dist/src/web/nextui/_next/static/css/5bd2f45de1f3ba83.css +0 -1
- package/dist/src/web/nextui/_next/static/css/94b771e23fc5d5f5.css +0 -1
- package/dist/src/web/nextui/_next/static/css/dab5d695b3657d59.css +0 -1
- /package/dist/src/redteam/{methods → strategies}/injections.d.ts +0 -0
- /package/dist/src/redteam/{methods → strategies}/iterative.d.ts +0 -0
- /package/dist/src/redteam/{methods → strategies}/iterative.js +0 -0
- /package/dist/src/web/nextui/_next/static/{8E4q0Tmu22G1wENZyXEq0 → L-tpppAe26U-euPv62afH}/_buildManifest.js +0 -0
- /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
|