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
|
- import { addCrescendo } from '../../../src/redteam/strategies/crescendo';
- import type { TestCase } from '../../../src/types';
- describe('addCrescendo', () => {
- it('should add crescendo configuration to test cases', () => {
- const testCases: TestCase[] = [
- {
- description: 'Test case 1',
- vars: { input: 'test input' },
- assert: [
- {
- type: 'contains',
- metric: 'exactMatch',
- value: 'expected output',
- },
- ],
- },
- ];
- const injectVar = 'input';
- const config = { someConfig: 'value' };
- const result = addCrescendo(testCases, injectVar, config);
- expect(result).toHaveLength(1);
- expect(result[0]).toEqual({
- description: 'Test case 1',
- vars: { input: 'test input' },
- provider: {
- id: 'promptfoo:redteam:crescendo',
- config: {
- injectVar: 'input',
- someConfig: 'value',
- },
- },
- metadata: {
- strategyId: 'crescendo',
- originalText: 'test input',
- },
- assert: [
- {
- type: 'contains',
- metric: 'exactMatch/Crescendo',
- value: 'expected output',
- },
- ],
- });
- });
- it('should handle test cases without assertions', () => {
- const testCases: TestCase[] = [
- {
- description: 'Test case without assertions',
- vars: { input: 'test input' },
- },
- ];
- const result = addCrescendo(testCases, 'input', {});
- expect(result).toHaveLength(1);
- expect(result[0].assert).toBeUndefined();
- expect(result[0].provider).toEqual({
- id: 'promptfoo:redteam:crescendo',
- config: {
- injectVar: 'input',
- },
- });
- expect(result[0].metadata).toEqual({
- strategyId: 'crescendo',
- originalText: 'test input',
- });
- });
- it('should handle empty test cases array', () => {
- const result = addCrescendo([], 'inject', {});
- expect(result).toEqual([]);
- });
- it('should preserve other test case properties', () => {
- const testCases: TestCase[] = [
- {
- description: 'Test case',
- vars: { input: 'test' },
- provider: { id: 'original-provider' },
- assert: [{ type: 'contains', metric: 'test', value: 'value' }],
- otherProp: 'should be preserved',
- } as TestCase & { otherProp: string },
- ];
- const result = addCrescendo(testCases, 'input', {});
- expect(result[0]).toMatchObject({
- description: 'Test case',
- vars: { input: 'test' },
- otherProp: 'should be preserved',
- provider: {
- id: 'promptfoo:redteam:crescendo',
- config: {
- injectVar: 'input',
- },
- },
- metadata: {
- strategyId: 'crescendo',
- originalText: 'test',
- },
- });
- });
- });
|