Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
import { normalizeEditArgs } from './edits';
describe('normalizeEditArgs', () => {
test.each(
[
[],
'[]',
null,
undefined,
{},
{ old_text: 'original', new_text: 'replacement' },
'not json',
'null',
1,
true,
[null],
[[]],
[{ old_text: 'original' }],
[{ old_text: '', new_text: 'replacement' }],
[{ old_text: 'original', new_text: 'replacement', replace_all: 'yes' }],
].map((edits) => [edits]),
)('rejects supplied invalid edits %# instead of using top-level replacements', (edits) => {
expect(typeof normalizeEditArgs({ edits, old_text: 'original', new_text: 'replacement' })).toBe(
'string',
);
});
test('normalizes a single replacement without changing the input', () => {
const args = { old_text: 'original', new_text: '', replace_all: 'true' };
expect(normalizeEditArgs(args)).toEqual([
{ old_text: 'original', new_text: '', replace_all: true },
]);
expect(args.replace_all).toBe('true');
});
test.each(
[
[{ old_text: 'batch', new_text: 'replacement', replace_all: 'false' }],
JSON.stringify([{ old_text: 'batch', new_text: 'replacement', replace_all: 'false' }]),
[JSON.stringify({ old_text: 'batch', new_text: 'replacement', replace_all: 'false' })],
].map((edits) => [edits]),
)('normalizes valid batches %# and never selects ignored top-level fields', (edits) => {
const normalized = normalizeEditArgs({
edits,
old_text: 'ignored',
new_text: 'ignored',
replace_all: true,
});
expect(normalized).toEqual([{ old_text: 'batch', new_text: 'replacement' }]);
expect(normalizeEditArgs({ edits: normalized })).toEqual(normalized);
});
});
it('rejects oversized batches even when entries are valid or JSON-stringified', () => {
const edits = Array.from({ length: 101 }, () => ({ old_text: 'a', new_text: 'b' }));
expect(normalizeEditArgs({ edits })).toContain('limited to 100');
expect(normalizeEditArgs({ edits: JSON.stringify(edits) })).toContain('limited to 100');
});