|
6 | 6 | import assert from 'assert' |
7 | 7 | import * as sinon from 'sinon' |
8 | 8 | import { Writable } from 'stream' |
9 | | -import { sanitizePath, OutputKind, InvokeOutput } from '../../../codewhispererChat/tools/toolShared' |
| 9 | +import { |
| 10 | + sanitizePath, |
| 11 | + OutputKind, |
| 12 | + InvokeOutput, |
| 13 | + listDirectoryToolResponseSize, |
| 14 | + fsReadToolResponseSize, |
| 15 | + defaultMaxToolResponseSize, |
| 16 | +} from '../../../codewhispererChat/tools/toolShared' |
10 | 17 | import { ToolUtils, Tool, ToolType } from '../../../codewhispererChat/tools/toolUtils' |
11 | 18 | import { FsRead } from '../../../codewhispererChat/tools/fsRead' |
12 | 19 | import { FsWrite } from '../../../codewhispererChat/tools/fsWrite' |
@@ -158,25 +165,67 @@ describe('ToolUtils', function () { |
158 | 165 | }) |
159 | 166 |
|
160 | 167 | describe('validateOutput', function () { |
161 | | - it('does not throw error if output is within size limit', function () { |
| 168 | + it('does not throw error if output is within size limit for fsRead', function () { |
162 | 169 | const output: InvokeOutput = { |
163 | 170 | output: { |
164 | 171 | kind: OutputKind.Text, |
165 | | - content: 'a'.repeat(150_000), |
| 172 | + content: 'a'.repeat(fsReadToolResponseSize - 1), |
166 | 173 | }, |
167 | 174 | } |
168 | | - assert.doesNotThrow(() => ToolUtils.validateOutput(output)) |
| 175 | + assert.doesNotThrow(() => ToolUtils.validateOutput(output, ToolType.FsRead)) |
169 | 176 | }) |
170 | | - it('throws error if output exceeds max size', function () { |
| 177 | + it('throws error if output exceeds max size for fsRead', function () { |
171 | 178 | const output: InvokeOutput = { |
172 | 179 | output: { |
173 | 180 | kind: OutputKind.Text, |
174 | | - content: 'a'.repeat(200_001), // 200,001 characters |
| 181 | + content: 'a'.repeat(fsReadToolResponseSize + 1), |
175 | 182 | }, |
176 | 183 | } |
177 | | - assert.throws(() => ToolUtils.validateOutput(output), { |
| 184 | + assert.throws(() => ToolUtils.validateOutput(output, ToolType.FsRead), { |
178 | 185 | name: 'Error', |
179 | | - message: 'Tool output exceeds maximum character limit of 200000', |
| 186 | + message: `fsRead output exceeds maximum character limit of ${fsReadToolResponseSize}`, |
| 187 | + }) |
| 188 | + }) |
| 189 | + it('does not throw error if output is within size limit for listDirectory', function () { |
| 190 | + const output: InvokeOutput = { |
| 191 | + output: { |
| 192 | + kind: OutputKind.Text, |
| 193 | + content: 'a'.repeat(listDirectoryToolResponseSize - 1), |
| 194 | + }, |
| 195 | + } |
| 196 | + assert.doesNotThrow(() => ToolUtils.validateOutput(output, ToolType.ListDirectory)) |
| 197 | + }) |
| 198 | + it('throws error if output exceeds max size for listDirectory', function () { |
| 199 | + const output: InvokeOutput = { |
| 200 | + output: { |
| 201 | + kind: OutputKind.Text, |
| 202 | + content: 'a'.repeat(listDirectoryToolResponseSize + 1), |
| 203 | + }, |
| 204 | + } |
| 205 | + assert.throws(() => ToolUtils.validateOutput(output, ToolType.ListDirectory), { |
| 206 | + name: 'Error', |
| 207 | + message: `listDirectory output exceeds maximum character limit of ${listDirectoryToolResponseSize}`, |
| 208 | + }) |
| 209 | + }) |
| 210 | + it('does not throw error if output is within size limit for fsWrite', function () { |
| 211 | + const output: InvokeOutput = { |
| 212 | + output: { |
| 213 | + kind: OutputKind.Text, |
| 214 | + content: 'a'.repeat(defaultMaxToolResponseSize - 1), |
| 215 | + }, |
| 216 | + } |
| 217 | + assert.doesNotThrow(() => ToolUtils.validateOutput(output, ToolType.FsWrite)) |
| 218 | + }) |
| 219 | + it('does not throw error if output is within size limit for fsWrite', function () { |
| 220 | + const output: InvokeOutput = { |
| 221 | + output: { |
| 222 | + kind: OutputKind.Text, |
| 223 | + content: 'a'.repeat(defaultMaxToolResponseSize + 1), |
| 224 | + }, |
| 225 | + } |
| 226 | + assert.throws(() => ToolUtils.validateOutput(output, ToolType.FsWrite), { |
| 227 | + name: 'Error', |
| 228 | + message: `fsWrite output exceeds maximum character limit of ${defaultMaxToolResponseSize}`, |
180 | 229 | }) |
181 | 230 | }) |
182 | 231 | }) |
|
0 commit comments