Files
oh-my-pi/packages/coding-agent/test/prompt-format.test.ts
T
can1357 7de4c831e6 refactor(coding-agent): extracted prompt formatting into reusable utility
- Extracted prompt formatting logic into reusable `formatPromptContent()` utility function with configurable render phases.
- Removed 166 lines of duplicate formatting code from scripts and config modules by centralizing regex patterns and helper functions.
- Updated prompt template rendering to use unified `formatPromptContent()` instead of inline `optimizePromptLayout()` implementation.
- Added comprehensive test coverage for prompt formatting with pre-render and post-render mode validation.
2026-02-28 05:27:46 +01:00

31 lines
1.3 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { formatPromptContent } from "@oh-my-pi/pi-coding-agent/utils/prompt-format";
describe("formatPromptContent renderPhase", () => {
test("pre-render mode strips indentation from Handlebars block lines", () => {
const input = "<root>\n {{#if ok}}\n value\n {{/if}}\n</root>";
const output = formatPromptContent(input, { renderPhase: "pre-render" });
expect(output).toBe("<root>\n{{#if ok}}\n value\n{{/if}}\n</root>");
});
test("post-render mode preserves indentation on Handlebars-like lines", () => {
const input = "<root>\n {{#if ok}}\n value\n {{/if}}\n</root>";
const output = formatPromptContent(input, { renderPhase: "post-render" });
expect(output).toBe("<root>\n {{#if ok}}\n value\n {{/if}}\n</root>");
});
test("pre-render removes blank line before closing Handlebars block while post-render keeps it", () => {
const input = "<root>\n{{#if ok}}\nvalue\n\n{{/if}}\n</root>";
const preRender = formatPromptContent(input, { renderPhase: "pre-render" });
const postRender = formatPromptContent(input, { renderPhase: "post-render" });
expect(preRender).toBe("<root>\n{{#if ok}}\nvalue\n{{/if}}\n</root>");
expect(postRender).toBe("<root>\n{{#if ok}}\nvalue\n\n{{/if}}\n</root>");
});
});