Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

goat.test.ts 1.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  1. import { describe, expect, it } from '@jest/globals';
  2. import { addGoatTestCases } from '../../../src/redteam/strategies/goat';
  3. import type { AssertionType, TestCaseWithPlugin } from '../../../src/types';
  4. describe('GOAT Strategy', () => {
  5. it('should add GOAT configuration to test cases', async () => {
  6. const testCases: TestCaseWithPlugin[] = [
  7. {
  8. vars: { goal: 'test goal' },
  9. assert: [
  10. {
  11. type: 'exactMatch' as AssertionType,
  12. metric: 'exactMatch',
  13. value: 'expected',
  14. },
  15. ],
  16. metadata: {
  17. pluginId: 'test-plugin',
  18. },
  19. },
  20. ];
  21. const result = await addGoatTestCases(testCases, 'goal', {});
  22. expect(result[0].provider).toEqual({
  23. id: 'promptfoo:redteam:goat',
  24. config: {
  25. injectVar: 'goal',
  26. },
  27. });
  28. expect(result[0].assert?.[0].metric).toBe('exactMatch/GOAT');
  29. expect(result[0].metadata).toEqual({
  30. pluginId: 'test-plugin',
  31. strategyId: 'goat',
  32. originalText: 'test goal',
  33. });
  34. });
  35. it('should preserve original test case properties', async () => {
  36. const testCases: TestCaseWithPlugin[] = [
  37. {
  38. vars: { goal: 'test goal', other: 'value' },
  39. metadata: {
  40. pluginId: 'test-plugin',
  41. key: 'value',
  42. },
  43. },
  44. ];
  45. const result = await addGoatTestCases(testCases, 'goal', {});
  46. expect(result[0].vars).toEqual(testCases[0].vars);
  47. expect(result[0].metadata).toEqual({
  48. pluginId: 'test-plugin',
  49. key: 'value',
  50. strategyId: 'goat',
  51. originalText: 'test goal',
  52. });
  53. });
  54. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...