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

crescendo.test.ts 2.7 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  1. import { addCrescendo } from '../../../src/redteam/strategies/crescendo';
  2. import type { TestCase } from '../../../src/types';
  3. describe('addCrescendo', () => {
  4. it('should add crescendo configuration to test cases', () => {
  5. const testCases: TestCase[] = [
  6. {
  7. description: 'Test case 1',
  8. vars: { input: 'test input' },
  9. assert: [
  10. {
  11. type: 'contains',
  12. metric: 'exactMatch',
  13. value: 'expected output',
  14. },
  15. ],
  16. },
  17. ];
  18. const injectVar = 'input';
  19. const config = { someConfig: 'value' };
  20. const result = addCrescendo(testCases, injectVar, config);
  21. expect(result).toHaveLength(1);
  22. expect(result[0]).toEqual({
  23. description: 'Test case 1',
  24. vars: { input: 'test input' },
  25. provider: {
  26. id: 'promptfoo:redteam:crescendo',
  27. config: {
  28. injectVar: 'input',
  29. someConfig: 'value',
  30. },
  31. },
  32. metadata: {
  33. strategyId: 'crescendo',
  34. originalText: 'test input',
  35. },
  36. assert: [
  37. {
  38. type: 'contains',
  39. metric: 'exactMatch/Crescendo',
  40. value: 'expected output',
  41. },
  42. ],
  43. });
  44. });
  45. it('should handle test cases without assertions', () => {
  46. const testCases: TestCase[] = [
  47. {
  48. description: 'Test case without assertions',
  49. vars: { input: 'test input' },
  50. },
  51. ];
  52. const result = addCrescendo(testCases, 'input', {});
  53. expect(result).toHaveLength(1);
  54. expect(result[0].assert).toBeUndefined();
  55. expect(result[0].provider).toEqual({
  56. id: 'promptfoo:redteam:crescendo',
  57. config: {
  58. injectVar: 'input',
  59. },
  60. });
  61. expect(result[0].metadata).toEqual({
  62. strategyId: 'crescendo',
  63. originalText: 'test input',
  64. });
  65. });
  66. it('should handle empty test cases array', () => {
  67. const result = addCrescendo([], 'inject', {});
  68. expect(result).toEqual([]);
  69. });
  70. it('should preserve other test case properties', () => {
  71. const testCases: TestCase[] = [
  72. {
  73. description: 'Test case',
  74. vars: { input: 'test' },
  75. provider: { id: 'original-provider' },
  76. assert: [{ type: 'contains', metric: 'test', value: 'value' }],
  77. otherProp: 'should be preserved',
  78. } as TestCase & { otherProp: string },
  79. ];
  80. const result = addCrescendo(testCases, 'input', {});
  81. expect(result[0]).toMatchObject({
  82. description: 'Test case',
  83. vars: { input: 'test' },
  84. otherProp: 'should be preserved',
  85. provider: {
  86. id: 'promptfoo:redteam:crescendo',
  87. config: {
  88. injectVar: 'input',
  89. },
  90. },
  91. metadata: {
  92. strategyId: 'crescendo',
  93. originalText: 'test',
  94. },
  95. });
  96. });
  97. });
Tip!

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

Comments

Loading...