Skip to content

Commit c4f473d

Browse files
committed
test(systemPrompts): align Piebald-AI#660 backtick tests with scoped-doubling fix
The two backtick-context tests from PR Piebald-AI#664 encoded the 'literal text' interpretation of prompt content, which doesn't match tweakcc's data format (markdown files store JS-source-escaped form, extracted from cli.js template literals). The scoped-doubling fix in a3c2f84 preserves already-escaped backticks; update assertions to match.
1 parent a3c2f84 commit c4f473d

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/patches/systemPrompts.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,14 @@ describe('systemPrompts.ts', () => {
273273
);
274274
});
275275

276-
it('should escape backslashes before backticks to preserve literal backslash-backticks (#660)', async () => {
276+
it('should preserve already-escaped backticks in template literal context (#660)', async () => {
277+
// tweakcc's markdown files store prompt content in JS-source-escaped form
278+
// (they are extracted from cli.js template literals, where each `\\`` is
279+
// already an escape sequence). When re-embedded into a template literal,
280+
// the content must NOT be re-escaped — escapeDepthZeroBackticks leaves
281+
// already-escaped backticks alone. Backslash-doubling is intentionally
282+
// scoped to `"` / `'` delimiters only; doubling here would break valid
283+
// cli.js template literals.
277284
const mockPromptData = buildMockPromptData({
278285
content: 'Use \\`foo\\` for config',
279286
regex: 'Use \\\\`foo\\\\` for config',
@@ -287,7 +294,7 @@ describe('systemPrompts.ts', () => {
287294

288295
const result = await applySystemPrompts(cliContent, '1.0.0', false);
289296

290-
expect(result.newContent).toBe('desc:`Use \\\\\\`foo\\\\\\` for config`');
297+
expect(result.newContent).toBe('desc:`Use \\`foo\\` for config`');
291298
});
292299

293300
it('should auto-escape backticks adjacent to template expressions', async () => {
@@ -307,7 +314,11 @@ describe('systemPrompts.ts', () => {
307314
expect(result.newContent).toBe('desc:`Value: \\`${x}\\``');
308315
});
309316

310-
it('should escape backslashes in already-escaped backticks and also escape bare backticks (#660)', async () => {
317+
it('should auto-escape bare backticks while preserving already-escaped backticks (#660)', async () => {
318+
// Mixed content: `\\`foo\\`` is already in JS-source-escaped form and
319+
// must pass through unchanged; bare `bar` has unescaped backticks that
320+
// escapeDepthZeroBackticks must escape to keep the surrounding template
321+
// literal parseable.
311322
const mockPromptData = buildMockPromptData({
312323
content: 'Use \\`foo\\` and `bar` for config',
313324
regex: 'Use \\\\`foo\\\\` and `bar` for config',
@@ -322,7 +333,7 @@ describe('systemPrompts.ts', () => {
322333
const result = await applySystemPrompts(cliContent, '1.0.0', false);
323334

324335
expect(result.newContent).toBe(
325-
'desc:`Use \\\\\\`foo\\\\\\` and \\`bar\\` for config`'
336+
'desc:`Use \\`foo\\` and \\`bar\\` for config`'
326337
);
327338
});
328339

0 commit comments

Comments
 (0)