|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License", destination); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import * as assert from 'assert'; |
| 19 | +import { getTestProposalPrompt, getTestFileContentPrompt, getFixFailingTestPrompt, getFixRuntimeFailurePrompt } from '../utils/prompts'; |
| 20 | + |
| 21 | +suite('prompts', () => { |
| 22 | + suite('getTestProposalPrompt', () => { |
| 23 | + test('returns a non-empty string', () => { |
| 24 | + const result = getTestProposalPrompt({ extensionId: 'test.ext' }); |
| 25 | + assert.ok(result.length > 0); |
| 26 | + }); |
| 27 | + |
| 28 | + test('includes the JSON of relevantParts in the output', () => { |
| 29 | + const parts = { extensionId: 'foo.bar', commands: [{ command: 'foo.bar.cmd' }] }; |
| 30 | + const result = getTestProposalPrompt(parts); |
| 31 | + assert.ok(result.includes('"extensionId"')); |
| 32 | + assert.ok(result.includes('foo.bar')); |
| 33 | + }); |
| 34 | + |
| 35 | + test('includes schema field names in the output', () => { |
| 36 | + const result = getTestProposalPrompt({}); |
| 37 | + assert.ok(result.includes('"category"')); |
| 38 | + assert.ok(result.includes('"test-name"')); |
| 39 | + assert.ok(result.includes('"description"')); |
| 40 | + assert.ok(result.includes('"cover"')); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + suite('getTestFileContentPrompt', () => { |
| 45 | + const baseProposal = { |
| 46 | + 'test-name': 'mySpecialTest', |
| 47 | + category: 'notifications', |
| 48 | + description: 'verifies the sidebar opens correctly', |
| 49 | + cover: ['featureAlpha', 'featureBeta'], |
| 50 | + }; |
| 51 | + |
| 52 | + test('includes test-name in the output', () => { |
| 53 | + const result = getTestFileContentPrompt(baseProposal, {}); |
| 54 | + assert.ok(result.includes('mySpecialTest')); |
| 55 | + }); |
| 56 | + |
| 57 | + test('includes category in the output', () => { |
| 58 | + const result = getTestFileContentPrompt(baseProposal, {}); |
| 59 | + assert.ok(result.includes('notifications')); |
| 60 | + }); |
| 61 | + |
| 62 | + test('includes description in the output', () => { |
| 63 | + const result = getTestFileContentPrompt(baseProposal, {}); |
| 64 | + assert.ok(result.includes('verifies the sidebar opens correctly')); |
| 65 | + }); |
| 66 | + |
| 67 | + test('includes each cover item in the output', () => { |
| 68 | + const result = getTestFileContentPrompt(baseProposal, {}); |
| 69 | + assert.ok(result.includes('featureAlpha')); |
| 70 | + assert.ok(result.includes('featureBeta')); |
| 71 | + }); |
| 72 | + |
| 73 | + test('includes relevantParts JSON in the output', () => { |
| 74 | + const result = getTestFileContentPrompt(baseProposal, { extensionId: 'my.ext' }); |
| 75 | + assert.ok(result.includes('my.ext')); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + suite('getFixFailingTestPrompt', () => { |
| 80 | + test('includes failingOutput in the output', () => { |
| 81 | + const result = getFixFailingTestPrompt({ failingOutput: 'error TS2552: cannot find name', relevantParts: {} }); |
| 82 | + assert.ok(result.includes('error TS2552: cannot find name')); |
| 83 | + }); |
| 84 | + |
| 85 | + test('includes filePath when provided', () => { |
| 86 | + const result = getFixFailingTestPrompt({ failingOutput: 'err', filePath: 'src/test.ts', relevantParts: {} }); |
| 87 | + assert.ok(result.includes('src/test.ts')); |
| 88 | + }); |
| 89 | + |
| 90 | + test('omits Failing file path label when filePath is undefined', () => { |
| 91 | + const result = getFixFailingTestPrompt({ failingOutput: 'err', relevantParts: {} }); |
| 92 | + assert.ok(!result.includes('Failing file path:')); |
| 93 | + }); |
| 94 | + |
| 95 | + test('includes currentContent when provided', () => { |
| 96 | + const result = getFixFailingTestPrompt({ failingOutput: 'err', currentContent: 'const x = 1;', relevantParts: {} }); |
| 97 | + assert.ok(result.includes('const x = 1;')); |
| 98 | + }); |
| 99 | + |
| 100 | + test('omits Current test file content label when currentContent is undefined', () => { |
| 101 | + const result = getFixFailingTestPrompt({ failingOutput: 'err', relevantParts: {} }); |
| 102 | + assert.ok(!result.includes('Current test file content:')); |
| 103 | + }); |
| 104 | + |
| 105 | + test('includes relevantParts JSON in the output', () => { |
| 106 | + const result = getFixFailingTestPrompt({ failingOutput: 'err', relevantParts: { extensionId: 'my.ext' } }); |
| 107 | + assert.ok(result.includes('my.ext')); |
| 108 | + }); |
| 109 | + }); |
| 110 | + |
| 111 | + suite('getFixRuntimeFailurePrompt', () => { |
| 112 | + test('includes failingOutput in the output', () => { |
| 113 | + const result = getFixRuntimeFailurePrompt({ failingOutput: 'Timeout of 20000ms exceeded', relevantParts: {} }); |
| 114 | + assert.ok(result.includes('Timeout of 20000ms exceeded')); |
| 115 | + }); |
| 116 | + |
| 117 | + test('includes filePath when provided', () => { |
| 118 | + const result = getFixRuntimeFailurePrompt({ failingOutput: 'err', filePath: 'src/runtime.test.ts', relevantParts: {} }); |
| 119 | + assert.ok(result.includes('src/runtime.test.ts')); |
| 120 | + }); |
| 121 | + |
| 122 | + test('includes currentContent when provided', () => { |
| 123 | + const result = getFixRuntimeFailurePrompt({ |
| 124 | + failingOutput: 'err', |
| 125 | + currentContent: 'await driver.findElement()', |
| 126 | + relevantParts: {}, |
| 127 | + }); |
| 128 | + assert.ok(result.includes('await driver.findElement()')); |
| 129 | + }); |
| 130 | + |
| 131 | + test('includes relevantParts JSON in the output', () => { |
| 132 | + const result = getFixRuntimeFailurePrompt({ failingOutput: 'err', relevantParts: { extensionId: 'rt.ext' } }); |
| 133 | + assert.ok(result.includes('rt.ext')); |
| 134 | + }); |
| 135 | + |
| 136 | + test('omits Failing file path label when filePath is undefined', () => { |
| 137 | + const result = getFixRuntimeFailurePrompt({ failingOutput: 'err', relevantParts: {} }); |
| 138 | + assert.ok(!result.includes('Failing file path:')); |
| 139 | + }); |
| 140 | + |
| 141 | + test('omits Current test file content label when currentContent is undefined', () => { |
| 142 | + const result = getFixRuntimeFailurePrompt({ failingOutput: 'err', relevantParts: {} }); |
| 143 | + assert.ok(!result.includes('Current test file content:')); |
| 144 | + }); |
| 145 | + }); |
| 146 | +}); |
0 commit comments