Skip to content

Commit 30572e1

Browse files
committed
fix: address PR review comments
- Restore console.error spies in cowriter.test.js to prevent leaks - Fix misleading 'unicode escape' test (was valid JSON, now invalid) - Add 256-char model name length limit to MODEL_NAME_PATTERN - Add test case for model name exceeding length limit Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
1 parent 0d9b658 commit 30572e1

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Classes/Domain/DTO/CompleteRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Allowed characters in model names (alphanumeric, hyphens, underscores, dots, colons, slashes).
3131
* Examples: gpt-4o, claude-3-opus-20240229, mistral/mixtral-8x7b, openai:gpt-4.
3232
*/
33-
private const MODEL_NAME_PATTERN = '/^[a-zA-Z0-9][-a-zA-Z0-9_.:\/]*$/';
33+
private const MODEL_NAME_PATTERN = '/^[a-zA-Z0-9][-a-zA-Z0-9_.:\/]{0,255}$/';
3434

3535
/**
3636
* Maximum allowed prompt length in characters.

Tests/JavaScript/cowriter.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,15 @@ describe('Cowriter Plugin', () => {
290290
getItems: () => [{ data: 'prompt' }],
291291
};
292292
mockEditor.model.document.selection.getRanges.mockReturnValue([mockRange]);
293-
vi.spyOn(console, 'error').mockImplementation(() => {});
293+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
294294

295295
await capturedButton.fire('execute');
296296

297297
expect(mockEditor._writer.insert).toHaveBeenCalledWith(
298298
expect.stringContaining('Unknown error'),
299299
expect.anything()
300300
);
301+
errorSpy.mockRestore();
301302
});
302303

303304
it('should reset _isProcessing after completion', async () => {
@@ -316,10 +317,11 @@ describe('Cowriter Plugin', () => {
316317
getItems: () => [{ data: 'prompt' }],
317318
};
318319
mockEditor.model.document.selection.getRanges.mockReturnValue([mockRange]);
319-
vi.spyOn(console, 'error').mockImplementation(() => {});
320+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
320321

321322
await capturedButton.fire('execute');
322323
expect(plugin._isProcessing).toBe(false);
324+
errorSpy.mockRestore();
323325
});
324326

325327
it('should handle null insertPosition gracefully', async () => {

Tests/Unit/Domain/DTO/CompleteRequestFuzzTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public static function malformedJsonProvider(): iterable
226226
yield 'empty object' => ['{}'];
227227
yield 'nested deeply' => [str_repeat('[', 100) . '1' . str_repeat(']', 100)];
228228
yield 'very large number' => ['{"prompt":"test","n":' . str_repeat('9', 1000) . '}'];
229-
yield 'unicode escape' => ['{"prompt":"\\u0048\\u0065\\u006c\\u006c\\u006f"}'];
229+
yield 'invalid unicode escape' => ['{"prompt":"\\u004G"}'];
230230
}
231231

232232
// ===================================================
@@ -297,7 +297,8 @@ public static function modelOverrideEdgeCaseProvider(): iterable
297297
yield 'case sensitive prefix' => ['#CW:gpt-4o test', null, '#CW:gpt-4o test'];
298298
yield 'prefix mid-string' => ['hello #cw:gpt-4o test', null, 'hello #cw:gpt-4o test'];
299299
yield 'model with all valid chars' => ['#cw:a-b_c.d:e/f test', 'a-b_c.d:e/f', 'test'];
300-
yield 'model max valid pattern' => ['#cw:' . str_repeat('a', 200) . ' test', str_repeat('a', 200), 'test'];
300+
yield 'model max valid length' => ['#cw:' . str_repeat('a', 256) . ' test', str_repeat('a', 256), 'test'];
301+
yield 'model name too long' => ['#cw:' . str_repeat('a', 257) . ' test', null, '#cw:' . str_repeat('a', 257) . ' test'];
301302
}
302303

303304
// ===================================================

0 commit comments

Comments
 (0)