wishforge c75f429716 🐛 Read the line breaks a model escapes inside its tool call
An answer travels in a submit_answer tool call, and the model writes its
line breaks there as the two characters \n. The console draws exactly what
it is given, so a customer read \n\n where a paragraph break belonged.

The layout escapes are now unfolded once, where model text enters: the
answer, the Wish draft, the quick replies and the excerpts all pass one
door. Answers stored before this change are unfolded as they are drawn, so
the history reads correctly without touching the database.
2026-11-09 20:12:01 -08:00

27 lines
1.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from 'vitest';
import { plainText } from '../src/text.js';
describe('text a model wrote inside a tool call', () => {
it('turns the escapes the model spelled out into the layout the customer should see', () => {
expect(plainText('改动已经提交。\\n\\n可以从这几件事开始:\\n1. 改文案')).toBe(
'改动已经提交。\n\n可以从这几件事开始:\n1. 改文案',
);
});
it('handles the Windows spelling of a line break as one break, not two', () => {
expect(plainText('第一行\\r\\n第二行')).toBe('第一行\n第二行');
expect(plainText('第一行\\r第二行')).toBe('第一行\n第二行');
});
it('leaves text that already carries real line breaks untouched', () => {
expect(plainText('第一行\n第二行')).toBe('第一行\n第二行');
expect(plainText('一句话,没有换行')).toBe('一句话,没有换行');
});
it('leaves every other backslash alone, so a pattern still reads as itself', () => {
expect(plainText('匹配 \\d{3} 或 \\w+')).toBe('匹配 \\d{3} 或 \\w+');
expect(plainText('写成 \\p{L} 匹配字母')).toBe('写成 \\p{L} 匹配字母');
});
it('is idempotent, so a value drawn twice still reads the same', () => {
const once = plainText('第一行\\n第二行');
expect(plainText(once)).toBe(once);
});
});